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
46 // 08/06/03 Improved performance
49 //==============================================================
50 // long double = scalbl (long double x, long double n)
51 // input floating point f8 and floating point f9
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
62 // Compute biased exponent of result exp_Result = N + exp_X
64 // exp_Result > 0x13ffe -> Certain overflow
65 // exp_Result = 0x13ffe -> Possible overflow
66 // 0x0c001 <= exp_Result < 0x13ffe -> No over/underflow (main path)
67 // 0x0c001 - 63 <= exp_Result < 0x0c001 -> Possible underflow
68 // exp_Result < 0x0c001 - 63 -> Certain underflow
106 GR_Parameter_RESULT = r37
110 GLOBAL_IEEE754_ENTRY(scalbl)
113 // Is x NAN, INF, ZERO, +-?
114 // Build the exponent Bias
117 getf.exp GR_signexp_N = FR_Floating_N // Get signexp of n
118 fclass.m p6,p0 = FR_Floating_X, 0xe7 // @snan | @qnan | @inf | @zero
119 mov GR_Bias = 0x0ffff
122 mov GR_Big = 35000 // If N this big then certain overflow
123 fcvt.fx.trunc.s1 FR_N_float_int = FR_Floating_N // Get N in significand
129 getf.exp GR_signexp_X = FR_Floating_X // Get signexp of x
130 fclass.m p7,p0 = FR_Floating_N, 0x0b // Test for n=unorm
137 mov GR_exp_mask = 0x1ffff // Exponent mask
138 fnorm.s1 FR_Norm_N = FR_Floating_N
144 // Is n NAN, INF, ZERO, +-?
147 mov GR_big_exp = 0x1003e // Exponent at which n is integer
148 fclass.m p9,p0 = FR_Floating_N, 0xe7 // @snan | @qnan | @inf | @zero
149 mov GR_max_exp = 0x13ffe // Exponent of maximum long double
156 fnorm.s1 FR_Norm_X = FR_Floating_X
157 (p7) br.cond.spnt SCALBL_N_UNORM // Branch if n=unorm
162 // Main path continues. Also return here from u=unorm path.
163 // Handle special cases if x = Nan, Inf, Zero
166 fcmp.lt.s1 p7,p0 = FR_Floating_N, f0 // Test N negative
167 (p6) br.cond.spnt SCALBL_NAN_INF_ZERO
171 // Handle special cases if n = Nan, Inf, Zero
173 getf.sig GR_N_as_int = FR_N_float_int // Get n from significand
174 fclass.m p8,p0 = FR_Floating_X, 0x0b // Test for x=unorm
175 mov GR_exp_sure_ou = 0x1000e // Exp_N where x*2^N sure over/under
178 mov GR_min_exp = 0x0c001 // Exponent of minimum long double
179 fcvt.xf FR_N_float_int = FR_N_float_int // Convert N to FP integer
180 (p9) br.cond.spnt SCALBL_NAN_INF_ZERO
185 and GR_exp_N = GR_exp_mask, GR_signexp_N // Get exponent of N
186 (p7) sub GR_Big = r0, GR_Big // Limit for N
192 cmp.lt p9,p0 = GR_exp_N, GR_big_exp // N possible non-integer?
193 cmp.ge p6,p0 = GR_exp_N, GR_exp_sure_ou // N certain over/under?
194 (p8) br.cond.spnt SCALBL_X_UNORM // Branch if x=unorm
199 // Main path continues. Also return here from x=unorm path.
200 // Create biased exponent for 2**N
202 (p6) mov GR_N_as_int = GR_Big // Limit N
204 add GR_N_Biased = GR_Bias,GR_N_as_int
210 setf.exp FR_Two_N = GR_N_Biased // Form 2**N
211 (p9) fcmp.neq.unc.s1 p9,p0 = FR_Norm_N, FR_N_float_int // Test if N an integer
212 and GR_exp_X = GR_exp_mask, GR_signexp_X // Get exponent of X
217 // Compute biased result exponent
218 // Branch if N is not an integer
221 add GR_exp_Result = GR_exp_X, GR_N_as_int
222 mov GR_min_den_exp = 0x0c001 - 63 // Exp of min denorm long dble
223 (p9) br.cond.spnt SCALBL_N_NOT_INT
228 // Raise Denormal operand flag with compare
229 // Do final operation
232 cmp.lt p7,p6 = GR_exp_Result, GR_max_exp // Test no overflow
233 fcmp.ge.s0 p0,p11 = FR_Floating_X,FR_Floating_N // Dummy to set denorm
234 cmp.lt p9,p0 = GR_exp_Result, GR_min_den_exp // Test sure underflow
238 fma.s0 FR_Result = FR_Two_N,FR_Norm_X,f0
239 (p9) br.cond.spnt SCALBL_UNDERFLOW // Branch if certain underflow
244 (p6) cmp.gt.unc p6,p8 = GR_exp_Result, GR_max_exp // Test sure overflow
245 (p7) cmp.ge.unc p7,p9 = GR_exp_Result, GR_min_exp // Test no over/underflow
246 (p7) br.ret.sptk b0 // Return from main path
251 (p6) br.cond.spnt SCALBL_OVERFLOW // Branch if certain overflow
252 (p8) br.cond.spnt SCALBL_POSSIBLE_OVERFLOW // Branch if possible overflow
253 (p9) br.cond.spnt SCALBL_POSSIBLE_UNDERFLOW // Branch if possible underflow
257 // Here if possible underflow.
258 // Resulting exponent: 0x0c001-63 <= exp_Result < 0x0c001
259 SCALBL_POSSIBLE_UNDERFLOW:
261 // Here if possible overflow.
262 // Resulting exponent: 0x13ffe = exp_Result
263 SCALBL_POSSIBLE_OVERFLOW:
265 // Set up necessary status fields
267 // S0 user supplied status
268 // S2 user supplied status + WRE + TD (Overflows)
269 // S3 user supplied status + FZ + TD (Underflows)
272 mov GR_pos_ov_limit = 0x13fff // Exponent for positive overflow
277 mov GR_neg_ov_limit = 0x33fff // Exponent for negative overflow
284 // Do final operation with s2 and s3
287 setf.exp FR_NBig = GR_neg_ov_limit
288 fma.s3 FR_Result3 = FR_Two_N,FR_Norm_X,f0
292 setf.exp FR_Big = GR_pos_ov_limit
293 fma.s2 FR_Result2 = FR_Two_N,FR_Norm_X,f0
298 // Check for overflow or underflow.
315 // Is the result zero?
319 fclass.m p6, p0 = FR_Result3, 0x007
324 fcmp.ge.s1 p7, p8 = FR_Result2 , FR_Big
330 // Detect masked underflow - Tiny + Inexact Only
334 (p6) fcmp.neq.unc.s1 p6, p0 = FR_Result , FR_Result2
340 // Is result bigger the allowed range?
341 // Branch out for underflow
345 (p8) fcmp.le.unc.s1 p9, p10 = FR_Result2 , FR_NBig
346 (p6) br.cond.spnt SCALBL_UNDERFLOW
351 // Branch out for overflow
354 (p7) br.cond.spnt SCALBL_OVERFLOW
355 (p9) br.cond.spnt SCALBL_OVERFLOW
356 br.ret.sptk b0 // Return from main path.
360 // Here if result overflows
363 alloc r32=ar.pfs,3,0,4,0
364 addl GR_Tag = 51, r0 // Set error tag for overflow
365 br.cond.sptk __libm_error_region // Call error support for overflow
369 // Here if result underflows
372 alloc r32=ar.pfs,3,0,4,0
373 addl GR_Tag = 52, r0 // Set error tag for underflow
374 br.cond.sptk __libm_error_region // Call error support for underflow
381 // Before entry, N has been converted to a fp integer in significand of
384 // Convert N_float_int to floating point value
387 getf.sig GR_N_as_int = FR_N_float_int
388 fclass.m p6,p0 = FR_Floating_N, 0xc3 //@snan | @qnan
392 addl GR_Scratch = 1,r0
393 fcvt.xf FR_N_float_int = FR_N_float_int
400 fclass.m p7,p0 = FR_Floating_X, 0xc3 //@snan | @qnan
401 shl GR_Scratch = GR_Scratch,63
407 fclass.m p8,p0 = FR_Floating_N, 0x21 // @inf
412 fclass.m p9,p0 = FR_Floating_N, 0x22 // @-inf
418 // Either X or N is a Nan, return result and possible raise invalid.
422 (p6) fma.s0 FR_Result = FR_Floating_N,FR_Floating_X,f0
429 (p7) fma.s0 FR_Result = FR_Floating_N,FR_Floating_X,f0
435 // If N + Inf do something special
436 // For N = -Inf, create Int
440 (p8) fma.s0 FR_Result = FR_Floating_X, FR_Floating_N,f0
445 (p9) fnma.s0 FR_Floating_N = FR_Floating_N, f1, f0
451 // If N==-Inf,return x/(-N)
454 cmp.ne p7,p0 = GR_N_as_int,GR_Scratch
455 (p9) frcpa.s0 FR_Result,p0 = FR_Floating_X,FR_Floating_N
465 (p7) fcmp.neq.unc.s1 p7,p0 = FR_Norm_N, FR_N_float_int
471 // If N not an int, return NaN and raise invalid.
475 (p7) frcpa.s0 FR_Result,p0 = f0,f0
481 // Always return x in other path.
485 fma.s0 FR_Result = FR_Floating_X,f1,f0
491 // Return NaN and raise invalid.
495 frcpa.s0 FR_Result,p0 = f0,f0
503 getf.exp GR_signexp_N = FR_Norm_N // Get signexp of normalized n
504 fcvt.fx.trunc.s1 FR_N_float_int = FR_Norm_N // Get N in significand
505 br.cond.sptk SCALBL_COMMON1 // Return to main path
512 getf.exp GR_signexp_X = FR_Norm_X // Get signexp of normalized x
514 br.cond.sptk SCALBL_COMMON2 // Return to main path
518 GLOBAL_IEEE754_END(scalbl)
519 LOCAL_LIBM_ENTRY(__libm_error_region)
522 // Get stack address of N
526 add GR_Parameter_Y=-32,sp
528 .save ar.pfs,GR_SAVE_PFS
529 mov GR_SAVE_PFS=ar.pfs
542 // Store N on stack in correct position
543 // Locate the address of x on stack
546 stfe [GR_Parameter_Y] = FR_Norm_N,16
547 add GR_Parameter_X = 16,sp
553 // Store x on the stack.
554 // Get address for result on stack.
558 stfe [GR_Parameter_X] = FR_Norm_X
559 add GR_Parameter_RESULT = 0,GR_Parameter_Y
563 stfe [GR_Parameter_Y] = FR_Result
564 add GR_Parameter_Y = -16,GR_Parameter_Y
565 br.call.sptk b0=__libm_error_support#
569 // Get location of result on stack
572 add GR_Parameter_RESULT = 48,sp
578 // Get the new result
581 ldfe FR_Result = [GR_Parameter_RESULT]
588 // Restore gp, ar.pfs and return
592 mov ar.pfs = GR_SAVE_PFS
596 LOCAL_LIBM_END(__libm_error_region)
598 .type __libm_error_support#,@function
599 .global __libm_error_support#