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.
11 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
12 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
13 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
14 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
15 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
16 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
17 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
18 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
19 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
20 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 // Intel Corporation is the author of this code, and requests that all
24 // problem reports or change requests be submitted to it directly at
25 // http://developer.intel.com/opensource.
28 //==============================================================
29 // 2/02/00 Initial version
30 // 1/26/01 scalbnf completely reworked and now standalone version
33 //==============================================================
34 // float = scalbnf (float x, int n)
35 // input floating point f8 and int n (r33)
36 // output floating point f8
38 // Returns x* 2**n using an fma and detects overflow
43 #include "libm_support.h"
68 GR_Parameter_RESULT = r37
81 // Is x NAN, INF, ZERO, +-?
82 // Build the exponent Bias
85 alloc r32=ar.pfs,1,2,4,0
86 fclass.m.unc p7,p0 = FR_Floating_X, 0xe7 //@snan | @qnan | @inf | @zero
87 addl GR_Bias = 0x0FFFF,r0
96 cmp.eq.unc p6,p0 = r33,r0
97 fnorm.s1 FR_Norm_X = FR_Floating_X
98 sxt4 GR_N_as_int = r33
104 // Branch and return special values.
109 addl GR_Big = 35000,r0
111 add GR_N_Biased = GR_Bias,GR_N_as_int
114 addl GR_NBig = -35000,r0
115 (p7) fma.s.s0 FR_Result = FR_Floating_X,f1, f0
120 // Build the exponent Bias
121 // Return x when N = 0
124 setf.exp FR_Two_N = GR_N_Biased
126 addl GR_Scratch1 = 0x063BF,r0
129 addl GR_Scratch = 0x019C3F,r0
130 (p6) fma.s.s0 FR_Result = FR_Floating_X,f1, f0
139 // Raise Denormal operand flag with compare
140 // Main path, create 2**N
143 setf.exp FR_NBig = GR_Scratch1
145 cmp.ge.unc p6, p0 = GR_N_as_int, GR_Big
148 setf.exp FR_Big = GR_Scratch
149 fcmp.ge.s0 p0,p11 = FR_Floating_X,f0
150 cmp.le.unc p8, p0 = GR_N_as_int, GR_NBig
154 // Adjust 2**N if N was very small or very large
158 (p6) fma.s1 FR_Two_N = FR_Big,f1,f0
163 (p0) movl GR_Scratch = 0x000000000003007F
169 (p8) fma.s1 FR_Two_N = FR_NBig,f1,f0
174 (p0) movl GR_Scratch1= 0x000000000001007F
177 // Set up necessary status fields
179 // S0 user supplied status
180 // S2 user supplied status + WRE + TD (Overflows)
181 // S3 user supplied status + FZ + TD (Underflows)
185 (p0) fsetc.s3 0x7F,0x41
190 (p0) fsetc.s2 0x7F,0x42
195 // Do final operation
198 setf.exp FR_NBig = GR_Scratch
199 fma.s.s0 FR_Result = FR_Two_N,FR_Norm_X,f0
204 fma.s.s3 FR_Result3 = FR_Two_N,FR_Norm_X,f0
208 setf.exp FR_Big = GR_Scratch1
209 fma.s.s2 FR_Result2 = FR_Two_N,FR_Norm_X,f0
213 // Check for overflow or underflow.
229 // Is the result zero?
233 fclass.m.unc p6, p0 = FR_Result3, 0x007
237 addl GR_Tag = 178, r0
238 fcmp.ge.unc.s1 p7, p8 = FR_Result2 , FR_Big
243 // Detect masked underflow - Tiny + Inexact Only
247 (p6) fcmp.neq.unc.s1 p6, p0 = FR_Result , FR_Result2
252 // Is result bigger the allowed range?
253 // Branch out for underflow
256 (p6) addl GR_Tag = 179, r0
257 (p8) fcmp.le.unc.s1 p9, p10 = FR_Result2 , FR_NBig
258 (p6) br.cond.spnt L(scalbnf_UNDERFLOW)
262 // Branch out for overflow
266 (p7) br.cond.spnt L(scalbnf_OVERFLOW)
267 (p9) br.cond.spnt L(scalbnf_OVERFLOW)
271 // Return from main path.
280 ASM_SIZE_DIRECTIVE(scalbnf)
281 .proc __libm_error_region
285 L(scalbnf_UNDERFLOW):
288 // Get stack address of N
292 add GR_Parameter_Y=-32,sp
294 .save ar.pfs,GR_SAVE_PFS
295 mov GR_SAVE_PFS=ar.pfs
308 // Store N on stack in correct position
309 // Locate the address of x on stack
312 st8 [GR_Parameter_Y] = GR_N_as_int,16
313 add GR_Parameter_X = 16,sp
319 // Store x on the stack.
320 // Get address for result on stack.
324 stfs [GR_Parameter_X] = FR_Norm_X
325 add GR_Parameter_RESULT = 0,GR_Parameter_Y
329 stfs [GR_Parameter_Y] = FR_Result
330 add GR_Parameter_Y = -16,GR_Parameter_Y
331 br.call.sptk b0=__libm_error_support#
335 // Get location of result on stack
340 add GR_Parameter_RESULT = 48,sp
344 // Get the new result
347 ldfs FR_Result = [GR_Parameter_RESULT]
354 // Restore gp, ar.pfs and return
358 mov ar.pfs = GR_SAVE_PFS
362 .endp __libm_error_region
363 ASM_SIZE_DIRECTIVE(__libm_error_region)
365 .type __libm_error_support#,@function
366 .global __libm_error_support#