(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / ia64 / fpu / s_logbl.S
blob38b131f3aa3415eb57972b75612a0de52230a472
1 .file "logbl.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 // long double logbl( long double x);
54 // Overview of operation
55 //==============================================================
56 // The logbl function extracts the exponent of x as an integer in 
57 // floating-point format. 
58 // logbl computes log2 of x as a long double
60 // logbl is similar to ilogbl but differs in the  following ways:
61 //         +-inf
62 //            ilogbl: returns INT_MAX
63 //             logbl: returns +inf
64 //         Nan  returns FP_LOGBNAN (which is either INT_MAX or INT_MIN)
65 //            ilogbl: returns INT_MAX (7fffffff)
66 //             logbl: returns QNAN (quietized SNAN)
67 //         0    returns FP_ILOGB0 (which is either INT_MIN or -INT_MAX)
68 //            ilogbl: returns -INT_MAX (80000001)
69 //             logbl: 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_PFS         = r32
89 GR_SAVE_B0          = r34
90 GR_SAVE_GP          = r35
91 GR_Parameter_X      = r38
92 GR_Parameter_Y      = r39
93 GR_Parameter_RESULT = r40
94 GR_Parameter_TAG    = r41
96 FR_X                = f8
97 FR_Y                = f0
98 FR_RESULT           = f10
100 .align 32
101 .global logbl#
103 .section .text
104 .proc  logbl#
105 .align 32
108 logbl: 
110 // qnan snan inf norm     unorm 0 -+
111 // 0    0    0   0        1     0 11
112 // 0                      b
113 { .mfi
114       alloc          r32=ar.pfs,1,5,4,0
115 (p0)  fclass.m.unc  p8,p0 = f8, 0x0b
116       nop.i 999
118 // X NORMAL
119 // r37 = exp(f8) - - 0xffff
120 // sig(f8) = r37
121 // f8 = convert_to_fp (sig))
122 { .mfi
123 (p0)  getf.exp      r35 = f8
124 (p0)  fnorm         f10=f8
125       nop.i 999 ;;
128 // qnan snan inf norm     unorm 0 -+
129 // 1    1    1   0        0     0 11
130 // e                      3
131 { .mmf
132 (p0)  mov      r33 = 0xffff
133 (p0)  mov      r34 = 0x1ffff
134 (p0)  fclass.m.unc  p6,p0 = f8, 0xe3 ;;
137 { .mfb
138 (p0)  and           r36 = r35, r34
139 (p0)  fclass.m.unc  p7,p0 = f8, 0x07
140 (p8)  br.cond.spnt  L(LOGB_DENORM) ;;
143 { .mib
144 (p0)  sub           r37 = r36, r33
145       nop.i 999
146 (p6)  br.cond.spnt  L(LOGB_NAN_INF) ;;
149 { .mib
150 (p0)  setf.sig      f9  = r37
151       nop.i 999
152 (p7)  br.cond.spnt  L(LOGB_ZERO) ;;
154 { .mfi
155       nop.m 999
156 (p0)  fcvt.xf       f10 = f9
157       nop.i 999 ;;
160 { .mfb
161       nop.m 999
162 (p0)  fnorm       f8 = f10
163 (p0)  br.ret.sptk    b0 ;;
166 L(LOGB_DENORM):
167 // Form signexp of 2^64 in case need to scale denormal
168 // Check to see if double-extended denormal
169 { .mfi
170 (p0)  mov r38 = 0x1003f
171 (p0)  fclass.m.unc  p8,p0 = f10, 0x0b
172       nop.i 999 ;;
175 // Form 2^64 in case need to scale denormal
176 { .mfi
177 (p0)  setf.exp f11 = r38
178       nop.f 999
179       nop.i 999 ;;
182 // If double-extended denormal add 64 to exponent bias for scaling
183 // If double-extended denormal form x * 2^64 which is normal
184 { .mfi
185 (p8)  add r33 = 64, r33
186 (p8)  fmpy f10 = f10, f11    
187       nop.i 999 ;;
190 // Logic is the same as normal path but use normalized input
191 { .mmi
192 (p0)  getf.exp      r35 = f10 ;;
193       nop.m 999
194       nop.i 999 ;;
197 { .mmi
198 (p0)  and           r36 = r35, r34 ;;
199 (p0)  sub           r37 = r36, r33
200       nop.i 999 ;;
203 { .mmi
204 (p0)  setf.sig      f9  = r37
205       nop.m 999
206       nop.i 999 ;;
209 { .mfi
210       nop.m 999
211 (p0)  fcvt.xf       f10 = f9
212       nop.i 999 ;;
215 { .mfb
216       nop.m 999
217 (p0)  fnorm       f8 = f10
218 (p0)  br.ret.sptk    b0 ;;
221 L(LOGB_NAN_INF): 
223 // X NAN or INFINITY, return f8 * f8
224 { .mfb
225       nop.m 999
226 (p0)  fma        f8= f8,f8,f0
227 (p0)  br.ret.sptk   b0 ;;
230 L(LOGB_ZERO): 
231 {.mfi
232       nop.m 0
233 (p0)  frcpa.s0       f10,p6 = f1,f0
234       nop.i 0
236 {.mfi
237       mov            GR_Parameter_TAG = 150
238 (p0)  fms.s1         f10 = f0,f0,f10
239       nop.i 0
241 // X ZERO
242 // return -1.0/fabs(f8)=-inf, set divide-by-zero flag, call error support
243 .endp logbl
244 ASM_SIZE_DIRECTIVE(logbl)
246 .proc __libm_error_region
247 __libm_error_region:
248 .prologue
249 { .mfi
250         add   GR_Parameter_Y=-32,sp             // Parameter 2 value
251         nop.f 0
252 .save   ar.pfs,GR_SAVE_PFS
253         mov  GR_SAVE_PFS=ar.pfs                 // Save ar.pfs
255 { .mfi
256 .fframe 64
257         add sp=-64,sp                           // Create new stack
258         nop.f 0
259         mov GR_SAVE_GP=gp                       // Save gp
261 { .mmi
262         stfe [GR_Parameter_Y] = FR_Y,16         // Save Parameter 2 on stack
263         add GR_Parameter_X = 16,sp              // Parameter 1 address
264 .save   b0, GR_SAVE_B0
265         mov GR_SAVE_B0=b0                       // Save b0
267 .body
268 { .mib
269         stfe [GR_Parameter_X] = FR_X            // Store Parameter 1 on stack
270         add   GR_Parameter_RESULT = 0,GR_Parameter_Y
271         nop.b 0                                 // Parameter 3 address
273 { .mib
274         stfe [GR_Parameter_Y] = FR_RESULT      // Store Parameter 3 on stack
275         add   GR_Parameter_Y = -16,GR_Parameter_Y
276         br.call.sptk b0=__libm_error_support#  // Call error handling function
278 { .mmi
279         nop.m 0
280         nop.m 0
281         add   GR_Parameter_RESULT = 48,sp
283 { .mmi
284         ldfe  f8 = [GR_Parameter_RESULT]       // Get return result off stack
285 .restore sp
286         add   sp = 64,sp                       // Restore stack pointer
287         mov   b0 = GR_SAVE_B0                  // Restore return address
289 { .mib
290         mov   gp = GR_SAVE_GP                  // Restore gp
291         mov   ar.pfs = GR_SAVE_PFS             // Restore ar.pfs
292         br.ret.sptk     b0                     // Return
295 .endp __libm_error_region
296 ASM_SIZE_DIRECTIVE(__libm_error_region)
298 .type   __libm_error_support#,@function
299 .global __libm_error_support#