[GSoC 2021] Swift Numerics: Decimal64

  1. Decimal128 isn't really harder than 64, but it requires more machinery be built to support it. We already have 64 bit integer arithmetic (including double-width multiply and divide) in Swift, which makes building Decimal64 relatively straightforward, once you implement some basic primitives for packing and unpacking the representation and doing rounding. Decimal128 requires building a bunch of primitives for Int128 first. I will probably have already done this by the time a GSoC project gets started, but I haven't actually done it yet, so a student working on it may end up doing some of that work as well before being able to make real headway on Decimal128.

  2. The opportunities for hardware-specific optimization with Decimal are relatively few; IBM Z-series has some partial hardware support, but the operations will just boil down to basic integer arithmetic on every other platform. The opportunities for low-level optimization that is not hardware-specific, however, are numerous, as are the opportunities for competitive benchmarking against other implementations and test-suite development.

  3. First, read Decimal floating point - Wikipedia. It's worth noting in particular that there are two competing encoding schemes for IEEE 754 Decimal arithmetic: Binary Integer Significand and Densely Packed Decimal. These are two different encodings of exactly the same set of values. Intel backed BIS (aka "BID"), IBM backed DPD. Absent hardware support (as on x86 and ARM) on a 64-bit machine, BIS is the preferred format to work with for fixed-width types for performance reasons, so that's what we'll be implementing, but we also need to be able to ingest both encodings. It may also be interesting in implementing some DPD primitives to support future arbitrary-precision work, but that would also be a stretch goal.

4 Likes