4 ms·
This is the main reason why I've codified a bunch of bit tricks so I don't forget them [1]. They're often not worth using, but can sometimes work as a last-mile
by kstenerud 7y ago
This is the main reason why I've codified a bunch of bit tricks so I don't forget them [1]. They're often not worth using, but can sometimes work as a last-mile optimization after you've done all your algorithmic changes, cache locality, sizing, alignment, etc.
[1] https://github.com/kstenerud/bit-tricks https://github.com/kstenerud/bit-tricks
- omgtehlion 7y ago> https://github.com/kstenerud/bit-tricks/blob/master/bytes_required_for_bits.h https://github.com/kstenerud/bit-tricks/blob/master/bytes_re... looks like over-engineering of (bits + 7) >> 3
- skrimp 7y agoYour solution can overflow.
- omgtehlion 7y agothis won't: (bits + 7LL) >> 3
- jacobolus 7y agoIn https://github.com/kstenerud/bit-tricks/blob/master/sign.h https://github.com/kstenerud/bit-tricks/blob/master/sign.h Why not use: (x > 0) - (x < 0)