Show HN: "crzy64", base64 mod aimed for fastest decoding
github.com
github.com
The rest is unchanged, but there is a trick in that the table indexes are shuffled, and shuffled differently depending on the neighboring values in a 24-bit block of source data.
> but I have had to decode a ton of 64-bit base64 strings, for example
Should be good for small data. It's a pity that no one (or I haven't seen such benchmarks) measures the performance of decoding a large amount of small data (like 1..64 bytes).
- Output bytes [A-Za-z0-9./] are shuffled so that it can be efficiently translated from and to the 0..63 range. The exact remapping is as follows:
cDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz./0123456789AaBbC
- Bits are reordered and XORed with each other to make the unpacking from three 8-bit bytes to four 6-bit units extremely simple: specifically, `x ^ (x >> 6)`. The input bits `qrstuvwx ijklmnop abcdefgh` thus should be converted to the following four 6-bit units, XORed together (here represented with two-bit padding as in the actual implementation): 00abcdef 00ijklgh 00qrmnop 00stuvwx
0000ijkl 00000000 0000gh00 00mnop00
000000qr 00000000 00000000 00gh0000
Since both optimizations can equally work well for SIMD and for SWAR (SIMD within a register), I guess they may even be useful for small inputs. 00000000 abcdefgh ijklmnop qrstuvwx
-------- -------- -------- --------
00abcdef 00ijklgh 00qrmnop 00stuvwx
0000ijkl 0000qr00 0000gh00 00mnop00 <-- missing "qr"
000000qr 00000000 00000000 00gh0000Due to the nature of CPUs operating asynchronously, if one function is waiting for memory to be read, it can continue doing other things.
As such, if this base64 implementation is more efficient, even though the “wall clock” time is exactly identical due to the memory bandwidth, the CPU has more time to perform _other_ tasks.
It would be cool to show a demo of a processor maintaining good IPC on one hyper thread while the other hyper thread running on the same core was able to do a base64 decode.
You know what else uses dot slash? The Unix crypt function.
I guess it'll go... nowhere.
https://en.wikipedia.org/wiki/Binary-to-text_encoding#Encodi...
Incidentally every Windows desktop now has UUENCODE built in
C:\>dir > %TEMP%\foo && tar -cf - --format shardump %TEMP%\foo
Finally I can extract those usenet archives. :)