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/02/00 Initial version
42 // 02/16/00 Modified to conform to C9X
43 // 03/16/00 Improved speed
44 // 04/04/00 Unwind support added
45 // 05/30/00 Fixed bug when x double-extended denormal
46 // 08/15/00 Bundle added after call to __libm_error_support to properly
47 // set [the previously overwritten] GR_Parameter_RESULT.
48 // 05/20/02 Cleaned up namespace and sf0 syntax
49 // 01/20/03 Improved performance
52 //==============================================================
53 // double logb( double x );
55 // Overview of operation
56 //==============================================================
57 // The logb function extracts the exponent of x as an integer in
58 // floating-point format.
59 // logb computes log2 of x as a double
61 // logb is similar to ilogb but differs in the following ways:
63 // ilogb: returns INT_MAX
65 // Nan returns FP_LOGBNAN (which is either INT_MAX or INT_MIN)
66 // ilogb: returns INT_MAX (7fffffff)
67 // logb: returns QNAN (quietized SNAN)
68 // 0 returns FP_ILOGB0 (which is either INT_MIN or -INT_MAX)
69 // ilogb: returns -INT_MAX (80000001)
70 // logb: returns -inf, raises the divide-by-zero exception,
71 // and calls libm_error_support to set domain error
74 //==============================================================
75 // general registers used:
77 // r35 -> r38 used as parameters to error path
79 // predicate registers used:
81 // floating-point registers used:
98 GR_Parameter_RESULT = r37
99 GR_Parameter_TAG = r38
107 GLOBAL_LIBM_ENTRY(logb)
110 // TrueExp_x = exp(f8) - 0xffff
112 // f8 = convert_to_fp (sig))
114 getf.exp rSignexp_x = f8
115 fclass.m p8,p0 = f8, 0x0b // Test for x unorm
116 mov rExpBias = 0xffff // Exponent bias
120 fnorm.s1 fNorm_x = f8
121 mov rExpMask = 0x1ffff // Exponent mask
125 // Form signexp of 2^64 in case need to scale denormal
127 mov rExp_2to64 = 0x1003f
128 fclass.m p6,p0 = f8, 0x1e3 // Test x natval, nan, inf
129 (p8) br.cond.spnt LOGB_DENORM // Branch if x unorm
134 // Return here from LOGB_DENORM
136 and rExp_x = rSignexp_x, rExpMask // Get biased exponent
137 fclass.m p7,p0 = f8, 0x07 // Test x zero
142 // X NAN or INFINITY, return f8 * f8
144 sub rTrueExp_x = rExp_x, rExpBias // Get true exponent
145 (p6) fma.d.s0 f8= f8,f8,f0 // Result if x natval, nan, inf
146 (p6) br.ret.spnt b0 // Exit if x natval, nan, inf
151 setf.sig fExp_in_signif = rTrueExp_x // Exponent as integer in fp
153 (p7) br.cond.spnt LOGB_ZERO
157 // Result can be represented in less than 24 bits, so no precision completer
161 fcvt.xf f8 = fExp_in_signif
162 br.ret.sptk b0 // Exit main path, 0 < |x| < inf
167 // Form 2^64 in case need to scale denormal
168 // Check to see if double-extended denormal
170 setf.exp f2to64 = rExp_2to64
171 fclass.m p8,p0 = fNorm_x, 0x0b
178 fcmp.eq.s0 p7,p0 = f8, f0 // Dummy op to set denormal flag
183 // If double-extended denormal add 64 to exponent bias for scaling
184 // If double-extended denormal form x * 2^64 which is normal
186 (p8) add rExpBias = 64, rExpBias
187 (p8) fmpy.s1 fNorm_x = fNorm_x, f2to64
192 // Logic is the same as normal path but use normalized input
194 getf.exp rSignexp_x = fNorm_x
196 br.cond.sptk LOGB_COMMON // Return to main path
203 // f9 = 1.0/f10 = -1.0/|f8| = -inf
206 alloc r32=ar.pfs,1,2,4,0
207 mov GR_Parameter_TAG = 151 // Error code
208 fmerge.ns f10 = f0,f8
214 frcpa.s0 f9,p6 = f1,f10 // Produce -inf, Z flag
215 br.cond.sptk __libm_error_region // Call error support
219 GLOBAL_LIBM_END(logb)
220 libm_alias_double_other (logb, logb)
223 LOCAL_LIBM_ENTRY(__libm_error_region)
227 add GR_Parameter_Y=-32,sp // Parameter 2 value
229 .save ar.pfs,GR_SAVE_PFS
230 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
234 add sp=-64,sp // Create new stack
236 mov GR_SAVE_GP=gp // Save gp
240 stfd [GR_Parameter_Y] = f0,16 // STORE Parameter 2 on stack
241 add GR_Parameter_X = 16,sp // Parameter 1 address
243 mov GR_SAVE_B0=b0 // Save b0
248 stfd [GR_Parameter_X] = f8 // STORE Parameter 1 on stack
249 add GR_Parameter_RESULT = 0,GR_Parameter_Y // Parameter 3 address
253 stfd [GR_Parameter_Y] = f9 // Store Parameter 3 on stack
254 add GR_Parameter_Y = -16,GR_Parameter_Y
255 br.call.sptk b0=__libm_error_support# // Call error handling function
259 add GR_Parameter_RESULT = 48,sp
265 ldfd f8 = [GR_Parameter_RESULT] // Get return result off stack
267 add sp = 64,sp // Restore stack pointer
268 mov b0 = GR_SAVE_B0 // Restore return address
272 mov gp = GR_SAVE_GP // Restore gp
273 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
277 LOCAL_LIBM_END(__libm_error_region)
280 .type __libm_error_support#,@function
281 .global __libm_error_support#