aca64b958a84d408b5fb33045759b1a4eff5aed9
[jlayton/glibc.git] / sysdeps / ia64 / fpu / s_truncl.S
1 .file "truncl.s"
2
3 // Copyright (c) 2000, 2001, Intel Corporation
4 // All rights reserved.
5 // 
6 // Contributed 7/7/2000 by John Harrison, Cristina Iordache, Ted Kubaska,
7 // Bob Norin, Shane Story, and Ping Tak Peter Tang of the
8 // Computational Software Lab, Intel Corporation.
9 // 
10 // WARRANTY DISCLAIMER
11 // 
12 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
13 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
14 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS 
16 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
17 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
18 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
19 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
20 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
21 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
22 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
23 // 
24 // Intel Corporation is the author of this code, and requests that all
25 // problem reports or change requests be submitted to it directly at 
26 // http://developer.intel.com/opensource.
27 //
28 .align 32
29 .global truncl#
30
31 .section .text
32 .proc  truncl#
33 .align 32
34
35 // History
36 //==============================================================
37 // 7/7/00: Created 
38 //==============================================================
39
40 // API
41 //==============================================================
42 // long double truncl(float x)
43 //==============================================================
44
45 #include "libm_support.h"
46
47 // general input registers:  
48 TRUNC_GR_FFFF      = r14
49 TRUNC_GR_signexp   = r15
50 TRUNC_GR_exponent  = r16
51 TRUNC_GR_expmask   = r17
52 TRUNC_GR_bigexp    = r18
53
54 // floating-point registers:
55 // f8, f9, f11, f12
56
57 // predicate registers used: 
58 // p6, p7, p8, p9, p10, p11
59
60 // Overview of operation
61 //==============================================================
62 // long double truncl(long double x)
63 // Return an integer value (represented as a long double) less than or 
64 // equal to x in magnitude.
65 // This is x rounded toward zero to an integral value.
66 //==============================================================
67
68 // double_extended
69 // if the exponent is > 1003e => 3F(true) = 63(decimal)
70 // we have a significand of 64 bits 1.63-bits.
71 // If we multiply by 2^63, we no longer have a fractional part
72 // So input is an integer value already.
73
74 // double
75 // if the exponent is >= 10033 => 34(true) = 52(decimal)
76 // 34 + 3ff = 433
77 // we have a significand of 53 bits 1.52-bits. (implicit 1)
78 // If we multiply by 2^52, we no longer have a fractional part
79 // So input is an integer value already.
80
81 // single
82 // if the exponent is > 10016 => 17(true) = 23(decimal)
83 // we have a significand of 24 bits 1.23-bits. (implicit 1)
84 // If we multiply by 2^23, we no longer have a fractional part
85 // So input is an integer value already.
86
87 truncl:
88
89 { .mfi
90       getf.exp         TRUNC_GR_signexp  = f8
91       fcvt.fx.trunc.s1 f9  = f8
92       addl             TRUNC_GR_bigexp = 0x1003e, r0
93 }
94 { .mfi
95       mov              TRUNC_GR_FFFF    = 0x0FFFF
96       fnorm            f11  = f8
97       mov              TRUNC_GR_expmask    = 0x1FFFF 
98 };;
99 //    get the exponent of x
100 //    convert x to integer in signficand of f9 
101 //    Normalize x - this will raise invalid on SNaNs, the
102 //    denormal operand flag - and possibly a spurious U flag
103 //    get exponent only mask (will exclude sign bit)
104
105 { .mfi
106       nop.m            0
107       fclass.m         p7,p8 = f8, 0x0b  
108       nop.i            0
109 }
110 { .mfi
111       nop.m            0
112       fcmp.eq.unc.s1   p9,p0 = f8,f0
113       nop.i      0       
114 };;
115 //    fclass to set p7 if unnorm 
116 { .mmi
117       and              TRUNC_GR_exponent = TRUNC_GR_signexp, TRUNC_GR_expmask ;;
118 (p8)  cmp.ge.unc       p10,p11 = TRUNC_GR_exponent, TRUNC_GR_bigexp
119 (p8)  cmp.ne.unc       p6,p0 = TRUNC_GR_exponent, TRUNC_GR_signexp
120 };;
121 //    Get the exponent of x
122 //    Test if exponent such that result already an integer
123 //    Test if x < 0
124 { .mmi
125 (p9)  cmp.eq.andcm     p10,p11 = r0, r0 
126 (p6)  cmp.lt.unc       p6,p0 = TRUNC_GR_exponent, TRUNC_GR_FFFF
127       nop.i 0 
128 };;
129 //    If -1 < x < 0, set p6, turn off p10 and p11, and set result to -0.0
130 { .mfb
131 (p6)  cmp.eq.andcm     p10,p11 = r0, r0 
132 (p6)  fmerge.s         f8 = f8, f0
133       nop.b 0
134 };;
135 //    If not a unnorm, set p10 if x already is a big int, nan, or inf?
136 //    If not a unnorm, set p10 if x already is a big int, nan, or inf?
137 .pred.rel "mutex",p10,p11    
138 { .mfb
139       nop.m            0
140 (p11) fcvt.xf          f8   = f9 
141       nop.b            0 
142 }
143 { .mfb
144       nop.m            0
145 (p10) fma.s1           f8   = f11,f1,f0 
146 (p8)  br.ret.sptk      b0 
147 };;
148 //    If not a unnorm and not an big int, nan,or +/-inf convert signficand
149 //    back to f8.
150 //    If not a unorm  and a big int, nan, or +/-inf, return fnorm'd x 
151 //    If not a unorm, Return
152 //    If unnorm, get the exponent again - perhaps it wasn't a denorm. 
153 { .mfb
154 (p7)  getf.exp         TRUNC_GR_signexp  = f11
155 (p7)  fcvt.fx.trunc.s1 f12   = f11 
156       nop.b 0
157 };;
158 { .mfb
159       and              TRUNC_GR_exponent = TRUNC_GR_signexp, TRUNC_GR_expmask
160       fcmp.lt.unc.s1   p9,p0 = f8,f0
161       nop.b            0
162 };;
163 { .mfb
164       cmp.ge.unc       p10,p11 = TRUNC_GR_exponent, TRUNC_GR_bigexp
165       nop.f            0
166       nop.b            0
167 };;
168 // If a unnorm, check to see if value is already a big int. 
169 { .mfb
170       nop.m 0
171 (p11) fcvt.xf          f8   = f12 
172       nop.b 0
173 }
174 { .mfi
175       nop.m 0
176 (p10) fma.s1           f8   = f11,f1,f0 
177       nop.i 0
178 };;
179 { .mfb
180       nop.m 0
181 (p9)  fmerge.ns        f8   = f1,f8 
182       br.ret.sptk      b0 
183 };;
184 // If so return it. Otherwise, return (fcvt.xf(fcvt.fx.trunc(x)))
185 // Make sure the result is negative if it should be - that is
186 // negative(denormal) -> -0.
187 .endp truncl
188 ASM_SIZE_DIRECTIVE(truncl)