PR82045: Avoid passing machine modes through "..."
[official-gcc.git] / gcc / machmode.h
blobb331f07b4fd8fb73c727901895c6d49f0e798d29
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 /* Represents a machine mode that is known to be scalar. */
413 class scalar_mode
415 public:
416 typedef mode_traits<scalar_mode>::from_int from_int;
418 ALWAYS_INLINE scalar_mode () {}
419 ALWAYS_INLINE scalar_mode (from_int m) : m_mode (machine_mode (m)) {}
420 ALWAYS_INLINE scalar_mode (const scalar_int_mode &m) : m_mode (m) {}
421 ALWAYS_INLINE scalar_mode (const scalar_float_mode &m) : m_mode (m) {}
422 ALWAYS_INLINE scalar_mode (const scalar_int_mode_pod &m) : m_mode (m) {}
423 ALWAYS_INLINE operator machine_mode () const { return m_mode; }
425 static bool includes_p (machine_mode);
427 protected:
428 machine_mode m_mode;
431 /* Return true if M represents some kind of scalar value. */
433 inline bool
434 scalar_mode::includes_p (machine_mode m)
436 switch (GET_MODE_CLASS (m))
438 case MODE_INT:
439 case MODE_PARTIAL_INT:
440 case MODE_FRACT:
441 case MODE_UFRACT:
442 case MODE_ACCUM:
443 case MODE_UACCUM:
444 case MODE_FLOAT:
445 case MODE_DECIMAL_FLOAT:
446 case MODE_POINTER_BOUNDS:
447 return true;
448 default:
449 return false;
453 /* Represents a machine mode that is known to be a COMPLEX_MODE_P. */
454 class complex_mode
456 public:
457 typedef mode_traits<complex_mode>::from_int from_int;
459 ALWAYS_INLINE complex_mode () {}
460 ALWAYS_INLINE complex_mode (from_int m) : m_mode (machine_mode (m)) {}
461 ALWAYS_INLINE operator machine_mode () const { return m_mode; }
463 static bool includes_p (machine_mode);
465 protected:
466 machine_mode m_mode;
469 /* Return true if M is a complex_mode. */
471 inline bool
472 complex_mode::includes_p (machine_mode m)
474 return COMPLEX_MODE_P (m);
477 /* Return the base GET_MODE_SIZE value for MODE. */
479 ALWAYS_INLINE unsigned short
480 mode_to_bytes (machine_mode mode)
482 #if GCC_VERSION >= 4001
483 return (__builtin_constant_p (mode)
484 ? mode_size_inline (mode) : mode_size[mode]);
485 #else
486 return mode_size[mode];
487 #endif
490 /* Return the base GET_MODE_BITSIZE value for MODE. */
492 ALWAYS_INLINE unsigned short
493 mode_to_bits (machine_mode mode)
495 return mode_to_bytes (mode) * BITS_PER_UNIT;
498 /* Return the base GET_MODE_PRECISION value for MODE. */
500 ALWAYS_INLINE unsigned short
501 mode_to_precision (machine_mode mode)
503 return mode_precision[mode];
506 /* Return the base GET_MODE_INNER value for MODE. */
508 ALWAYS_INLINE scalar_mode
509 mode_to_inner (machine_mode mode)
511 #if GCC_VERSION >= 4001
512 return scalar_mode::from_int (__builtin_constant_p (mode)
513 ? mode_inner_inline (mode)
514 : mode_inner[mode]);
515 #else
516 return scalar_mode::from_int (mode_inner[mode]);
517 #endif
520 /* Return the base GET_MODE_UNIT_SIZE value for MODE. */
522 ALWAYS_INLINE unsigned char
523 mode_to_unit_size (machine_mode mode)
525 #if GCC_VERSION >= 4001
526 return (__builtin_constant_p (mode)
527 ? mode_unit_size_inline (mode) : mode_unit_size[mode]);
528 #else
529 return mode_unit_size[mode];
530 #endif
533 /* Return the base GET_MODE_UNIT_PRECISION value for MODE. */
535 ALWAYS_INLINE unsigned short
536 mode_to_unit_precision (machine_mode mode)
538 #if GCC_VERSION >= 4001
539 return (__builtin_constant_p (mode)
540 ? mode_unit_precision_inline (mode) : mode_unit_precision[mode]);
541 #else
542 return mode_unit_precision[mode];
543 #endif
546 /* Return the base GET_MODE_NUNITS value for MODE. */
548 ALWAYS_INLINE unsigned short
549 mode_to_nunits (machine_mode mode)
551 #if GCC_VERSION >= 4001
552 return (__builtin_constant_p (mode)
553 ? mode_nunits_inline (mode) : mode_nunits[mode]);
554 #else
555 return mode_nunits[mode];
556 #endif
559 /* Get the size in bytes of an object of mode MODE. */
561 #define GET_MODE_SIZE(MODE) (mode_to_bytes (MODE))
563 /* Get the size in bits of an object of mode MODE. */
565 #define GET_MODE_BITSIZE(MODE) (mode_to_bits (MODE))
567 /* Get the number of value bits of an object of mode MODE. */
569 #define GET_MODE_PRECISION(MODE) (mode_to_precision (MODE))
571 /* Get the number of integral bits of an object of mode MODE. */
572 extern CONST_MODE_IBIT unsigned char mode_ibit[NUM_MACHINE_MODES];
573 #define GET_MODE_IBIT(MODE) mode_ibit[MODE]
575 /* Get the number of fractional bits of an object of mode MODE. */
576 extern CONST_MODE_FBIT unsigned char mode_fbit[NUM_MACHINE_MODES];
577 #define GET_MODE_FBIT(MODE) mode_fbit[MODE]
579 /* Get a bitmask containing 1 for all bits in a word
580 that fit within mode MODE. */
582 extern const unsigned HOST_WIDE_INT mode_mask_array[NUM_MACHINE_MODES];
584 #define GET_MODE_MASK(MODE) mode_mask_array[MODE]
586 /* Return the mode of the basic parts of MODE. For vector modes this is the
587 mode of the vector elements. For complex modes it is the mode of the real
588 and imaginary parts. For other modes it is MODE itself. */
590 #define GET_MODE_INNER(MODE) (mode_to_inner (MODE))
592 /* Get the size in bytes or bits of the basic parts of an
593 object of mode MODE. */
595 #define GET_MODE_UNIT_SIZE(MODE) mode_to_unit_size (MODE)
597 #define GET_MODE_UNIT_BITSIZE(MODE) \
598 ((unsigned short) (GET_MODE_UNIT_SIZE (MODE) * BITS_PER_UNIT))
600 #define GET_MODE_UNIT_PRECISION(MODE) (mode_to_unit_precision (MODE))
602 /* Get the number of units in an object of mode MODE. This is 2 for
603 complex modes and the number of elements for vector modes. */
605 #define GET_MODE_NUNITS(MODE) (mode_to_nunits (MODE))
607 /* Get the next wider natural mode (eg, QI -> HI -> SI -> DI -> TI). */
609 template<typename T>
610 ALWAYS_INLINE opt_mode<T>
611 GET_MODE_WIDER_MODE (const T &m)
613 return typename opt_mode<T>::from_int (mode_wider[m]);
616 /* For scalars, this is a mode with twice the precision. For vectors,
617 this is a mode with the same inner mode but with twice the elements. */
619 template<typename T>
620 ALWAYS_INLINE opt_mode<T>
621 GET_MODE_2XWIDER_MODE (const T &m)
623 return typename opt_mode<T>::from_int (mode_2xwider[m]);
626 /* Get the complex mode from the component mode. */
627 extern const unsigned char mode_complex[NUM_MACHINE_MODES];
628 #define GET_MODE_COMPLEX_MODE(MODE) ((machine_mode) mode_complex[MODE])
630 /* Return the mode for data of a given size SIZE and mode class CLASS.
631 If LIMIT is nonzero, then don't use modes bigger than MAX_FIXED_MODE_SIZE.
632 The value is BLKmode if no other mode is found. */
634 extern machine_mode mode_for_size (unsigned int, enum mode_class, int);
636 /* Return the machine mode to use for a MODE_INT of SIZE bits, if one
637 exists. If LIMIT is nonzero, modes wider than MAX_FIXED_MODE_SIZE
638 will not be used. */
640 inline opt_scalar_int_mode
641 int_mode_for_size (unsigned int size, int limit)
643 return dyn_cast <scalar_int_mode> (mode_for_size (size, MODE_INT, limit));
646 /* Return the machine mode to use for a MODE_FLOAT of SIZE bits, if one
647 exists. */
649 inline opt_scalar_float_mode
650 float_mode_for_size (unsigned int size)
652 return dyn_cast <scalar_float_mode> (mode_for_size (size, MODE_FLOAT, 0));
655 /* Similar to mode_for_size, but find the smallest mode for a given width. */
657 extern machine_mode smallest_mode_for_size (unsigned int, enum mode_class);
659 /* Find the narrowest integer mode that contains at least SIZE bits.
660 Such a mode must exist. */
662 inline scalar_int_mode
663 smallest_int_mode_for_size (unsigned int size)
665 return as_a <scalar_int_mode> (smallest_mode_for_size (size, MODE_INT));
668 /* Return an integer mode of exactly the same size as the input mode. */
670 extern opt_scalar_int_mode int_mode_for_mode (machine_mode);
672 extern machine_mode bitwise_mode_for_mode (machine_mode);
674 /* Return a mode that is suitable for representing a vector,
675 or BLKmode on failure. */
677 extern machine_mode mode_for_vector (scalar_mode, unsigned);
679 /* A class for iterating through possible bitfield modes. */
680 class bit_field_mode_iterator
682 public:
683 bit_field_mode_iterator (HOST_WIDE_INT, HOST_WIDE_INT,
684 HOST_WIDE_INT, HOST_WIDE_INT,
685 unsigned int, bool);
686 bool next_mode (scalar_int_mode *);
687 bool prefer_smaller_modes ();
689 private:
690 opt_scalar_int_mode m_mode;
691 /* We use signed values here because the bit position can be negative
692 for invalid input such as gcc.dg/pr48335-8.c. */
693 HOST_WIDE_INT m_bitsize;
694 HOST_WIDE_INT m_bitpos;
695 HOST_WIDE_INT m_bitregion_start;
696 HOST_WIDE_INT m_bitregion_end;
697 unsigned int m_align;
698 bool m_volatilep;
699 int m_count;
702 /* Find the best mode to use to access a bit field. */
704 extern bool get_best_mode (int, int, unsigned HOST_WIDE_INT,
705 unsigned HOST_WIDE_INT, unsigned int,
706 unsigned HOST_WIDE_INT, bool, scalar_int_mode *);
708 /* Determine alignment, 1<=result<=BIGGEST_ALIGNMENT. */
710 extern CONST_MODE_BASE_ALIGN unsigned short mode_base_align[NUM_MACHINE_MODES];
712 extern unsigned get_mode_alignment (machine_mode);
714 #define GET_MODE_ALIGNMENT(MODE) get_mode_alignment (MODE)
716 /* For each class, get the narrowest mode in that class. */
718 extern const unsigned char class_narrowest_mode[MAX_MODE_CLASS];
719 #define GET_CLASS_NARROWEST_MODE(CLASS) \
720 ((machine_mode) class_narrowest_mode[CLASS])
722 /* The narrowest full integer mode available on the target. */
724 #define NARROWEST_INT_MODE \
725 (scalar_int_mode \
726 (scalar_int_mode::from_int (class_narrowest_mode[MODE_INT])))
728 /* Return the narrowest mode in T's class. */
730 template<typename T>
731 inline T
732 get_narrowest_mode (T mode)
734 return typename mode_traits<T>::from_int
735 (class_narrowest_mode[GET_MODE_CLASS (mode)]);
738 /* Define the integer modes whose sizes are BITS_PER_UNIT and BITS_PER_WORD
739 and the mode whose class is Pmode and whose size is POINTER_SIZE. */
741 extern scalar_int_mode byte_mode;
742 extern scalar_int_mode word_mode;
743 extern scalar_int_mode ptr_mode;
745 /* Target-dependent machine mode initialization - in insn-modes.c. */
746 extern void init_adjust_machine_modes (void);
748 #define TRULY_NOOP_TRUNCATION_MODES_P(MODE1, MODE2) \
749 TRULY_NOOP_TRUNCATION (GET_MODE_PRECISION (MODE1), \
750 GET_MODE_PRECISION (MODE2))
752 #define HWI_COMPUTABLE_MODE_P(MODE) \
753 (SCALAR_INT_MODE_P (MODE) \
754 && GET_MODE_PRECISION (MODE) <= HOST_BITS_PER_WIDE_INT)
756 struct int_n_data_t {
757 /* These parts are initailized by genmodes output */
758 unsigned int bitsize;
759 scalar_int_mode_pod m;
760 /* RID_* is RID_INTN_BASE + index into this array */
763 /* This is also in tree.h. genmodes.c guarantees the're sorted from
764 smallest bitsize to largest bitsize. */
765 extern bool int_n_enabled_p[NUM_INT_N_ENTS];
766 extern const int_n_data_t int_n_data[NUM_INT_N_ENTS];
768 /* Return true if MODE has class MODE_INT, storing it as a scalar_int_mode
769 in *INT_MODE if so. */
771 template<typename T>
772 inline bool
773 is_int_mode (machine_mode mode, T *int_mode)
775 if (GET_MODE_CLASS (mode) == MODE_INT)
777 *int_mode = scalar_int_mode (scalar_int_mode::from_int (mode));
778 return true;
780 return false;
783 /* Return true if MODE has class MODE_FLOAT, storing it as a
784 scalar_float_mode in *FLOAT_MODE if so. */
786 template<typename T>
787 inline bool
788 is_float_mode (machine_mode mode, T *float_mode)
790 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
792 *float_mode = scalar_float_mode (scalar_float_mode::from_int (mode));
793 return true;
795 return false;
798 /* Return true if MODE has class MODE_COMPLEX_INT, storing it as
799 a complex_mode in *CMODE if so. */
801 template<typename T>
802 inline bool
803 is_complex_int_mode (machine_mode mode, T *cmode)
805 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
807 *cmode = complex_mode (complex_mode::from_int (mode));
808 return true;
810 return false;
813 /* Return true if MODE has class MODE_COMPLEX_FLOAT, storing it as
814 a complex_mode in *CMODE if so. */
816 template<typename T>
817 inline bool
818 is_complex_float_mode (machine_mode mode, T *cmode)
820 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
822 *cmode = complex_mode (complex_mode::from_int (mode));
823 return true;
825 return false;
828 namespace mode_iterator
830 /* Start mode iterator *ITER at the first mode in class MCLASS, if any. */
832 template<typename T>
833 inline void
834 start (opt_mode<T> *iter, enum mode_class mclass)
836 if (GET_CLASS_NARROWEST_MODE (mclass) == E_VOIDmode)
837 *iter = opt_mode<T> ();
838 else
839 *iter = as_a<T> (GET_CLASS_NARROWEST_MODE (mclass));
842 inline void
843 start (machine_mode *iter, enum mode_class mclass)
845 *iter = GET_CLASS_NARROWEST_MODE (mclass);
848 /* Return true if mode iterator *ITER has not reached the end. */
850 template<typename T>
851 inline bool
852 iterate_p (opt_mode<T> *iter)
854 return iter->exists ();
857 inline bool
858 iterate_p (machine_mode *iter)
860 return *iter != E_VOIDmode;
863 /* Set mode iterator *ITER to the next widest mode in the same class,
864 if any. */
866 template<typename T>
867 inline void
868 get_wider (opt_mode<T> *iter)
870 *iter = GET_MODE_WIDER_MODE (iter->require ());
873 inline void
874 get_wider (machine_mode *iter)
876 *iter = GET_MODE_WIDER_MODE (*iter).else_void ();
879 /* Set mode iterator *ITER to the next widest mode in the same class.
880 Such a mode is known to exist. */
882 template<typename T>
883 inline void
884 get_known_wider (T *iter)
886 *iter = GET_MODE_WIDER_MODE (*iter).require ();
889 /* Set mode iterator *ITER to the mode that is two times wider than the
890 current one, if such a mode exists. */
892 template<typename T>
893 inline void
894 get_2xwider (opt_mode<T> *iter)
896 *iter = GET_MODE_2XWIDER_MODE (iter->require ());
899 inline void
900 get_2xwider (machine_mode *iter)
902 *iter = GET_MODE_2XWIDER_MODE (*iter).else_void ();
906 /* Make ITERATOR iterate over all the modes in mode class CLASS,
907 from narrowest to widest. */
908 #define FOR_EACH_MODE_IN_CLASS(ITERATOR, CLASS) \
909 for (mode_iterator::start (&(ITERATOR), CLASS); \
910 mode_iterator::iterate_p (&(ITERATOR)); \
911 mode_iterator::get_wider (&(ITERATOR)))
913 /* Make ITERATOR iterate over all the modes in the range [START, END),
914 in order of increasing width. */
915 #define FOR_EACH_MODE(ITERATOR, START, END) \
916 for ((ITERATOR) = (START); \
917 (ITERATOR) != (END); \
918 mode_iterator::get_known_wider (&(ITERATOR)))
920 /* Make ITERATOR iterate over START and all wider modes in the same
921 class, in order of increasing width. */
922 #define FOR_EACH_MODE_FROM(ITERATOR, START) \
923 for ((ITERATOR) = (START); \
924 mode_iterator::iterate_p (&(ITERATOR)); \
925 mode_iterator::get_wider (&(ITERATOR)))
927 /* Make ITERATOR iterate over modes in the range [NARROWEST, END)
928 in order of increasing width, where NARROWEST is the narrowest mode
929 in END's class. */
930 #define FOR_EACH_MODE_UNTIL(ITERATOR, END) \
931 FOR_EACH_MODE (ITERATOR, get_narrowest_mode (END), END)
933 /* Make ITERATOR iterate over modes in the same class as MODE, in order
934 of increasing width. Start at the first mode wider than START,
935 or don't iterate at all if there is no wider mode. */
936 #define FOR_EACH_WIDER_MODE(ITERATOR, START) \
937 for ((ITERATOR) = (START), mode_iterator::get_wider (&(ITERATOR)); \
938 mode_iterator::iterate_p (&(ITERATOR)); \
939 mode_iterator::get_wider (&(ITERATOR)))
941 /* Make ITERATOR iterate over modes in the same class as MODE, in order
942 of increasing width, and with each mode being twice the width of the
943 previous mode. Start at the mode that is two times wider than START,
944 or don't iterate at all if there is no such mode. */
945 #define FOR_EACH_2XWIDER_MODE(ITERATOR, START) \
946 for ((ITERATOR) = (START), mode_iterator::get_2xwider (&(ITERATOR)); \
947 mode_iterator::iterate_p (&(ITERATOR)); \
948 mode_iterator::get_2xwider (&(ITERATOR)))
950 template<typename T>
951 void
952 gt_ggc_mx (pod_mode<T> *)
956 template<typename T>
957 void
958 gt_pch_nx (pod_mode<T> *)
962 template<typename T>
963 void
964 gt_pch_nx (pod_mode<T> *, void (*) (void *, void *), void *)
968 #endif /* not HAVE_MACHINE_MODES */