Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2025-01-21 16:28:17


Matt Borland wrote:
> Here are some preliminary results:
>
> All tests run on an i9-11900k with Ubuntu 24.04 and the Intel(R) oneAPI
> DPC++/C++ Compiler 2025.0.4 (2025.0.4.20241205). The Intel benchmarks
> are written in C but should be a faithful port. Bottom line up front is the Intel
> library is an order of magnitude faster.
>
> Intel
>
> ===== Comparisons =====
> Comparisons <Decimal32 >: 73831 us
> Comparisons <Decimal64 >: 76725 us
>
...
>
> Proposal and built-in types
>
> ===== Comparisons =====
> comparisons<float >: 73013 us
> comparisons<double >: 104019 us
> comparisons<dec32_fast >: 562165 us
> comparisons<dec64_fast >: 592997 us

I took a look at operator<

https://github.com/cppalliance/decimal/blob/069c26a111b33123e6ce5c34b4bb007762b32155/include/boost/decimal/decimal64_fast.hpp#L566

https://github.com/cppalliance/decimal/blob/069c26a111b33123e6ce5c34b4bb007762b32155/include/boost/decimal/decimal64.hpp#L1703
https://github.com/cppalliance/decimal/blob/069c26a111b33123e6ce5c34b4bb007762b32155/include/boost/decimal/detail/comparison.hpp#L283

and I think it can be improved somewhat - unless I'm missing something subtle.

Assuming normalized numbers (which should be the case) of the same sign, operator< is equivalent (NaN notwithstanding) to comparing the two integers

eeeeeeee... mmmmmmmmmm...

I'm not quite sure whether zero needs to be a special case here. There's special case logic in operator< for it, but I'm not positive it's needed.

This makes me wonder whether { uintNN_t exp_and_mant; bool sign; } wouldn't be a better representation for _fast, although that would depend on how
important comparisons are, performance-wise.

We can actually apply a similar trick to BID encoding, by first checking whether the exponents start with something other than 11.
In that case, we can use a single compare without having to unpack.

(And if not, do something else clever :-) )


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk