Hacker News new | past | comments | ask | show | jobs | submit login

We used to use the BCD opcodes for this kind of thing. Masking off the 0x30, shift digits (if you want packed BCD)

I can't imagine that has been efficient for decades tho




The BCD instructions are one of the few things that was dropped in the x86-64 transition, so it wouldn't work at all anymore.


they'd never been extended to work on more than 8 bits, even in the 8086; they only really existed for 8080 compatibility, and arguably the 8080 primarily had them to ease the path from earlier intel processors designed for, if i'm not mistaken, literal pocket calculators

in pocket calculators you have to display the result in decimal after performing a single arithmetic operation, so it's much more efficient to do the arithmetic in bcd than to convert from decimal to binary, perform the arithmetic operation, and then convert back


Yeah, if you wanted numbers greater than 99 you had to use them in the x87 (if you had one)


Agner says that AAA has latency 5 on Cannon Lake, so using that instruction is a bit faster than doing the operations manually. But if you vectorize (or use SWAR) I imagine you can start to beat the legacy instructions with larger numbers.




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

Search: