Is a logical right shift by a power of 2 faster in AVR?

后端 未结 9 1583
栀梦
栀梦 2020-12-06 19:21

I would like to know if performing a logical right shift is faster when shifting by a power of 2

For example, is

myUnsigned >> 4
9条回答
  •  旧时难觅i
    2020-12-06 20:01

    Let's look at the datasheet:

    http://atmel.com/dyn/resources/prod_documents/8271S.pdf

    As far as I can see, the ASR (arithmetic shift right) always shifts by one bit and cannot take the number of bits to shift; it takes one cycle to execute. Therefore, shifting right by n bits will take n cycles. Powers of two behave just the same as any other number.

提交回复
热议问题