2 * Copyright 2023 Siemens
4 * The authors hereby grant permission to use, copy, modify, distribute,
5 * and license this software and its documentation for any purpose, provided
6 * that existing copyright notices are retained in all copies and that this
7 * notice is included verbatim in any distributions. No written agreement,
8 * license, or royalty fee is required for any of the authorized uses.
9 * Modifications to this software may be copyrighted by their authors
10 * and need not follow the licensing terms described here, provided that
11 * the new terms are clearly indicated on the first page of each file where
16 * ====================================================
17 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
19 * Developed at SunPro, a Sun Microsystems, Inc. business.
20 * Permission to use, copy, modify, and distribute this
21 * software is freely granted, provided that this notice
23 * ====================================================
26 /* Based on newlib/libm/common/sf_rint.c in Newlib. */
28 #include "amdgcnmach.h"
30 static const float TWO23
[2] = {
31 8.3886080000e+06, /* 0x4b000000 */
32 -8.3886080000e+06, /* 0xcb000000 */
35 DEF_VS_MATH_FUNC (v64sf
, rintf
, v64sf x
)
37 FUNCTION_INIT (v64sf
);
40 GET_FLOAT_WORD (i0
, x
, NO_COND
);
41 v64si sx
= (i0
>> 31) & 1;
42 v64sf two23
= VECTOR_MERGE (TWO23
[1] + x
, TWO23
[0] + x
, sx
!= 0);
43 v64si ix
= (i0
& 0x7fffffff);
44 v64si j0
= (ix
>> 23) - 0x7f;
45 VECTOR_IF (j0
< 23, cond
)
46 VECTOR_RETURN (x
, cond
& FLT_UWORD_IS_ZERO (ix
));
47 VECTOR_IF2 (j0
< 0, cond2
, cond
)
48 v64si i1
= (i0
& 0x07fffff);
49 VECTOR_COND_MOVE (i0
, i0
& 0xfff00000, cond2
);
50 VECTOR_COND_MOVE (i0
, i0
| (((i1
| -i1
) >> 9) & 0x400000), cond2
);
51 SET_FLOAT_WORD (x
, i0
, cond2
);
54 GET_FLOAT_WORD (i0
, t
, cond2
);
55 SET_FLOAT_WORD (t
, (i0
&0x7fffffff)|(sx
<<31), cond2
);
56 VECTOR_RETURN (t
, cond2
);
57 VECTOR_ELSE2 (cond2
, cond
)
58 v64si i
= (0x007fffff) >> j0
;
59 VECTOR_RETURN (x
, cond2
& ((i0
& i
) == 0)); /* x is integral */
61 VECTOR_COND_MOVE (i0
, (i0
& (~i
)) | (0x200000 >> j0
),
62 cond2
& ((i0
& i
) != 0));
65 VECTOR_RETURN (x
+ x
, cond
& ~FLT_UWORD_IS_FINITE (ix
)); /* inf or NaN */
66 VECTOR_RETURN (x
, cond
); /* x is integral */
69 SET_FLOAT_WORD (x
, i0
, NO_COND
);
71 VECTOR_RETURN (w
- two23
, NO_COND
);
76 DEF_VARIANTS (rintf
, sf
, sf
)