4 // Copyright (c) 2000 - 2003, Intel Corporation
5 // All rights reserved.
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
15 // * Redistributions in binary form must reproduce the above copyright
16 // notice, this list of conditions and the following disclaimer in the
17 // documentation and/or other materials provided with the distribution.
19 // * The name of Intel Corporation may not be used to endorse or promote
20 // products derived from this software without specific prior written
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
27 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
31 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
32 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 // Intel Corporation is the author of this code, and requests that all
36 // problem reports or change requests be submitted to it directly at
37 // http://www.intel.com/software/products/opensource/libraries/num.htm.
40 //==============================================================
41 // 02/02/00 Initial version
42 // 01/26/01 Scalb completely reworked and now standalone version
43 // 05/20/02 Cleaned up namespace and sf0 syntax
44 // 02/10/03 Reordered header: .section, .global, .proc, .align
45 // 08/06/03 Improved performance
48 //==============================================================
49 // float = scalbf (float x, float n)
50 // input floating point f8 and floating point f9
51 // output floating point f8
53 // int_type = 0 if int is 32 bits
54 // int_type = 1 if int is 64 bits
56 // Returns x* 2**n using an fma and detects overflow
61 // Compute biased exponent of result exp_Result = N + exp_X
63 // exp_Result > 0x1007e -> Certain overflow
64 // exp_Result = 0x1007e -> Possible overflow
65 // 0x0ff81 <= exp_Result < 0x1007e -> No over/underflow (main path)
66 // 0x0ff81 - 23 <= exp_Result < 0x0ff81 -> Possible underflow
67 // exp_Result < 0x0ff81 - 23 -> Certain underflow
105 GR_Parameter_RESULT = r37
109 GLOBAL_IEEE754_ENTRY(scalbf)
112 // Is x NAN, INF, ZERO, +-?
113 // Build the exponent Bias
116 getf.exp GR_signexp_N = FR_Floating_N // Get signexp of n
117 fclass.m p6,p0 = FR_Floating_X, 0xe7 // @snan | @qnan | @inf | @zero
118 mov GR_Bias = 0x0ffff
121 mov GR_Big = 35000 // If N this big then certain overflow
122 fcvt.fx.trunc.s1 FR_N_float_int = FR_Floating_N // Get N in significand
128 getf.exp GR_signexp_X = FR_Floating_X // Get signexp of x
129 fclass.m p7,p0 = FR_Floating_N, 0x0b // Test for n=unorm
136 mov GR_exp_mask = 0x1ffff // Exponent mask
137 fnorm.s1 FR_Norm_N = FR_Floating_N
143 // Is n NAN, INF, ZERO, +-?
146 mov GR_big_exp = 0x1003e // Exponent at which n is integer
147 fclass.m p9,p0 = FR_Floating_N, 0xe7 // @snan | @qnan | @inf | @zero
148 mov GR_max_exp = 0x1007e // Exponent of maximum float
155 fnorm.s1 FR_Norm_X = FR_Floating_X
156 (p7) br.cond.spnt SCALBF_N_UNORM // Branch if n=unorm
161 // Main path continues. Also return here from u=unorm path.
162 // Handle special cases if x = Nan, Inf, Zero
165 fcmp.lt.s1 p7,p0 = FR_Floating_N, f0 // Test N negative
166 (p6) br.cond.spnt SCALBF_NAN_INF_ZERO
170 // Handle special cases if n = Nan, Inf, Zero
172 getf.sig GR_N_as_int = FR_N_float_int // Get n from significand
173 fclass.m p8,p0 = FR_Floating_X, 0x0b // Test for x=unorm
174 mov GR_exp_sure_ou = 0x1000e // Exp_N where x*2^N sure over/under
177 mov GR_min_exp = 0x0ff81 // Exponent of minimum float
178 fcvt.xf FR_N_float_int = FR_N_float_int // Convert N to FP integer
179 (p9) br.cond.spnt SCALBF_NAN_INF_ZERO
184 and GR_exp_N = GR_exp_mask, GR_signexp_N // Get exponent of N
185 (p7) sub GR_Big = r0, GR_Big // Limit for N
191 cmp.lt p9,p0 = GR_exp_N, GR_big_exp // N possible non-integer?
192 cmp.ge p6,p0 = GR_exp_N, GR_exp_sure_ou // N certain over/under?
193 (p8) br.cond.spnt SCALBF_X_UNORM // Branch if x=unorm
198 // Main path continues. Also return here from x=unorm path.
199 // Create biased exponent for 2**N
201 (p6) mov GR_N_as_int = GR_Big // Limit N
203 add GR_N_Biased = GR_Bias,GR_N_as_int
209 setf.exp FR_Two_N = GR_N_Biased // Form 2**N
210 (p9) fcmp.neq.unc.s1 p9,p0 = FR_Norm_N, FR_N_float_int // Test if N an integer
211 and GR_exp_X = GR_exp_mask, GR_signexp_X // Get exponent of X
216 // Compute biased result exponent
217 // Branch if N is not an integer
220 add GR_exp_Result = GR_exp_X, GR_N_as_int
221 mov GR_min_den_exp = 0x0ff81 - 23 // Exponent of min denorm float
222 (p9) br.cond.spnt SCALBF_N_NOT_INT
227 // Raise Denormal operand flag with compare
228 // Do final operation
231 cmp.lt p7,p6 = GR_exp_Result, GR_max_exp // Test no overflow
232 fcmp.ge.s0 p0,p11 = FR_Floating_X,FR_Floating_N // Dummy to set denorm
233 cmp.lt p9,p0 = GR_exp_Result, GR_min_den_exp // Test sure underflow
237 fma.s.s0 FR_Result = FR_Two_N,FR_Norm_X,f0
238 (p9) br.cond.spnt SCALBF_UNDERFLOW // Branch if certain underflow
243 (p6) cmp.gt.unc p6,p8 = GR_exp_Result, GR_max_exp // Test sure overflow
244 (p7) cmp.ge.unc p7,p9 = GR_exp_Result, GR_min_exp // Test no over/underflow
245 (p7) br.ret.sptk b0 // Return from main path
250 (p6) br.cond.spnt SCALBF_OVERFLOW // Branch if certain overflow
251 (p8) br.cond.spnt SCALBF_POSSIBLE_OVERFLOW // Branch if possible overflow
252 (p9) br.cond.spnt SCALBF_POSSIBLE_UNDERFLOW // Branch if possible underflow
256 // Here if possible underflow.
257 // Resulting exponent: 0x0ff81-23 <= exp_Result < 0x0ff81
258 SCALBF_POSSIBLE_UNDERFLOW:
260 // Here if possible overflow.
261 // Resulting exponent: 0x1007e = exp_Result
262 SCALBF_POSSIBLE_OVERFLOW:
264 // Set up necessary status fields
266 // S0 user supplied status
267 // S2 user supplied status + WRE + TD (Overflows)
268 // S3 user supplied status + FZ + TD (Underflows)
271 mov GR_pos_ov_limit = 0x1007f // Exponent for positive overflow
276 mov GR_neg_ov_limit = 0x3007f // Exponent for negative overflow
283 // Do final operation with s2 and s3
286 setf.exp FR_NBig = GR_neg_ov_limit
287 fma.s.s3 FR_Result3 = FR_Two_N,FR_Norm_X,f0
291 setf.exp FR_Big = GR_pos_ov_limit
292 fma.s.s2 FR_Result2 = FR_Two_N,FR_Norm_X,f0
297 // Check for overflow or underflow.
314 // Is the result zero?
318 fclass.m p6, p0 = FR_Result3, 0x007
323 fcmp.ge.s1 p7, p8 = FR_Result2 , FR_Big
329 // Detect masked underflow - Tiny + Inexact Only
333 (p6) fcmp.neq.unc.s1 p6, p0 = FR_Result , FR_Result2
339 // Is result bigger the allowed range?
340 // Branch out for underflow
344 (p8) fcmp.le.unc.s1 p9, p10 = FR_Result2 , FR_NBig
345 (p6) br.cond.spnt SCALBF_UNDERFLOW
350 // Branch out for overflow
353 (p7) br.cond.spnt SCALBF_OVERFLOW
354 (p9) br.cond.spnt SCALBF_OVERFLOW
355 br.ret.sptk b0 // Return from main path.
359 // Here if result overflows
362 alloc r32=ar.pfs,3,0,4,0
363 addl GR_Tag = 55, r0 // Set error tag for overflow
364 br.cond.sptk __libm_error_region // Call error support for overflow
368 // Here if result underflows
371 alloc r32=ar.pfs,3,0,4,0
372 addl GR_Tag = 56, r0 // Set error tag for underflow
373 br.cond.sptk __libm_error_region // Call error support for underflow
380 // Before entry, N has been converted to a fp integer in significand of
383 // Convert N_float_int to floating point value
386 getf.sig GR_N_as_int = FR_N_float_int
387 fclass.m p6,p0 = FR_Floating_N, 0xc3 //@snan | @qnan
391 addl GR_Scratch = 1,r0
392 fcvt.xf FR_N_float_int = FR_N_float_int
399 fclass.m p7,p0 = FR_Floating_X, 0xc3 //@snan | @qnan
400 shl GR_Scratch = GR_Scratch,63
406 fclass.m p8,p0 = FR_Floating_N, 0x21 // @inf
411 fclass.m p9,p0 = FR_Floating_N, 0x22 // @-inf
417 // Either X or N is a Nan, return result and possible raise invalid.
421 (p6) fma.s.s0 FR_Result = FR_Floating_N,FR_Floating_X,f0
428 (p7) fma.s.s0 FR_Result = FR_Floating_N,FR_Floating_X,f0
434 // If N + Inf do something special
435 // For N = -Inf, create Int
439 (p8) fma.s.s0 FR_Result = FR_Floating_X, FR_Floating_N,f0
444 (p9) fnma.s.s0 FR_Floating_N = FR_Floating_N, f1, f0
450 // If N==-Inf,return x/(-N)
453 cmp.ne p7,p0 = GR_N_as_int,GR_Scratch
454 (p9) frcpa.s0 FR_Result,p0 = FR_Floating_X,FR_Floating_N
464 (p7) fcmp.neq.unc.s1 p7,p0 = FR_Norm_N, FR_N_float_int
470 // If N not an int, return NaN and raise invalid.
474 (p7) frcpa.s0 FR_Result,p0 = f0,f0
480 // Always return x in other path.
484 fma.s.s0 FR_Result = FR_Floating_X,f1,f0
490 // Return NaN and raise invalid.
494 frcpa.s0 FR_Result,p0 = f0,f0
502 getf.exp GR_signexp_N = FR_Norm_N // Get signexp of normalized n
503 fcvt.fx.trunc.s1 FR_N_float_int = FR_Norm_N // Get N in significand
504 br.cond.sptk SCALBF_COMMON1 // Return to main path
511 getf.exp GR_signexp_X = FR_Norm_X // Get signexp of normalized x
513 br.cond.sptk SCALBF_COMMON2 // Return to main path
517 GLOBAL_IEEE754_END(scalbf)
518 LOCAL_LIBM_ENTRY(__libm_error_region)
521 // Get stack address of N
525 add GR_Parameter_Y=-32,sp
527 .save ar.pfs,GR_SAVE_PFS
528 mov GR_SAVE_PFS=ar.pfs
541 // Store N on stack in correct position
542 // Locate the address of x on stack
545 stfs [GR_Parameter_Y] = FR_Norm_N,16
546 add GR_Parameter_X = 16,sp
552 // Store x on the stack.
553 // Get address for result on stack.
557 stfs [GR_Parameter_X] = FR_Norm_X
558 add GR_Parameter_RESULT = 0,GR_Parameter_Y
562 stfs [GR_Parameter_Y] = FR_Result
563 add GR_Parameter_Y = -16,GR_Parameter_Y
564 br.call.sptk b0=__libm_error_support#
568 // Get location of result on stack
571 add GR_Parameter_RESULT = 48,sp
577 // Get the new result
580 ldfs FR_Result = [GR_Parameter_RESULT]
587 // Restore gp, ar.pfs and return
591 mov ar.pfs = GR_SAVE_PFS
595 LOCAL_LIBM_END(__libm_error_region)
597 .type __libm_error_support#,@function
598 .global __libm_error_support#