devctl.h: update for POSIX-1.2024
[newlib-cygwin.git] / newlib / libm / machine / amdgcn / v64df_rint.c
blob18f6b318fca5ec96d1689ebd72bbe77a9a1ce7e4
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/s_rint.c in Newlib. */
28 #include "amdgcnmach.h"
30 static const double TWO52[2] = {
31 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
32 -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
35 DEF_VD_MATH_FUNC (v64df, rint, v64df x)
37 FUNCTION_INIT (v64df);
39 v64si i0, i1;
40 EXTRACT_WORDS (i0, i1, x);
41 v64si sx = (i0 >> 31) & 1;
42 v64df two52 = VECTOR_MERGE (VECTOR_INIT (TWO52[1]), VECTOR_INIT (TWO52[0]), sx != 0);
43 v64si j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
44 v64si i;
45 VECTOR_IF (j0 < 20, cond)
46 VECTOR_IF2 (j0 < 0, cond2, cond)
47 VECTOR_RETURN (x, cond2 & (((i0 & 0x7fffffff) | i1) == 0));
48 VECTOR_COND_MOVE (i1, i1 | (i0 & 0x0fffff), cond2);
49 VECTOR_COND_MOVE (i0, i0 & 0xfffe0000, cond2);
50 VECTOR_COND_MOVE (i0, i0 | (((i1 | -i1) >> 12) & 0x80000), cond2);
51 SET_HIGH_WORD (x, i0, cond2);
52 v64df w = two52 + x;
53 v64df t = w - two52;
54 GET_HIGH_WORD (i0, t, cond2);
55 SET_HIGH_WORD (t, (i0&0x7fffffff)|(sx<<31), cond2);
56 VECTOR_RETURN (t, cond2);
57 VECTOR_ELSE2 (cond2, cond)
58 i = (0x000fffff) >> j0;
59 VECTOR_RETURN (x, cond2 & (((i0 & i) | i1) == 0)); /* x is integral */
60 i >>= 1;
61 VECTOR_IF2 (((i0 & i) | i1) != 0, cond3, cond2)
62 VECTOR_COND_MOVE (i1, CAST_VECTOR(v64si, VECTOR_INIT (0x80000000)), cond3 & (j0 == 19));
63 VECTOR_COND_MOVE (i1, VECTOR_INIT (0), cond3 & (j0 != 19));
64 VECTOR_COND_MOVE (i0, (i0 & (~i)) | ((0x40000) >> j0), cond3);
65 VECTOR_ENDIF
66 VECTOR_ENDIF
67 VECTOR_ELSEIF (j0 > 51, cond)
68 VECTOR_RETURN (x + x, cond & (j0 == 0x400));
69 VECTOR_RETURN (x, cond);
70 VECTOR_ELSE (cond)
71 i = CAST_VECTOR (v64si, VECTOR_INIT (0xffffffff) >> (j0 - 20));
72 VECTOR_RETURN (x, cond & ((i1 & i) == 0));
73 i >>= 1;
74 VECTOR_COND_MOVE (i1, (i1 & (~i)) | (0x40000000 >> (j0 - 20)), cond & ((i1 & i) != 0));
75 VECTOR_ENDIF
76 INSERT_WORDS (x, i0, i1, NO_COND);
77 v64df w = two52 + x;
78 VECTOR_RETURN (w - two52, NO_COND);
80 FUNCTION_RETURN;
83 DEF_VARIANTS (rint, df, df)