3 ms·
I've been puzzling over your assembly code for a while. Assuming you just had the useful bits in eax and had just executed bswap: MSB .... byte1... byte2... LS
by sounds 9y ago
I've been puzzling over your assembly code for a while. Assuming you just had the useful bits in eax and had just executed bswap:
MSB .... byte1... byte2... LSB
00000xxx 00xxxxxx 00xxxxxx 00xxxxxx
How does multiplying (byte1 | LSB) * 3 help? I'm asking about lea ebx, [ebx + ebx*2], which is a shortcut for multiplying by 3.
Genuinely lost here, the 6 bits of byte1 and the 6 bits of LSB are separated by enough 0 bits that a multiplication by 3 won't mix them up. But within the 6 bits of byte1 and within the 6 bits of LSB, the multiplication will mean each bit is the sum of itself, the lower order bit, and any carried bits. What is that for?
Thanks for any tips!
- userbinator 9y agoThe hint is to look at the next instruction. Spoiler: https://pastebin.com/msjkXkKd https://pastebin.com/msjkXkKd
- deleted 9y ago[deleted]
- sounds 9y agoYes, that makes sense now. Thanks! Edit: I fiddled around a bit and came up with: https://pastebin.com/WA1Tp2KK https://pastebin.com/WA1Tp2KK The nullprogram.com version is 0x185 bytes (gcc 4.8.4 x86_64 -O3; objdump -s -j .text -j .rodata) I switched to __builtin_clz (with cross platform support). I hesitate to put in your assembly code, though it would work great! My version still sticks to C and not inline assembly. My version takes 0xeb bytes. Benchmarking with clang-802.0.42 -O3 -march=native on a Core i7-4770HQ @ 2.20GHz: branchless: 490.666725 MB/s, 0 errors 0xeb small: 352.000042 MB/s, 0 errors Hoehrmann: 337.333374 MB/s, 0 errors With gcc 4.8.4 -O3 -march=native on a Xeon E5-1650v3 @ 3.50GHz: branchless: 436.000052 MB/s, 0 errors 0xeb small: 345.333375 MB/s, 0 errors Hoehrmann: 412.000049 MB/s, 0 errors [1] https://stackoverflow.com/questions/19527897/how-undefined-are-builtin-ctz0-or-builtin-clz0 https://stackoverflow.com/questions/19527897/how-undefined-a...
- sounds 9y agoI was able to reduce it to 0xe9 bytes and I'm getting: clang-802.0.42 -O3 -march=native on a Core i7-4770HQ @ 2.20GHz: branchless: 490.666725 MB/s, 0 errors 0xe9 small: 380.000045 MB/s, 0 errors Hoehrmann: 337.333374 MB/s, 0 errors With gcc 4.8.4 -O3 -march=native on a Xeon E5-1650v3 @ 3.50GHz: branchless: 436.000052 MB/s, 0 errors 0xe9 small: 405.333382 MB/s, 0 errors Hoehrmann: 412.000049 MB/s, 0 errors https://pastebin.com/j7T3bDwR https://pastebin.com/j7T3bDwR