https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121652
--- Comment #11 from Aurelien Jarno <aurelien at aurel32 dot net> --- (In reply to Vineet Gupta from comment #4) > Also I'm thinking to model this based on existing libc implementation which > has been around for a while and should hopefully be correct. > > What glibc does is early check for nan and return x + x if so. See [1] > > This implicitly > - doesn't restore flags for nan case (this PR/121652) > - restores flag otherwise (retains fix for PR/121534) In addition the x+x addition converts a possible snan into a nan. > https://github.com/bminor/glibc/blob/master/sysdeps/riscv/rv64/rvd/s_round.c > > This requires the gcc builtin to call equivalent of __builtin_isnan(). > > However looks like there's a different problem lurking under the hood so let > me run it by this group who care about these subtleties. > > Consider following test: -O2 -march=rv64gc -mabi=lp64d > > ` > int myisnan(double __x) > { > return __builtin_isnan(__x); > } > ` > > generates > > ` > myisnan: > feq.d a0,fa0,fa0 > xori a0,a0,1 > ret > ` > > FEQ.D is a quite comparison meaning it *can* set the invalid operation > exception flag if either input is a signaling NaN. I think it is what we want no? In addition this is what is currently used by the GLIBC code. At the end it seems the GLIBC round code is correct and widely tested, so we just want to mimic it in the builtin.
