Update.
[glibc.git] / sysdeps / ia64 / fpu / s_roundl.S
blobf581d2f65ae1983eeca8a37c57ee70d49306236a
1 .file "roundl.s"
3 // Copyright (c) 2000, 2001, Intel Corporation
4 // All rights reserved.
5 // 
6 // Contributed 10/25/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/25/2000: Created
31 //==============================================================
33 // API
34 //==============================================================
35 // long double roundl(long double x)
38 #include "libm_support.h"
40 // general input registers:  
42 roundl_GR_half      = r14
43 roundl_GR_big       = r15
44 roundl_GR_expmask   = r16
45 roundl_GR_signexp   = r17
46 roundl_GR_exp       = r18
47 roundl_GR_expdiff   = r19
49 // predicate registers used: 
50 // p6 - p10
52 // floating-point registers used: 
54 ROUNDL_NORM_f8        = f9                        
55 ROUNDL_TRUNC_f8       = f10
56 ROUNDL_RINT_f8        = f11
57 ROUNDL_FLOAT_TRUNC_f8 = f12
58 ROUNDL_FLOAT_RINT_f8  = f13
59 ROUNDL_REMAINDER      = f14
60 ROUNDL_HALF           = f15
62 // Overview of operation
63 //==============================================================
65 // long double roundl(long double x)
66 // Return an integer value (represented as a long double) that is x 
67 // rounded to nearest integer, halfway cases rounded away from 
68 // zero. 
69 //  if x>0   result = trunc(x+0.5)
70 //  if x<0   result = trunc(x-0.5)
71 // *******************************************************************************
73 // Set denormal flag for denormal input and
74 // and take denormal fault if necessary.
76 // If x is NAN, ZERO, INFINITY, or >= 2^63 then return
78 // qnan snan inf norm     unorm 0 -+
79 // 1    1    1   0        0     1 11     0xe7
82 .align 32
83 .global roundl#
85 .section .text
86 .proc  roundl#
87 .align 32
90 roundl: 
91         
92 // Get exponent for +0.5
93 // Truncate x to integer
94 { .mfi
95       addl           roundl_GR_half  = 0x0fffe, r0
96       fcvt.fx.trunc.s1     ROUNDL_TRUNC_f8 = f8
97       nop.i 999
99         
100 // Get signexp of x
101 // Normalize input
102 // Form exponent mask
103 { .mfi
104       getf.exp  roundl_GR_signexp = f8
105       fnorm     ROUNDL_NORM_f8 = f8                        
106       addl      roundl_GR_expmask  = 0x1ffff, r0 ;;
109 // Form +0.5
110 // Round x to integer
111 { .mfi
112       setf.exp    ROUNDL_HALF  = roundl_GR_half                      
113       fcvt.fx.s1  ROUNDL_RINT_f8 = f8
114       nop.i 999 ;;
116 // Get exp of x
117 // Test for NAN, INF, ZERO
118 // Get exponent at which input has no fractional part
119 { .mfi
120       and         roundl_GR_exp = roundl_GR_expmask, roundl_GR_signexp
121       fclass.m    p8,p9 = f8,0xe7
122       addl        roundl_GR_big  = 0x1003e, r0 ;;
125 // Get exp-bigexp
126 // If exp is so big there is no fractional part, then turn on p8, off p9
127 { .mmi
128       sub    roundl_GR_expdiff = roundl_GR_exp, roundl_GR_big ;;
129 #ifdef _LIBC
130 (p9)  cmp.lt.or.andcm  p8,p9 = r0, roundl_GR_expdiff
131 #else
132 (p9)  cmp.ge.or.andcm  p8,p9 = roundl_GR_expdiff, r0
133 #endif
134       nop.i 999 ;;
136      
137 // Set p6 if x<0, else set p7
138 { .mfi
139       nop.m 999
140 (p9)  fcmp.lt.unc  p6,p7 = f8,f0
141       nop.i 999
143         
144 // If NAN, INF, ZERO, or no fractional part, result is just normalized input
145 { .mfi
146       nop.m 999
147 (p8)  fnorm.s0  f8 = f8
148       nop.i 999 ;;
151 // Float the truncated integer
152 { .mfi
153       nop.m 999
154 (p9)  fcvt.xf     ROUNDL_FLOAT_TRUNC_f8 = ROUNDL_TRUNC_f8
155       nop.i 999 ;;
158 // Float the rounded integer to get preliminary result
159 { .mfi
160       nop.m 999
161 (p9)  fcvt.xf     ROUNDL_FLOAT_RINT_f8 = ROUNDL_RINT_f8
162       nop.i 999 ;;
165 // If x<0 and the difference of the truncated input minus the input is 0.5
166 //    then result = truncated input - 1.0
167 // Else if x>0 and the difference of the input minus truncated input is 0.5
168 //    then result = truncated input + 1.0
169 // Else 
170 //    result = rounded input
171 // Endif
172 { .mfi
173       nop.m 999
174 (p6)  fsub.s1   ROUNDL_REMAINDER = ROUNDL_FLOAT_TRUNC_f8, ROUNDL_NORM_f8 
175       nop.i 999
177         
178 { .mfi
179       nop.m 999
180 (p7)  fsub.s1   ROUNDL_REMAINDER = ROUNDL_NORM_f8, ROUNDL_FLOAT_TRUNC_f8
181       nop.i 999 ;;
184 // Assume preliminary result is rounded integer
185 { .mfi
186       nop.m 999
187 (p9)  fnorm.s0  f8 = ROUNDL_FLOAT_RINT_f8
188       nop.i 999
191 // If x<0, test if result=0
192 { .mfi
193       nop.m 999
194 (p6)  fcmp.eq.unc  p10,p0 = ROUNDL_FLOAT_RINT_f8,f0
195       nop.i 999 ;;
198 // If x<0 and result=0, set result=-0
199 { .mfi
200       nop.m 999
201 (p10) fmerge.ns  f8 = f1,f8
202       nop.i 999
204         
205 // If x<0, test if remainder=0.5
206 { .mfi
207       nop.m 999
208 (p6)  fcmp.eq.unc  p6,p0 = ROUNDL_REMAINDER, ROUNDL_HALF
209       nop.i 999 ;;
211         
212 // If x>0, test if remainder=0.5
213 { .mfi
214       nop.m 999
215 (p7)  fcmp.eq.unc  p7,p0 = ROUNDL_REMAINDER, ROUNDL_HALF
216       nop.i 999 ;;
219 // If x<0 and remainder=0.5, result=truncated-1.0
220 // If x>0 and remainder=0.5, result=truncated+1.0
221 // Exit
222 .pred.rel "mutex",p6,p7
223 { .mfi
224       nop.m 999
225 (p6)  fsub.s0  f8 = ROUNDL_FLOAT_TRUNC_f8,f1
226       nop.i 999 
228         
229 { .mfb
230       nop.m 999
231 (p7)  fadd.s0  f8 = ROUNDL_FLOAT_TRUNC_f8,f1
232       br.ret.sptk  b0 ;;
235 .endp roundl
236 ASM_SIZE_DIRECTIVE(roundl)