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 Scalb completely reworked and now standalone version
46 //==============================================================
47 // double-extended = scalbl (double-extended x, double-extended n)
48 // input floating point f8 and floating point f9
49 // output floating point f8
51 // Returns x* 2**n using an fma and detects overflow
56 #include "libm_support.h"
84 GR_Parameter_RESULT = r37
96 .global __ieee754_scalbl
97 .type __ieee754_scalbl,@function
102 // Is x NAN, INF, ZERO, +-?
105 alloc r32=ar.pfs,0,3,4,0
106 fclass.m.unc p7,p0 = FR_Floating_X, 0xe7 //@snan | @qnan | @inf | @zero
107 addl GR_Scratch = 0x019C3F,r0
110 // Is y a NAN, INF, ZERO, +-?
114 fclass.m.unc p6,p0 = FR_Floating_N, 0xe7 //@snan | @qnan | @inf | @zero
115 addl GR_Scratch1 = 0x063BF,r0
120 // Convert N to a fp integer
125 fnorm.s1 FR_Norm_N = FR_Floating_N
130 fnorm.s1 FR_Norm_X = FR_Floating_X
138 // Branch on special values.
141 setf.exp FR_Big = GR_Scratch
143 (p6) br.cond.spnt L(SCALBL_NAN_INF_ZERO)
146 setf.exp FR_NBig = GR_Scratch1
148 (p7) br.cond.spnt L(SCALBL_NAN_INF_ZERO)
152 // Convert N to a fp integer
156 addl GR_Scratch = 1,r0
157 fcvt.fx.trunc.s1 FR_N_float_int = FR_Norm_N
158 addl GR_NBig = -35000,r0
163 // Put N if a GP register
164 // Convert N_float_int to floating point value
166 // Build the exponent Bias
169 getf.sig GR_N_as_int = FR_N_float_int
170 shl GR_Scratch = GR_Scratch,63
171 addl GR_Big = 35000,r0
174 addl GR_Bias = 0x0FFFF,r0
175 fcvt.xf FR_N_float_int = FR_N_float_int
180 // Catch those fp values that are beyond 2**64-1
185 cmp.ne.unc p9,p10 = GR_N_as_int,GR_Scratch
190 cmp.ge.unc p6, p0 = GR_N_as_int, GR_Big
191 cmp.le.unc p8, p0 = GR_N_as_int, GR_NBig
196 // Is N really an int, only for those non-int indefinites?
200 add GR_N_Biased = GR_Bias,GR_N_as_int
201 (p9) fcmp.neq.unc.s1 p7,p0 = FR_Norm_N, FR_N_float_int
206 // Branch and return if N is not an int.
207 // Main path, create 2**N
210 setf.exp FR_Two_N = GR_N_Biased
215 (p7) frcpa f8,p11 = f0,f0
220 // Set denormal on denormal input x and denormal input N
224 (p10)fcmp.ge.s1 p6,p8 = FR_Norm_N,f0
229 fcmp.ge.s0 p0,p11 = FR_Floating_X,f0
234 fcmp.ge.s0 p12,p13 = FR_Floating_N,f0
239 // Adjust 2**N if N was very small or very large
244 (p6) fma.s1 FR_Two_N = FR_Big,f1,f0
249 (p0) movl GR_Scratch = 0x0000000000033FFF
253 (p8) fma.s1 FR_Two_N = FR_NBig,f1,f0
258 (p0) movl GR_Scratch1= 0x0000000000013FFF
261 // Set up necessary status fields
263 // S0 user supplied status
264 // S2 user supplied status + WRE + TD (Overflows)
265 // S3 user supplied status + FZ + TD (Underflows)
269 (p0) fsetc.s3 0x7F,0x41
274 (p0) fsetc.s2 0x7F,0x42
279 // Do final operation
282 setf.exp FR_NBig = GR_Scratch
283 fma.s0 FR_Result = FR_Two_N,FR_Norm_X,f0
288 fma.s3 FR_Result3 = FR_Two_N,FR_Norm_X,f0
292 setf.exp FR_Big = GR_Scratch1
293 fma.s2 FR_Result2 = FR_Two_N,FR_Norm_X,f0
297 // Check for overflow or underflow.
299 // S0 user supplied status
300 // S2 user supplied status + WRE + TD (Overflow)
301 // S3 user supplied status + FZ + TD (Underflow)
319 // Is the result zero?
323 fclass.m.unc p6, p0 = FR_Result3, 0x007
328 fcmp.ge.unc.s1 p7, p8 = FR_Result2 , FR_Big
333 // Detect masked underflow - Tiny + Inexact Only
337 (p6) fcmp.neq.unc.s1 p6, p0 = FR_Result , FR_Result2
342 // Is result bigger the allowed range?
343 // Branch out for underflow
346 (p6) addl GR_Tag = 52, r0
347 (p8) fcmp.le.unc.s1 p9, p10 = FR_Result2 , FR_NBig
348 (p6) br.cond.spnt L(SCALBL_UNDERFLOW)
352 // Branch out for overflow
356 (p7) br.cond.spnt L(SCALBL_OVERFLOW)
357 (p9) br.cond.spnt L(SCALBL_OVERFLOW)
361 // Return from main path.
369 L(SCALBL_NAN_INF_ZERO):
372 // Convert N to a fp integer
375 addl GR_Scratch = 1,r0
376 fcvt.fx.trunc.s1 FR_N_float_int = FR_Norm_N
381 fclass.m.unc p6,p0 = FR_Floating_N, 0xc3 //@snan | @qnan
386 fclass.m.unc p7,p0 = FR_Floating_X, 0xc3 //@snan | @qnan
387 shl GR_Scratch = GR_Scratch,63
391 fclass.m.unc p8,p0 = FR_Floating_N, 0x21 // @inf
396 fclass.m.unc p9,p0 = FR_Floating_N, 0x22 // @-inf
401 // Either X or N is a Nan, return result and possible raise invalid.
405 (p6) fma.s0 FR_Result = FR_Floating_N,FR_Floating_X,f0
409 getf.sig GR_N_as_int = FR_N_float_int
410 (p7) fma.s0 FR_Result = FR_Floating_N,FR_Floating_X,f0
415 // If N + Inf do something special
416 // For N = -Inf, create Int
420 (p8) fma.s0 FR_Result = FR_Floating_X, FR_Floating_N,f0
425 (p9) fnma.s0 FR_Floating_N = FR_Floating_N, f1, f0
430 // If N==-Inf,return x/(-N)
434 (p9) frcpa.s0 FR_Result,p6 = FR_Floating_X,FR_Floating_N
439 // Convert N_float_int to floating point value
442 cmp.ne.unc p9,p0 = GR_N_as_int,GR_Scratch
443 fcvt.xf FR_N_float_int = FR_N_float_int
452 (p9) fcmp.neq.unc.s1 p7,p0 = FR_Norm_N, FR_N_float_int
457 // If N not an int, return NaN and raise invalid.
461 (p7) frcpa.s0 FR_Result,p6 = f0,f0
466 // Always return x in other path.
470 fma.s0 FR_Result = FR_Floating_X,f1,f0
475 ASM_SIZE_DIRECTIVE(scalbl)
477 ASM_SIZE_DIRECTIVE(__ieee754_scalbl)
479 .proc __libm_error_region
486 // Get stack address of N
490 add GR_Parameter_Y=-32,sp
492 .save ar.pfs,GR_SAVE_PFS
493 mov GR_SAVE_PFS=ar.pfs
506 // Store N on stack in correct position
507 // Locate the address of x on stack
510 stfe [GR_Parameter_Y] = FR_Norm_N,16
511 add GR_Parameter_X = 16,sp
517 // Store x on the stack.
518 // Get address for result on stack.
522 stfe [GR_Parameter_X] = FR_Norm_X
523 add GR_Parameter_RESULT = 0,GR_Parameter_Y
527 stfe [GR_Parameter_Y] = FR_Result
528 add GR_Parameter_Y = -16,GR_Parameter_Y
529 br.call.sptk b0=__libm_error_support#
533 // Get location of result on stack
538 add GR_Parameter_RESULT = 48,sp
542 // Get the new result
545 ldfe FR_Result = [GR_Parameter_RESULT]
552 // Restore gp, ar.pfs and return
556 mov ar.pfs = GR_SAVE_PFS
560 .endp __libm_error_region
561 ASM_SIZE_DIRECTIVE(__libm_error_region)
563 .type __libm_error_support#,@function
564 .global __libm_error_support#