localedata: dz_BT, bo_CN: convert to UTF-8
[glibc.git] / sysdeps / ia64 / fpu / s_round.S
blobd54bafe1888e550911af453892f7b758651fd753
1 .file "round.s"
4 // Copyright (c) 2000 - 2003, Intel Corporation
5 // All rights reserved.
6 //
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
10 // met:
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
15 // * Redistributions in binary form must reproduce the above copyright
16 // notice, this list of conditions and the following disclaimer in the
17 // documentation and/or other materials provided with the distribution.
19 // * The name of Intel Corporation may not be used to endorse or promote
20 // products derived from this software without specific prior written
21 // permission.
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
27 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
31 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
32 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 // Intel Corporation is the author of this code, and requests that all
36 // problem reports or change requests be submitted to it directly at
37 // http://www.intel.com/software/products/opensource/libraries/num.htm.
39 // History
40 //==============================================================
41 // 10/25/00 Initial version
42 // 06/14/01 Changed cmp to an equivalent form
43 // 05/20/02 Cleaned up namespace and sf0 syntax
44 // 01/20/03 Improved performance and reduced code size
45 // 04/18/03 Eliminate possible WAW dependency warning
46 // 09/03/03 Improved performance
47 //==============================================================
49 // API
50 //==============================================================
51 // double round(double x)
52 //==============================================================
54 // general input registers:
55 // r14 - r18
57 rSignexp   = r14
58 rExp       = r15
59 rExpMask   = r16
60 rBigexp    = r17
61 rExpHalf   = r18
63 // floating-point registers:
64 // f8 - f13
66 fXtruncInt = f9
67 fNormX     = f10
68 fHalf      = f11
69 fInc       = f12
70 fRem       = f13
72 // predicate registers used:
73 // p6 - p10
75 // Overview of operation
76 //==============================================================
77 // double round(double x)
78 // Return an integer value (represented as a double) that is x
79 // rounded to nearest integer, halfway cases rounded away from
80 // zero.
81 //  if x>0   result = trunc(x+0.5)
82 //  if x<0   result = trunc(x-0.5)
84 //==============================================================
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 24 bits 1.23-bits. (implicit 1)
102 // If we multiply by 2^23, we no longer have a fractional part
103 // So input is an integer value already.
106 .section .text
107 GLOBAL_LIBM_ENTRY(round)
109 { .mfi
110       getf.exp         rSignexp  = f8        // Get signexp, recompute if unorm
111       fcvt.fx.trunc.s1 fXtruncInt  = f8      // Convert to int in significand
112       addl             rBigexp = 0x10033, r0 // Set exponent at which is integer
114 { .mfi
115       mov              rExpHalf    = 0x0FFFE // Form sign and exponent of 0.5
116       fnorm.s1         fNormX  = f8          // Normalize input
117       mov              rExpMask    = 0x1FFFF // Form exponent mask
121 { .mfi
122       setf.exp         fHalf = rExpHalf      // Form 0.5
123       fclass.m         p7,p0 = f8, 0x0b      // Test x unorm
124       nop.i            0
128 { .mfb
129       nop.m            0
130       fclass.m         p6,p0 = f8, 0x1e3     // Test x natval, nan, inf
131 (p7)  br.cond.spnt     ROUND_UNORM           // Branch if x unorm
135 ROUND_COMMON:
136 // Return here from ROUND_UNORM
137 { .mfb
138       nop.m            0
139       fcmp.lt.s1       p8,p9 = f8, f0        // Test if x < 0
140 (p6)  br.cond.spnt     ROUND_SPECIAL         // Exit if x natval, nan, inf
144 { .mfi
145       nop.m            0
146       fcvt.xf          f8 = fXtruncInt        // Pre-Result if 0.5 <= |x| < 2^52
147       nop.i            0
151 { .mfi
152       and              rExp = rSignexp, rExpMask // Get biased exponent
153       fmerge.s         fInc = fNormX, f1      // Form increment if |rem| >= 0.5
154       nop.i            0
158 { .mmi
159       cmp.lt           p6,p0 = rExp, rExpHalf // Is |x| < 0.5?
160       cmp.ge           p7,p0 = rExp, rBigexp  // Is |x| >= 2^52?
161       cmp.lt           p10,p0 = rExp, rExpHalf // Is |x| < 0.5?
165 // We must correct result if |x| < 0.5, or |x| >= 2^52
166 .pred.rel "mutex",p6,p7
167 { .mfi
168       nop.m            0
169 (p6)  fmerge.s         f8 = fNormX, f0        // If |x| < 0.5, result sgn(x)*0
170       nop.i            0
172 { .mfb
173 (p7)  cmp.eq           p10,p0 = r0, r0        // Also turn on p10 if |x| >= 2^52
174 (p7)  fma.d.s0         f8 = fNormX, f1, f0    // If |x| >= 2^52, result x
175 (p10) br.ret.spnt      b0                     // Exit |x| < 0.5 or |x| >= 2^52
179 // Here if 0.5 <= |x| < 2^52
180 { .mfi
181       nop.m            0
182 (p9)  fms.s1           fRem = fNormX, f1, f8  // Get remainder = x - trunc(x)
183       nop.i            0
185 { .mfi
186       nop.m            0
187 (p8)  fms.s1           fRem = f8, f1, fNormX  // Get remainder = trunc(x) - x
188       nop.i            0
192 { .mfi
193       nop.m            0
194       fcmp.ge.s1       p9,p0 = fRem, fHalf    // Test |rem| >= 0.5
195       nop.i            0
199 // If x < 0 and remainder <= -0.5, then subtract 1 from result
200 // If x > 0 and remainder >= +0.5, then add 1 to result
201 { .mfb
202       nop.m            0
203 (p9)  fma.d.s0         f8 = f8, f1, fInc
204       br.ret.sptk      b0
209 ROUND_SPECIAL:
210 // Here if x natval, nan, inf
211 { .mfb
212       nop.m            0
213       fma.d.s0         f8 = f8, f1, f0
214       br.ret.sptk      b0
218 ROUND_UNORM:
219 // Here if x unorm
220 { .mfi
221       getf.exp         rSignexp  = fNormX     // Get signexp, recompute if unorm
222       fcmp.eq.s0       p7,p0 = f8, f0         // Dummy op to set denormal flag
223       nop.i            0
225 { .mfb
226       nop.m            0
227       fcvt.fx.trunc.s1 fXtruncInt  = fNormX   // Convert to int in significand
228       br.cond.sptk     ROUND_COMMON           // Return to main path
232 GLOBAL_LIBM_END(round)
233 libm_alias_double_other (round, round)