(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / ia64 / fpu / s_logbf.S
blobf2f671f8920c1d85cccc2e867f8b82f59658f573
1 .file "logbf.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 // 2/16/00  Modified to conform to C9X 
44 // 3/16/00  Improved speed
45 // 4/04/00  Unwind support added
46 // 5/30/00  Fixed bug when x double-extended denormal
47 // 8/15/00  Bundle added after call to __libm_error_support to properly
48 //          set [the previously overwritten] GR_Parameter_RESULT.
50 // API
51 //==============================================================
52 // float logbf( float x);
54 // Overview of operation
55 //==============================================================
56 // The logbf function extracts the exponent of x as an integer in 
57 // floating-point format. 
58 // logbf computes log2 of x as a float
60 // logbf is similar to ilogbf but differs in the  following ways:
61 //         +-inf
62 //            ilogbf: returns INT_MAX
63 //             logbf: returns +inf
64 //         Nan  returns FP_LOGBNAN (which is either INT_MAX or INT_MIN)
65 //            ilogbf: returns INT_MAX (7fffffff)
66 //             logbf: returns QNAN (quietized SNAN)
67 //         0    returns FP_ILOGB0 (which is either INT_MIN or -INT_MAX)
68 //            ilogbf: returns -INT_MAX (80000001)
69 //             logbf: returns -inf, raises the divide-by-zero exception,
70 //                   and calls libm_error_support to set domain error
72 // Registers used
73 //==============================================================
74 // general registers used: 
75 // ar.pfs r32 
76 // r33 -> r37
77 // r38 -> r41 used as parameters to error path
79 // predicate registers used: 
80 // p6, p7, p8
82 // floating-point registers used: 
83 // f9, f10, f11
84 // f8, input
86 #include "libm_support.h"
88 GR_SAVE_B0                    = r34
89 // r40 is address of table of coefficients
90 GR_SAVE_PFS                   = r32
91 GR_SAVE_GP                    = r35 
93 GR_Parameter_X                = r38
94 GR_Parameter_Y                = r39
95 GR_Parameter_RESULT           = r40
96 GR_Parameter_TAG              = r41
98 FR_X             = f8
99 FR_Y             = f0
100 FR_RESULT        = f10
103 .align 32
104 .global logbf#
106 .section .text
107 .proc  logbf#
108 .align 32
111 logbf: 
113 // qnan snan inf norm     unorm 0 -+
114 // 0    0    0   0        1     0 11
115 // 0                      b
116 { .mfi
117       alloc          r32=ar.pfs,1,5,4,0
118 (p0)  fclass.m.unc  p8,p0 = f8, 0x0b
119       nop.i 999
121 // X NORMAL
122 // r37 = exp(f8) - - 0xffff
123 // sig(f8) = r37
124 // f8 = convert_to_fp (sig))
125 { .mfi
126 (p0)  getf.exp      r35 = f8
127 (p0)  fnorm         f10=f8
128       nop.i 999 ;;
131 // qnan snan inf norm     unorm 0 -+
132 // 1    1    1   0        0     0 11
133 // e                      3
134 { .mmf
135 (p0)  mov      r33 = 0xffff
136 (p0)  mov      r34 = 0x1ffff
137 (p0)  fclass.m.unc  p6,p0 = f8, 0xe3 ;;
140 { .mfb
141 (p0)  and           r36 = r35, r34
142 (p0)  fclass.m.unc  p7,p0 = f8, 0x07
143 (p8)  br.cond.spnt  L(LOGB_DENORM) ;;
146 { .mib
147 (p0)  sub           r37 = r36, r33
148       nop.i 999
149 (p6)  br.cond.spnt  L(LOGB_NAN_INF) ;;
152 { .mib
153 (p0)  setf.sig      f9  = r37
154       nop.i 999
155 (p7)  br.cond.spnt  L(LOGB_ZERO) ;;
158 { .mfi
159       nop.m 999
160 (p0)  fcvt.xf       f10 = f9
161       nop.i 999 ;;
164 { .mfb
165       nop.m 999
166 (p0)  fnorm.s       f8 = f10
167 (p0)  br.ret.sptk    b0 ;;
170 L(LOGB_DENORM):
171 // Form signexp of 2^64 in case need to scale denormal
172 // Check to see if double-extended denormal
173 { .mfi
174 (p0)  mov r38 = 0x1003f
175 (p0)  fclass.m.unc  p8,p0 = f10, 0x0b
176       nop.i 999 ;;
179 // Form 2^64 in case need to scale denormal
180 { .mfi
181 (p0)  setf.exp f11 = r38
182       nop.f 999
183       nop.i 999 ;;
186 // If double-extended denormal add 64 to exponent bias for scaling
187 // If double-extended denormal form x * 2^64 which is normal
188 { .mfi
189 (p8)  add r33 = 64, r33
190 (p8)  fmpy f10 = f10, f11    
191       nop.i 999 ;;
194 // Logic is the same as normal path but use normalized input
195 { .mmi
196 (p0)  getf.exp      r35 = f10 ;;
197       nop.m 999
198       nop.i 999 ;;
201 { .mmi
202 (p0)  and           r36 = r35, r34 ;;
203 (p0)  sub           r37 = r36, r33
204       nop.i 999 ;;
207 { .mmi
208 (p0)  setf.sig      f9  = r37
209       nop.m 999
210       nop.i 999 ;;
213 { .mfi
214       nop.m 999
215 (p0)  fcvt.xf       f10 = f9
216       nop.i 999 ;;
219 { .mfb
220       nop.m 999
221 (p0)  fnorm.s       f8 = f10
222 (p0)  br.ret.sptk    b0 ;;
225 L(LOGB_NAN_INF): 
227 // X NAN or INFINITY, return f8 * f8
228 { .mfb
229       nop.m 999
230 (p0)  fma.s      f8= f8,f8,f0
231 (p0)  br.ret.sptk   b0 ;;
234 L(LOGB_ZERO): 
236 // X ZERO
237 // return -1.0/fabs(f8)=-inf, set divide-by-zero flag, call error support
238 { .mfi
239       nop.m 999
240 (p0)  fmerge.s      f9 = f0,f8
241       nop.i 999 ;;
244 { .mfi
245       nop.m 999
246 (p0)  fmerge.ns     f10 = f0,f9
247       nop.i 999 ;;
250 { .mfi
251       nop.m 999
252 (p0)  frcpa         f10,p6 = f1,f10
253       nop.i 999 ;;
256 .endp logbf
257 ASM_SIZE_DIRECTIVE(logbf)
260 .proc __libm_error_region
261 __libm_error_region:
262 .prologue
263 { .mii
264         add   GR_Parameter_Y=-32,sp             // Parameter 2 value
265 (p0)    mov   GR_Parameter_TAG = 152                   
266 .save   ar.pfs,GR_SAVE_PFS
267         mov  GR_SAVE_PFS=ar.pfs                 // Save ar.pfs
269 { .mfi
270 .fframe 64
271         add sp=-64,sp                           // Create new stack
272         nop.f 0
273         mov GR_SAVE_GP=gp                       // Save gp
275 { .mmi
276         stfs [GR_Parameter_Y] = FR_Y,16         // Store Parameter 2 on stack
277         add GR_Parameter_X = 16,sp              // Parameter 1 address
278 .save   b0, GR_SAVE_B0
279         mov GR_SAVE_B0=b0                       // Save b0
281 .body
282 { .mib
283         stfs [GR_Parameter_X] = FR_X            // Store Parameter 1 on stack
284         add   GR_Parameter_RESULT = 0,GR_Parameter_Y
285         nop.b 0                                 // Parameter 3 address
287 { .mib
288         stfs [GR_Parameter_Y] = FR_RESULT       // Store Parameter 3 on stack
289         add   GR_Parameter_Y = -16,GR_Parameter_Y
290         br.call.sptk b0=__libm_error_support#   // Call error handling function
292 { .mmi
293         nop.m 0
294         nop.m 0
295         add   GR_Parameter_RESULT = 48,sp
297 { .mmi
298         ldfs  f8 = [GR_Parameter_RESULT]       // Get return result off stack
299 .restore sp
300         add   sp = 64,sp                       // Restore stack pointer
301         mov   b0 = GR_SAVE_B0                  // Restore return address
303 { .mib
304         mov   gp = GR_SAVE_GP                  // Restore gp 
305         mov   ar.pfs = GR_SAVE_PFS             // Restore ar.pfs
306         br.ret.sptk     b0                     // Return
307 };; 
309 .endp __libm_error_region
310 ASM_SIZE_DIRECTIVE(__libm_error_region)
313 .type   __libm_error_support#,@function
314 .global __libm_error_support#