Just for the record: Rick and Erich have updated the code and improved the 
speed considerably, which
is really great!

---rony


On 19.04.2019 17:01, Moritz Hoffmann wrote:
> Hi,
> looking at ooRexx's implemetation of x2c I find the original code much easier 
> to understand and to
> reason about. Instead of hand-tuning an implementation I'd like to know why 
> the native
> implementation is slower than your approach. I'd suspect it's because it's 
> using strchr to
> validate each character against a set of valid characters. Might want to 
> improve that instead...
>
> It might be good to use VTune to do the actual performance analysis because 
> that will give a
> cycle-accurate break-down of instructions.
>
> Cheers,
> Moritz
>
> On Fri, Apr 19, 2019 at 4:18 PM Rony G. Flatscher <rony.flatsc...@wu.ac.at
> <mailto:rony.flatsc...@wu.ac.at>> wrote:
>
>     Double-checked the test hex strings and their positions of illegal 
> whitespace chars, here the
>     native routine with the corrected position:
>
>         int64_t hex2char(RexxCallContext *rcc, CSTRING hexData, size_t len, 
> char *data)
>         {
>             // check for trailing whitespace
>             char tmp=(hexData[len-1]);      // get last character (must not 
> be whitespace)
>             if (tmp==' ' || tmp=='\t')
>                 rcc->ThrowException1(93931, rcc->UnsignedInt64ToObject(len));
>
>             size_t dIdx=0;
>
>             for (size_t i=0; i<len; i++)
>             {
>
>                 if      (hexData[i]>='0' && hexData[i]<='9') 
> tmp=hexData[i]-'0';
>                 else if (hexData[i]>='A' && hexData[i]<='F') 
> tmp=hexData[i]-'A'+10;
>                 else if (hexData[i]>='a' && hexData[i]<='f') 
> tmp=hexData[i]-'a'+10;
>                 else
>                 {
>                     // check for leading whitespace
>                     if (dIdx==0 && (hexData[i]==' ' || hexData[i]=='\t') )
>                         rcc->ThrowException1(93931, rcc->Int32ToObject(1));
>
>                     if (hexData[i]==' ' || hexData[i]=='\t') continue; // 
> skip on whitespace
>
>                     // illegal hex digit
>                     char buf[64];
>                     snprintf(buf, 64, "%c\0", hexData[i]);
>                     rcc->ThrowException1(93933, 
> rcc->NewStringFromAsciiz(buf));
>                 }
>                 tmp<<=4;    // shift to high order nibble
>                 i++;        // position on next hex digit
>
>                 if (i==len) // we are beyond the hex string and missing the 
> second hex digit
>                 {
>                     char buf[256];
>                     snprintf(buf, 256, "Hexadecimal string incomplete: 
> hexadecimal pair starting with the character \"%c\" in position %zd is 
> missing the second hexadecimal digit\0", hexData[i-1], len);
>                     rcc->ThrowException1(93900,rcc->NewStringFromAsciiz(buf));
>                 }
>
>
>                 if      (hexData[i]>='0' && hexData[i]<='9') 
> tmp|=hexData[i]-'0';
>                 else if (hexData[i]>='A' && hexData[i]<='F') 
> tmp|=hexData[i]-'A'+10;
>                 else if (hexData[i]>='a' && hexData[i]<='f') 
> tmp|=hexData[i]-'a'+10;
>                 else if (hexData[i]==' ' || hexData[i]=='\t')  // also 
> whitespace not allowed in between of a hex pair
>                         rcc->ThrowException1(93931, 
> rcc->UnsignedInt64ToObject(i*+1*));
>                 else // illegal hex digit
>                 {
>                     char buf[64];
>                     snprintf(buf, 64, "%c\0", hexData[i]);
>                     rcc->ThrowException1(93933, 
> rcc->NewStringFromAsciiz(buf));
>                 }
>                 data[dIdx++]=tmp;
>             }
>             data[dIdx]='\0';
>             return (int64_t)dIdx;            // return number or characters 
> in data
>         }
>
>     ---rony
>
>     _______________________________________________
>     Oorexx-devel mailing list
>     Oorexx-devel@lists.sourceforge.net 
> <mailto:Oorexx-devel@lists.sourceforge.net>
>     https://lists.sourceforge.net/lists/listinfo/oorexx-devel
>
>
>
> -- 
> Moritz Hoffmann;
> http://antiguru.de/

_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

Reply via email to