#include "../../cmd/ld/textflag.h"
#define PosInf 0x7FF0000000000000
#define NaN 0x7FF8000000000001
#define NegInf 0xFFF0000000000000
TEXT ·Dim(SB),NOSPLIT,$0
MOVQ x+0(FP), BX
MOVQ y+8(FP), CX
MOVQ $PosInf, AX
CMPQ AX, BX
JNE dim2
CMPQ AX, CX
JEQ bothInf
dim2:
MOVQ $NegInf, AX
CMPQ AX, BX
JNE dim3
CMPQ AX, CX
JEQ bothInf
dim3:
MOVQ $~(1<<63), DX
MOVQ $NaN, AX
ANDQ DX, BX
CMPQ AX, BX
JLE isDimNaN
ANDQ DX, CX
CMPQ AX, CX
JLE isDimNaN
MOVSD x+0(FP), X0
SUBSD y+8(FP), X0
MOVSD $(0.0), X1
MAXSD X1, X0
MOVSD X0, ret+16(FP)
RET
bothInf:
MOVQ $NaN, AX
isDimNaN:
MOVQ AX, ret+16(FP)
RET
TEXT ·Max(SB),NOSPLIT,$0
MOVQ $PosInf, AX
MOVQ x+0(FP), R8
CMPQ AX, R8
JEQ isPosInf
MOVQ y+8(FP), R9
CMPQ AX, R9
JEQ isPosInf
MOVQ $~(1<<63), DX
MOVQ $NaN, AX
MOVQ R8, BX
ANDQ DX, BX
CMPQ AX, BX
JLE isMaxNaN
MOVQ R9, CX
ANDQ DX, CX
CMPQ AX, CX
JLE isMaxNaN
ORQ CX, BX
JEQ isMaxZero
MOVQ R8, X0
MOVQ R9, X1
MAXSD X1, X0
MOVSD X0, ret+16(FP)
RET
isMaxNaN:
isPosInf:
MOVQ AX, ret+16(FP)
RET
isMaxZero:
MOVQ $(1<<63), AX
CMPQ AX, R8
JEQ +3(PC)
MOVQ R8, ret+16(FP)
RET
MOVQ R9, ret+16(FP)
RET
TEXT ·Min(SB),NOSPLIT,$0
MOVQ $NegInf, AX
MOVQ x+0(FP), R8
CMPQ AX, R8
JEQ isNegInf
MOVQ y+8(FP), R9
CMPQ AX, R9
JEQ isNegInf
MOVQ $~(1<<63), DX
MOVQ $NaN, AX
MOVQ R8, BX
ANDQ DX, BX
CMPQ AX, BX
JLE isMinNaN
MOVQ R9, CX
ANDQ DX, CX
CMPQ AX, CX
JLE isMinNaN
ORQ CX, BX
JEQ isMinZero
MOVQ R8, X0
MOVQ R9, X1
MINSD X1, X0
MOVSD X0, ret+16(FP)
RET
isMinNaN:
isNegInf:
MOVQ AX, ret+16(FP)
RET
isMinZero:
MOVQ $(1<<63), AX
CMPQ AX, R8
JEQ +3(PC)
MOVQ R9, ret+16(FP)
RET
MOVQ R8, ret+16(FP)
RET