Updated to fedora-glibc-20050106T1443
[glibc.git] / sysdeps / ia64 / fpu / s_nearbyint.S
blobcba74e61d3a085a407bb949d6fda8e6adcbc3dcf
1 .file "nearbyint.s"
4 // Copyright (c) 2000 - 2003, Intel Corporation
5 // All rights reserved.
6 //
7 // Contributed 2000 by the Intel Numerics Group, Intel Corporation
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
11 // met:
13 // * Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
16 // * Redistributions in binary form must reproduce the above copyright
17 // notice, this list of conditions and the following disclaimer in the
18 // documentation and/or other materials provided with the distribution.
20 // * The name of Intel Corporation may not be used to endorse or promote
21 // products derived from this software without specific prior written
22 // permission.
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS 
28 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
30 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
31 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
32 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
33 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
34 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
35 // 
36 // Intel Corporation is the author of this code, and requests that all
37 // problem reports or change requests be submitted to it directly at 
38 // http://www.intel.com/software/products/opensource/libraries/num.htm.
40 // History
41 //==============================================================
42 // 10/19/00 Created
43 // 02/08/01 Corrected behavior for all rounding modes.
44 // 05/20/02 Cleaned up namespace and sf0 syntax
45 // 02/10/03 Reordered header: .section, .global, .proc, .align
46 //==============================================================
48 // API
49 //==============================================================
50 // double nearbyint(double x)
52 // general registers used:  
55 nearbyint_GR_signexp   = r14
56 nearbyint_GR_exponent  = r15
57 nearbyint_GR_17ones    = r16
58 nearbyint_GR_10033     = r17
59 nearbyint_GR_fpsr      = r18
60 nearbyint_GR_rcs0      = r19
61 nearbyint_GR_rcs0_mask = r20
64 // predicate registers used: 
65 // p6-11
67 // floating-point registers used: 
69 NEARBYINT_NORM_f8      = f9                        
70 NEARBYINT_FLOAT_INT_f8 = f10
71 NEARBYINT_INT_f8       = f11
73 // Overview of operation
74 //==============================================================
76 // double nearbyint(double x)
77 // Return an integer value (represented as a double) that is x rounded to integer in current
78 // rounding mode 
79 // *******************************************************************************
81 // Set denormal flag for denormal input and
82 // and take denormal fault if necessary.
84 // Is the input an integer value already?
86 // double_extended
87 // if the exponent is >= 1003e => 3F(true) = 63(decimal)
88 // we have a significand of 64 bits 1.63-bits.
89 // If we multiply by 2^63, we no longer have a fractional part
90 // So input is an integer value already.
92 // double
93 // if the exponent is >= 10033 => 34(true) = 52(decimal)
94 // 34 + 3ff = 433
95 // we have a significand of 53 bits 1.52-bits. (implicit 1)
96 // If we multiply by 2^52, we no longer have a fractional part
97 // So input is an integer value already.
99 // single
100 // if the exponent is >= 10016 => 17(true) = 23(decimal)
101 // we have a significand of 53 bits 1.52-bits. (implicit 1)
102 // If we multiply by 2^52, we no longer have a fractional part
103 // So input is an integer value already.
105 // If x is NAN, ZERO, or INFINITY, then  return
107 // qnan snan inf norm     unorm 0 -+
108 // 1    1    1   0        0     1 11     0xe7
111 .section .text
112 GLOBAL_LIBM_ENTRY(nearbyint)
114 { .mfi
115       mov nearbyint_GR_fpsr = ar40    // Read the fpsr--need to check rc.s0
116       fcvt.fx.s1     NEARBYINT_INT_f8  = f8
117       addl            nearbyint_GR_10033 = 0x10033, r0
119 { .mfi
120       nop.m 999
121       fnorm.s1        NEARBYINT_NORM_f8  = f8
122       mov         nearbyint_GR_17ones    = 0x1FFFF
126 { .mfi
127       nop.m 999
128       fclass.m.unc  p6,p0 = f8, 0xe7
129       mov         nearbyint_GR_rcs0_mask  = 0x0c00
133 { .mfb
134         nop.m 999
135 (p6)  fnorm.d.s0 f8 = f8
136 (p6)  br.ret.spnt   b0    // Exit if x nan, inf, zero
140 { .mfi
141         nop.m 999
142       fcvt.xf         NEARBYINT_FLOAT_INT_f8   = NEARBYINT_INT_f8
143         nop.i 999
147 { .mfi
148       getf.exp nearbyint_GR_signexp  = NEARBYINT_NORM_f8
149       fcmp.eq.s0  p8,p0 = f8,f0      // Dummy op to set denormal
150         nop.i 999
155 { .mii
156         nop.m 999
157         nop.i 999 
158       and nearbyint_GR_exponent = nearbyint_GR_signexp, nearbyint_GR_17ones
162 { .mmi
163       cmp.ge.unc      p7,p6 = nearbyint_GR_exponent, nearbyint_GR_10033
164       and nearbyint_GR_rcs0 = nearbyint_GR_rcs0_mask, nearbyint_GR_fpsr
165         nop.i 999
169 // Check to see if s0 rounding mode is round to nearest.  If not then set s2
170 // rounding mode to that of s0 and repeat conversions.
171 NEARBYINT_COMMON:
172 { .mfb
173       cmp.ne   p11,p0 = nearbyint_GR_rcs0, r0
174 (p6) fclass.m.unc   p9,p10  = NEARBYINT_FLOAT_INT_f8, 0x07  // Test for result=0
175 (p11) br.cond.spnt NEARBYINT_NOT_ROUND_NEAREST  // Branch if not round to nearest
179 { .mfi
180         nop.m 999
181 (p7) fnorm.d.s0   f8 = f8
182         nop.i 999
186 // If result is zero, merge sign of input
187 { .mfi
188      nop.m 999
189 (p9) fmerge.s f8 = f8, NEARBYINT_FLOAT_INT_f8
190      nop.i 999
192 { .mfb
193       nop.m 999
194 (p10) fnorm.d.s0 f8 = NEARBYINT_FLOAT_INT_f8
195      br.ret.sptk    b0
196 ;;                             
200 NEARBYINT_NOT_ROUND_NEAREST:
201 // Set rounding mode of s2 to that of s0
202 { .mfi
203       mov nearbyint_GR_rcs0 = r0       // Clear so we don't come back here
204       fsetc.s2     0x7f, 0x40
205         nop.i 999
209 { .mfi
210         nop.m 999
211       fcvt.fx.s2     NEARBYINT_INT_f8  = f8
212         nop.i 999
216 { .mfb
217         nop.m 999
218       fcvt.xf         NEARBYINT_FLOAT_INT_f8   = NEARBYINT_INT_f8
219       br.cond.sptk  NEARBYINT_COMMON
224 GLOBAL_LIBM_END(nearbyint)