1 /* Machine mode definitions for GCC; included by rtl.h and tree.h. 2 Copyright (C) 1991-2019 Free Software Foundation, Inc. 3 4 This file is part of GCC. 5 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 8 Software Foundation; either version 3, or (at your option) any later 9 version. 10 11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY 12 WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GCC; see the file COPYING3. If not see 18 <http://www.gnu.org/licenses/>. */ 19 20 #ifndef HAVE_MACHINE_MODES 21 #define HAVE_MACHINE_MODES 22 23 typedef opt_mode<machine_mode> opt_machine_mode; 24 25 extern CONST_MODE_SIZE poly_uint16_pod mode_size[NUM_MACHINE_MODES]; 26 extern CONST_MODE_PRECISION poly_uint16_pod mode_precision[NUM_MACHINE_MODES]; 27 extern const unsigned char mode_inner[NUM_MACHINE_MODES]; 28 extern CONST_MODE_NUNITS poly_uint16_pod mode_nunits[NUM_MACHINE_MODES]; 29 extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES]; 30 extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES]; 31 extern const unsigned char mode_wider[NUM_MACHINE_MODES]; 32 extern const unsigned char mode_2xwider[NUM_MACHINE_MODES]; 33 34 template<typename T> 35 struct mode_traits 36 { 37 /* For use by the machmode support code only. 38 39 There are cases in which the machmode support code needs to forcibly 40 convert a machine_mode to a specific mode class T, and in which the 41 context guarantees that this is valid without the need for an assert. 42 This can be done using: 43 44 return typename mode_traits<T>::from_int (mode); 45 46 when returning a T and: 47 48 res = T (typename mode_traits<T>::from_int (mode)); 49 50 when assigning to a value RES that must be assignment-compatible 51 with (but possibly not the same as) T. */ 52 #ifdef USE_ENUM_MODES 53 /* Allow direct conversion of enums to specific mode classes only 54 when USE_ENUM_MODES is defined. This is only intended for use 55 by gencondmd, so that it can tell more easily when .md conditions 56 are always false. */ 57 typedef machine_mode from_int; 58 #else 59 /* Here we use an enum type distinct from machine_mode but with the 60 same range as machine_mode. T should have a constructor that 61 accepts this enum type; it should not have a constructor that 62 accepts machine_mode. 63 64 We use this somewhat indirect approach to avoid too many constructor 65 calls when the compiler is built with -O0. For example, even in 66 unoptimized code, the return statement above would construct the 67 returned T directly from the numerical value of MODE. */ 68 enum from_int { dummy = MAX_MACHINE_MODE }; 69 #endif 70 }; 71 72 template<> 73 struct mode_traits<machine_mode> 74 { 75 /* machine_mode itself needs no conversion. */ 76 typedef machine_mode from_int; 77 }; 78 79 /* Always treat machine modes as fixed-size while compiling code specific 80 to targets that have no variable-size modes. */ 81 #if defined (IN_TARGET_CODE) && NUM_POLY_INT_COEFFS == 1 82 #define ONLY_FIXED_SIZE_MODES 1 83 #else 84 #define ONLY_FIXED_SIZE_MODES 0 85 #endif 86 87 /* Get the name of mode MODE as a string. */ 88 89 extern const char * const mode_name[NUM_MACHINE_MODES]; 90 #define GET_MODE_NAME(MODE) mode_name[MODE] 91 92 /* Mode classes. */ 93 94 #include "mode-classes.def" 95 #define DEF_MODE_CLASS(M) M 96 enum mode_class { MODE_CLASSES, MAX_MODE_CLASS }; 97 #undef DEF_MODE_CLASS 98 #undef MODE_CLASSES 99 100 /* Get the general kind of object that mode MODE represents 101 (integer, floating, complex, etc.) */ 102 103 extern const unsigned char mode_class[NUM_MACHINE_MODES]; 104 #define GET_MODE_CLASS(MODE) ((enum mode_class) mode_class[MODE]) 105 106 /* Nonzero if MODE is an integral mode. */ 107 #define INTEGRAL_MODE_P(MODE) \ 108 (GET_MODE_CLASS (MODE) == MODE_INT \ 109 || GET_MODE_CLASS (MODE) == MODE_PARTIAL_INT \ 110 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_INT \ 111 || GET_MODE_CLASS (MODE) == MODE_VECTOR_BOOL \ 112 || GET_MODE_CLASS (MODE) == MODE_VECTOR_INT) 113 114 /* Nonzero if MODE is a floating-point mode. */ 115 #define FLOAT_MODE_P(MODE) \ 116 (GET_MODE_CLASS (MODE) == MODE_FLOAT \ 117 || GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT \ 118 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT \ 119 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT) 120 121 /* Nonzero if MODE is a complex mode. */ 122 #define COMPLEX_MODE_P(MODE) \ 123 (GET_MODE_CLASS (MODE) == MODE_COMPLEX_INT \ 124 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT) 125 126 /* Nonzero if MODE is a vector mode. */ 127 #define VECTOR_MODE_P(MODE) \ 128 (GET_MODE_CLASS (MODE) == MODE_VECTOR_BOOL \ 129 || GET_MODE_CLASS (MODE) == MODE_VECTOR_INT \ 130 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT \ 131 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FRACT \ 132 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UFRACT \ 133 || GET_MODE_CLASS (MODE) == MODE_VECTOR_ACCUM \ 134 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UACCUM) 135 136 /* Nonzero if MODE is a scalar integral mode. */ 137 #define SCALAR_INT_MODE_P(MODE) \ 138 (GET_MODE_CLASS (MODE) == MODE_INT \ 139 || GET_MODE_CLASS (MODE) == MODE_PARTIAL_INT) 140 141 /* Nonzero if MODE is a scalar floating point mode. */ 142 #define SCALAR_FLOAT_MODE_P(MODE) \ 143 (GET_MODE_CLASS (MODE) == MODE_FLOAT \ 144 || GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT) 145 146 /* Nonzero if MODE is a decimal floating point mode. */ 147 #define DECIMAL_FLOAT_MODE_P(MODE) \ 148 (GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT) 149 150 /* Nonzero if MODE is a scalar fract mode. */ 151 #define SCALAR_FRACT_MODE_P(MODE) \ 152 (GET_MODE_CLASS (MODE) == MODE_FRACT) 153 154 /* Nonzero if MODE is a scalar ufract mode. */ 155 #define SCALAR_UFRACT_MODE_P(MODE) \ 156 (GET_MODE_CLASS (MODE) == MODE_UFRACT) 157 158 /* Nonzero if MODE is a scalar fract or ufract mode. */ 159 #define ALL_SCALAR_FRACT_MODE_P(MODE) \ 160 (SCALAR_FRACT_MODE_P (MODE) || SCALAR_UFRACT_MODE_P (MODE)) 161 162 /* Nonzero if MODE is a scalar accum mode. */ 163 #define SCALAR_ACCUM_MODE_P(MODE) \ 164 (GET_MODE_CLASS (MODE) == MODE_ACCUM) 165 166 /* Nonzero if MODE is a scalar uaccum mode. */ 167 #define SCALAR_UACCUM_MODE_P(MODE) \ 168 (GET_MODE_CLASS (MODE) == MODE_UACCUM) 169 170 /* Nonzero if MODE is a scalar accum or uaccum mode. */ 171 #define ALL_SCALAR_ACCUM_MODE_P(MODE) \ 172 (SCALAR_ACCUM_MODE_P (MODE) || SCALAR_UACCUM_MODE_P (MODE)) 173 174 /* Nonzero if MODE is a scalar fract or accum mode. */ 175 #define SIGNED_SCALAR_FIXED_POINT_MODE_P(MODE) \ 176 (SCALAR_FRACT_MODE_P (MODE) || SCALAR_ACCUM_MODE_P (MODE)) 177 178 /* Nonzero if MODE is a scalar ufract or uaccum mode. */ 179 #define UNSIGNED_SCALAR_FIXED_POINT_MODE_P(MODE) \ 180 (SCALAR_UFRACT_MODE_P (MODE) || SCALAR_UACCUM_MODE_P (MODE)) 181 182 /* Nonzero if MODE is a scalar fract, ufract, accum or uaccum mode. */ 183 #define ALL_SCALAR_FIXED_POINT_MODE_P(MODE) \ 184 (SIGNED_SCALAR_FIXED_POINT_MODE_P (MODE) \ 185 || UNSIGNED_SCALAR_FIXED_POINT_MODE_P (MODE)) 186 187 /* Nonzero if MODE is a scalar/vector fract mode. */ 188 #define FRACT_MODE_P(MODE) \ 189 (GET_MODE_CLASS (MODE) == MODE_FRACT \ 190 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FRACT) 191 192 /* Nonzero if MODE is a scalar/vector ufract mode. */ 193 #define UFRACT_MODE_P(MODE) \ 194 (GET_MODE_CLASS (MODE) == MODE_UFRACT \ 195 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UFRACT) 196 197 /* Nonzero if MODE is a scalar/vector fract or ufract mode. */ 198 #define ALL_FRACT_MODE_P(MODE) \ 199 (FRACT_MODE_P (MODE) || UFRACT_MODE_P (MODE)) 200 201 /* Nonzero if MODE is a scalar/vector accum mode. */ 202 #define ACCUM_MODE_P(MODE) \ 203 (GET_MODE_CLASS (MODE) == MODE_ACCUM \ 204 || GET_MODE_CLASS (MODE) == MODE_VECTOR_ACCUM) 205 206 /* Nonzero if MODE is a scalar/vector uaccum mode. */ 207 #define UACCUM_MODE_P(MODE) \ 208 (GET_MODE_CLASS (MODE) == MODE_UACCUM \ 209 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UACCUM) 210 211 /* Nonzero if MODE is a scalar/vector accum or uaccum mode. */ 212 #define ALL_ACCUM_MODE_P(MODE) \ 213 (ACCUM_MODE_P (MODE) || UACCUM_MODE_P (MODE)) 214 215 /* Nonzero if MODE is a scalar/vector fract or accum mode. */ 216 #define SIGNED_FIXED_POINT_MODE_P(MODE) \ 217 (FRACT_MODE_P (MODE) || ACCUM_MODE_P (MODE)) 218 219 /* Nonzero if MODE is a scalar/vector ufract or uaccum mode. */ 220 #define UNSIGNED_FIXED_POINT_MODE_P(MODE) \ 221 (UFRACT_MODE_P (MODE) || UACCUM_MODE_P (MODE)) 222 223 /* Nonzero if MODE is a scalar/vector fract, ufract, accum or uaccum mode. */ 224 #define ALL_FIXED_POINT_MODE_P(MODE) \ 225 (SIGNED_FIXED_POINT_MODE_P (MODE) \ 226 || UNSIGNED_FIXED_POINT_MODE_P (MODE)) 227 228 /* Nonzero if CLASS modes can be widened. */ 229 #define CLASS_HAS_WIDER_MODES_P(CLASS) \ 230 (CLASS == MODE_INT \ 231 || CLASS == MODE_PARTIAL_INT \ 232 || CLASS == MODE_FLOAT \ 233 || CLASS == MODE_DECIMAL_FLOAT \ 234 || CLASS == MODE_COMPLEX_FLOAT \ 235 || CLASS == MODE_FRACT \ 236 || CLASS == MODE_UFRACT \ 237 || CLASS == MODE_ACCUM \ 238 || CLASS == MODE_UACCUM) 239 240 /* An optional T (i.e. a T or nothing), where T is some form of mode class. */ 241 template<typename T> 242 class opt_mode 243 { 244 public: 245 enum from_int { dummy = MAX_MACHINE_MODE }; 246 247 ALWAYS_INLINE opt_mode () : m_mode (E_VOIDmode) {} 248 ALWAYS_INLINE opt_mode (const T &m) : m_mode (m) {} 249 template<typename U> 250 ALWAYS_INLINE opt_mode (const U &m) : m_mode (T (m)) {} 251 ALWAYS_INLINE opt_mode (from_int m) : m_mode (machine_mode (m)) {} 252 253 machine_mode else_void () const; 254 machine_mode else_blk () const; 255 T require () const; 256 257 bool exists () const; 258 template<typename U> bool exists (U *) const; 259 260 private: 261 machine_mode m_mode; 262 }; 263 264 /* If the object contains a T, return its enum value, otherwise return 265 E_VOIDmode. */ 266 267 template<typename T> 268 ALWAYS_INLINE machine_mode 269 opt_mode<T>::else_void () const 270 { 271 return m_mode; 272 } 273 274 /* If the T exists, return its enum value, otherwise return E_BLKmode. */ 275 276 template<typename T> 277 inline machine_mode 278 opt_mode<T>::else_blk () const 279 { 280 return m_mode == E_VOIDmode ? E_BLKmode : m_mode; 281 } 282 283 /* Assert that the object contains a T and return it. */ 284 285 template<typename T> 286 inline T 287 opt_mode<T>::require () const 288 { 289 gcc_checking_assert (m_mode != E_VOIDmode); 290 return typename mode_traits<T>::from_int (m_mode); 291 } 292 293 /* Return true if the object contains a T rather than nothing. */ 294 295 template<typename T> 296 ALWAYS_INLINE bool 297 opt_mode<T>::exists () const 298 { 299 return m_mode != E_VOIDmode; 300 } 301 302 /* Return true if the object contains a T, storing it in *MODE if so. */ 303 304 template<typename T> 305 template<typename U> 306 inline bool 307 opt_mode<T>::exists (U *mode) const 308 { 309 if (m_mode != E_VOIDmode) 310 { 311 *mode = T (typename mode_traits<T>::from_int (m_mode)); 312 return true; 313 } 314 return false; 315 } 316 317 /* A POD version of mode class T. */ 318 319 template<typename T> 320 struct pod_mode 321 { 322 typedef typename mode_traits<T>::from_int from_int; 323 typedef typename T::measurement_type measurement_type; 324 325 machine_mode m_mode; 326 ALWAYS_INLINE operator machine_mode () const { return m_mode; } 327 ALWAYS_INLINE operator T () const { return from_int (m_mode); } 328 ALWAYS_INLINE pod_mode &operator = (const T &m) { m_mode = m; return *this; } 329 }; 330 331 /* Return true if mode M has type T. */ 332 333 template<typename T> 334 inline bool 335 is_a (machine_mode m) 336 { 337 return T::includes_p (m); 338 } 339 340 template<typename T, typename U> 341 inline bool 342 is_a (const opt_mode<U> &m) 343 { 344 return T::includes_p (m.else_void ()); 345 } 346 347 /* Assert that mode M has type T, and return it in that form. */ 348 349 template<typename T> 350 inline T 351 as_a (machine_mode m) 352 { 353 gcc_checking_assert (T::includes_p (m)); 354 return typename mode_traits<T>::from_int (m); 355 } 356 357 template<typename T, typename U> 358 inline T 359 as_a (const opt_mode<U> &m) 360 { 361 return as_a <T> (m.else_void ()); 362 } 363 364 /* Convert M to an opt_mode<T>. */ 365 366 template<typename T> 367 inline opt_mode<T> 368 dyn_cast (machine_mode m) 369 { 370 if (T::includes_p (m)) 371 return T (typename mode_traits<T>::from_int (m)); 372 return opt_mode<T> (); 373 } 374 375 template<typename T, typename U> 376 inline opt_mode<T> 377 dyn_cast (const opt_mode<U> &m) 378 { 379 return dyn_cast <T> (m.else_void ()); 380 } 381 382 /* Return true if mode M has type T, storing it as a T in *RESULT 383 if so. */ 384 385 template<typename T, typename U> 386 inline bool 387 is_a (machine_mode m, U *result) 388 { 389 if (T::includes_p (m)) 390 { 391 *result = T (typename mode_traits<T>::from_int (m)); 392 return true; 393 } 394 return false; 395 } 396 397 /* Represents a machine mode that is known to be a SCALAR_INT_MODE_P. */ 398 class scalar_int_mode 399 { 400 public: 401 typedef mode_traits<scalar_int_mode>::from_int from_int; 402 typedef unsigned short measurement_type; 403 404 ALWAYS_INLINE scalar_int_mode () {} 405 ALWAYS_INLINE scalar_int_mode (from_int m) : m_mode (machine_mode (m)) {} 406 ALWAYS_INLINE operator machine_mode () const { return m_mode; } 407 408 static bool includes_p (machine_mode); 409 410 protected: 411 machine_mode m_mode; 412 }; 413 414 /* Return true if M is a scalar_int_mode. */ 415 416 inline bool 417 scalar_int_mode::includes_p (machine_mode m) 418 { 419 return SCALAR_INT_MODE_P (m); 420 } 421 422 /* Represents a machine mode that is known to be a SCALAR_FLOAT_MODE_P. */ 423 class scalar_float_mode 424 { 425 public: 426 typedef mode_traits<scalar_float_mode>::from_int from_int; 427 typedef unsigned short measurement_type; 428 429 ALWAYS_INLINE scalar_float_mode () {} 430 ALWAYS_INLINE scalar_float_mode (from_int m) : m_mode (machine_mode (m)) {} 431 ALWAYS_INLINE operator machine_mode () const { return m_mode; } 432 433 static bool includes_p (machine_mode); 434 435 protected: 436 machine_mode m_mode; 437 }; 438 439 /* Return true if M is a scalar_float_mode. */ 440 441 inline bool 442 scalar_float_mode::includes_p (machine_mode m) 443 { 444 return SCALAR_FLOAT_MODE_P (m); 445 } 446 447 /* Represents a machine mode that is known to be scalar. */ 448 class scalar_mode 449 { 450 public: 451 typedef mode_traits<scalar_mode>::from_int from_int; 452 typedef unsigned short measurement_type; 453 454 ALWAYS_INLINE scalar_mode () {} 455 ALWAYS_INLINE scalar_mode (from_int m) : m_mode (machine_mode (m)) {} 456 ALWAYS_INLINE scalar_mode (const scalar_int_mode &m) : m_mode (m) {} 457 ALWAYS_INLINE scalar_mode (const scalar_float_mode &m) : m_mode (m) {} 458 ALWAYS_INLINE scalar_mode (const scalar_int_mode_pod &m) : m_mode (m) {} 459 ALWAYS_INLINE operator machine_mode () const { return m_mode; } 460 461 static bool includes_p (machine_mode); 462 463 protected: 464 machine_mode m_mode; 465 }; 466 467 /* Return true if M represents some kind of scalar value. */ 468 469 inline bool 470 scalar_mode::includes_p (machine_mode m) 471 { 472 switch (GET_MODE_CLASS (m)) 473 { 474 case MODE_INT: 475 case MODE_PARTIAL_INT: 476 case MODE_FRACT: 477 case MODE_UFRACT: 478 case MODE_ACCUM: 479 case MODE_UACCUM: 480 case MODE_FLOAT: 481 case MODE_DECIMAL_FLOAT: 482 return true; 483 default: 484 return false; 485 } 486 } 487 488 /* Represents a machine mode that is known to be a COMPLEX_MODE_P. */ 489 class complex_mode 490 { 491 public: 492 typedef mode_traits<complex_mode>::from_int from_int; 493 typedef unsigned short measurement_type; 494 495 ALWAYS_INLINE complex_mode () {} 496 ALWAYS_INLINE complex_mode (from_int m) : m_mode (machine_mode (m)) {} 497 ALWAYS_INLINE operator machine_mode () const { return m_mode; } 498 499 static bool includes_p (machine_mode); 500 501 protected: 502 machine_mode m_mode; 503 }; 504 505 /* Return true if M is a complex_mode. */ 506 507 inline bool 508 complex_mode::includes_p (machine_mode m) 509 { 510 return COMPLEX_MODE_P (m); 511 } 512 513 /* Return the base GET_MODE_SIZE value for MODE. */ 514 515 ALWAYS_INLINE poly_uint16 516 mode_to_bytes (machine_mode mode) 517 { 518 #if GCC_VERSION >= 4001 519 return (__builtin_constant_p (mode) 520 ? mode_size_inline (mode) : mode_size[mode]); 521 #else 522 return mode_size[mode]; 523 #endif 524 } 525 526 /* Return the base GET_MODE_BITSIZE value for MODE. */ 527 528 ALWAYS_INLINE poly_uint16 529 mode_to_bits (machine_mode mode) 530 { 531 return mode_to_bytes (mode) * BITS_PER_UNIT; 532 } 533 534 /* Return the base GET_MODE_PRECISION value for MODE. */ 535 536 ALWAYS_INLINE poly_uint16 537 mode_to_precision (machine_mode mode) 538 { 539 return mode_precision[mode]; 540 } 541 542 /* Return the base GET_MODE_INNER value for MODE. */ 543 544 ALWAYS_INLINE scalar_mode 545 mode_to_inner (machine_mode mode) 546 { 547 #if GCC_VERSION >= 4001 548 return scalar_mode::from_int (__builtin_constant_p (mode) 549 ? mode_inner_inline (mode) 550 : mode_inner[mode]); 551 #else 552 return scalar_mode::from_int (mode_inner[mode]); 553 #endif 554 } 555 556 /* Return the base GET_MODE_UNIT_SIZE value for MODE. */ 557 558 ALWAYS_INLINE unsigned char 559 mode_to_unit_size (machine_mode mode) 560 { 561 #if GCC_VERSION >= 4001 562 return (__builtin_constant_p (mode) 563 ? mode_unit_size_inline (mode) : mode_unit_size[mode]); 564 #else 565 return mode_unit_size[mode]; 566 #endif 567 } 568 569 /* Return the base GET_MODE_UNIT_PRECISION value for MODE. */ 570 571 ALWAYS_INLINE unsigned short 572 mode_to_unit_precision (machine_mode mode) 573 { 574 #if GCC_VERSION >= 4001 575 return (__builtin_constant_p (mode) 576 ? mode_unit_precision_inline (mode) : mode_unit_precision[mode]); 577 #else 578 return mode_unit_precision[mode]; 579 #endif 580 } 581 582 /* Return the base GET_MODE_NUNITS value for MODE. */ 583 584 ALWAYS_INLINE poly_uint16 585 mode_to_nunits (machine_mode mode) 586 { 587 #if GCC_VERSION >= 4001 588 return (__builtin_constant_p (mode) 589 ? mode_nunits_inline (mode) : mode_nunits[mode]); 590 #else 591 return mode_nunits[mode]; 592 #endif 593 } 594 595 /* Get the size in bytes of an object of mode MODE. */ 596 597 #if ONLY_FIXED_SIZE_MODES 598 #define GET_MODE_SIZE(MODE) ((unsigned short) mode_to_bytes (MODE).coeffs[0]) 599 #else 600 ALWAYS_INLINE poly_uint16 601 GET_MODE_SIZE (machine_mode mode) 602 { 603 return mode_to_bytes (mode); 604 } 605 606 template<typename T> 607 ALWAYS_INLINE typename if_poly<typename T::measurement_type>::type 608 GET_MODE_SIZE (const T &mode) 609 { 610 return mode_to_bytes (mode); 611 } 612 613 template<typename T> 614 ALWAYS_INLINE typename if_nonpoly<typename T::measurement_type>::type 615 GET_MODE_SIZE (const T &mode) 616 { 617 return mode_to_bytes (mode).coeffs[0]; 618 } 619 #endif 620 621 /* Get the size in bits of an object of mode MODE. */ 622 623 #if ONLY_FIXED_SIZE_MODES 624 #define GET_MODE_BITSIZE(MODE) ((unsigned short) mode_to_bits (MODE).coeffs[0]) 625 #else 626 ALWAYS_INLINE poly_uint16 627 GET_MODE_BITSIZE (machine_mode mode) 628 { 629 return mode_to_bits (mode); 630 } 631 632 template<typename T> 633 ALWAYS_INLINE typename if_poly<typename T::measurement_type>::type 634 GET_MODE_BITSIZE (const T &mode) 635 { 636 return mode_to_bits (mode); 637 } 638 639 template<typename T> 640 ALWAYS_INLINE typename if_nonpoly<typename T::measurement_type>::type 641 GET_MODE_BITSIZE (const T &mode) 642 { 643 return mode_to_bits (mode).coeffs[0]; 644 } 645 #endif 646 647 /* Get the number of value bits of an object of mode MODE. */ 648 649 #if ONLY_FIXED_SIZE_MODES 650 #define GET_MODE_PRECISION(MODE) \ 651 ((unsigned short) mode_to_precision (MODE).coeffs[0]) 652 #else 653 ALWAYS_INLINE poly_uint16 654 GET_MODE_PRECISION (machine_mode mode) 655 { 656 return mode_to_precision (mode); 657 } 658 659 template<typename T> 660 ALWAYS_INLINE typename if_poly<typename T::measurement_type>::type 661 GET_MODE_PRECISION (const T &mode) 662 { 663 return mode_to_precision (mode); 664 } 665 666 template<typename T> 667 ALWAYS_INLINE typename if_nonpoly<typename T::measurement_type>::type 668 GET_MODE_PRECISION (const T &mode) 669 { 670 return mode_to_precision (mode).coeffs[0]; 671 } 672 #endif 673 674 /* Get the number of integral bits of an object of mode MODE. */ 675 extern CONST_MODE_IBIT unsigned char mode_ibit[NUM_MACHINE_MODES]; 676 #define GET_MODE_IBIT(MODE) mode_ibit[MODE] 677 678 /* Get the number of fractional bits of an object of mode MODE. */ 679 extern CONST_MODE_FBIT unsigned char mode_fbit[NUM_MACHINE_MODES]; 680 #define GET_MODE_FBIT(MODE) mode_fbit[MODE] 681 682 /* Get a bitmask containing 1 for all bits in a word 683 that fit within mode MODE. */ 684 685 extern const unsigned HOST_WIDE_INT mode_mask_array[NUM_MACHINE_MODES]; 686 687 #define GET_MODE_MASK(MODE) mode_mask_array[MODE] 688 689 /* Return the mode of the basic parts of MODE. For vector modes this is the 690 mode of the vector elements. For complex modes it is the mode of the real 691 and imaginary parts. For other modes it is MODE itself. */ 692 693 #define GET_MODE_INNER(MODE) (mode_to_inner (MODE)) 694 695 /* Get the size in bytes or bits of the basic parts of an 696 object of mode MODE. */ 697 698 #define GET_MODE_UNIT_SIZE(MODE) mode_to_unit_size (MODE) 699 700 #define GET_MODE_UNIT_BITSIZE(MODE) \ 701 ((unsigned short) (GET_MODE_UNIT_SIZE (MODE) * BITS_PER_UNIT)) 702 703 #define GET_MODE_UNIT_PRECISION(MODE) (mode_to_unit_precision (MODE)) 704 705 /* Get the number of units in an object of mode MODE. This is 2 for 706 complex modes and the number of elements for vector modes. */ 707 708 #if ONLY_FIXED_SIZE_MODES 709 #define GET_MODE_NUNITS(MODE) (mode_to_nunits (MODE).coeffs[0]) 710 #else 711 ALWAYS_INLINE poly_uint16 712 GET_MODE_NUNITS (machine_mode mode) 713 { 714 return mode_to_nunits (mode); 715 } 716 717 template<typename T> 718 ALWAYS_INLINE typename if_poly<typename T::measurement_type>::type 719 GET_MODE_NUNITS (const T &mode) 720 { 721 return mode_to_nunits (mode); 722 } 723 724 template<typename T> 725 ALWAYS_INLINE typename if_nonpoly<typename T::measurement_type>::type 726 GET_MODE_NUNITS (const T &mode) 727 { 728 return mode_to_nunits (mode).coeffs[0]; 729 } 730 #endif 731 732 /* Get the next wider natural mode (eg, QI -> HI -> SI -> DI -> TI). */ 733 734 template<typename T> 735 ALWAYS_INLINE opt_mode<T> 736 GET_MODE_WIDER_MODE (const T &m) 737 { 738 return typename opt_mode<T>::from_int (mode_wider[m]); 739 } 740 741 /* For scalars, this is a mode with twice the precision. For vectors, 742 this is a mode with the same inner mode but with twice the elements. */ 743 744 template<typename T> 745 ALWAYS_INLINE opt_mode<T> 746 GET_MODE_2XWIDER_MODE (const T &m) 747 { 748 return typename opt_mode<T>::from_int (mode_2xwider[m]); 749 } 750 751 /* Get the complex mode from the component mode. */ 752 extern const unsigned char mode_complex[NUM_MACHINE_MODES]; 753 #define GET_MODE_COMPLEX_MODE(MODE) ((machine_mode) mode_complex[MODE]) 754 755 /* Represents a machine mode that must have a fixed size. The main 756 use of this class is to represent the modes of objects that always 757 have static storage duration, such as constant pool entries. 758 (No current target supports the concept of variable-size static data.) */ 759 class fixed_size_mode 760 { 761 public: 762 typedef mode_traits<fixed_size_mode>::from_int from_int; 763 typedef unsigned short measurement_type; 764 765 ALWAYS_INLINE fixed_size_mode () {} 766 ALWAYS_INLINE fixed_size_mode (from_int m) : m_mode (machine_mode (m)) {} 767 ALWAYS_INLINE fixed_size_mode (const scalar_mode &m) : m_mode (m) {} 768 ALWAYS_INLINE fixed_size_mode (const scalar_int_mode &m) : m_mode (m) {} 769 ALWAYS_INLINE fixed_size_mode (const scalar_float_mode &m) : m_mode (m) {} 770 ALWAYS_INLINE fixed_size_mode (const scalar_mode_pod &m) : m_mode (m) {} 771 ALWAYS_INLINE fixed_size_mode (const scalar_int_mode_pod &m) : m_mode (m) {} 772 ALWAYS_INLINE fixed_size_mode (const complex_mode &m) : m_mode (m) {} 773 ALWAYS_INLINE operator machine_mode () const { return m_mode; } 774 775 static bool includes_p (machine_mode); 776 777 protected: 778 machine_mode m_mode; 779 }; 780 781 /* Return true if MODE has a fixed size. */ 782 783 inline bool 784 fixed_size_mode::includes_p (machine_mode mode) 785 { 786 return mode_to_bytes (mode).is_constant (); 787 } 788 789 /* Wrapper for mode arguments to target macros, so that if a target 790 doesn't need polynomial-sized modes, its header file can continue 791 to treat everything as fixed_size_mode. This should go away once 792 macros are moved to target hooks. It shouldn't be used in other 793 contexts. */ 794 #if NUM_POLY_INT_COEFFS == 1 795 #define MACRO_MODE(MODE) (as_a <fixed_size_mode> (MODE)) 796 #else 797 #define MACRO_MODE(MODE) (MODE) 798 #endif 799 800 extern opt_machine_mode mode_for_size (poly_uint64, enum mode_class, int); 801 802 /* Return the machine mode to use for a MODE_INT of SIZE bits, if one 803 exists. If LIMIT is nonzero, modes wider than MAX_FIXED_MODE_SIZE 804 will not be used. */ 805 806 inline opt_scalar_int_mode 807 int_mode_for_size (poly_uint64 size, int limit) 808 { 809 return dyn_cast <scalar_int_mode> (mode_for_size (size, MODE_INT, limit)); 810 } 811 812 /* Return the machine mode to use for a MODE_FLOAT of SIZE bits, if one 813 exists. */ 814 815 inline opt_scalar_float_mode 816 float_mode_for_size (poly_uint64 size) 817 { 818 return dyn_cast <scalar_float_mode> (mode_for_size (size, MODE_FLOAT, 0)); 819 } 820 821 /* Likewise for MODE_DECIMAL_FLOAT. */ 822 823 inline opt_scalar_float_mode 824 decimal_float_mode_for_size (unsigned int size) 825 { 826 return dyn_cast <scalar_float_mode> 827 (mode_for_size (size, MODE_DECIMAL_FLOAT, 0)); 828 } 829 830 extern machine_mode smallest_mode_for_size (poly_uint64, enum mode_class); 831 832 /* Find the narrowest integer mode that contains at least SIZE bits. 833 Such a mode must exist. */ 834 835 inline scalar_int_mode 836 smallest_int_mode_for_size (poly_uint64 size) 837 { 838 return as_a <scalar_int_mode> (smallest_mode_for_size (size, MODE_INT)); 839 } 840 841 extern opt_scalar_int_mode int_mode_for_mode (machine_mode); 842 extern opt_machine_mode bitwise_mode_for_mode (machine_mode); 843 extern opt_machine_mode mode_for_vector (scalar_mode, poly_uint64); 844 extern opt_machine_mode mode_for_int_vector (unsigned int, poly_uint64); 845 846 /* Return the integer vector equivalent of MODE, if one exists. In other 847 words, return the mode for an integer vector that has the same number 848 of bits as MODE and the same number of elements as MODE, with the 849 latter being 1 if MODE is scalar. The returned mode can be either 850 an integer mode or a vector mode. */ 851 852 inline opt_machine_mode 853 mode_for_int_vector (machine_mode mode) 854 { 855 return mode_for_int_vector (GET_MODE_UNIT_BITSIZE (mode), 856 GET_MODE_NUNITS (mode)); 857 } 858 859 /* A class for iterating through possible bitfield modes. */ 860 class bit_field_mode_iterator 861 { 862 public: 863 bit_field_mode_iterator (HOST_WIDE_INT, HOST_WIDE_INT, 864 poly_int64, poly_int64, 865 unsigned int, bool); 866 bool next_mode (scalar_int_mode *); 867 bool prefer_smaller_modes (); 868 869 private: 870 opt_scalar_int_mode m_mode; 871 /* We use signed values here because the bit position can be negative 872 for invalid input such as gcc.dg/pr48335-8.c. */ 873 HOST_WIDE_INT m_bitsize; 874 HOST_WIDE_INT m_bitpos; 875 poly_int64 m_bitregion_start; 876 poly_int64 m_bitregion_end; 877 unsigned int m_align; 878 bool m_volatilep; 879 int m_count; 880 }; 881 882 /* Find the best mode to use to access a bit field. */ 883 884 extern bool get_best_mode (int, int, poly_uint64, poly_uint64, unsigned int, 885 unsigned HOST_WIDE_INT, bool, scalar_int_mode *); 886 887 /* Determine alignment, 1<=result<=BIGGEST_ALIGNMENT. */ 888 889 extern CONST_MODE_BASE_ALIGN unsigned short mode_base_align[NUM_MACHINE_MODES]; 890 891 extern unsigned get_mode_alignment (machine_mode); 892 893 #define GET_MODE_ALIGNMENT(MODE) get_mode_alignment (MODE) 894 895 /* For each class, get the narrowest mode in that class. */ 896 897 extern const unsigned char class_narrowest_mode[MAX_MODE_CLASS]; 898 #define GET_CLASS_NARROWEST_MODE(CLASS) \ 899 ((machine_mode) class_narrowest_mode[CLASS]) 900 901 /* The narrowest full integer mode available on the target. */ 902 903 #define NARROWEST_INT_MODE \ 904 (scalar_int_mode \ 905 (scalar_int_mode::from_int (class_narrowest_mode[MODE_INT]))) 906 907 /* Return the narrowest mode in T's class. */ 908 909 template<typename T> 910 inline T 911 get_narrowest_mode (T mode) 912 { 913 return typename mode_traits<T>::from_int 914 (class_narrowest_mode[GET_MODE_CLASS (mode)]); 915 } 916 917 /* Define the integer modes whose sizes are BITS_PER_UNIT and BITS_PER_WORD 918 and the mode whose class is Pmode and whose size is POINTER_SIZE. */ 919 920 extern scalar_int_mode byte_mode; 921 extern scalar_int_mode word_mode; 922 extern scalar_int_mode ptr_mode; 923 924 /* Target-dependent machine mode initialization - in insn-modes.c. */ 925 extern void init_adjust_machine_modes (void); 926 927 #define TRULY_NOOP_TRUNCATION_MODES_P(MODE1, MODE2) \ 928 (targetm.truly_noop_truncation (GET_MODE_PRECISION (MODE1), \ 929 GET_MODE_PRECISION (MODE2))) 930 931 /* Return true if MODE is a scalar integer mode that fits in a 932 HOST_WIDE_INT. */ 933 934 inline bool 935 HWI_COMPUTABLE_MODE_P (machine_mode mode) 936 { 937 machine_mode mme = mode; 938 return (SCALAR_INT_MODE_P (mme) 939 && mode_to_precision (mme).coeffs[0] <= HOST_BITS_PER_WIDE_INT); 940 } 941 942 inline bool 943 HWI_COMPUTABLE_MODE_P (scalar_int_mode mode) 944 { 945 return GET_MODE_PRECISION (mode) <= HOST_BITS_PER_WIDE_INT; 946 } 947 948 struct int_n_data_t { 949 /* These parts are initailized by genmodes output */ 950 unsigned int bitsize; 951 scalar_int_mode_pod m; 952 /* RID_* is RID_INTN_BASE + index into this array */ 953 }; 954 955 /* This is also in tree.h. genmodes.c guarantees the're sorted from 956 smallest bitsize to largest bitsize. */ 957 extern bool int_n_enabled_p[NUM_INT_N_ENTS]; 958 extern const int_n_data_t int_n_data[NUM_INT_N_ENTS]; 959 960 /* Return true if MODE has class MODE_INT, storing it as a scalar_int_mode 961 in *INT_MODE if so. */ 962 963 template<typename T> 964 inline bool 965 is_int_mode (machine_mode mode, T *int_mode) 966 { 967 if (GET_MODE_CLASS (mode) == MODE_INT) 968 { 969 *int_mode = scalar_int_mode (scalar_int_mode::from_int (mode)); 970 return true; 971 } 972 return false; 973 } 974 975 /* Return true if MODE has class MODE_FLOAT, storing it as a 976 scalar_float_mode in *FLOAT_MODE if so. */ 977 978 template<typename T> 979 inline bool 980 is_float_mode (machine_mode mode, T *float_mode) 981 { 982 if (GET_MODE_CLASS (mode) == MODE_FLOAT) 983 { 984 *float_mode = scalar_float_mode (scalar_float_mode::from_int (mode)); 985 return true; 986 } 987 return false; 988 } 989 990 /* Return true if MODE has class MODE_COMPLEX_INT, storing it as 991 a complex_mode in *CMODE if so. */ 992 993 template<typename T> 994 inline bool 995 is_complex_int_mode (machine_mode mode, T *cmode) 996 { 997 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT) 998 { 999 *cmode = complex_mode (complex_mode::from_int (mode)); 1000 return true; 1001 } 1002 return false; 1003 } 1004 1005 /* Return true if MODE has class MODE_COMPLEX_FLOAT, storing it as 1006 a complex_mode in *CMODE if so. */ 1007 1008 template<typename T> 1009 inline bool 1010 is_complex_float_mode (machine_mode mode, T *cmode) 1011 { 1012 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT) 1013 { 1014 *cmode = complex_mode (complex_mode::from_int (mode)); 1015 return true; 1016 } 1017 return false; 1018 } 1019 1020 /* Return true if MODE is a scalar integer mode with a precision 1021 smaller than LIMIT's precision. */ 1022 1023 inline bool 1024 is_narrower_int_mode (machine_mode mode, scalar_int_mode limit) 1025 { 1026 scalar_int_mode int_mode; 1027 return (is_a <scalar_int_mode> (mode, &int_mode) 1028 && GET_MODE_PRECISION (int_mode) < GET_MODE_PRECISION (limit)); 1029 } 1030 1031 namespace mode_iterator 1032 { 1033 /* Start mode iterator *ITER at the first mode in class MCLASS, if any. */ 1034 1035 template<typename T> 1036 inline void 1037 start (opt_mode<T> *iter, enum mode_class mclass) 1038 { 1039 if (GET_CLASS_NARROWEST_MODE (mclass) == E_VOIDmode) 1040 *iter = opt_mode<T> (); 1041 else 1042 *iter = as_a<T> (GET_CLASS_NARROWEST_MODE (mclass)); 1043 } 1044 1045 inline void 1046 start (machine_mode *iter, enum mode_class mclass) 1047 { 1048 *iter = GET_CLASS_NARROWEST_MODE (mclass); 1049 } 1050 1051 /* Return true if mode iterator *ITER has not reached the end. */ 1052 1053 template<typename T> 1054 inline bool 1055 iterate_p (opt_mode<T> *iter) 1056 { 1057 return iter->exists (); 1058 } 1059 1060 inline bool 1061 iterate_p (machine_mode *iter) 1062 { 1063 return *iter != E_VOIDmode; 1064 } 1065 1066 /* Set mode iterator *ITER to the next widest mode in the same class, 1067 if any. */ 1068 1069 template<typename T> 1070 inline void 1071 get_wider (opt_mode<T> *iter) 1072 { 1073 *iter = GET_MODE_WIDER_MODE (iter->require ()); 1074 } 1075 1076 inline void 1077 get_wider (machine_mode *iter) 1078 { 1079 *iter = GET_MODE_WIDER_MODE (*iter).else_void (); 1080 } 1081 1082 /* Set mode iterator *ITER to the next widest mode in the same class. 1083 Such a mode is known to exist. */ 1084 1085 template<typename T> 1086 inline void 1087 get_known_wider (T *iter) 1088 { 1089 *iter = GET_MODE_WIDER_MODE (*iter).require (); 1090 } 1091 1092 /* Set mode iterator *ITER to the mode that is two times wider than the 1093 current one, if such a mode exists. */ 1094 1095 template<typename T> 1096 inline void 1097 get_2xwider (opt_mode<T> *iter) 1098 { 1099 *iter = GET_MODE_2XWIDER_MODE (iter->require ()); 1100 } 1101 1102 inline void 1103 get_2xwider (machine_mode *iter) 1104 { 1105 *iter = GET_MODE_2XWIDER_MODE (*iter).else_void (); 1106 } 1107 } 1108 1109 /* Make ITERATOR iterate over all the modes in mode class CLASS, 1110 from narrowest to widest. */ 1111 #define FOR_EACH_MODE_IN_CLASS(ITERATOR, CLASS) \ 1112 for (mode_iterator::start (&(ITERATOR), CLASS); \ 1113 mode_iterator::iterate_p (&(ITERATOR)); \ 1114 mode_iterator::get_wider (&(ITERATOR))) 1115 1116 /* Make ITERATOR iterate over all the modes in the range [START, END), 1117 in order of increasing width. */ 1118 #define FOR_EACH_MODE(ITERATOR, START, END) \ 1119 for ((ITERATOR) = (START); \ 1120 (ITERATOR) != (END); \ 1121 mode_iterator::get_known_wider (&(ITERATOR))) 1122 1123 /* Make ITERATOR iterate over START and all wider modes in the same 1124 class, in order of increasing width. */ 1125 #define FOR_EACH_MODE_FROM(ITERATOR, START) \ 1126 for ((ITERATOR) = (START); \ 1127 mode_iterator::iterate_p (&(ITERATOR)); \ 1128 mode_iterator::get_wider (&(ITERATOR))) 1129 1130 /* Make ITERATOR iterate over modes in the range [NARROWEST, END) 1131 in order of increasing width, where NARROWEST is the narrowest mode 1132 in END's class. */ 1133 #define FOR_EACH_MODE_UNTIL(ITERATOR, END) \ 1134 FOR_EACH_MODE (ITERATOR, get_narrowest_mode (END), END) 1135 1136 /* Make ITERATOR iterate over modes in the same class as MODE, in order 1137 of increasing width. Start at the first mode wider than START, 1138 or don't iterate at all if there is no wider mode. */ 1139 #define FOR_EACH_WIDER_MODE(ITERATOR, START) \ 1140 for ((ITERATOR) = (START), mode_iterator::get_wider (&(ITERATOR)); \ 1141 mode_iterator::iterate_p (&(ITERATOR)); \ 1142 mode_iterator::get_wider (&(ITERATOR))) 1143 1144 /* Make ITERATOR iterate over modes in the same class as MODE, in order 1145 of increasing width, and with each mode being twice the width of the 1146 previous mode. Start at the mode that is two times wider than START, 1147 or don't iterate at all if there is no such mode. */ 1148 #define FOR_EACH_2XWIDER_MODE(ITERATOR, START) \ 1149 for ((ITERATOR) = (START), mode_iterator::get_2xwider (&(ITERATOR)); \ 1150 mode_iterator::iterate_p (&(ITERATOR)); \ 1151 mode_iterator::get_2xwider (&(ITERATOR))) 1152 1153 template<typename T> 1154 void 1155 gt_ggc_mx (pod_mode<T> *) 1156 { 1157 } 1158 1159 template<typename T> 1160 void 1161 gt_pch_nx (pod_mode<T> *) 1162 { 1163 } 1164 1165 template<typename T> 1166 void 1167 gt_pch_nx (pod_mode<T> *, void (*) (void *, void *), void *) 1168 { 1169 } 1170 1171 #endif /* not HAVE_MACHINE_MODES */ 1172