github.com/likebike/go--@v0.0.0-20190911215757-0bd925d16e96/go/src/math/hypot_386.s (about) 1 // Copyright 2010 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 #include "textflag.h" 6 7 // func Hypot(p, q float64) float64 8 TEXT ·Hypot(SB),NOSPLIT,$0 9 // test bits for not-finite 10 MOVL p_hi+4(FP), AX // high word p 11 ANDL $0x7ff00000, AX 12 CMPL AX, $0x7ff00000 13 JEQ not_finite 14 MOVL q_hi+12(FP), AX // high word q 15 ANDL $0x7ff00000, AX 16 CMPL AX, $0x7ff00000 17 JEQ not_finite 18 FMOVD p+0(FP), F0 // F0=p 19 FABS // F0=|p| 20 FMOVD q+8(FP), F0 // F0=q, F1=|p| 21 FABS // F0=|q|, F1=|p| 22 FUCOMI F0, F1 // compare F0 to F1 23 JCC 2(PC) // jump if F0 >= F1 24 FXCHD F0, F1 // F0=|p| (larger), F1=|q| (smaller) 25 FTST // compare F0 to 0 26 FSTSW AX 27 ANDW $0x4000, AX 28 JNE 10(PC) // jump if F0 = 0 29 FXCHD F0, F1 // F0=q (smaller), F1=p (larger) 30 FDIVD F1, F0 // F0=q(=q/p), F1=p 31 FMULD F0, F0 // F0=q*q, F1=p 32 FLD1 // F0=1, F1=q*q, F2=p 33 FADDDP F0, F1 // F0=1+q*q, F1=p 34 FSQRT // F0=sqrt(1+q*q), F1=p 35 FMULDP F0, F1 // F0=p*sqrt(1+q*q) 36 FMOVDP F0, ret+16(FP) 37 RET 38 FMOVDP F0, F1 // F0=0 39 FMOVDP F0, ret+16(FP) 40 RET 41 not_finite: 42 // test bits for -Inf or +Inf 43 MOVL p_hi+4(FP), AX // high word p 44 ORL p_lo+0(FP), AX // low word p 45 ANDL $0x7fffffff, AX 46 CMPL AX, $0x7ff00000 47 JEQ is_inf 48 MOVL q_hi+12(FP), AX // high word q 49 ORL q_lo+8(FP), AX // low word q 50 ANDL $0x7fffffff, AX 51 CMPL AX, $0x7ff00000 52 JEQ is_inf 53 MOVL $0x7ff80000, ret_hi+20(FP) // return NaN = 0x7FF8000000000001 54 MOVL $0x00000001, ret_lo+16(FP) 55 RET 56 is_inf: 57 MOVL AX, ret_hi+20(FP) // return +Inf = 0x7FF0000000000000 58 MOVL $0x00000000, ret_lo+16(FP) 59 RET