128 bit numbers and the compiler

I like to use 128 bit numbers, I've already used them some times with the Nightly. But they increase the complexity of the compiler, and there are many reasons for keeping a compiler as simple as possible.

So, is it a good idea to remove the 128 bit numbers from Rustc, and add to the language the features needed to allow library-level code to implement 128 bit numbers as good and as efficient as the built-in ones?

To do this I guess you need better ways to specify error messages, empty compiler-blessed traits to specify your U128 + operation to be commutative, perhaps more operator overloading, etc. This stuff hopefully adds less complexity to the compiler compared to adding i128/u128 support, and allows other people to write other kind of efficient number-like things in library code.

LLVM has support for very efficient 128-bit integers, which are exposed by Clang in C as the __int128 type.

This is from the RFC on 128 bit numbers, I'm not sure if you read it but it also states that

There have been several attempts to create u128/i128 wrappers based on two u64 values, but these can't match the performance of LLVM's native 128-bit integers. For example LLVM is able to lower a 128-bit add into just 2 instructions on 64-bit platforms and 4 instructions on 32-bit platforms.

Here is the RFC: https://github.com/rust-lang/rfcs/blob/master/text/1504-int128.md

3 Likes