4 // Copyright (c) 2000 - 2003, Intel Corporation
5 // All rights reserved.
7 // Contributed 2000 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 // 02/02/00 Initial version
43 // 01/26/01 Scalbn completely reworked and now standalone version
44 // 01/04/02 Added handling for int 32 or 64 bits
45 // 05/20/02 Cleaned up namespace and sf0 syntax
46 // 02/10/03 Reordered header: .section, .global, .proc, .align
49 //==============================================================
50 // double __libm_scalbn (double x, int n, int int_type)
51 // input floating point f8 and int n (r33), int int_type (r34)
52 // output floating point f8
54 // int_type = 0 if int is 32 bits
55 // int_type = 1 if int is 64 bits
57 // Returns x* 2**n using an fma and detects overflow
85 GR_Parameter_RESULT = r37
89 GLOBAL_LIBM_ENTRY(__libm_scalbn)
92 // Is x NAN, INF, ZERO, +-?
93 // Build the exponent Bias
96 alloc r32=ar.pfs,3,0,4,0
97 fclass.m p7,p0 = FR_Floating_X, 0xe7 //@snan | @qnan | @inf | @zero
98 addl GR_Bias = 0x0FFFF,r0
104 // Is integer type 32 bits?
107 cmp.eq p6,p0 = r33,r0
108 fnorm.s1 FR_Norm_X = FR_Floating_X
109 cmp.eq p8,p9 = r34,r0
113 // Sign extend N if int is 32 bits
115 (p9) mov GR_N_as_int = r33 // Copy N if int is 64 bits
117 (p8) sxt4 GR_N_as_int = r33 // Sign extend N if int is 32 bits
122 // Branch and return special values.
127 addl GR_Big = 35000,r0
129 add GR_N_Biased = GR_Bias,GR_N_as_int
132 addl GR_NBig = -35000,r0
133 (p7) fma.d.s0 FR_Result = FR_Floating_X,f1, f0
138 // Build the exponent Bias
139 // Return x when N = 0
142 setf.exp FR_Two_N = GR_N_Biased
144 addl GR_Scratch1 = 0x063BF,r0
147 addl GR_Scratch = 0x019C3F,r0
148 (p6) fma.d.s0 FR_Result = FR_Floating_X,f1, f0
157 // Raise Denormal operand flag with compare
158 // Main path, create 2**N
161 setf.exp FR_NBig = GR_Scratch1
163 cmp.ge p6, p0 = GR_N_as_int, GR_Big
166 setf.exp FR_Big = GR_Scratch
167 fcmp.ge.s0 p0,p11 = FR_Floating_X,f0
168 cmp.le p8, p0 = GR_N_as_int, GR_NBig
172 // Adjust 2**N if N was very small or very large
176 (p6) fma.s1 FR_Two_N = FR_Big,f1,f0
181 movl GR_Scratch = 0x00000000000303FF
187 (p8) fma.s1 FR_Two_N = FR_NBig,f1,f0
192 movl GR_Scratch1= 0x00000000000103FF
195 // Set up necessary status fields
197 // S0 user supplied status
198 // S2 user supplied status + WRE + TD (Overflows)
199 // S3 user supplied status + FZ + TD (Underflows)
213 // Do final operation
216 setf.exp FR_NBig = GR_Scratch
217 fma.d.s0 FR_Result = FR_Two_N,FR_Norm_X,f0
222 fma.d.s3 FR_Result3 = FR_Two_N,FR_Norm_X,f0
226 setf.exp FR_Big = GR_Scratch1
227 fma.d.s2 FR_Result2 = FR_Two_N,FR_Norm_X,f0
231 // Check for overflow or underflow.
247 // Is the result zero?
251 fclass.m p6, p0 = FR_Result3, 0x007
255 addl GR_Tag = 176, r0
256 fcmp.ge.s1 p7, p8 = FR_Result2 , FR_Big
261 // Detect masked underflow - Tiny + Inexact Only
265 (p6) fcmp.neq.unc.s1 p6, p0 = FR_Result , FR_Result2
270 // Is result bigger the allowed range?
271 // Branch out for underflow
274 (p6) addl GR_Tag = 177, r0
275 (p8) fcmp.le.unc.s1 p9, p10 = FR_Result2 , FR_NBig
276 (p6) br.cond.spnt SCALBN_UNDERFLOW
280 // Branch out for overflow
284 (p7) br.cond.spnt SCALBN_OVERFLOW
285 (p9) br.cond.spnt SCALBN_OVERFLOW
289 // Return from main path.
297 GLOBAL_LIBM_END(__libm_scalbn)
304 // Get stack address of N
308 add GR_Parameter_Y=-32,sp
310 .save ar.pfs,GR_SAVE_PFS
311 mov GR_SAVE_PFS=ar.pfs
324 // Store N on stack in correct position
325 // Locate the address of x on stack
328 st8 [GR_Parameter_Y] = GR_N_as_int,16
329 add GR_Parameter_X = 16,sp
335 // Store x on the stack.
336 // Get address for result on stack.
340 stfd [GR_Parameter_X] = FR_Norm_X
341 add GR_Parameter_RESULT = 0,GR_Parameter_Y
345 stfd [GR_Parameter_Y] = FR_Result
346 add GR_Parameter_Y = -16,GR_Parameter_Y
347 br.call.sptk b0=__libm_error_support#
351 // Get location of result on stack
356 add GR_Parameter_RESULT = 48,sp
360 // Get the new result
363 ldfd FR_Result = [GR_Parameter_RESULT]
370 // Restore gp, ar.pfs and return
374 mov ar.pfs = GR_SAVE_PFS
378 LOCAL_LIBM_END(__libm_error_region)
380 .type __libm_error_support#,@function
381 .global __libm_error_support#