Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> In fact, bit shifting is always faster than anything.

This is overly simplistic. A fixed bitwise mapping is simple wiring and about as fast as anything can be, yes. Extending that, the "fastest" 32-bit shifter might be to put down 31 circuits, one for each possible shift amount. But that still requires a mux tree to select between the different circuits, which already goes beyond simple wiring.

While that might be the minimum-delay implementation, it's also very area inefficient. A more area-efficient design would be to cascade lg(32) = 5 muxed shifters, one for each bit in the shift amount. For example, x << 19 is the same as ((x << 16) << 2) << 1. If you read a VLSI design textbook, you'll see that there are all kinds of low-level tricks for designing barrel shifters, especially when it comes to layout.

Finally, the practical reality for programmers is that variable-amount shifts and rotates are relatively expensive on quite a few processors.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: