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/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
);
39 GET_FLOAT_WORD (hx
, x
, NO_COND
);
41 GET_FLOAT_WORD (hp
, p
, NO_COND
);
42 v64si sx
= hx
& 0x80000000;
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);
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
));
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
));
75 GET_FLOAT_WORD (hx
, x
, NO_COND
);
76 SET_FLOAT_WORD (x
, hx
^ sx
, NO_COND
);
78 VECTOR_RETURN (x
, NO_COND
);
83 DEF_VARIANTS2 (remainderf
, sf
, sf
)