[64/77] Add a scalar_mode class
[official-gcc.git] / gcc / machmode.h
blob4586d62b81a29260042bd4c5ccda308b9de714cf
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 /* Return the base GET_MODE_SIZE value for MODE. */
455 ALWAYS_INLINE unsigned short
456 mode_to_bytes (machine_mode mode)
458 #if GCC_VERSION >= 4001
459 return (__builtin_constant_p (mode)
460 ? mode_size_inline (mode) : mode_size[mode]);
461 #else
462 return mode_size[mode];
463 #endif
466 /* Return the base GET_MODE_BITSIZE value for MODE. */
468 ALWAYS_INLINE unsigned short
469 mode_to_bits (machine_mode mode)
471 return mode_to_bytes (mode) * BITS_PER_UNIT;
474 /* Return the base GET_MODE_PRECISION value for MODE. */
476 ALWAYS_INLINE unsigned short
477 mode_to_precision (machine_mode mode)
479 return mode_precision[mode];
482 /* Return the base GET_MODE_INNER value for MODE. */
484 ALWAYS_INLINE scalar_mode
485 mode_to_inner (machine_mode mode)
487 #if GCC_VERSION >= 4001
488 return scalar_mode::from_int (__builtin_constant_p (mode)
489 ? mode_inner_inline (mode)
490 : mode_inner[mode]);
491 #else
492 return scalar_mode::from_int (mode_inner[mode]);
493 #endif
496 /* Return the base GET_MODE_UNIT_SIZE value for MODE. */
498 ALWAYS_INLINE unsigned char
499 mode_to_unit_size (machine_mode mode)
501 #if GCC_VERSION >= 4001
502 return (__builtin_constant_p (mode)
503 ? mode_unit_size_inline (mode) : mode_unit_size[mode]);
504 #else
505 return mode_unit_size[mode];
506 #endif
509 /* Return the base GET_MODE_UNIT_PRECISION value for MODE. */
511 ALWAYS_INLINE unsigned short
512 mode_to_unit_precision (machine_mode mode)
514 #if GCC_VERSION >= 4001
515 return (__builtin_constant_p (mode)
516 ? mode_unit_precision_inline (mode) : mode_unit_precision[mode]);
517 #else
518 return mode_unit_precision[mode];
519 #endif
522 /* Return the base GET_MODE_NUNITS value for MODE. */
524 ALWAYS_INLINE unsigned short
525 mode_to_nunits (machine_mode mode)
527 #if GCC_VERSION >= 4001
528 return (__builtin_constant_p (mode)
529 ? mode_nunits_inline (mode) : mode_nunits[mode]);
530 #else
531 return mode_nunits[mode];
532 #endif
535 /* Get the size in bytes of an object of mode MODE. */
537 #define GET_MODE_SIZE(MODE) (mode_to_bytes (MODE))
539 /* Get the size in bits of an object of mode MODE. */
541 #define GET_MODE_BITSIZE(MODE) (mode_to_bits (MODE))
543 /* Get the number of value bits of an object of mode MODE. */
545 #define GET_MODE_PRECISION(MODE) (mode_to_precision (MODE))
547 /* Get the number of integral bits of an object of mode MODE. */
548 extern CONST_MODE_IBIT unsigned char mode_ibit[NUM_MACHINE_MODES];
549 #define GET_MODE_IBIT(MODE) mode_ibit[MODE]
551 /* Get the number of fractional bits of an object of mode MODE. */
552 extern CONST_MODE_FBIT unsigned char mode_fbit[NUM_MACHINE_MODES];
553 #define GET_MODE_FBIT(MODE) mode_fbit[MODE]
555 /* Get a bitmask containing 1 for all bits in a word
556 that fit within mode MODE. */
558 extern const unsigned HOST_WIDE_INT mode_mask_array[NUM_MACHINE_MODES];
560 #define GET_MODE_MASK(MODE) mode_mask_array[MODE]
562 /* Return the mode of the basic parts of MODE. For vector modes this is the
563 mode of the vector elements. For complex modes it is the mode of the real
564 and imaginary parts. For other modes it is MODE itself. */
566 #define GET_MODE_INNER(MODE) (mode_to_inner (MODE))
568 /* Get the size in bytes or bits of the basic parts of an
569 object of mode MODE. */
571 #define GET_MODE_UNIT_SIZE(MODE) mode_to_unit_size (MODE)
573 #define GET_MODE_UNIT_BITSIZE(MODE) \
574 ((unsigned short) (GET_MODE_UNIT_SIZE (MODE) * BITS_PER_UNIT))
576 #define GET_MODE_UNIT_PRECISION(MODE) (mode_to_unit_precision (MODE))
578 /* Get the number of units in an object of mode MODE. This is 2 for
579 complex modes and the number of elements for vector modes. */
581 #define GET_MODE_NUNITS(MODE) (mode_to_nunits (MODE))
583 /* Get the next wider natural mode (eg, QI -> HI -> SI -> DI -> TI). */
585 template<typename T>
586 ALWAYS_INLINE opt_mode<T>
587 GET_MODE_WIDER_MODE (const T &m)
589 return typename opt_mode<T>::from_int (mode_wider[m]);
592 /* For scalars, this is a mode with twice the precision. For vectors,
593 this is a mode with the same inner mode but with twice the elements. */
595 template<typename T>
596 ALWAYS_INLINE opt_mode<T>
597 GET_MODE_2XWIDER_MODE (const T &m)
599 return typename opt_mode<T>::from_int (mode_2xwider[m]);
602 /* Get the complex mode from the component mode. */
603 extern const unsigned char mode_complex[NUM_MACHINE_MODES];
604 #define GET_MODE_COMPLEX_MODE(MODE) ((machine_mode) mode_complex[MODE])
606 /* Return the mode for data of a given size SIZE and mode class CLASS.
607 If LIMIT is nonzero, then don't use modes bigger than MAX_FIXED_MODE_SIZE.
608 The value is BLKmode if no other mode is found. */
610 extern machine_mode mode_for_size (unsigned int, enum mode_class, int);
612 /* Return the machine mode to use for a MODE_INT of SIZE bits, if one
613 exists. If LIMIT is nonzero, modes wider than MAX_FIXED_MODE_SIZE
614 will not be used. */
616 inline opt_scalar_int_mode
617 int_mode_for_size (unsigned int size, int limit)
619 return dyn_cast <scalar_int_mode> (mode_for_size (size, MODE_INT, limit));
622 /* Return the machine mode to use for a MODE_FLOAT of SIZE bits, if one
623 exists. */
625 inline opt_scalar_float_mode
626 float_mode_for_size (unsigned int size)
628 return dyn_cast <scalar_float_mode> (mode_for_size (size, MODE_FLOAT, 0));
631 /* Similar to mode_for_size, but find the smallest mode for a given width. */
633 extern machine_mode smallest_mode_for_size (unsigned int, enum mode_class);
635 /* Find the narrowest integer mode that contains at least SIZE bits.
636 Such a mode must exist. */
638 inline scalar_int_mode
639 smallest_int_mode_for_size (unsigned int size)
641 return as_a <scalar_int_mode> (smallest_mode_for_size (size, MODE_INT));
644 /* Return an integer mode of exactly the same size as the input mode. */
646 extern opt_scalar_int_mode int_mode_for_mode (machine_mode);
648 extern machine_mode bitwise_mode_for_mode (machine_mode);
650 /* Return a mode that is suitable for representing a vector,
651 or BLKmode on failure. */
653 extern machine_mode mode_for_vector (machine_mode, unsigned);
655 /* A class for iterating through possible bitfield modes. */
656 class bit_field_mode_iterator
658 public:
659 bit_field_mode_iterator (HOST_WIDE_INT, HOST_WIDE_INT,
660 HOST_WIDE_INT, HOST_WIDE_INT,
661 unsigned int, bool);
662 bool next_mode (scalar_int_mode *);
663 bool prefer_smaller_modes ();
665 private:
666 opt_scalar_int_mode m_mode;
667 /* We use signed values here because the bit position can be negative
668 for invalid input such as gcc.dg/pr48335-8.c. */
669 HOST_WIDE_INT m_bitsize;
670 HOST_WIDE_INT m_bitpos;
671 HOST_WIDE_INT m_bitregion_start;
672 HOST_WIDE_INT m_bitregion_end;
673 unsigned int m_align;
674 bool m_volatilep;
675 int m_count;
678 /* Find the best mode to use to access a bit field. */
680 extern bool get_best_mode (int, int, unsigned HOST_WIDE_INT,
681 unsigned HOST_WIDE_INT, unsigned int,
682 unsigned HOST_WIDE_INT, bool, scalar_int_mode *);
684 /* Determine alignment, 1<=result<=BIGGEST_ALIGNMENT. */
686 extern CONST_MODE_BASE_ALIGN unsigned short mode_base_align[NUM_MACHINE_MODES];
688 extern unsigned get_mode_alignment (machine_mode);
690 #define GET_MODE_ALIGNMENT(MODE) get_mode_alignment (MODE)
692 /* For each class, get the narrowest mode in that class. */
694 extern const unsigned char class_narrowest_mode[MAX_MODE_CLASS];
695 #define GET_CLASS_NARROWEST_MODE(CLASS) \
696 ((machine_mode) class_narrowest_mode[CLASS])
698 /* The narrowest full integer mode available on the target. */
700 #define NARROWEST_INT_MODE \
701 (scalar_int_mode \
702 (scalar_int_mode::from_int (class_narrowest_mode[MODE_INT])))
704 /* Return the narrowest mode in T's class. */
706 template<typename T>
707 inline T
708 get_narrowest_mode (T mode)
710 return typename mode_traits<T>::from_int
711 (class_narrowest_mode[GET_MODE_CLASS (mode)]);
714 /* Define the integer modes whose sizes are BITS_PER_UNIT and BITS_PER_WORD
715 and the mode whose class is Pmode and whose size is POINTER_SIZE. */
717 extern scalar_int_mode byte_mode;
718 extern scalar_int_mode word_mode;
719 extern scalar_int_mode ptr_mode;
721 /* Target-dependent machine mode initialization - in insn-modes.c. */
722 extern void init_adjust_machine_modes (void);
724 #define TRULY_NOOP_TRUNCATION_MODES_P(MODE1, MODE2) \
725 TRULY_NOOP_TRUNCATION (GET_MODE_PRECISION (MODE1), \
726 GET_MODE_PRECISION (MODE2))
728 #define HWI_COMPUTABLE_MODE_P(MODE) \
729 (SCALAR_INT_MODE_P (MODE) \
730 && GET_MODE_PRECISION (MODE) <= HOST_BITS_PER_WIDE_INT)
732 struct int_n_data_t {
733 /* These parts are initailized by genmodes output */
734 unsigned int bitsize;
735 scalar_int_mode_pod m;
736 /* RID_* is RID_INTN_BASE + index into this array */
739 /* This is also in tree.h. genmodes.c guarantees the're sorted from
740 smallest bitsize to largest bitsize. */
741 extern bool int_n_enabled_p[NUM_INT_N_ENTS];
742 extern const int_n_data_t int_n_data[NUM_INT_N_ENTS];
744 /* Return true if MODE has class MODE_INT, storing it as a scalar_int_mode
745 in *INT_MODE if so. */
747 template<typename T>
748 inline bool
749 is_int_mode (machine_mode mode, T *int_mode)
751 if (GET_MODE_CLASS (mode) == MODE_INT)
753 *int_mode = scalar_int_mode (scalar_int_mode::from_int (mode));
754 return true;
756 return false;
759 /* Return true if MODE has class MODE_FLOAT, storing it as a
760 scalar_float_mode in *FLOAT_MODE if so. */
762 template<typename T>
763 inline bool
764 is_float_mode (machine_mode mode, T *float_mode)
766 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
768 *float_mode = scalar_float_mode (scalar_float_mode::from_int (mode));
769 return true;
771 return false;
774 namespace mode_iterator
776 /* Start mode iterator *ITER at the first mode in class MCLASS, if any. */
778 template<typename T>
779 inline void
780 start (opt_mode<T> *iter, enum mode_class mclass)
782 if (GET_CLASS_NARROWEST_MODE (mclass) == E_VOIDmode)
783 *iter = opt_mode<T> ();
784 else
785 *iter = as_a<T> (GET_CLASS_NARROWEST_MODE (mclass));
788 inline void
789 start (machine_mode *iter, enum mode_class mclass)
791 *iter = GET_CLASS_NARROWEST_MODE (mclass);
794 /* Return true if mode iterator *ITER has not reached the end. */
796 template<typename T>
797 inline bool
798 iterate_p (opt_mode<T> *iter)
800 return iter->exists ();
803 inline bool
804 iterate_p (machine_mode *iter)
806 return *iter != E_VOIDmode;
809 /* Set mode iterator *ITER to the next widest mode in the same class,
810 if any. */
812 template<typename T>
813 inline void
814 get_wider (opt_mode<T> *iter)
816 *iter = GET_MODE_WIDER_MODE (iter->require ());
819 inline void
820 get_wider (machine_mode *iter)
822 *iter = GET_MODE_WIDER_MODE (*iter).else_void ();
825 /* Set mode iterator *ITER to the next widest mode in the same class.
826 Such a mode is known to exist. */
828 template<typename T>
829 inline void
830 get_known_wider (T *iter)
832 *iter = GET_MODE_WIDER_MODE (*iter).require ();
835 /* Set mode iterator *ITER to the mode that is two times wider than the
836 current one, if such a mode exists. */
838 inline void
839 get_2xwider (machine_mode *iter)
841 *iter = GET_MODE_2XWIDER_MODE (*iter).else_void ();
845 /* Make ITERATOR iterate over all the modes in mode class CLASS,
846 from narrowest to widest. */
847 #define FOR_EACH_MODE_IN_CLASS(ITERATOR, CLASS) \
848 for (mode_iterator::start (&(ITERATOR), CLASS); \
849 mode_iterator::iterate_p (&(ITERATOR)); \
850 mode_iterator::get_wider (&(ITERATOR)))
852 /* Make ITERATOR iterate over all the modes in the range [START, END),
853 in order of increasing width. */
854 #define FOR_EACH_MODE(ITERATOR, START, END) \
855 for ((ITERATOR) = (START); \
856 (ITERATOR) != (END); \
857 mode_iterator::get_known_wider (&(ITERATOR)))
859 /* Make ITERATOR iterate over START and all wider modes in the same
860 class, in order of increasing width. */
861 #define FOR_EACH_MODE_FROM(ITERATOR, START) \
862 for ((ITERATOR) = (START); \
863 mode_iterator::iterate_p (&(ITERATOR)); \
864 mode_iterator::get_wider (&(ITERATOR)))
866 /* Make ITERATOR iterate over modes in the range [NARROWEST, END)
867 in order of increasing width, where NARROWEST is the narrowest mode
868 in END's class. */
869 #define FOR_EACH_MODE_UNTIL(ITERATOR, END) \
870 FOR_EACH_MODE (ITERATOR, get_narrowest_mode (END), END)
872 /* Make ITERATOR iterate over modes in the same class as MODE, in order
873 of increasing width. Start at the first mode wider than START,
874 or don't iterate at all if there is no wider mode. */
875 #define FOR_EACH_WIDER_MODE(ITERATOR, START) \
876 for ((ITERATOR) = (START), mode_iterator::get_wider (&(ITERATOR)); \
877 mode_iterator::iterate_p (&(ITERATOR)); \
878 mode_iterator::get_wider (&(ITERATOR)))
880 /* Make ITERATOR iterate over modes in the same class as MODE, in order
881 of increasing width, and with each mode being twice the width of the
882 previous mode. Start at the mode that is two times wider than START,
883 or don't iterate at all if there is no such mode. */
884 #define FOR_EACH_2XWIDER_MODE(ITERATOR, START) \
885 for ((ITERATOR) = (START), mode_iterator::get_2xwider (&(ITERATOR)); \
886 mode_iterator::iterate_p (&(ITERATOR)); \
887 mode_iterator::get_2xwider (&(ITERATOR)))
889 #endif /* not HAVE_MACHINE_MODES */