* sysdeps/unix/sysv/linux/m68k/sysdep.h (INLINE_SYSCALL): Don't
[glibc.git] / sysdeps / ia64 / fpu / s_modf.S
blob0bfad137639fa738b682d56e4a966ce2d5403fac
1 .file "modf.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 // WARRANTY DISCLAIMER
10 // 
11 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
12 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
13 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
14 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS 
15 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
16 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
17 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
18 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
19 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
20 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
21 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
22 // 
23 // Intel Corporation is the author of this code, and requests that all
24 // problem reports or change requests be submitted to it directly at 
25 // http://developer.intel.com/opensource.
27 // History
28 //==============================================================
29 // 2/02/00: Initial version
30 // 4/04/00: Improved speed, corrected result for NaN input
31 // 12/22/00 Fixed so inexact flag is never set, and invalid is not set for 
32 //            qnans nor for inputs larger than 2^63.
34 // API
35 //==============================================================
36 // double modf(double x, double *iptr)
37 // break a floating point x number into fraction and an exponent
39 // input  floating point f8, address in r33
40 // output floating point f8 (x fraction), and *iptr (x integral part)
42 // OVERVIEW
43 //==============================================================
45 // NO FRACTIONAL PART: HUGE
46 // If
47 // for double-extended
48 // If the true exponent is greater than or equal 63
49 //      1003e ==> 1003e -ffff = 3f = 63(dec)
50 // for double
51 // If the true exponent is greater than or equal 52
52 //                10033 -ffff = 34 = 52(dec)
53 // for single
54 // If the true exponent is greater than or equal 23
55 //                10016 -ffff = 17 = 23(dec)
56 // then
57 // we are already an integer (p9 true)
59 // NO INTEGER PART:    SMALL
60 //     Is f8 exponent less than register bias (that is, is it
61 //     less than 1). If it is, get the right sign of
62 //     zero and store this in iptr.
64 // CALCULATION: NOT HUGE, NOT SMALL
65 // To get the integer part
66 // Take the floating-point  input and truncate 
67 //   then convert  this integer to fp  Call it  MODF_INTEGER_PART
69 // Subtract  MODF_INTEGER_PART from MODF_NORM_F8 to get fraction part
70 // Then put fraction part in f8 
71 //      put integer  part MODF_INTEGER_PART into *iptr
73 // Registers used
74 //==============================================================
76 // predicate registers used: 
77 // p6 - p13
79 //                      0xFFFF           0x10033
80 // -----------------------+-----------------+-------------
81 //              SMALL     |      NORMAL     | HUGE
82 //    p11 --------------->|<----- p12 ----->| <-------------- p9
83 //    p10 --------------------------------->|
84 //    p13 --------------------------------------------------->|
87 #include "libm_support.h"
89 // floating-point registers used: 
90 MODF_NORM_F8               = f9
91 MODF_FRACTION_PART         = f10
92 MODF_INTEGER_PART          = f11
93 MODF_INT_INTEGER_PART      = f12
96 // general registers used 
97 modf_signexp    = r14
98 modf_GR_no_frac = r15
99 modf_GR_FFFF    = r16
100 modf_17_ones    = r17 
101 modf_exp        = r18
102 // r33 = iptr
103      
105 .align 32
106 .global modf#
108 .section .text
109 .proc  modf#
110 .align 32
113 // Main path is p9, p11, p8 FALSE and p12 TRUE
115 // Assume input is normalized and get signexp
116 // Normalize input just in case
117 // Form exponent bias 
118 modf: 
119 { .mfi
120       getf.exp  modf_signexp = f8
121       fnorm          MODF_NORM_F8  = f8
122       addl           modf_GR_FFFF  = 0xffff, r0
124 // Get integer part of input
125 // Form exponent mask
126 { .mfi
127       nop.m 999
128       fcvt.fx.trunc.s1  MODF_INT_INTEGER_PART   = f8
129       mov  modf_17_ones     = 0x1ffff ;;
132 // Is x nan or inf?
133 // qnan snan inf norm     unorm 0 -+
134 // 1    1    1   0        0     0 11 = 0xe3 NAN_INF
135 // Form biased exponent where input only has an integer part
136 { .mfi
137       nop.m 999
138       fclass.m.unc p6,p13 = f8, 0xe3
139       addl modf_GR_no_frac = 0x10033, r0 ;;
142 // Mask to get exponent
143 // Is x unnorm?
144 // qnan snan inf norm     unorm 0 -+
145 // 0    0    0   0        1     0 11 = 0x0b UNORM
146 // Set p13 to indicate calculation path, else p6 if nan or inf 
147 { .mfi
148       and       modf_exp = modf_17_ones, modf_signexp 
149       fclass.m.unc p8,p0 = f8, 0x0b
150       nop.i 999 ;;
153 // p11 <== SMALL, no integer part, fraction is everyting
154 // p9  <== HUGE,  no fraction part, integer is everything
155 // p12 <== NORMAL, fraction part and integer part
156 { .mii
157 (p13) cmp.lt.unc p11,p10 = modf_exp, modf_GR_FFFF
158       nop.i 999
159       nop.i 999 ;;
162 // Is x inf? p6 if inf, p7 if nan
163 { .mfb
164 (p10) cmp.ge.unc p9,p12  = modf_exp, modf_GR_no_frac
165 (p6)  fclass.m.unc p6,p7 = f8, 0x23
166 (p8)  br.cond.spnt L(MODF_DENORM) ;;
169 L(MODF_COMMON):
170 // For HUGE set fraction to signed 0
171 { .mfi
172       nop.m 999
173 (p9)  fmerge.s f8 = f8,f0
174       nop.i 999
176 // For HUGE set integer part to normalized input
177 { .mfi
178       nop.m 999
179 (p9)  fnorm.d MODF_INTEGER_PART = MODF_NORM_F8
180       nop.i 999 ;;
183 // For SMALL set fraction to normalized input, integer part to signed 0
184 { .mfi
185       nop.m 999
186 (p11) fmerge.s MODF_INTEGER_PART = f8,f0
187       nop.i 999
189 { .mfi
190       nop.m 999
191 (p11) fnorm.d f8 = MODF_NORM_F8
192       nop.i 999 ;;
195 // For NORMAL float the integer part
196 { .mfi
197       nop.m 999
198 (p12) fcvt.xf    MODF_INTEGER_PART = MODF_INT_INTEGER_PART
199       nop.i 999 ;;
202 // If x inf set integer part to INF, fraction to signed 0
203 { .mfi
204 (p6)  stfd [r33] = MODF_NORM_F8
205 (p6)  fmerge.s  f8 = f8,f0
206       nop.i 999 ;;
209 // If x nan set integer and fraction parts to NaN (quietized)
210 { .mfi
211 (p7)  stfd [r33] = MODF_NORM_F8
212 (p7)  fmerge.s  f8 = MODF_NORM_F8, MODF_NORM_F8
213       nop.i 999 ;;
216 { .mmi
217 (p9)  stfd [r33] = MODF_INTEGER_PART
218       nop.m 999
219       nop.i 999 ;;
222 // For NORMAL compute fraction part
223 { .mfi
224 (p11) stfd [r33] = MODF_INTEGER_PART
225 (p12) fms.d.s0   f8 = MODF_NORM_F8,f1, MODF_INTEGER_PART
226       nop.i 999 ;;
229 // For NORMAL test if fraction part is zero; if so append correct sign
230 { .mfi
231       nop.m 999
232 (p12) fcmp.eq.unc p7,p0 = MODF_NORM_F8, MODF_INTEGER_PART
233       nop.i 999 ;;
236 { .mfi
237 (p12) stfd [r33] = MODF_INTEGER_PART
238       nop.f 999
239       nop.i 999 ;;
242 // For NORMAL if fraction part is zero append sign of input
243 { .mfb
244       nop.m 999
245 (p7)  fmerge.s f8 = MODF_NORM_F8, f0
246       br.ret.sptk    b0 ;;
249 L(MODF_DENORM):
250 // If x unorm get signexp from normalized input
251 // If x unorm get integer part from normalized input
252 { .mfi
253       getf.exp  modf_signexp = MODF_NORM_F8
254       fcvt.fx.trunc.s1  MODF_INT_INTEGER_PART   = MODF_NORM_F8
255       nop.i 999 ;;
258 // If x unorm mask to get exponent
259 { .mmi
260       and       modf_exp = modf_17_ones, modf_signexp ;;
261       cmp.lt.unc p11,p10 = modf_exp, modf_GR_FFFF
262       nop.i 999 ;;
265 { .mfb
266 (p10) cmp.ge.unc p9,p12  = modf_exp, modf_GR_no_frac
267       nop.f 999
268       br.cond.spnt L(MODF_COMMON) ;;
271 .endp modf
272 ASM_SIZE_DIRECTIVE(modf)