[15/77] Add scalar_int_mode
[official-gcc.git] / gcc / machmode.h
blobdda7c0aed410ecacae24ac4607dea5c45908f132
1 /* Machine mode definitions for GCC; included by rtl.h and tree.h.
2 Copyright (C) 1991-2017 Free Software Foundation, Inc.
4 This file is part of GCC.
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.
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.
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/>. */
20 #ifndef HAVE_MACHINE_MODES
21 #define HAVE_MACHINE_MODES
23 extern CONST_MODE_SIZE unsigned short mode_size[NUM_MACHINE_MODES];
24 extern const unsigned short mode_precision[NUM_MACHINE_MODES];
25 extern const unsigned char mode_inner[NUM_MACHINE_MODES];
26 extern const unsigned char mode_nunits[NUM_MACHINE_MODES];
27 extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES];
28 extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES];
29 extern const unsigned char mode_wider[NUM_MACHINE_MODES];
30 extern const unsigned char mode_2xwider[NUM_MACHINE_MODES];
32 template<typename T>
33 struct mode_traits
35 /* For use by the machmode support code only.
37 There are cases in which the machmode support code needs to forcibly
38 convert a machine_mode to a specific mode class T, and in which the
39 context guarantees that this is valid without the need for an assert.
40 This can be done using:
42 return typename mode_traits<T>::from_int (mode);
44 when returning a T and:
46 res = T (typename mode_traits<T>::from_int (mode));
48 when assigning to a value RES that must be assignment-compatible
49 with (but possibly not the same as) T. */
50 #ifdef USE_ENUM_MODES
51 /* Allow direct conversion of enums to specific mode classes only
52 when USE_ENUM_MODES is defined. This is only intended for use
53 by gencondmd, so that it can tell more easily when .md conditions
54 are always false. */
55 typedef machine_mode from_int;
56 #else
57 /* Here we use an enum type distinct from machine_mode but with the
58 same range as machine_mode. T should have a constructor that
59 accepts this enum type; it should not have a constructor that
60 accepts machine_mode.
62 We use this somewhat indirect approach to avoid too many constructor
63 calls when the compiler is built with -O0. For example, even in
64 unoptimized code, the return statement above would construct the
65 returned T directly from the numerical value of MODE. */
66 enum from_int { dummy = MAX_MACHINE_MODE };
67 #endif
70 template<>
71 struct mode_traits<machine_mode>
73 /* machine_mode itself needs no conversion. */
74 typedef machine_mode from_int;
77 /* Get the name of mode MODE as a string. */
79 extern const char * const mode_name[NUM_MACHINE_MODES];
80 #define GET_MODE_NAME(MODE) mode_name[MODE]
82 /* Mode classes. */
84 #include "mode-classes.def"
85 #define DEF_MODE_CLASS(M) M
86 enum mode_class { MODE_CLASSES, MAX_MODE_CLASS };
87 #undef DEF_MODE_CLASS
88 #undef MODE_CLASSES
90 /* Get the general kind of object that mode MODE represents
91 (integer, floating, complex, etc.) */
93 extern const unsigned char mode_class[NUM_MACHINE_MODES];
94 #define GET_MODE_CLASS(MODE) ((enum mode_class) mode_class[MODE])
96 /* Nonzero if MODE is an integral mode. */
97 #define INTEGRAL_MODE_P(MODE) \
98 (GET_MODE_CLASS (MODE) == MODE_INT \
99 || GET_MODE_CLASS (MODE) == MODE_PARTIAL_INT \
100 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_INT \
101 || GET_MODE_CLASS (MODE) == MODE_VECTOR_INT)
103 /* Nonzero if MODE is a floating-point mode. */
104 #define FLOAT_MODE_P(MODE) \
105 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
106 || GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT \
107 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT \
108 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT)
110 /* Nonzero if MODE is a complex mode. */
111 #define COMPLEX_MODE_P(MODE) \
112 (GET_MODE_CLASS (MODE) == MODE_COMPLEX_INT \
113 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT)
115 /* Nonzero if MODE is a vector mode. */
116 #define VECTOR_MODE_P(MODE) \
117 (GET_MODE_CLASS (MODE) == MODE_VECTOR_INT \
118 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT \
119 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FRACT \
120 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UFRACT \
121 || GET_MODE_CLASS (MODE) == MODE_VECTOR_ACCUM \
122 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UACCUM)
124 /* Nonzero if MODE is a scalar integral mode. */
125 #define SCALAR_INT_MODE_P(MODE) \
126 (GET_MODE_CLASS (MODE) == MODE_INT \
127 || GET_MODE_CLASS (MODE) == MODE_PARTIAL_INT)
129 /* Nonzero if MODE is a scalar floating point mode. */
130 #define SCALAR_FLOAT_MODE_P(MODE) \
131 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
132 || GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT)
134 /* Nonzero if MODE is a decimal floating point mode. */
135 #define DECIMAL_FLOAT_MODE_P(MODE) \
136 (GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT)
138 /* Nonzero if MODE is a scalar fract mode. */
139 #define SCALAR_FRACT_MODE_P(MODE) \
140 (GET_MODE_CLASS (MODE) == MODE_FRACT)
142 /* Nonzero if MODE is a scalar ufract mode. */
143 #define SCALAR_UFRACT_MODE_P(MODE) \
144 (GET_MODE_CLASS (MODE) == MODE_UFRACT)
146 /* Nonzero if MODE is a scalar fract or ufract mode. */
147 #define ALL_SCALAR_FRACT_MODE_P(MODE) \
148 (SCALAR_FRACT_MODE_P (MODE) || SCALAR_UFRACT_MODE_P (MODE))
150 /* Nonzero if MODE is a scalar accum mode. */
151 #define SCALAR_ACCUM_MODE_P(MODE) \
152 (GET_MODE_CLASS (MODE) == MODE_ACCUM)
154 /* Nonzero if MODE is a scalar uaccum mode. */
155 #define SCALAR_UACCUM_MODE_P(MODE) \
156 (GET_MODE_CLASS (MODE) == MODE_UACCUM)
158 /* Nonzero if MODE is a scalar accum or uaccum mode. */
159 #define ALL_SCALAR_ACCUM_MODE_P(MODE) \
160 (SCALAR_ACCUM_MODE_P (MODE) || SCALAR_UACCUM_MODE_P (MODE))
162 /* Nonzero if MODE is a scalar fract or accum mode. */
163 #define SIGNED_SCALAR_FIXED_POINT_MODE_P(MODE) \
164 (SCALAR_FRACT_MODE_P (MODE) || SCALAR_ACCUM_MODE_P (MODE))
166 /* Nonzero if MODE is a scalar ufract or uaccum mode. */
167 #define UNSIGNED_SCALAR_FIXED_POINT_MODE_P(MODE) \
168 (SCALAR_UFRACT_MODE_P (MODE) || SCALAR_UACCUM_MODE_P (MODE))
170 /* Nonzero if MODE is a scalar fract, ufract, accum or uaccum mode. */
171 #define ALL_SCALAR_FIXED_POINT_MODE_P(MODE) \
172 (SIGNED_SCALAR_FIXED_POINT_MODE_P (MODE) \
173 || UNSIGNED_SCALAR_FIXED_POINT_MODE_P (MODE))
175 /* Nonzero if MODE is a scalar/vector fract mode. */
176 #define FRACT_MODE_P(MODE) \
177 (GET_MODE_CLASS (MODE) == MODE_FRACT \
178 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FRACT)
180 /* Nonzero if MODE is a scalar/vector ufract mode. */
181 #define UFRACT_MODE_P(MODE) \
182 (GET_MODE_CLASS (MODE) == MODE_UFRACT \
183 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UFRACT)
185 /* Nonzero if MODE is a scalar/vector fract or ufract mode. */
186 #define ALL_FRACT_MODE_P(MODE) \
187 (FRACT_MODE_P (MODE) || UFRACT_MODE_P (MODE))
189 /* Nonzero if MODE is a scalar/vector accum mode. */
190 #define ACCUM_MODE_P(MODE) \
191 (GET_MODE_CLASS (MODE) == MODE_ACCUM \
192 || GET_MODE_CLASS (MODE) == MODE_VECTOR_ACCUM)
194 /* Nonzero if MODE is a scalar/vector uaccum mode. */
195 #define UACCUM_MODE_P(MODE) \
196 (GET_MODE_CLASS (MODE) == MODE_UACCUM \
197 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UACCUM)
199 /* Nonzero if MODE is a scalar/vector accum or uaccum mode. */
200 #define ALL_ACCUM_MODE_P(MODE) \
201 (ACCUM_MODE_P (MODE) || UACCUM_MODE_P (MODE))
203 /* Nonzero if MODE is a scalar/vector fract or accum mode. */
204 #define SIGNED_FIXED_POINT_MODE_P(MODE) \
205 (FRACT_MODE_P (MODE) || ACCUM_MODE_P (MODE))
207 /* Nonzero if MODE is a scalar/vector ufract or uaccum mode. */
208 #define UNSIGNED_FIXED_POINT_MODE_P(MODE) \
209 (UFRACT_MODE_P (MODE) || UACCUM_MODE_P (MODE))
211 /* Nonzero if MODE is a scalar/vector fract, ufract, accum or uaccum mode. */
212 #define ALL_FIXED_POINT_MODE_P(MODE) \
213 (SIGNED_FIXED_POINT_MODE_P (MODE) \
214 || UNSIGNED_FIXED_POINT_MODE_P (MODE))
216 /* Nonzero if CLASS modes can be widened. */
217 #define CLASS_HAS_WIDER_MODES_P(CLASS) \
218 (CLASS == MODE_INT \
219 || CLASS == MODE_PARTIAL_INT \
220 || CLASS == MODE_FLOAT \
221 || CLASS == MODE_DECIMAL_FLOAT \
222 || CLASS == MODE_COMPLEX_FLOAT \
223 || CLASS == MODE_FRACT \
224 || CLASS == MODE_UFRACT \
225 || CLASS == MODE_ACCUM \
226 || CLASS == MODE_UACCUM)
228 #define POINTER_BOUNDS_MODE_P(MODE) \
229 (GET_MODE_CLASS (MODE) == MODE_POINTER_BOUNDS)
231 /* An optional T (i.e. a T or nothing), where T is some form of mode class. */
232 template<typename T>
233 class opt_mode
235 public:
236 enum from_int { dummy = MAX_MACHINE_MODE };
238 ALWAYS_INLINE opt_mode () : m_mode (E_VOIDmode) {}
239 ALWAYS_INLINE opt_mode (const T &m) : m_mode (m) {}
240 ALWAYS_INLINE opt_mode (from_int m) : m_mode (machine_mode (m)) {}
242 machine_mode else_void () const;
243 T require () const;
245 bool exists () const;
246 template<typename U> bool exists (U *) const;
248 private:
249 machine_mode m_mode;
252 /* If the object contains a T, return its enum value, otherwise return
253 E_VOIDmode. */
255 template<typename T>
256 ALWAYS_INLINE machine_mode
257 opt_mode<T>::else_void () const
259 return m_mode;
262 /* Assert that the object contains a T and return it. */
264 template<typename T>
265 inline T
266 opt_mode<T>::require () const
268 gcc_checking_assert (m_mode != E_VOIDmode);
269 return typename mode_traits<T>::from_int (m_mode);
272 /* Return true if the object contains a T rather than nothing. */
274 template<typename T>
275 ALWAYS_INLINE bool
276 opt_mode<T>::exists () const
278 return m_mode != E_VOIDmode;
281 /* Return true if the object contains a T, storing it in *MODE if so. */
283 template<typename T>
284 template<typename U>
285 inline bool
286 opt_mode<T>::exists (U *mode) const
288 if (m_mode != E_VOIDmode)
290 *mode = T (typename mode_traits<T>::from_int (m_mode));
291 return true;
293 return false;
296 /* Return true if mode M has type T. */
298 template<typename T>
299 inline bool
300 is_a (machine_mode m)
302 return T::includes_p (m);
305 /* Assert that mode M has type T, and return it in that form. */
307 template<typename T>
308 inline T
309 as_a (machine_mode m)
311 gcc_checking_assert (T::includes_p (m));
312 return typename mode_traits<T>::from_int (m);
315 /* Convert M to an opt_mode<T>. */
317 template<typename T>
318 inline opt_mode<T>
319 dyn_cast (machine_mode m)
321 if (T::includes_p (m))
322 return T (typename mode_traits<T>::from_int (m));
323 return opt_mode<T> ();
326 /* Return true if mode M has type T, storing it as a T in *RESULT
327 if so. */
329 template<typename T, typename U>
330 inline bool
331 is_a (machine_mode m, U *result)
333 if (T::includes_p (m))
335 *result = T (typename mode_traits<T>::from_int (m));
336 return true;
338 return false;
341 /* Represents a machine mode that is known to be a SCALAR_INT_MODE_P. */
342 class scalar_int_mode
344 public:
345 typedef mode_traits<scalar_int_mode>::from_int from_int;
347 ALWAYS_INLINE scalar_int_mode () {}
348 ALWAYS_INLINE scalar_int_mode (from_int m) : m_mode (machine_mode (m)) {}
349 ALWAYS_INLINE operator machine_mode () const { return m_mode; }
351 static bool includes_p (machine_mode);
353 protected:
354 machine_mode m_mode;
357 /* Return true if M is a scalar_int_mode. */
359 inline bool
360 scalar_int_mode::includes_p (machine_mode m)
362 return SCALAR_INT_MODE_P (m);
365 /* Represents a machine mode that is known to be a SCALAR_FLOAT_MODE_P. */
366 class scalar_float_mode
368 public:
369 typedef mode_traits<scalar_float_mode>::from_int from_int;
371 ALWAYS_INLINE scalar_float_mode () {}
372 ALWAYS_INLINE scalar_float_mode (from_int m) : m_mode (machine_mode (m)) {}
373 ALWAYS_INLINE operator machine_mode () const { return m_mode; }
375 static bool includes_p (machine_mode);
377 protected:
378 machine_mode m_mode;
381 /* Return true if M is a scalar_float_mode. */
383 inline bool
384 scalar_float_mode::includes_p (machine_mode m)
386 return SCALAR_FLOAT_MODE_P (m);
389 /* Return the base GET_MODE_SIZE value for MODE. */
391 ALWAYS_INLINE unsigned short
392 mode_to_bytes (machine_mode mode)
394 #if GCC_VERSION >= 4001
395 return (__builtin_constant_p (mode)
396 ? mode_size_inline (mode) : mode_size[mode]);
397 #else
398 return mode_size[mode];
399 #endif
402 /* Return the base GET_MODE_BITSIZE value for MODE. */
404 ALWAYS_INLINE unsigned short
405 mode_to_bits (machine_mode mode)
407 return mode_to_bytes (mode) * BITS_PER_UNIT;
410 /* Return the base GET_MODE_PRECISION value for MODE. */
412 ALWAYS_INLINE unsigned short
413 mode_to_precision (machine_mode mode)
415 return mode_precision[mode];
418 /* Return the base GET_MODE_INNER value for MODE. */
420 ALWAYS_INLINE machine_mode
421 mode_to_inner (machine_mode mode)
423 #if GCC_VERSION >= 4001
424 return (machine_mode) (__builtin_constant_p (mode)
425 ? mode_inner_inline (mode) : mode_inner[mode]);
426 #else
427 return (machine_mode) mode_inner[mode];
428 #endif
431 /* Return the base GET_MODE_UNIT_SIZE value for MODE. */
433 ALWAYS_INLINE unsigned char
434 mode_to_unit_size (machine_mode mode)
436 #if GCC_VERSION >= 4001
437 return (__builtin_constant_p (mode)
438 ? mode_unit_size_inline (mode) : mode_unit_size[mode]);
439 #else
440 return mode_unit_size[mode];
441 #endif
444 /* Return the base GET_MODE_UNIT_PRECISION value for MODE. */
446 ALWAYS_INLINE unsigned short
447 mode_to_unit_precision (machine_mode mode)
449 #if GCC_VERSION >= 4001
450 return (__builtin_constant_p (mode)
451 ? mode_unit_precision_inline (mode) : mode_unit_precision[mode]);
452 #else
453 return mode_unit_precision[mode];
454 #endif
457 /* Return the base GET_MODE_NUNITS value for MODE. */
459 ALWAYS_INLINE unsigned short
460 mode_to_nunits (machine_mode mode)
462 #if GCC_VERSION >= 4001
463 return (__builtin_constant_p (mode)
464 ? mode_nunits_inline (mode) : mode_nunits[mode]);
465 #else
466 return mode_nunits[mode];
467 #endif
470 /* Get the size in bytes of an object of mode MODE. */
472 #define GET_MODE_SIZE(MODE) (mode_to_bytes (MODE))
474 /* Get the size in bits of an object of mode MODE. */
476 #define GET_MODE_BITSIZE(MODE) (mode_to_bits (MODE))
478 /* Get the number of value bits of an object of mode MODE. */
480 #define GET_MODE_PRECISION(MODE) (mode_to_precision (MODE))
482 /* Get the number of integral bits of an object of mode MODE. */
483 extern CONST_MODE_IBIT unsigned char mode_ibit[NUM_MACHINE_MODES];
484 #define GET_MODE_IBIT(MODE) mode_ibit[MODE]
486 /* Get the number of fractional bits of an object of mode MODE. */
487 extern CONST_MODE_FBIT unsigned char mode_fbit[NUM_MACHINE_MODES];
488 #define GET_MODE_FBIT(MODE) mode_fbit[MODE]
490 /* Get a bitmask containing 1 for all bits in a word
491 that fit within mode MODE. */
493 extern const unsigned HOST_WIDE_INT mode_mask_array[NUM_MACHINE_MODES];
495 #define GET_MODE_MASK(MODE) mode_mask_array[MODE]
497 /* Return the mode of the basic parts of MODE. For vector modes this is the
498 mode of the vector elements. For complex modes it is the mode of the real
499 and imaginary parts. For other modes it is MODE itself. */
501 #define GET_MODE_INNER(MODE) (mode_to_inner (MODE))
503 /* Get the size in bytes or bits of the basic parts of an
504 object of mode MODE. */
506 #define GET_MODE_UNIT_SIZE(MODE) mode_to_unit_size (MODE)
508 #define GET_MODE_UNIT_BITSIZE(MODE) \
509 ((unsigned short) (GET_MODE_UNIT_SIZE (MODE) * BITS_PER_UNIT))
511 #define GET_MODE_UNIT_PRECISION(MODE) (mode_to_unit_precision (MODE))
513 /* Get the number of units in an object of mode MODE. This is 2 for
514 complex modes and the number of elements for vector modes. */
516 #define GET_MODE_NUNITS(MODE) (mode_to_nunits (MODE))
518 /* Get the next wider natural mode (eg, QI -> HI -> SI -> DI -> TI). */
520 template<typename T>
521 ALWAYS_INLINE opt_mode<T>
522 GET_MODE_WIDER_MODE (const T &m)
524 return typename opt_mode<T>::from_int (mode_wider[m]);
527 /* For scalars, this is a mode with twice the precision. For vectors,
528 this is a mode with the same inner mode but with twice the elements. */
530 template<typename T>
531 ALWAYS_INLINE opt_mode<T>
532 GET_MODE_2XWIDER_MODE (const T &m)
534 return typename opt_mode<T>::from_int (mode_2xwider[m]);
537 /* Get the complex mode from the component mode. */
538 extern const unsigned char mode_complex[NUM_MACHINE_MODES];
539 #define GET_MODE_COMPLEX_MODE(MODE) ((machine_mode) mode_complex[MODE])
541 /* Return the mode for data of a given size SIZE and mode class CLASS.
542 If LIMIT is nonzero, then don't use modes bigger than MAX_FIXED_MODE_SIZE.
543 The value is BLKmode if no other mode is found. */
545 extern machine_mode mode_for_size (unsigned int, enum mode_class, int);
547 /* Return the machine mode to use for a MODE_FLOAT of SIZE bits, if one
548 exists. */
550 inline opt_scalar_float_mode
551 float_mode_for_size (unsigned int size)
553 return dyn_cast <scalar_float_mode> (mode_for_size (size, MODE_FLOAT, 0));
556 /* Similar to mode_for_size, but find the smallest mode for a given width. */
558 extern machine_mode smallest_mode_for_size (unsigned int,
559 enum mode_class);
562 /* Return an integer mode of the exact same size as the input mode,
563 or BLKmode on failure. */
565 extern machine_mode int_mode_for_mode (machine_mode);
567 extern machine_mode bitwise_mode_for_mode (machine_mode);
569 /* Return a mode that is suitable for representing a vector,
570 or BLKmode on failure. */
572 extern machine_mode mode_for_vector (machine_mode, unsigned);
574 /* A class for iterating through possible bitfield modes. */
575 class bit_field_mode_iterator
577 public:
578 bit_field_mode_iterator (HOST_WIDE_INT, HOST_WIDE_INT,
579 HOST_WIDE_INT, HOST_WIDE_INT,
580 unsigned int, bool);
581 bool next_mode (machine_mode *);
582 bool prefer_smaller_modes ();
584 private:
585 machine_mode m_mode;
586 /* We use signed values here because the bit position can be negative
587 for invalid input such as gcc.dg/pr48335-8.c. */
588 HOST_WIDE_INT m_bitsize;
589 HOST_WIDE_INT m_bitpos;
590 HOST_WIDE_INT m_bitregion_start;
591 HOST_WIDE_INT m_bitregion_end;
592 unsigned int m_align;
593 bool m_volatilep;
594 int m_count;
597 /* Find the best mode to use to access a bit field. */
599 extern machine_mode get_best_mode (int, int,
600 unsigned HOST_WIDE_INT,
601 unsigned HOST_WIDE_INT,
602 unsigned int,
603 machine_mode, bool);
605 /* Determine alignment, 1<=result<=BIGGEST_ALIGNMENT. */
607 extern CONST_MODE_BASE_ALIGN unsigned short mode_base_align[NUM_MACHINE_MODES];
609 extern unsigned get_mode_alignment (machine_mode);
611 #define GET_MODE_ALIGNMENT(MODE) get_mode_alignment (MODE)
613 /* For each class, get the narrowest mode in that class. */
615 extern const unsigned char class_narrowest_mode[MAX_MODE_CLASS];
616 #define GET_CLASS_NARROWEST_MODE(CLASS) \
617 ((machine_mode) class_narrowest_mode[CLASS])
619 /* Return the narrowest mode in T's class. */
621 template<typename T>
622 inline T
623 get_narrowest_mode (T mode)
625 return typename mode_traits<T>::from_int
626 (class_narrowest_mode[GET_MODE_CLASS (mode)]);
629 /* Define the integer modes whose sizes are BITS_PER_UNIT and BITS_PER_WORD
630 and the mode whose class is Pmode and whose size is POINTER_SIZE. */
632 extern scalar_int_mode byte_mode;
633 extern scalar_int_mode word_mode;
634 extern scalar_int_mode ptr_mode;
636 /* Target-dependent machine mode initialization - in insn-modes.c. */
637 extern void init_adjust_machine_modes (void);
639 #define TRULY_NOOP_TRUNCATION_MODES_P(MODE1, MODE2) \
640 TRULY_NOOP_TRUNCATION (GET_MODE_PRECISION (MODE1), \
641 GET_MODE_PRECISION (MODE2))
643 #define HWI_COMPUTABLE_MODE_P(MODE) \
644 (SCALAR_INT_MODE_P (MODE) \
645 && GET_MODE_PRECISION (MODE) <= HOST_BITS_PER_WIDE_INT)
647 struct int_n_data_t {
648 /* These parts are initailized by genmodes output */
649 unsigned int bitsize;
650 machine_mode m;
651 /* RID_* is RID_INTN_BASE + index into this array */
654 /* This is also in tree.h. genmodes.c guarantees the're sorted from
655 smallest bitsize to largest bitsize. */
656 extern bool int_n_enabled_p[NUM_INT_N_ENTS];
657 extern const int_n_data_t int_n_data[NUM_INT_N_ENTS];
659 /* Return true if MODE has class MODE_FLOAT, storing it as a
660 scalar_float_mode in *FLOAT_MODE if so. */
662 template<typename T>
663 inline bool
664 is_float_mode (machine_mode mode, T *float_mode)
666 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
668 *float_mode = scalar_float_mode (scalar_float_mode::from_int (mode));
669 return true;
671 return false;
674 namespace mode_iterator
676 /* Start mode iterator *ITER at the first mode in class MCLASS, if any. */
678 template<typename T>
679 inline void
680 start (opt_mode<T> *iter, enum mode_class mclass)
682 if (GET_CLASS_NARROWEST_MODE (mclass) == E_VOIDmode)
683 *iter = opt_mode<T> ();
684 else
685 *iter = as_a<T> (GET_CLASS_NARROWEST_MODE (mclass));
688 inline void
689 start (machine_mode *iter, enum mode_class mclass)
691 *iter = GET_CLASS_NARROWEST_MODE (mclass);
694 /* Return true if mode iterator *ITER has not reached the end. */
696 template<typename T>
697 inline bool
698 iterate_p (opt_mode<T> *iter)
700 return iter->exists ();
703 inline bool
704 iterate_p (machine_mode *iter)
706 return *iter != E_VOIDmode;
709 /* Set mode iterator *ITER to the next widest mode in the same class,
710 if any. */
712 template<typename T>
713 inline void
714 get_wider (opt_mode<T> *iter)
716 *iter = GET_MODE_WIDER_MODE (iter->require ());
719 inline void
720 get_wider (machine_mode *iter)
722 *iter = GET_MODE_WIDER_MODE (*iter).else_void ();
725 /* Set mode iterator *ITER to the next widest mode in the same class.
726 Such a mode is known to exist. */
728 template<typename T>
729 inline void
730 get_known_wider (T *iter)
732 *iter = GET_MODE_WIDER_MODE (*iter).require ();
735 /* Set mode iterator *ITER to the mode that is two times wider than the
736 current one, if such a mode exists. */
738 inline void
739 get_2xwider (machine_mode *iter)
741 *iter = GET_MODE_2XWIDER_MODE (*iter).else_void ();
745 /* Make ITERATOR iterate over all the modes in mode class CLASS,
746 from narrowest to widest. */
747 #define FOR_EACH_MODE_IN_CLASS(ITERATOR, CLASS) \
748 for (mode_iterator::start (&(ITERATOR), CLASS); \
749 mode_iterator::iterate_p (&(ITERATOR)); \
750 mode_iterator::get_wider (&(ITERATOR)))
752 /* Make ITERATOR iterate over all the modes in the range [START, END),
753 in order of increasing width. */
754 #define FOR_EACH_MODE(ITERATOR, START, END) \
755 for ((ITERATOR) = (START); \
756 (ITERATOR) != (END); \
757 mode_iterator::get_known_wider (&(ITERATOR)))
759 /* Make ITERATOR iterate over START and all wider modes in the same
760 class, in order of increasing width. */
761 #define FOR_EACH_MODE_FROM(ITERATOR, START) \
762 for ((ITERATOR) = (START); \
763 mode_iterator::iterate_p (&(ITERATOR)); \
764 mode_iterator::get_wider (&(ITERATOR)))
766 /* Make ITERATOR iterate over modes in the range [NARROWEST, END)
767 in order of increasing width, where NARROWEST is the narrowest mode
768 in END's class. */
769 #define FOR_EACH_MODE_UNTIL(ITERATOR, END) \
770 FOR_EACH_MODE (ITERATOR, get_narrowest_mode (END), END)
772 /* Make ITERATOR iterate over modes in the same class as MODE, in order
773 of increasing width. Start at the first mode wider than START,
774 or don't iterate at all if there is no wider mode. */
775 #define FOR_EACH_WIDER_MODE(ITERATOR, START) \
776 for ((ITERATOR) = (START), mode_iterator::get_wider (&(ITERATOR)); \
777 mode_iterator::iterate_p (&(ITERATOR)); \
778 mode_iterator::get_wider (&(ITERATOR)))
780 /* Make ITERATOR iterate over modes in the same class as MODE, in order
781 of increasing width, and with each mode being twice the width of the
782 previous mode. Start at the mode that is two times wider than START,
783 or don't iterate at all if there is no such mode. */
784 #define FOR_EACH_2XWIDER_MODE(ITERATOR, START) \
785 for ((ITERATOR) = (START), mode_iterator::get_2xwider (&(ITERATOR)); \
786 mode_iterator::iterate_p (&(ITERATOR)); \
787 mode_iterator::get_2xwider (&(ITERATOR)))
789 #endif /* not HAVE_MACHINE_MODES */