re PR middle-end/91603 (Unaligned access in expand_assignment)
[official-gcc.git] / gcc / machmode.h
blob005ec80e89d273edaee9cc26e26981353b8f3476
1 /* Machine mode definitions for GCC; included by rtl.h and tree.h.
2 Copyright (C) 1991-2019 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 poly_uint16_pod mode_size[NUM_MACHINE_MODES];
26 extern CONST_MODE_PRECISION poly_uint16_pod mode_precision[NUM_MACHINE_MODES];
27 extern const unsigned char mode_inner[NUM_MACHINE_MODES];
28 extern CONST_MODE_NUNITS poly_uint16_pod 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 /* Always treat machine modes as fixed-size while compiling code specific
80 to targets that have no variable-size modes. */
81 #if defined (IN_TARGET_CODE) && NUM_POLY_INT_COEFFS == 1
82 #define ONLY_FIXED_SIZE_MODES 1
83 #else
84 #define ONLY_FIXED_SIZE_MODES 0
85 #endif
87 /* Get the name of mode MODE as a string. */
89 extern const char * const mode_name[NUM_MACHINE_MODES];
90 #define GET_MODE_NAME(MODE) mode_name[MODE]
92 /* Mode classes. */
94 #include "mode-classes.def"
95 #define DEF_MODE_CLASS(M) M
96 enum mode_class { MODE_CLASSES, MAX_MODE_CLASS };
97 #undef DEF_MODE_CLASS
98 #undef MODE_CLASSES
100 /* Get the general kind of object that mode MODE represents
101 (integer, floating, complex, etc.) */
103 extern const unsigned char mode_class[NUM_MACHINE_MODES];
104 #define GET_MODE_CLASS(MODE) ((enum mode_class) mode_class[MODE])
106 /* Nonzero if MODE is an integral mode. */
107 #define INTEGRAL_MODE_P(MODE) \
108 (GET_MODE_CLASS (MODE) == MODE_INT \
109 || GET_MODE_CLASS (MODE) == MODE_PARTIAL_INT \
110 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_INT \
111 || GET_MODE_CLASS (MODE) == MODE_VECTOR_BOOL \
112 || GET_MODE_CLASS (MODE) == MODE_VECTOR_INT)
114 /* Nonzero if MODE is a floating-point mode. */
115 #define FLOAT_MODE_P(MODE) \
116 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
117 || GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT \
118 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT \
119 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT)
121 /* Nonzero if MODE is a complex mode. */
122 #define COMPLEX_MODE_P(MODE) \
123 (GET_MODE_CLASS (MODE) == MODE_COMPLEX_INT \
124 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT)
126 /* Nonzero if MODE is a vector mode. */
127 #define VECTOR_MODE_P(MODE) \
128 (GET_MODE_CLASS (MODE) == MODE_VECTOR_BOOL \
129 || GET_MODE_CLASS (MODE) == MODE_VECTOR_INT \
130 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT \
131 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FRACT \
132 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UFRACT \
133 || GET_MODE_CLASS (MODE) == MODE_VECTOR_ACCUM \
134 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UACCUM)
136 /* Nonzero if MODE is a scalar integral mode. */
137 #define SCALAR_INT_MODE_P(MODE) \
138 (GET_MODE_CLASS (MODE) == MODE_INT \
139 || GET_MODE_CLASS (MODE) == MODE_PARTIAL_INT)
141 /* Nonzero if MODE is a scalar floating point mode. */
142 #define SCALAR_FLOAT_MODE_P(MODE) \
143 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
144 || GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT)
146 /* Nonzero if MODE is a decimal floating point mode. */
147 #define DECIMAL_FLOAT_MODE_P(MODE) \
148 (GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT)
150 /* Nonzero if MODE is a scalar fract mode. */
151 #define SCALAR_FRACT_MODE_P(MODE) \
152 (GET_MODE_CLASS (MODE) == MODE_FRACT)
154 /* Nonzero if MODE is a scalar ufract mode. */
155 #define SCALAR_UFRACT_MODE_P(MODE) \
156 (GET_MODE_CLASS (MODE) == MODE_UFRACT)
158 /* Nonzero if MODE is a scalar fract or ufract mode. */
159 #define ALL_SCALAR_FRACT_MODE_P(MODE) \
160 (SCALAR_FRACT_MODE_P (MODE) || SCALAR_UFRACT_MODE_P (MODE))
162 /* Nonzero if MODE is a scalar accum mode. */
163 #define SCALAR_ACCUM_MODE_P(MODE) \
164 (GET_MODE_CLASS (MODE) == MODE_ACCUM)
166 /* Nonzero if MODE is a scalar uaccum mode. */
167 #define SCALAR_UACCUM_MODE_P(MODE) \
168 (GET_MODE_CLASS (MODE) == MODE_UACCUM)
170 /* Nonzero if MODE is a scalar accum or uaccum mode. */
171 #define ALL_SCALAR_ACCUM_MODE_P(MODE) \
172 (SCALAR_ACCUM_MODE_P (MODE) || SCALAR_UACCUM_MODE_P (MODE))
174 /* Nonzero if MODE is a scalar fract or accum mode. */
175 #define SIGNED_SCALAR_FIXED_POINT_MODE_P(MODE) \
176 (SCALAR_FRACT_MODE_P (MODE) || SCALAR_ACCUM_MODE_P (MODE))
178 /* Nonzero if MODE is a scalar ufract or uaccum mode. */
179 #define UNSIGNED_SCALAR_FIXED_POINT_MODE_P(MODE) \
180 (SCALAR_UFRACT_MODE_P (MODE) || SCALAR_UACCUM_MODE_P (MODE))
182 /* Nonzero if MODE is a scalar fract, ufract, accum or uaccum mode. */
183 #define ALL_SCALAR_FIXED_POINT_MODE_P(MODE) \
184 (SIGNED_SCALAR_FIXED_POINT_MODE_P (MODE) \
185 || UNSIGNED_SCALAR_FIXED_POINT_MODE_P (MODE))
187 /* Nonzero if MODE is a scalar/vector fract mode. */
188 #define FRACT_MODE_P(MODE) \
189 (GET_MODE_CLASS (MODE) == MODE_FRACT \
190 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FRACT)
192 /* Nonzero if MODE is a scalar/vector ufract mode. */
193 #define UFRACT_MODE_P(MODE) \
194 (GET_MODE_CLASS (MODE) == MODE_UFRACT \
195 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UFRACT)
197 /* Nonzero if MODE is a scalar/vector fract or ufract mode. */
198 #define ALL_FRACT_MODE_P(MODE) \
199 (FRACT_MODE_P (MODE) || UFRACT_MODE_P (MODE))
201 /* Nonzero if MODE is a scalar/vector accum mode. */
202 #define ACCUM_MODE_P(MODE) \
203 (GET_MODE_CLASS (MODE) == MODE_ACCUM \
204 || GET_MODE_CLASS (MODE) == MODE_VECTOR_ACCUM)
206 /* Nonzero if MODE is a scalar/vector uaccum mode. */
207 #define UACCUM_MODE_P(MODE) \
208 (GET_MODE_CLASS (MODE) == MODE_UACCUM \
209 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UACCUM)
211 /* Nonzero if MODE is a scalar/vector accum or uaccum mode. */
212 #define ALL_ACCUM_MODE_P(MODE) \
213 (ACCUM_MODE_P (MODE) || UACCUM_MODE_P (MODE))
215 /* Nonzero if MODE is a scalar/vector fract or accum mode. */
216 #define SIGNED_FIXED_POINT_MODE_P(MODE) \
217 (FRACT_MODE_P (MODE) || ACCUM_MODE_P (MODE))
219 /* Nonzero if MODE is a scalar/vector ufract or uaccum mode. */
220 #define UNSIGNED_FIXED_POINT_MODE_P(MODE) \
221 (UFRACT_MODE_P (MODE) || UACCUM_MODE_P (MODE))
223 /* Nonzero if MODE is a scalar/vector fract, ufract, accum or uaccum mode. */
224 #define ALL_FIXED_POINT_MODE_P(MODE) \
225 (SIGNED_FIXED_POINT_MODE_P (MODE) \
226 || UNSIGNED_FIXED_POINT_MODE_P (MODE))
228 /* Nonzero if CLASS modes can be widened. */
229 #define CLASS_HAS_WIDER_MODES_P(CLASS) \
230 (CLASS == MODE_INT \
231 || CLASS == MODE_PARTIAL_INT \
232 || CLASS == MODE_FLOAT \
233 || CLASS == MODE_DECIMAL_FLOAT \
234 || CLASS == MODE_COMPLEX_FLOAT \
235 || CLASS == MODE_FRACT \
236 || CLASS == MODE_UFRACT \
237 || CLASS == MODE_ACCUM \
238 || CLASS == MODE_UACCUM)
240 /* An optional T (i.e. a T or nothing), where T is some form of mode class. */
241 template<typename T>
242 class opt_mode
244 public:
245 enum from_int { dummy = MAX_MACHINE_MODE };
247 ALWAYS_INLINE opt_mode () : m_mode (E_VOIDmode) {}
248 ALWAYS_INLINE opt_mode (const T &m) : m_mode (m) {}
249 template<typename U>
250 ALWAYS_INLINE opt_mode (const U &m) : m_mode (T (m)) {}
251 ALWAYS_INLINE opt_mode (from_int m) : m_mode (machine_mode (m)) {}
253 machine_mode else_void () const;
254 machine_mode else_blk () const { return else_mode (BLKmode); }
255 machine_mode else_mode (machine_mode) const;
256 T require () const;
258 bool exists () const;
259 template<typename U> bool exists (U *) const;
261 private:
262 machine_mode m_mode;
265 /* If the object contains a T, return its enum value, otherwise return
266 E_VOIDmode. */
268 template<typename T>
269 ALWAYS_INLINE machine_mode
270 opt_mode<T>::else_void () const
272 return m_mode;
275 /* If the T exists, return its enum value, otherwise return FALLBACK. */
277 template<typename T>
278 inline machine_mode
279 opt_mode<T>::else_mode (machine_mode fallback) const
281 return m_mode == E_VOIDmode ? fallback : m_mode;
284 /* Assert that the object contains a T and return it. */
286 template<typename T>
287 inline T
288 opt_mode<T>::require () const
290 gcc_checking_assert (m_mode != E_VOIDmode);
291 return typename mode_traits<T>::from_int (m_mode);
294 /* Return true if the object contains a T rather than nothing. */
296 template<typename T>
297 ALWAYS_INLINE bool
298 opt_mode<T>::exists () const
300 return m_mode != E_VOIDmode;
303 /* Return true if the object contains a T, storing it in *MODE if so. */
305 template<typename T>
306 template<typename U>
307 inline bool
308 opt_mode<T>::exists (U *mode) const
310 if (m_mode != E_VOIDmode)
312 *mode = T (typename mode_traits<T>::from_int (m_mode));
313 return true;
315 return false;
318 /* A POD version of mode class T. */
320 template<typename T>
321 struct pod_mode
323 typedef typename mode_traits<T>::from_int from_int;
324 typedef typename T::measurement_type measurement_type;
326 machine_mode m_mode;
327 ALWAYS_INLINE operator machine_mode () const { return m_mode; }
328 ALWAYS_INLINE operator T () const { return from_int (m_mode); }
329 ALWAYS_INLINE pod_mode &operator = (const T &m) { m_mode = m; return *this; }
332 /* Return true if mode M has type T. */
334 template<typename T>
335 inline bool
336 is_a (machine_mode m)
338 return T::includes_p (m);
341 template<typename T, typename U>
342 inline bool
343 is_a (const opt_mode<U> &m)
345 return T::includes_p (m.else_void ());
348 /* Assert that mode M has type T, and return it in that form. */
350 template<typename T>
351 inline T
352 as_a (machine_mode m)
354 gcc_checking_assert (T::includes_p (m));
355 return typename mode_traits<T>::from_int (m);
358 template<typename T, typename U>
359 inline T
360 as_a (const opt_mode<U> &m)
362 return as_a <T> (m.else_void ());
365 /* Convert M to an opt_mode<T>. */
367 template<typename T>
368 inline opt_mode<T>
369 dyn_cast (machine_mode m)
371 if (T::includes_p (m))
372 return T (typename mode_traits<T>::from_int (m));
373 return opt_mode<T> ();
376 template<typename T, typename U>
377 inline opt_mode<T>
378 dyn_cast (const opt_mode<U> &m)
380 return dyn_cast <T> (m.else_void ());
383 /* Return true if mode M has type T, storing it as a T in *RESULT
384 if so. */
386 template<typename T, typename U>
387 inline bool
388 is_a (machine_mode m, U *result)
390 if (T::includes_p (m))
392 *result = T (typename mode_traits<T>::from_int (m));
393 return true;
395 return false;
398 /* Represents a machine mode that is known to be a SCALAR_INT_MODE_P. */
399 class scalar_int_mode
401 public:
402 typedef mode_traits<scalar_int_mode>::from_int from_int;
403 typedef unsigned short measurement_type;
405 ALWAYS_INLINE scalar_int_mode () {}
406 ALWAYS_INLINE scalar_int_mode (from_int m) : m_mode (machine_mode (m)) {}
407 ALWAYS_INLINE operator machine_mode () const { return m_mode; }
409 static bool includes_p (machine_mode);
411 protected:
412 machine_mode m_mode;
415 /* Return true if M is a scalar_int_mode. */
417 inline bool
418 scalar_int_mode::includes_p (machine_mode m)
420 return SCALAR_INT_MODE_P (m);
423 /* Represents a machine mode that is known to be a SCALAR_FLOAT_MODE_P. */
424 class scalar_float_mode
426 public:
427 typedef mode_traits<scalar_float_mode>::from_int from_int;
428 typedef unsigned short measurement_type;
430 ALWAYS_INLINE scalar_float_mode () {}
431 ALWAYS_INLINE scalar_float_mode (from_int m) : m_mode (machine_mode (m)) {}
432 ALWAYS_INLINE operator machine_mode () const { return m_mode; }
434 static bool includes_p (machine_mode);
436 protected:
437 machine_mode m_mode;
440 /* Return true if M is a scalar_float_mode. */
442 inline bool
443 scalar_float_mode::includes_p (machine_mode m)
445 return SCALAR_FLOAT_MODE_P (m);
448 /* Represents a machine mode that is known to be scalar. */
449 class scalar_mode
451 public:
452 typedef mode_traits<scalar_mode>::from_int from_int;
453 typedef unsigned short measurement_type;
455 ALWAYS_INLINE scalar_mode () {}
456 ALWAYS_INLINE scalar_mode (from_int m) : m_mode (machine_mode (m)) {}
457 ALWAYS_INLINE scalar_mode (const scalar_int_mode &m) : m_mode (m) {}
458 ALWAYS_INLINE scalar_mode (const scalar_float_mode &m) : m_mode (m) {}
459 ALWAYS_INLINE scalar_mode (const scalar_int_mode_pod &m) : m_mode (m) {}
460 ALWAYS_INLINE operator machine_mode () const { return m_mode; }
462 static bool includes_p (machine_mode);
464 protected:
465 machine_mode m_mode;
468 /* Return true if M represents some kind of scalar value. */
470 inline bool
471 scalar_mode::includes_p (machine_mode m)
473 switch (GET_MODE_CLASS (m))
475 case MODE_INT:
476 case MODE_PARTIAL_INT:
477 case MODE_FRACT:
478 case MODE_UFRACT:
479 case MODE_ACCUM:
480 case MODE_UACCUM:
481 case MODE_FLOAT:
482 case MODE_DECIMAL_FLOAT:
483 return true;
484 default:
485 return false;
489 /* Represents a machine mode that is known to be a COMPLEX_MODE_P. */
490 class complex_mode
492 public:
493 typedef mode_traits<complex_mode>::from_int from_int;
494 typedef unsigned short measurement_type;
496 ALWAYS_INLINE complex_mode () {}
497 ALWAYS_INLINE complex_mode (from_int m) : m_mode (machine_mode (m)) {}
498 ALWAYS_INLINE operator machine_mode () const { return m_mode; }
500 static bool includes_p (machine_mode);
502 protected:
503 machine_mode m_mode;
506 /* Return true if M is a complex_mode. */
508 inline bool
509 complex_mode::includes_p (machine_mode m)
511 return COMPLEX_MODE_P (m);
514 /* Return the base GET_MODE_SIZE value for MODE. */
516 ALWAYS_INLINE poly_uint16
517 mode_to_bytes (machine_mode mode)
519 #if GCC_VERSION >= 4001
520 return (__builtin_constant_p (mode)
521 ? mode_size_inline (mode) : mode_size[mode]);
522 #else
523 return mode_size[mode];
524 #endif
527 /* Return the base GET_MODE_BITSIZE value for MODE. */
529 ALWAYS_INLINE poly_uint16
530 mode_to_bits (machine_mode mode)
532 return mode_to_bytes (mode) * BITS_PER_UNIT;
535 /* Return the base GET_MODE_PRECISION value for MODE. */
537 ALWAYS_INLINE poly_uint16
538 mode_to_precision (machine_mode mode)
540 return mode_precision[mode];
543 /* Return the base GET_MODE_INNER value for MODE. */
545 ALWAYS_INLINE scalar_mode
546 mode_to_inner (machine_mode mode)
548 #if GCC_VERSION >= 4001
549 return scalar_mode::from_int (__builtin_constant_p (mode)
550 ? mode_inner_inline (mode)
551 : mode_inner[mode]);
552 #else
553 return scalar_mode::from_int (mode_inner[mode]);
554 #endif
557 /* Return the base GET_MODE_UNIT_SIZE value for MODE. */
559 ALWAYS_INLINE unsigned char
560 mode_to_unit_size (machine_mode mode)
562 #if GCC_VERSION >= 4001
563 return (__builtin_constant_p (mode)
564 ? mode_unit_size_inline (mode) : mode_unit_size[mode]);
565 #else
566 return mode_unit_size[mode];
567 #endif
570 /* Return the base GET_MODE_UNIT_PRECISION value for MODE. */
572 ALWAYS_INLINE unsigned short
573 mode_to_unit_precision (machine_mode mode)
575 #if GCC_VERSION >= 4001
576 return (__builtin_constant_p (mode)
577 ? mode_unit_precision_inline (mode) : mode_unit_precision[mode]);
578 #else
579 return mode_unit_precision[mode];
580 #endif
583 /* Return the base GET_MODE_NUNITS value for MODE. */
585 ALWAYS_INLINE poly_uint16
586 mode_to_nunits (machine_mode mode)
588 #if GCC_VERSION >= 4001
589 return (__builtin_constant_p (mode)
590 ? mode_nunits_inline (mode) : mode_nunits[mode]);
591 #else
592 return mode_nunits[mode];
593 #endif
596 /* Get the size in bytes of an object of mode MODE. */
598 #if ONLY_FIXED_SIZE_MODES
599 #define GET_MODE_SIZE(MODE) ((unsigned short) mode_to_bytes (MODE).coeffs[0])
600 #else
601 ALWAYS_INLINE poly_uint16
602 GET_MODE_SIZE (machine_mode mode)
604 return mode_to_bytes (mode);
607 template<typename T>
608 ALWAYS_INLINE typename if_poly<typename T::measurement_type>::type
609 GET_MODE_SIZE (const T &mode)
611 return mode_to_bytes (mode);
614 template<typename T>
615 ALWAYS_INLINE typename if_nonpoly<typename T::measurement_type>::type
616 GET_MODE_SIZE (const T &mode)
618 return mode_to_bytes (mode).coeffs[0];
620 #endif
622 /* Get the size in bits of an object of mode MODE. */
624 #if ONLY_FIXED_SIZE_MODES
625 #define GET_MODE_BITSIZE(MODE) ((unsigned short) mode_to_bits (MODE).coeffs[0])
626 #else
627 ALWAYS_INLINE poly_uint16
628 GET_MODE_BITSIZE (machine_mode mode)
630 return mode_to_bits (mode);
633 template<typename T>
634 ALWAYS_INLINE typename if_poly<typename T::measurement_type>::type
635 GET_MODE_BITSIZE (const T &mode)
637 return mode_to_bits (mode);
640 template<typename T>
641 ALWAYS_INLINE typename if_nonpoly<typename T::measurement_type>::type
642 GET_MODE_BITSIZE (const T &mode)
644 return mode_to_bits (mode).coeffs[0];
646 #endif
648 /* Get the number of value bits of an object of mode MODE. */
650 #if ONLY_FIXED_SIZE_MODES
651 #define GET_MODE_PRECISION(MODE) \
652 ((unsigned short) mode_to_precision (MODE).coeffs[0])
653 #else
654 ALWAYS_INLINE poly_uint16
655 GET_MODE_PRECISION (machine_mode mode)
657 return mode_to_precision (mode);
660 template<typename T>
661 ALWAYS_INLINE typename if_poly<typename T::measurement_type>::type
662 GET_MODE_PRECISION (const T &mode)
664 return mode_to_precision (mode);
667 template<typename T>
668 ALWAYS_INLINE typename if_nonpoly<typename T::measurement_type>::type
669 GET_MODE_PRECISION (const T &mode)
671 return mode_to_precision (mode).coeffs[0];
673 #endif
675 /* Get the number of integral bits of an object of mode MODE. */
676 extern CONST_MODE_IBIT unsigned char mode_ibit[NUM_MACHINE_MODES];
677 #define GET_MODE_IBIT(MODE) mode_ibit[MODE]
679 /* Get the number of fractional bits of an object of mode MODE. */
680 extern CONST_MODE_FBIT unsigned char mode_fbit[NUM_MACHINE_MODES];
681 #define GET_MODE_FBIT(MODE) mode_fbit[MODE]
683 /* Get a bitmask containing 1 for all bits in a word
684 that fit within mode MODE. */
686 extern const unsigned HOST_WIDE_INT mode_mask_array[NUM_MACHINE_MODES];
688 #define GET_MODE_MASK(MODE) mode_mask_array[MODE]
690 /* Return the mode of the basic parts of MODE. For vector modes this is the
691 mode of the vector elements. For complex modes it is the mode of the real
692 and imaginary parts. For other modes it is MODE itself. */
694 #define GET_MODE_INNER(MODE) (mode_to_inner (MODE))
696 /* Get the size in bytes or bits of the basic parts of an
697 object of mode MODE. */
699 #define GET_MODE_UNIT_SIZE(MODE) mode_to_unit_size (MODE)
701 #define GET_MODE_UNIT_BITSIZE(MODE) \
702 ((unsigned short) (GET_MODE_UNIT_SIZE (MODE) * BITS_PER_UNIT))
704 #define GET_MODE_UNIT_PRECISION(MODE) (mode_to_unit_precision (MODE))
706 /* Get the number of units in an object of mode MODE. This is 2 for
707 complex modes and the number of elements for vector modes. */
709 #if ONLY_FIXED_SIZE_MODES
710 #define GET_MODE_NUNITS(MODE) (mode_to_nunits (MODE).coeffs[0])
711 #else
712 ALWAYS_INLINE poly_uint16
713 GET_MODE_NUNITS (machine_mode mode)
715 return mode_to_nunits (mode);
718 template<typename T>
719 ALWAYS_INLINE typename if_poly<typename T::measurement_type>::type
720 GET_MODE_NUNITS (const T &mode)
722 return mode_to_nunits (mode);
725 template<typename T>
726 ALWAYS_INLINE typename if_nonpoly<typename T::measurement_type>::type
727 GET_MODE_NUNITS (const T &mode)
729 return mode_to_nunits (mode).coeffs[0];
731 #endif
733 /* Get the next wider natural mode (eg, QI -> HI -> SI -> DI -> TI). */
735 template<typename T>
736 ALWAYS_INLINE opt_mode<T>
737 GET_MODE_WIDER_MODE (const T &m)
739 return typename opt_mode<T>::from_int (mode_wider[m]);
742 /* For scalars, this is a mode with twice the precision. For vectors,
743 this is a mode with the same inner mode but with twice the elements. */
745 template<typename T>
746 ALWAYS_INLINE opt_mode<T>
747 GET_MODE_2XWIDER_MODE (const T &m)
749 return typename opt_mode<T>::from_int (mode_2xwider[m]);
752 /* Get the complex mode from the component mode. */
753 extern const unsigned char mode_complex[NUM_MACHINE_MODES];
754 #define GET_MODE_COMPLEX_MODE(MODE) ((machine_mode) mode_complex[MODE])
756 /* Represents a machine mode that must have a fixed size. The main
757 use of this class is to represent the modes of objects that always
758 have static storage duration, such as constant pool entries.
759 (No current target supports the concept of variable-size static data.) */
760 class fixed_size_mode
762 public:
763 typedef mode_traits<fixed_size_mode>::from_int from_int;
764 typedef unsigned short measurement_type;
766 ALWAYS_INLINE fixed_size_mode () {}
767 ALWAYS_INLINE fixed_size_mode (from_int m) : m_mode (machine_mode (m)) {}
768 ALWAYS_INLINE fixed_size_mode (const scalar_mode &m) : m_mode (m) {}
769 ALWAYS_INLINE fixed_size_mode (const scalar_int_mode &m) : m_mode (m) {}
770 ALWAYS_INLINE fixed_size_mode (const scalar_float_mode &m) : m_mode (m) {}
771 ALWAYS_INLINE fixed_size_mode (const scalar_mode_pod &m) : m_mode (m) {}
772 ALWAYS_INLINE fixed_size_mode (const scalar_int_mode_pod &m) : m_mode (m) {}
773 ALWAYS_INLINE fixed_size_mode (const complex_mode &m) : m_mode (m) {}
774 ALWAYS_INLINE operator machine_mode () const { return m_mode; }
776 static bool includes_p (machine_mode);
778 protected:
779 machine_mode m_mode;
782 /* Return true if MODE has a fixed size. */
784 inline bool
785 fixed_size_mode::includes_p (machine_mode mode)
787 return mode_to_bytes (mode).is_constant ();
790 /* Wrapper for mode arguments to target macros, so that if a target
791 doesn't need polynomial-sized modes, its header file can continue
792 to treat everything as fixed_size_mode. This should go away once
793 macros are moved to target hooks. It shouldn't be used in other
794 contexts. */
795 #if NUM_POLY_INT_COEFFS == 1
796 #define MACRO_MODE(MODE) (as_a <fixed_size_mode> (MODE))
797 #else
798 #define MACRO_MODE(MODE) (MODE)
799 #endif
801 extern opt_machine_mode mode_for_size (poly_uint64, enum mode_class, int);
803 /* Return the machine mode to use for a MODE_INT of SIZE bits, if one
804 exists. If LIMIT is nonzero, modes wider than MAX_FIXED_MODE_SIZE
805 will not be used. */
807 inline opt_scalar_int_mode
808 int_mode_for_size (poly_uint64 size, int limit)
810 return dyn_cast <scalar_int_mode> (mode_for_size (size, MODE_INT, limit));
813 /* Return the machine mode to use for a MODE_FLOAT of SIZE bits, if one
814 exists. */
816 inline opt_scalar_float_mode
817 float_mode_for_size (poly_uint64 size)
819 return dyn_cast <scalar_float_mode> (mode_for_size (size, MODE_FLOAT, 0));
822 /* Likewise for MODE_DECIMAL_FLOAT. */
824 inline opt_scalar_float_mode
825 decimal_float_mode_for_size (unsigned int size)
827 return dyn_cast <scalar_float_mode>
828 (mode_for_size (size, MODE_DECIMAL_FLOAT, 0));
831 extern machine_mode smallest_mode_for_size (poly_uint64, enum mode_class);
833 /* Find the narrowest integer mode that contains at least SIZE bits.
834 Such a mode must exist. */
836 inline scalar_int_mode
837 smallest_int_mode_for_size (poly_uint64 size)
839 return as_a <scalar_int_mode> (smallest_mode_for_size (size, MODE_INT));
842 extern opt_scalar_int_mode int_mode_for_mode (machine_mode);
843 extern opt_machine_mode bitwise_mode_for_mode (machine_mode);
844 extern opt_machine_mode mode_for_vector (scalar_mode, poly_uint64);
845 extern opt_machine_mode mode_for_int_vector (unsigned int, poly_uint64);
847 /* Return the integer vector equivalent of MODE, if one exists. In other
848 words, return the mode for an integer vector that has the same number
849 of bits as MODE and the same number of elements as MODE, with the
850 latter being 1 if MODE is scalar. The returned mode can be either
851 an integer mode or a vector mode. */
853 inline opt_machine_mode
854 mode_for_int_vector (machine_mode mode)
856 return mode_for_int_vector (GET_MODE_UNIT_BITSIZE (mode),
857 GET_MODE_NUNITS (mode));
860 /* A class for iterating through possible bitfield modes. */
861 class bit_field_mode_iterator
863 public:
864 bit_field_mode_iterator (HOST_WIDE_INT, HOST_WIDE_INT,
865 poly_int64, poly_int64,
866 unsigned int, bool);
867 bool next_mode (scalar_int_mode *);
868 bool prefer_smaller_modes ();
870 private:
871 opt_scalar_int_mode m_mode;
872 /* We use signed values here because the bit position can be negative
873 for invalid input such as gcc.dg/pr48335-8.c. */
874 HOST_WIDE_INT m_bitsize;
875 HOST_WIDE_INT m_bitpos;
876 poly_int64 m_bitregion_start;
877 poly_int64 m_bitregion_end;
878 unsigned int m_align;
879 bool m_volatilep;
880 int m_count;
883 /* Find the best mode to use to access a bit field. */
885 extern bool get_best_mode (int, int, poly_uint64, poly_uint64, unsigned int,
886 unsigned HOST_WIDE_INT, bool, scalar_int_mode *);
888 /* Determine alignment, 1<=result<=BIGGEST_ALIGNMENT. */
890 extern CONST_MODE_BASE_ALIGN unsigned short mode_base_align[NUM_MACHINE_MODES];
892 extern unsigned get_mode_alignment (machine_mode);
894 #define GET_MODE_ALIGNMENT(MODE) get_mode_alignment (MODE)
896 /* For each class, get the narrowest mode in that class. */
898 extern const unsigned char class_narrowest_mode[MAX_MODE_CLASS];
899 #define GET_CLASS_NARROWEST_MODE(CLASS) \
900 ((machine_mode) class_narrowest_mode[CLASS])
902 /* The narrowest full integer mode available on the target. */
904 #define NARROWEST_INT_MODE \
905 (scalar_int_mode \
906 (scalar_int_mode::from_int (class_narrowest_mode[MODE_INT])))
908 /* Return the narrowest mode in T's class. */
910 template<typename T>
911 inline T
912 get_narrowest_mode (T mode)
914 return typename mode_traits<T>::from_int
915 (class_narrowest_mode[GET_MODE_CLASS (mode)]);
918 /* Define the integer modes whose sizes are BITS_PER_UNIT and BITS_PER_WORD
919 and the mode whose class is Pmode and whose size is POINTER_SIZE. */
921 extern scalar_int_mode byte_mode;
922 extern scalar_int_mode word_mode;
923 extern scalar_int_mode ptr_mode;
925 /* Target-dependent machine mode initialization - in insn-modes.c. */
926 extern void init_adjust_machine_modes (void);
928 #define TRULY_NOOP_TRUNCATION_MODES_P(MODE1, MODE2) \
929 (targetm.truly_noop_truncation (GET_MODE_PRECISION (MODE1), \
930 GET_MODE_PRECISION (MODE2)))
932 /* Return true if MODE is a scalar integer mode that fits in a
933 HOST_WIDE_INT. */
935 inline bool
936 HWI_COMPUTABLE_MODE_P (machine_mode mode)
938 machine_mode mme = mode;
939 return (SCALAR_INT_MODE_P (mme)
940 && mode_to_precision (mme).coeffs[0] <= HOST_BITS_PER_WIDE_INT);
943 inline bool
944 HWI_COMPUTABLE_MODE_P (scalar_int_mode mode)
946 return GET_MODE_PRECISION (mode) <= HOST_BITS_PER_WIDE_INT;
949 struct int_n_data_t {
950 /* These parts are initailized by genmodes output */
951 unsigned int bitsize;
952 scalar_int_mode_pod m;
953 /* RID_* is RID_INTN_BASE + index into this array */
956 /* This is also in tree.h. genmodes.c guarantees the're sorted from
957 smallest bitsize to largest bitsize. */
958 extern bool int_n_enabled_p[NUM_INT_N_ENTS];
959 extern const int_n_data_t int_n_data[NUM_INT_N_ENTS];
961 /* Return true if MODE has class MODE_INT, storing it as a scalar_int_mode
962 in *INT_MODE if so. */
964 template<typename T>
965 inline bool
966 is_int_mode (machine_mode mode, T *int_mode)
968 if (GET_MODE_CLASS (mode) == MODE_INT)
970 *int_mode = scalar_int_mode (scalar_int_mode::from_int (mode));
971 return true;
973 return false;
976 /* Return true if MODE has class MODE_FLOAT, storing it as a
977 scalar_float_mode in *FLOAT_MODE if so. */
979 template<typename T>
980 inline bool
981 is_float_mode (machine_mode mode, T *float_mode)
983 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
985 *float_mode = scalar_float_mode (scalar_float_mode::from_int (mode));
986 return true;
988 return false;
991 /* Return true if MODE has class MODE_COMPLEX_INT, storing it as
992 a complex_mode in *CMODE if so. */
994 template<typename T>
995 inline bool
996 is_complex_int_mode (machine_mode mode, T *cmode)
998 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
1000 *cmode = complex_mode (complex_mode::from_int (mode));
1001 return true;
1003 return false;
1006 /* Return true if MODE has class MODE_COMPLEX_FLOAT, storing it as
1007 a complex_mode in *CMODE if so. */
1009 template<typename T>
1010 inline bool
1011 is_complex_float_mode (machine_mode mode, T *cmode)
1013 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
1015 *cmode = complex_mode (complex_mode::from_int (mode));
1016 return true;
1018 return false;
1021 /* Return true if MODE is a scalar integer mode with a precision
1022 smaller than LIMIT's precision. */
1024 inline bool
1025 is_narrower_int_mode (machine_mode mode, scalar_int_mode limit)
1027 scalar_int_mode int_mode;
1028 return (is_a <scalar_int_mode> (mode, &int_mode)
1029 && GET_MODE_PRECISION (int_mode) < GET_MODE_PRECISION (limit));
1032 namespace mode_iterator
1034 /* Start mode iterator *ITER at the first mode in class MCLASS, if any. */
1036 template<typename T>
1037 inline void
1038 start (opt_mode<T> *iter, enum mode_class mclass)
1040 if (GET_CLASS_NARROWEST_MODE (mclass) == E_VOIDmode)
1041 *iter = opt_mode<T> ();
1042 else
1043 *iter = as_a<T> (GET_CLASS_NARROWEST_MODE (mclass));
1046 inline void
1047 start (machine_mode *iter, enum mode_class mclass)
1049 *iter = GET_CLASS_NARROWEST_MODE (mclass);
1052 /* Return true if mode iterator *ITER has not reached the end. */
1054 template<typename T>
1055 inline bool
1056 iterate_p (opt_mode<T> *iter)
1058 return iter->exists ();
1061 inline bool
1062 iterate_p (machine_mode *iter)
1064 return *iter != E_VOIDmode;
1067 /* Set mode iterator *ITER to the next widest mode in the same class,
1068 if any. */
1070 template<typename T>
1071 inline void
1072 get_wider (opt_mode<T> *iter)
1074 *iter = GET_MODE_WIDER_MODE (iter->require ());
1077 inline void
1078 get_wider (machine_mode *iter)
1080 *iter = GET_MODE_WIDER_MODE (*iter).else_void ();
1083 /* Set mode iterator *ITER to the next widest mode in the same class.
1084 Such a mode is known to exist. */
1086 template<typename T>
1087 inline void
1088 get_known_wider (T *iter)
1090 *iter = GET_MODE_WIDER_MODE (*iter).require ();
1093 /* Set mode iterator *ITER to the mode that is two times wider than the
1094 current one, if such a mode exists. */
1096 template<typename T>
1097 inline void
1098 get_2xwider (opt_mode<T> *iter)
1100 *iter = GET_MODE_2XWIDER_MODE (iter->require ());
1103 inline void
1104 get_2xwider (machine_mode *iter)
1106 *iter = GET_MODE_2XWIDER_MODE (*iter).else_void ();
1110 /* Make ITERATOR iterate over all the modes in mode class CLASS,
1111 from narrowest to widest. */
1112 #define FOR_EACH_MODE_IN_CLASS(ITERATOR, CLASS) \
1113 for (mode_iterator::start (&(ITERATOR), CLASS); \
1114 mode_iterator::iterate_p (&(ITERATOR)); \
1115 mode_iterator::get_wider (&(ITERATOR)))
1117 /* Make ITERATOR iterate over all the modes in the range [START, END),
1118 in order of increasing width. */
1119 #define FOR_EACH_MODE(ITERATOR, START, END) \
1120 for ((ITERATOR) = (START); \
1121 (ITERATOR) != (END); \
1122 mode_iterator::get_known_wider (&(ITERATOR)))
1124 /* Make ITERATOR iterate over START and all wider modes in the same
1125 class, in order of increasing width. */
1126 #define FOR_EACH_MODE_FROM(ITERATOR, START) \
1127 for ((ITERATOR) = (START); \
1128 mode_iterator::iterate_p (&(ITERATOR)); \
1129 mode_iterator::get_wider (&(ITERATOR)))
1131 /* Make ITERATOR iterate over modes in the range [NARROWEST, END)
1132 in order of increasing width, where NARROWEST is the narrowest mode
1133 in END's class. */
1134 #define FOR_EACH_MODE_UNTIL(ITERATOR, END) \
1135 FOR_EACH_MODE (ITERATOR, get_narrowest_mode (END), END)
1137 /* Make ITERATOR iterate over modes in the same class as MODE, in order
1138 of increasing width. Start at the first mode wider than START,
1139 or don't iterate at all if there is no wider mode. */
1140 #define FOR_EACH_WIDER_MODE(ITERATOR, START) \
1141 for ((ITERATOR) = (START), mode_iterator::get_wider (&(ITERATOR)); \
1142 mode_iterator::iterate_p (&(ITERATOR)); \
1143 mode_iterator::get_wider (&(ITERATOR)))
1145 /* Make ITERATOR iterate over modes in the same class as MODE, in order
1146 of increasing width, and with each mode being twice the width of the
1147 previous mode. Start at the mode that is two times wider than START,
1148 or don't iterate at all if there is no such mode. */
1149 #define FOR_EACH_2XWIDER_MODE(ITERATOR, START) \
1150 for ((ITERATOR) = (START), mode_iterator::get_2xwider (&(ITERATOR)); \
1151 mode_iterator::iterate_p (&(ITERATOR)); \
1152 mode_iterator::get_2xwider (&(ITERATOR)))
1154 template<typename T>
1155 void
1156 gt_ggc_mx (pod_mode<T> *)
1160 template<typename T>
1161 void
1162 gt_pch_nx (pod_mode<T> *)
1166 template<typename T>
1167 void
1168 gt_pch_nx (pod_mode<T> *, void (*) (void *, void *), void *)
1172 #endif /* not HAVE_MACHINE_MODES */