1/* 2 * COPYRIGHT: See COPYING in the top level directory 3 * PROJECT: ReactOS system libraries 4 * PURPOSE: Implementation of sqrt 5 * FILE: lib/sdk/crt/math/amd64/sqrt.S 6 * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org) 7 */ 8 9/* INCLUDES ******************************************************************/ 10 11#include <asm.inc> 12 13/* CODE **********************************************************************/ 14.code64 15 16PUBLIC sqrt 17sqrt: 18 19 /* Load the sign bit into rdx */ 20 mov rdx, HEX(8000000000000000) 21 22 /* Move the lower 64 bits of xmm0 into rax */ 23 movd rax, xmm0 24 25 /* Test the sign bit */ 26 test rax, rdx 27 28 /* If it is set, go to the failure path */ 29 jnz x_is_negative 30 31 /* x is positive, now check if it is NaN by checking if the unsigned 32 integer value is larger than the highest valid positive value. */ 33 mov rcx, HEX(7FF0000000000000) 34 cmp rax, rcx 35 ja short x_is_nan 36 37 /* All is well, calculate the sqrt */ 38 sqrtpd xmm0, xmm0 39 ret 40 41x_is_negative: 42 /* Load failure return value (-1.#IND00) into rcx */ 43 mov rcx, HEX(0FFF8000000000000) 44 45 /* Check if the parameter was -0.0 */ 46 cmp rax, rdx 47 48 /* If it was not, load the failure value, otherwise keep -0.0 */ 49 cmovne rax, rcx 50 51 /* Move the value back into the return register */ 52 movd xmm0, rax 53 ret 54 55x_is_nan: 56 /* Create a 1.#QNAN0 by setting this bit */ 57 mov rcx, HEX(8000000000000) 58 or rax, rcx 59 60 /* Move the value back into the return register */ 61 movd xmm0, rax 62 ret 63 64 65END 66