#include "../../cmd/ld/textflag.h"
#define Big 0x4330000000000000
TEXT ·Floor(SB),NOSPLIT,$0
MOVQ x+0(FP), AX
MOVQ $~(1<<63), DX
ANDQ AX,DX
SUBQ $1,DX
MOVQ $(Big - 1), CX
CMPQ DX,CX
JAE isBig_floor
MOVQ AX, X0
CVTTSD2SQ X0, AX
CVTSQ2SD AX, X1
CMPSD X1, X0, 1
MOVSD $(-1.0), X2
ANDPD X2, X0
ADDSD X1, X0
MOVSD X0, ret+8(FP)
RET
isBig_floor:
MOVQ AX, ret+8(FP)
RET
TEXT ·Ceil(SB),NOSPLIT,$0
MOVQ x+0(FP), AX
MOVQ $~(1<<63), DX
MOVQ AX, BX
ANDQ DX, BX
MOVQ $Big, CX
CMPQ BX, CX
JAE isBig_ceil
MOVQ AX, X0
MOVQ DX, X2
CVTTSD2SQ X0, AX
ANDNPD X0, X2
CVTSQ2SD AX, X1
CMPSD X1, X0, 2
ORPD X2, X1
MOVSD $1.0, X3
ANDNPD X3, X0
ORPD X2, X0
ADDSD X1, X0
MOVSD X0, ret+8(FP)
RET
isBig_ceil:
MOVQ AX, ret+8(FP)
RET
TEXT ·Trunc(SB),NOSPLIT,$0
MOVQ x+0(FP), AX
MOVQ $~(1<<63), DX
MOVQ AX, BX
ANDQ DX, BX
MOVQ $Big, CX
CMPQ BX, CX
JAE isBig_trunc
MOVQ AX, X0
MOVQ DX, X2
CVTTSD2SQ X0, AX
ANDNPD X0, X2
CVTSQ2SD AX, X0
ORPD X2, X0
MOVSD X0, ret+8(FP)
RET
isBig_trunc:
MOVQ AX, ret+8(FP)
RET