2010-08-06 17:50:48 -06: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.
|
|
|
|
|
2014-08-12 18:04:45 -06:00
|
|
|
#include "textflag.h"
|
2013-08-12 11:25:18 -06:00
|
|
|
|
2012-08-08 17:40:05 -06:00
|
|
|
#define PosInf 0x7FF0000000000000
|
|
|
|
#define NaN 0x7FF8000000000001
|
2010-08-06 17:50:48 -06:00
|
|
|
|
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-08-06 17:50:48 -06:00
|
|
|
// test bits for special cases
|
2012-09-20 22:35:56 -06:00
|
|
|
MOVQ p+0(FP), BX
|
2010-08-06 17:50:48 -06:00
|
|
|
MOVQ $~(1<<63), AX
|
2012-09-20 22:35:56 -06:00
|
|
|
ANDQ AX, BX // p = |p|
|
|
|
|
MOVQ q+8(FP), CX
|
|
|
|
ANDQ AX, CX // q = |q|
|
2010-08-06 17:50:48 -06:00
|
|
|
MOVQ $PosInf, AX
|
|
|
|
CMPQ AX, BX
|
|
|
|
JLE isInfOrNaN
|
|
|
|
CMPQ AX, CX
|
|
|
|
JLE isInfOrNaN
|
|
|
|
// hypot = max * sqrt(1 + (min/max)**2)
|
|
|
|
MOVQ BX, X0
|
|
|
|
MOVQ CX, X1
|
|
|
|
ORQ CX, BX
|
|
|
|
JEQ isZero
|
|
|
|
MOVAPD X0, X2
|
|
|
|
MAXSD X1, X0
|
|
|
|
MINSD X2, X1
|
|
|
|
DIVSD X0, X1
|
|
|
|
MULSD X1, X1
|
|
|
|
ADDSD $1.0, X1
|
|
|
|
SQRTSD X1, X1
|
|
|
|
MULSD X1, X0
|
2013-03-22 10:57:55 -06:00
|
|
|
MOVSD X0, ret+16(FP)
|
2010-08-06 17:50:48 -06:00
|
|
|
RET
|
|
|
|
isInfOrNaN:
|
|
|
|
CMPQ AX, BX
|
|
|
|
JEQ isInf
|
|
|
|
CMPQ AX, CX
|
|
|
|
JEQ isInf
|
|
|
|
MOVQ $NaN, AX
|
2013-03-22 10:57:55 -06:00
|
|
|
MOVQ AX, ret+16(FP) // return NaN
|
2010-08-06 17:50:48 -06:00
|
|
|
RET
|
|
|
|
isInf:
|
2013-03-22 10:57:55 -06:00
|
|
|
MOVQ AX, ret+16(FP) // return +Inf
|
2010-08-06 17:50:48 -06:00
|
|
|
RET
|
|
|
|
isZero:
|
|
|
|
MOVQ $0, AX
|
2013-03-22 10:57:55 -06:00
|
|
|
MOVQ AX, ret+16(FP) // return 0
|
2010-08-06 17:50:48 -06:00
|
|
|
RET
|