[20/77] Replace MODE_INT checks with is_int_mode
[official-gcc.git] / gcc / machmode.h
blob497b0fbde54e610afa29198e0266f01d7587baa4
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 machine_mode else_blk () const;
244 T require () const;
246 bool exists () const;
247 template<typename U> bool exists (U *) const;
249 private:
250 machine_mode m_mode;
253 /* If the object contains a T, return its enum value, otherwise return
254 E_VOIDmode. */
256 template<typename T>
257 ALWAYS_INLINE machine_mode
258 opt_mode<T>::else_void () const
260 return m_mode;
263 /* If the T exists, return its enum value, otherwise return E_BLKmode. */
265 template<typename T>
266 inline machine_mode
267 opt_mode<T>::else_blk () const
269 return m_mode == E_VOIDmode ? E_BLKmode : m_mode;
272 /* Assert that the object contains a T and return it. */
274 template<typename T>
275 inline T
276 opt_mode<T>::require () const
278 gcc_checking_assert (m_mode != E_VOIDmode);
279 return typename mode_traits<T>::from_int (m_mode);
282 /* Return true if the object contains a T rather than nothing. */
284 template<typename T>
285 ALWAYS_INLINE bool
286 opt_mode<T>::exists () const
288 return m_mode != E_VOIDmode;
291 /* Return true if the object contains a T, storing it in *MODE if so. */
293 template<typename T>
294 template<typename U>
295 inline bool
296 opt_mode<T>::exists (U *mode) const
298 if (m_mode != E_VOIDmode)
300 *mode = T (typename mode_traits<T>::from_int (m_mode));
301 return true;
303 return false;
306 /* A POD version of mode class T. */
308 template<typename T>
309 struct pod_mode
311 typedef typename mode_traits<T>::from_int from_int;
313 machine_mode m_mode;
314 ALWAYS_INLINE operator machine_mode () const { return m_mode; }
315 ALWAYS_INLINE operator T () const { return from_int (m_mode); }
316 ALWAYS_INLINE pod_mode &operator = (const T &m) { m_mode = m; return *this; }
319 /* Return true if mode M has type T. */
321 template<typename T>
322 inline bool
323 is_a (machine_mode m)
325 return T::includes_p (m);
328 /* Assert that mode M has type T, and return it in that form. */
330 template<typename T>
331 inline T
332 as_a (machine_mode m)
334 gcc_checking_assert (T::includes_p (m));
335 return typename mode_traits<T>::from_int (m);
338 /* Convert M to an opt_mode<T>. */
340 template<typename T>
341 inline opt_mode<T>
342 dyn_cast (machine_mode m)
344 if (T::includes_p (m))
345 return T (typename mode_traits<T>::from_int (m));
346 return opt_mode<T> ();
349 /* Return true if mode M has type T, storing it as a T in *RESULT
350 if so. */
352 template<typename T, typename U>
353 inline bool
354 is_a (machine_mode m, U *result)
356 if (T::includes_p (m))
358 *result = T (typename mode_traits<T>::from_int (m));
359 return true;
361 return false;
364 /* Represents a machine mode that is known to be a SCALAR_INT_MODE_P. */
365 class scalar_int_mode
367 public:
368 typedef mode_traits<scalar_int_mode>::from_int from_int;
370 ALWAYS_INLINE scalar_int_mode () {}
371 ALWAYS_INLINE scalar_int_mode (from_int m) : m_mode (machine_mode (m)) {}
372 ALWAYS_INLINE operator machine_mode () const { return m_mode; }
374 static bool includes_p (machine_mode);
376 protected:
377 machine_mode m_mode;
380 /* Return true if M is a scalar_int_mode. */
382 inline bool
383 scalar_int_mode::includes_p (machine_mode m)
385 return SCALAR_INT_MODE_P (m);
388 /* Represents a machine mode that is known to be a SCALAR_FLOAT_MODE_P. */
389 class scalar_float_mode
391 public:
392 typedef mode_traits<scalar_float_mode>::from_int from_int;
394 ALWAYS_INLINE scalar_float_mode () {}
395 ALWAYS_INLINE scalar_float_mode (from_int m) : m_mode (machine_mode (m)) {}
396 ALWAYS_INLINE operator machine_mode () const { return m_mode; }
398 static bool includes_p (machine_mode);
400 protected:
401 machine_mode m_mode;
404 /* Return true if M is a scalar_float_mode. */
406 inline bool
407 scalar_float_mode::includes_p (machine_mode m)
409 return SCALAR_FLOAT_MODE_P (m);
412 /* Return the base GET_MODE_SIZE value for MODE. */
414 ALWAYS_INLINE unsigned short
415 mode_to_bytes (machine_mode mode)
417 #if GCC_VERSION >= 4001
418 return (__builtin_constant_p (mode)
419 ? mode_size_inline (mode) : mode_size[mode]);
420 #else
421 return mode_size[mode];
422 #endif
425 /* Return the base GET_MODE_BITSIZE value for MODE. */
427 ALWAYS_INLINE unsigned short
428 mode_to_bits (machine_mode mode)
430 return mode_to_bytes (mode) * BITS_PER_UNIT;
433 /* Return the base GET_MODE_PRECISION value for MODE. */
435 ALWAYS_INLINE unsigned short
436 mode_to_precision (machine_mode mode)
438 return mode_precision[mode];
441 /* Return the base GET_MODE_INNER value for MODE. */
443 ALWAYS_INLINE machine_mode
444 mode_to_inner (machine_mode mode)
446 #if GCC_VERSION >= 4001
447 return (machine_mode) (__builtin_constant_p (mode)
448 ? mode_inner_inline (mode) : mode_inner[mode]);
449 #else
450 return (machine_mode) mode_inner[mode];
451 #endif
454 /* Return the base GET_MODE_UNIT_SIZE value for MODE. */
456 ALWAYS_INLINE unsigned char
457 mode_to_unit_size (machine_mode mode)
459 #if GCC_VERSION >= 4001
460 return (__builtin_constant_p (mode)
461 ? mode_unit_size_inline (mode) : mode_unit_size[mode]);
462 #else
463 return mode_unit_size[mode];
464 #endif
467 /* Return the base GET_MODE_UNIT_PRECISION value for MODE. */
469 ALWAYS_INLINE unsigned short
470 mode_to_unit_precision (machine_mode mode)
472 #if GCC_VERSION >= 4001
473 return (__builtin_constant_p (mode)
474 ? mode_unit_precision_inline (mode) : mode_unit_precision[mode]);
475 #else
476 return mode_unit_precision[mode];
477 #endif
480 /* Return the base GET_MODE_NUNITS value for MODE. */
482 ALWAYS_INLINE unsigned short
483 mode_to_nunits (machine_mode mode)
485 #if GCC_VERSION >= 4001
486 return (__builtin_constant_p (mode)
487 ? mode_nunits_inline (mode) : mode_nunits[mode]);
488 #else
489 return mode_nunits[mode];
490 #endif
493 /* Get the size in bytes of an object of mode MODE. */
495 #define GET_MODE_SIZE(MODE) (mode_to_bytes (MODE))
497 /* Get the size in bits of an object of mode MODE. */
499 #define GET_MODE_BITSIZE(MODE) (mode_to_bits (MODE))
501 /* Get the number of value bits of an object of mode MODE. */
503 #define GET_MODE_PRECISION(MODE) (mode_to_precision (MODE))
505 /* Get the number of integral bits of an object of mode MODE. */
506 extern CONST_MODE_IBIT unsigned char mode_ibit[NUM_MACHINE_MODES];
507 #define GET_MODE_IBIT(MODE) mode_ibit[MODE]
509 /* Get the number of fractional bits of an object of mode MODE. */
510 extern CONST_MODE_FBIT unsigned char mode_fbit[NUM_MACHINE_MODES];
511 #define GET_MODE_FBIT(MODE) mode_fbit[MODE]
513 /* Get a bitmask containing 1 for all bits in a word
514 that fit within mode MODE. */
516 extern const unsigned HOST_WIDE_INT mode_mask_array[NUM_MACHINE_MODES];
518 #define GET_MODE_MASK(MODE) mode_mask_array[MODE]
520 /* Return the mode of the basic parts of MODE. For vector modes this is the
521 mode of the vector elements. For complex modes it is the mode of the real
522 and imaginary parts. For other modes it is MODE itself. */
524 #define GET_MODE_INNER(MODE) (mode_to_inner (MODE))
526 /* Get the size in bytes or bits of the basic parts of an
527 object of mode MODE. */
529 #define GET_MODE_UNIT_SIZE(MODE) mode_to_unit_size (MODE)
531 #define GET_MODE_UNIT_BITSIZE(MODE) \
532 ((unsigned short) (GET_MODE_UNIT_SIZE (MODE) * BITS_PER_UNIT))
534 #define GET_MODE_UNIT_PRECISION(MODE) (mode_to_unit_precision (MODE))
536 /* Get the number of units in an object of mode MODE. This is 2 for
537 complex modes and the number of elements for vector modes. */
539 #define GET_MODE_NUNITS(MODE) (mode_to_nunits (MODE))
541 /* Get the next wider natural mode (eg, QI -> HI -> SI -> DI -> TI). */
543 template<typename T>
544 ALWAYS_INLINE opt_mode<T>
545 GET_MODE_WIDER_MODE (const T &m)
547 return typename opt_mode<T>::from_int (mode_wider[m]);
550 /* For scalars, this is a mode with twice the precision. For vectors,
551 this is a mode with the same inner mode but with twice the elements. */
553 template<typename T>
554 ALWAYS_INLINE opt_mode<T>
555 GET_MODE_2XWIDER_MODE (const T &m)
557 return typename opt_mode<T>::from_int (mode_2xwider[m]);
560 /* Get the complex mode from the component mode. */
561 extern const unsigned char mode_complex[NUM_MACHINE_MODES];
562 #define GET_MODE_COMPLEX_MODE(MODE) ((machine_mode) mode_complex[MODE])
564 /* Return the mode for data of a given size SIZE and mode class CLASS.
565 If LIMIT is nonzero, then don't use modes bigger than MAX_FIXED_MODE_SIZE.
566 The value is BLKmode if no other mode is found. */
568 extern machine_mode mode_for_size (unsigned int, enum mode_class, int);
570 /* Return the machine mode to use for a MODE_INT of SIZE bits, if one
571 exists. If LIMIT is nonzero, modes wider than MAX_FIXED_MODE_SIZE
572 will not be used. */
574 inline opt_scalar_int_mode
575 int_mode_for_size (unsigned int size, int limit)
577 return dyn_cast <scalar_int_mode> (mode_for_size (size, MODE_INT, limit));
580 /* Return the machine mode to use for a MODE_FLOAT of SIZE bits, if one
581 exists. */
583 inline opt_scalar_float_mode
584 float_mode_for_size (unsigned int size)
586 return dyn_cast <scalar_float_mode> (mode_for_size (size, MODE_FLOAT, 0));
589 /* Similar to mode_for_size, but find the smallest mode for a given width. */
591 extern machine_mode smallest_mode_for_size (unsigned int, enum mode_class);
593 /* Find the narrowest integer mode that contains at least SIZE bits.
594 Such a mode must exist. */
596 inline scalar_int_mode
597 smallest_int_mode_for_size (unsigned int size)
599 return as_a <scalar_int_mode> (smallest_mode_for_size (size, MODE_INT));
602 /* Return an integer mode of exactly the same size as the input mode. */
604 extern opt_scalar_int_mode int_mode_for_mode (machine_mode);
606 extern machine_mode bitwise_mode_for_mode (machine_mode);
608 /* Return a mode that is suitable for representing a vector,
609 or BLKmode on failure. */
611 extern machine_mode mode_for_vector (machine_mode, unsigned);
613 /* A class for iterating through possible bitfield modes. */
614 class bit_field_mode_iterator
616 public:
617 bit_field_mode_iterator (HOST_WIDE_INT, HOST_WIDE_INT,
618 HOST_WIDE_INT, HOST_WIDE_INT,
619 unsigned int, bool);
620 bool next_mode (machine_mode *);
621 bool prefer_smaller_modes ();
623 private:
624 machine_mode m_mode;
625 /* We use signed values here because the bit position can be negative
626 for invalid input such as gcc.dg/pr48335-8.c. */
627 HOST_WIDE_INT m_bitsize;
628 HOST_WIDE_INT m_bitpos;
629 HOST_WIDE_INT m_bitregion_start;
630 HOST_WIDE_INT m_bitregion_end;
631 unsigned int m_align;
632 bool m_volatilep;
633 int m_count;
636 /* Find the best mode to use to access a bit field. */
638 extern machine_mode get_best_mode (int, int,
639 unsigned HOST_WIDE_INT,
640 unsigned HOST_WIDE_INT,
641 unsigned int,
642 machine_mode, bool);
644 /* Determine alignment, 1<=result<=BIGGEST_ALIGNMENT. */
646 extern CONST_MODE_BASE_ALIGN unsigned short mode_base_align[NUM_MACHINE_MODES];
648 extern unsigned get_mode_alignment (machine_mode);
650 #define GET_MODE_ALIGNMENT(MODE) get_mode_alignment (MODE)
652 /* For each class, get the narrowest mode in that class. */
654 extern const unsigned char class_narrowest_mode[MAX_MODE_CLASS];
655 #define GET_CLASS_NARROWEST_MODE(CLASS) \
656 ((machine_mode) class_narrowest_mode[CLASS])
658 /* Return the narrowest mode in T's class. */
660 template<typename T>
661 inline T
662 get_narrowest_mode (T mode)
664 return typename mode_traits<T>::from_int
665 (class_narrowest_mode[GET_MODE_CLASS (mode)]);
668 /* Define the integer modes whose sizes are BITS_PER_UNIT and BITS_PER_WORD
669 and the mode whose class is Pmode and whose size is POINTER_SIZE. */
671 extern scalar_int_mode byte_mode;
672 extern scalar_int_mode word_mode;
673 extern scalar_int_mode ptr_mode;
675 /* Target-dependent machine mode initialization - in insn-modes.c. */
676 extern void init_adjust_machine_modes (void);
678 #define TRULY_NOOP_TRUNCATION_MODES_P(MODE1, MODE2) \
679 TRULY_NOOP_TRUNCATION (GET_MODE_PRECISION (MODE1), \
680 GET_MODE_PRECISION (MODE2))
682 #define HWI_COMPUTABLE_MODE_P(MODE) \
683 (SCALAR_INT_MODE_P (MODE) \
684 && GET_MODE_PRECISION (MODE) <= HOST_BITS_PER_WIDE_INT)
686 struct int_n_data_t {
687 /* These parts are initailized by genmodes output */
688 unsigned int bitsize;
689 scalar_int_mode_pod m;
690 /* RID_* is RID_INTN_BASE + index into this array */
693 /* This is also in tree.h. genmodes.c guarantees the're sorted from
694 smallest bitsize to largest bitsize. */
695 extern bool int_n_enabled_p[NUM_INT_N_ENTS];
696 extern const int_n_data_t int_n_data[NUM_INT_N_ENTS];
698 /* Return true if MODE has class MODE_INT, storing it as a scalar_int_mode
699 in *INT_MODE if so. */
701 template<typename T>
702 inline bool
703 is_int_mode (machine_mode mode, T *int_mode)
705 if (GET_MODE_CLASS (mode) == MODE_INT)
707 *int_mode = scalar_int_mode (scalar_int_mode::from_int (mode));
708 return true;
710 return false;
713 /* Return true if MODE has class MODE_FLOAT, storing it as a
714 scalar_float_mode in *FLOAT_MODE if so. */
716 template<typename T>
717 inline bool
718 is_float_mode (machine_mode mode, T *float_mode)
720 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
722 *float_mode = scalar_float_mode (scalar_float_mode::from_int (mode));
723 return true;
725 return false;
728 namespace mode_iterator
730 /* Start mode iterator *ITER at the first mode in class MCLASS, if any. */
732 template<typename T>
733 inline void
734 start (opt_mode<T> *iter, enum mode_class mclass)
736 if (GET_CLASS_NARROWEST_MODE (mclass) == E_VOIDmode)
737 *iter = opt_mode<T> ();
738 else
739 *iter = as_a<T> (GET_CLASS_NARROWEST_MODE (mclass));
742 inline void
743 start (machine_mode *iter, enum mode_class mclass)
745 *iter = GET_CLASS_NARROWEST_MODE (mclass);
748 /* Return true if mode iterator *ITER has not reached the end. */
750 template<typename T>
751 inline bool
752 iterate_p (opt_mode<T> *iter)
754 return iter->exists ();
757 inline bool
758 iterate_p (machine_mode *iter)
760 return *iter != E_VOIDmode;
763 /* Set mode iterator *ITER to the next widest mode in the same class,
764 if any. */
766 template<typename T>
767 inline void
768 get_wider (opt_mode<T> *iter)
770 *iter = GET_MODE_WIDER_MODE (iter->require ());
773 inline void
774 get_wider (machine_mode *iter)
776 *iter = GET_MODE_WIDER_MODE (*iter).else_void ();
779 /* Set mode iterator *ITER to the next widest mode in the same class.
780 Such a mode is known to exist. */
782 template<typename T>
783 inline void
784 get_known_wider (T *iter)
786 *iter = GET_MODE_WIDER_MODE (*iter).require ();
789 /* Set mode iterator *ITER to the mode that is two times wider than the
790 current one, if such a mode exists. */
792 inline void
793 get_2xwider (machine_mode *iter)
795 *iter = GET_MODE_2XWIDER_MODE (*iter).else_void ();
799 /* Make ITERATOR iterate over all the modes in mode class CLASS,
800 from narrowest to widest. */
801 #define FOR_EACH_MODE_IN_CLASS(ITERATOR, CLASS) \
802 for (mode_iterator::start (&(ITERATOR), CLASS); \
803 mode_iterator::iterate_p (&(ITERATOR)); \
804 mode_iterator::get_wider (&(ITERATOR)))
806 /* Make ITERATOR iterate over all the modes in the range [START, END),
807 in order of increasing width. */
808 #define FOR_EACH_MODE(ITERATOR, START, END) \
809 for ((ITERATOR) = (START); \
810 (ITERATOR) != (END); \
811 mode_iterator::get_known_wider (&(ITERATOR)))
813 /* Make ITERATOR iterate over START and all wider modes in the same
814 class, in order of increasing width. */
815 #define FOR_EACH_MODE_FROM(ITERATOR, START) \
816 for ((ITERATOR) = (START); \
817 mode_iterator::iterate_p (&(ITERATOR)); \
818 mode_iterator::get_wider (&(ITERATOR)))
820 /* Make ITERATOR iterate over modes in the range [NARROWEST, END)
821 in order of increasing width, where NARROWEST is the narrowest mode
822 in END's class. */
823 #define FOR_EACH_MODE_UNTIL(ITERATOR, END) \
824 FOR_EACH_MODE (ITERATOR, get_narrowest_mode (END), END)
826 /* Make ITERATOR iterate over modes in the same class as MODE, in order
827 of increasing width. Start at the first mode wider than START,
828 or don't iterate at all if there is no wider mode. */
829 #define FOR_EACH_WIDER_MODE(ITERATOR, START) \
830 for ((ITERATOR) = (START), mode_iterator::get_wider (&(ITERATOR)); \
831 mode_iterator::iterate_p (&(ITERATOR)); \
832 mode_iterator::get_wider (&(ITERATOR)))
834 /* Make ITERATOR iterate over modes in the same class as MODE, in order
835 of increasing width, and with each mode being twice the width of the
836 previous mode. Start at the mode that is two times wider than START,
837 or don't iterate at all if there is no such mode. */
838 #define FOR_EACH_2XWIDER_MODE(ITERATOR, START) \
839 for ((ITERATOR) = (START), mode_iterator::get_2xwider (&(ITERATOR)); \
840 mode_iterator::iterate_p (&(ITERATOR)); \
841 mode_iterator::get_2xwider (&(ITERATOR)))
843 #endif /* not HAVE_MACHINE_MODES */