in reply to Fastest byteswap (little endian to big endian (eg. 34127856 -> 12345678)
I am sure that dd is faster than XS, but here is an XS snippet (although I am not sure about the signed/unsigned or if I need to actually detect unicode bytes, assuming normal 8 bit bytes):
the ror idea comes from stackoverflow.char * swapstring(str) SV *str INIT: STRLEN len; char* buf = SvPVbyte(str, len); CODE: while(len--){ asm("ror $4,%1" : "+r" (buf[len])); } RETVAL = buf; OUTPUT: RETVAL
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Fastest byteswap (little endian to big endian (eg. 34127856 -> 12345678)
by oiskuu (Hermit) on Apr 16, 2015 at 09:19 UTC | |
by FreeBeerReekingMonk (Deacon) on Apr 16, 2015 at 18:24 UTC |