* sysdeps/unix/sysv/linux/m68k/sysdep.h (INLINE_SYSCALL): Don't
[glibc.git] / sysdeps / ia64 / fpu / s_nearbyintf.S
blob02806e34dc1d82fbbd6e129b20d2b73d93350707
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 // 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.
28 // History
29 //==============================================================
30 // 10/19/2000: Created
31 // 2/08/01  Corrected behavior for all rounding modes.
32 //==============================================================
34 // API
35 //==============================================================
36 // float nearbyintf(float x)
38 #include "libm_support.h"
41 // general registers used:  
44 nearbyint_GR_signexp   = r14
45 nearbyint_GR_exponent  = r15
46 nearbyint_GR_17ones    = r16
47 nearbyint_GR_10033     = r17
48 nearbyint_GR_fpsr      = r18
49 nearbyint_GR_rcs0      = r19
50 nearbyint_GR_rcs0_mask = r20
53 // predicate registers used: 
54 // p6-11
56 // floating-point registers used: 
58 NEARBYINT_NORM_f8      = f9                        
59 NEARBYINT_FLOAT_INT_f8 = f10
60 NEARBYINT_INT_f8       = f11
62 // Overview of operation
63 //==============================================================
65 // float nearbyintf(float x)
66 // Return an integer value (represented as a float) that is x rounded to integer in current
67 // rounding mode 
68 // *******************************************************************************
70 // Set denormal flag for denormal input and
71 // and take denormal fault if necessary.
73 // Is the input an integer value already?
75 // double_extended
76 // if the exponent is >= 1003e => 3F(true) = 63(decimal)
77 // we have a significand of 64 bits 1.63-bits.
78 // If we multiply by 2^63, we no longer have a fractional part
79 // So input is an integer value already.
81 // double
82 // if the exponent is >= 10033 => 34(true) = 52(decimal)
83 // 34 + 3ff = 433
84 // we have a significand of 53 bits 1.52-bits. (implicit 1)
85 // If we multiply by 2^52, we no longer have a fractional part
86 // So input is an integer value already.
88 // single
89 // if the exponent is >= 10016 => 17(true) = 23(decimal)
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 // If x is NAN, ZERO, or INFINITY, then  return
96 // qnan snan inf norm     unorm 0 -+
97 // 1    1    1   0        0     1 11     0xe7
100 .align 32
101 .global nearbyintf#
103 .section .text
104 .proc  nearbyintf#
105 .align 32
108 nearbyintf: 
110 { .mfi
111       mov nearbyint_GR_fpsr = ar40           // Read the fpsr--need to check rc.s0
112       fcvt.fx.s1     NEARBYINT_INT_f8  = f8
113       addl            nearbyint_GR_10033 = 0x10016, r0
115 { .mfi
116       nop.m 999
117       fnorm.s1        NEARBYINT_NORM_f8  = f8
118       mov         nearbyint_GR_17ones    = 0x1FFFF
122 { .mfi
123       nop.m 999
124       fclass.m.unc  p6,p0 = f8, 0xe7
125       mov         nearbyint_GR_rcs0_mask  = 0x0c00
129 { .mfb
130         nop.m 999
131 (p6)  fnorm.s f8 = f8
132 (p6)  br.ret.spnt   b0    // Exit if x nan, inf, zero
136 { .mfi
137         nop.m 999
138       fcvt.xf         NEARBYINT_FLOAT_INT_f8   = NEARBYINT_INT_f8
139         nop.i 999
143 { .mfi
144       getf.exp nearbyint_GR_signexp  = NEARBYINT_NORM_f8
145       fcmp.eq.s0  p8,p0 = f8,f0      // Dummy op to set denormal
146         nop.i 999
151 { .mii
152         nop.m 999
153         nop.i 999 
154       and      nearbyint_GR_exponent = nearbyint_GR_signexp, nearbyint_GR_17ones
158 { .mmi
159       cmp.ge.unc      p7,p6 = nearbyint_GR_exponent, nearbyint_GR_10033
160       and nearbyint_GR_rcs0 = nearbyint_GR_rcs0_mask, nearbyint_GR_fpsr
161         nop.i 999
165 // Check to see if s0 rounding mode is round to nearest.  If not then set s2
166 // rounding mode to that of s0 and repeat conversions.
167 L(NEARBYINT_COMMON):
168 { .mfb
169       cmp.ne   p11,p0 = nearbyint_GR_rcs0, r0
170 (p6) fclass.m.unc   p9,p10  = NEARBYINT_FLOAT_INT_f8, 0x07  // Test for result=0
171 (p11) br.cond.spnt L(NEARBYINT_NOT_ROUND_NEAREST)  // Branch if not round to nearest
175 { .mfi
176         nop.m 999
177 (p7) fnorm.s.s0   f8 = f8
178         nop.i 999
182 // If result is zero, merge sign of input
183 { .mfi
184      nop.m 999
185 (p9) fmerge.s f8 = f8, NEARBYINT_FLOAT_INT_f8
186      nop.i 999
188 { .mfb
189       nop.m 999
190 (p10) fnorm.s f8 = NEARBYINT_FLOAT_INT_f8
191      br.ret.sptk    b0
196 L(NEARBYINT_NOT_ROUND_NEAREST):
197 // Set rounding mode of s2 to that of s0
198 { .mfi
199       mov nearbyint_GR_rcs0 = r0       // Clear so we don't come back here
200       fsetc.s2     0x7f, 0x40
201         nop.i 999
205 { .mfi
206         nop.m 999
207       fcvt.fx.s2     NEARBYINT_INT_f8  = f8
208         nop.i 999
212 { .mfb
213         nop.m 999
214       fcvt.xf         NEARBYINT_FLOAT_INT_f8   = NEARBYINT_INT_f8
215       br.cond.sptk  L(NEARBYINT_COMMON)
220 .endp nearbyintf
221 ASM_SIZE_DIRECTIVE(nearbyintf)