4 ms·
How is it divisionless when there are right shifts in the code?
by classified 2y ago
How is it divisionless when there are right shifts in the code?
- fanf2 2y agoNo division instructions, because they are many times slower than other arithmetic instructions. In many instruction sets the shifts are not even shifts, because the multiply returns a double-width result in two registers and the shift is just a way of telling the compiler to use the register containing the top half of the result.
- nullc 2y agoWhich also the same sense that a form using % is not divisionless. When bittwiddlers speak of divisionless they mean not using the exceptionally slow div and divmod instructions. Also the same sense in that code that uses division by a compile time constant is divisionless-- any competent compiler will turn that into a multiply.
- hansvm 2y agoThe sibling comment talking about division _instructions_ is spot on. It's sort of like how you can use shifts and other bit twiddling to divide by small constants (like 5) much more quickly than actually issuing a division instruction. Or, to divide a float by an integer power of 2 you can just manually set the exponent bits correctly.