2010-01-26 13:53:02 -07:00
|
|
|
// Copyright 2010 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2013-08-12 11:25:18 -06:00
|
|
|
#include "../../cmd/ld/textflag.h"
|
|
|
|
|
2012-09-20 22:35:56 -06:00
|
|
|
// func Hypot(p, q float64) float64
|
2013-08-12 11:25:18 -06:00
|
|
|
TEXT ·Hypot(SB),NOSPLIT,$0
|
2010-01-26 13:53:02 -07:00
|
|
|
// test bits for not-finite
|
2013-03-22 10:57:55 -06:00
|
|
|
MOVL p_hi+4(FP), AX // high word p
|
2010-01-26 13:53:02 -07:00
|
|
|
ANDL $0x7ff00000, AX
|
|
|
|
CMPL AX, $0x7ff00000
|
|
|
|
JEQ not_finite
|
2013-03-22 10:57:55 -06:00
|
|
|
MOVL q_hi+12(FP), AX // high word q
|
2010-01-26 13:53:02 -07:00
|
|
|
ANDL $0x7ff00000, AX
|
|
|
|
CMPL AX, $0x7ff00000
|
|
|
|
JEQ not_finite
|
2012-09-20 22:35:56 -06:00
|
|
|
FMOVD p+0(FP), F0 // F0=p
|
|
|
|
FABS // F0=|p|
|
|
|
|
FMOVD q+8(FP), F0 // F0=q, F1=|p|
|
|
|
|
FABS // F0=|q|, F1=|p|
|
2010-01-26 13:53:02 -07:00
|
|
|
FUCOMI F0, F1 // compare F0 to F1
|
2010-02-09 14:33:12 -07:00
|
|
|
JCC 2(PC) // jump if F0 >= F1
|
2012-09-20 22:35:56 -06:00
|
|
|
FXCHD F0, F1 // F0=|p| (larger), F1=|q| (smaller)
|
2010-01-26 13:53:02 -07:00
|
|
|
FTST // compare F0 to 0
|
|
|
|
FSTSW AX
|
|
|
|
ANDW $0x4000, AX
|
2010-02-01 23:21:40 -07:00
|
|
|
JNE 10(PC) // jump if F0 = 0
|
2012-09-20 22:35:56 -06:00
|
|
|
FXCHD F0, F1 // F0=q (smaller), F1=p (larger)
|
|
|
|
FDIVD F1, F0 // F0=q(=q/p), F1=p
|
|
|
|
FMULD F0, F0 // F0=q*q, F1=p
|
|
|
|
FLD1 // F0=1, F1=q*q, F2=p
|
|
|
|
FADDDP F0, F1 // F0=1+q*q, F1=p
|
|
|
|
FSQRT // F0=sqrt(1+q*q), F1=p
|
|
|
|
FMULDP F0, F1 // F0=p*sqrt(1+q*q)
|
2013-03-22 10:57:55 -06:00
|
|
|
FMOVDP F0, ret+16(FP)
|
2010-01-26 13:53:02 -07:00
|
|
|
RET
|
|
|
|
FMOVDP F0, F1 // F0=0
|
2013-03-22 10:57:55 -06:00
|
|
|
FMOVDP F0, ret+16(FP)
|
2010-01-26 13:53:02 -07:00
|
|
|
RET
|
|
|
|
not_finite:
|
|
|
|
// test bits for -Inf or +Inf
|
2013-03-22 10:57:55 -06:00
|
|
|
MOVL p_hi+4(FP), AX // high word p
|
|
|
|
ORL p_lo+0(FP), AX // low word p
|
2010-01-26 13:53:02 -07:00
|
|
|
ANDL $0x7fffffff, AX
|
|
|
|
CMPL AX, $0x7ff00000
|
|
|
|
JEQ is_inf
|
2013-03-22 10:57:55 -06:00
|
|
|
MOVL q_hi+12(FP), AX // high word q
|
|
|
|
ORL q_lo+8(FP), AX // low word q
|
2010-01-26 13:53:02 -07:00
|
|
|
ANDL $0x7fffffff, AX
|
|
|
|
CMPL AX, $0x7ff00000
|
|
|
|
JEQ is_inf
|
2013-03-22 10:57:55 -06:00
|
|
|
MOVL $0x7ff80000, ret_hi+20(FP) // return NaN = 0x7FF8000000000001
|
|
|
|
MOVL $0x00000001, ret_lo+16(FP)
|
2010-01-26 13:53:02 -07:00
|
|
|
RET
|
|
|
|
is_inf:
|
2013-03-22 10:57:55 -06:00
|
|
|
MOVL AX, ret_hi+20(FP) // return +Inf = 0x7FF0000000000000
|
|
|
|
MOVL $0x00000000, ret_lo+16(FP)
|
2010-01-26 13:53:02 -07:00
|
|
|
RET
|