Is logical/arithmetic shift fewer bits faster?

Viewed 166

Is x>>2 faster than x>>31? In other words, is sar x, 2 faster than sar x, 31? I did some simple test, they seem to have the same speed. I would appreciate any solid evidence.

1 Answers

It would depend on the hardware implementation. For common operations involving a shift by a constant amount (e.g. pointer arithmetic), there could be a faster path (e.g. it might be fused with a related addition operation). For shifting by a variable, a barrel shifter circuitry is used, where any shift amount would have the same delay.

Related