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 ldexpf 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 // float __libm_ldexpf (float 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_ldexpf)
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
103 // Is integer type 32 bits?
106 cmp.eq p6,p0 = r33,r0
107 fnorm.s1 FR_Norm_X = FR_Floating_X
108 cmp.eq p8,p9 = r34,r0
112 // Sign extend N if int is 32 bits
114 (p9) mov GR_N_as_int = r33 // Copy N if int is 64 bits
116 (p8) sxt4 GR_N_as_int = r33 // Sign extend N if int is 32 bits
121 // Branch and return special values.
126 addl GR_Big = 35000,r0
128 add GR_N_Biased = GR_Bias,GR_N_as_int
131 addl GR_NBig = -35000,r0
132 (p7) fma.s.s0 FR_Result = FR_Floating_X,f1, f0
137 // Build the exponent Bias
138 // Return x when N = 0
141 setf.exp FR_Two_N = GR_N_Biased
143 addl GR_Scratch1 = 0x063BF,r0
146 addl GR_Scratch = 0x019C3F,r0
147 (p6) fma.s.s0 FR_Result = FR_Floating_X,f1, f0
156 // Raise Denormal operand flag with compare
157 // Main path, create 2**N
160 setf.exp FR_NBig = GR_Scratch1
162 cmp.ge p6, p0 = GR_N_as_int, GR_Big
165 setf.exp FR_Big = GR_Scratch
166 fcmp.ge.s0 p0,p11 = FR_Floating_X,f0
167 cmp.le p8, p0 = GR_N_as_int, GR_NBig
171 // Adjust 2**N if N was very small or very large
175 (p6) fma.s1 FR_Two_N = FR_Big,f1,f0
180 movl GR_Scratch = 0x000000000003007F
186 (p8) fma.s1 FR_Two_N = FR_NBig,f1,f0
191 movl GR_Scratch1= 0x000000000001007F
194 // Set up necessary status fields
196 // S0 user supplied status
197 // S2 user supplied status + WRE + TD (Overflows)
198 // S3 user supplied status + FZ + TD (Underflows)
212 // Do final operation
215 setf.exp FR_NBig = GR_Scratch
216 fma.s.s0 FR_Result = FR_Two_N,FR_Norm_X,f0
221 fma.s.s3 FR_Result3 = FR_Two_N,FR_Norm_X,f0
225 setf.exp FR_Big = GR_Scratch1
226 fma.s.s2 FR_Result2 = FR_Two_N,FR_Norm_X,f0
230 // Check for overflow or underflow.
246 // Is the result zero?
250 fclass.m p6, p0 = FR_Result3, 0x007
254 addl GR_Tag = 148, r0
255 fcmp.ge.s1 p7, p8 = FR_Result2 , FR_Big
260 // Detect masked underflow - Tiny + Inexact Only
264 (p6) fcmp.neq.unc.s1 p6, p0 = FR_Result , FR_Result2
269 // Is result bigger the allowed range?
270 // Branch out for underflow
273 (p6) addl GR_Tag = 149, r0
274 (p8) fcmp.le.unc.s1 p9, p10 = FR_Result2 , FR_NBig
275 (p6) br.cond.spnt LDEXPF_UNDERFLOW
279 // Branch out for overflow
283 (p7) br.cond.spnt LDEXPF_OVERFLOW
284 (p9) br.cond.spnt LDEXPF_OVERFLOW
288 // Return from main path.
296 GLOBAL_LIBM_END(__libm_ldexpf)
303 // Get stack address of N
307 add GR_Parameter_Y=-32,sp
309 .save ar.pfs,GR_SAVE_PFS
310 mov GR_SAVE_PFS=ar.pfs
323 // Store N on stack in correct position
324 // Locate the address of x on stack
327 st8 [GR_Parameter_Y] = GR_N_as_int,16
328 add GR_Parameter_X = 16,sp
334 // Store x on the stack.
335 // Get address for result on stack.
339 stfs [GR_Parameter_X] = FR_Norm_X
340 add GR_Parameter_RESULT = 0,GR_Parameter_Y
344 stfs [GR_Parameter_Y] = FR_Result
345 add GR_Parameter_Y = -16,GR_Parameter_Y
346 br.call.sptk b0=__libm_error_support#
350 // Get location of result on stack
355 add GR_Parameter_RESULT = 48,sp
359 // Get the new result
362 ldfs FR_Result = [GR_Parameter_RESULT]
369 // Restore gp, ar.pfs and return
373 mov ar.pfs = GR_SAVE_PFS
377 LOCAL_LIBM_END(__libm_error_region)
379 .type __libm_error_support#,@function
380 .global __libm_error_support#