3 ms·
Can't you do an arithmetic shift-right? That takes the sign into account.
by chrisseaton 7y ago
Can't you do an arithmetic shift-right? That takes the sign into account.
- xxpor 7y agoYep, ASR is the ARM64 instruction.
- jcranmer 7y agoNo. An arithmetic shift right does a division that rounds down; an integer division operation instead truncates (rounds to zero). The easiest example is -1 / 2: -1 / 2 is 0, but -1 ashr 1 is -1. To replace a signed division with ashr, you have to know that for all negative inputs, the value of the bits shifted out are all 0.