blob: 31c9b174d6ef06418499689383b8446f897bcd3c [file] [log] [blame]
Charles L. Dorian7f11db52010-01-15 13:21:36 -08001// 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. Dorian7f11db52010-01-15 13:21:36 -08007// func Ceil(x float64) float64
Keith Randall1f796632013-08-12 10:25:18 -07008TEXT ·Ceil(SB),NOSPLIT,$0
Charles L. Dorian7f11db52010-01-15 13:21:36 -08009 FMOVD x+0(FP), F0 // F0=x
10 FSTCW -2(SP) // save old Control Word
11 MOVW -2(SP), AX
12 ANDW $0xf3ff, AX
Charles L. Doriana0690b62010-02-01 22:21:40 -080013 ORW $0x0800, AX // Rounding Control set to +Inf
Charles L. Dorian7f11db52010-01-15 13:21:36 -080014 MOVW AX, -4(SP) // store new Control Word
15 FLDCW -4(SP) // load new Control Word
16 FRNDINT // F0=Ceil(x)
17 FLDCW -2(SP) // load old Control Word
Russ Cox07720b62013-03-22 12:57:55 -040018 FMOVDP F0, ret+8(FP)
Charles L. Dorian7f11db52010-01-15 13:21:36 -080019 RET
20
21// func Floor(x float64) float64
Keith Randall1f796632013-08-12 10:25:18 -070022TEXT ·Floor(SB),NOSPLIT,$0
Charles L. Dorian7f11db52010-01-15 13:21:36 -080023 FMOVD x+0(FP), F0 // F0=x
24 FSTCW -2(SP) // save old Control Word
25 MOVW -2(SP), AX
26 ANDW $0xf3ff, AX
Charles L. Doriana0690b62010-02-01 22:21:40 -080027 ORW $0x0400, AX // Rounding Control set to -Inf
Charles L. Dorian7f11db52010-01-15 13:21:36 -080028 MOVW AX, -4(SP) // store new Control Word
29 FLDCW -4(SP) // load new Control Word
Charles L. Doriana0690b62010-02-01 22:21:40 -080030 FRNDINT // F0=Floor(x)
31 FLDCW -2(SP) // load old Control Word
Russ Cox07720b62013-03-22 12:57:55 -040032 FMOVDP F0, ret+8(FP)
Charles L. Doriana0690b62010-02-01 22:21:40 -080033 RET
34
35// func Trunc(x float64) float64
Keith Randall1f796632013-08-12 10:25:18 -070036TEXT ·Trunc(SB),NOSPLIT,$0
Charles L. Doriana0690b62010-02-01 22:21:40 -080037 FMOVD x+0(FP), F0 // F0=x
38 FSTCW -2(SP) // save old Control Word
39 MOVW -2(SP), AX
40 ORW $0x0c00, AX // Rounding Control set to truncate
41 MOVW AX, -4(SP) // store new Control Word
42 FLDCW -4(SP) // load new Control Word
43 FRNDINT // F0=Trunc(x)
Charles L. Dorian7f11db52010-01-15 13:21:36 -080044 FLDCW -2(SP) // load old Control Word
Russ Cox07720b62013-03-22 12:57:55 -040045 FMOVDP F0, ret+8(FP)
Charles L. Dorian7f11db52010-01-15 13:21:36 -080046 RET