Charles L. Dorian | 7f11db5 | 2010-01-15 13:21:36 -0800 | [diff] [blame] | 1 | // 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 Pike | 8bca148 | 2014-08-12 17:04:45 -0700 | [diff] [blame] | 5 | #include "textflag.h" |
Keith Randall | 1f79663 | 2013-08-12 10:25:18 -0700 | [diff] [blame] | 6 | |
Charles L. Dorian | 7f11db5 | 2010-01-15 13:21:36 -0800 | [diff] [blame] | 7 | // func Ceil(x float64) float64 |
Keith Randall | 1f79663 | 2013-08-12 10:25:18 -0700 | [diff] [blame] | 8 | TEXT ·Ceil(SB),NOSPLIT,$0 |
Charles L. Dorian | 7f11db5 | 2010-01-15 13:21:36 -0800 | [diff] [blame] | 9 | 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. Dorian | a0690b6 | 2010-02-01 22:21:40 -0800 | [diff] [blame] | 13 | ORW $0x0800, AX // Rounding Control set to +Inf |
Charles L. Dorian | 7f11db5 | 2010-01-15 13:21:36 -0800 | [diff] [blame] | 14 | 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 Cox | 07720b6 | 2013-03-22 12:57:55 -0400 | [diff] [blame] | 18 | FMOVDP F0, ret+8(FP) |
Charles L. Dorian | 7f11db5 | 2010-01-15 13:21:36 -0800 | [diff] [blame] | 19 | RET |
| 20 | |
| 21 | // func Floor(x float64) float64 |
Keith Randall | 1f79663 | 2013-08-12 10:25:18 -0700 | [diff] [blame] | 22 | TEXT ·Floor(SB),NOSPLIT,$0 |
Charles L. Dorian | 7f11db5 | 2010-01-15 13:21:36 -0800 | [diff] [blame] | 23 | 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. Dorian | a0690b6 | 2010-02-01 22:21:40 -0800 | [diff] [blame] | 27 | ORW $0x0400, AX // Rounding Control set to -Inf |
Charles L. Dorian | 7f11db5 | 2010-01-15 13:21:36 -0800 | [diff] [blame] | 28 | MOVW AX, -4(SP) // store new Control Word |
| 29 | FLDCW -4(SP) // load new Control Word |
Charles L. Dorian | a0690b6 | 2010-02-01 22:21:40 -0800 | [diff] [blame] | 30 | FRNDINT // F0=Floor(x) |
| 31 | FLDCW -2(SP) // load old Control Word |
Russ Cox | 07720b6 | 2013-03-22 12:57:55 -0400 | [diff] [blame] | 32 | FMOVDP F0, ret+8(FP) |
Charles L. Dorian | a0690b6 | 2010-02-01 22:21:40 -0800 | [diff] [blame] | 33 | RET |
| 34 | |
| 35 | // func Trunc(x float64) float64 |
Keith Randall | 1f79663 | 2013-08-12 10:25:18 -0700 | [diff] [blame] | 36 | TEXT ·Trunc(SB),NOSPLIT,$0 |
Charles L. Dorian | a0690b6 | 2010-02-01 22:21:40 -0800 | [diff] [blame] | 37 | 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. Dorian | 7f11db5 | 2010-01-15 13:21:36 -0800 | [diff] [blame] | 44 | FLDCW -2(SP) // load old Control Word |
Russ Cox | 07720b6 | 2013-03-22 12:57:55 -0400 | [diff] [blame] | 45 | FMOVDP F0, ret+8(FP) |
Charles L. Dorian | 7f11db5 | 2010-01-15 13:21:36 -0800 | [diff] [blame] | 46 | RET |