d94ad095a04dde2ae23704ac46867fdef965f9ed
[jlayton/glibc.git] / sysdeps / ia64 / fpu / libm_frexp4f.S
1 .file "libm_frexp_4f.s"
2
3 // Copyright (c) 2000, 2001, Intel Corporation
4 // All rights reserved.
5 // 
6 // Contributed 2/2/2000 by John Harrison, Ted Kubaska, Bob Norin, Shane Story,
7 // and Ping Tak Peter Tang of the Computational Software Lab, Intel Corporation.
8 // 
9 // WARRANTY DISCLAIMER
10 // 
11 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
12 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
13 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
14 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS 
15 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
16 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
17 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
18 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
19 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
20 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
21 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
22 // 
23 // Intel Corporation is the author of this code, and requests that all
24 // problem reports or change requests be submitted to it directly at 
25 // http://developer.intel.com/opensource.
26 //
27 // History
28 //==============================================================
29 // 2/02/00: Initial version
30 // 3/20/00: Improved speed
31 // 6/01/00: Fixed bug when x a double-extended denormal
32 // 12/08/00 Corrected label on .endp
33 //
34 // API
35 //==============================================================
36 // float frexp(float x, int* y)
37 // float __libm_frexp_4f(float x, int* y)
38 //   where int* y is a 32-bit integer
39 //
40 // Overview of operation
41 //==============================================================
42 // break a floating point x number into fraction and an exponent
43 // The fraction is returned as a float
44 // The exponent is returned as an integer pointed to by y
45 //    This is a true (not a biased exponent) but 0fffe is subtracted
46 //    as a bias instead of 0xffff. This is because the fraction returned
47 //    is between 0.5 and 1.0, not the expected IEEE range.
48 //
49 // The fraction is 0.5 <= fraction < 1.0
50 //
51 // Registers used
52 //==============================================================
53
54 // general registers: 
55 // r14  exponent bias for x negative
56 // r15  exponent bias for x positive
57 // r16  signexp of x
58 // r17  exponent mask
59 // r18  exponent of x
60 // r19  exponent result
61 // r20  signexp of 2^64
62 // r32  on input contains the 32-bit IEEE float that is in f8
63 // r33  on input pointer to 32-bit integer for exponent
64
65 // predicate registers:
66 // p6   set if x is Nan, zero, or infinity
67 // p7   set if x negative
68 // p8   set if x positive
69 // p9   set if x double-extended denormal
70
71 // floating-point registers:
72 // f8  input, output
73 // f9  normalized x
74 // f10 signexp for significand result for x positive
75 // f11 signexp for significand result for x negative
76 // f12 2^64
77
78 #include "libm_support.h"
79
80 .align 32
81 .global __libm_frexp_4f#
82
83 .section .text
84 .proc  __libm_frexp_4f#
85 .align 32
86
87 __libm_frexp_4f: 
88
89 // Set signexp for significand result for x>0
90 // If x is a NaN, zero, or infinity, return it.
91 // Put 0 in the int pointer.
92 // x NAN, ZERO, INFINITY?
93 // Set signexp for significand result for x<0
94 { .mfi
95 (p0)    mov         r15 = 0x0fffe
96 (p0)    fclass.m.unc p6,p0 = f8, 0xe7
97 (p0)    mov         r14 = 0x2fffe
98 }
99 // Form signexp of 2^64 in case x double-extended denormal
100 // Save the normalized value of input in f9
101 // The normalization also sets fault flags and takes faults if necessary
102 { .mfi
103 (p0)    mov         r20 = 0x1003f
104 (p0)    fnorm       f9 = f8 
105         nop.i 999 ;;
106 }
107
108 // Move signexp for significand result for x>0 to FP reg
109 // Form 2^64 in case x double-extended denormal
110 { .mmi
111 (p0)    setf.exp    f10 = r15
112 (p0)    setf.exp    f12 = r20
113         nop.i 999 ;;
114 }
115
116 // Move signexp for significand result for x<0 to FP reg
117 // If x NAN, ZERO, INFINITY, set *y=0 as a 32-bit integer, and exit
118 { .mmb
119 (p0)    setf.exp    f11 = r14
120 (p6)    st4         [r33] = r0
121 (p6)    br.ret.spnt b0 ;;
122 }
123
124 // Form exponent mask
125 // p7 if x<0, else p8
126 { .mfi
127 (p0)    mov         r17 = 0x1ffff
128 (p0)    fcmp.lt.unc p7,p8 = f8,f0
129         nop.i 999 ;;
130 }
131
132 // Test for fnorm(x) denormal, means x double-extended denormal
133 { .mfi
134         nop.m 999
135 (p0)    fclass.m.unc p9,p0 = f9, 0x0b
136         nop.i 999 ;;
137 }
138
139 // If x double-extended denormal add 64 to exponent bias for scaling
140 // If x double-extended denormal multiply x * 2^64 which is normal
141 { .mfi
142 (p9)    add         r15 = 64, r15
143 (p9)    fmpy        f9 = f9, f12
144         nop.i 999 ;;
145 }
146
147 // true exponent stored to int pointer
148 // the bias is treated as 0xfffe instead of 
149 // normal 0xffff because we want the significand
150 // to be in the range <=0.5 sig < 1.0
151 // Store the value of the exponent at the pointer in r33
152
153 // If x>0 form significand result 
154 { .mfi
155         nop.m 999
156 (p8)    fmerge.se   f8 = f10,f9
157         nop.i 999  ;;
158 }
159
160 // Get signexp of normalized x
161 // If x<0 form significand result 
162 { .mfi
163 (p0)    getf.exp    r16 = f9
164 (p7)    fmerge.se   f8 = f11,f9
165         nop.i 999  ;;
166 }
167
168 // Get exp of normalized x
169 // Subtract off bias to get true exponent of x
170 { .mmi
171 (p0)    and         r18 = r17,r16 ;;
172 (p0)    sub         r19 = r18,r15
173         nop.i 999  ;;
174 }
175
176 // Store int y as a 32-bit integer
177 // Make the value a float
178 { .mfb
179 (p0)    st4         [r33] = r19
180 (p0)    fnorm.s     f8 = f8
181 (p0)    br.ret.sptk b0 ;;
182 }
183
184 .endp __libm_frexp_4f
185 ASM_SIZE_DIRECTIVE(__libm_frexp_4f)