initial commit
[glibc.git] / sysdeps / ia64 / fpu / libm_frexpf.S
1 .file "libm_frexpf.s"
2
3
4 // Copyright (c) 2000 - 2003, Intel Corporation
5 // All rights reserved.
6 //
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
10 // met:
11 //
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 //
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.
18 //
19 // * The name of Intel Corporation may not be used to endorse or promote
20 // products derived from this software without specific prior written
21 // permission.
22
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.
34 //
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.
38 //
39 // History
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
48 //
49 // API
50 //==============================================================
51 // float __libm_frexpf(float 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
55 //
56 // int_type = 0 if int is 32 bits
57 // int_type = 1 if int is 64 bits
58 //
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
61 //
62 // Overview of operation
63 //==============================================================
64 // break a floating point x number into fraction and an exponent
65 // The fraction is returned as a float
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.
70 //
71 // The fraction is 0.5 <= fraction < 1.0
72 //
73 // Registers used
74 //==============================================================
75 //
76 // general registers:
77 // r14 exponent bias for x negative
78 // r15 exponent bias for x positive
79 // r16 signexp of x
80 // r17 exponent mask
81 // r18 exponent of x
82 // r19 exponent result
83 // r20 signexp of 2^64
84 // r32 on input contains the 32-bit IEEE float 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
87 //
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
95 //
96 // floating-point registers:
97 // f8 input, output
98 // f9 normalized x
99 // f10 signexp for significand result for x positive
100 // f11 signexp for significand result for x negative
101 // f12 2^64
102
103 .section .text
104 GLOBAL_LIBM_ENTRY(__libm_frexpf)
105
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
111 { .mfi
112 mov r15 = 0x0fffe
113 fclass.m p6,p7 = f8, 0xe7
114 mov r14 = 0x2fffe
115 }
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
119 { .mfi
120 mov r20 = 0x1003f
121 fnorm.s0 f9 = f8
122 nop.i 999 ;;
123 }
124
125 // Move signexp for significand result for x>0 to FP reg
126 // Form 2^64 in case x double-extended denormal
127 { .mmi
128 setf.exp f10 = r15
129 setf.exp f12 = r20
130 nop.i 999 ;;
131 }
132
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
136 { .mfi
137 setf.exp f11 = r14
138 (p7) fcmp.lt.s0 p7,p8 = f8,f0
139 (p6) cmp.eq.unc p10,p11 = r34, r0 ;;
140 }
141
142 // If x NAN, ZERO, INFINITY, set *y=0 and exit
143 { .mmb
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 ;;
147 }
148
149 // Form exponent mask
150 // Test for fnorm(x) denormal, means x double-extended denormal
151 { .mfi
152 mov r17 = 0x1ffff
153 fclass.m p9,p0 = f9, 0x0b
154 nop.i 999 ;;
155 }
156
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
160 { .mfi
161 (p9) add r15 = 64, r15
162 (p9) fmpy.s0 f9 = f9, f12
163 cmp.eq p10,p11 = r34, r0 ;;
164 }
165
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
171
172 // If x>0 form significand result
173 { .mfi
174 nop.m 999
175 (p8) fmerge.se f8 = f10,f9
176 nop.i 999 ;;
177 }
178
179 // Get signexp of normalized x
180 // If x<0 form significand result
181 { .mfi
182 getf.exp r16 = f9
183 (p7) fmerge.se f8 = f11,f9
184 nop.i 999 ;;
185 }
186
187 // Get exp of normalized x
188 // Subtract off bias to get true exponent of x
189 { .mmi
190 and r18 = r17,r16 ;;
191 sub r19 = r18,r15
192 nop.i 999 ;;
193 }
194
195 // Store int *y as a 32-bit integer
196 // Make the value a float
197 { .mfi
198 (p10) st4 [r33] = r19 // Store *y as 32-bit integer
199 fnorm.s.s0 f8 = f8
200 nop.i 999
201 }
202 { .mfb
203 (p11) st8 [r33] = r19 // Store *y as 64-bit integer
204 nop.f 999
205 br.ret.sptk b0 ;;
206 }
207
208 GLOBAL_LIBM_END(__libm_frexpf)