chfast / intx

Extended precision integer C++ library
Apache License 2.0
132 stars 30 forks source link

Redesign: change internal structure of intx types #185

Closed chfast closed 3 years ago

chfast commented 3 years ago

The current intx 0.5 has "recursive" design, i.e. uint<N> types is composed of two (high and low) parts of uint<N/2> types. This was inspired by LLVM type legalization, but it turned out to have number of limitations and issues:

We propose to change the internal structure of intx types to simple array of 64-bit words uint64_t[K]. This makes this types being very close to std::array<uint64_t, K> although we will not use std::array directly — we want freedom to define other constructors and conversion operators.

An alternative was also considered:

  1. Union of uint64_t[K} and two parts uint<N/2> hi, lo. This would allow two different style of access to the data, but it is quite complex and requires very obscure hackery to have constexpr support. In lo/hi access is needed it is probably much easier and cleaner to provide hi() and lo() helpers (methods or free functions).
chfast commented 3 years ago

Done.