Speeduino
|
As of AVR-GCC 13.2.0, the code produced for 32-bit shifts with a compile time shift distance is very poor. The templates here implement optimised shifting. Average 35% increase in shift performance on AtMega2560: see unit tests. More...
Functions | |
template<uint8_t b> | |
static uint32_t | lshift (uint32_t a) |
Bitwise left shift - generic, unoptimized, case. | |
template<uint8_t b> | |
static uint32_t | rshift (uint32_t a) |
Bitwise right shift - generic, unoptimized, case. | |
template<uint8_t b> | |
static uint32_t | rshift_round (uint32_t a) |
Rounded arithmetic right shift. | |
template<> | |
uint32_t | lshift< 4U > (uint32_t a) |
uint32_t bitwise left shift optimised for the specified shift distance | |
template<> | |
uint32_t | lshift< 5U > (uint32_t a) |
uint32_t bitwise left shift optimised for the specified shift distance | |
template<> | |
uint32_t | lshift< 6U > (uint32_t a) |
uint32_t bitwise left shift optimised for the specified shift distance | |
template<> | |
uint32_t | lshift< 7U > (uint32_t a) |
uint32_t bitwise left shift optimised for the specified shift distance | |
template<> | |
uint32_t | lshift< 9U > (uint32_t a) |
uint32_t bitwise left shift optimised for the specified shift distance | |
template<> | |
uint32_t | lshift< 10U > (uint32_t a) |
uint32_t bitwise left shift optimised for the specified shift distance | |
template<> | |
uint32_t | lshift< 11U > (uint32_t a) |
uint32_t bitwise left shift optimised for the specified shift distance | |
template<> | |
uint32_t | lshift< 12U > (uint32_t a) |
uint32_t bitwise left shift optimised for the specified shift distance | |
template<> | |
uint32_t | lshift< 13U > (uint32_t a) |
uint32_t bitwise left shift optimised for the specified shift distance | |
template<> | |
uint32_t | lshift< 14U > (uint32_t a) |
uint32_t bitwise left shift optimised for the specified shift distance | |
template<> | |
uint32_t | lshift< 15U > (uint32_t a) |
uint32_t bitwise left shift optimised for the specified shift distance | |
template<> | |
uint32_t | rshift< 3U > (uint32_t a) |
uint32_t bitwise right shift optimised for the specified shift distance | |
template<> | |
uint32_t | rshift< 4U > (uint32_t a) |
uint32_t bitwise right shift optimised for the specified shift distance | |
template<> | |
uint32_t | rshift< 5U > (uint32_t a) |
uint32_t bitwise right shift optimised for the specified shift distance | |
template<> | |
uint32_t | rshift< 6U > (uint32_t a) |
uint32_t bitwise right shift optimised for the specified shift distance | |
template<> | |
uint32_t | rshift< 7U > (uint32_t a) |
uint32_t bitwise right shift optimised for the specified shift distance | |
template<> | |
uint32_t | rshift< 9U > (uint32_t a) |
uint32_t bitwise right shift optimised for the specified shift distance | |
template<> | |
uint32_t | rshift< 10U > (uint32_t a) |
uint32_t bitwise right shift optimised for the specified shift distance | |
template<> | |
uint32_t | rshift< 11U > (uint32_t a) |
uint32_t bitwise right shift optimised for the specified shift distance | |
template<> | |
uint32_t | rshift< 12U > (uint32_t a) |
uint32_t bitwise right shift optimised for the specified shift distance | |
template<> | |
uint32_t | rshift< 13U > (uint32_t a) |
uint32_t bitwise right shift optimised for the specified shift distance | |
template<> | |
uint32_t | rshift< 14U > (uint32_t a) |
uint32_t bitwise right shift optimised for the specified shift distance | |
template<> | |
uint32_t | rshift< 15U > (uint32_t a) |
uint32_t bitwise right shift optimised for the specified shift distance | |
As of AVR-GCC 13.2.0, the code produced for 32-bit shifts with a compile time shift distance is very poor. The templates here implement optimised shifting. Average 35% increase in shift performance on AtMega2560: see unit tests.
Usage:
If there is no overload for a certain shift, that's because GCC produced decent ASM in that case.
Bitwise left shift - generic, unoptimized, case.
b | number of bits to shift by |
a | value to shift |
uint32_t bitwise left shift optimised for the specified shift distance
a | value to shift |
uint32_t bitwise left shift optimised for the specified shift distance
a | value to shift |
uint32_t bitwise left shift optimised for the specified shift distance
a | value to shift |
uint32_t bitwise left shift optimised for the specified shift distance
a | value to shift |
uint32_t bitwise left shift optimised for the specified shift distance
a | value to shift |
uint32_t bitwise left shift optimised for the specified shift distance
a | value to shift |
uint32_t bitwise left shift optimised for the specified shift distance
a | value to shift |
uint32_t bitwise left shift optimised for the specified shift distance
a | value to shift |
uint32_t bitwise left shift optimised for the specified shift distance
a | value to shift |
uint32_t bitwise left shift optimised for the specified shift distance
a | value to shift |
uint32_t bitwise left shift optimised for the specified shift distance
a | value to shift |
|
inlinestatic |
Bitwise right shift - generic, unoptimized, case.
b | number of bits to shift by |
a | value to shift |
uint32_t bitwise right shift optimised for the specified shift distance
a | value to shift |
uint32_t bitwise right shift optimised for the specified shift distance
a | value to shift |
uint32_t bitwise right shift optimised for the specified shift distance
a | value to shift |
uint32_t bitwise right shift optimised for the specified shift distance
a | value to shift |
uint32_t bitwise right shift optimised for the specified shift distance
a | value to shift |
uint32_t bitwise right shift optimised for the specified shift distance
a | value to shift |
uint32_t bitwise right shift optimised for the specified shift distance
a | value to shift |
uint32_t bitwise right shift optimised for the specified shift distance
a | value to shift |
uint32_t bitwise right shift optimised for the specified shift distance
a | value to shift |
uint32_t bitwise right shift optimised for the specified shift distance
a | value to shift |
uint32_t bitwise right shift optimised for the specified shift distance
a | value to shift |
uint32_t bitwise right shift optimised for the specified shift distance
a | value to shift |
Rounded arithmetic right shift.
Right shifting throws away bits. When use for fixed point division, this effectively rounds down (towards zero). To round-to-the-nearest-integer when right-shifting by S, just add in 2 power b−1 (which is the fixed-point equivalent of 0.5) first
b | number of bits to shift by |
a | value to shift |