1 /* Copyright (C) 2007 Free Software Foundation, Inc.
3 This file is part of GCC.
5 GCC is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2, or (at your option) any later
10 In addition to the permissions in the GNU General Public License, the
11 Free Software Foundation gives you unlimited permission to link the
12 compiled version of this file into combinations with other programs,
13 and to distribute those combinations without any restriction coming
14 from the use of this file. (The General Public License restrictions
15 do apply in other respects; for example, they cover modification of
16 the file, and distribution when not linked into a combine
19 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
20 WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 You should have received a copy of the GNU General Public License
25 along with GCC; see the file COPYING. If not, write to the Free
26 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
30 #include "bid_internal.h"
32 #define DECIMAL_EXPONENT_BIAS_128 6176
33 #define MAX_DECIMAL_EXPONENT_128 12287
37 BID128_FUNCTION_ARG128_ARGTYPE2 (bid128_scalb
, x
, int, n
)
39 UINT128 CX
, CX2
, CX8
, res
;
42 int exponent_x
, rmode
;
44 // unpack arguments, check for NaN or Infinity
45 if (!unpack_BID128_value (&sign_x
, &exponent_x
, &CX
, x
)) {
46 // x is Inf. or NaN or 0
47 #ifdef SET_STATUS_FLAGS
48 if ((x
.w
[1] & SNAN_MASK64
) == SNAN_MASK64
) // y is sNaN
49 __set_status_flags (pfpsf
, INVALID_EXCEPTION
);
51 res
.w
[1] = CX
.w
[1] & QUIET_MASK64
;
54 exp64
= (SINT64
) exponent_x
+ (SINT64
) n
;
56 if(exp64
>MAX_DECIMAL_EXPONENT_128
) exp64
=MAX_DECIMAL_EXPONENT_128
;
58 get_BID128_very_fast (&res
, sign_x
, exponent_x
, CX
);
63 exp64
= (SINT64
) exponent_x
+ (SINT64
) n
;
66 if ((UINT32
) exponent_x
<= MAX_DECIMAL_EXPONENT_128
) {
67 get_BID128_very_fast (&res
, sign_x
, exponent_x
, CX
);
71 if (exp64
> MAX_DECIMAL_EXPONENT_128
) {
72 if (CX
.w
[1] < 0x314dc6448d93ull
) {
73 // try to normalize coefficient
75 CX8
.w
[1] = (CX
.w
[1] << 3) | (CX
.w
[0] >> 61);
76 CX8
.w
[0] = CX
.w
[0] << 3;
77 CX2
.w
[1] = (CX
.w
[1] << 1) | (CX
.w
[0] >> 63);
78 CX2
.w
[0] = CX
.w
[0] << 1;
79 __add_128_128 (CX
, CX2
, CX8
);
84 while (CX
.w
[1] < 0x314dc6448d93ull
85 && exp64
> MAX_DECIMAL_EXPONENT_128
);
88 if (exp64
<= MAX_DECIMAL_EXPONENT_128
) {
89 get_BID128_very_fast (&res
, sign_x
, exponent_x
, CX
);
92 exponent_x
= 0x7fffffff; // overflow
95 // the BID pack routine will round the coefficient
97 get_BID128 (&res
, sign_x
, exponent_x
, CX
, (unsigned int *) &rmode
,