https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91690
kargl at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |kargl at gcc dot gnu.org --- Comment #1 from kargl at gcc dot gnu.org --- (In reply to Rich Townsend from comment #0) > Created attachment 46844 [details] > Demo program > > The intrinsics provided by the IEEE_ARITHMETIC module appear to be > significantly slower than an equivalent implementation based on inspecting > bits. > The implementations are not equivalent. -fdump-tree-original may shield some light. is_nan_bits() isn't worried about FPU state (ie., keeping track of exceptions). is_nan_bits is reduced to something simply using simple bit twiddling. The following is somewhat edited to reduce length is_nan_bits (real(kind=4) & x) { integer(kind=4) expn, frac, is_nan, ix, sign; { integer(kind=8) D.3904, D.3905, D.3906, transfer.0; D.3904 = 4; D.3905 = 4; __builtin_memcpy ((void *) &transfer.0, (void *) x, (unsigned long) MAX_EXPR <MIN_EXPR <D.3905, D.3904>, 0>); ix = transfer.0; } frac = NON_LVALUE_EXPR <ix> & 8388607; expn = ix >> 23 & 255; sign = (integer(kind=4)) ((unsigned int) ix >> 31); is_nan = expn == 255 && frac != 0; return is_nan; } is_nan_ieee is reduced to something with 2 function calls to maintain fpu state. is_nan_ieee (real(kind=4) & restrict x) { c_char fpstate.1[33]; logical(kind=4) is_nan; try { _gfortran_ieee_procedure_entry ((void *) &fpstate.1); is_nan = SAVE_EXPR <*x> unord SAVE_EXPR <*x>; return is_nan; } finally { _gfortran_ieee_procedure_exit ((void *) &fpstate.1); } } Both _entry and _exit are manipulating the FPU.