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/mathfp/e_remainder.c in Newlib. */
28 #include "amdgcnmach.h"
30 v64df
v64df_fmod_aux (v64df
, v64df
, v64di
);
32 #if defined (__has_builtin) && __has_builtin (__builtin_gcn_fabsv)
34 DEF_VD_MATH_FUNC (v64df
, remainder
, v64df x
, v64df p
)
36 FUNCTION_INIT (v64df
);
39 EXTRACT_WORDS (hx
, lx
, x
);
41 EXTRACT_WORDS (hp
, lp
, p
);
42 v64si sx
= hx
& 0x80000000;
46 /* purge off exception values */
47 VECTOR_RETURN ((x
* p
) / (x
* p
), ((hp
| lp
) == 0) | ((hx
>= 0x7ff00000)
49 ((hp
>= 0x7ff00000) & /* p is NaN */
50 (((hp
- 0x7ff00000) | lp
) != 0))));
52 VECTOR_COND_MOVE (x
, v64df_fmod_aux (x
, p
+p
, __mask
), hp
<= 0x7fdfffff); // now x < 2p
54 VECTOR_RETURN (0.0 * x
, ((hx
-hp
)|(lx
-lp
))==0);
56 x
= __builtin_gcn_fabsv (x
);
57 p
= __builtin_gcn_fabsv (p
);
59 VECTOR_IF (hp
< 0x00200000, cond
)
60 VECTOR_IF2 (x
+ x
> p
, cond2
, __builtin_convertvector(cond
, v64di
))
61 VECTOR_COND_MOVE (x
, x
- p
, cond2
);
62 VECTOR_COND_MOVE (x
, x
- p
, cond2
& (x
+ x
>= p
));
65 v64df p_half
= 0.5 * p
;
66 VECTOR_IF2 (x
> p_half
, cond2
, __builtin_convertvector(cond
, v64di
))
67 VECTOR_COND_MOVE (x
, x
- p
, cond2
);
68 VECTOR_COND_MOVE (x
, x
- p
, cond2
& (x
>= p_half
));
72 GET_HIGH_WORD (hx
, x
, NO_COND
);
73 SET_HIGH_WORD (x
, hx
^ sx
, NO_COND
);
75 VECTOR_RETURN (x
, NO_COND
);
80 DEF_VARIANTS2 (remainder
, df
, df
)