Hi! I'm happy to say that the fast-posit library (
https://github.com/andrepd/posit-rust) now supports
bounded posits (b-posits). If you're unfamiliar, fast-posit is a Rust library that aims to be a correct and fast software implementation of posit arithmetic, including the 2022 standard and some features beyond (b-posits, arbitrary N, ES, RS parameters, etc).
Here's a summary of new features since I last posted on this group
# Bounded positsThe big one is probably b-posits. These are posits which have a fixed limit `RS` on the maximum length of the regime field. This clips the dynamic range, but places a limit on the tapering of precision, ensuring that there are never less than `N - RS - ES` bits left over for the fraction. The ES can be increased to compensate the dynamic range loss, thus essentially letting you have a "flatter" tapering profile. Normal posits can be thought of as b-posits where RS ≥ N-1.
fast-posit allows you to specify any (valid) combination of N, ES, RS (up to 128 bits). The `Posit` type now has, beside the mandatory N and ES parameters it had before, an optional RS parameter:
```type MyPosit = Posit<32, 2, i32>; // Posit: 32 bits, 2 exponent bitstype MyBPosit = Posit<32, 5, i32, 6>; // b-posit: 32 bits, 5 exponent bits, 6 max regime```All operations are available for any N, ES, RS, including conversions between any posit/b-posit (going through a "fast path" of simply trimming the bit pattern or right-padding with 0s if the RS and ES are the same, or doing a decode → convert → encode otherwise).
# Quire improvementsThe quire implementation is feature-complete now. Several things that were missing are now available: adding two quires together (essential for parallel code), negating a quire, and of course the fused dot product.
The internals were also substantially reworked. The routines now do the core operation of "fixed-point add-with-carry" always 64 bits at a time, emit better code on x86_64 platforms by using an indirect jump instead of many branches, and have better i-cache footprint. On my computer on 512-bit quires for 32-bit posits, I now measure ~200Mops for sums vs ~30Mops for SoftPosit, about double as before these changes (benchmarks included in the source).
# Square rootThe sqrt function is now available (as all other functions, for any N, ES, RS). It's implemented as a "decode → kernel → encode" sequence just like add, mul, etc. The "kernel" part simply calls the integer sqrt routine in the Rust standard library for an integer with the same bits as the posit. It is *marginally* faster than SoftPosit, which I attribute to the faster "decode" and "encode" parts.
# MiscA constant INT_MAX (greatest consecutive integer representable as posit) is available for any `Posit<N, ES, RS>` type, better tests, smaller performance improvements across the board (~15% add, ~10% div, etc), polishing the documentation, etc.
Since C is the lingua franca of software, in the works is a C interface to call into this library. Since C has no generics, there will be a config file, user-editable, like
```p8: 8 2p16: 16 2bp16: 16 5 6```and a generator which will instantiate a C header library containing all the types in the config file. You will be able to simply run `./build-c-api.sh` to generate the library, tailored to your needs.
If you'd like to help, feedback is always appreciated. In particular, the documentation can be found at
https://docs.rs/fast-posit. See for instance: the front page with a small tutorial, the documentation for
the base Posit type, or for
the method nearestInt. I tried to be thorough and include examples; if you spot any mistakes or have any suggestions, feel free to let me know here or on github! Pull requests to add features or improve performance are welcome too.