1 .file "libm_scalblnf.s"
4 // Copyright (c) 2001 - 2003, Intel Corporation
5 // All rights reserved.
7 // Contributed 2001 by the Intel Numerics Group, 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://www.intel.com/software/products/opensource/libraries/num.htm.
41 //==============================================================
42 // 08/03/01 Initial version
43 // 08/23/01 Corrected error tag number
44 // 02/06/02 Corrected to handle 32- or 64-bit integers
45 // 05/20/02 Cleaned up namespace and sf0 syntax
46 // 02/10/03 Reordered header: .section, .global, .proc, .align
49 //==============================================================
50 // float = __libm_scalblnf (float x, long int n, int long_int_type)
51 // input floating point f8 and long int n (r33)
52 // input long_int_type = 0 if long int defined as 32 bits, = 1 if 64 bits
54 // output floating point f8
57 // Returns x* 2**n using an fma and detects overflow
85 GR_Parameter_RESULT = r37
89 GLOBAL_LIBM_ENTRY(__libm_scalblnf)
92 // Is x NAN, INF, ZERO, +-?
93 // Build the exponent Bias
96 alloc r32=ar.pfs,3,0,4,0
97 fclass.m.unc p7,p0 = FR_Floating_X, 0xe7 //@snan | @qnan | @inf | @zero
98 addl GR_Bias = 0x0FFFF,r0
105 // Do we need to sign extend input (long_int_type = 0)?
108 cmp.eq.unc p6,p0 = r33,r0
109 fnorm.s1 FR_Norm_X = FR_Floating_X
110 cmp.eq.unc p8,p9 = r34,r0
115 (p9) mov GR_N_as_int = r33 // Get n directly if long int 64 bits
116 (p8) sxt4 GR_N_as_int = r33 // Sign extend n if long int 32 bits
123 // Branch and return special values.
128 addl GR_Big = 35000,r0
130 add GR_N_Biased = GR_Bias,GR_N_as_int
133 addl GR_NBig = -35000,r0
134 (p7) fma.s.s0 FR_Result = FR_Floating_X,f1, f0
139 // Build the exponent Bias
140 // Return x when N = 0
143 setf.exp FR_Two_N = GR_N_Biased
145 addl GR_Scratch1 = 0x063BF,r0
148 addl GR_Scratch = 0x019C3F,r0
149 (p6) fma.s.s0 FR_Result = FR_Floating_X,f1, f0
158 // Raise Denormal operand flag with compare
159 // Main path, create 2**N
162 setf.exp FR_NBig = GR_Scratch1
164 cmp.ge.unc p6, p0 = GR_N_as_int, GR_Big
167 setf.exp FR_Big = GR_Scratch
168 fcmp.ge.s0 p0,p11 = FR_Floating_X,f0
169 cmp.le.unc p8, p0 = GR_N_as_int, GR_NBig
173 // Adjust 2**N if N was very small or very large
177 (p6) fma.s1 FR_Two_N = FR_Big,f1,f0
182 movl GR_Scratch = 0x000000000003007F
188 (p8) fma.s1 FR_Two_N = FR_NBig,f1,f0
193 movl GR_Scratch1= 0x000000000001007F
196 // Set up necessary status fields
198 // S0 user supplied status
199 // S2 user supplied status + WRE + TD (Overflows)
200 // S3 user supplied status + FZ + TD (Underflows)
214 // Do final operation
217 setf.exp FR_NBig = GR_Scratch
218 fma.s.s0 FR_Result = FR_Two_N,FR_Norm_X,f0
223 fma.s.s3 FR_Result3 = FR_Two_N,FR_Norm_X,f0
227 setf.exp FR_Big = GR_Scratch1
228 fma.s.s2 FR_Result2 = FR_Two_N,FR_Norm_X,f0
232 // Check for overflow or underflow.
248 // Is the result zero?
252 fclass.m.unc p6, p0 = FR_Result3, 0x007
256 addl GR_Tag = 205, r0
257 fcmp.ge.unc.s1 p7, p8 = FR_Result2 , FR_Big
262 // Detect masked underflow - Tiny + Inexact Only
266 (p6) fcmp.neq.unc.s1 p6, p0 = FR_Result , FR_Result2
271 // Is result bigger the allowed range?
272 // Branch out for underflow
275 (p6) addl GR_Tag = 206, r0
276 (p8) fcmp.le.unc.s1 p9, p10 = FR_Result2 , FR_NBig
277 (p6) br.cond.spnt scalbnf_UNDERFLOW
281 // Branch out for overflow
285 (p7) br.cond.spnt scalbnf_OVERFLOW
286 (p9) br.cond.spnt scalbnf_OVERFLOW
290 // Return from main path.
298 GLOBAL_LIBM_END(__libm_scalblnf)
305 // Get stack address of N
309 add GR_Parameter_Y=-32,sp
311 .save ar.pfs,GR_SAVE_PFS
312 mov GR_SAVE_PFS=ar.pfs
325 // Store N on stack in correct position
326 // Locate the address of x on stack
329 st8 [GR_Parameter_Y] = GR_N_as_int,16
330 add GR_Parameter_X = 16,sp
336 // Store x on the stack.
337 // Get address for result on stack.
341 stfs [GR_Parameter_X] = FR_Norm_X
342 add GR_Parameter_RESULT = 0,GR_Parameter_Y
346 stfs [GR_Parameter_Y] = FR_Result
347 add GR_Parameter_Y = -16,GR_Parameter_Y
348 br.call.sptk b0=__libm_error_support#
352 // Get location of result on stack
357 add GR_Parameter_RESULT = 48,sp
361 // Get the new result
364 ldfs FR_Result = [GR_Parameter_RESULT]
371 // Restore gp, ar.pfs and return
375 mov ar.pfs = GR_SAVE_PFS
379 LOCAL_LIBM_END(__libm_error_region)
381 .type __libm_error_support#,@function
382 .global __libm_error_support#