(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / ia64 / fpu / s_modfl.S
blobb5eb509adf2e3a88f087051215f38a5361deff92
1 .file "modfl.s"
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:
13 // * Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
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.
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.
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.
40 // History
41 //==============================================================
42 // 2/02/00: Initial version
43 // 4/04/00: Improved speed, corrected result for NaN input
44 // 5/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.
48 // API
49 //==============================================================
50 // long double modfl(long double x, long double *iptr)
51 // break a floating point x number into fraction and an exponent
53 // input  floating point f8, address in r34
54 // output floating point f8 (x fraction), and *iptr (x integral part)
56 // OVERVIEW
57 //==============================================================
59 // NO FRACTIONAL PART: HUGE
60 // If
61 // for double-extended
62 // If the true exponent is >= 63
63 //      1003e ==> 1003e -ffff = 3f = 63(dec)
64 // then
65 // we are already an integer (p9 true)
67 // NO INTEGER PART:    SMALL
68 //     Is f8 exponent less than register bias (that is, is it
69 //     less than 1). If it is, get the right sign of
70 //     zero and store this in iptr.
72 // CALCULATION: NOT HUGE, NOT SMALL
73 // To get the integer part
74 // Take the floating-point  input and truncate 
75 //   then convert  this integer to fp  Call it  MODF_INTEGER_PART
77 // Subtract  MODF_INTEGER_PART from MODF_NORM_F8 to get fraction part
78 // Then put fraction part in f8 
79 //      put integer  part MODF_INTEGER_PART into *iptr
81 // Registers used
82 //==============================================================
84 // predicate registers used: 
85 // p6 - p13
87 //                      0xFFFF           0x1003e
88 // -----------------------+-----------------+-------------
89 //              SMALL     |      NORMAL     | HUGE
90 //    p11 --------------->|<----- p12 ----->| <-------------- p9
91 //    p10 --------------------------------->|
92 //    p13 --------------------------------------------------->|
95 #include "libm_support.h"
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
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      
113 .align 32
114 .global modfl#
116 .section .text
117 .proc  modfl#
118 .align 32
121 // Main path is p9, p11, p8 FALSE and p12 TRUE
123 // Assume input is normalized and get signexp
124 // Normalize input just in case
125 // Form exponent bias 
126 modfl: 
127 { .mfi
128       getf.exp  modf_signexp = f8
129       fnorm          MODF_NORM_F8  = f8
130       addl           modf_GR_FFFF  = 0xffff, r0
132 // Get integer part of input
133 // Form exponent mask
134 { .mfi
135       nop.m 999
136       fcvt.fx.trunc.s1  MODF_INT_INTEGER_PART   = f8
137       mov  modf_17_ones     = 0x1ffff ;;
140 // Is x nan or inf?
141 // qnan snan inf norm     unorm 0 -+
142 // 1    1    1   0        0     0 11 = 0xe3 NAN_INF
143 // Form biased exponent where input only has an integer part
144 { .mfi
145       nop.m 999
146       fclass.m.unc p6,p13 = f8, 0xe3
147       addl modf_GR_no_frac = 0x1003e, r0 ;;
150 // Mask to get exponent
151 // Is x unnorm?
152 // qnan snan inf norm     unorm 0 -+
153 // 0    0    0   0        1     0 11 = 0x0b UNORM
154 // Set p13 to indicate calculation path, else p6 if nan or inf 
155 { .mfi
156       and       modf_exp = modf_17_ones, modf_signexp 
157       fclass.m.unc p8,p0 = f8, 0x0b
158       nop.i 999 ;;
161 // p11 <== SMALL, no integer part, fraction is everyting
162 // p9  <== HUGE,  no fraction part, integer is everything
163 // p12 <== NORMAL, fraction part and integer part
164 { .mii
165 (p13) cmp.lt.unc p11,p10 = modf_exp, modf_GR_FFFF
166       nop.i 999
167       nop.i 999 ;;
170 // Is x inf? p6 if inf, p7 if nan
171 { .mfb
172 (p10) cmp.ge.unc p9,p12  = modf_exp, modf_GR_no_frac
173 (p6)  fclass.m.unc p6,p7 = f8, 0x23
174 (p8)  br.cond.spnt L(MODF_DENORM) ;;
177 L(MODF_COMMON):
178 // For HUGE set fraction to signed 0
179 { .mfi
180       nop.m 999
181 (p9)  fmerge.s f8 = f8,f0
182       nop.i 999
184 // For HUGE set integer part to normalized input
185 { .mfi
186       nop.m 999
187 (p9)  fnorm MODF_INTEGER_PART = MODF_NORM_F8
188       nop.i 999 ;;
191 // For SMALL set fraction to normalized input, integer part to signed 0
192 { .mfi
193       nop.m 999
194 (p11) fmerge.s MODF_INTEGER_PART = f8,f0
195       nop.i 999
197 { .mfi
198       nop.m 999
199 (p11) fnorm   f8 = MODF_NORM_F8
200       nop.i 999 ;;
203 // For NORMAL float the integer part
204 { .mfi
205       nop.m 999
206 (p12) fcvt.xf    MODF_INTEGER_PART = MODF_INT_INTEGER_PART
207       nop.i 999 ;;
210 // If x inf set integer part to INF, fraction to signed 0
211 { .mfi
212 (p6)  stfe [r34] = MODF_NORM_F8
213 (p6)  fmerge.s  f8 = f8,f0
214       nop.i 999 ;;
217 // If x nan set integer and fraction parts to NaN (quietized)
218 { .mfi
219 (p7)  stfe [r34] = MODF_NORM_F8
220 (p7)  fmerge.s  f8 = MODF_NORM_F8, MODF_NORM_F8
221       nop.i 999 ;;
224 { .mmi
225 (p9)  stfe [r34] = MODF_INTEGER_PART
226       nop.m 999
227       nop.i 999 ;;
230 // For NORMAL compute fraction part
231 { .mfi
232 (p11) stfe [r34] = MODF_INTEGER_PART
233 (p12) fms.s0   f8 = MODF_NORM_F8,f1, MODF_INTEGER_PART
234       nop.i 999 ;;
237 // For NORMAL test if fraction part is zero; if so append correct sign
238 { .mfi
239       nop.m 999
240 (p12) fcmp.eq.unc p7,p0 = MODF_NORM_F8, MODF_INTEGER_PART
241       nop.i 999 ;;
244 { .mfi
245 (p12) stfe [r34] = MODF_INTEGER_PART
246       nop.f 999
247       nop.i 999 ;;
250 // For NORMAL if fraction part is zero append sign of input
251 { .mfb
252       nop.m 999
253 (p7)  fmerge.s f8 = MODF_NORM_F8, f0
254       br.ret.sptk    b0 ;;
257 L(MODF_DENORM):
258 // If x unorm get signexp from normalized input
259 // If x unorm get integer part from normalized input
260 { .mfi
261       getf.exp  modf_signexp = MODF_NORM_F8
262       fcvt.fx.trunc.s1  MODF_INT_INTEGER_PART   = MODF_NORM_F8
263       nop.i 999 ;;
266 // If x unorm mask to get exponent
267 { .mmi
268       and       modf_exp = modf_17_ones, modf_signexp ;;
269       cmp.lt.unc p11,p10 = modf_exp, modf_GR_FFFF
270       nop.i 999 ;;
273 { .mfb
274 (p10) cmp.ge.unc p9,p12  = modf_exp, modf_GR_no_frac
275       nop.f 999
276       br.cond.spnt L(MODF_COMMON) ;;
279 .endp modfl
280 ASM_SIZE_DIRECTIVE(modfl)