Skip to content

Dev Notes: 2017_02_27

Dave Hudson edited this page Feb 27, 2017 · 5 revisions

Introducing Digit Arrays

While the C++ code has been written to be pretty fast, there's always an opportunity to make this sort of library code go faster by making use of assembler code. The problem is that building assembler support mixed in with the object class operations is really difficult.

In order to get around this we really need the core of each numerical operation to be abstracted into a form that's easier to optimize in the future. The abstraction chosen is a digit array, where a digit array is an array of c8::natural_digit values. All of the c8::natural operations can be reworked in terms of these digit arrays.

The use of digit arrays turns out to have quite a number of advantages:

  • Where each c8::natural operation might use multiple digit array operations we can now avoid doing unnecessary zero checks, exception checks, etc. Instead we can do these all in one place per numeric operation.

  • The inline operations can be much more efficient than making function calls, especially for something like the divide_modulus operations.

  • Many of our operators can actually use the same core digit array operations, reducing the amount of code duplication, and improving our ability to optimize things.

The performance impact is substantial!

natural_check -b -v:

integer_check -b -v:

rational_check -b -v:

See Also

Clone this wiki locally