4 // Copyright (c) 2000 - 2003, Intel Corporation
5 // All rights reserved.
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
15 // * Redistributions in binary form must reproduce the above copyright
16 // notice, this list of conditions and the following disclaimer in the
17 // documentation and/or other materials provided with the distribution.
19 // * The name of Intel Corporation may not be used to endorse or promote
20 // products derived from this software without specific prior written
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
27 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
31 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
32 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 // Intel Corporation is the author of this code, and requests that all
36 // problem reports or change requests be submitted to it directly at
37 // http://www.intel.com/software/products/opensource/libraries/num.htm.
40 //==============================================================
41 // 02/03/00 Initial version
42 // 05/26/00 Fix bug when x a double-extended denormal;
43 // if x=0 call error routine, per C9X
44 // 08/15/00 Bundle added after call to __libm_error_support to properly
45 // set [the previously overwritten] GR_Parameter_RESULT.
46 // 01/20/01 Fixed result for x=0
47 // 05/20/02 Cleaned up namespace and sf0 syntax
48 // 01/20/03 Improved performance
51 //==============================================================
52 // int ilogbl( long double x );
54 // Overview of operation
55 //==============================================================
56 // The ilogbl function extracts the exponent of x as an integer
57 // and returns it in r8
59 // ilogbl is similar to logbl but differs in the following ways:
61 // ilogbl: returns INT_MAX
62 // logbl: returns +inf
63 // Nan returns FP_LOGBNAN (which is either INT_MAX or INT_MIN)
64 // ilogbl: returns INT_MAX (7fffffff)
65 // logbl: returns QNAN (quietized SNAN)
66 // 0 returns FP_ILOGB0 (which is either INT_MIN or -INT_MAX)
67 // ilogbl: returns -INT_MAX (80000001)
68 // logbl: returns -inf, raises the divide-by-zero exception,
69 // and calls libm_error_support to set domain error
72 //==============================================================
73 // general registers used:
75 // r36 -> r39 used as parameters to error path
77 // predicate registers used:
79 // floating-point registers used:
97 GR_Parameter_RESULT = r38
98 GR_Parameter_TAG = r39
105 GLOBAL_LIBM_ENTRY(__ieee754_ilogbl)
108 // TrueExp_x = exp(f8) - 0xffff
111 getf.exp rSignexp_x = f8
112 fclass.m p8,p0 = f8, 0x0b // Test for x unorm
113 mov rExpBias = 0xffff // Exponent bias
117 fnorm.s1 fNorm_x = f8
118 mov rExpMask = 0x1ffff // Exponent mask
122 // Form signexp of 2^64 in case need to scale denormal
124 mov rExp_2to64 = 0x1003f
125 fclass.m p6,p9 = f8, 0x1e3 // Test x natval, nan, inf
126 (p8) br.cond.spnt ILOGB_DENORM // Branch if x unorm
131 // Return here from ILOGB_DENORM
133 and rExp_x = rSignexp_x, rExpMask // Get biased exponent
134 fclass.m p7,p10 = f8, 0x07 // Test x zero
139 movl rIntMax = 0x000000007fffffff // Form INT_MAX
143 .pred.rel "mutex",p6,p9
145 (p9) sub r8 = rExp_x, rExpBias // Get true exponent for normal path
146 (p6) fma.s0 fTmp = f8, f8, f0 // Dummy to set Invalid flag
147 (p6) mov r8 = rIntMax // If nan, inf, return INT_MAX
151 (p7) br.cond.spnt ILOGB_ZERO // Branch if x zero
152 (p10) br.ret.sptk b0 // Exit if x not zero
158 // Form 2^64 in case need to scale denormal
159 // Check to see if double-extended denormal
161 setf.exp f2to64 = rExp_2to64
162 fclass.m p8,p0 = fNorm_x, 0x0b
169 fcmp.eq.s0 p7,p0 = f8, f0 // Dummy op to set denormal flag
174 // If double-extended denormal add 64 to exponent bias for scaling
175 // If double-extended denormal form x * 2^64 which is normal
177 (p8) add rExpBias = 64, rExpBias
178 (p8) fmpy.s1 fNorm_x = fNorm_x, f2to64
183 // Logic is the same as normal path but use normalized input
185 getf.exp rSignexp_x = fNorm_x
187 br.cond.sptk ILOGB_COMMON // Return to main path
193 // Return INT_MIN, call error support
196 alloc r32=ar.pfs,1,3,4,0
197 movl rTrialResult = 0x0000000080000000
200 mov GR_Parameter_TAG = 156 // Error code
202 br.cond.sptk __libm_error_region // Call error support
206 GLOBAL_LIBM_END(__ieee754_ilogbl)
209 LOCAL_LIBM_ENTRY(__libm_error_region)
213 add GR_Parameter_Y=-32,sp // Parameter 2 value
215 .save ar.pfs,GR_SAVE_PFS
216 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
220 add sp=-64,sp // Create new stack
222 mov GR_SAVE_GP=gp // Save gp
226 stfe [GR_Parameter_Y] = f0,16 // STORE Parameter 2 on stack
227 add GR_Parameter_X = 16,sp // Parameter 1 address
229 mov GR_SAVE_B0=b0 // Save b0
234 stfe [GR_Parameter_X] = f8 // STORE Parameter 1 on stack
235 add GR_Parameter_RESULT = 0,GR_Parameter_Y // Parameter 3 address
239 stfe [GR_Parameter_Y] = f9 // Store Parameter 3 on stack
240 add GR_Parameter_Y = -16,GR_Parameter_Y
241 br.call.sptk b0=__libm_error_support# // Call error handling function
245 add GR_Parameter_RESULT = 48,sp
251 mov r8 = rTrialResult
253 add sp = 64,sp // Restore stack pointer
254 mov b0 = GR_SAVE_B0 // Restore return address
258 mov gp = GR_SAVE_GP // Restore gp
259 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
263 LOCAL_LIBM_END(__libm_error_region)
266 .type __libm_error_support#,@function
267 .global __libm_error_support#