devctl.h: update for POSIX-1.2024
[newlib-cygwin.git] / newlib / libm / machine / amdgcn / v64sf_remainder.c
blob5820498ac3751ec343caaf0d8be6468217881de3
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/mathfp/ef_remainder.c in Newlib. */
28 #include "amdgcnmach.h"
30 v64sf v64sf_fmodf_aux (v64sf, v64sf, v64si);
32 #if defined (__has_builtin) && __has_builtin (__builtin_gcn_fabsvf)
34 DEF_VS_MATH_FUNC (v64sf, remainderf, v64sf x, v64sf p)
36 FUNCTION_INIT (v64sf);
38 v64si hx;
39 GET_FLOAT_WORD (hx, x, NO_COND);
40 v64si hp;
41 GET_FLOAT_WORD (hp, p, NO_COND);
42 v64si sx = hx & 0x80000000;
43 hp &= 0x7fffffff;
44 hx &= 0x7fffffff;
46 /* purge off exception values */
47 /*if(hp==0) // p = 0 */
48 /*if((hx>=0x7f800000)|| // x not finite
49 ((hp>0x7f800000))) // p is NaN */
50 VECTOR_RETURN ((x*p) / (x*p),
51 (hp == 0) | (hx >= 0x7f800000) | (hp > 0x7f800000));
53 /* if (hp<=0x7effffff) // now x < 2p */
54 VECTOR_COND_MOVE (x, v64sf_fmodf_aux (x, p+p, __mask), hp <= 0x7effffff);
56 /*if ((hx-hp)==0) */
57 VECTOR_RETURN (0.0f * x, (hx-hp) == 0);
59 x = __builtin_gcn_fabsvf (x);
60 p = __builtin_gcn_fabsvf (p);
62 VECTOR_IF (hp < 0x01000000, cond)
63 VECTOR_IF2 (x + x > p, cond2, cond)
64 VECTOR_COND_MOVE (x, x - p, cond2);
65 VECTOR_COND_MOVE (x, x - p, cond2 & (x + x >= p));
66 VECTOR_ENDIF
67 VECTOR_ELSE (cond)
68 v64sf p_half = 0.5f * p;
69 VECTOR_IF2 (x > p_half, cond2, cond)
70 VECTOR_COND_MOVE (x, x - p, cond2);
71 VECTOR_COND_MOVE (x, x - p, cond2 & (x >= p_half));
72 VECTOR_ENDIF
73 VECTOR_ENDIF
75 GET_FLOAT_WORD (hx, x, NO_COND);
76 SET_FLOAT_WORD (x, hx ^ sx, NO_COND);
78 VECTOR_RETURN (x, NO_COND);
80 FUNCTION_RETURN;
83 DEF_VARIANTS2 (remainderf, sf, sf)
85 #endif