Add an is_narrower_int_mode helper function
[official-gcc.git] / gcc / machmode.h
blobf53e7b359f75be08ca0d0e6e411397fbdf4de055
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 typedef opt_mode<machine_mode> opt_machine_mode;
25 extern CONST_MODE_SIZE unsigned short mode_size[NUM_MACHINE_MODES];
26 extern const unsigned short mode_precision[NUM_MACHINE_MODES];
27 extern const unsigned char mode_inner[NUM_MACHINE_MODES];
28 extern const unsigned char 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];
34 template<typename T>
35 struct mode_traits
37 /* For use by the machmode support code only.
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:
44 return typename mode_traits<T>::from_int (mode);
46 when returning a T and:
48 res = T (typename mode_traits<T>::from_int (mode));
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.
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
72 template<>
73 struct mode_traits<machine_mode>
75 /* machine_mode itself needs no conversion. */
76 typedef machine_mode from_int;
79 /* Get the name of mode MODE as a string. */
81 extern const char * const mode_name[NUM_MACHINE_MODES];
82 #define GET_MODE_NAME(MODE) mode_name[MODE]
84 /* Mode classes. */
86 #include "mode-classes.def"
87 #define DEF_MODE_CLASS(M) M
88 enum mode_class { MODE_CLASSES, MAX_MODE_CLASS };
89 #undef DEF_MODE_CLASS
90 #undef MODE_CLASSES
92 /* Get the general kind of object that mode MODE represents
93 (integer, floating, complex, etc.) */
95 extern const unsigned char mode_class[NUM_MACHINE_MODES];
96 #define GET_MODE_CLASS(MODE) ((enum mode_class) mode_class[MODE])
98 /* Nonzero if MODE is an integral mode. */
99 #define INTEGRAL_MODE_P(MODE) \
100 (GET_MODE_CLASS (MODE) == MODE_INT \
101 || GET_MODE_CLASS (MODE) == MODE_PARTIAL_INT \
102 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_INT \
103 || GET_MODE_CLASS (MODE) == MODE_VECTOR_INT)
105 /* Nonzero if MODE is a floating-point mode. */
106 #define FLOAT_MODE_P(MODE) \
107 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
108 || GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT \
109 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT \
110 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT)
112 /* Nonzero if MODE is a complex mode. */
113 #define COMPLEX_MODE_P(MODE) \
114 (GET_MODE_CLASS (MODE) == MODE_COMPLEX_INT \
115 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT)
117 /* Nonzero if MODE is a vector mode. */
118 #define VECTOR_MODE_P(MODE) \
119 (GET_MODE_CLASS (MODE) == MODE_VECTOR_INT \
120 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT \
121 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FRACT \
122 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UFRACT \
123 || GET_MODE_CLASS (MODE) == MODE_VECTOR_ACCUM \
124 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UACCUM)
126 /* Nonzero if MODE is a scalar integral mode. */
127 #define SCALAR_INT_MODE_P(MODE) \
128 (GET_MODE_CLASS (MODE) == MODE_INT \
129 || GET_MODE_CLASS (MODE) == MODE_PARTIAL_INT)
131 /* Nonzero if MODE is a scalar floating point mode. */
132 #define SCALAR_FLOAT_MODE_P(MODE) \
133 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
134 || GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT)
136 /* Nonzero if MODE is a decimal floating point mode. */
137 #define DECIMAL_FLOAT_MODE_P(MODE) \
138 (GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT)
140 /* Nonzero if MODE is a scalar fract mode. */
141 #define SCALAR_FRACT_MODE_P(MODE) \
142 (GET_MODE_CLASS (MODE) == MODE_FRACT)
144 /* Nonzero if MODE is a scalar ufract mode. */
145 #define SCALAR_UFRACT_MODE_P(MODE) \
146 (GET_MODE_CLASS (MODE) == MODE_UFRACT)
148 /* Nonzero if MODE is a scalar fract or ufract mode. */
149 #define ALL_SCALAR_FRACT_MODE_P(MODE) \
150 (SCALAR_FRACT_MODE_P (MODE) || SCALAR_UFRACT_MODE_P (MODE))
152 /* Nonzero if MODE is a scalar accum mode. */
153 #define SCALAR_ACCUM_MODE_P(MODE) \
154 (GET_MODE_CLASS (MODE) == MODE_ACCUM)
156 /* Nonzero if MODE is a scalar uaccum mode. */
157 #define SCALAR_UACCUM_MODE_P(MODE) \
158 (GET_MODE_CLASS (MODE) == MODE_UACCUM)
160 /* Nonzero if MODE is a scalar accum or uaccum mode. */
161 #define ALL_SCALAR_ACCUM_MODE_P(MODE) \
162 (SCALAR_ACCUM_MODE_P (MODE) || SCALAR_UACCUM_MODE_P (MODE))
164 /* Nonzero if MODE is a scalar fract or accum mode. */
165 #define SIGNED_SCALAR_FIXED_POINT_MODE_P(MODE) \
166 (SCALAR_FRACT_MODE_P (MODE) || SCALAR_ACCUM_MODE_P (MODE))
168 /* Nonzero if MODE is a scalar ufract or uaccum mode. */
169 #define UNSIGNED_SCALAR_FIXED_POINT_MODE_P(MODE) \
170 (SCALAR_UFRACT_MODE_P (MODE) || SCALAR_UACCUM_MODE_P (MODE))
172 /* Nonzero if MODE is a scalar fract, ufract, accum or uaccum mode. */
173 #define ALL_SCALAR_FIXED_POINT_MODE_P(MODE) \
174 (SIGNED_SCALAR_FIXED_POINT_MODE_P (MODE) \
175 || UNSIGNED_SCALAR_FIXED_POINT_MODE_P (MODE))
177 /* Nonzero if MODE is a scalar/vector fract mode. */
178 #define FRACT_MODE_P(MODE) \
179 (GET_MODE_CLASS (MODE) == MODE_FRACT \
180 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FRACT)
182 /* Nonzero if MODE is a scalar/vector ufract mode. */
183 #define UFRACT_MODE_P(MODE) \
184 (GET_MODE_CLASS (MODE) == MODE_UFRACT \
185 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UFRACT)
187 /* Nonzero if MODE is a scalar/vector fract or ufract mode. */
188 #define ALL_FRACT_MODE_P(MODE) \
189 (FRACT_MODE_P (MODE) || UFRACT_MODE_P (MODE))
191 /* Nonzero if MODE is a scalar/vector accum mode. */
192 #define ACCUM_MODE_P(MODE) \
193 (GET_MODE_CLASS (MODE) == MODE_ACCUM \
194 || GET_MODE_CLASS (MODE) == MODE_VECTOR_ACCUM)
196 /* Nonzero if MODE is a scalar/vector uaccum mode. */
197 #define UACCUM_MODE_P(MODE) \
198 (GET_MODE_CLASS (MODE) == MODE_UACCUM \
199 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UACCUM)
201 /* Nonzero if MODE is a scalar/vector accum or uaccum mode. */
202 #define ALL_ACCUM_MODE_P(MODE) \
203 (ACCUM_MODE_P (MODE) || UACCUM_MODE_P (MODE))
205 /* Nonzero if MODE is a scalar/vector fract or accum mode. */
206 #define SIGNED_FIXED_POINT_MODE_P(MODE) \
207 (FRACT_MODE_P (MODE) || ACCUM_MODE_P (MODE))
209 /* Nonzero if MODE is a scalar/vector ufract or uaccum mode. */
210 #define UNSIGNED_FIXED_POINT_MODE_P(MODE) \
211 (UFRACT_MODE_P (MODE) || UACCUM_MODE_P (MODE))
213 /* Nonzero if MODE is a scalar/vector fract, ufract, accum or uaccum mode. */
214 #define ALL_FIXED_POINT_MODE_P(MODE) \
215 (SIGNED_FIXED_POINT_MODE_P (MODE) \
216 || UNSIGNED_FIXED_POINT_MODE_P (MODE))
218 /* Nonzero if CLASS modes can be widened. */
219 #define CLASS_HAS_WIDER_MODES_P(CLASS) \
220 (CLASS == MODE_INT \
221 || CLASS == MODE_PARTIAL_INT \
222 || CLASS == MODE_FLOAT \
223 || CLASS == MODE_DECIMAL_FLOAT \
224 || CLASS == MODE_COMPLEX_FLOAT \
225 || CLASS == MODE_FRACT \
226 || CLASS == MODE_UFRACT \
227 || CLASS == MODE_ACCUM \
228 || CLASS == MODE_UACCUM)
230 #define POINTER_BOUNDS_MODE_P(MODE) \
231 (GET_MODE_CLASS (MODE) == MODE_POINTER_BOUNDS)
233 /* An optional T (i.e. a T or nothing), where T is some form of mode class. */
234 template<typename T>
235 class opt_mode
237 public:
238 enum from_int { dummy = MAX_MACHINE_MODE };
240 ALWAYS_INLINE opt_mode () : m_mode (E_VOIDmode) {}
241 ALWAYS_INLINE opt_mode (const T &m) : m_mode (m) {}
242 template<typename U>
243 ALWAYS_INLINE opt_mode (const U &m) : m_mode (T (m)) {}
244 ALWAYS_INLINE opt_mode (from_int m) : m_mode (machine_mode (m)) {}
246 machine_mode else_void () const;
247 machine_mode else_blk () const;
248 T require () const;
250 bool exists () const;
251 template<typename U> bool exists (U *) const;
253 private:
254 machine_mode m_mode;
257 /* If the object contains a T, return its enum value, otherwise return
258 E_VOIDmode. */
260 template<typename T>
261 ALWAYS_INLINE machine_mode
262 opt_mode<T>::else_void () const
264 return m_mode;
267 /* If the T exists, return its enum value, otherwise return E_BLKmode. */
269 template<typename T>
270 inline machine_mode
271 opt_mode<T>::else_blk () const
273 return m_mode == E_VOIDmode ? E_BLKmode : m_mode;
276 /* Assert that the object contains a T and return it. */
278 template<typename T>
279 inline T
280 opt_mode<T>::require () const
282 gcc_checking_assert (m_mode != E_VOIDmode);
283 return typename mode_traits<T>::from_int (m_mode);
286 /* Return true if the object contains a T rather than nothing. */
288 template<typename T>
289 ALWAYS_INLINE bool
290 opt_mode<T>::exists () const
292 return m_mode != E_VOIDmode;
295 /* Return true if the object contains a T, storing it in *MODE if so. */
297 template<typename T>
298 template<typename U>
299 inline bool
300 opt_mode<T>::exists (U *mode) const
302 if (m_mode != E_VOIDmode)
304 *mode = T (typename mode_traits<T>::from_int (m_mode));
305 return true;
307 return false;
310 /* A POD version of mode class T. */
312 template<typename T>
313 struct pod_mode
315 typedef typename mode_traits<T>::from_int from_int;
317 machine_mode m_mode;
318 ALWAYS_INLINE operator machine_mode () const { return m_mode; }
319 ALWAYS_INLINE operator T () const { return from_int (m_mode); }
320 ALWAYS_INLINE pod_mode &operator = (const T &m) { m_mode = m; return *this; }
323 /* Return true if mode M has type T. */
325 template<typename T>
326 inline bool
327 is_a (machine_mode m)
329 return T::includes_p (m);
332 template<typename T, typename U>
333 inline bool
334 is_a (const opt_mode<U> &m)
336 return T::includes_p (m.else_void ());
339 /* Assert that mode M has type T, and return it in that form. */
341 template<typename T>
342 inline T
343 as_a (machine_mode m)
345 gcc_checking_assert (T::includes_p (m));
346 return typename mode_traits<T>::from_int (m);
349 template<typename T, typename U>
350 inline T
351 as_a (const opt_mode<U> &m)
353 return as_a <T> (m.else_void ());
356 /* Convert M to an opt_mode<T>. */
358 template<typename T>
359 inline opt_mode<T>
360 dyn_cast (machine_mode m)
362 if (T::includes_p (m))
363 return T (typename mode_traits<T>::from_int (m));
364 return opt_mode<T> ();
367 template<typename T, typename U>
368 inline opt_mode<T>
369 dyn_cast (const opt_mode<U> &m)
371 return dyn_cast <T> (m.else_void ());
374 /* Return true if mode M has type T, storing it as a T in *RESULT
375 if so. */
377 template<typename T, typename U>
378 inline bool
379 is_a (machine_mode m, U *result)
381 if (T::includes_p (m))
383 *result = T (typename mode_traits<T>::from_int (m));
384 return true;
386 return false;
389 /* Represents a machine mode that is known to be a SCALAR_INT_MODE_P. */
390 class scalar_int_mode
392 public:
393 typedef mode_traits<scalar_int_mode>::from_int from_int;
395 ALWAYS_INLINE scalar_int_mode () {}
396 ALWAYS_INLINE scalar_int_mode (from_int m) : m_mode (machine_mode (m)) {}
397 ALWAYS_INLINE operator machine_mode () const { return m_mode; }
399 static bool includes_p (machine_mode);
401 protected:
402 machine_mode m_mode;
405 /* Return true if M is a scalar_int_mode. */
407 inline bool
408 scalar_int_mode::includes_p (machine_mode m)
410 return SCALAR_INT_MODE_P (m);
413 /* Represents a machine mode that is known to be a SCALAR_FLOAT_MODE_P. */
414 class scalar_float_mode
416 public:
417 typedef mode_traits<scalar_float_mode>::from_int from_int;
419 ALWAYS_INLINE scalar_float_mode () {}
420 ALWAYS_INLINE scalar_float_mode (from_int m) : m_mode (machine_mode (m)) {}
421 ALWAYS_INLINE operator machine_mode () const { return m_mode; }
423 static bool includes_p (machine_mode);
425 protected:
426 machine_mode m_mode;
429 /* Return true if M is a scalar_float_mode. */
431 inline bool
432 scalar_float_mode::includes_p (machine_mode m)
434 return SCALAR_FLOAT_MODE_P (m);
437 /* Represents a machine mode that is known to be scalar. */
438 class scalar_mode
440 public:
441 typedef mode_traits<scalar_mode>::from_int from_int;
443 ALWAYS_INLINE scalar_mode () {}
444 ALWAYS_INLINE scalar_mode (from_int m) : m_mode (machine_mode (m)) {}
445 ALWAYS_INLINE scalar_mode (const scalar_int_mode &m) : m_mode (m) {}
446 ALWAYS_INLINE scalar_mode (const scalar_float_mode &m) : m_mode (m) {}
447 ALWAYS_INLINE scalar_mode (const scalar_int_mode_pod &m) : m_mode (m) {}
448 ALWAYS_INLINE operator machine_mode () const { return m_mode; }
450 static bool includes_p (machine_mode);
452 protected:
453 machine_mode m_mode;
456 /* Return true if M represents some kind of scalar value. */
458 inline bool
459 scalar_mode::includes_p (machine_mode m)
461 switch (GET_MODE_CLASS (m))
463 case MODE_INT:
464 case MODE_PARTIAL_INT:
465 case MODE_FRACT:
466 case MODE_UFRACT:
467 case MODE_ACCUM:
468 case MODE_UACCUM:
469 case MODE_FLOAT:
470 case MODE_DECIMAL_FLOAT:
471 case MODE_POINTER_BOUNDS:
472 return true;
473 default:
474 return false;
478 /* Represents a machine mode that is known to be a COMPLEX_MODE_P. */
479 class complex_mode
481 public:
482 typedef mode_traits<complex_mode>::from_int from_int;
484 ALWAYS_INLINE complex_mode () {}
485 ALWAYS_INLINE complex_mode (from_int m) : m_mode (machine_mode (m)) {}
486 ALWAYS_INLINE operator machine_mode () const { return m_mode; }
488 static bool includes_p (machine_mode);
490 protected:
491 machine_mode m_mode;
494 /* Return true if M is a complex_mode. */
496 inline bool
497 complex_mode::includes_p (machine_mode m)
499 return COMPLEX_MODE_P (m);
502 /* Return the base GET_MODE_SIZE value for MODE. */
504 ALWAYS_INLINE unsigned short
505 mode_to_bytes (machine_mode mode)
507 #if GCC_VERSION >= 4001
508 return (__builtin_constant_p (mode)
509 ? mode_size_inline (mode) : mode_size[mode]);
510 #else
511 return mode_size[mode];
512 #endif
515 /* Return the base GET_MODE_BITSIZE value for MODE. */
517 ALWAYS_INLINE unsigned short
518 mode_to_bits (machine_mode mode)
520 return mode_to_bytes (mode) * BITS_PER_UNIT;
523 /* Return the base GET_MODE_PRECISION value for MODE. */
525 ALWAYS_INLINE unsigned short
526 mode_to_precision (machine_mode mode)
528 return mode_precision[mode];
531 /* Return the base GET_MODE_INNER value for MODE. */
533 ALWAYS_INLINE scalar_mode
534 mode_to_inner (machine_mode mode)
536 #if GCC_VERSION >= 4001
537 return scalar_mode::from_int (__builtin_constant_p (mode)
538 ? mode_inner_inline (mode)
539 : mode_inner[mode]);
540 #else
541 return scalar_mode::from_int (mode_inner[mode]);
542 #endif
545 /* Return the base GET_MODE_UNIT_SIZE value for MODE. */
547 ALWAYS_INLINE unsigned char
548 mode_to_unit_size (machine_mode mode)
550 #if GCC_VERSION >= 4001
551 return (__builtin_constant_p (mode)
552 ? mode_unit_size_inline (mode) : mode_unit_size[mode]);
553 #else
554 return mode_unit_size[mode];
555 #endif
558 /* Return the base GET_MODE_UNIT_PRECISION value for MODE. */
560 ALWAYS_INLINE unsigned short
561 mode_to_unit_precision (machine_mode mode)
563 #if GCC_VERSION >= 4001
564 return (__builtin_constant_p (mode)
565 ? mode_unit_precision_inline (mode) : mode_unit_precision[mode]);
566 #else
567 return mode_unit_precision[mode];
568 #endif
571 /* Return the base GET_MODE_NUNITS value for MODE. */
573 ALWAYS_INLINE unsigned short
574 mode_to_nunits (machine_mode mode)
576 #if GCC_VERSION >= 4001
577 return (__builtin_constant_p (mode)
578 ? mode_nunits_inline (mode) : mode_nunits[mode]);
579 #else
580 return mode_nunits[mode];
581 #endif
584 /* Get the size in bytes of an object of mode MODE. */
586 #define GET_MODE_SIZE(MODE) (mode_to_bytes (MODE))
588 /* Get the size in bits of an object of mode MODE. */
590 #define GET_MODE_BITSIZE(MODE) (mode_to_bits (MODE))
592 /* Get the number of value bits of an object of mode MODE. */
594 #define GET_MODE_PRECISION(MODE) (mode_to_precision (MODE))
596 /* Get the number of integral bits of an object of mode MODE. */
597 extern CONST_MODE_IBIT unsigned char mode_ibit[NUM_MACHINE_MODES];
598 #define GET_MODE_IBIT(MODE) mode_ibit[MODE]
600 /* Get the number of fractional bits of an object of mode MODE. */
601 extern CONST_MODE_FBIT unsigned char mode_fbit[NUM_MACHINE_MODES];
602 #define GET_MODE_FBIT(MODE) mode_fbit[MODE]
604 /* Get a bitmask containing 1 for all bits in a word
605 that fit within mode MODE. */
607 extern const unsigned HOST_WIDE_INT mode_mask_array[NUM_MACHINE_MODES];
609 #define GET_MODE_MASK(MODE) mode_mask_array[MODE]
611 /* Return the mode of the basic parts of MODE. For vector modes this is the
612 mode of the vector elements. For complex modes it is the mode of the real
613 and imaginary parts. For other modes it is MODE itself. */
615 #define GET_MODE_INNER(MODE) (mode_to_inner (MODE))
617 /* Get the size in bytes or bits of the basic parts of an
618 object of mode MODE. */
620 #define GET_MODE_UNIT_SIZE(MODE) mode_to_unit_size (MODE)
622 #define GET_MODE_UNIT_BITSIZE(MODE) \
623 ((unsigned short) (GET_MODE_UNIT_SIZE (MODE) * BITS_PER_UNIT))
625 #define GET_MODE_UNIT_PRECISION(MODE) (mode_to_unit_precision (MODE))
627 /* Get the number of units in an object of mode MODE. This is 2 for
628 complex modes and the number of elements for vector modes. */
630 #define GET_MODE_NUNITS(MODE) (mode_to_nunits (MODE))
632 /* Get the next wider natural mode (eg, QI -> HI -> SI -> DI -> TI). */
634 template<typename T>
635 ALWAYS_INLINE opt_mode<T>
636 GET_MODE_WIDER_MODE (const T &m)
638 return typename opt_mode<T>::from_int (mode_wider[m]);
641 /* For scalars, this is a mode with twice the precision. For vectors,
642 this is a mode with the same inner mode but with twice the elements. */
644 template<typename T>
645 ALWAYS_INLINE opt_mode<T>
646 GET_MODE_2XWIDER_MODE (const T &m)
648 return typename opt_mode<T>::from_int (mode_2xwider[m]);
651 /* Get the complex mode from the component mode. */
652 extern const unsigned char mode_complex[NUM_MACHINE_MODES];
653 #define GET_MODE_COMPLEX_MODE(MODE) ((machine_mode) mode_complex[MODE])
655 /* Represents a machine mode that must have a fixed size. The main
656 use of this class is to represent the modes of objects that always
657 have static storage duration, such as constant pool entries.
658 (No current target supports the concept of variable-size static data.) */
659 class fixed_size_mode
661 public:
662 typedef mode_traits<fixed_size_mode>::from_int from_int;
664 ALWAYS_INLINE fixed_size_mode () {}
665 ALWAYS_INLINE fixed_size_mode (from_int m) : m_mode (machine_mode (m)) {}
666 ALWAYS_INLINE fixed_size_mode (const scalar_mode &m) : m_mode (m) {}
667 ALWAYS_INLINE fixed_size_mode (const scalar_int_mode &m) : m_mode (m) {}
668 ALWAYS_INLINE fixed_size_mode (const scalar_float_mode &m) : m_mode (m) {}
669 ALWAYS_INLINE fixed_size_mode (const scalar_mode_pod &m) : m_mode (m) {}
670 ALWAYS_INLINE fixed_size_mode (const scalar_int_mode_pod &m) : m_mode (m) {}
671 ALWAYS_INLINE fixed_size_mode (const complex_mode &m) : m_mode (m) {}
672 ALWAYS_INLINE operator machine_mode () const { return m_mode; }
674 static bool includes_p (machine_mode);
676 protected:
677 machine_mode m_mode;
680 /* Return true if MODE has a fixed size. */
682 inline bool
683 fixed_size_mode::includes_p (machine_mode)
685 return true;
688 extern opt_machine_mode mode_for_size (unsigned int, enum mode_class, int);
690 /* Return the machine mode to use for a MODE_INT of SIZE bits, if one
691 exists. If LIMIT is nonzero, modes wider than MAX_FIXED_MODE_SIZE
692 will not be used. */
694 inline opt_scalar_int_mode
695 int_mode_for_size (unsigned int size, int limit)
697 return dyn_cast <scalar_int_mode> (mode_for_size (size, MODE_INT, limit));
700 /* Return the machine mode to use for a MODE_FLOAT of SIZE bits, if one
701 exists. */
703 inline opt_scalar_float_mode
704 float_mode_for_size (unsigned int size)
706 return dyn_cast <scalar_float_mode> (mode_for_size (size, MODE_FLOAT, 0));
709 /* Likewise for MODE_DECIMAL_FLOAT. */
711 inline opt_scalar_float_mode
712 decimal_float_mode_for_size (unsigned int size)
714 return dyn_cast <scalar_float_mode>
715 (mode_for_size (size, MODE_DECIMAL_FLOAT, 0));
718 extern machine_mode smallest_mode_for_size (unsigned int, enum mode_class);
720 /* Find the narrowest integer mode that contains at least SIZE bits.
721 Such a mode must exist. */
723 inline scalar_int_mode
724 smallest_int_mode_for_size (unsigned int size)
726 return as_a <scalar_int_mode> (smallest_mode_for_size (size, MODE_INT));
729 extern opt_scalar_int_mode int_mode_for_mode (machine_mode);
730 extern opt_machine_mode bitwise_mode_for_mode (machine_mode);
731 extern opt_machine_mode mode_for_vector (scalar_mode, unsigned);
732 extern opt_machine_mode mode_for_int_vector (unsigned int, unsigned int);
734 /* Return the integer vector equivalent of MODE, if one exists. In other
735 words, return the mode for an integer vector that has the same number
736 of bits as MODE and the same number of elements as MODE, with the
737 latter being 1 if MODE is scalar. The returned mode can be either
738 an integer mode or a vector mode. */
740 inline opt_machine_mode
741 mode_for_int_vector (machine_mode mode)
743 return mode_for_int_vector (GET_MODE_UNIT_BITSIZE (mode),
744 GET_MODE_NUNITS (mode));
747 /* A class for iterating through possible bitfield modes. */
748 class bit_field_mode_iterator
750 public:
751 bit_field_mode_iterator (HOST_WIDE_INT, HOST_WIDE_INT,
752 HOST_WIDE_INT, HOST_WIDE_INT,
753 unsigned int, bool);
754 bool next_mode (scalar_int_mode *);
755 bool prefer_smaller_modes ();
757 private:
758 opt_scalar_int_mode m_mode;
759 /* We use signed values here because the bit position can be negative
760 for invalid input such as gcc.dg/pr48335-8.c. */
761 HOST_WIDE_INT m_bitsize;
762 HOST_WIDE_INT m_bitpos;
763 HOST_WIDE_INT m_bitregion_start;
764 HOST_WIDE_INT m_bitregion_end;
765 unsigned int m_align;
766 bool m_volatilep;
767 int m_count;
770 /* Find the best mode to use to access a bit field. */
772 extern bool get_best_mode (int, int, unsigned HOST_WIDE_INT,
773 unsigned HOST_WIDE_INT, unsigned int,
774 unsigned HOST_WIDE_INT, bool, scalar_int_mode *);
776 /* Determine alignment, 1<=result<=BIGGEST_ALIGNMENT. */
778 extern CONST_MODE_BASE_ALIGN unsigned short mode_base_align[NUM_MACHINE_MODES];
780 extern unsigned get_mode_alignment (machine_mode);
782 #define GET_MODE_ALIGNMENT(MODE) get_mode_alignment (MODE)
784 /* For each class, get the narrowest mode in that class. */
786 extern const unsigned char class_narrowest_mode[MAX_MODE_CLASS];
787 #define GET_CLASS_NARROWEST_MODE(CLASS) \
788 ((machine_mode) class_narrowest_mode[CLASS])
790 /* The narrowest full integer mode available on the target. */
792 #define NARROWEST_INT_MODE \
793 (scalar_int_mode \
794 (scalar_int_mode::from_int (class_narrowest_mode[MODE_INT])))
796 /* Return the narrowest mode in T's class. */
798 template<typename T>
799 inline T
800 get_narrowest_mode (T mode)
802 return typename mode_traits<T>::from_int
803 (class_narrowest_mode[GET_MODE_CLASS (mode)]);
806 /* Define the integer modes whose sizes are BITS_PER_UNIT and BITS_PER_WORD
807 and the mode whose class is Pmode and whose size is POINTER_SIZE. */
809 extern scalar_int_mode byte_mode;
810 extern scalar_int_mode word_mode;
811 extern scalar_int_mode ptr_mode;
813 /* Target-dependent machine mode initialization - in insn-modes.c. */
814 extern void init_adjust_machine_modes (void);
816 #define TRULY_NOOP_TRUNCATION_MODES_P(MODE1, MODE2) \
817 (targetm.truly_noop_truncation (GET_MODE_PRECISION (MODE1), \
818 GET_MODE_PRECISION (MODE2)))
820 #define HWI_COMPUTABLE_MODE_P(MODE) \
821 (SCALAR_INT_MODE_P (MODE) \
822 && GET_MODE_PRECISION (MODE) <= HOST_BITS_PER_WIDE_INT)
824 struct int_n_data_t {
825 /* These parts are initailized by genmodes output */
826 unsigned int bitsize;
827 scalar_int_mode_pod m;
828 /* RID_* is RID_INTN_BASE + index into this array */
831 /* This is also in tree.h. genmodes.c guarantees the're sorted from
832 smallest bitsize to largest bitsize. */
833 extern bool int_n_enabled_p[NUM_INT_N_ENTS];
834 extern const int_n_data_t int_n_data[NUM_INT_N_ENTS];
836 /* Return true if MODE has class MODE_INT, storing it as a scalar_int_mode
837 in *INT_MODE if so. */
839 template<typename T>
840 inline bool
841 is_int_mode (machine_mode mode, T *int_mode)
843 if (GET_MODE_CLASS (mode) == MODE_INT)
845 *int_mode = scalar_int_mode (scalar_int_mode::from_int (mode));
846 return true;
848 return false;
851 /* Return true if MODE has class MODE_FLOAT, storing it as a
852 scalar_float_mode in *FLOAT_MODE if so. */
854 template<typename T>
855 inline bool
856 is_float_mode (machine_mode mode, T *float_mode)
858 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
860 *float_mode = scalar_float_mode (scalar_float_mode::from_int (mode));
861 return true;
863 return false;
866 /* Return true if MODE has class MODE_COMPLEX_INT, storing it as
867 a complex_mode in *CMODE if so. */
869 template<typename T>
870 inline bool
871 is_complex_int_mode (machine_mode mode, T *cmode)
873 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
875 *cmode = complex_mode (complex_mode::from_int (mode));
876 return true;
878 return false;
881 /* Return true if MODE has class MODE_COMPLEX_FLOAT, storing it as
882 a complex_mode in *CMODE if so. */
884 template<typename T>
885 inline bool
886 is_complex_float_mode (machine_mode mode, T *cmode)
888 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
890 *cmode = complex_mode (complex_mode::from_int (mode));
891 return true;
893 return false;
896 /* Return true if MODE is a scalar integer mode with a precision
897 smaller than LIMIT's precision. */
899 inline bool
900 is_narrower_int_mode (machine_mode mode, scalar_int_mode limit)
902 scalar_int_mode int_mode;
903 return (is_a <scalar_int_mode> (mode, &int_mode)
904 && GET_MODE_PRECISION (int_mode) < GET_MODE_PRECISION (limit));
907 namespace mode_iterator
909 /* Start mode iterator *ITER at the first mode in class MCLASS, if any. */
911 template<typename T>
912 inline void
913 start (opt_mode<T> *iter, enum mode_class mclass)
915 if (GET_CLASS_NARROWEST_MODE (mclass) == E_VOIDmode)
916 *iter = opt_mode<T> ();
917 else
918 *iter = as_a<T> (GET_CLASS_NARROWEST_MODE (mclass));
921 inline void
922 start (machine_mode *iter, enum mode_class mclass)
924 *iter = GET_CLASS_NARROWEST_MODE (mclass);
927 /* Return true if mode iterator *ITER has not reached the end. */
929 template<typename T>
930 inline bool
931 iterate_p (opt_mode<T> *iter)
933 return iter->exists ();
936 inline bool
937 iterate_p (machine_mode *iter)
939 return *iter != E_VOIDmode;
942 /* Set mode iterator *ITER to the next widest mode in the same class,
943 if any. */
945 template<typename T>
946 inline void
947 get_wider (opt_mode<T> *iter)
949 *iter = GET_MODE_WIDER_MODE (iter->require ());
952 inline void
953 get_wider (machine_mode *iter)
955 *iter = GET_MODE_WIDER_MODE (*iter).else_void ();
958 /* Set mode iterator *ITER to the next widest mode in the same class.
959 Such a mode is known to exist. */
961 template<typename T>
962 inline void
963 get_known_wider (T *iter)
965 *iter = GET_MODE_WIDER_MODE (*iter).require ();
968 /* Set mode iterator *ITER to the mode that is two times wider than the
969 current one, if such a mode exists. */
971 template<typename T>
972 inline void
973 get_2xwider (opt_mode<T> *iter)
975 *iter = GET_MODE_2XWIDER_MODE (iter->require ());
978 inline void
979 get_2xwider (machine_mode *iter)
981 *iter = GET_MODE_2XWIDER_MODE (*iter).else_void ();
985 /* Make ITERATOR iterate over all the modes in mode class CLASS,
986 from narrowest to widest. */
987 #define FOR_EACH_MODE_IN_CLASS(ITERATOR, CLASS) \
988 for (mode_iterator::start (&(ITERATOR), CLASS); \
989 mode_iterator::iterate_p (&(ITERATOR)); \
990 mode_iterator::get_wider (&(ITERATOR)))
992 /* Make ITERATOR iterate over all the modes in the range [START, END),
993 in order of increasing width. */
994 #define FOR_EACH_MODE(ITERATOR, START, END) \
995 for ((ITERATOR) = (START); \
996 (ITERATOR) != (END); \
997 mode_iterator::get_known_wider (&(ITERATOR)))
999 /* Make ITERATOR iterate over START and all wider modes in the same
1000 class, in order of increasing width. */
1001 #define FOR_EACH_MODE_FROM(ITERATOR, START) \
1002 for ((ITERATOR) = (START); \
1003 mode_iterator::iterate_p (&(ITERATOR)); \
1004 mode_iterator::get_wider (&(ITERATOR)))
1006 /* Make ITERATOR iterate over modes in the range [NARROWEST, END)
1007 in order of increasing width, where NARROWEST is the narrowest mode
1008 in END's class. */
1009 #define FOR_EACH_MODE_UNTIL(ITERATOR, END) \
1010 FOR_EACH_MODE (ITERATOR, get_narrowest_mode (END), END)
1012 /* Make ITERATOR iterate over modes in the same class as MODE, in order
1013 of increasing width. Start at the first mode wider than START,
1014 or don't iterate at all if there is no wider mode. */
1015 #define FOR_EACH_WIDER_MODE(ITERATOR, START) \
1016 for ((ITERATOR) = (START), mode_iterator::get_wider (&(ITERATOR)); \
1017 mode_iterator::iterate_p (&(ITERATOR)); \
1018 mode_iterator::get_wider (&(ITERATOR)))
1020 /* Make ITERATOR iterate over modes in the same class as MODE, in order
1021 of increasing width, and with each mode being twice the width of the
1022 previous mode. Start at the mode that is two times wider than START,
1023 or don't iterate at all if there is no such mode. */
1024 #define FOR_EACH_2XWIDER_MODE(ITERATOR, START) \
1025 for ((ITERATOR) = (START), mode_iterator::get_2xwider (&(ITERATOR)); \
1026 mode_iterator::iterate_p (&(ITERATOR)); \
1027 mode_iterator::get_2xwider (&(ITERATOR)))
1029 template<typename T>
1030 void
1031 gt_ggc_mx (pod_mode<T> *)
1035 template<typename T>
1036 void
1037 gt_pch_nx (pod_mode<T> *)
1041 template<typename T>
1042 void
1043 gt_pch_nx (pod_mode<T> *, void (*) (void *, void *), void *)
1047 #endif /* not HAVE_MACHINE_MODES */