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 // 03/20/00 Improved speed
43 // 06/01/00 Fixed bug when x a double-extended denormal
44 // 12/08/00 Corrected label on .endp
45 // 01/23/02 Added handling for int 32 or 64 bits
46 // 05/20/02 Cleaned up namespace and sf0 syntax
47 // 02/10/03 Reordered header: .section, .global, .proc, .align
50 //==============================================================
51 // double __libm_frexp(double x, int* y, int int_type)
52 // input floating point f8, pointer to y (r33), int int_type (r34)
53 // output floating point f8, returns the fraction of x, 0.5 <= fraction < 1.0
54 // output int* y, returns the true exponent of x
56 // int_type = 0 if int is 32 bits
57 // int_type = 1 if int is 64 bits
59 // int* y is returned as a 32 bit integer if int_type = 0
60 // int* y is returned as a 64 bit integer if int_type = 1
62 // Overview of operation
63 //==============================================================
64 // break a floating point x number into fraction and an exponent
65 // The fraction is returned as a double
66 // The exponent is returned as an integer pointed to by y
67 // This is a true (not a biased exponent) but 0fffe is subtracted
68 // as a bias instead of 0xffff. This is because the fraction returned
69 // is between 0.5 and 1.0, not the expected IEEE range.
71 // The fraction is 0.5 <= fraction < 1.0
74 //==============================================================
77 // r14 exponent bias for x negative
78 // r15 exponent bias for x positive
82 // r19 exponent result
83 // r20 signexp of 2^64
84 // r32 on input contains the 64-bit IEEE double that is in f8
85 // r33 on input pointer to 32-bit or 64-bit integer for exponent
86 // r34 on input contains 0 if output int is 32 bits, else output int is 64 bits
88 // predicate registers:
89 // p6 set if x is Nan, zero, or infinity
90 // p7 set if x negative
91 // p8 set if x positive
92 // p9 set if x double-extended denormal
93 // p10 set if int_type = 0, 32-bit integer
94 // p11 set if int_type = 1, 64-bit integer
96 // floating-point registers:
99 // f10 signexp for significand result for x positive
100 // f11 signexp for significand result for x negative
104 GLOBAL_LIBM_ENTRY(__libm_frexp)
106 // Set signexp for significand result for x>0
107 // If x is a NaN, zero, or infinity, return it.
108 // Put 0 in the int pointer.
109 // x NAN, ZERO, INFINITY?
110 // Set signexp for significand result for x<0
113 fclass.m p6,p7 = f8, 0xe7
116 // Form signexp of 2^64 in case x double-extended denormal
117 // Save the normalized value of input in f9
118 // The normalization also sets fault flags and takes faults if necessary
125 // Move signexp for significand result for x>0 to FP reg
126 // Form 2^64 in case x double-extended denormal
133 // Move signexp for significand result for x<0 to FP reg
134 // p7 if x<0, else p8
135 // If x=0,nan,inf, set p10 if output int to be 32 bits, or set p11 if 64 bits
138 (p7) fcmp.lt.s0 p7,p8 = f8,f0
139 (p6) cmp.eq.unc p10,p11 = r34, r0 ;;
142 // If x NAN, ZERO, INFINITY, set *y=0 and exit
144 (p10) st4 [r33] = r0 // Store *y=0 as 32-bit integer
145 (p11) st8 [r33] = r0 // Store *y=0 as 64-bit integer
146 (p6) br.ret.spnt b0 ;;
149 // Form exponent mask
150 // Test for fnorm(x) denormal, means x double-extended denormal
153 fclass.m p9,p0 = f9, 0x0b
157 // If x double-extended denormal add 64 to exponent bias for scaling
158 // If x double-extended denormal multiply x * 2^64 which is normal
159 // Set p10 if output int to be 32 bits, or set p11 if 64 bits
161 (p9) add r15 = 64, r15
162 (p9) fmpy.s0 f9 = f9, f12
163 cmp.eq p10,p11 = r34, r0 ;;
166 // true exponent stored to int pointer
167 // the bias is treated as 0xfffe instead of
168 // normal 0xffff because we want the significand
169 // to be in the range <=0.5 sig < 1.0
170 // Store the value of the exponent at the pointer in r33
172 // If x>0 form significand result
175 (p8) fmerge.se f8 = f10,f9
179 // Get signexp of normalized x
180 // If x<0 form significand result
183 (p7) fmerge.se f8 = f11,f9
187 // Get exp of normalized x
188 // Subtract off bias to get true exponent of x
195 // Store int *y as a 32-bit integer
196 // Make the value a double
198 (p10) st4 [r33] = r19 // Store *y as 32-bit integer
203 (p11) st8 [r33] = r19 // Store *y as 64-bit integer
208 GLOBAL_LIBM_END(__libm_frexp)