In this simple code, for x86-64:
The compiler creates code like this:Code:double f( double x ) { return sqrt( x ); }
Testing the direct use of SQRTSD against this routine with invalid values (x < 0.0, x = -0.0, +/-NAN or +/-INFINITE) I see no difference. And why calls sqrt() if it will recover XMM1 from stack?Code:f: pxor xmm2, xmm2 sqrtsd xmm1, xmm0 ucomisd xmm2, xmm0 ja .L8 ; 0 > x? movapd xmm0, xmm1 ret .L8: sub rsp, 24 ; store SQRTSD result on stack. movsd QWORD [rsp+8], xmm1 call sqrt ; why? sqrt() doesn't use the stack! ; Get result back from stack (zeroing upper bits). movsd xmm1, QWORD [rsp+8] add rsp, 24 ; Use SQRTSD result anyway! movapd xmm0, xmm1 ret
The compiler does something similar if using fp87 instructions.
Strange...