flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
Furs 10 Apr 2019, 13:55
Compile with -Ofast and it will be just a sqrtss. Looks like a bug to me but GCC is full of crap code generation without -ffast-math.
|
|||
![]() |
|
revolution 10 Apr 2019, 14:05
My guess would be for exception generation/handling.
|
|||
![]() |
|
fpissarra 03 May 2019, 03:51
Sorry, here's a follow up:
Yes, GCC has a tiny problem with this built in function. It should check if the argument is less than 0 before executing sqrtss (or sqrtsd for sqrt() function). The call to libm sqrtf() needs to be made if x < 0 because errno and math exceptions must be set acordingly. I've reported this bug to GCC Bugzilla and it was accepted as such. Future versions (or patches) will correct the problem (which doesn't affect the correctness of the built in function, but makes it very slow only - I've measured 70000 clock cycles in my machine)... |
|||
![]() |
|
revolution 03 May 2019, 04:26
Exceptions are expensive.
Glad you were able to fix the C silliness. ![]() |
|||
![]() |
|
fpissarra 04 May 2019, 17:25
The solutions, until GCC gets patched, are:
1- Use -ffast-math. This way, the compiler will not touch errno (won't call libm sqrt()) and still returns -NAN when x < 0; 2- Use inline assembly: Code: #include <math.h> inline double sqrt_(double x) { if ( x < 0 ) { errno = EDOM; return -NAN; } __asm__ __volatile__ ( "sqrtsd %0,%0" : "+x" (x) ); return x; } |
|||
![]() |
|
revolution 04 May 2019, 17:29
fpissarra wrote: The solutions, until GCC gets patched, are: But what about option 3? 3- Use pure assembly ![]() |
|||
![]() |
|
fpissarra 04 May 2019, 20:35
revolution wrote: But what about option 3? Yep... but, in this case, every call to sqrtf_() won't be 'inline'. PS: I do prefer #1, since is portable (if you are using GCC on multiple platforms). |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.