2010-05-18 23:33:50 -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
|
|
|
|
2011-12-07 12:52:17 -07:00
|
|
|
#define PosInf 0x7FF0000000000000
|
2012-08-08 17:40:05 -06:00
|
|
|
#define NaN 0x7FF8000000000001
|
2011-12-07 12:52:17 -07:00
|
|
|
#define NegInf 0xFFF0000000000000
|
|
|
|
|
2011-09-29 10:54:20 -06:00
|
|
|
// func Dim(x, y float64) float64
|
2013-08-12 11:25:18 -06:00
|
|
|
TEXT ·Dim(SB),NOSPLIT,$0
|
2011-12-07 12:52:17 -07:00
|
|
|
// (+Inf, +Inf) special case
|
|
|
|
MOVQ x+0(FP), BX
|
|
|
|
MOVQ y+8(FP), CX
|
|
|
|
MOVQ $PosInf, AX
|
|
|
|
CMPQ AX, BX
|
|
|
|
JNE dim2
|
|
|
|
CMPQ AX, CX
|
|
|
|
JEQ bothInf
|
|
|
|
dim2: // (-Inf, -Inf) special case
|
|
|
|
MOVQ $NegInf, AX
|
|
|
|
CMPQ AX, BX
|
|
|
|
JNE dim3
|
|
|
|
CMPQ AX, CX
|
|
|
|
JEQ bothInf
|
|
|
|
dim3: // (NaN, x) or (x, NaN)
|
|
|
|
MOVQ $~(1<<63), DX
|
2015-02-22 14:12:51 -07:00
|
|
|
MOVQ $PosInf, AX
|
2011-12-07 12:52:17 -07:00
|
|
|
ANDQ DX, BX // x = |x|
|
|
|
|
CMPQ AX, BX
|
2015-02-22 14:12:51 -07:00
|
|
|
JLT isDimNaN
|
2011-12-07 12:52:17 -07:00
|
|
|
ANDQ DX, CX // y = |y|
|
|
|
|
CMPQ AX, CX
|
2015-02-22 14:12:51 -07:00
|
|
|
JLT isDimNaN
|
2011-12-07 12:52:17 -07:00
|
|
|
|
2010-05-18 23:33:50 -06:00
|
|
|
MOVSD x+0(FP), X0
|
|
|
|
SUBSD y+8(FP), X0
|
|
|
|
MOVSD $(0.0), X1
|
|
|
|
MAXSD X1, X0
|
2013-03-22 10:57:55 -06:00
|
|
|
MOVSD X0, ret+16(FP)
|
2010-05-18 23:33:50 -06:00
|
|
|
RET
|
2011-12-07 12:52:17 -07:00
|
|
|
bothInf: // Dim(-Inf, -Inf) or Dim(+Inf, +Inf)
|
|
|
|
isDimNaN:
|
2015-02-22 14:12:51 -07:00
|
|
|
MOVQ $NaN, AX
|
2013-03-22 10:57:55 -06:00
|
|
|
MOVQ AX, ret+16(FP)
|
2011-12-07 12:52:17 -07:00
|
|
|
RET
|
2010-05-18 23:33:50 -06:00
|
|
|
|
2011-09-29 10:54:20 -06:00
|
|
|
// func ·Max(x, y float64) float64
|
2013-08-12 11:25:18 -06:00
|
|
|
TEXT ·Max(SB),NOSPLIT,$0
|
2011-12-07 12:52:17 -07:00
|
|
|
// +Inf special cases
|
|
|
|
MOVQ $PosInf, AX
|
|
|
|
MOVQ x+0(FP), R8
|
|
|
|
CMPQ AX, R8
|
|
|
|
JEQ isPosInf
|
|
|
|
MOVQ y+8(FP), R9
|
|
|
|
CMPQ AX, R9
|
|
|
|
JEQ isPosInf
|
|
|
|
// NaN special cases
|
|
|
|
MOVQ $~(1<<63), DX // bit mask
|
2015-02-22 14:12:51 -07:00
|
|
|
MOVQ $PosInf, AX
|
2011-12-07 12:52:17 -07:00
|
|
|
MOVQ R8, BX
|
|
|
|
ANDQ DX, BX // x = |x|
|
|
|
|
CMPQ AX, BX
|
2015-02-22 14:12:51 -07:00
|
|
|
JLT isMaxNaN
|
2011-12-07 12:52:17 -07:00
|
|
|
MOVQ R9, CX
|
|
|
|
ANDQ DX, CX // y = |y|
|
|
|
|
CMPQ AX, CX
|
2015-02-22 14:12:51 -07:00
|
|
|
JLT isMaxNaN
|
2011-12-07 12:52:17 -07:00
|
|
|
// ±0 special cases
|
|
|
|
ORQ CX, BX
|
|
|
|
JEQ isMaxZero
|
|
|
|
|
|
|
|
MOVQ R8, X0
|
|
|
|
MOVQ R9, X1
|
|
|
|
MAXSD X1, X0
|
2013-03-22 10:57:55 -06:00
|
|
|
MOVSD X0, ret+16(FP)
|
2011-12-07 12:52:17 -07:00
|
|
|
RET
|
|
|
|
isMaxNaN: // return NaN
|
2015-02-22 14:12:51 -07:00
|
|
|
MOVQ $NaN, AX
|
2011-12-07 12:52:17 -07:00
|
|
|
isPosInf: // return +Inf
|
2013-03-22 10:57:55 -06:00
|
|
|
MOVQ AX, ret+16(FP)
|
2011-12-07 12:52:17 -07:00
|
|
|
RET
|
|
|
|
isMaxZero:
|
|
|
|
MOVQ $(1<<63), AX // -0.0
|
|
|
|
CMPQ AX, R8
|
|
|
|
JEQ +3(PC)
|
2013-03-22 10:57:55 -06:00
|
|
|
MOVQ R8, ret+16(FP) // return 0
|
2011-12-07 12:52:17 -07:00
|
|
|
RET
|
2013-03-22 10:57:55 -06:00
|
|
|
MOVQ R9, ret+16(FP) // return other 0
|
2010-05-18 23:33:50 -06:00
|
|
|
RET
|
|
|
|
|
2011-09-29 10:54:20 -06:00
|
|
|
// func Min(x, y float64) float64
|
2013-08-12 11:25:18 -06:00
|
|
|
TEXT ·Min(SB),NOSPLIT,$0
|
2011-12-07 12:52:17 -07:00
|
|
|
// -Inf special cases
|
|
|
|
MOVQ $NegInf, AX
|
|
|
|
MOVQ x+0(FP), R8
|
|
|
|
CMPQ AX, R8
|
|
|
|
JEQ isNegInf
|
|
|
|
MOVQ y+8(FP), R9
|
|
|
|
CMPQ AX, R9
|
|
|
|
JEQ isNegInf
|
|
|
|
// NaN special cases
|
|
|
|
MOVQ $~(1<<63), DX
|
2015-02-22 14:12:51 -07:00
|
|
|
MOVQ $PosInf, AX
|
2011-12-07 12:52:17 -07:00
|
|
|
MOVQ R8, BX
|
|
|
|
ANDQ DX, BX // x = |x|
|
|
|
|
CMPQ AX, BX
|
2015-02-22 14:12:51 -07:00
|
|
|
JLT isMinNaN
|
2011-12-07 12:52:17 -07:00
|
|
|
MOVQ R9, CX
|
|
|
|
ANDQ DX, CX // y = |y|
|
|
|
|
CMPQ AX, CX
|
2015-02-22 14:12:51 -07:00
|
|
|
JLT isMinNaN
|
2011-12-07 12:52:17 -07:00
|
|
|
// ±0 special cases
|
|
|
|
ORQ CX, BX
|
|
|
|
JEQ isMinZero
|
|
|
|
|
|
|
|
MOVQ R8, X0
|
|
|
|
MOVQ R9, X1
|
|
|
|
MINSD X1, X0
|
2013-03-22 10:57:55 -06:00
|
|
|
MOVSD X0, ret+16(FP)
|
2010-05-18 23:33:50 -06:00
|
|
|
RET
|
2011-12-07 12:52:17 -07:00
|
|
|
isMinNaN: // return NaN
|
2015-02-22 14:12:51 -07:00
|
|
|
MOVQ $NaN, AX
|
2011-12-07 12:52:17 -07:00
|
|
|
isNegInf: // return -Inf
|
2013-03-22 10:57:55 -06:00
|
|
|
MOVQ AX, ret+16(FP)
|
2011-12-07 12:52:17 -07:00
|
|
|
RET
|
|
|
|
isMinZero:
|
|
|
|
MOVQ $(1<<63), AX // -0.0
|
|
|
|
CMPQ AX, R8
|
|
|
|
JEQ +3(PC)
|
2013-03-22 10:57:55 -06:00
|
|
|
MOVQ R9, ret+16(FP) // return other 0
|
2011-12-07 12:52:17 -07:00
|
|
|
RET
|
2013-03-22 10:57:55 -06:00
|
|
|
MOVQ R8, ret+16(FP) // return -0
|
2011-12-07 12:52:17 -07:00
|
|
|
RET
|
|
|
|
|