[GSoC 2021] Swift Numerics: Decimal64

Hi everyone, hope you all are doing well.
My name is Alex, and I'm a first-year CS student at Georgia Tech.

I am really interested in the Decimal64 project idea with @scanon, as I am interested programming languages and the opportunity to add functionality to one, through the swift-numerics module. Relevant to this project, I am familiar with Swift and more so with C/C++. I also have some understanding of IEEE-754 standards and basic computer hardware/assembly through my coursework.

I had a few questions about writing a proposal for this project:

  1. Could you please explain the different challenges between Decimal64 and Decimal128 that the larger bit-width presents (so what makes Decimal128 a stretch goal to add)?

  2. Also, I would be interested to try and optimize the data type for specific hardware. I was wondering how you would suggest to do that? Would there be a way to do that with bit operands or should I mention taking advantage of specific ISAs?

  3. What are some of the areas in particular you suggest that I research and include in my proposal?

Thank you and I look forward to hearing back!

4 Likes
  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

I made a single thread with some more details and to address any questions here: Notes on GSoC Decimal arithmetic. Please ask away.

Let's concentrate discussion in Steve's thread; I'll lock this one.

1 Like