I am trying to make my microcontroller library more efficient and the most called function in the library (can be called 1 million times a second) is where im focusing my efforts into.
In this function there are some bitshift operation. like this where bool type
is coverted to 16bits and shifted 10 places
value = ((uint16_t) type) << 10
How many clock cycles / assembly instructions does a shift 10 uses?? Is it 10 instructions? or is it done in a single instruction?
As an alternative to that i am considering of doing something like this instead
if(type)
value = 0x0400
else
value = 0x0000
now if << 10
does take 10 operations i would assume that the later would be slightly faster by a few operations (the flash space trade off is negligible)
The program library is used in both C and C++ languages and the target microcontroller architecture is ARM and RISC
Bonus Points : Are there tools for answering questions like this where i want to test the whole function on how many assembly instructions it compiles into? for further optimatiation. Of course without digging into the whole compiled hex files