(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / ia64 / fpu / s_modff.S
blob6aa43c884d855911937b52fca00fd2e56431c8b1
1 .file "modff.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 // 12/22/00 Fixed so inexact flag is never set, and invalid is not set for 
45 //            qnans nor for inputs larger than 2^63.
47 // API
48 //==============================================================
49 // float modff(float x, float *iptr)
50 // break a floating point x number into fraction and an exponent
52 // input  floating point f8, address in r33
53 // output floating point f8 (x fraction), and *iptr (x integral part)
55 // OVERVIEW
56 //==============================================================
58 // NO FRACTIONAL PART: HUGE
59 // If
60 // for double-extended
61 // If the true exponent is greater than or equal 63
62 //      1003e ==> 1003e -ffff = 3f = 63(dec)
63 // for double
64 // If the true exponent is greater than or equal 52
65 //                10033 -ffff = 34 = 52(dec)
66 // for single
67 // If the true exponent is greater than or equal 23
68 //                10016 -ffff = 17 = 23(dec)
69 // then
70 // we are already an integer (p9 true)
72 // NO INTEGER PART:    SMALL
73 //     Is f8 exponent less than register bias (that is, is it
74 //     less than 1). If it is, get the right sign of
75 //     zero and store this in iptr.
77 // CALCULATION: NOT HUGE, NOT SMALL
78 // To get the integer part
79 // Take the floating-point  input and truncate 
80 //   then convert  this integer to fp  Call it  MODF_INTEGER_PART
82 // Subtract  MODF_INTEGER_PART from MODF_NORM_F8 to get fraction part
83 // Then put fraction part in f8 
84 //      put integer  part MODF_INTEGER_PART into *iptr
86 // Registers used
87 //==============================================================
89 // predicate registers used: 
90 // p6 - p13
92 //                      0xFFFF           0x10016
93 // -----------------------+-----------------+-------------
94 //              SMALL     |      NORMAL     | HUGE
95 //    p11 --------------->|<----- p12 ----->| <-------------- p9
96 //    p10 --------------------------------->|
97 //    p13 --------------------------------------------------->|
100 #include "libm_support.h"
102 // floating-point registers used: 
103 MODF_NORM_F8               = f9
104 MODF_FRACTION_PART         = f10
105 MODF_INTEGER_PART          = f11
106 MODF_INT_INTEGER_PART      = f12
109 // general registers used 
110 modf_signexp    = r14
111 modf_GR_no_frac = r15
112 modf_GR_FFFF    = r16
113 modf_17_ones    = r17 
114 modf_exp        = r18
115 // r33 = iptr
116      
118 .align 32
119 .global modff#
121 .section .text
122 .proc  modff#
123 .align 32
126 // Main path is p9, p11, p8 FALSE and p12 TRUE
128 // Assume input is normalized and get signexp
129 // Normalize input just in case
130 // Form exponent bias 
131 modff: 
132 { .mfi
133       getf.exp  modf_signexp = f8
134       fnorm          MODF_NORM_F8  = f8
135       addl           modf_GR_FFFF  = 0xffff, r0
137 // Get integer part of input
138 // Form exponent mask
139 { .mfi
140       nop.m 999
141       fcvt.fx.trunc.s1  MODF_INT_INTEGER_PART   = f8
142       mov  modf_17_ones     = 0x1ffff ;;
145 // Is x nan or inf?
146 // qnan snan inf norm     unorm 0 -+
147 // 1    1    1   0        0     0 11 = 0xe3 NAN_INF
148 // Form biased exponent where input only has an integer part
149 { .mfi
150       nop.m 999
151       fclass.m.unc p6,p13 = f8, 0xe3
152       addl modf_GR_no_frac = 0x10016, r0 ;;
155 // Mask to get exponent
156 // Is x unnorm?
157 // qnan snan inf norm     unorm 0 -+
158 // 0    0    0   0        1     0 11 = 0x0b UNORM
159 // Set p13 to indicate calculation path, else p6 if nan or inf 
160 { .mfi
161       and       modf_exp = modf_17_ones, modf_signexp 
162       fclass.m.unc p8,p0 = f8, 0x0b
163       nop.i 999 ;;
166 // p11 <== SMALL, no integer part, fraction is everyting
167 // p9  <== HUGE,  no fraction part, integer is everything
168 // p12 <== NORMAL, fraction part and integer part
169 { .mii
170 (p13) cmp.lt.unc p11,p10 = modf_exp, modf_GR_FFFF
171       nop.i 999
172       nop.i 999 ;;
175 // Is x inf? p6 if inf, p7 if nan
176 { .mfb
177 (p10) cmp.ge.unc p9,p12  = modf_exp, modf_GR_no_frac
178 (p6)  fclass.m.unc p6,p7 = f8, 0x23
179 (p8)  br.cond.spnt L(MODF_DENORM) ;;
182 L(MODF_COMMON):
183 // For HUGE set fraction to signed 0
184 { .mfi
185       nop.m 999
186 (p9)  fmerge.s f8 = f8,f0
187       nop.i 999
189 // For HUGE set integer part to normalized input
190 { .mfi
191       nop.m 999
192 (p9)  fnorm.s MODF_INTEGER_PART = MODF_NORM_F8
193       nop.i 999 ;;
196 // For SMALL set fraction to normalized input, integer part to signed 0
197 { .mfi
198       nop.m 999
199 (p11) fmerge.s MODF_INTEGER_PART = f8,f0
200       nop.i 999
202 { .mfi
203       nop.m 999
204 (p11) fnorm.s f8 = MODF_NORM_F8
205       nop.i 999 ;;
208 // For NORMAL float the integer part
209 { .mfi
210       nop.m 999
211 (p12) fcvt.xf    MODF_INTEGER_PART = MODF_INT_INTEGER_PART
212       nop.i 999 ;;
215 // If x inf set integer part to INF, fraction to signed 0
216 { .mfi
217 (p6)  stfs [r33] = MODF_NORM_F8
218 (p6)  fmerge.s  f8 = f8,f0
219       nop.i 999 ;;
222 // If x nan set integer and fraction parts to NaN (quietized)
223 { .mfi
224 (p7)  stfs [r33] = MODF_NORM_F8
225 (p7)  fmerge.s  f8 = MODF_NORM_F8, MODF_NORM_F8
226       nop.i 999 ;;
229 { .mmi
230 (p9)  stfs [r33] = MODF_INTEGER_PART
231       nop.m 999
232       nop.i 999 ;;
235 // For NORMAL compute fraction part
236 { .mfi
237 (p11) stfs [r33] = MODF_INTEGER_PART
238 (p12) fms.s.s0   f8 = MODF_NORM_F8,f1, MODF_INTEGER_PART
239       nop.i 999 ;;
242 // For NORMAL test if fraction part is zero; if so append correct sign
243 { .mfi
244       nop.m 999
245 (p12) fcmp.eq.unc p7,p0 = MODF_NORM_F8, MODF_INTEGER_PART
246       nop.i 999 ;;
249 { .mfi
250 (p12) stfs [r33] = MODF_INTEGER_PART
251       nop.f 999
252       nop.i 999 ;;
255 // For NORMAL if fraction part is zero append sign of input
256 { .mfb
257       nop.m 999
258 (p7)  fmerge.s f8 = MODF_NORM_F8, f0
259       br.ret.sptk    b0 ;;
262 L(MODF_DENORM):
263 // If x unorm get signexp from normalized input
264 // If x unorm get integer part from normalized input
265 { .mfi
266       getf.exp  modf_signexp = MODF_NORM_F8
267       fcvt.fx.trunc.s1  MODF_INT_INTEGER_PART   = MODF_NORM_F8
268       nop.i 999 ;;
271 // If x unorm mask to get exponent
272 { .mmi
273       and       modf_exp = modf_17_ones, modf_signexp ;;
274       cmp.lt.unc p11,p10 = modf_exp, modf_GR_FFFF
275       nop.i 999 ;;
278 { .mfb
279 (p10) cmp.ge.unc p9,p12  = modf_exp, modf_GR_no_frac
280       nop.f 999
281       br.cond.spnt L(MODF_COMMON) ;;
284 .endp modff
285 ASM_SIZE_DIRECTIVE(modff)