3 // Copyright (C) 2000, 2001, Intel Corporation
4 // All rights reserved.
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.
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
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
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://developer.intel.com/opensource.
41 //==============================================================
42 // 2/03/00 Initial version
43 // 5/26/00 Fix bug when x a double-extended denormal;
44 // if x=0 call error routine, per C9X
45 // 8/15/00 Bundle added after call to __libm_error_support to properly
46 // set [the previously overwritten] GR_Parameter_RESULT.
47 // 1/20/01 Fixed result for x=0
57 //==============================================================
58 // int = ilogbf(float)
60 // Overview of operation
61 //==============================================================
62 // ilogbf computes log2(x) as an int
63 // and returns it in r8
65 // ilogbf is similar to logbf but differs in the following ways:
67 // ilogbf: returns INT_MAX
68 // logbf: returns +inf
69 // Nan returns FP_ILOGBNAN (which is either INT_MAX or INT_MIN)
70 // ilogbf: returns INT_MAX (7fffffff)
71 // logbf: returns QNAN (quieted SNAN)
72 // 0 returns FP_ILOGB0 (which is either INT_MIN or -INT_MAX)
73 // ilogbf: returns INT_MIN (80000000)
74 // logbf: returns -inf
77 //==============================================================
79 // general local registers:
82 // r38 -> r41 used as parameters to error path
84 // predicate registers used:
90 // floating-point registers used:
93 #include "libm_support.h"
100 GR_Parameter_RESULT = r40
101 GR_Parameter_TAG = r41
110 // Form signexp of 2^64 in case need to scale denormal
112 alloc r32=ar.pfs,1,5,4,0
113 (p0) mov r37 = 0x1003f
114 (p0) fnorm f9 = f8 ;;
117 // Form 2^64 in case need to scale denormal
119 (p0) setf.exp f10 = r37
120 (p0) fclass.m.unc p7, p8 = f8, 0xe3
121 (p0) mov r34 = 0xffff ;;
124 // qnan snan inf norm unorm 0 -+
127 // X ZERO, returns INT_MIN
128 // X INF or NAN, returns INT_MAX
131 (p0) mov r35 = 0x1ffff
132 (p8) fclass.m.unc p6, p8 = f8, 0x07
137 (p7) movl r8 = 0x000000007fffffff ;;
143 (p6) br.cond.spnt L(ILOGB_ZERO) ;;
149 (p8) fclass.m.unc p9, p0 = f9, 0x0b
154 // X NORMAL returns true exponent
157 (p8) getf.exp r33 = f9
161 // If denormal add 64 to exponent bias for scaling
163 (p9) add r34 = 64, r34
165 (p9) br.cond.spnt L(ILOGB_DENORM) ;;
169 (p8) and r36 = r35, r33
175 (p8) sub r8 = r36, r34
177 (p0) br.ret.sptk b0 ;;
181 // Here if x denormal
182 // Form x * 2^64 which is normal
183 // Return to common code
187 br.cond.sptk L(ILOGB_COMMON) ;;
191 // return INT_MIN, call error support
194 mov GR_Parameter_TAG = 158
195 (p6) movl r33 = 0x0000000080000000 ;;
198 ASM_SIZE_DIRECTIVE(ilogbf)
200 .proc __libm_error_region
204 add GR_Parameter_Y=-32,sp // Parameter 2 value
206 .save ar.pfs,GR_SAVE_PFS
207 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
211 add sp=-64,sp // Create new stack
213 mov GR_SAVE_GP=gp // Save gp
216 stfs [GR_Parameter_Y] = FR_Y,16 // Save Parameter 2 on stack
217 add GR_Parameter_X = 16,sp // Parameter 1 address
219 mov GR_SAVE_B0=b0 // Save b0
223 stfs [GR_Parameter_X] = FR_X // Store Parameter 1 on stack
224 add GR_Parameter_RESULT = 0,GR_Parameter_Y
225 nop.b 0 // Parameter 3 address
228 stfs [GR_Parameter_Y] = FR_RESULT // Store Parameter 3 on stack
229 add GR_Parameter_Y = -16,GR_Parameter_Y
230 br.call.sptk b0=__libm_error_support# // Call error handling function
235 add GR_Parameter_RESULT = 48,sp
238 mov r8 = r33 // Store result
240 add sp = 64,sp // Restore stack pointer
241 mov b0 = GR_SAVE_B0 // Restore return address
244 mov gp = GR_SAVE_GP // Restore gp
245 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
246 br.ret.sptk b0 // Return
249 .endp __libm_error_region
250 ASM_SIZE_DIRECTIVE(__libm_error_region)
252 .type __libm_error_support#,@function
253 .global __libm_error_support#