]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/ia64/fpu/s_ceil.S
(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[thirdparty/glibc.git] / sysdeps / ia64 / fpu / s_ceil.S
1 .file "ceil.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
41 #include "libm_support.h"
42
43 .align 32
44 .global ceil#
45
46 .section .text
47 .proc ceil#
48 .align 32
49
50 // History
51 //==============================================================
52 // 2/02/00: Initial version
53 // 6/13/00: Improved speed
54 // 6/27/00: Eliminated incorrect invalid flag setting
55
56 // API
57 //==============================================================
58 // double ceil(double x)
59
60 // general input registers:
61
62 ceil_GR_FFFF = r14
63 ceil_GR_signexp = r15
64 ceil_GR_exponent = r16
65 ceil_GR_expmask = r17
66 ceil_GR_bigexp = r18
67
68
69 // predicate registers used:
70
71 // p6 ==> Input is NaN, infinity, zero
72 // p7 ==> Input is denormal
73 // p8 ==> Input is <0
74 // p9 ==> Input is >=0
75 // p10 ==> Input is already an integer (bigger than largest integer)
76 // p11 ==> Input is not a large integer
77 // p12 ==> Input is a smaller integer
78 // p13 ==> Input is not an even integer, so inexact must be set
79 // p14 ==> Input is between -1 and 0, so result will be -0 and inexact
80
81
82 // floating-point registers used:
83
84 CEIL_SIGNED_ZERO = f7
85 CEIL_NORM_f8 = f9
86 CEIL_FFFF = f10
87 CEIL_INEXACT = f11
88 CEIL_FLOAT_INT_f8 = f12
89 CEIL_INT_f8 = f13
90 CEIL_adj = f14
91 CEIL_MINUS_ONE = f15
92
93 // Overview of operation
94 //==============================================================
95
96 // double ceil(double x)
97 // Return an integer value (represented as a double) that is the smallest
98 // value not less than x
99 // This is x rounded toward +infinity to an integral value.
100 // Inexact is set if x != ceil(x)
101 // **************************************************************************
102
103 // Set denormal flag for denormal input and
104 // and take denormal fault if necessary.
105
106 // Is the input an integer value already?
107
108 // double_extended
109 // if the exponent is > 1003e => 3F(true) = 63(decimal)
110 // we have a significand of 64 bits 1.63-bits.
111 // If we multiply by 2^63, we no longer have a fractional part
112 // So input is an integer value already.
113
114 // double
115 // if the exponent is >= 10033 => 34(true) = 52(decimal)
116 // 34 + 3ff = 433
117 // we have a significand of 53 bits 1.52-bits. (implicit 1)
118 // If we multiply by 2^52, we no longer have a fractional part
119 // So input is an integer value already.
120
121 // single
122 // if the exponent is > 10016 => 17(true) = 23(decimal)
123 // we have a significand of 24 bits 1.23-bits. (implicit 1)
124 // If we multiply by 2^23, we no longer have a fractional part
125 // So input is an integer value already.
126
127 // If x is NAN, ZERO, or INFINITY, then return
128
129 // qnan snan inf norm unorm 0 -+
130 // 1 1 1 0 0 1 11 0xe7
131
132
133 ceil:
134
135 { .mfi
136 getf.exp ceil_GR_signexp = f8
137 fcvt.fx.trunc.s1 CEIL_INT_f8 = f8
138 addl ceil_GR_bigexp = 0x10033, r0
139 }
140 { .mfi
141 addl ceil_GR_FFFF = -1,r0
142 fcmp.lt.s1 p8,p9 = f8,f0
143 mov ceil_GR_expmask = 0x1FFFF ;;
144 }
145
146 // p7 ==> denorm
147 { .mfi
148 setf.sig CEIL_FFFF = ceil_GR_FFFF
149 fclass.m p7,p0 = f8, 0x0b
150 nop.i 999
151 }
152 { .mfi
153 nop.m 999
154 fnorm CEIL_NORM_f8 = f8
155 nop.i 999 ;;
156 }
157
158 // Form 0 with sign of input in case negative zero is needed
159 { .mfi
160 nop.m 999
161 fmerge.s CEIL_SIGNED_ZERO = f8, f0
162 nop.i 999
163 }
164 { .mfi
165 nop.m 999
166 fsub.s1 CEIL_MINUS_ONE = f0, f1
167 nop.i 999 ;;
168 }
169
170 // p6 ==> NAN, INF, ZERO
171 { .mfb
172 nop.m 999
173 fclass.m p6,p10 = f8, 0xe7
174 (p7) br.cond.spnt L(CEIL_DENORM) ;;
175 }
176
177 L(CEIL_COMMON):
178 .pred.rel "mutex",p8,p9
179 // Set adjustment to add to trunc(x) for result
180 // If x>0, adjustment is 1.0
181 // If x<=0, adjustment is 0.0
182 { .mfi
183 and ceil_GR_exponent = ceil_GR_signexp, ceil_GR_expmask
184 (p9) fadd.s1 CEIL_adj = f1,f0
185 nop.i 999
186 }
187 { .mfi
188 nop.m 999
189 (p8) fadd.s1 CEIL_adj = f0,f0
190 nop.i 999 ;;
191 }
192
193 { .mfi
194 (p10) cmp.ge.unc p10,p11 = ceil_GR_exponent, ceil_GR_bigexp
195 (p6) fnorm.d f8 = f8
196 nop.i 999 ;;
197 }
198
199 { .mfi
200 nop.m 999
201 (p11) fcvt.xf CEIL_FLOAT_INT_f8 = CEIL_INT_f8
202 nop.i 999 ;;
203 }
204
205 { .mfi
206 nop.m 999
207 (p10) fnorm.d f8 = CEIL_NORM_f8
208 nop.i 999 ;;
209 }
210
211 // Is -1 < x < 0? If so, result will be -0. Special case it with p14 set.
212 { .mfi
213 nop.m 999
214 (p8) fcmp.gt.unc.s1 p14,p0 = CEIL_NORM_f8, CEIL_MINUS_ONE
215 nop.i 999 ;;
216 }
217
218 { .mfi
219 (p14) cmp.ne p11,p0 = r0,r0
220 (p14) fnorm.d f8 = CEIL_SIGNED_ZERO
221 nop.i 999
222 }
223 { .mfi
224 nop.m 999
225 (p14) fmpy.s0 CEIL_INEXACT = CEIL_FFFF,CEIL_FFFF
226 nop.i 999 ;;
227 }
228
229 { .mfi
230 nop.m 999
231 (p11) fadd.d f8 = CEIL_FLOAT_INT_f8,CEIL_adj
232 nop.i 999 ;;
233 }
234 { .mfi
235 nop.m 999
236 (p11) fcmp.eq.unc.s1 p12,p13 = CEIL_FLOAT_INT_f8, CEIL_NORM_f8
237 nop.i 999 ;;
238 }
239
240 // Set inexact if result not equal to input
241 { .mfi
242 nop.m 999
243 (p13) fmpy.s0 CEIL_INEXACT = CEIL_FFFF,CEIL_FFFF
244 nop.i 999
245 }
246 // Set result to input if integer
247 { .mfb
248 nop.m 999
249 (p12) fnorm.d f8 = CEIL_NORM_f8
250 br.ret.sptk b0 ;;
251 }
252
253 // Here if input denorm
254 L(CEIL_DENORM):
255 { .mfb
256 getf.exp ceil_GR_signexp = CEIL_NORM_f8
257 fcvt.fx.trunc.s1 CEIL_INT_f8 = CEIL_NORM_f8
258 br.cond.sptk L(CEIL_COMMON) ;;
259 }
260
261 .endp ceil
262 ASM_SIZE_DIRECTIVE(ceil)