]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/ia64/fpu/s_floor.S
(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[thirdparty/glibc.git] / sysdeps / ia64 / fpu / s_floor.S
1 .file "floor.s"
2
3 // Copyright (C) 2000, 2001, Intel Corporation
4 // All rights reserved.
5 //
6 // Contributed 2/2/2000 by John Harrison, Ted Kubaska, Bob Norin, Shane Story,
7 // and Ping Tak Peter Tang of the Computational Software Lab, Intel Corporation.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
11 // met:
12 //
13 // * Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
15 //
16 // * Redistributions in binary form must reproduce the above copyright
17 // notice, this list of conditions and the following disclaimer in the
18 // documentation and/or other materials provided with the distribution.
19 //
20 // * The name of Intel Corporation may not be used to endorse or promote
21 // products derived from this software without specific prior written
22 // permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
28 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
32 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
33 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
36 // Intel Corporation is the author of this code, and requests that all
37 // problem reports or change requests be submitted to it directly at
38 // http://developer.intel.com/opensource.
39 //
40 .align 32
41 .global floor#
42
43 .section .text
44 .proc floor#
45 .align 32
46
47 // History
48 //==============================================================
49 // 2/02/00: Initial version
50 // 3/22/00: Updated to improve performance
51 // 6/13/00: Improved speed, fixed setting of inexact flag
52 // 6/27/00: Eliminated incorrect invalid flag setting
53 // 2/07/01: Corrected sign of zero result in round to -inf mode
54
55 // API
56 //==============================================================
57 // double floor(double x)
58
59 // general input registers:
60
61 floor_GR_FFFF = r14
62 floor_GR_signexp = r15
63 floor_GR_exponent = r16
64 floor_GR_expmask = r17
65 floor_GR_bigexp = r18
66
67
68 // predicate registers used:
69
70 // p6 ==> Input is NaN, infinity, zero
71 // p7 ==> Input is denormal
72 // p8 ==> Input is <0
73 // p9 ==> Input is >=0
74 // p10 ==> Input is already an integer (bigger than largest integer)
75 // p11 ==> Input is not a large integer
76 // p12 ==> Input is a smaller integer
77 // p13 ==> Input is not an even integer, so inexact must be set
78
79
80 // floating-point registers used:
81
82 FLOOR_NORM_f8 = f9
83 FLOOR_FFFF = f10
84 FLOOR_INEXACT = f11
85 FLOOR_FLOAT_INT_f8 = f12
86 FLOOR_INT_f8 = f13
87 FLOOR_adj = f14
88
89 // Overview of operation
90 //==============================================================
91
92 // double floor(double x)
93 // Return an integer value (represented as a double) that is the largest
94 // value not greater than x
95 // This is x rounded toward -infinity to an integral value.
96 // Inexact is set if x != floor(x)
97 // **************************************************************************
98
99 // Set denormal flag for denormal input and
100 // and take denormal fault if necessary.
101
102 // Is the input an integer value already?
103
104 // double_extended
105 // if the exponent is > 1003e => 3F(true) = 63(decimal)
106 // we have a significand of 64 bits 1.63-bits.
107 // If we multiply by 2^63, we no longer have a fractional part
108 // So input is an integer value already.
109
110 // double
111 // if the exponent is >= 10033 => 34(true) = 52(decimal)
112 // 34 + 3ff = 433
113 // we have a significand of 53 bits 1.52-bits. (implicit 1)
114 // If we multiply by 2^52, we no longer have a fractional part
115 // So input is an integer value already.
116
117 // single
118 // if the exponent is > 10016 => 17(true) = 23(decimal)
119 // we have a significand of 24 bits 1.23-bits. (implicit 1)
120 // If we multiply by 2^23, we no longer have a fractional part
121 // So input is an integer value already.
122
123 // If x is NAN, ZERO, or INFINITY, then return
124
125 // qnan snan inf norm unorm 0 -+
126 // 1 1 1 0 0 1 11 0xe7
127
128 #include "libm_support.h"
129
130 floor:
131 #ifdef _LIBC
132 .global __floor
133 __floor:
134 #endif
135
136 { .mfi
137 getf.exp floor_GR_signexp = f8
138 fcvt.fx.trunc.s1 FLOOR_INT_f8 = f8
139 addl floor_GR_bigexp = 0x10033, r0
140 }
141 { .mfi
142 addl floor_GR_FFFF = -1,r0
143 fcmp.lt.s1 p8,p9 = f8,f0
144 mov floor_GR_expmask = 0x1FFFF ;;
145 }
146
147 // p7 ==> denorm
148 { .mfi
149 setf.sig FLOOR_FFFF = floor_GR_FFFF
150 fclass.m p7,p0 = f8, 0x0b
151 nop.i 999
152 }
153 { .mfi
154 nop.m 999
155 fnorm.s1 FLOOR_NORM_f8 = f8
156 nop.i 999 ;;
157 }
158
159 // p6 ==> NAN, INF, ZERO
160 { .mfb
161 nop.m 999
162 fclass.m p6,p10 = f8, 0xe7
163 (p7) br.cond.spnt L(FLOOR_DENORM) ;;
164 }
165
166 L(FLOOR_COMMON):
167 .pred.rel "mutex",p8,p9
168 // Set adjustment to subtract from trunc(x) for result
169 // If x<0, adjustment is -1.0
170 // If x>=0, adjustment is 0.0
171 { .mfi
172 and floor_GR_exponent = floor_GR_signexp, floor_GR_expmask
173 (p8) fnma.s1 FLOOR_adj = f1,f1,f0
174 nop.i 999
175 }
176 { .mfi
177 nop.m 999
178 (p9) fadd.s1 FLOOR_adj = f0,f0
179 nop.i 999 ;;
180 }
181
182 { .mfi
183 nop.m 999
184 fcmp.eq.s0 p12,p0 = f8,f0 // Dummy op to set denormal and invalid flag
185 nop.i 999
186 }
187 { .mfi
188 (p10) cmp.ge.unc p10,p11 = floor_GR_exponent, floor_GR_bigexp
189 (p6) fnorm.d f8 = f8
190 nop.i 999 ;;
191 }
192
193 { .mfi
194 nop.m 999
195 (p11) fcvt.xf FLOOR_FLOAT_INT_f8 = FLOOR_INT_f8
196 nop.i 999 ;;
197 }
198
199 { .mfi
200 nop.m 999
201 (p10) fnorm.d f8 = FLOOR_NORM_f8
202 nop.i 999 ;;
203 }
204
205
206 { .mfi
207 nop.m 999
208 (p11) fadd.d f8 = FLOOR_FLOAT_INT_f8,FLOOR_adj
209 nop.i 999 ;;
210 }
211
212 { .mfi
213 nop.m 999
214 (p11) fcmp.eq.unc.s1 p12,p13 = FLOOR_FLOAT_INT_f8, FLOOR_NORM_f8
215 nop.i 999 ;;
216 }
217
218 // Set inexact if result not equal to input
219 { .mfi
220 nop.m 999
221 (p13) fmpy.s0 FLOOR_INEXACT = FLOOR_FFFF,FLOOR_FFFF
222 nop.i 999
223 }
224 // Set result to input if integer
225 { .mfb
226 nop.m 999
227 (p12) fnorm.d f8 = FLOOR_NORM_f8
228 br.ret.sptk b0 ;;
229 }
230
231 // Here if input denorm
232 L(FLOOR_DENORM):
233 { .mfb
234 getf.exp floor_GR_signexp = FLOOR_NORM_f8
235 fcvt.fx.trunc.s1 FLOOR_INT_f8 = FLOOR_NORM_f8
236 br.cond.sptk L(FLOOR_COMMON) ;;
237 }
238
239 .endp floor
240 ASM_SIZE_DIRECTIVE(floor)