]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/ia64/fpu/s_modfl.S
ia64: move from main tree
[thirdparty/glibc.git] / sysdeps / ia64 / fpu / s_modfl.S
1 .file "modfl.s"
2
3
4 // Copyright (c) 2000 - 2003, Intel Corporation
5 // All rights reserved.
6 //
7 // Contributed 2000 by the Intel Numerics Group, 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://www.intel.com/software/products/opensource/libraries/num.htm.
39 //
40 // History
41 //==============================================================
42 // 02/02/00 Initial version
43 // 04/04/00 Improved speed, corrected result for NaN input
44 // 05/30/00 Fixed bug for exponent 0x1003e
45 // 12/22/00 Fixed so inexact flag is never set, and invalid is not set for
46 // qnans nor for inputs larger than 2^63.
47 // 05/20/02 Cleaned up namespace and sf0 syntax
48 // 02/10/03 Reordered header: .section, .global, .proc, .align
49 //
50 // API
51 //==============================================================
52 // long double modfl(long double x, long double *iptr)
53 // break a floating point x number into fraction and an exponent
54 //
55 // input floating point f8, address in r34
56 // output floating point f8 (x fraction), and *iptr (x integral part)
57 //
58 // OVERVIEW
59 //==============================================================
60 //
61 // NO FRACTIONAL PART: HUGE
62 // If
63 // for double-extended
64 // If the true exponent is >= 63
65 // 1003e ==> 1003e -ffff = 3f = 63(dec)
66 // then
67 // we are already an integer (p9 true)
68
69 // NO INTEGER PART: SMALL
70 // Is f8 exponent less than register bias (that is, is it
71 // less than 1). If it is, get the right sign of
72 // zero and store this in iptr.
73
74 // CALCULATION: NOT HUGE, NOT SMALL
75 // To get the integer part
76 // Take the floating-point input and truncate
77 // then convert this integer to fp Call it MODF_INTEGER_PART
78
79 // Subtract MODF_INTEGER_PART from MODF_NORM_F8 to get fraction part
80 // Then put fraction part in f8
81 // put integer part MODF_INTEGER_PART into *iptr
82
83 // Registers used
84 //==============================================================
85
86 // predicate registers used:
87 // p6 - p13
88
89 // 0xFFFF 0x1003e
90 // -----------------------+-----------------+-------------
91 // SMALL | NORMAL | HUGE
92 // p11 --------------->|<----- p12 ----->| <-------------- p9
93 // p10 --------------------------------->|
94 // p13 --------------------------------------------------->|
95 //
96
97 // floating-point registers used:
98 MODF_NORM_F8 = f9
99 MODF_FRACTION_PART = f10
100 MODF_INTEGER_PART = f11
101 MODF_INT_INTEGER_PART = f12
102
103
104 // general registers used
105 modf_signexp = r14
106 modf_GR_no_frac = r15
107 modf_GR_FFFF = r16
108 modf_17_ones = r17
109 modf_exp = r18
110 // r34 = iptr
111
112
113 .section .text
114 GLOBAL_LIBM_ENTRY(modfl)
115
116 // Main path is p9, p11, p8 FALSE and p12 TRUE
117
118 // Assume input is normalized and get signexp
119 // Normalize input just in case
120 // Form exponent bias
121 { .mfi
122 getf.exp modf_signexp = f8
123 fnorm.s0 MODF_NORM_F8 = f8
124 addl modf_GR_FFFF = 0xffff, r0
125 }
126 // Get integer part of input
127 // Form exponent mask
128 { .mfi
129 nop.m 999
130 fcvt.fx.trunc.s1 MODF_INT_INTEGER_PART = f8
131 mov modf_17_ones = 0x1ffff ;;
132 }
133
134 // Is x nan or inf?
135 // qnan snan inf norm unorm 0 -+
136 // 1 1 1 0 0 0 11 = 0xe3 NAN_INF
137 // Form biased exponent where input only has an integer part
138 { .mfi
139 nop.m 999
140 fclass.m.unc p6,p13 = f8, 0xe3
141 addl modf_GR_no_frac = 0x1003e, r0 ;;
142 }
143
144 // Mask to get exponent
145 // Is x unnorm?
146 // qnan snan inf norm unorm 0 -+
147 // 0 0 0 0 1 0 11 = 0x0b UNORM
148 // Set p13 to indicate calculation path, else p6 if nan or inf
149 { .mfi
150 and modf_exp = modf_17_ones, modf_signexp
151 fclass.m.unc p8,p0 = f8, 0x0b
152 nop.i 999 ;;
153 }
154
155 // p11 <== SMALL, no integer part, fraction is everyting
156 // p9 <== HUGE, no fraction part, integer is everything
157 // p12 <== NORMAL, fraction part and integer part
158 { .mii
159 (p13) cmp.lt.unc p11,p10 = modf_exp, modf_GR_FFFF
160 nop.i 999
161 nop.i 999 ;;
162 }
163
164 // Is x inf? p6 if inf, p7 if nan
165 { .mfb
166 (p10) cmp.ge.unc p9,p12 = modf_exp, modf_GR_no_frac
167 (p6) fclass.m.unc p6,p7 = f8, 0x23
168 (p8) br.cond.spnt MODF_DENORM ;;
169 }
170
171 MODF_COMMON:
172 // For HUGE set fraction to signed 0
173 { .mfi
174 nop.m 999
175 (p9) fmerge.s f8 = f8,f0
176 nop.i 999
177 }
178 // For HUGE set integer part to normalized input
179 { .mfi
180 nop.m 999
181 (p9) fnorm.s0 MODF_INTEGER_PART = MODF_NORM_F8
182 nop.i 999 ;;
183 }
184
185 // For SMALL set fraction to normalized input, integer part to signed 0
186 { .mfi
187 nop.m 999
188 (p11) fmerge.s MODF_INTEGER_PART = f8,f0
189 nop.i 999
190 }
191 { .mfi
192 nop.m 999
193 (p11) fnorm.s0 f8 = MODF_NORM_F8
194 nop.i 999 ;;
195 }
196
197 // For NORMAL float the integer part
198 { .mfi
199 nop.m 999
200 (p12) fcvt.xf MODF_INTEGER_PART = MODF_INT_INTEGER_PART
201 nop.i 999 ;;
202 }
203
204 // If x inf set integer part to INF, fraction to signed 0
205 { .mfi
206 (p6) stfe [r34] = MODF_NORM_F8
207 (p6) fmerge.s f8 = f8,f0
208 nop.i 999 ;;
209 }
210
211 // If x nan set integer and fraction parts to NaN (quietized)
212 { .mfi
213 (p7) stfe [r34] = MODF_NORM_F8
214 (p7) fmerge.s f8 = MODF_NORM_F8, MODF_NORM_F8
215 nop.i 999 ;;
216 }
217
218 { .mmi
219 (p9) stfe [r34] = MODF_INTEGER_PART
220 nop.m 999
221 nop.i 999 ;;
222 }
223
224 // For NORMAL compute fraction part
225 { .mfi
226 (p11) stfe [r34] = MODF_INTEGER_PART
227 (p12) fms.s0 f8 = MODF_NORM_F8,f1, MODF_INTEGER_PART
228 nop.i 999 ;;
229 }
230
231 // For NORMAL test if fraction part is zero; if so append correct sign
232 { .mfi
233 nop.m 999
234 (p12) fcmp.eq.unc.s0 p7,p0 = MODF_NORM_F8, MODF_INTEGER_PART
235 nop.i 999 ;;
236 }
237
238 { .mfi
239 (p12) stfe [r34] = MODF_INTEGER_PART
240 nop.f 999
241 nop.i 999 ;;
242 }
243
244 // For NORMAL if fraction part is zero append sign of input
245 { .mfb
246 nop.m 999
247 (p7) fmerge.s f8 = MODF_NORM_F8, f0
248 br.ret.sptk b0 ;;
249 }
250
251 MODF_DENORM:
252 // If x unorm get signexp from normalized input
253 // If x unorm get integer part from normalized input
254 { .mfi
255 getf.exp modf_signexp = MODF_NORM_F8
256 fcvt.fx.trunc.s1 MODF_INT_INTEGER_PART = MODF_NORM_F8
257 nop.i 999 ;;
258 }
259
260 // If x unorm mask to get exponent
261 { .mmi
262 and modf_exp = modf_17_ones, modf_signexp ;;
263 cmp.lt.unc p11,p10 = modf_exp, modf_GR_FFFF
264 nop.i 999 ;;
265 }
266
267 { .mfb
268 (p10) cmp.ge.unc p9,p12 = modf_exp, modf_GR_no_frac
269 nop.f 999
270 br.cond.spnt MODF_COMMON ;;
271 }
272
273 GLOBAL_LIBM_END(modfl)