(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / ia64 / fpu / s_truncl.S
blob91bf96ce904860f38e22326cf034adfbdf3ce529
1 .file "truncl.s"
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 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
14 // * Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
17 // * Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
21 // * The name of Intel Corporation may not be used to endorse or promote
22 // products derived from this software without specific prior written
23 // permission.
25 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
26 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
27 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS 
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
33 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
36 // 
37 // Intel Corporation is the author of this code, and requests that all
38 // problem reports or change requests be submitted to it directly at 
39 // http://developer.intel.com/opensource.
41 .align 32
42 .global truncl#
44 .section .text
45 .proc  truncl#
46 .align 32
48 // History
49 //==============================================================
50 // 7/7/00: Created 
51 //==============================================================
53 // API
54 //==============================================================
55 // long double truncl(float x)
56 //==============================================================
58 #include "libm_support.h"
60 // general input registers:  
61 TRUNC_GR_FFFF      = r14
62 TRUNC_GR_signexp   = r15
63 TRUNC_GR_exponent  = r16
64 TRUNC_GR_expmask   = r17
65 TRUNC_GR_bigexp    = r18
67 // floating-point registers:
68 // f8, f9, f11, f12
70 // predicate registers used: 
71 // p6, p7, p8, p9, p10, p11
73 // Overview of operation
74 //==============================================================
75 // long double truncl(long double x)
76 // Return an integer value (represented as a long double) less than or 
77 // equal to x in magnitude.
78 // This is x rounded toward zero to an integral value.
79 //==============================================================
81 // double_extended
82 // if the exponent is > 1003e => 3F(true) = 63(decimal)
83 // we have a significand of 64 bits 1.63-bits.
84 // If we multiply by 2^63, we no longer have a fractional part
85 // So input is an integer value already.
87 // double
88 // if the exponent is >= 10033 => 34(true) = 52(decimal)
89 // 34 + 3ff = 433
90 // we have a significand of 53 bits 1.52-bits. (implicit 1)
91 // If we multiply by 2^52, we no longer have a fractional part
92 // So input is an integer value already.
94 // single
95 // if the exponent is > 10016 => 17(true) = 23(decimal)
96 // we have a significand of 24 bits 1.23-bits. (implicit 1)
97 // If we multiply by 2^23, we no longer have a fractional part
98 // So input is an integer value already.
100 truncl:
102 { .mfi
103       getf.exp         TRUNC_GR_signexp  = f8
104       fcvt.fx.trunc.s1 f9  = f8
105       addl             TRUNC_GR_bigexp = 0x1003e, r0
107 { .mfi
108       mov              TRUNC_GR_FFFF    = 0x0FFFF
109       fnorm            f11  = f8
110       mov              TRUNC_GR_expmask    = 0x1FFFF 
112 //    get the exponent of x
113 //    convert x to integer in signficand of f9 
114 //    Normalize x - this will raise invalid on SNaNs, the
115 //    denormal operand flag - and possibly a spurious U flag
116 //    get exponent only mask (will exclude sign bit)
118 { .mfi
119       nop.m            0
120       fclass.m         p7,p8 = f8, 0x0b  
121       nop.i            0
123 { .mfi
124       nop.m            0
125       fcmp.eq.unc.s1   p9,p0 = f8,f0
126       nop.i      0       
128 //    fclass to set p7 if unnorm 
129 { .mmi
130       and              TRUNC_GR_exponent = TRUNC_GR_signexp, TRUNC_GR_expmask ;;
131 (p8)  cmp.ge.unc       p10,p11 = TRUNC_GR_exponent, TRUNC_GR_bigexp
132 (p8)  cmp.ne.unc       p6,p0 = TRUNC_GR_exponent, TRUNC_GR_signexp
134 //    Get the exponent of x
135 //    Test if exponent such that result already an integer
136 //    Test if x < 0
137 { .mmi
138 (p9)  cmp.eq.andcm     p10,p11 = r0, r0 
139 (p6)  cmp.lt.unc       p6,p0 = TRUNC_GR_exponent, TRUNC_GR_FFFF
140       nop.i 0 
142 //    If -1 < x < 0, set p6, turn off p10 and p11, and set result to -0.0
143 { .mfb
144 (p6)  cmp.eq.andcm     p10,p11 = r0, r0 
145 (p6)  fmerge.s         f8 = f8, f0
146       nop.b 0
148 //    If not a unnorm, set p10 if x already is a big int, nan, or inf?
149 //    If not a unnorm, set p10 if x already is a big int, nan, or inf?
150 .pred.rel "mutex",p10,p11    
151 { .mfb
152       nop.m            0
153 (p11) fcvt.xf          f8   = f9 
154       nop.b            0 
156 { .mfb
157       nop.m            0
158 (p10) fma.s1           f8   = f11,f1,f0 
159 (p8)  br.ret.sptk      b0 
161 //    If not a unnorm and not an big int, nan,or +/-inf convert signficand
162 //    back to f8.
163 //    If not a unorm  and a big int, nan, or +/-inf, return fnorm'd x 
164 //    If not a unorm, Return
165 //    If unnorm, get the exponent again - perhaps it wasn't a denorm. 
166 { .mfb
167 (p7)  getf.exp         TRUNC_GR_signexp  = f11
168 (p7)  fcvt.fx.trunc.s1 f12   = f11 
169       nop.b 0
171 { .mfb
172       and              TRUNC_GR_exponent = TRUNC_GR_signexp, TRUNC_GR_expmask
173       fcmp.lt.unc.s1   p9,p0 = f8,f0
174       nop.b            0
176 { .mfb
177       cmp.ge.unc       p10,p11 = TRUNC_GR_exponent, TRUNC_GR_bigexp
178       nop.f            0
179       nop.b            0
181 // If a unnorm, check to see if value is already a big int. 
182 { .mfb
183       nop.m 0
184 (p11) fcvt.xf          f8   = f12 
185       nop.b 0
187 { .mfi
188       nop.m 0
189 (p10) fma.s1           f8   = f11,f1,f0 
190       nop.i 0
192 { .mfb
193       nop.m 0
194 (p9)  fmerge.ns        f8   = f1,f8 
195       br.ret.sptk      b0 
197 // If so return it. Otherwise, return (fcvt.xf(fcvt.fx.trunc(x)))
198 // Make sure the result is negative if it should be - that is
199 // negative(denormal) -> -0.
200 .endp truncl
201 ASM_SIZE_DIRECTIVE(truncl)