3 ms·
Does `shl eax 1` really outperform `add eax eax`? Although i guess that's a question for `-mtune` to decide.
by mappu 12y ago
Does `shl eax 1` really outperform `add eax eax`? Although i guess that's a question for `-mtune` to decide.
- JoshTriplett 12y agoShift definitely outperforms "mul"; it may or may not outperform "add", but it'll probably outperform a series of adds to implement a larger power of 2. And if you're using the result as part of an address, you can use [eax*2 + ...] as an operand and the shift will happen as part of addressing.
- spc476 12y agoSHL EAX,1 and ADD EAX,EAX are the same, time wise. The only difference is that the A flag (auxiliary carry [1]) is undefined for SHL and defined for ADD. SHL EAX,n may be faster than n repeats of ADD EAX,EAX, but there are other ways to do quick multiplication by powers of 2 though. [1] The auxiliary carry reflects a borrow from bit 4 to bit 3, or a carry from bit 3 to bit 4. It's used for BCD [2] arithmetic, and there is is no direct way to test for it. [2] Binary Coded Decimal