devctl.h: update for POSIX-1.2024
[newlib-cygwin.git] / newlib / libm / machine / amdgcn / v64sf_rint.c
blobf0760206346668ebed3d18f4d60fa8bce03b84d1
1 /*
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
12 * they apply.
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
22 * is preserved.
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);
39 v64si i0;
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);
52 v64sf w = two23 + x;
53 v64sf t = w - two23;
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 */
60 i >>= 1;
61 VECTOR_COND_MOVE (i0, (i0 & (~i)) | (0x200000 >> j0),
62 cond2 & ((i0 & i) != 0));
63 VECTOR_ENDIF
64 VECTOR_ELSE (cond)
65 VECTOR_RETURN (x + x, cond & ~FLT_UWORD_IS_FINITE (ix)); /* inf or NaN */
66 VECTOR_RETURN (x, cond); /* x is integral */
67 VECTOR_ENDIF
69 SET_FLOAT_WORD (x, i0, NO_COND);
70 v64sf w = two23 + x;
71 VECTOR_RETURN (w - two23, NO_COND);
73 FUNCTION_RETURN;
76 DEF_VARIANTS (rintf, sf, sf)