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 Scalb completely reworked and now standalone version
44 // 05/20/02 Cleaned up namespace and sf0 syntax
45 // 02/10/03 Reordered header: .section, .global, .proc, .align
48 //==============================================================
49 // double-extended = scalbl (double-extended x, double-extended n)
50 // input floating point f8 and floating point f9
51 // output floating point f8
53 // Returns x* 2**n using an fma and detects overflow
84 GR_Parameter_RESULT = r37
88 GLOBAL_IEEE754_ENTRY(scalbl)
91 // Is x NAN, INF, ZERO, +-?
94 alloc r32=ar.pfs,0,3,4,0
95 fclass.m.unc p7,p0 = FR_Floating_X, 0xe7 //@snan | @qnan | @inf | @zero
96 addl GR_Scratch = 0x019C3F,r0
99 // Is y a NAN, INF, ZERO, +-?
103 fclass.m.unc p6,p0 = FR_Floating_N, 0xe7 //@snan | @qnan | @inf | @zero
104 addl GR_Scratch1 = 0x063BF,r0
109 // Convert N to a fp integer
114 fnorm.s1 FR_Norm_N = FR_Floating_N
119 fnorm.s1 FR_Norm_X = FR_Floating_X
127 // Branch on special values.
130 setf.exp FR_Big = GR_Scratch
132 (p6) br.cond.spnt SCALBL_NAN_INF_ZERO
135 setf.exp FR_NBig = GR_Scratch1
137 (p7) br.cond.spnt SCALBL_NAN_INF_ZERO
141 // Convert N to a fp integer
145 addl GR_Scratch = 1,r0
146 fcvt.fx.trunc.s1 FR_N_float_int = FR_Norm_N
147 addl GR_NBig = -35000,r0
152 // Put N if a GP register
153 // Convert N_float_int to floating point value
155 // Build the exponent Bias
158 getf.sig GR_N_as_int = FR_N_float_int
159 shl GR_Scratch = GR_Scratch,63
160 addl GR_Big = 35000,r0
163 addl GR_Bias = 0x0FFFF,r0
164 fcvt.xf FR_N_float_int = FR_N_float_int
169 // Catch those fp values that are beyond 2**64-1
174 cmp.ne.unc p9,p10 = GR_N_as_int,GR_Scratch
179 cmp.ge.unc p6, p0 = GR_N_as_int, GR_Big
180 cmp.le.unc p8, p0 = GR_N_as_int, GR_NBig
185 // Is N really an int, only for those non-int indefinites?
189 add GR_N_Biased = GR_Bias,GR_N_as_int
190 (p9) fcmp.neq.unc.s1 p7,p0 = FR_Norm_N, FR_N_float_int
195 // Branch and return if N is not an int.
196 // Main path, create 2**N
199 setf.exp FR_Two_N = GR_N_Biased
204 (p7) frcpa.s0 f8,p11 = f0,f0
209 // Set denormal on denormal input x and denormal input N
213 (p10)fcmp.ge.s1 p6,p8 = FR_Norm_N,f0
218 fcmp.ge.s0 p0,p11 = FR_Floating_X,f0
223 fcmp.ge.s0 p12,p13 = FR_Floating_N,f0
228 // Adjust 2**N if N was very small or very large
233 (p6) fma.s1 FR_Two_N = FR_Big,f1,f0
238 movl GR_Scratch = 0x0000000000033FFF
242 (p8) fma.s1 FR_Two_N = FR_NBig,f1,f0
247 movl GR_Scratch1= 0x0000000000013FFF
250 // Set up necessary status fields
252 // S0 user supplied status
253 // S2 user supplied status + WRE + TD (Overflows)
254 // S3 user supplied status + FZ + TD (Underflows)
268 // Do final operation
271 setf.exp FR_NBig = GR_Scratch
272 fma.s0 FR_Result = FR_Two_N,FR_Norm_X,f0
277 fma.s3 FR_Result3 = FR_Two_N,FR_Norm_X,f0
281 setf.exp FR_Big = GR_Scratch1
282 fma.s2 FR_Result2 = FR_Two_N,FR_Norm_X,f0
286 // Check for overflow or underflow.
288 // S0 user supplied status
289 // S2 user supplied status + WRE + TD (Overflow)
290 // S3 user supplied status + FZ + TD (Underflow)
308 // Is the result zero?
312 fclass.m.unc p6, p0 = FR_Result3, 0x007
317 fcmp.ge.unc.s1 p7, p8 = FR_Result2 , FR_Big
322 // Detect masked underflow - Tiny + Inexact Only
326 (p6) fcmp.neq.unc.s1 p6, p0 = FR_Result , FR_Result2
331 // Is result bigger the allowed range?
332 // Branch out for underflow
335 (p6) addl GR_Tag = 52, r0
336 (p8) fcmp.le.unc.s1 p9, p10 = FR_Result2 , FR_NBig
337 (p6) br.cond.spnt SCALBL_UNDERFLOW
341 // Branch out for overflow
345 (p7) br.cond.spnt SCALBL_OVERFLOW
346 (p9) br.cond.spnt SCALBL_OVERFLOW
350 // Return from main path.
361 // Convert N to a fp integer
364 addl GR_Scratch = 1,r0
365 fcvt.fx.trunc.s1 FR_N_float_int = FR_Norm_N
370 fclass.m.unc p6,p0 = FR_Floating_N, 0xc3 //@snan | @qnan
375 fclass.m.unc p7,p0 = FR_Floating_X, 0xc3 //@snan | @qnan
376 shl GR_Scratch = GR_Scratch,63
380 fclass.m.unc p8,p0 = FR_Floating_N, 0x21 // @inf
385 fclass.m.unc p9,p0 = FR_Floating_N, 0x22 // @-inf
390 // Either X or N is a Nan, return result and possible raise invalid.
394 (p6) fma.s0 FR_Result = FR_Floating_N,FR_Floating_X,f0
398 getf.sig GR_N_as_int = FR_N_float_int
399 (p7) fma.s0 FR_Result = FR_Floating_N,FR_Floating_X,f0
404 // If N + Inf do something special
405 // For N = -Inf, create Int
409 (p8) fma.s0 FR_Result = FR_Floating_X, FR_Floating_N,f0
414 (p9) fnma.s0 FR_Floating_N = FR_Floating_N, f1, f0
419 // If N==-Inf,return x/(-N)
423 (p9) frcpa.s0 FR_Result,p6 = FR_Floating_X,FR_Floating_N
428 // Convert N_float_int to floating point value
431 cmp.ne.unc p9,p0 = GR_N_as_int,GR_Scratch
432 fcvt.xf FR_N_float_int = FR_N_float_int
441 (p9) fcmp.neq.unc.s1 p7,p0 = FR_Norm_N, FR_N_float_int
446 // If N not an int, return NaN and raise invalid.
450 (p7) frcpa.s0 FR_Result,p6 = f0,f0
455 // Always return x in other path.
459 fma.s0 FR_Result = FR_Floating_X,f1,f0
463 GLOBAL_IEEE754_END(scalbl)
470 // Get stack address of N
474 add GR_Parameter_Y=-32,sp
476 .save ar.pfs,GR_SAVE_PFS
477 mov GR_SAVE_PFS=ar.pfs
490 // Store N on stack in correct position
491 // Locate the address of x on stack
494 stfe [GR_Parameter_Y] = FR_Norm_N,16
495 add GR_Parameter_X = 16,sp
501 // Store x on the stack.
502 // Get address for result on stack.
506 stfe [GR_Parameter_X] = FR_Norm_X
507 add GR_Parameter_RESULT = 0,GR_Parameter_Y
511 stfe [GR_Parameter_Y] = FR_Result
512 add GR_Parameter_Y = -16,GR_Parameter_Y
513 br.call.sptk b0=__libm_error_support#
517 // Get location of result on stack
522 add GR_Parameter_RESULT = 48,sp
526 // Get the new result
529 ldfe FR_Result = [GR_Parameter_RESULT]
536 // Restore gp, ar.pfs and return
540 mov ar.pfs = GR_SAVE_PFS
544 LOCAL_LIBM_END(__libm_error_region)
546 .type __libm_error_support#,@function
547 .global __libm_error_support#