mppp
mppp copied to clipboard
[BUG] Literal `_rq` performs conversion of string literal in runtime instead of compile time
I expect the performance of the quad prec literal NUM_rq
to have the same performance of doing real128(NUM.q)
, however it is much slower. Running perf
on some sample code shows that the conversion from string to __float128 is not happening at compile time as seems to be the case with .q
, but occurs at runtime:
When I use real128(NUM.q)
, there is no function call to strtofloat
:
Changing from _rq
to .q
made my code about 1.5 times faster.
Hi @benruijl . The _rq
literal is implemented via a C function from the GCC quadmath library:
https://gcc.gnu.org/onlinedocs/libquadmath/strtoflt128.html#strtoflt128
In order to have the conversion done at compile time, one would need to re-implement the strtoflt128
function (or a subset of it at least) as a constexpr
function.
An alternative is to use the floating-point literal for __float128
provided by GCC, which however requires the use of specific compiler flags:
https://gcc.gnu.org/onlinedocs/gcc/Floating-Types.html
At the moment, I am using this second option. Basically, I have turned all the literals into real128(NUM.q)
, which requires the -fext-numeric-literals
flag.