(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / ia64 / fpu / s_logb.S
blob76c4fe778e45f819fc57139983fc06b21f0ae71b
1 .file "logb.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 // double logb( double x);
54 // Overview of operation
55 //==============================================================
56 // The logb function extracts the exponent of x as an integer in 
57 // floating-point format. 
58 // logb computes log2 of x as a double
60 // logb is similar to ilogb but differs in the  following ways:
61 //         +-inf
62 //            ilogb: returns INT_MAX
63 //             logb: returns +inf
64 //         Nan  returns FP_LOGBNAN (which is either INT_MAX or INT_MIN)
65 //            ilogb: returns INT_MAX (7fffffff)
66 //             logb: returns QNAN (quietized SNAN)
67 //         0    returns FP_ILOGB0 (which is either INT_MIN or -INT_MAX)
68 //            ilogb: returns -INT_MAX (80000001)
69 //             logb: 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
81 // floating-point registers used: 
82 // f9, f10, f11
83 // f8, input
85 #include "libm_support.h"
87 GR_SAVE_B0          = r34
88 GR_SAVE_GP          = r35
89 GR_SAVE_PFS         = r32
91 GR_Parameter_X      = r38
92 GR_Parameter_Y      = r39
93 GR_Parameter_RESULT = r40
95 .align 32
96 .global logb#
98 .section .text
99 .proc  logb#
100 .align 32
103 logb: 
105 // qnan snan inf norm     unorm 0 -+
106 // 0    0    0   0        1     0 11
107 // 0                      b
108 { .mfi
109       alloc          r32=ar.pfs,1,5,4,0
110 (p0)  fclass.m.unc  p8,p0 = f8, 0x0b
111       nop.i 999
113 // X NORMAL
114 // r37 = exp(f8) - - 0xffff
115 // sig(f8) = r37
116 // f8 = convert_to_fp (sig))
117 { .mfi
118 (p0)  getf.exp      r35 = f8
119 (p0)  fnorm         f10=f8
120       nop.i 999 ;;
123 // qnan snan inf norm     unorm 0 -+
124 // 1    1    1   0        0     0 11
125 // e                      3
126 { .mmf
127 (p0)  mov      r33 = 0xffff
128 (p0)  mov      r34 = 0x1ffff
129 (p0)  fclass.m.unc  p6,p0 = f8, 0xe3 ;;
132 { .mfb
133 (p0)  and           r36 = r35, r34
134 (p0)  fclass.m.unc  p7,p0 = f8, 0x07
135 (p8)  br.cond.spnt  L(LOGB_DENORM) ;;
138 { .mib
139 (p0)  sub           r37 = r36, r33
140       nop.i 999
141 (p6)  br.cond.spnt  L(LOGB_NAN_INF) ;;
144 { .mib
145 (p0)  setf.sig      f9  = r37
146       nop.i 999
147 (p7)  br.cond.spnt  L(LOGB_ZERO) ;;
150 { .mfi
151       nop.m 999
152 (p0)  fcvt.xf       f10 = f9
153       nop.i 999 ;;
156 { .mfb
157       nop.m 999
158 (p0)  fnorm.d       f8 = f10
159 (p0)  br.ret.sptk    b0 ;;
162 L(LOGB_DENORM):
163 // Form signexp of 2^64 in case need to scale denormal
164 // Check to see if double-extended denormal
165 { .mfi
166 (p0)  mov r38 = 0x1003f
167 (p0)  fclass.m.unc  p8,p0 = f10, 0x0b
168       nop.i 999 ;;
171 // Form 2^64 in case need to scale denormal
172 { .mfi
173 (p0)  setf.exp f11 = r38
174       nop.f 999
175       nop.i 999 ;;
178 // If double-extended denormal add 64 to exponent bias for scaling
179 // If double-extended denormal form x * 2^64 which is normal
180 { .mfi
181 (p8)  add r33 = 64, r33
182 (p8)  fmpy f10 = f10, f11    
183       nop.i 999 ;;
186 // Logic is the same as normal path but use normalized input
187 { .mmi
188 (p0)  getf.exp      r35 = f10 ;;
189       nop.m 999
190       nop.i 999 ;;
193 { .mmi
194 (p0)  and           r36 = r35, r34 ;;
195 (p0)  sub           r37 = r36, r33
196       nop.i 999 ;;
199 { .mmi
200 (p0)  setf.sig      f9  = r37
201       nop.m 999
202       nop.i 999 ;;
205 { .mfi
206       nop.m 999
207 (p0)  fcvt.xf       f10 = f9
208       nop.i 999 ;;
211 { .mfb
212       nop.m 999
213 (p0)  fnorm.d       f8 = f10
214 (p0)  br.ret.sptk    b0 ;;
217 L(LOGB_NAN_INF): 
219 // X NAN or INFINITY, return f8 * f8
220 { .mfb
221       nop.m 999
222 (p0)  fma.d      f8= f8,f8,f0
223 (p0)  br.ret.sptk   b0 ;;
226 .endp logb#
227 ASM_SIZE_DIRECTIVE(logb)
229 // Stack operations when calling error support.
230 //       (1)               (2)                          (3) (call)              (4)
231 //   sp   -> +          psp -> +                     psp -> +                   sp -> +
232 //           |                 |                            |                         |
233 //           |                 | <- GR_Y               R3 ->| <- GR_RESULT            | -> f8
234 //           |                 |                            |                         |
235 //           | <-GR_Y      Y2->|                       Y2 ->| <- GR_Y                 |
236 //           |                 |                            |                         |
237 //           |                 | <- GR_X               X1 ->|                         |
238 //           |                 |                            |                         |
239 //  sp-64 -> +          sp ->  +                     sp ->  +                         +
240 //    save ar.pfs          save b0                                               restore gp
241 //    save gp                                                                    restore ar.pfs
245 .proc __libm_error_region
246 __libm_error_region:
247 L(LOGB_ZERO): 
248 .prologue
250 // f9  = |f8|
251 // f10 = -f9 = -|f8|
252 // f9  = 1.0/f10 = -1.0/-|f8|
254 { .mfi 
255       mov           r41 = 151      // Error code
256 (p0)  fmerge.s      f9 = f0,f8
257       nop.i 999
262 { .mfi
263       nop.m 999
264       fmerge.ns     f10 = f0,f9
265       nop.i 999
269 // (1)
270 { .mfi
271         add   GR_Parameter_Y=-32,sp             // Parameter 2 value
272         frcpa         f9,p6 = f1,f10
273 .save   ar.pfs,GR_SAVE_PFS
274         mov  GR_SAVE_PFS=ar.pfs                 // Save ar.pfs
276 { .mfi
277 .fframe 64
278         add sp=-64,sp                          // Create new stack
279         nop.f 0
280         mov GR_SAVE_GP=gp                      // Save gp
284 // (2)
285 { .mmi
286         stfd [GR_Parameter_Y] = f0,16         // STORE Parameter 2 on stack
287         add GR_Parameter_X    = 16,sp         // Parameter 1 address
288 .save   b0, GR_SAVE_B0
289         mov GR_SAVE_B0=b0                     // Save b0
292 .body
293 // (3)
294 { .mib
295         stfd [GR_Parameter_X] = f8            // STORE Parameter 1 on stack
296         add   GR_Parameter_RESULT = 0,GR_Parameter_Y    // Parameter 3 address
297         nop.b 0                                         
299 { .mib
300         stfd [GR_Parameter_Y] = f9            // Store Parameter 3 on stack
301         add   GR_Parameter_Y = -16,GR_Parameter_Y
302         br.call.sptk b0=__libm_error_support# // Call error handling function
304 { .mmi
305         nop.m 0
306         nop.m 0
307         add   GR_Parameter_RESULT = 48,sp
310 // (4)
311 { .mmi
312         ldfd  f8 = [GR_Parameter_RESULT]       // Get return result off stack
313 .restore sp
314         add   sp = 64,sp                       // Restore stack pointer
315         mov   b0 = GR_SAVE_B0                  // Restore return address
317 { .mib
318         mov   gp = GR_SAVE_GP                  // Restore gp
319         mov   ar.pfs = GR_SAVE_PFS             // Restore ar.pfs
320         br.ret.sptk   b0
323 .endp __libm_error_region
324 ASM_SIZE_DIRECTIVE(__libm_error_region)
326 .type   __libm_error_support#,@function
327 .global __libm_error_support#