2.9
[glibc/nacl-glibc.git] / sysdeps / ia64 / fpu / s_ilogb.S
blob0102370cd65b2c840bfbca0b4765bfc9e6807455
1 .file "ilogb.s"
4 // Copyright (c) 2000 - 2003, Intel Corporation
5 // All rights reserved.
6 //
7 // Contributed 2000 by the Intel Numerics Group, 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.
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://www.intel.com/software/products/opensource/libraries/num.htm.
40 // History
41 //==============================================================
42 // 02/03/00 Initial version
43 // 05/26/00 Fix bug when x a double-extended denormal;
44 //          if x=0 call error routine, per C9X
45 // 08/15/00 Bundle added after call to __libm_error_support to properly
46 //          set [the previously overwritten] GR_Parameter_RESULT.
47 // 01/20/01 Fixed result for x=0, corrected error tag value.
48 // 05/20/02 Cleaned up namespace and sf0 syntax
49 // 01/20/03 Improved performance
51 // API
52 //==============================================================
53 // int ilogb( double x );
55 // Overview of operation
56 //==============================================================
57 // The ilogb function extracts the exponent of x as an integer
58 // and returns it in r8
60 // ilogb is similar to logb 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 // r26 -> r39
76 // r36 -> r39 used as parameters to error path
78 // predicate registers used:
79 // p6 -> p10
80 // floating-point registers used:
81 // f9, f10, f11
82 // f8, input
84 rExpBias            = r26
85 rExpMask            = r27
86 rSignexp_x          = r28
87 rExp_x              = r29
88 rIntMax             = r30
89 rExp_2to64          = r31
91 GR_SAVE_PFS         = r32
92 rTrialResult        = r33
93 GR_SAVE_B0          = r34
94 GR_SAVE_GP          = r35
96 GR_Parameter_X      = r36
97 GR_Parameter_Y      = r37
98 GR_Parameter_RESULT = r38
99 GR_Parameter_TAG    = r39
101 fTmp                = f9
102 fNorm_x             = f10
103 f2to64              = f11
105 .section .text
106 GLOBAL_LIBM_ENTRY(ilogb)
108 // X NORMAL
109 // TrueExp_x = exp(f8) - 0xffff
110 // r8 = TrueExp_x
111 { .mfi
112       getf.exp        rSignexp_x = f8
113       fclass.m        p8,p0 = f8, 0x0b   // Test for x unorm
114       mov             rExpBias = 0xffff  // Exponent bias
116 { .mfi
117       nop.m           0
118       fnorm.s1        fNorm_x = f8
119       mov             rExpMask = 0x1ffff // Exponent mask
123 // Form signexp of 2^64 in case need to scale denormal
124 { .mfb
125       mov             rExp_2to64 = 0x1003f
126       fclass.m        p6,p9 = f8, 0x1e3  // Test x natval, nan, inf
127 (p8)  br.cond.spnt    ILOGB_DENORM       // Branch if x unorm
131 ILOGB_COMMON:
132 // Return here from ILOGB_DENORM
133 { .mfi
134       and             rExp_x = rSignexp_x, rExpMask // Get biased exponent
135       fclass.m        p7,p10 = f8, 0x07   // Test x zero
136       nop.i           0
138 { .mlx
139       nop.m           0
140       movl            rIntMax = 0x000000007fffffff // Form INT_MAX
144 .pred.rel "mutex",p6,p9
145 { .mfi
146 (p9)  sub             r8 = rExp_x, rExpBias // Get true exponent for normal path
147 (p6)  fma.s0          fTmp = f8, f8, f0     // Dummy to set Invalid flag
148 (p6)  mov             r8 = rIntMax          // If nan, inf, return INT_MAX
150 { .mbb
151       nop.m           0
152 (p7)  br.cond.spnt    ILOGB_ZERO            // Branch if x zero
153 (p10) br.ret.sptk     b0                    // Exit if x not zero
158 ILOGB_DENORM:
159 // Form 2^64 in case need to scale denormal
160 // Check to see if double-extended denormal
161 { .mfi
162       setf.exp        f2to64 = rExp_2to64
163       fclass.m        p8,p0 = fNorm_x, 0x0b
164       nop.i           0
168 { .mfi
169       nop.m           0
170       fcmp.eq.s0      p7,p0 = f8, f0           // Dummy op to set denormal flag
171       nop.i           0
175 // If double-extended denormal add 64 to exponent bias for scaling
176 // If double-extended denormal form x * 2^64 which is normal
177 { .mfi
178 (p8)  add             rExpBias = 64, rExpBias
179 (p8)  fmpy.s1         fNorm_x = fNorm_x, f2to64
180       nop.i           0
184 // Logic is the same as normal path but use normalized input
185 { .mib
186       getf.exp        rSignexp_x = fNorm_x
187       nop.i           0
188       br.cond.sptk    ILOGB_COMMON             // Return to main path
192 ILOGB_ZERO:
193 // Here if x zero
194 // Return INT_MIN, call error support
196 { .mlx
197       alloc           r32=ar.pfs,1,3,4,0
198       movl            rTrialResult = 0x0000000080000000
200 { .mib
201       mov             GR_Parameter_TAG = 157  // Error code
202       nop.i           0
203       br.cond.sptk    __libm_error_region     // Call error support
207 GLOBAL_LIBM_END(ilogb)
210 LOCAL_LIBM_ENTRY(__libm_error_region)
211 .prologue
213 { .mfi
214         add   GR_Parameter_Y=-32,sp           // Parameter 2 value
215         nop.f 0
216 .save   ar.pfs,GR_SAVE_PFS
217         mov  GR_SAVE_PFS=ar.pfs               // Save ar.pfs
219 { .mfi
220 .fframe 64
221         add sp=-64,sp                         // Create new stack
222         nop.f 0
223         mov GR_SAVE_GP=gp                     // Save gp
226 { .mmi
227         stfd [GR_Parameter_Y] = f0,16         // STORE Parameter 2 on stack
228         add GR_Parameter_X    = 16,sp         // Parameter 1 address
229 .save   b0, GR_SAVE_B0
230         mov GR_SAVE_B0=b0                     // Save b0
233 .body
234 { .mib
235         stfd [GR_Parameter_X] = f8            // STORE Parameter 1 on stack
236         add   GR_Parameter_RESULT = 0,GR_Parameter_Y    // Parameter 3 address
237         nop.b 0
239 { .mib
240         stfd [GR_Parameter_Y] = f9            // Store Parameter 3 on stack
241         add   GR_Parameter_Y = -16,GR_Parameter_Y
242         br.call.sptk b0=__libm_error_support# // Call error handling function
245 { .mmi
246         add   GR_Parameter_RESULT = 48,sp
247         nop.m 0
248         nop.i 0
251 { .mmi
252         mov   r8 = rTrialResult
253 .restore sp
254         add   sp = 64,sp                       // Restore stack pointer
255         mov   b0 = GR_SAVE_B0                  // Restore return address
258 { .mib
259         mov   gp = GR_SAVE_GP                  // Restore gp
260         mov   ar.pfs = GR_SAVE_PFS             // Restore ar.pfs
261         br.ret.sptk   b0
264 LOCAL_LIBM_END(__libm_error_region)
267 .type   __libm_error_support#,@function
268 .global __libm_error_support#