Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Literal _rq performs conversion of string literal in runtime instead of compile time #288

Open
benruijl opened this issue Oct 20, 2021 · 2 comments

Comments

@benruijl
Copy link

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:
strtoflt128

When I use real128(NUM.q), there is no function call to strtofloat:
nostringconv

Changing from _rq to .q made my code about 1.5 times faster.

@benruijl benruijl added the bug label Oct 20, 2021
@bluescarni
Copy link
Owner

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

@benruijl
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants