(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / ia64 / fpu / s_nearbyintf.S
blob7050ddc52c36b8948da66c5228c68f996931f6da
1 .file "nearbyintf.s"
3 // Copyright (C) 2000, 2001, Intel Corporation
4 // All rights reserved.
5 // 
6 // Contributed 10/19/2000 by John Harrison, Cristina Iordache, Ted Kubaska,
7 // Bob Norin, Tom Rowan, 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 // History
42 //==============================================================
43 // 10/19/2000: Created
44 // 2/08/01  Corrected behavior for all rounding modes.
45 //==============================================================
47 // API
48 //==============================================================
49 // float nearbyintf(float x)
51 #include "libm_support.h"
54 // general registers used:  
57 nearbyint_GR_signexp   = r14
58 nearbyint_GR_exponent  = r15
59 nearbyint_GR_17ones    = r16
60 nearbyint_GR_10033     = r17
61 nearbyint_GR_fpsr      = r18
62 nearbyint_GR_rcs0      = r19
63 nearbyint_GR_rcs0_mask = r20
66 // predicate registers used: 
67 // p6-11
69 // floating-point registers used: 
71 NEARBYINT_NORM_f8      = f9                        
72 NEARBYINT_FLOAT_INT_f8 = f10
73 NEARBYINT_INT_f8       = f11
75 // Overview of operation
76 //==============================================================
78 // float nearbyintf(float x)
79 // Return an integer value (represented as a float) that is x rounded to integer in current
80 // rounding mode 
81 // *******************************************************************************
83 // Set denormal flag for denormal input and
84 // and take denormal fault if necessary.
86 // Is the input an integer value already?
88 // double_extended
89 // if the exponent is >= 1003e => 3F(true) = 63(decimal)
90 // we have a significand of 64 bits 1.63-bits.
91 // If we multiply by 2^63, we no longer have a fractional part
92 // So input is an integer value already.
94 // double
95 // if the exponent is >= 10033 => 34(true) = 52(decimal)
96 // 34 + 3ff = 433
97 // we have a significand of 53 bits 1.52-bits. (implicit 1)
98 // If we multiply by 2^52, we no longer have a fractional part
99 // So input is an integer value already.
101 // single
102 // if the exponent is >= 10016 => 17(true) = 23(decimal)
103 // we have a significand of 53 bits 1.52-bits. (implicit 1)
104 // If we multiply by 2^52, we no longer have a fractional part
105 // So input is an integer value already.
107 // If x is NAN, ZERO, or INFINITY, then  return
109 // qnan snan inf norm     unorm 0 -+
110 // 1    1    1   0        0     1 11     0xe7
113 .align 32
114 .global nearbyintf#
116 .section .text
117 .proc  nearbyintf#
118 .align 32
121 nearbyintf: 
123 { .mfi
124       mov nearbyint_GR_fpsr = ar40           // Read the fpsr--need to check rc.s0
125       fcvt.fx.s1     NEARBYINT_INT_f8  = f8
126       addl            nearbyint_GR_10033 = 0x10016, r0
128 { .mfi
129       nop.m 999
130       fnorm.s1        NEARBYINT_NORM_f8  = f8
131       mov         nearbyint_GR_17ones    = 0x1FFFF
135 { .mfi
136       nop.m 999
137       fclass.m.unc  p6,p0 = f8, 0xe7
138       mov         nearbyint_GR_rcs0_mask  = 0x0c00
142 { .mfb
143         nop.m 999
144 (p6)  fnorm.s f8 = f8
145 (p6)  br.ret.spnt   b0    // Exit if x nan, inf, zero
149 { .mfi
150         nop.m 999
151       fcvt.xf         NEARBYINT_FLOAT_INT_f8   = NEARBYINT_INT_f8
152         nop.i 999
156 { .mfi
157       getf.exp nearbyint_GR_signexp  = NEARBYINT_NORM_f8
158       fcmp.eq.s0  p8,p0 = f8,f0      // Dummy op to set denormal
159         nop.i 999
164 { .mii
165         nop.m 999
166         nop.i 999 
167       and      nearbyint_GR_exponent = nearbyint_GR_signexp, nearbyint_GR_17ones
171 { .mmi
172       cmp.ge.unc      p7,p6 = nearbyint_GR_exponent, nearbyint_GR_10033
173       and nearbyint_GR_rcs0 = nearbyint_GR_rcs0_mask, nearbyint_GR_fpsr
174         nop.i 999
178 // Check to see if s0 rounding mode is round to nearest.  If not then set s2
179 // rounding mode to that of s0 and repeat conversions.
180 L(NEARBYINT_COMMON):
181 { .mfb
182       cmp.ne   p11,p0 = nearbyint_GR_rcs0, r0
183 (p6) fclass.m.unc   p9,p10  = NEARBYINT_FLOAT_INT_f8, 0x07  // Test for result=0
184 (p11) br.cond.spnt L(NEARBYINT_NOT_ROUND_NEAREST)  // Branch if not round to nearest
188 { .mfi
189         nop.m 999
190 (p7) fnorm.s.s0   f8 = f8
191         nop.i 999
195 // If result is zero, merge sign of input
196 { .mfi
197      nop.m 999
198 (p9) fmerge.s f8 = f8, NEARBYINT_FLOAT_INT_f8
199      nop.i 999
201 { .mfb
202       nop.m 999
203 (p10) fnorm.s f8 = NEARBYINT_FLOAT_INT_f8
204      br.ret.sptk    b0
209 L(NEARBYINT_NOT_ROUND_NEAREST):
210 // Set rounding mode of s2 to that of s0
211 { .mfi
212       mov nearbyint_GR_rcs0 = r0       // Clear so we don't come back here
213       fsetc.s2     0x7f, 0x40
214         nop.i 999
218 { .mfi
219         nop.m 999
220       fcvt.fx.s2     NEARBYINT_INT_f8  = f8
221         nop.i 999
225 { .mfb
226         nop.m 999
227       fcvt.xf         NEARBYINT_FLOAT_INT_f8   = NEARBYINT_INT_f8
228       br.cond.sptk  L(NEARBYINT_COMMON)
233 .endp nearbyintf
234 ASM_SIZE_DIRECTIVE(nearbyintf)