]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgcc/config/libbid/bid128_scalb.c
Update copyright years.
[thirdparty/gcc.git] / libgcc / config / libbid / bid128_scalb.c
CommitLineData
a945c346 1/* Copyright (C) 2007-2024 Free Software Foundation, Inc.
200359e8
L
2
3This file is part of GCC.
4
5GCC is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free
748086b7 7Software Foundation; either version 3, or (at your option) any later
200359e8
L
8version.
9
200359e8
L
10GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11WARRANTY; without even the implied warranty of MERCHANTABILITY or
12FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13for more details.
14
748086b7
JJ
15Under Section 7 of GPL version 3, you are granted additional
16permissions described in the GCC Runtime Library Exception, version
173.1, as published by the Free Software Foundation.
18
19You should have received a copy of the GNU General Public License and
20a copy of the GCC Runtime Library Exception along with this program;
21see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22<http://www.gnu.org/licenses/>. */
200359e8
L
23
24#define BID_128RES
25#include "bid_internal.h"
26
27#define DECIMAL_EXPONENT_BIAS_128 6176
28#define MAX_DECIMAL_EXPONENT_128 12287
29
30
31
b2a00c89 32BID128_FUNCTION_ARG128_ARGTYPE2 (bid128_scalb, x, int, n)
200359e8 33
b2a00c89
L
34 UINT128 CX, CX2, CX8, res;
35 SINT64 exp64;
36 UINT64 sign_x;
37 int exponent_x, rmode;
200359e8
L
38
39 // unpack arguments, check for NaN or Infinity
b2a00c89 40if (!unpack_BID128_value (&sign_x, &exponent_x, &CX, x)) {
200359e8 41 // x is Inf. or NaN or 0
b2a00c89
L
42#ifdef SET_STATUS_FLAGS
43if ((x.w[1] & SNAN_MASK64) == SNAN_MASK64) // y is sNaN
44 __set_status_flags (pfpsf, INVALID_EXCEPTION);
45#endif
46res.w[1] = CX.w[1] & QUIET_MASK64;
47res.w[0] = CX.w[0];
48if (!CX.w[1]) {
49 exp64 = (SINT64) exponent_x + (SINT64) n;
50 if(exp64<0) exp64=0;
51 if(exp64>MAX_DECIMAL_EXPONENT_128) exp64=MAX_DECIMAL_EXPONENT_128;
52 exponent_x = exp64;
53 get_BID128_very_fast (&res, sign_x, exponent_x, CX);
54}
55BID_RETURN (res);
56}
200359e8 57
b2a00c89
L
58exp64 = (SINT64) exponent_x + (SINT64) n;
59exponent_x = exp64;
200359e8 60
b2a00c89
L
61if ((UINT32) exponent_x <= MAX_DECIMAL_EXPONENT_128) {
62 get_BID128_very_fast (&res, sign_x, exponent_x, CX);
63 BID_RETURN (res);
64}
200359e8 65 // check for overflow
b2a00c89
L
66if (exp64 > MAX_DECIMAL_EXPONENT_128) {
67 if (CX.w[1] < 0x314dc6448d93ull) {
68 // try to normalize coefficient
69 do {
70 CX8.w[1] = (CX.w[1] << 3) | (CX.w[0] >> 61);
71 CX8.w[0] = CX.w[0] << 3;
72 CX2.w[1] = (CX.w[1] << 1) | (CX.w[0] >> 63);
73 CX2.w[0] = CX.w[0] << 1;
74 __add_128_128 (CX, CX2, CX8);
75
76 exponent_x--;
77 exp64--;
200359e8 78 }
b2a00c89
L
79 while (CX.w[1] < 0x314dc6448d93ull
80 && exp64 > MAX_DECIMAL_EXPONENT_128);
81
200359e8 82 }
b2a00c89
L
83 if (exp64 <= MAX_DECIMAL_EXPONENT_128) {
84 get_BID128_very_fast (&res, sign_x, exponent_x, CX);
85 BID_RETURN (res);
86 } else
87 exponent_x = 0x7fffffff; // overflow
88}
200359e8
L
89 // exponent < 0
90 // the BID pack routine will round the coefficient
b2a00c89
L
91rmode = rnd_mode;
92get_BID128 (&res, sign_x, exponent_x, CX, (unsigned int *) &rmode,
93 pfpsf);
94BID_RETURN (res);
200359e8
L
95
96}