1 /* Copyright (C) 2007-2013 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 3, or (at your option) any later
10 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 Under Section 7 of GPL version 3, you are granted additional
16 permissions described in the GCC Runtime Library Exception, version
17 3.1, as published by the Free Software Foundation.
19 You should have received a copy of the GNU General Public License and
20 a copy of the GCC Runtime Library Exception along with this program;
21 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 <http://www.gnu.org/licenses/>. */
25 #include "bid_internal.h"
27 #define DECIMAL_EXPONENT_BIAS_128 6176
28 #define MAX_DECIMAL_EXPONENT_128 12287
32 BID128_FUNCTION_ARG128_ARGTYPE2 (bid128_scalb
, x
, int, n
)
34 UINT128 CX
, CX2
, CX8
, res
;
37 int exponent_x
, rmode
;
39 // unpack arguments, check for NaN or Infinity
40 if (!unpack_BID128_value (&sign_x
, &exponent_x
, &CX
, x
)) {
41 // x is Inf. or NaN or 0
42 #ifdef SET_STATUS_FLAGS
43 if ((x
.w
[1] & SNAN_MASK64
) == SNAN_MASK64
) // y is sNaN
44 __set_status_flags (pfpsf
, INVALID_EXCEPTION
);
46 res
.w
[1] = CX
.w
[1] & QUIET_MASK64
;
49 exp64
= (SINT64
) exponent_x
+ (SINT64
) n
;
51 if(exp64
>MAX_DECIMAL_EXPONENT_128
) exp64
=MAX_DECIMAL_EXPONENT_128
;
53 get_BID128_very_fast (&res
, sign_x
, exponent_x
, CX
);
58 exp64
= (SINT64
) exponent_x
+ (SINT64
) n
;
61 if ((UINT32
) exponent_x
<= MAX_DECIMAL_EXPONENT_128
) {
62 get_BID128_very_fast (&res
, sign_x
, exponent_x
, CX
);
66 if (exp64
> MAX_DECIMAL_EXPONENT_128
) {
67 if (CX
.w
[1] < 0x314dc6448d93ull
) {
68 // try to normalize coefficient
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
);
79 while (CX
.w
[1] < 0x314dc6448d93ull
80 && exp64
> MAX_DECIMAL_EXPONENT_128
);
83 if (exp64
<= MAX_DECIMAL_EXPONENT_128
) {
84 get_BID128_very_fast (&res
, sign_x
, exponent_x
, CX
);
87 exponent_x
= 0x7fffffff; // overflow
90 // the BID pack routine will round the coefficient
92 get_BID128 (&res
, sign_x
, exponent_x
, CX
, (unsigned int *) &rmode
,