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_scalbn.c in Newlib. */
28 #include "amdgcnmach.h"
33 #define OVERFLOW_INT 50000
35 #define OVERFLOW_INT 30000
39 two25
= 3.355443200e+07, /* 0x4c000000 */
40 twom25
= 2.9802322388e-08, /* 0x33000000 */
44 v64sf
v64sf_copysignf_aux (v64sf
, v64sf
, v64si
);
46 DEF_VS_MATH_FUNC (v64sf
, scalbnf
, v64sf x
, v64si n
)
48 FUNCTION_INIT (v64sf
);
50 const v64sf huge_v
= VECTOR_INIT ((float) huge
);
51 const v64sf tiny_v
= VECTOR_INIT ((float) tiny
);
54 GET_FLOAT_WORD (ix
, x
, NO_COND
);
55 v64si hx
= ix
& 0x7fffffff;
56 v64si k
= hx
>> 23; /* extract exponent */
57 VECTOR_IF (FLT_UWORD_IS_ZERO(hx
), cond
)
58 VECTOR_RETURN (x
, cond
);
60 VECTOR_IF (~FLT_UWORD_IS_FINITE(hx
), cond
) /* NaN or Inf */
61 VECTOR_RETURN (x
+ x
, cond
);
63 VECTOR_IF (FLT_UWORD_IS_SUBNORMAL (hx
), cond
);
64 VECTOR_COND_MOVE (x
, x
* two25
, cond
);
65 GET_FLOAT_WORD (ix
, x
, cond
);
66 VECTOR_COND_MOVE (k
, ((ix
& 0x7f800000) >> 23) - 25, cond
);
67 VECTOR_IF2 (n
< -50000, cond2
, cond
) /*underflow*/
68 VECTOR_RETURN (tiny
* x
, cond2
);
71 VECTOR_IF (n
> OVERFLOW_INT
, cond
) // in case integer overflow in n+k
72 VECTOR_RETURN (huge_v
* v64sf_copysignf_aux (huge_v
, x
, __mask
), cond
);
75 VECTOR_IF (k
> FLT_LARGEST_EXP
, cond
) /* overflow */
76 VECTOR_RETURN (huge_v
* v64sf_copysignf_aux (huge_v
, x
, __mask
), cond
);
78 VECTOR_IF (k
> 0, cond
) /* normal result */
79 SET_FLOAT_WORD (x
, (ix
& 0x807fffff) | (k
<< 23), cond
);
80 VECTOR_RETURN (x
, cond
);
82 VECTOR_IF (k
< FLT_SMALLEST_EXP
, cond
) /*underflow*/
83 VECTOR_RETURN (tiny_v
* v64sf_copysignf_aux (tiny_v
, x
, __mask
),
84 k
< FLT_SMALLEST_EXP
);
87 k
+= 25; /* subnormal result */
88 SET_FLOAT_WORD (x
, (ix
& 0x807fffff) | (k
<< 23), NO_COND
);
89 VECTOR_RETURN (x
* twom25
, NO_COND
);