devctl.h: update for POSIX-1.2024
[newlib-cygwin.git] / newlib / libm / machine / amdgcn / v64sf_scalbn.c
blob52c18dc1a27d259250c09045101687c151c187f0
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/common/sf_scalbn.c in Newlib. */
28 #include "amdgcnmach.h"
29 #include <limits.h>
30 #include <float.h>
32 #if INT_MAX > 50000
33 #define OVERFLOW_INT 50000
34 #else
35 #define OVERFLOW_INT 30000
36 #endif
38 static const float
39 two25 = 3.355443200e+07, /* 0x4c000000 */
40 twom25 = 2.9802322388e-08, /* 0x33000000 */
41 huge = 1.0e+30,
42 tiny = 1.0e-30;
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);
53 v64si ix;
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);
59 VECTOR_ENDIF
60 VECTOR_IF (~FLT_UWORD_IS_FINITE(hx), cond) /* NaN or Inf */
61 VECTOR_RETURN (x + x, cond);
62 VECTOR_ENDIF
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);
69 VECTOR_ENDIF
70 VECTOR_ENDIF
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);
73 VECTOR_ENDIF
74 k = k + n;
75 VECTOR_IF (k > FLT_LARGEST_EXP, cond) /* overflow */
76 VECTOR_RETURN (huge_v * v64sf_copysignf_aux (huge_v, x, __mask), cond);
77 VECTOR_ENDIF
78 VECTOR_IF (k > 0, cond) /* normal result */
79 SET_FLOAT_WORD (x, (ix & 0x807fffff) | (k << 23), cond);
80 VECTOR_RETURN (x, cond);
81 VECTOR_ENDIF
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);
85 VECTOR_ENDIF
87 k += 25; /* subnormal result */
88 SET_FLOAT_WORD (x, (ix & 0x807fffff) | (k << 23), NO_COND);
89 VECTOR_RETURN (x * twom25, NO_COND);
91 FUNCTION_RETURN;