comparison gcc/fixed-value.c @ 16:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
comparison
equal deleted inserted replaced
15:561a7518be6b 16:04ced10e8804
1 /* Fixed-point arithmetic support. 1 /* Fixed-point arithmetic support.
2 Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. 2 Copyright (C) 2006-2017 Free Software Foundation, Inc.
3 3
4 This file is part of GCC. 4 This file is part of GCC.
5 5
6 GCC is free software; you can redistribute it and/or modify it under 6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free 7 the terms of the GNU General Public License as published by the Free
57 FIXED_GT_MAX_EPS, if it is greater than the maximum, but not equal to 57 FIXED_GT_MAX_EPS, if it is greater than the maximum, but not equal to
58 the maximum plus the epsilon. 58 the maximum plus the epsilon.
59 FIXED_MAX_EPS, if it is equal to the maximum plus the epsilon. */ 59 FIXED_MAX_EPS, if it is equal to the maximum plus the epsilon. */
60 60
61 static enum fixed_value_range_code 61 static enum fixed_value_range_code
62 check_real_for_fixed_mode (REAL_VALUE_TYPE *real_value, enum machine_mode mode) 62 check_real_for_fixed_mode (REAL_VALUE_TYPE *real_value, machine_mode mode)
63 { 63 {
64 REAL_VALUE_TYPE max_value, min_value, epsilon_value; 64 REAL_VALUE_TYPE max_value, min_value, epsilon_value;
65 65
66 real_2expN (&max_value, GET_MODE_IBIT (mode), mode); 66 real_2expN (&max_value, GET_MODE_IBIT (mode), VOIDmode);
67 real_2expN (&epsilon_value, -GET_MODE_FBIT (mode), mode); 67 real_2expN (&epsilon_value, -GET_MODE_FBIT (mode), VOIDmode);
68 68
69 if (SIGNED_FIXED_POINT_MODE_P (mode)) 69 if (SIGNED_FIXED_POINT_MODE_P (mode))
70 min_value = real_value_negate (&max_value); 70 min_value = real_value_negate (&max_value);
71 else 71 else
72 real_from_string (&min_value, "0.0"); 72 real_from_string (&min_value, "0.0");
79 if (real_compare (GT_EXPR, real_value, &max_value)) 79 if (real_compare (GT_EXPR, real_value, &max_value))
80 return FIXED_GT_MAX_EPS; 80 return FIXED_GT_MAX_EPS;
81 return FIXED_OK; 81 return FIXED_OK;
82 } 82 }
83 83
84
85 /* Construct a CONST_FIXED from a bit payload and machine mode MODE.
86 The bits in PAYLOAD are sign-extended/zero-extended according to MODE. */
87
88 FIXED_VALUE_TYPE
89 fixed_from_double_int (double_int payload, scalar_mode mode)
90 {
91 FIXED_VALUE_TYPE value;
92
93 gcc_assert (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_DOUBLE_INT);
94
95 if (SIGNED_SCALAR_FIXED_POINT_MODE_P (mode))
96 value.data = payload.sext (1 + GET_MODE_IBIT (mode) + GET_MODE_FBIT (mode));
97 else if (UNSIGNED_SCALAR_FIXED_POINT_MODE_P (mode))
98 value.data = payload.zext (GET_MODE_IBIT (mode) + GET_MODE_FBIT (mode));
99 else
100 gcc_unreachable ();
101
102 value.mode = mode;
103
104 return value;
105 }
106
107
84 /* Initialize from a decimal or hexadecimal string. */ 108 /* Initialize from a decimal or hexadecimal string. */
85 109
86 void 110 void
87 fixed_from_string (FIXED_VALUE_TYPE *f, const char *str, enum machine_mode mode) 111 fixed_from_string (FIXED_VALUE_TYPE *f, const char *str, scalar_mode mode)
88 { 112 {
89 REAL_VALUE_TYPE real_value, fixed_value, base_value; 113 REAL_VALUE_TYPE real_value, fixed_value, base_value;
90 unsigned int fbit; 114 unsigned int fbit;
91 enum fixed_value_range_code temp; 115 enum fixed_value_range_code temp;
116 bool fail;
92 117
93 f->mode = mode; 118 f->mode = mode;
94 fbit = GET_MODE_FBIT (mode); 119 fbit = GET_MODE_FBIT (mode);
95 120
96 real_from_string (&real_value, str); 121 real_from_string (&real_value, str);
99 if (temp == FIXED_UNDERFLOW 124 if (temp == FIXED_UNDERFLOW
100 || temp == FIXED_GT_MAX_EPS 125 || temp == FIXED_GT_MAX_EPS
101 || (temp == FIXED_MAX_EPS && ALL_ACCUM_MODE_P (f->mode))) 126 || (temp == FIXED_MAX_EPS && ALL_ACCUM_MODE_P (f->mode)))
102 warning (OPT_Woverflow, 127 warning (OPT_Woverflow,
103 "large fixed-point constant implicitly truncated to fixed-point type"); 128 "large fixed-point constant implicitly truncated to fixed-point type");
104 real_2expN (&base_value, fbit, mode); 129 real_2expN (&base_value, fbit, VOIDmode);
105 real_arithmetic (&fixed_value, MULT_EXPR, &real_value, &base_value); 130 real_arithmetic (&fixed_value, MULT_EXPR, &real_value, &base_value);
106 real_to_integer2 ((HOST_WIDE_INT *)&f->data.low, &f->data.high, 131 wide_int w = real_to_integer (&fixed_value, &fail,
107 &fixed_value); 132 GET_MODE_PRECISION (mode));
133 f->data.low = w.ulow ();
134 f->data.high = w.elt (1);
108 135
109 if (temp == FIXED_MAX_EPS && ALL_FRACT_MODE_P (f->mode)) 136 if (temp == FIXED_MAX_EPS && ALL_FRACT_MODE_P (f->mode))
110 { 137 {
111 /* From the spec, we need to evaluate 1 to the maximal value. */ 138 /* From the spec, we need to evaluate 1 to the maximal value. */
112 f->data.low = -1; 139 f->data.low = -1;
113 f->data.high = -1; 140 f->data.high = -1;
114 f->data = double_int_ext (f->data, 141 f->data = f->data.zext (GET_MODE_FBIT (f->mode)
115 GET_MODE_FBIT (f->mode) 142 + GET_MODE_IBIT (f->mode));
116 + GET_MODE_IBIT (f->mode), 1);
117 } 143 }
118 else 144 else
119 f->data = double_int_ext (f->data, 145 f->data = f->data.ext (SIGNED_FIXED_POINT_MODE_P (f->mode)
120 SIGNED_FIXED_POINT_MODE_P (f->mode)
121 + GET_MODE_FBIT (f->mode) 146 + GET_MODE_FBIT (f->mode)
122 + GET_MODE_IBIT (f->mode), 147 + GET_MODE_IBIT (f->mode),
123 UNSIGNED_FIXED_POINT_MODE_P (f->mode)); 148 UNSIGNED_FIXED_POINT_MODE_P (f->mode));
124 } 149 }
125 150
129 fixed_to_decimal (char *str, const FIXED_VALUE_TYPE *f_orig, 154 fixed_to_decimal (char *str, const FIXED_VALUE_TYPE *f_orig,
130 size_t buf_size) 155 size_t buf_size)
131 { 156 {
132 REAL_VALUE_TYPE real_value, base_value, fixed_value; 157 REAL_VALUE_TYPE real_value, base_value, fixed_value;
133 158
134 real_2expN (&base_value, GET_MODE_FBIT (f_orig->mode), f_orig->mode); 159 signop sgn = UNSIGNED_FIXED_POINT_MODE_P (f_orig->mode) ? UNSIGNED : SIGNED;
135 real_from_integer (&real_value, VOIDmode, f_orig->data.low, f_orig->data.high, 160 real_2expN (&base_value, GET_MODE_FBIT (f_orig->mode), VOIDmode);
136 UNSIGNED_FIXED_POINT_MODE_P (f_orig->mode)); 161 real_from_integer (&real_value, VOIDmode,
162 wide_int::from (f_orig->data,
163 GET_MODE_PRECISION (f_orig->mode), sgn),
164 sgn);
137 real_arithmetic (&fixed_value, RDIV_EXPR, &real_value, &base_value); 165 real_arithmetic (&fixed_value, RDIV_EXPR, &real_value, &base_value);
138 real_to_decimal (str, &fixed_value, buf_size, 0, 1); 166 real_to_decimal (str, &fixed_value, buf_size, 0, 1);
139 } 167 }
140 168
141 /* If SAT_P, saturate A to the maximum or the minimum, and save to *F based on 169 /* If SAT_P, saturate A to the maximum or the minimum, and save to *F based on
145 of the fixed-point value (the sum of a possible sign bit, possible ibits, 173 of the fixed-point value (the sum of a possible sign bit, possible ibits,
146 and fbits). 174 and fbits).
147 Return true, if !SAT_P and overflow. */ 175 Return true, if !SAT_P and overflow. */
148 176
149 static bool 177 static bool
150 fixed_saturate1 (enum machine_mode mode, double_int a, double_int *f, 178 fixed_saturate1 (machine_mode mode, double_int a, double_int *f,
151 bool sat_p) 179 bool sat_p)
152 { 180 {
153 bool overflow_p = false; 181 bool overflow_p = false;
154 bool unsigned_p = UNSIGNED_FIXED_POINT_MODE_P (mode); 182 bool unsigned_p = UNSIGNED_FIXED_POINT_MODE_P (mode);
155 int i_f_bits = GET_MODE_IBIT (mode) + GET_MODE_FBIT (mode); 183 int i_f_bits = GET_MODE_IBIT (mode) + GET_MODE_FBIT (mode);
157 if (unsigned_p) /* Unsigned type. */ 185 if (unsigned_p) /* Unsigned type. */
158 { 186 {
159 double_int max; 187 double_int max;
160 max.low = -1; 188 max.low = -1;
161 max.high = -1; 189 max.high = -1;
162 max = double_int_ext (max, i_f_bits, 1); 190 max = max.zext (i_f_bits);
163 if (double_int_cmp (a, max, 1) == 1) 191 if (a.ugt (max))
164 { 192 {
165 if (sat_p) 193 if (sat_p)
166 *f = max; 194 *f = max;
167 else 195 else
168 overflow_p = true; 196 overflow_p = true;
171 else /* Signed type. */ 199 else /* Signed type. */
172 { 200 {
173 double_int max, min; 201 double_int max, min;
174 max.high = -1; 202 max.high = -1;
175 max.low = -1; 203 max.low = -1;
176 max = double_int_ext (max, i_f_bits, 1); 204 max = max.zext (i_f_bits);
177 min.high = 0; 205 min.high = 0;
178 min.low = 1; 206 min.low = 1;
179 lshift_double (min.low, min.high, i_f_bits, 207 min = min.alshift (i_f_bits, HOST_BITS_PER_DOUBLE_INT);
180 2 * HOST_BITS_PER_WIDE_INT, 208 min = min.sext (1 + i_f_bits);
181 &min.low, &min.high, 1); 209 if (a.sgt (max))
182 min = double_int_ext (min, 1 + i_f_bits, 0);
183 if (double_int_cmp (a, max, 0) == 1)
184 { 210 {
185 if (sat_p) 211 if (sat_p)
186 *f = max; 212 *f = max;
187 else 213 else
188 overflow_p = true; 214 overflow_p = true;
189 } 215 }
190 else if (double_int_cmp (a, min, 0) == -1) 216 else if (a.slt (min))
191 { 217 {
192 if (sat_p) 218 if (sat_p)
193 *f = min; 219 *f = min;
194 else 220 else
195 overflow_p = true; 221 overflow_p = true;
205 of the fixed-point value (the sum of a possible sign bit, possible ibits, 231 of the fixed-point value (the sum of a possible sign bit, possible ibits,
206 and fbits). 232 and fbits).
207 Return true, if !SAT_P and overflow. */ 233 Return true, if !SAT_P and overflow. */
208 234
209 static bool 235 static bool
210 fixed_saturate2 (enum machine_mode mode, double_int a_high, double_int a_low, 236 fixed_saturate2 (machine_mode mode, double_int a_high, double_int a_low,
211 double_int *f, bool sat_p) 237 double_int *f, bool sat_p)
212 { 238 {
213 bool overflow_p = false; 239 bool overflow_p = false;
214 bool unsigned_p = UNSIGNED_FIXED_POINT_MODE_P (mode); 240 bool unsigned_p = UNSIGNED_FIXED_POINT_MODE_P (mode);
215 int i_f_bits = GET_MODE_IBIT (mode) + GET_MODE_FBIT (mode); 241 int i_f_bits = GET_MODE_IBIT (mode) + GET_MODE_FBIT (mode);
219 double_int max_r, max_s; 245 double_int max_r, max_s;
220 max_r.high = 0; 246 max_r.high = 0;
221 max_r.low = 0; 247 max_r.low = 0;
222 max_s.high = -1; 248 max_s.high = -1;
223 max_s.low = -1; 249 max_s.low = -1;
224 max_s = double_int_ext (max_s, i_f_bits, 1); 250 max_s = max_s.zext (i_f_bits);
225 if (double_int_cmp (a_high, max_r, 1) == 1 251 if (a_high.ugt (max_r)
226 || (double_int_equal_p (a_high, max_r) && 252 || (a_high == max_r &&
227 double_int_cmp (a_low, max_s, 1) == 1)) 253 a_low.ugt (max_s)))
228 { 254 {
229 if (sat_p) 255 if (sat_p)
230 *f = max_s; 256 *f = max_s;
231 else 257 else
232 overflow_p = true; 258 overflow_p = true;
237 double_int max_r, max_s, min_r, min_s; 263 double_int max_r, max_s, min_r, min_s;
238 max_r.high = 0; 264 max_r.high = 0;
239 max_r.low = 0; 265 max_r.low = 0;
240 max_s.high = -1; 266 max_s.high = -1;
241 max_s.low = -1; 267 max_s.low = -1;
242 max_s = double_int_ext (max_s, i_f_bits, 1); 268 max_s = max_s.zext (i_f_bits);
243 min_r.high = -1; 269 min_r.high = -1;
244 min_r.low = -1; 270 min_r.low = -1;
245 min_s.high = 0; 271 min_s.high = 0;
246 min_s.low = 1; 272 min_s.low = 1;
247 lshift_double (min_s.low, min_s.high, i_f_bits, 273 min_s = min_s.alshift (i_f_bits, HOST_BITS_PER_DOUBLE_INT);
248 2 * HOST_BITS_PER_WIDE_INT, 274 min_s = min_s.sext (1 + i_f_bits);
249 &min_s.low, &min_s.high, 1); 275 if (a_high.sgt (max_r)
250 min_s = double_int_ext (min_s, 1 + i_f_bits, 0); 276 || (a_high == max_r &&
251 if (double_int_cmp (a_high, max_r, 0) == 1 277 a_low.ugt (max_s)))
252 || (double_int_equal_p (a_high, max_r) &&
253 double_int_cmp (a_low, max_s, 1) == 1))
254 { 278 {
255 if (sat_p) 279 if (sat_p)
256 *f = max_s; 280 *f = max_s;
257 else 281 else
258 overflow_p = true; 282 overflow_p = true;
259 } 283 }
260 else if (double_int_cmp (a_high, min_r, 0) == -1 284 else if (a_high.slt (min_r)
261 || (double_int_equal_p (a_high, min_r) && 285 || (a_high == min_r &&
262 double_int_cmp (a_low, min_s, 1) == -1)) 286 a_low.ult (min_s)))
263 { 287 {
264 if (sat_p) 288 if (sat_p)
265 *f = min_s; 289 *f = min_s;
266 else 290 else
267 overflow_p = true; 291 overflow_p = true;
295 int i_f_bits; 319 int i_f_bits;
296 320
297 /* This was a conditional expression but it triggered a bug in 321 /* This was a conditional expression but it triggered a bug in
298 Sun C 5.5. */ 322 Sun C 5.5. */
299 if (subtract_p) 323 if (subtract_p)
300 temp = double_int_neg (b->data); 324 temp = -b->data;
301 else 325 else
302 temp = b->data; 326 temp = b->data;
303 327
304 unsigned_p = UNSIGNED_FIXED_POINT_MODE_P (a->mode); 328 unsigned_p = UNSIGNED_FIXED_POINT_MODE_P (a->mode);
305 i_f_bits = GET_MODE_IBIT (a->mode) + GET_MODE_FBIT (a->mode); 329 i_f_bits = GET_MODE_IBIT (a->mode) + GET_MODE_FBIT (a->mode);
306 f->mode = a->mode; 330 f->mode = a->mode;
307 f->data = double_int_add (a->data, temp); 331 f->data = a->data + temp;
308 if (unsigned_p) /* Unsigned type. */ 332 if (unsigned_p) /* Unsigned type. */
309 { 333 {
310 if (subtract_p) /* Unsigned subtraction. */ 334 if (subtract_p) /* Unsigned subtraction. */
311 { 335 {
312 if (double_int_cmp (a->data, b->data, 1) == -1) 336 if (a->data.ult (b->data))
313 { 337 {
314 if (sat_p) 338 if (sat_p)
315 { 339 {
316 f->data.high = 0; 340 f->data.high = 0;
317 f->data.low = 0; 341 f->data.low = 0;
320 overflow_p = true; 344 overflow_p = true;
321 } 345 }
322 } 346 }
323 else /* Unsigned addition. */ 347 else /* Unsigned addition. */
324 { 348 {
325 f->data = double_int_ext (f->data, i_f_bits, 1); 349 f->data = f->data.zext (i_f_bits);
326 if (double_int_cmp (f->data, a->data, 1) == -1 350 if (f->data.ult (a->data)
327 || double_int_cmp (f->data, b->data, 1) == -1) 351 || f->data.ult (b->data))
328 { 352 {
329 if (sat_p) 353 if (sat_p)
330 { 354 {
331 f->data.high = -1; 355 f->data.high = -1;
332 f->data.low = -1; 356 f->data.low = -1;
351 { 375 {
352 if (sat_p) 376 if (sat_p)
353 { 377 {
354 f->data.low = 1; 378 f->data.low = 1;
355 f->data.high = 0; 379 f->data.high = 0;
356 lshift_double (f->data.low, f->data.high, i_f_bits, 380 f->data = f->data.alshift (i_f_bits, HOST_BITS_PER_DOUBLE_INT);
357 2 * HOST_BITS_PER_WIDE_INT,
358 &f->data.low, &f->data.high, 1);
359 if (get_fixed_sign_bit (a->data, i_f_bits) == 0) 381 if (get_fixed_sign_bit (a->data, i_f_bits) == 0)
360 { 382 {
361 double_int one; 383 --f->data;
362 one.low = 1;
363 one.high = 0;
364 f->data = double_int_sub (f->data, one);
365 } 384 }
366 } 385 }
367 else 386 else
368 overflow_p = true; 387 overflow_p = true;
369 } 388 }
370 } 389 }
371 f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p); 390 f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p);
372 return overflow_p; 391 return overflow_p;
373 } 392 }
374 393
375 /* Calculate F = A * B. 394 /* Calculate F = A * B.
376 If SAT_P, saturate the result to the max or the min. 395 If SAT_P, saturate the result to the max or the min.
384 bool unsigned_p = UNSIGNED_FIXED_POINT_MODE_P (a->mode); 403 bool unsigned_p = UNSIGNED_FIXED_POINT_MODE_P (a->mode);
385 int i_f_bits = GET_MODE_IBIT (a->mode) + GET_MODE_FBIT (a->mode); 404 int i_f_bits = GET_MODE_IBIT (a->mode) + GET_MODE_FBIT (a->mode);
386 f->mode = a->mode; 405 f->mode = a->mode;
387 if (GET_MODE_PRECISION (f->mode) <= HOST_BITS_PER_WIDE_INT) 406 if (GET_MODE_PRECISION (f->mode) <= HOST_BITS_PER_WIDE_INT)
388 { 407 {
389 f->data = double_int_mul (a->data, b->data); 408 f->data = a->data * b->data;
390 lshift_double (f->data.low, f->data.high, 409 f->data = f->data.lshift (-GET_MODE_FBIT (f->mode),
391 (-GET_MODE_FBIT (f->mode)), 410 HOST_BITS_PER_DOUBLE_INT, !unsigned_p);
392 2 * HOST_BITS_PER_WIDE_INT,
393 &f->data.low, &f->data.high, !unsigned_p);
394 overflow_p = fixed_saturate1 (f->mode, f->data, &f->data, sat_p); 411 overflow_p = fixed_saturate1 (f->mode, f->data, &f->data, sat_p);
395 } 412 }
396 else 413 else
397 { 414 {
398 /* The result of multiplication expands to two double_int. */ 415 /* The result of multiplication expands to two double_int. */
410 b_high.high = 0; 427 b_high.high = 0;
411 b_low.low = b->data.low; 428 b_low.low = b->data.low;
412 b_low.high = 0; 429 b_low.high = 0;
413 430
414 /* Perform four multiplications. */ 431 /* Perform four multiplications. */
415 low_low = double_int_mul (a_low, b_low); 432 low_low = a_low * b_low;
416 low_high = double_int_mul (a_low, b_high); 433 low_high = a_low * b_high;
417 high_low = double_int_mul (a_high, b_low); 434 high_low = a_high * b_low;
418 high_high = double_int_mul (a_high, b_high); 435 high_high = a_high * b_high;
419 436
420 /* Accumulate four results to {r, s}. */ 437 /* Accumulate four results to {r, s}. */
421 temp1.high = high_low.low; 438 temp1.high = high_low.low;
422 temp1.low = 0; 439 temp1.low = 0;
423 s = double_int_add (low_low, temp1); 440 s = low_low + temp1;
424 if (double_int_cmp (s, low_low, 1) == -1 441 if (s.ult (low_low)
425 || double_int_cmp (s, temp1, 1) == -1) 442 || s.ult (temp1))
426 carry ++; /* Carry */ 443 carry ++; /* Carry */
427 temp1.high = s.high; 444 temp1.high = s.high;
428 temp1.low = s.low; 445 temp1.low = s.low;
429 temp2.high = low_high.low; 446 temp2.high = low_high.low;
430 temp2.low = 0; 447 temp2.low = 0;
431 s = double_int_add (temp1, temp2); 448 s = temp1 + temp2;
432 if (double_int_cmp (s, temp1, 1) == -1 449 if (s.ult (temp1)
433 || double_int_cmp (s, temp2, 1) == -1) 450 || s.ult (temp2))
434 carry ++; /* Carry */ 451 carry ++; /* Carry */
435 452
436 temp1.low = high_low.high; 453 temp1.low = high_low.high;
437 temp1.high = 0; 454 temp1.high = 0;
438 r = double_int_add (high_high, temp1); 455 r = high_high + temp1;
439 temp1.low = low_high.high; 456 temp1.low = low_high.high;
440 temp1.high = 0; 457 temp1.high = 0;
441 r = double_int_add (r, temp1); 458 r += temp1;
442 temp1.low = carry; 459 temp1.low = carry;
443 temp1.high = 0; 460 temp1.high = 0;
444 r = double_int_add (r, temp1); 461 r += temp1;
445 462
446 /* We need to subtract b from r, if a < 0. */ 463 /* We need to subtract b from r, if a < 0. */
447 if (!unsigned_p && a->data.high < 0) 464 if (!unsigned_p && a->data.high < 0)
448 r = double_int_sub (r, b->data); 465 r -= b->data;
449 /* We need to subtract a from r, if b < 0. */ 466 /* We need to subtract a from r, if b < 0. */
450 if (!unsigned_p && b->data.high < 0) 467 if (!unsigned_p && b->data.high < 0)
451 r = double_int_sub (r, a->data); 468 r -= a->data;
452 469
453 /* Shift right the result by FBIT. */ 470 /* Shift right the result by FBIT. */
454 if (GET_MODE_FBIT (f->mode) == 2 * HOST_BITS_PER_WIDE_INT) 471 if (GET_MODE_FBIT (f->mode) == HOST_BITS_PER_DOUBLE_INT)
455 { 472 {
456 s.low = r.low; 473 s.low = r.low;
457 s.high = r.high; 474 s.high = r.high;
458 if (unsigned_p) 475 if (unsigned_p)
459 { 476 {
468 f->data.low = s.low; 485 f->data.low = s.low;
469 f->data.high = s.high; 486 f->data.high = s.high;
470 } 487 }
471 else 488 else
472 { 489 {
473 lshift_double (s.low, s.high, 490 s = s.llshift ((-GET_MODE_FBIT (f->mode)), HOST_BITS_PER_DOUBLE_INT);
474 (-GET_MODE_FBIT (f->mode)), 491 f->data = r.llshift ((HOST_BITS_PER_DOUBLE_INT
475 2 * HOST_BITS_PER_WIDE_INT,
476 &s.low, &s.high, 0);
477 lshift_double (r.low, r.high,
478 (2 * HOST_BITS_PER_WIDE_INT
479 - GET_MODE_FBIT (f->mode)), 492 - GET_MODE_FBIT (f->mode)),
480 2 * HOST_BITS_PER_WIDE_INT, 493 HOST_BITS_PER_DOUBLE_INT);
481 &f->data.low, &f->data.high, 0);
482 f->data.low = f->data.low | s.low; 494 f->data.low = f->data.low | s.low;
483 f->data.high = f->data.high | s.high; 495 f->data.high = f->data.high | s.high;
484 s.low = f->data.low; 496 s.low = f->data.low;
485 s.high = f->data.high; 497 s.high = f->data.high;
486 lshift_double (r.low, r.high, 498 r = r.lshift (-GET_MODE_FBIT (f->mode),
487 (-GET_MODE_FBIT (f->mode)), 499 HOST_BITS_PER_DOUBLE_INT, !unsigned_p);
488 2 * HOST_BITS_PER_WIDE_INT,
489 &r.low, &r.high, !unsigned_p);
490 } 500 }
491 501
492 overflow_p = fixed_saturate2 (f->mode, r, s, &f->data, sat_p); 502 overflow_p = fixed_saturate2 (f->mode, r, s, &f->data, sat_p);
493 } 503 }
494 504
495 f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p); 505 f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p);
496 return overflow_p; 506 return overflow_p;
497 } 507 }
498 508
499 /* Calculate F = A / B. 509 /* Calculate F = A / B.
500 If SAT_P, saturate the result to the max or the min. 510 If SAT_P, saturate the result to the max or the min.
508 bool unsigned_p = UNSIGNED_FIXED_POINT_MODE_P (a->mode); 518 bool unsigned_p = UNSIGNED_FIXED_POINT_MODE_P (a->mode);
509 int i_f_bits = GET_MODE_IBIT (a->mode) + GET_MODE_FBIT (a->mode); 519 int i_f_bits = GET_MODE_IBIT (a->mode) + GET_MODE_FBIT (a->mode);
510 f->mode = a->mode; 520 f->mode = a->mode;
511 if (GET_MODE_PRECISION (f->mode) <= HOST_BITS_PER_WIDE_INT) 521 if (GET_MODE_PRECISION (f->mode) <= HOST_BITS_PER_WIDE_INT)
512 { 522 {
513 lshift_double (a->data.low, a->data.high, 523 f->data = a->data.lshift (GET_MODE_FBIT (f->mode),
514 GET_MODE_FBIT (f->mode), 524 HOST_BITS_PER_DOUBLE_INT, !unsigned_p);
515 2 * HOST_BITS_PER_WIDE_INT, 525 f->data = f->data.div (b->data, unsigned_p, TRUNC_DIV_EXPR);
516 &f->data.low, &f->data.high, !unsigned_p);
517 f->data = double_int_div (f->data, b->data, unsigned_p, TRUNC_DIV_EXPR);
518 overflow_p = fixed_saturate1 (f->mode, f->data, &f->data, sat_p); 526 overflow_p = fixed_saturate1 (f->mode, f->data, &f->data, sat_p);
519 } 527 }
520 else 528 else
521 { 529 {
522 double_int pos_a, pos_b, r, s; 530 double_int pos_a, pos_b, r, s;
525 int i; 533 int i;
526 534
527 /* If a < 0, negate a. */ 535 /* If a < 0, negate a. */
528 if (!unsigned_p && a->data.high < 0) 536 if (!unsigned_p && a->data.high < 0)
529 { 537 {
530 pos_a = double_int_neg (a->data); 538 pos_a = -a->data;
531 num_of_neg ++; 539 num_of_neg ++;
532 } 540 }
533 else 541 else
534 pos_a = a->data; 542 pos_a = a->data;
535 543
536 /* If b < 0, negate b. */ 544 /* If b < 0, negate b. */
537 if (!unsigned_p && b->data.high < 0) 545 if (!unsigned_p && b->data.high < 0)
538 { 546 {
539 pos_b = double_int_neg (b->data); 547 pos_b = -b->data;
540 num_of_neg ++; 548 num_of_neg ++;
541 } 549 }
542 else 550 else
543 pos_b = b->data; 551 pos_b = b->data;
544 552
545 /* Left shift pos_a to {r, s} by FBIT. */ 553 /* Left shift pos_a to {r, s} by FBIT. */
546 if (GET_MODE_FBIT (f->mode) == 2 * HOST_BITS_PER_WIDE_INT) 554 if (GET_MODE_FBIT (f->mode) == HOST_BITS_PER_DOUBLE_INT)
547 { 555 {
548 r = pos_a; 556 r = pos_a;
549 s.high = 0; 557 s.high = 0;
550 s.low = 0; 558 s.low = 0;
551 } 559 }
552 else 560 else
553 { 561 {
554 lshift_double (pos_a.low, pos_a.high, 562 s = pos_a.llshift (GET_MODE_FBIT (f->mode), HOST_BITS_PER_DOUBLE_INT);
555 GET_MODE_FBIT (f->mode), 563 r = pos_a.llshift (- (HOST_BITS_PER_DOUBLE_INT
556 2 * HOST_BITS_PER_WIDE_INT,
557 &s.low, &s.high, 0);
558 lshift_double (pos_a.low, pos_a.high,
559 - (2 * HOST_BITS_PER_WIDE_INT
560 - GET_MODE_FBIT (f->mode)), 564 - GET_MODE_FBIT (f->mode)),
561 2 * HOST_BITS_PER_WIDE_INT, 565 HOST_BITS_PER_DOUBLE_INT);
562 &r.low, &r.high, 0);
563 } 566 }
564 567
565 /* Divide r by pos_b to quo_r. The remainder is in mod. */ 568 /* Divide r by pos_b to quo_r. The remainder is in mod. */
566 div_and_round_double (TRUNC_DIV_EXPR, 1, r.low, r.high, pos_b.low, 569 quo_r = r.divmod (pos_b, 1, TRUNC_DIV_EXPR, &mod);
567 pos_b.high, &quo_r.low, &quo_r.high, &mod.low, 570 quo_s = double_int_zero;
568 &mod.high); 571
569 572 for (i = 0; i < HOST_BITS_PER_DOUBLE_INT; i++)
570 quo_s.high = 0;
571 quo_s.low = 0;
572
573 for (i = 0; i < 2 * HOST_BITS_PER_WIDE_INT; i++)
574 { 573 {
575 /* Record the leftmost bit of mod. */ 574 /* Record the leftmost bit of mod. */
576 int leftmost_mod = (mod.high < 0); 575 int leftmost_mod = (mod.high < 0);
577 576
578 /* Shift left mod by 1 bit. */ 577 /* Shift left mod by 1 bit. */
579 lshift_double (mod.low, mod.high, 1, 2 * HOST_BITS_PER_WIDE_INT, 578 mod = mod.lshift (1);
580 &mod.low, &mod.high, 0);
581 579
582 /* Test the leftmost bit of s to add to mod. */ 580 /* Test the leftmost bit of s to add to mod. */
583 if (s.high < 0) 581 if (s.high < 0)
584 mod.low += 1; 582 mod.low += 1;
585 583
586 /* Shift left quo_s by 1 bit. */ 584 /* Shift left quo_s by 1 bit. */
587 lshift_double (quo_s.low, quo_s.high, 1, 2 * HOST_BITS_PER_WIDE_INT, 585 quo_s = quo_s.lshift (1);
588 &quo_s.low, &quo_s.high, 0);
589 586
590 /* Try to calculate (mod - pos_b). */ 587 /* Try to calculate (mod - pos_b). */
591 temp = double_int_sub (mod, pos_b); 588 temp = mod - pos_b;
592 589
593 if (leftmost_mod == 1 || double_int_cmp (mod, pos_b, 1) != -1) 590 if (leftmost_mod == 1 || mod.ucmp (pos_b) != -1)
594 { 591 {
595 quo_s.low += 1; 592 quo_s.low += 1;
596 mod = temp; 593 mod = temp;
597 } 594 }
598 595
599 /* Shift left s by 1 bit. */ 596 /* Shift left s by 1 bit. */
600 lshift_double (s.low, s.high, 1, 2 * HOST_BITS_PER_WIDE_INT, 597 s = s.lshift (1);
601 &s.low, &s.high, 0);
602 598
603 } 599 }
604 600
605 if (num_of_neg == 1) 601 if (num_of_neg == 1)
606 { 602 {
607 quo_s = double_int_neg (quo_s); 603 quo_s = -quo_s;
608 if (quo_s.high == 0 && quo_s.low == 0) 604 if (quo_s.high == 0 && quo_s.low == 0)
609 quo_r = double_int_neg (quo_r); 605 quo_r = -quo_r;
610 else 606 else
611 { 607 {
612 quo_r.low = ~quo_r.low; 608 quo_r.low = ~quo_r.low;
613 quo_r.high = ~quo_r.high; 609 quo_r.high = ~quo_r.high;
614 } 610 }
616 612
617 f->data = quo_s; 613 f->data = quo_s;
618 overflow_p = fixed_saturate2 (f->mode, quo_r, quo_s, &f->data, sat_p); 614 overflow_p = fixed_saturate2 (f->mode, quo_r, quo_s, &f->data, sat_p);
619 } 615 }
620 616
621 f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p); 617 f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p);
622 return overflow_p; 618 return overflow_p;
623 } 619 }
624 620
625 /* Calculate F = A << B if LEFT_P. Otherwise, F = A >> B. 621 /* Calculate F = A << B if LEFT_P. Otherwise, F = A >> B.
626 If SAT_P, saturate the result to the max or the min. 622 If SAT_P, saturate the result to the max or the min.
641 return overflow_p; 637 return overflow_p;
642 } 638 }
643 639
644 if (GET_MODE_PRECISION (f->mode) <= HOST_BITS_PER_WIDE_INT || (!left_p)) 640 if (GET_MODE_PRECISION (f->mode) <= HOST_BITS_PER_WIDE_INT || (!left_p))
645 { 641 {
646 lshift_double (a->data.low, a->data.high, 642 f->data = a->data.lshift (left_p ? b->data.low : -b->data.low,
647 left_p ? b->data.low : (-b->data.low), 643 HOST_BITS_PER_DOUBLE_INT, !unsigned_p);
648 2 * HOST_BITS_PER_WIDE_INT,
649 &f->data.low, &f->data.high, !unsigned_p);
650 if (left_p) /* Only left shift saturates. */ 644 if (left_p) /* Only left shift saturates. */
651 overflow_p = fixed_saturate1 (f->mode, f->data, &f->data, sat_p); 645 overflow_p = fixed_saturate1 (f->mode, f->data, &f->data, sat_p);
652 } 646 }
653 else /* We need two double_int to store the left-shift result. */ 647 else /* We need two double_int to store the left-shift result. */
654 { 648 {
655 double_int temp_high, temp_low; 649 double_int temp_high, temp_low;
656 if (b->data.low == 2 * HOST_BITS_PER_WIDE_INT) 650 if (b->data.low == HOST_BITS_PER_DOUBLE_INT)
657 { 651 {
658 temp_high = a->data; 652 temp_high = a->data;
659 temp_low.high = 0; 653 temp_low.high = 0;
660 temp_low.low = 0; 654 temp_low.low = 0;
661 } 655 }
662 else 656 else
663 { 657 {
664 lshift_double (a->data.low, a->data.high, 658 temp_low = a->data.lshift (b->data.low,
665 b->data.low, 659 HOST_BITS_PER_DOUBLE_INT, !unsigned_p);
666 2 * HOST_BITS_PER_WIDE_INT,
667 &temp_low.low, &temp_low.high, !unsigned_p);
668 /* Logical shift right to temp_high. */ 660 /* Logical shift right to temp_high. */
669 lshift_double (a->data.low, a->data.high, 661 temp_high = a->data.llshift (b->data.low - HOST_BITS_PER_DOUBLE_INT,
670 b->data.low - 2 * HOST_BITS_PER_WIDE_INT, 662 HOST_BITS_PER_DOUBLE_INT);
671 2 * HOST_BITS_PER_WIDE_INT,
672 &temp_high.low, &temp_high.high, 0);
673 } 663 }
674 if (!unsigned_p && a->data.high < 0) /* Signed-extend temp_high. */ 664 if (!unsigned_p && a->data.high < 0) /* Signed-extend temp_high. */
675 temp_high = double_int_ext (temp_high, b->data.low, unsigned_p); 665 temp_high = temp_high.ext (b->data.low, unsigned_p);
676 f->data = temp_low; 666 f->data = temp_low;
677 overflow_p = fixed_saturate2 (f->mode, temp_high, temp_low, &f->data, 667 overflow_p = fixed_saturate2 (f->mode, temp_high, temp_low, &f->data,
678 sat_p); 668 sat_p);
679 } 669 }
680 f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p); 670 f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p);
681 return overflow_p; 671 return overflow_p;
682 } 672 }
683 673
684 /* Calculate F = -A. 674 /* Calculate F = -A.
685 If SAT_P, saturate the result to the max or the min. 675 If SAT_P, saturate the result to the max or the min.
690 { 680 {
691 bool overflow_p = false; 681 bool overflow_p = false;
692 bool unsigned_p = UNSIGNED_FIXED_POINT_MODE_P (a->mode); 682 bool unsigned_p = UNSIGNED_FIXED_POINT_MODE_P (a->mode);
693 int i_f_bits = GET_MODE_IBIT (a->mode) + GET_MODE_FBIT (a->mode); 683 int i_f_bits = GET_MODE_IBIT (a->mode) + GET_MODE_FBIT (a->mode);
694 f->mode = a->mode; 684 f->mode = a->mode;
695 f->data = double_int_neg (a->data); 685 f->data = -a->data;
696 f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p); 686 f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p);
697 687
698 if (unsigned_p) /* Unsigned type. */ 688 if (unsigned_p) /* Unsigned type. */
699 { 689 {
700 if (f->data.low != 0 || f->data.high != 0) 690 if (f->data.low != 0 || f->data.high != 0)
701 { 691 {
716 if (sat_p) 706 if (sat_p)
717 { 707 {
718 /* Saturate to the maximum by subtracting f->data by one. */ 708 /* Saturate to the maximum by subtracting f->data by one. */
719 f->data.low = -1; 709 f->data.low = -1;
720 f->data.high = -1; 710 f->data.high = -1;
721 f->data = double_int_ext (f->data, i_f_bits, 1); 711 f->data = f->data.zext (i_f_bits);
722 } 712 }
723 else 713 else
724 overflow_p = true; 714 overflow_p = true;
725 } 715 }
726 } 716 }
738 { 728 {
739 switch (icode) 729 switch (icode)
740 { 730 {
741 case NEGATE_EXPR: 731 case NEGATE_EXPR:
742 return do_fixed_neg (f, op0, sat_p); 732 return do_fixed_neg (f, op0, sat_p);
743 break;
744 733
745 case PLUS_EXPR: 734 case PLUS_EXPR:
746 gcc_assert (op0->mode == op1->mode); 735 gcc_assert (op0->mode == op1->mode);
747 return do_fixed_add (f, op0, op1, false, sat_p); 736 return do_fixed_add (f, op0, op1, false, sat_p);
748 break;
749 737
750 case MINUS_EXPR: 738 case MINUS_EXPR:
751 gcc_assert (op0->mode == op1->mode); 739 gcc_assert (op0->mode == op1->mode);
752 return do_fixed_add (f, op0, op1, true, sat_p); 740 return do_fixed_add (f, op0, op1, true, sat_p);
753 break;
754 741
755 case MULT_EXPR: 742 case MULT_EXPR:
756 gcc_assert (op0->mode == op1->mode); 743 gcc_assert (op0->mode == op1->mode);
757 return do_fixed_multiply (f, op0, op1, sat_p); 744 return do_fixed_multiply (f, op0, op1, sat_p);
758 break;
759 745
760 case TRUNC_DIV_EXPR: 746 case TRUNC_DIV_EXPR:
761 gcc_assert (op0->mode == op1->mode); 747 gcc_assert (op0->mode == op1->mode);
762 return do_fixed_divide (f, op0, op1, sat_p); 748 return do_fixed_divide (f, op0, op1, sat_p);
763 break;
764 749
765 case LSHIFT_EXPR: 750 case LSHIFT_EXPR:
766 return do_fixed_shift (f, op0, op1, true, sat_p); 751 return do_fixed_shift (f, op0, op1, true, sat_p);
767 break;
768 752
769 case RSHIFT_EXPR: 753 case RSHIFT_EXPR:
770 return do_fixed_shift (f, op0, op1, false, sat_p); 754 return do_fixed_shift (f, op0, op1, false, sat_p);
771 break;
772 755
773 default: 756 default:
774 gcc_unreachable (); 757 gcc_unreachable ();
775 } 758 }
776 return false; 759 return false;
787 gcc_assert (op0->mode == op1->mode); 770 gcc_assert (op0->mode == op1->mode);
788 771
789 switch (code) 772 switch (code)
790 { 773 {
791 case NE_EXPR: 774 case NE_EXPR:
792 return !double_int_equal_p (op0->data, op1->data); 775 return op0->data != op1->data;
793 776
794 case EQ_EXPR: 777 case EQ_EXPR:
795 return double_int_equal_p (op0->data, op1->data); 778 return op0->data == op1->data;
796 779
797 case LT_EXPR: 780 case LT_EXPR:
798 return double_int_cmp (op0->data, op1->data, 781 return op0->data.cmp (op1->data,
799 UNSIGNED_FIXED_POINT_MODE_P (op0->mode)) == -1; 782 UNSIGNED_FIXED_POINT_MODE_P (op0->mode)) == -1;
800 783
801 case LE_EXPR: 784 case LE_EXPR:
802 return double_int_cmp (op0->data, op1->data, 785 return op0->data.cmp (op1->data,
803 UNSIGNED_FIXED_POINT_MODE_P (op0->mode)) != 1; 786 UNSIGNED_FIXED_POINT_MODE_P (op0->mode)) != 1;
804 787
805 case GT_EXPR: 788 case GT_EXPR:
806 return double_int_cmp (op0->data, op1->data, 789 return op0->data.cmp (op1->data,
807 UNSIGNED_FIXED_POINT_MODE_P (op0->mode)) == 1; 790 UNSIGNED_FIXED_POINT_MODE_P (op0->mode)) == 1;
808 791
809 case GE_EXPR: 792 case GE_EXPR:
810 return double_int_cmp (op0->data, op1->data, 793 return op0->data.cmp (op1->data,
811 UNSIGNED_FIXED_POINT_MODE_P (op0->mode)) != -1; 794 UNSIGNED_FIXED_POINT_MODE_P (op0->mode)) != -1;
812 795
813 default: 796 default:
814 gcc_unreachable (); 797 gcc_unreachable ();
815 } 798 }
818 /* Extend or truncate to a new mode. 801 /* Extend or truncate to a new mode.
819 If SAT_P, saturate the result to the max or the min. 802 If SAT_P, saturate the result to the max or the min.
820 Return true, if !SAT_P and overflow. */ 803 Return true, if !SAT_P and overflow. */
821 804
822 bool 805 bool
823 fixed_convert (FIXED_VALUE_TYPE *f, enum machine_mode mode, 806 fixed_convert (FIXED_VALUE_TYPE *f, scalar_mode mode,
824 const FIXED_VALUE_TYPE *a, bool sat_p) 807 const FIXED_VALUE_TYPE *a, bool sat_p)
825 { 808 {
826 bool overflow_p = false; 809 bool overflow_p = false;
827 if (mode == a->mode) 810 if (mode == a->mode)
828 { 811 {
833 if (GET_MODE_FBIT (mode) > GET_MODE_FBIT (a->mode)) 816 if (GET_MODE_FBIT (mode) > GET_MODE_FBIT (a->mode))
834 { 817 {
835 /* Left shift a to temp_high, temp_low based on a->mode. */ 818 /* Left shift a to temp_high, temp_low based on a->mode. */
836 double_int temp_high, temp_low; 819 double_int temp_high, temp_low;
837 int amount = GET_MODE_FBIT (mode) - GET_MODE_FBIT (a->mode); 820 int amount = GET_MODE_FBIT (mode) - GET_MODE_FBIT (a->mode);
838 lshift_double (a->data.low, a->data.high, 821 temp_low = a->data.lshift (amount,
839 amount, 822 HOST_BITS_PER_DOUBLE_INT,
840 2 * HOST_BITS_PER_WIDE_INT, 823 SIGNED_FIXED_POINT_MODE_P (a->mode));
841 &temp_low.low, &temp_low.high,
842 SIGNED_FIXED_POINT_MODE_P (a->mode));
843 /* Logical shift right to temp_high. */ 824 /* Logical shift right to temp_high. */
844 lshift_double (a->data.low, a->data.high, 825 temp_high = a->data.llshift (amount - HOST_BITS_PER_DOUBLE_INT,
845 amount - 2 * HOST_BITS_PER_WIDE_INT, 826 HOST_BITS_PER_DOUBLE_INT);
846 2 * HOST_BITS_PER_WIDE_INT,
847 &temp_high.low, &temp_high.high, 0);
848 if (SIGNED_FIXED_POINT_MODE_P (a->mode) 827 if (SIGNED_FIXED_POINT_MODE_P (a->mode)
849 && a->data.high < 0) /* Signed-extend temp_high. */ 828 && a->data.high < 0) /* Signed-extend temp_high. */
850 temp_high = double_int_ext (temp_high, amount, 0); 829 temp_high = temp_high.sext (amount);
851 f->mode = mode; 830 f->mode = mode;
852 f->data = temp_low; 831 f->data = temp_low;
853 if (SIGNED_FIXED_POINT_MODE_P (a->mode) == 832 if (SIGNED_FIXED_POINT_MODE_P (a->mode) ==
854 SIGNED_FIXED_POINT_MODE_P (f->mode)) 833 SIGNED_FIXED_POINT_MODE_P (f->mode))
855 overflow_p = fixed_saturate2 (f->mode, temp_high, temp_low, &f->data, 834 overflow_p = fixed_saturate2 (f->mode, temp_high, temp_low, &f->data,
883 if (sat_p) 862 if (sat_p)
884 { 863 {
885 /* Set to maximum. */ 864 /* Set to maximum. */
886 f->data.low = -1; /* Set to all ones. */ 865 f->data.low = -1; /* Set to all ones. */
887 f->data.high = -1; /* Set to all ones. */ 866 f->data.high = -1; /* Set to all ones. */
888 f->data = double_int_ext (f->data, 867 f->data = f->data.zext (GET_MODE_FBIT (f->mode)
889 GET_MODE_FBIT (f->mode) 868 + GET_MODE_IBIT (f->mode));
890 + GET_MODE_IBIT (f->mode), 869 /* Clear the sign. */
891 1); /* Clear the sign. */
892 } 870 }
893 else 871 else
894 overflow_p = true; 872 overflow_p = true;
895 } 873 }
896 else 874 else
901 } 879 }
902 else 880 else
903 { 881 {
904 /* Right shift a to temp based on a->mode. */ 882 /* Right shift a to temp based on a->mode. */
905 double_int temp; 883 double_int temp;
906 lshift_double (a->data.low, a->data.high, 884 temp = a->data.lshift (GET_MODE_FBIT (mode) - GET_MODE_FBIT (a->mode),
907 GET_MODE_FBIT (mode) - GET_MODE_FBIT (a->mode), 885 HOST_BITS_PER_DOUBLE_INT,
908 2 * HOST_BITS_PER_WIDE_INT, 886 SIGNED_FIXED_POINT_MODE_P (a->mode));
909 &temp.low, &temp.high,
910 SIGNED_FIXED_POINT_MODE_P (a->mode));
911 f->mode = mode; 887 f->mode = mode;
912 f->data = temp; 888 f->data = temp;
913 if (SIGNED_FIXED_POINT_MODE_P (a->mode) == 889 if (SIGNED_FIXED_POINT_MODE_P (a->mode) ==
914 SIGNED_FIXED_POINT_MODE_P (f->mode)) 890 SIGNED_FIXED_POINT_MODE_P (f->mode))
915 overflow_p = fixed_saturate1 (f->mode, f->data, &f->data, sat_p); 891 overflow_p = fixed_saturate1 (f->mode, f->data, &f->data, sat_p);
942 if (sat_p) 918 if (sat_p)
943 { 919 {
944 /* Set to maximum. */ 920 /* Set to maximum. */
945 f->data.low = -1; /* Set to all ones. */ 921 f->data.low = -1; /* Set to all ones. */
946 f->data.high = -1; /* Set to all ones. */ 922 f->data.high = -1; /* Set to all ones. */
947 f->data = double_int_ext (f->data, 923 f->data = f->data.zext (GET_MODE_FBIT (f->mode)
948 GET_MODE_FBIT (f->mode) 924 + GET_MODE_IBIT (f->mode));
949 + GET_MODE_IBIT (f->mode), 925 /* Clear the sign. */
950 1); /* Clear the sign. */
951 } 926 }
952 else 927 else
953 overflow_p = true; 928 overflow_p = true;
954 } 929 }
955 else 930 else
957 sat_p); 932 sat_p);
958 } 933 }
959 } 934 }
960 } 935 }
961 936
962 f->data = double_int_ext (f->data, 937 f->data = f->data.ext (SIGNED_FIXED_POINT_MODE_P (f->mode)
963 SIGNED_FIXED_POINT_MODE_P (f->mode)
964 + GET_MODE_FBIT (f->mode) 938 + GET_MODE_FBIT (f->mode)
965 + GET_MODE_IBIT (f->mode), 939 + GET_MODE_IBIT (f->mode),
966 UNSIGNED_FIXED_POINT_MODE_P (f->mode)); 940 UNSIGNED_FIXED_POINT_MODE_P (f->mode));
967 return overflow_p; 941 return overflow_p;
968 } 942 }
971 If UNSIGNED_P, this integer is unsigned. 945 If UNSIGNED_P, this integer is unsigned.
972 If SAT_P, saturate the result to the max or the min. 946 If SAT_P, saturate the result to the max or the min.
973 Return true, if !SAT_P and overflow. */ 947 Return true, if !SAT_P and overflow. */
974 948
975 bool 949 bool
976 fixed_convert_from_int (FIXED_VALUE_TYPE *f, enum machine_mode mode, 950 fixed_convert_from_int (FIXED_VALUE_TYPE *f, scalar_mode mode,
977 double_int a, bool unsigned_p, bool sat_p) 951 double_int a, bool unsigned_p, bool sat_p)
978 { 952 {
979 bool overflow_p = false; 953 bool overflow_p = false;
980 /* Left shift a to temp_high, temp_low. */ 954 /* Left shift a to temp_high, temp_low. */
981 double_int temp_high, temp_low; 955 double_int temp_high, temp_low;
982 int amount = GET_MODE_FBIT (mode); 956 int amount = GET_MODE_FBIT (mode);
983 if (amount == 2 * HOST_BITS_PER_WIDE_INT) 957 if (amount == HOST_BITS_PER_DOUBLE_INT)
984 { 958 {
985 temp_high = a; 959 temp_high = a;
986 temp_low.low = 0; 960 temp_low.low = 0;
987 temp_low.high = 0; 961 temp_low.high = 0;
988 } 962 }
989 else 963 else
990 { 964 {
991 lshift_double (a.low, a.high, 965 temp_low = a.llshift (amount, HOST_BITS_PER_DOUBLE_INT);
992 amount,
993 2 * HOST_BITS_PER_WIDE_INT,
994 &temp_low.low, &temp_low.high, 0);
995 966
996 /* Logical shift right to temp_high. */ 967 /* Logical shift right to temp_high. */
997 lshift_double (a.low, a.high, 968 temp_high = a.llshift (amount - HOST_BITS_PER_DOUBLE_INT,
998 amount - 2 * HOST_BITS_PER_WIDE_INT, 969 HOST_BITS_PER_DOUBLE_INT);
999 2 * HOST_BITS_PER_WIDE_INT,
1000 &temp_high.low, &temp_high.high, 0);
1001 } 970 }
1002 if (!unsigned_p && a.high < 0) /* Signed-extend temp_high. */ 971 if (!unsigned_p && a.high < 0) /* Signed-extend temp_high. */
1003 temp_high = double_int_ext (temp_high, amount, 0); 972 temp_high = temp_high.sext (amount);
1004 973
1005 f->mode = mode; 974 f->mode = mode;
1006 f->data = temp_low; 975 f->data = temp_low;
1007 976
1008 if (unsigned_p == UNSIGNED_FIXED_POINT_MODE_P (f->mode)) 977 if (unsigned_p == UNSIGNED_FIXED_POINT_MODE_P (f->mode))
1036 if (sat_p) 1005 if (sat_p)
1037 { 1006 {
1038 /* Set to maximum. */ 1007 /* Set to maximum. */
1039 f->data.low = -1; /* Set to all ones. */ 1008 f->data.low = -1; /* Set to all ones. */
1040 f->data.high = -1; /* Set to all ones. */ 1009 f->data.high = -1; /* Set to all ones. */
1041 f->data = double_int_ext (f->data, 1010 f->data = f->data.zext (GET_MODE_FBIT (f->mode)
1042 GET_MODE_FBIT (f->mode) 1011 + GET_MODE_IBIT (f->mode));
1043 + GET_MODE_IBIT (f->mode), 1012 /* Clear the sign. */
1044 1); /* Clear the sign. */
1045 } 1013 }
1046 else 1014 else
1047 overflow_p = true; 1015 overflow_p = true;
1048 } 1016 }
1049 else 1017 else
1050 overflow_p = fixed_saturate2 (f->mode, temp_high, temp_low, 1018 overflow_p = fixed_saturate2 (f->mode, temp_high, temp_low,
1051 &f->data, sat_p); 1019 &f->data, sat_p);
1052 } 1020 }
1053 } 1021 }
1054 f->data = double_int_ext (f->data, 1022 f->data = f->data.ext (SIGNED_FIXED_POINT_MODE_P (f->mode)
1055 SIGNED_FIXED_POINT_MODE_P (f->mode)
1056 + GET_MODE_FBIT (f->mode) 1023 + GET_MODE_FBIT (f->mode)
1057 + GET_MODE_IBIT (f->mode), 1024 + GET_MODE_IBIT (f->mode),
1058 UNSIGNED_FIXED_POINT_MODE_P (f->mode)); 1025 UNSIGNED_FIXED_POINT_MODE_P (f->mode));
1059 return overflow_p; 1026 return overflow_p;
1060 } 1027 }
1062 /* Convert to a new fixed-point mode from a real. 1029 /* Convert to a new fixed-point mode from a real.
1063 If SAT_P, saturate the result to the max or the min. 1030 If SAT_P, saturate the result to the max or the min.
1064 Return true, if !SAT_P and overflow. */ 1031 Return true, if !SAT_P and overflow. */
1065 1032
1066 bool 1033 bool
1067 fixed_convert_from_real (FIXED_VALUE_TYPE *f, enum machine_mode mode, 1034 fixed_convert_from_real (FIXED_VALUE_TYPE *f, scalar_mode mode,
1068 const REAL_VALUE_TYPE *a, bool sat_p) 1035 const REAL_VALUE_TYPE *a, bool sat_p)
1069 { 1036 {
1070 bool overflow_p = false; 1037 bool overflow_p = false;
1071 REAL_VALUE_TYPE real_value, fixed_value, base_value; 1038 REAL_VALUE_TYPE real_value, fixed_value, base_value;
1072 bool unsigned_p = UNSIGNED_FIXED_POINT_MODE_P (mode); 1039 bool unsigned_p = UNSIGNED_FIXED_POINT_MODE_P (mode);
1073 int i_f_bits = GET_MODE_IBIT (mode) + GET_MODE_FBIT (mode); 1040 int i_f_bits = GET_MODE_IBIT (mode) + GET_MODE_FBIT (mode);
1074 unsigned int fbit = GET_MODE_FBIT (mode); 1041 unsigned int fbit = GET_MODE_FBIT (mode);
1075 enum fixed_value_range_code temp; 1042 enum fixed_value_range_code temp;
1043 bool fail;
1076 1044
1077 real_value = *a; 1045 real_value = *a;
1078 f->mode = mode; 1046 f->mode = mode;
1079 real_2expN (&base_value, fbit, mode); 1047 real_2expN (&base_value, fbit, VOIDmode);
1080 real_arithmetic (&fixed_value, MULT_EXPR, &real_value, &base_value); 1048 real_arithmetic (&fixed_value, MULT_EXPR, &real_value, &base_value);
1081 real_to_integer2 ((HOST_WIDE_INT *)&f->data.low, &f->data.high, &fixed_value); 1049
1050 wide_int w = real_to_integer (&fixed_value, &fail,
1051 GET_MODE_PRECISION (mode));
1052 f->data.low = w.ulow ();
1053 f->data.high = w.elt (1);
1082 temp = check_real_for_fixed_mode (&real_value, mode); 1054 temp = check_real_for_fixed_mode (&real_value, mode);
1083 if (temp == FIXED_UNDERFLOW) /* Minimum. */ 1055 if (temp == FIXED_UNDERFLOW) /* Minimum. */
1084 { 1056 {
1085 if (sat_p) 1057 if (sat_p)
1086 { 1058 {
1091 } 1063 }
1092 else 1064 else
1093 { 1065 {
1094 f->data.low = 1; 1066 f->data.low = 1;
1095 f->data.high = 0; 1067 f->data.high = 0;
1096 lshift_double (f->data.low, f->data.high, i_f_bits, 1068 f->data = f->data.alshift (i_f_bits, HOST_BITS_PER_DOUBLE_INT);
1097 2 * HOST_BITS_PER_WIDE_INT, 1069 f->data = f->data.sext (1 + i_f_bits);
1098 &f->data.low, &f->data.high, 1);
1099 f->data = double_int_ext (f->data, 1 + i_f_bits, 0);
1100 } 1070 }
1101 } 1071 }
1102 else 1072 else
1103 overflow_p = true; 1073 overflow_p = true;
1104 } 1074 }
1106 { 1076 {
1107 if (sat_p) 1077 if (sat_p)
1108 { 1078 {
1109 f->data.low = -1; 1079 f->data.low = -1;
1110 f->data.high = -1; 1080 f->data.high = -1;
1111 f->data = double_int_ext (f->data, i_f_bits, 1); 1081 f->data = f->data.zext (i_f_bits);
1112 } 1082 }
1113 else 1083 else
1114 overflow_p = true; 1084 overflow_p = true;
1115 } 1085 }
1116 f->data = double_int_ext (f->data, (!unsigned_p) + i_f_bits, unsigned_p); 1086 f->data = f->data.ext ((!unsigned_p) + i_f_bits, unsigned_p);
1117 return overflow_p; 1087 return overflow_p;
1118 } 1088 }
1119 1089
1120 /* Convert to a new real mode from a fixed-point. */ 1090 /* Convert to a new real mode from a fixed-point. */
1121 1091
1122 void 1092 void
1123 real_convert_from_fixed (REAL_VALUE_TYPE *r, enum machine_mode mode, 1093 real_convert_from_fixed (REAL_VALUE_TYPE *r, scalar_mode mode,
1124 const FIXED_VALUE_TYPE *f) 1094 const FIXED_VALUE_TYPE *f)
1125 { 1095 {
1126 REAL_VALUE_TYPE base_value, fixed_value, real_value; 1096 REAL_VALUE_TYPE base_value, fixed_value, real_value;
1127 1097
1128 real_2expN (&base_value, GET_MODE_FBIT (f->mode), f->mode); 1098 signop sgn = UNSIGNED_FIXED_POINT_MODE_P (f->mode) ? UNSIGNED : SIGNED;
1129 real_from_integer (&fixed_value, VOIDmode, f->data.low, f->data.high, 1099 real_2expN (&base_value, GET_MODE_FBIT (f->mode), VOIDmode);
1130 UNSIGNED_FIXED_POINT_MODE_P (f->mode)); 1100 real_from_integer (&fixed_value, VOIDmode,
1101 wide_int::from (f->data, GET_MODE_PRECISION (f->mode),
1102 sgn), sgn);
1131 real_arithmetic (&real_value, RDIV_EXPR, &fixed_value, &base_value); 1103 real_arithmetic (&real_value, RDIV_EXPR, &fixed_value, &base_value);
1132 real_convert (r, mode, &real_value); 1104 real_convert (r, mode, &real_value);
1133 } 1105 }
1134 1106
1135 /* Determine whether a fixed-point value F is negative. */ 1107 /* Determine whether a fixed-point value F is negative. */