3 ms·
Agree on both points. I am often pleasantly surprised by clever compiler optimizations. I recently saw the following code optimized into a couple of bit-shift o
by bxparks 5y ago
Agree on both points. I am often pleasantly surprised by clever compiler optimizations. I recently saw the following code optimized into a couple of bit-shift operations, with no branching:
uint8_t pattern = ...;
uint8_t result = (pattern & 0x80) ? 0x1 : 0x0;
- tzs 5y agoAssuming N-bit ints: result = pattern; result <<= N-8; result >>= N-1; ?
- bxparks 5y ago(No one upvoted my post, so I didn't bother checking the threads, sorry for the delayed response). This was on an 8-bit microcontroller, so it was compiled to a left-shift into the carry bit, then a left-shift from the carry bit into a register that contained a 0x00.