Commit | Line | Data |
---|---|---|
e0a11985 KB |
1 | /*- |
2 | * Copyright (c) 1990 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * This code is derived from software contributed to Berkeley by | |
6 | * the Systems Programming Group of the University of Utah Computer | |
7 | * Science Department. | |
8 | * | |
9 | * %sccs.include.redist.c% | |
10 | * | |
11 | * @(#)floor.s 5.1 (Berkeley) %G% | |
12 | */ | |
13 | ||
14 | .text | |
15 | .globl _floor,_ceil,_rint | |
16 | ||
17 | | floor(x) | |
18 | | the largest integer no larger than x | |
19 | _floor: | |
20 | fmovel fpcr,d0 | save old FPCR | |
21 | fmoved sp@(4),fp0 | get argument | |
22 | fbun Lret | if NaN, return NaN | |
23 | fboge Lrtz | >=0, round to zero | |
24 | fmovel #0x20,fpcr | <0, round to -inf | |
25 | jra Ldoit | |
26 | ||
27 | | ceil(x) | |
28 | | -floor(-x), for all real x | |
29 | _ceil: | |
30 | fmovel fpcr,d0 | save old FPCR | |
31 | fmoved sp@(4),fp0 | get argument | |
32 | fbun Lret | if NaN, return NaN | |
33 | fbolt Lrtz | <0, round to zero | |
34 | fmovel #0x30,fpcr | >=0, round to inf | |
35 | jra Ldoit | |
36 | ||
37 | Lrtz: | |
38 | fmovel #0x10,fpcr | |
39 | Ldoit: | |
40 | fintd sp@(4),fp0 | truncate | |
41 | fmovel d0,fpcr | restore old FPCR | |
42 | Lret: | |
43 | fmoved fp0,sp@- | |
44 | movel sp@+,d0 | |
45 | movel sp@+,d1 | |
46 | rts | |
47 | ||
48 | | rint(x) | |
49 | | delivers integer nearest x in direction of prevailing rounding mode | |
50 | _rint: | |
51 | fintd sp@(4),fp0 | use prevailing rounding mode | |
52 | jra Lret |