SQLite Forum

Decimal128
Login
I'm not going to quibble with the above merely hyperbolic assertions. (They are not misleading because they are so obviously overstated.) However, there is one semi-untruth to be remedied:

> ... the CISC instructions that used to exist in CPUs to do that sort of arithmetic have long since been retired.

In fact, to support doing decimal arithmetic, which is still a software-intensive proposition compared to using a modern floating point arithmetic unit, nearly every microprocessor made since they were invented, up to today's 64-bit word crunchers, has had instructions called DAA and DAS (or similar). For example, see the [Intel® 64 and IA-32 ArchitecturesSoftware Developer’s Manual](https://software.intel.com/sites/default/files/managed/39/c5/325462-sdm-vol-1-2abcd-3abcd.pdf) at pages at 3-291 and 3-293. These instructions perform a post-addition or post-subtraction fix-up upon a pair of decimal digits held in an 8-bit register after similar pairs are added or subtracted. While primitive, this speeds up decimal arithmetic done in software by eliminating a lot of test/branch operations.  There is even a processor ALU flag to help with these fix-ups.

To grant the "... retired" assertion its due: These instructions are available only in legacy and compatibility modes. I suppose that means they are retired. But they can be readily coaxed out of their retirement.