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/02/00 Initial version
43 // 1/26/01 scalbnf completely reworked and now standalone version
46 //==============================================================
47 // float = scalbnf (float x, int n)
48 // input floating point f8 and int n (r33)
49 // output floating point f8
51 // Returns x* 2**n using an fma and detects overflow
56 #include "libm_support.h"
81 GR_Parameter_RESULT = r37
94 // Is x NAN, INF, ZERO, +-?
95 // Build the exponent Bias
98 alloc r32=ar.pfs,1,2,4,0
99 fclass.m.unc p7,p0 = FR_Floating_X, 0xe7 //@snan | @qnan | @inf | @zero
100 addl GR_Bias = 0x0FFFF,r0
109 cmp.eq.unc p6,p0 = r33,r0
110 fnorm.s1 FR_Norm_X = FR_Floating_X
111 sxt4 GR_N_as_int = r33
117 // Branch and return special values.
122 addl GR_Big = 35000,r0
124 add GR_N_Biased = GR_Bias,GR_N_as_int
127 addl GR_NBig = -35000,r0
128 (p7) fma.s.s0 FR_Result = FR_Floating_X,f1, f0
133 // Build the exponent Bias
134 // Return x when N = 0
137 setf.exp FR_Two_N = GR_N_Biased
139 addl GR_Scratch1 = 0x063BF,r0
142 addl GR_Scratch = 0x019C3F,r0
143 (p6) fma.s.s0 FR_Result = FR_Floating_X,f1, f0
152 // Raise Denormal operand flag with compare
153 // Main path, create 2**N
156 setf.exp FR_NBig = GR_Scratch1
158 cmp.ge.unc p6, p0 = GR_N_as_int, GR_Big
161 setf.exp FR_Big = GR_Scratch
162 fcmp.ge.s0 p0,p11 = FR_Floating_X,f0
163 cmp.le.unc p8, p0 = GR_N_as_int, GR_NBig
167 // Adjust 2**N if N was very small or very large
171 (p6) fma.s1 FR_Two_N = FR_Big,f1,f0
176 (p0) movl GR_Scratch = 0x000000000003007F
182 (p8) fma.s1 FR_Two_N = FR_NBig,f1,f0
187 (p0) movl GR_Scratch1= 0x000000000001007F
190 // Set up necessary status fields
192 // S0 user supplied status
193 // S2 user supplied status + WRE + TD (Overflows)
194 // S3 user supplied status + FZ + TD (Underflows)
198 (p0) fsetc.s3 0x7F,0x41
203 (p0) fsetc.s2 0x7F,0x42
208 // Do final operation
211 setf.exp FR_NBig = GR_Scratch
212 fma.s.s0 FR_Result = FR_Two_N,FR_Norm_X,f0
217 fma.s.s3 FR_Result3 = FR_Two_N,FR_Norm_X,f0
221 setf.exp FR_Big = GR_Scratch1
222 fma.s.s2 FR_Result2 = FR_Two_N,FR_Norm_X,f0
226 // Check for overflow or underflow.
242 // Is the result zero?
246 fclass.m.unc p6, p0 = FR_Result3, 0x007
250 addl GR_Tag = 178, r0
251 fcmp.ge.unc.s1 p7, p8 = FR_Result2 , FR_Big
256 // Detect masked underflow - Tiny + Inexact Only
260 (p6) fcmp.neq.unc.s1 p6, p0 = FR_Result , FR_Result2
265 // Is result bigger the allowed range?
266 // Branch out for underflow
269 (p6) addl GR_Tag = 179, r0
270 (p8) fcmp.le.unc.s1 p9, p10 = FR_Result2 , FR_NBig
271 (p6) br.cond.spnt L(scalbnf_UNDERFLOW)
275 // Branch out for overflow
279 (p7) br.cond.spnt L(scalbnf_OVERFLOW)
280 (p9) br.cond.spnt L(scalbnf_OVERFLOW)
284 // Return from main path.
293 ASM_SIZE_DIRECTIVE(scalbnf)
294 .proc __libm_error_region
298 L(scalbnf_UNDERFLOW):
301 // Get stack address of N
305 add GR_Parameter_Y=-32,sp
307 .save ar.pfs,GR_SAVE_PFS
308 mov GR_SAVE_PFS=ar.pfs
321 // Store N on stack in correct position
322 // Locate the address of x on stack
325 st8 [GR_Parameter_Y] = GR_N_as_int,16
326 add GR_Parameter_X = 16,sp
332 // Store x on the stack.
333 // Get address for result on stack.
337 stfs [GR_Parameter_X] = FR_Norm_X
338 add GR_Parameter_RESULT = 0,GR_Parameter_Y
342 stfs [GR_Parameter_Y] = FR_Result
343 add GR_Parameter_Y = -16,GR_Parameter_Y
344 br.call.sptk b0=__libm_error_support#
348 // Get location of result on stack
353 add GR_Parameter_RESULT = 48,sp
357 // Get the new result
360 ldfs FR_Result = [GR_Parameter_RESULT]
367 // Restore gp, ar.pfs and return
371 mov ar.pfs = GR_SAVE_PFS
375 .endp __libm_error_region
376 ASM_SIZE_DIRECTIVE(__libm_error_region)
378 .type __libm_error_support#,@function
379 .global __libm_error_support#