blob: a68eebc8ca619810107fac75a91c0afa89e89ebb [file] [log] [blame]
Charles L. Dorianc8c2bdb2010-08-06 16:50:48 -07001// 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
Rob Pike8bca1482014-08-12 17:04:45 -07005#include "textflag.h"
Keith Randall1f796632013-08-12 10:25:18 -07006
Charles L. Doriana5c4e0f2012-08-09 09:40:05 +10007#define PosInf 0x7FF0000000000000
8#define NaN 0x7FF8000000000001
Charles L. Dorianc8c2bdb2010-08-06 16:50:48 -07009
Russ Cox85729502012-09-21 00:35:56 -040010// func Hypot(p, q float64) float64
Keith Randall1f796632013-08-12 10:25:18 -070011TEXT ·Hypot(SB),NOSPLIT,$0
Charles L. Dorianc8c2bdb2010-08-06 16:50:48 -070012 // test bits for special cases
Russ Cox85729502012-09-21 00:35:56 -040013 MOVQ p+0(FP), BX
Charles L. Dorianc8c2bdb2010-08-06 16:50:48 -070014 MOVQ $~(1<<63), AX
Russ Cox85729502012-09-21 00:35:56 -040015 ANDQ AX, BX // p = |p|
16 MOVQ q+8(FP), CX
17 ANDQ AX, CX // q = |q|
Charles L. Dorianc8c2bdb2010-08-06 16:50:48 -070018 MOVQ $PosInf, AX
19 CMPQ AX, BX
20 JLE isInfOrNaN
21 CMPQ AX, CX
22 JLE isInfOrNaN
23 // hypot = max * sqrt(1 + (min/max)**2)
24 MOVQ BX, X0
25 MOVQ CX, X1
26 ORQ CX, BX
27 JEQ isZero
28 MOVAPD X0, X2
29 MAXSD X1, X0
30 MINSD X2, X1
31 DIVSD X0, X1
32 MULSD X1, X1
33 ADDSD $1.0, X1
34 SQRTSD X1, X1
35 MULSD X1, X0
Russ Cox07720b62013-03-22 12:57:55 -040036 MOVSD X0, ret+16(FP)
Charles L. Dorianc8c2bdb2010-08-06 16:50:48 -070037 RET
38isInfOrNaN:
39 CMPQ AX, BX
40 JEQ isInf
41 CMPQ AX, CX
42 JEQ isInf
43 MOVQ $NaN, AX
Russ Cox07720b62013-03-22 12:57:55 -040044 MOVQ AX, ret+16(FP) // return NaN
Charles L. Dorianc8c2bdb2010-08-06 16:50:48 -070045 RET
46isInf:
Russ Cox07720b62013-03-22 12:57:55 -040047 MOVQ AX, ret+16(FP) // return +Inf
Charles L. Dorianc8c2bdb2010-08-06 16:50:48 -070048 RET
49isZero:
50 MOVQ $0, AX
Russ Cox07720b62013-03-22 12:57:55 -040051 MOVQ AX, ret+16(FP) // return 0
Charles L. Dorianc8c2bdb2010-08-06 16:50:48 -070052 RET