3 // Copyright (C) 2000, 2001, Intel Corporation
4 // All rights reserved.
6 // Contributed 2/2/2000 by John Harrison, Ted Kubaska, Bob Norin, Shane Story,
7 // and Ping Tak Peter Tang of the Computational Software Lab, Intel Corporation.
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
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
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.
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://developer.intel.com/opensource.
41 #include "libm_support.h"
51 //==============================================================
52 // 2/02/00: Initial version
53 // 6/13/00: Improved speed
54 // 6/27/00: Eliminated incorrect invalid flag setting
57 //==============================================================
58 // double ceill(double x)
60 // general input registers:
64 ceil_GR_exponent = r16
69 // predicate registers used:
71 // p6 ==> Input is NaN, infinity, zero
72 // p7 ==> Input is denormal
74 // p9 ==> Input is >=0
75 // p10 ==> Input is already an integer (bigger than largest integer)
76 // p11 ==> Input is not a large integer
77 // p12 ==> Input is a smaller integer
78 // p13 ==> Input is not an even integer, so inexact must be set
79 // p14 ==> Input is between -1 and 0, so result will be -0 and inexact
82 // floating-point registers used:
88 CEIL_FLOAT_INT_f8 = f12
93 // Overview of operation
94 //==============================================================
96 // long double ceill(long double x)
97 // Return an integer value (represented as a long double) that is the smallest
98 // value not less than x
99 // This is x rounded toward +infinity to an integral value.
100 // Inexact is set if x != ceill(x)
101 // **************************************************************************
103 // Set denormal flag for denormal input and
104 // and take denormal fault if necessary.
106 // Is the input an integer value already?
109 // if the exponent is > 1003e => 3F(true) = 63(decimal)
110 // we have a significand of 64 bits 1.63-bits.
111 // If we multiply by 2^63, we no longer have a fractional part
112 // So input is an integer value already.
115 // if the exponent is >= 10033 => 34(true) = 52(decimal)
117 // we have a significand of 53 bits 1.52-bits. (implicit 1)
118 // If we multiply by 2^52, we no longer have a fractional part
119 // So input is an integer value already.
122 // if the exponent is > 10016 => 17(true) = 23(decimal)
123 // we have a significand of 24 bits 1.23-bits. (implicit 1)
124 // If we multiply by 2^23, we no longer have a fractional part
125 // So input is an integer value already.
127 // If x is NAN, ZERO, or INFINITY, then return
129 // qnan snan inf norm unorm 0 -+
130 // 1 1 1 0 0 1 11 0xe7
136 getf.exp ceil_GR_signexp = f8
137 fcvt.fx.trunc.s1 CEIL_INT_f8 = f8
138 addl ceil_GR_bigexp = 0x1003e, r0
141 addl ceil_GR_FFFF = -1,r0
142 fcmp.lt.s1 p8,p9 = f8,f0
143 mov ceil_GR_expmask = 0x1FFFF ;;
148 setf.sig CEIL_FFFF = ceil_GR_FFFF
149 fclass.m p7,p0 = f8, 0x0b
154 fnorm CEIL_NORM_f8 = f8
158 // Form 0 with sign of input in case negative zero is needed
161 fmerge.s CEIL_SIGNED_ZERO = f8, f0
166 fsub.s1 CEIL_MINUS_ONE = f0, f1
170 // p6 ==> NAN, INF, ZERO
173 fclass.m p6,p10 = f8, 0xe7
174 (p7) br.cond.spnt L(CEIL_DENORM) ;;
178 .pred.rel "mutex",p8,p9
179 // Set adjustment to add to trunc(x) for result
180 // If x>0, adjustment is 1.0
181 // If x<=0, adjustment is 0.0
183 and ceil_GR_exponent = ceil_GR_signexp, ceil_GR_expmask
184 (p9) fadd.s1 CEIL_adj = f1,f0
189 (p8) fadd.s1 CEIL_adj = f0,f0
194 (p10) cmp.ge.unc p10,p11 = ceil_GR_exponent, ceil_GR_bigexp
201 (p11) fcvt.xf CEIL_FLOAT_INT_f8 = CEIL_INT_f8
207 (p10) fnorm f8 = CEIL_NORM_f8
211 // Is -1 < x < 0? If so, result will be -0. Special case it with p14 set.
214 (p8) fcmp.gt.unc.s1 p14,p0 = CEIL_NORM_f8, CEIL_MINUS_ONE
219 (p14) cmp.ne p11,p0 = r0,r0
220 (p14) fnorm f8 = CEIL_SIGNED_ZERO
225 (p14) fmpy.s0 CEIL_INEXACT = CEIL_FFFF,CEIL_FFFF
231 (p11) fadd f8 = CEIL_FLOAT_INT_f8,CEIL_adj
236 (p11) fcmp.eq.unc.s1 p12,p13 = CEIL_FLOAT_INT_f8, CEIL_NORM_f8
240 // Set inexact if result not equal to input
243 (p13) fmpy.s0 CEIL_INEXACT = CEIL_FFFF,CEIL_FFFF
246 // Set result to input if integer
249 (p12) fnorm f8 = CEIL_NORM_f8
253 // Here if input denorm
256 getf.exp ceil_GR_signexp = CEIL_NORM_f8
257 fcvt.fx.trunc.s1 CEIL_INT_f8 = CEIL_NORM_f8
258 br.cond.sptk L(CEIL_COMMON) ;;
262 ASM_SIZE_DIRECTIVE(ceill)