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/common/sf_modf.c in Newlib. */
28 #include "amdgcnmach.h"
30 v64si
v64sf_numtestf (v64sf
);
32 DEF_VS_MATH_FUNC (v64sf
, modff
, v64sf x
, v64sf
*iptr
)
34 FUNCTION_INIT (v64sf
);
38 GET_FLOAT_WORD (i0
, x
, NO_COND
);
39 v64si j0
= ((i0
>> 23) & 0xff) - 0x7f; /* exponent of x */
41 SET_FLOAT_WORD (zero
, i0
& 0x80000000,NO_COND
);
43 VECTOR_IF (j0
< 23, cond
) /* integer part in x*/
44 VECTOR_IF2 (j0
< 0, cond2
, cond
) /* |x|<1 */
45 VECTOR_COND_MOVE (ret_i
, zero
, cond2
);
46 VECTOR_RETURN (x
, cond2
);
47 VECTOR_ELSE2 (cond2
, cond
)
48 v64si i
= (0x007fffff) >> j0
;
50 VECTOR_IF2 ((i0
& i
) == 0, cond3
, cond2
) /* x is integral */
51 VECTOR_COND_MOVE (ret_i
, x
, cond3
);
52 VECTOR_RETURN (zero
, cond3
);
53 VECTOR_ELSE2 (cond3
, cond2
)
54 SET_FLOAT_WORD (ret_i
, i0
& ~i
, cond3
);
55 VECTOR_RETURN (x
- ret_i
, cond3
);
58 VECTOR_ELSE (cond
) /* no fraction part */
59 VECTOR_COND_MOVE (ret_i
, x
, cond
);
60 VECTOR_IF2 (v64sf_numtestf (x
) == NAN
, cond2
, cond
)
61 VECTOR_COND_MOVE (ret_i
, x
+ x
, cond2
);
62 VECTOR_RETURN (ret_i
, cond2
); /* x is NaN, return NaN */
64 VECTOR_RETURN (zero
, cond
); /* return +- 0 */