1 /* Machine mode definitions for GCC; included by rtl.h and tree.h.
2 Copyright (C) 1991-2023 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
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
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_next
[NUM_MACHINE_MODES
];
32 extern const unsigned char mode_wider
[NUM_MACHINE_MODES
];
33 extern const unsigned char mode_2xwider
[NUM_MACHINE_MODES
];
38 /* For use by the machmode support code only.
40 There are cases in which the machmode support code needs to forcibly
41 convert a machine_mode to a specific mode class T, and in which the
42 context guarantees that this is valid without the need for an assert.
43 This can be done using:
45 return typename mode_traits<T>::from_int (mode);
47 when returning a T and:
49 res = T (typename mode_traits<T>::from_int (mode));
51 when assigning to a value RES that must be assignment-compatible
52 with (but possibly not the same as) T. */
54 /* Allow direct conversion of enums to specific mode classes only
55 when USE_ENUM_MODES is defined. This is only intended for use
56 by gencondmd, so that it can tell more easily when .md conditions
58 typedef machine_mode from_int
;
60 /* Here we use an enum type distinct from machine_mode but with the
61 same range as machine_mode. T should have a constructor that
62 accepts this enum type; it should not have a constructor that
65 We use this somewhat indirect approach to avoid too many constructor
66 calls when the compiler is built with -O0. For example, even in
67 unoptimized code, the return statement above would construct the
68 returned T directly from the numerical value of MODE. */
69 enum from_int
{ dummy
= MAX_MACHINE_MODE
};
74 struct mode_traits
<machine_mode
>
76 /* machine_mode itself needs no conversion. */
77 typedef machine_mode from_int
;
80 /* Always treat machine modes as fixed-size while compiling code specific
81 to targets that have no variable-size modes. */
82 #if defined (IN_TARGET_CODE) && NUM_POLY_INT_COEFFS == 1
83 #define ONLY_FIXED_SIZE_MODES 1
85 #define ONLY_FIXED_SIZE_MODES 0
88 /* Get the name of mode MODE as a string. */
90 extern const char * const mode_name
[NUM_MACHINE_MODES
];
91 #define GET_MODE_NAME(MODE) mode_name[MODE]
95 #include "mode-classes.def"
96 #define DEF_MODE_CLASS(M) M
97 enum mode_class
{ MODE_CLASSES
, MAX_MODE_CLASS
};
101 /* Get the general kind of object that mode MODE represents
102 (integer, floating, complex, etc.) */
104 extern const unsigned char mode_class
[NUM_MACHINE_MODES
];
105 #define GET_MODE_CLASS(MODE) ((enum mode_class) mode_class[MODE])
107 /* Nonzero if MODE is an integral mode. */
108 #define INTEGRAL_MODE_P(MODE) \
109 (GET_MODE_CLASS (MODE) == MODE_INT \
110 || GET_MODE_CLASS (MODE) == MODE_PARTIAL_INT \
111 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_INT \
112 || GET_MODE_CLASS (MODE) == MODE_VECTOR_BOOL \
113 || GET_MODE_CLASS (MODE) == MODE_VECTOR_INT)
115 /* Nonzero if MODE is a floating-point mode. */
116 #define FLOAT_MODE_P(MODE) \
117 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
118 || GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT \
119 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT \
120 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT)
122 /* Nonzero if MODE is a complex mode. */
123 #define COMPLEX_MODE_P(MODE) \
124 (GET_MODE_CLASS (MODE) == MODE_COMPLEX_INT \
125 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT)
127 /* Nonzero if MODE is a vector mode. */
128 #define VECTOR_MODE_P(MODE) \
129 (GET_MODE_CLASS (MODE) == MODE_VECTOR_BOOL \
130 || GET_MODE_CLASS (MODE) == MODE_VECTOR_INT \
131 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT \
132 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FRACT \
133 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UFRACT \
134 || GET_MODE_CLASS (MODE) == MODE_VECTOR_ACCUM \
135 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UACCUM)
137 /* Nonzero if MODE is a scalar integral mode. */
138 #define SCALAR_INT_MODE_P(MODE) \
139 (GET_MODE_CLASS (MODE) == MODE_INT \
140 || GET_MODE_CLASS (MODE) == MODE_PARTIAL_INT)
142 /* Nonzero if MODE is a scalar floating point mode. */
143 #define SCALAR_FLOAT_MODE_P(MODE) \
144 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
145 || GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT)
147 /* Nonzero if MODE is a decimal floating point mode. */
148 #define DECIMAL_FLOAT_MODE_P(MODE) \
149 (GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT)
151 /* Nonzero if MODE is a scalar fract mode. */
152 #define SCALAR_FRACT_MODE_P(MODE) \
153 (GET_MODE_CLASS (MODE) == MODE_FRACT)
155 /* Nonzero if MODE is a scalar ufract mode. */
156 #define SCALAR_UFRACT_MODE_P(MODE) \
157 (GET_MODE_CLASS (MODE) == MODE_UFRACT)
159 /* Nonzero if MODE is a scalar fract or ufract mode. */
160 #define ALL_SCALAR_FRACT_MODE_P(MODE) \
161 (SCALAR_FRACT_MODE_P (MODE) || SCALAR_UFRACT_MODE_P (MODE))
163 /* Nonzero if MODE is a scalar accum mode. */
164 #define SCALAR_ACCUM_MODE_P(MODE) \
165 (GET_MODE_CLASS (MODE) == MODE_ACCUM)
167 /* Nonzero if MODE is a scalar uaccum mode. */
168 #define SCALAR_UACCUM_MODE_P(MODE) \
169 (GET_MODE_CLASS (MODE) == MODE_UACCUM)
171 /* Nonzero if MODE is a scalar accum or uaccum mode. */
172 #define ALL_SCALAR_ACCUM_MODE_P(MODE) \
173 (SCALAR_ACCUM_MODE_P (MODE) || SCALAR_UACCUM_MODE_P (MODE))
175 /* Nonzero if MODE is a scalar fract or accum mode. */
176 #define SIGNED_SCALAR_FIXED_POINT_MODE_P(MODE) \
177 (SCALAR_FRACT_MODE_P (MODE) || SCALAR_ACCUM_MODE_P (MODE))
179 /* Nonzero if MODE is a scalar ufract or uaccum mode. */
180 #define UNSIGNED_SCALAR_FIXED_POINT_MODE_P(MODE) \
181 (SCALAR_UFRACT_MODE_P (MODE) || SCALAR_UACCUM_MODE_P (MODE))
183 /* Nonzero if MODE is a scalar fract, ufract, accum or uaccum mode. */
184 #define ALL_SCALAR_FIXED_POINT_MODE_P(MODE) \
185 (SIGNED_SCALAR_FIXED_POINT_MODE_P (MODE) \
186 || UNSIGNED_SCALAR_FIXED_POINT_MODE_P (MODE))
188 /* Nonzero if MODE is a scalar/vector fract mode. */
189 #define FRACT_MODE_P(MODE) \
190 (GET_MODE_CLASS (MODE) == MODE_FRACT \
191 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FRACT)
193 /* Nonzero if MODE is a scalar/vector ufract mode. */
194 #define UFRACT_MODE_P(MODE) \
195 (GET_MODE_CLASS (MODE) == MODE_UFRACT \
196 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UFRACT)
198 /* Nonzero if MODE is a scalar/vector fract or ufract mode. */
199 #define ALL_FRACT_MODE_P(MODE) \
200 (FRACT_MODE_P (MODE) || UFRACT_MODE_P (MODE))
202 /* Nonzero if MODE is a scalar/vector accum mode. */
203 #define ACCUM_MODE_P(MODE) \
204 (GET_MODE_CLASS (MODE) == MODE_ACCUM \
205 || GET_MODE_CLASS (MODE) == MODE_VECTOR_ACCUM)
207 /* Nonzero if MODE is a scalar/vector uaccum mode. */
208 #define UACCUM_MODE_P(MODE) \
209 (GET_MODE_CLASS (MODE) == MODE_UACCUM \
210 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UACCUM)
212 /* Nonzero if MODE is a scalar/vector accum or uaccum mode. */
213 #define ALL_ACCUM_MODE_P(MODE) \
214 (ACCUM_MODE_P (MODE) || UACCUM_MODE_P (MODE))
216 /* Nonzero if MODE is a scalar/vector fract or accum mode. */
217 #define SIGNED_FIXED_POINT_MODE_P(MODE) \
218 (FRACT_MODE_P (MODE) || ACCUM_MODE_P (MODE))
220 /* Nonzero if MODE is a scalar/vector ufract or uaccum mode. */
221 #define UNSIGNED_FIXED_POINT_MODE_P(MODE) \
222 (UFRACT_MODE_P (MODE) || UACCUM_MODE_P (MODE))
224 /* Nonzero if MODE is a scalar/vector fract, ufract, accum or uaccum mode. */
225 #define ALL_FIXED_POINT_MODE_P(MODE) \
226 (SIGNED_FIXED_POINT_MODE_P (MODE) \
227 || UNSIGNED_FIXED_POINT_MODE_P (MODE))
229 /* Nonzero if MODE is opaque. */
230 #define OPAQUE_MODE_P(MODE) \
231 (GET_MODE_CLASS (MODE) == MODE_OPAQUE)
233 /* Nonzero if CLASS modes can be widened. */
234 #define CLASS_HAS_WIDER_MODES_P(CLASS) \
236 || CLASS == MODE_PARTIAL_INT \
237 || CLASS == MODE_FLOAT \
238 || CLASS == MODE_DECIMAL_FLOAT \
239 || CLASS == MODE_COMPLEX_FLOAT \
240 || CLASS == MODE_FRACT \
241 || CLASS == MODE_UFRACT \
242 || CLASS == MODE_ACCUM \
243 || CLASS == MODE_UACCUM)
245 /* An optional T (i.e. a T or nothing), where T is some form of mode class. */
250 enum from_int
{ dummy
= MAX_MACHINE_MODE
};
252 ALWAYS_INLINE CONSTEXPR
opt_mode () : m_mode (E_VOIDmode
) {}
253 ALWAYS_INLINE CONSTEXPR
opt_mode (const T
&m
) : m_mode (m
) {}
255 ALWAYS_INLINE CONSTEXPR
opt_mode (const U
&m
) : m_mode (T (m
)) {}
256 ALWAYS_INLINE CONSTEXPR
opt_mode (from_int m
) : m_mode (machine_mode (m
)) {}
258 machine_mode
else_void () const;
259 machine_mode
else_blk () const { return else_mode (BLKmode
); }
260 machine_mode
else_mode (machine_mode
) const;
263 bool exists () const;
264 template<typename U
> bool exists (U
*) const;
266 bool operator== (const T
&m
) const { return m_mode
== m
; }
267 bool operator!= (const T
&m
) const { return m_mode
!= m
; }
273 /* If the object contains a T, return its enum value, otherwise return
277 ALWAYS_INLINE machine_mode
278 opt_mode
<T
>::else_void () const
283 /* If the T exists, return its enum value, otherwise return FALLBACK. */
287 opt_mode
<T
>::else_mode (machine_mode fallback
) const
289 return m_mode
== E_VOIDmode
? fallback
: m_mode
;
292 /* Assert that the object contains a T and return it. */
296 opt_mode
<T
>::require () const
298 gcc_checking_assert (m_mode
!= E_VOIDmode
);
299 return typename mode_traits
<T
>::from_int (m_mode
);
302 /* Return true if the object contains a T rather than nothing. */
306 opt_mode
<T
>::exists () const
308 return m_mode
!= E_VOIDmode
;
311 /* Return true if the object contains a T, storing it in *MODE if so. */
316 opt_mode
<T
>::exists (U
*mode
) const
318 if (m_mode
!= E_VOIDmode
)
320 *mode
= T (typename mode_traits
<T
>::from_int (m_mode
));
326 /* A POD version of mode class T. */
331 typedef typename mode_traits
<T
>::from_int from_int
;
332 typedef typename
T::measurement_type measurement_type
;
335 ALWAYS_INLINE CONSTEXPR
336 operator machine_mode () const { return m_mode
; }
338 ALWAYS_INLINE CONSTEXPR
339 operator T () const { return from_int (m_mode
); }
341 ALWAYS_INLINE pod_mode
&operator = (const T
&m
) { m_mode
= m
; return *this; }
344 /* Return true if mode M has type T. */
348 is_a (machine_mode m
)
350 return T::includes_p (m
);
353 template<typename T
, typename U
>
355 is_a (const opt_mode
<U
> &m
)
357 return T::includes_p (m
.else_void ());
360 /* Assert that mode M has type T, and return it in that form. */
364 as_a (machine_mode m
)
366 gcc_checking_assert (T::includes_p (m
));
367 return typename mode_traits
<T
>::from_int (m
);
370 template<typename T
, typename U
>
372 as_a (const opt_mode
<U
> &m
)
374 return as_a
<T
> (m
.else_void ());
377 /* Convert M to an opt_mode<T>. */
381 dyn_cast (machine_mode m
)
383 if (T::includes_p (m
))
384 return T (typename mode_traits
<T
>::from_int (m
));
385 return opt_mode
<T
> ();
388 template<typename T
, typename U
>
390 dyn_cast (const opt_mode
<U
> &m
)
392 return dyn_cast
<T
> (m
.else_void ());
395 /* Return true if mode M has type T, storing it as a T in *RESULT
398 template<typename T
, typename U
>
400 is_a (machine_mode m
, U
*result
)
402 if (T::includes_p (m
))
404 *result
= T (typename mode_traits
<T
>::from_int (m
));
410 /* Represents a machine mode that is known to be a SCALAR_INT_MODE_P. */
411 class scalar_int_mode
414 typedef mode_traits
<scalar_int_mode
>::from_int from_int
;
415 typedef unsigned short measurement_type
;
417 ALWAYS_INLINE
scalar_int_mode () {}
419 ALWAYS_INLINE CONSTEXPR
420 scalar_int_mode (from_int m
) : m_mode (machine_mode (m
)) {}
422 ALWAYS_INLINE CONSTEXPR
operator machine_mode () const { return m_mode
; }
424 static bool includes_p (machine_mode
);
430 /* Return true if M is a scalar_int_mode. */
433 scalar_int_mode::includes_p (machine_mode m
)
435 return SCALAR_INT_MODE_P (m
);
438 /* Represents a machine mode that is known to be a SCALAR_FLOAT_MODE_P. */
439 class scalar_float_mode
442 typedef mode_traits
<scalar_float_mode
>::from_int from_int
;
443 typedef unsigned short measurement_type
;
445 ALWAYS_INLINE
scalar_float_mode () {}
447 ALWAYS_INLINE CONSTEXPR
448 scalar_float_mode (from_int m
) : m_mode (machine_mode (m
)) {}
450 ALWAYS_INLINE CONSTEXPR
operator machine_mode () const { return m_mode
; }
452 static bool includes_p (machine_mode
);
458 /* Return true if M is a scalar_float_mode. */
461 scalar_float_mode::includes_p (machine_mode m
)
463 return SCALAR_FLOAT_MODE_P (m
);
466 /* Represents a machine mode that is known to be scalar. */
470 typedef mode_traits
<scalar_mode
>::from_int from_int
;
471 typedef unsigned short measurement_type
;
473 ALWAYS_INLINE
scalar_mode () {}
475 ALWAYS_INLINE CONSTEXPR
476 scalar_mode (from_int m
) : m_mode (machine_mode (m
)) {}
478 ALWAYS_INLINE CONSTEXPR
479 scalar_mode (const scalar_int_mode
&m
) : m_mode (m
) {}
481 ALWAYS_INLINE CONSTEXPR
482 scalar_mode (const scalar_float_mode
&m
) : m_mode (m
) {}
484 ALWAYS_INLINE CONSTEXPR
485 scalar_mode (const scalar_int_mode_pod
&m
) : m_mode (m
) {}
487 ALWAYS_INLINE CONSTEXPR
operator machine_mode () const { return m_mode
; }
489 static bool includes_p (machine_mode
);
495 /* Return true if M represents some kind of scalar value. */
498 scalar_mode::includes_p (machine_mode m
)
500 switch (GET_MODE_CLASS (m
))
503 case MODE_PARTIAL_INT
:
509 case MODE_DECIMAL_FLOAT
:
516 /* Represents a machine mode that is known to be a COMPLEX_MODE_P. */
520 typedef mode_traits
<complex_mode
>::from_int from_int
;
521 typedef unsigned short measurement_type
;
523 ALWAYS_INLINE
complex_mode () {}
525 ALWAYS_INLINE CONSTEXPR
526 complex_mode (from_int m
) : m_mode (machine_mode (m
)) {}
528 ALWAYS_INLINE CONSTEXPR
operator machine_mode () const { return m_mode
; }
530 static bool includes_p (machine_mode
);
536 /* Return true if M is a complex_mode. */
539 complex_mode::includes_p (machine_mode m
)
541 return COMPLEX_MODE_P (m
);
544 /* Return the base GET_MODE_SIZE value for MODE. */
546 ALWAYS_INLINE poly_uint16
547 mode_to_bytes (machine_mode mode
)
549 #if GCC_VERSION >= 4001
550 return (__builtin_constant_p (mode
)
551 ? mode_size_inline (mode
) : mode_size
[mode
]);
553 return mode_size
[mode
];
557 /* Return the base GET_MODE_BITSIZE value for MODE. */
559 ALWAYS_INLINE poly_uint16
560 mode_to_bits (machine_mode mode
)
562 return mode_to_bytes (mode
) * BITS_PER_UNIT
;
565 /* Return the base GET_MODE_PRECISION value for MODE. */
567 ALWAYS_INLINE poly_uint16
568 mode_to_precision (machine_mode mode
)
570 return mode_precision
[mode
];
573 /* Return the base GET_MODE_INNER value for MODE. */
575 ALWAYS_INLINE scalar_mode
576 mode_to_inner (machine_mode mode
)
578 #if GCC_VERSION >= 4001
579 return scalar_mode::from_int (__builtin_constant_p (mode
)
580 ? mode_inner_inline (mode
)
583 return scalar_mode::from_int (mode_inner
[mode
]);
587 /* Return the base GET_MODE_UNIT_SIZE value for MODE. */
589 ALWAYS_INLINE
unsigned char
590 mode_to_unit_size (machine_mode mode
)
592 #if GCC_VERSION >= 4001
593 return (__builtin_constant_p (mode
)
594 ? mode_unit_size_inline (mode
) : mode_unit_size
[mode
]);
596 return mode_unit_size
[mode
];
600 /* Return the base GET_MODE_UNIT_PRECISION value for MODE. */
602 ALWAYS_INLINE
unsigned short
603 mode_to_unit_precision (machine_mode mode
)
605 #if GCC_VERSION >= 4001
606 return (__builtin_constant_p (mode
)
607 ? mode_unit_precision_inline (mode
) : mode_unit_precision
[mode
]);
609 return mode_unit_precision
[mode
];
613 /* Return the base GET_MODE_NUNITS value for MODE. */
615 ALWAYS_INLINE poly_uint16
616 mode_to_nunits (machine_mode mode
)
618 #if GCC_VERSION >= 4001
619 return (__builtin_constant_p (mode
)
620 ? mode_nunits_inline (mode
) : mode_nunits
[mode
]);
622 return mode_nunits
[mode
];
626 /* Get the size in bytes of an object of mode MODE. */
628 #if ONLY_FIXED_SIZE_MODES
629 #define GET_MODE_SIZE(MODE) ((unsigned short) mode_to_bytes (MODE).coeffs[0])
631 ALWAYS_INLINE poly_uint16
632 GET_MODE_SIZE (machine_mode mode
)
634 return mode_to_bytes (mode
);
638 ALWAYS_INLINE typename if_poly
<typename
T::measurement_type
>::type
639 GET_MODE_SIZE (const T
&mode
)
641 return mode_to_bytes (mode
);
645 ALWAYS_INLINE typename if_nonpoly
<typename
T::measurement_type
>::type
646 GET_MODE_SIZE (const T
&mode
)
648 return mode_to_bytes (mode
).coeffs
[0];
652 /* Get the size in bits of an object of mode MODE. */
654 #if ONLY_FIXED_SIZE_MODES
655 #define GET_MODE_BITSIZE(MODE) ((unsigned short) mode_to_bits (MODE).coeffs[0])
657 ALWAYS_INLINE poly_uint16
658 GET_MODE_BITSIZE (machine_mode mode
)
660 return mode_to_bits (mode
);
664 ALWAYS_INLINE typename if_poly
<typename
T::measurement_type
>::type
665 GET_MODE_BITSIZE (const T
&mode
)
667 return mode_to_bits (mode
);
671 ALWAYS_INLINE typename if_nonpoly
<typename
T::measurement_type
>::type
672 GET_MODE_BITSIZE (const T
&mode
)
674 return mode_to_bits (mode
).coeffs
[0];
678 /* Get the number of value bits of an object of mode MODE. */
680 #if ONLY_FIXED_SIZE_MODES
681 #define GET_MODE_PRECISION(MODE) \
682 ((unsigned short) mode_to_precision (MODE).coeffs[0])
684 ALWAYS_INLINE poly_uint16
685 GET_MODE_PRECISION (machine_mode mode
)
687 return mode_to_precision (mode
);
691 ALWAYS_INLINE typename if_poly
<typename
T::measurement_type
>::type
692 GET_MODE_PRECISION (const T
&mode
)
694 return mode_to_precision (mode
);
698 ALWAYS_INLINE typename if_nonpoly
<typename
T::measurement_type
>::type
699 GET_MODE_PRECISION (const T
&mode
)
701 return mode_to_precision (mode
).coeffs
[0];
705 /* Get the number of integral bits of an object of mode MODE. */
706 extern CONST_MODE_IBIT
unsigned char mode_ibit
[NUM_MACHINE_MODES
];
707 #define GET_MODE_IBIT(MODE) mode_ibit[MODE]
709 /* Get the number of fractional bits of an object of mode MODE. */
710 extern CONST_MODE_FBIT
unsigned char mode_fbit
[NUM_MACHINE_MODES
];
711 #define GET_MODE_FBIT(MODE) mode_fbit[MODE]
713 /* Get a bitmask containing 1 for all bits in a word
714 that fit within mode MODE. */
716 extern CONST_MODE_MASK
unsigned HOST_WIDE_INT
717 mode_mask_array
[NUM_MACHINE_MODES
];
719 #define GET_MODE_MASK(MODE) mode_mask_array[MODE]
721 /* Return the mode of the basic parts of MODE. For vector modes this is the
722 mode of the vector elements. For complex modes it is the mode of the real
723 and imaginary parts. For other modes it is MODE itself. */
725 #define GET_MODE_INNER(MODE) (mode_to_inner (MODE))
727 /* Get the size in bytes or bits of the basic parts of an
728 object of mode MODE. */
730 #define GET_MODE_UNIT_SIZE(MODE) mode_to_unit_size (MODE)
732 #define GET_MODE_UNIT_BITSIZE(MODE) \
733 ((unsigned short) (GET_MODE_UNIT_SIZE (MODE) * BITS_PER_UNIT))
735 #define GET_MODE_UNIT_PRECISION(MODE) (mode_to_unit_precision (MODE))
737 /* Get the number of units in an object of mode MODE. This is 2 for
738 complex modes and the number of elements for vector modes. */
740 #if ONLY_FIXED_SIZE_MODES
741 #define GET_MODE_NUNITS(MODE) (mode_to_nunits (MODE).coeffs[0])
743 ALWAYS_INLINE poly_uint16
744 GET_MODE_NUNITS (machine_mode mode
)
746 return mode_to_nunits (mode
);
750 ALWAYS_INLINE typename if_poly
<typename
T::measurement_type
>::type
751 GET_MODE_NUNITS (const T
&mode
)
753 return mode_to_nunits (mode
);
757 ALWAYS_INLINE typename if_nonpoly
<typename
T::measurement_type
>::type
758 GET_MODE_NUNITS (const T
&mode
)
760 return mode_to_nunits (mode
).coeffs
[0];
764 /* Get the next natural mode (not narrower, eg, QI -> HI -> SI -> DI -> TI
765 or HF -> BF -> SF -> DF -> XF -> TF). */
768 ALWAYS_INLINE opt_mode
<T
>
769 GET_MODE_NEXT_MODE (const T
&m
)
771 return typename opt_mode
<T
>::from_int (mode_next
[m
]);
774 /* Get the next wider mode (eg, QI -> HI -> SI -> DI -> TI
775 or { HF, BF } -> SF -> DF -> XF -> TF).
776 This is similar to GET_MODE_NEXT_MODE, but while GET_MODE_NEXT_MODE
777 can include mode that have the same precision (e.g.
778 GET_MODE_NEXT_MODE (HFmode) can be BFmode even when both have the same
779 precision), this one will skip those. And always VOIDmode for
780 modes whose class is !CLASS_HAS_WIDER_MODES_P. */
783 ALWAYS_INLINE opt_mode
<T
>
784 GET_MODE_WIDER_MODE (const T
&m
)
786 return typename opt_mode
<T
>::from_int (mode_wider
[m
]);
789 /* For scalars, this is a mode with twice the precision. For vectors,
790 this is a mode with the same inner mode but with twice the elements. */
793 ALWAYS_INLINE opt_mode
<T
>
794 GET_MODE_2XWIDER_MODE (const T
&m
)
796 return typename opt_mode
<T
>::from_int (mode_2xwider
[m
]);
799 /* Get the complex mode from the component mode. */
800 extern const unsigned char mode_complex
[NUM_MACHINE_MODES
];
801 #define GET_MODE_COMPLEX_MODE(MODE) ((machine_mode) mode_complex[MODE])
803 /* Represents a machine mode that must have a fixed size. The main
804 use of this class is to represent the modes of objects that always
805 have static storage duration, such as constant pool entries.
806 (No current target supports the concept of variable-size static data.) */
807 class fixed_size_mode
810 typedef mode_traits
<fixed_size_mode
>::from_int from_int
;
811 typedef unsigned short measurement_type
;
813 ALWAYS_INLINE
fixed_size_mode () {}
815 ALWAYS_INLINE CONSTEXPR
816 fixed_size_mode (from_int m
) : m_mode (machine_mode (m
)) {}
818 ALWAYS_INLINE CONSTEXPR
819 fixed_size_mode (const scalar_mode
&m
) : m_mode (m
) {}
821 ALWAYS_INLINE CONSTEXPR
822 fixed_size_mode (const scalar_int_mode
&m
) : m_mode (m
) {}
824 ALWAYS_INLINE CONSTEXPR
825 fixed_size_mode (const scalar_float_mode
&m
) : m_mode (m
) {}
827 ALWAYS_INLINE CONSTEXPR
828 fixed_size_mode (const scalar_mode_pod
&m
) : m_mode (m
) {}
830 ALWAYS_INLINE CONSTEXPR
831 fixed_size_mode (const scalar_int_mode_pod
&m
) : m_mode (m
) {}
833 ALWAYS_INLINE CONSTEXPR
834 fixed_size_mode (const complex_mode
&m
) : m_mode (m
) {}
836 ALWAYS_INLINE CONSTEXPR
operator machine_mode () const { return m_mode
; }
838 static bool includes_p (machine_mode
);
844 /* Return true if MODE has a fixed size. */
847 fixed_size_mode::includes_p (machine_mode mode
)
849 return mode_to_bytes (mode
).is_constant ();
852 /* Wrapper for mode arguments to target macros, so that if a target
853 doesn't need polynomial-sized modes, its header file can continue
854 to treat everything as fixed_size_mode. This should go away once
855 macros are moved to target hooks. It shouldn't be used in other
857 #if NUM_POLY_INT_COEFFS == 1
858 #define MACRO_MODE(MODE) (as_a <fixed_size_mode> (MODE))
860 #define MACRO_MODE(MODE) (MODE)
863 extern opt_machine_mode
mode_for_size (poly_uint64
, enum mode_class
, int);
865 /* Return the machine mode to use for a MODE_INT of SIZE bits, if one
866 exists. If LIMIT is nonzero, modes wider than MAX_FIXED_MODE_SIZE
869 inline opt_scalar_int_mode
870 int_mode_for_size (poly_uint64 size
, int limit
)
872 return dyn_cast
<scalar_int_mode
> (mode_for_size (size
, MODE_INT
, limit
));
875 /* Return the machine mode to use for a MODE_FLOAT of SIZE bits, if one
878 inline opt_scalar_float_mode
879 float_mode_for_size (poly_uint64 size
)
881 return dyn_cast
<scalar_float_mode
> (mode_for_size (size
, MODE_FLOAT
, 0));
884 /* Likewise for MODE_DECIMAL_FLOAT. */
886 inline opt_scalar_float_mode
887 decimal_float_mode_for_size (unsigned int size
)
889 return dyn_cast
<scalar_float_mode
>
890 (mode_for_size (size
, MODE_DECIMAL_FLOAT
, 0));
893 extern machine_mode
smallest_mode_for_size (poly_uint64
, enum mode_class
);
895 /* Find the narrowest integer mode that contains at least SIZE bits.
896 Such a mode must exist. */
898 inline scalar_int_mode
899 smallest_int_mode_for_size (poly_uint64 size
)
901 return as_a
<scalar_int_mode
> (smallest_mode_for_size (size
, MODE_INT
));
904 extern opt_scalar_int_mode
int_mode_for_mode (machine_mode
);
905 extern opt_machine_mode
bitwise_mode_for_mode (machine_mode
);
906 extern opt_machine_mode
mode_for_vector (scalar_mode
, poly_uint64
);
907 extern opt_machine_mode
related_vector_mode (machine_mode
, scalar_mode
,
909 extern opt_machine_mode
related_int_vector_mode (machine_mode
);
911 /* A class for iterating through possible bitfield modes. */
912 class bit_field_mode_iterator
915 bit_field_mode_iterator (HOST_WIDE_INT
, HOST_WIDE_INT
,
916 poly_int64
, poly_int64
,
918 bool next_mode (scalar_int_mode
*);
919 bool prefer_smaller_modes ();
922 opt_scalar_int_mode m_mode
;
923 /* We use signed values here because the bit position can be negative
924 for invalid input such as gcc.dg/pr48335-8.c. */
925 HOST_WIDE_INT m_bitsize
;
926 HOST_WIDE_INT m_bitpos
;
927 poly_int64 m_bitregion_start
;
928 poly_int64 m_bitregion_end
;
929 unsigned int m_align
;
934 /* Find the best mode to use to access a bit field. */
936 extern bool get_best_mode (int, int, poly_uint64
, poly_uint64
, unsigned int,
937 unsigned HOST_WIDE_INT
, bool, scalar_int_mode
*);
939 /* Determine alignment, 1<=result<=BIGGEST_ALIGNMENT. */
941 extern CONST_MODE_BASE_ALIGN
unsigned short mode_base_align
[NUM_MACHINE_MODES
];
943 extern unsigned get_mode_alignment (machine_mode
);
945 #define GET_MODE_ALIGNMENT(MODE) get_mode_alignment (MODE)
947 /* For each class, get the narrowest mode in that class. */
949 extern const unsigned char class_narrowest_mode
[MAX_MODE_CLASS
];
950 #define GET_CLASS_NARROWEST_MODE(CLASS) \
951 ((machine_mode) class_narrowest_mode[CLASS])
953 /* The narrowest full integer mode available on the target. */
955 #define NARROWEST_INT_MODE \
957 (scalar_int_mode::from_int (class_narrowest_mode[MODE_INT])))
959 /* Return the narrowest mode in T's class. */
963 get_narrowest_mode (T mode
)
965 return typename mode_traits
<T
>::from_int
966 (class_narrowest_mode
[GET_MODE_CLASS (mode
)]);
969 /* Define the integer modes whose sizes are BITS_PER_UNIT and BITS_PER_WORD
970 and the mode whose class is Pmode and whose size is POINTER_SIZE. */
972 extern scalar_int_mode byte_mode
;
973 extern scalar_int_mode word_mode
;
974 extern scalar_int_mode ptr_mode
;
976 /* Target-dependent machine mode initialization - in insn-modes.cc. */
977 extern void init_adjust_machine_modes (void);
979 #define TRULY_NOOP_TRUNCATION_MODES_P(MODE1, MODE2) \
980 (targetm.truly_noop_truncation (GET_MODE_PRECISION (MODE1), \
981 GET_MODE_PRECISION (MODE2)))
983 /* Return true if MODE is a scalar integer mode that fits in a
987 HWI_COMPUTABLE_MODE_P (machine_mode mode
)
989 machine_mode mme
= mode
;
990 return (SCALAR_INT_MODE_P (mme
)
991 && mode_to_precision (mme
).coeffs
[0] <= HOST_BITS_PER_WIDE_INT
);
995 HWI_COMPUTABLE_MODE_P (scalar_int_mode mode
)
997 return GET_MODE_PRECISION (mode
) <= HOST_BITS_PER_WIDE_INT
;
1000 struct int_n_data_t
{
1001 /* These parts are initailized by genmodes output */
1002 unsigned int bitsize
;
1003 scalar_int_mode_pod m
;
1004 /* RID_* is RID_INTN_BASE + index into this array */
1007 /* This is also in tree.h. genmodes.cc guarantees the're sorted from
1008 smallest bitsize to largest bitsize. */
1009 extern bool int_n_enabled_p
[NUM_INT_N_ENTS
];
1010 extern const int_n_data_t int_n_data
[NUM_INT_N_ENTS
];
1012 /* Return true if MODE has class MODE_INT, storing it as a scalar_int_mode
1013 in *INT_MODE if so. */
1015 template<typename T
>
1017 is_int_mode (machine_mode mode
, T
*int_mode
)
1019 if (GET_MODE_CLASS (mode
) == MODE_INT
)
1021 *int_mode
= scalar_int_mode (scalar_int_mode::from_int (mode
));
1027 /* Return true if MODE has class MODE_FLOAT, storing it as a
1028 scalar_float_mode in *FLOAT_MODE if so. */
1030 template<typename T
>
1032 is_float_mode (machine_mode mode
, T
*float_mode
)
1034 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
1036 *float_mode
= scalar_float_mode (scalar_float_mode::from_int (mode
));
1042 /* Return true if MODE has class MODE_COMPLEX_INT, storing it as
1043 a complex_mode in *CMODE if so. */
1045 template<typename T
>
1047 is_complex_int_mode (machine_mode mode
, T
*cmode
)
1049 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_INT
)
1051 *cmode
= complex_mode (complex_mode::from_int (mode
));
1057 /* Return true if MODE has class MODE_COMPLEX_FLOAT, storing it as
1058 a complex_mode in *CMODE if so. */
1060 template<typename T
>
1062 is_complex_float_mode (machine_mode mode
, T
*cmode
)
1064 if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
)
1066 *cmode
= complex_mode (complex_mode::from_int (mode
));
1072 /* Return true if MODE is a scalar integer mode with a precision
1073 smaller than LIMIT's precision. */
1076 is_narrower_int_mode (machine_mode mode
, scalar_int_mode limit
)
1078 scalar_int_mode int_mode
;
1079 return (is_a
<scalar_int_mode
> (mode
, &int_mode
)
1080 && GET_MODE_PRECISION (int_mode
) < GET_MODE_PRECISION (limit
));
1083 namespace mode_iterator
1085 /* Start mode iterator *ITER at the first mode in class MCLASS, if any. */
1087 template<typename T
>
1089 start (opt_mode
<T
> *iter
, enum mode_class mclass
)
1091 if (GET_CLASS_NARROWEST_MODE (mclass
) == E_VOIDmode
)
1092 *iter
= opt_mode
<T
> ();
1094 *iter
= as_a
<T
> (GET_CLASS_NARROWEST_MODE (mclass
));
1098 start (machine_mode
*iter
, enum mode_class mclass
)
1100 *iter
= GET_CLASS_NARROWEST_MODE (mclass
);
1103 /* Return true if mode iterator *ITER has not reached the end. */
1105 template<typename T
>
1107 iterate_p (opt_mode
<T
> *iter
)
1109 return iter
->exists ();
1113 iterate_p (machine_mode
*iter
)
1115 return *iter
!= E_VOIDmode
;
1118 /* Set mode iterator *ITER to the next mode in the same class,
1121 template<typename T
>
1123 get_next (opt_mode
<T
> *iter
)
1125 *iter
= GET_MODE_NEXT_MODE (iter
->require ());
1129 get_next (machine_mode
*iter
)
1131 *iter
= GET_MODE_NEXT_MODE (*iter
).else_void ();
1134 /* Set mode iterator *ITER to the next mode in the same class.
1135 Such a mode is known to exist. */
1137 template<typename T
>
1139 get_known_next (T
*iter
)
1141 *iter
= GET_MODE_NEXT_MODE (*iter
).require ();
1144 /* Set mode iterator *ITER to the next wider mode in the same class,
1147 template<typename T
>
1149 get_wider (opt_mode
<T
> *iter
)
1151 *iter
= GET_MODE_WIDER_MODE (iter
->require ());
1155 get_wider (machine_mode
*iter
)
1157 *iter
= GET_MODE_WIDER_MODE (*iter
).else_void ();
1160 /* Set mode iterator *ITER to the next wider mode in the same class.
1161 Such a mode is known to exist. */
1163 template<typename T
>
1165 get_known_wider (T
*iter
)
1167 *iter
= GET_MODE_WIDER_MODE (*iter
).require ();
1170 /* Set mode iterator *ITER to the mode that is two times wider than the
1171 current one, if such a mode exists. */
1173 template<typename T
>
1175 get_2xwider (opt_mode
<T
> *iter
)
1177 *iter
= GET_MODE_2XWIDER_MODE (iter
->require ());
1181 get_2xwider (machine_mode
*iter
)
1183 *iter
= GET_MODE_2XWIDER_MODE (*iter
).else_void ();
1187 /* Make ITERATOR iterate over all the modes in mode class CLASS,
1188 from narrowest to widest. */
1189 #define FOR_EACH_MODE_IN_CLASS(ITERATOR, CLASS) \
1190 for (mode_iterator::start (&(ITERATOR), CLASS); \
1191 mode_iterator::iterate_p (&(ITERATOR)); \
1192 mode_iterator::get_next (&(ITERATOR)))
1194 /* Make ITERATOR iterate over all the modes in the range [START, END),
1195 in order of increasing width. */
1196 #define FOR_EACH_MODE(ITERATOR, START, END) \
1197 for ((ITERATOR) = (START); \
1198 (ITERATOR) != (END); \
1199 mode_iterator::get_known_next (&(ITERATOR)))
1201 /* Make ITERATOR iterate over START and all non-narrower modes in the same
1202 class, in order of increasing width. */
1203 #define FOR_EACH_MODE_FROM(ITERATOR, START) \
1204 for ((ITERATOR) = (START); \
1205 mode_iterator::iterate_p (&(ITERATOR)); \
1206 mode_iterator::get_next (&(ITERATOR)))
1208 /* Make ITERATOR iterate over START and all wider modes in the same
1209 class, in order of strictly increasing width. */
1210 #define FOR_EACH_WIDER_MODE_FROM(ITERATOR, START) \
1211 for ((ITERATOR) = (START); \
1212 mode_iterator::iterate_p (&(ITERATOR)); \
1213 mode_iterator::get_wider (&(ITERATOR)))
1215 /* Make ITERATOR iterate over modes in the range [NARROWEST, END)
1216 in order of increasing width, where NARROWEST is the narrowest mode
1218 #define FOR_EACH_MODE_UNTIL(ITERATOR, END) \
1219 FOR_EACH_MODE (ITERATOR, get_narrowest_mode (END), END)
1221 /* Make ITERATOR iterate over modes in the same class as MODE, in order
1222 of non-decreasing width. Start at next such mode after START,
1223 or don't iterate at all if there is no such mode. */
1224 #define FOR_EACH_NEXT_MODE(ITERATOR, START) \
1225 for ((ITERATOR) = (START), mode_iterator::get_next (&(ITERATOR)); \
1226 mode_iterator::iterate_p (&(ITERATOR)); \
1227 mode_iterator::get_next (&(ITERATOR)))
1229 /* Make ITERATOR iterate over modes in the same class as MODE, in order
1230 of increasing width. Start at the first mode wider than START,
1231 or don't iterate at all if there is no wider mode. */
1232 #define FOR_EACH_WIDER_MODE(ITERATOR, START) \
1233 for ((ITERATOR) = (START), mode_iterator::get_wider (&(ITERATOR)); \
1234 mode_iterator::iterate_p (&(ITERATOR)); \
1235 mode_iterator::get_wider (&(ITERATOR)))
1237 /* Make ITERATOR iterate over modes in the same class as MODE, in order
1238 of increasing width, and with each mode being twice the width of the
1239 previous mode. Start at the mode that is two times wider than START,
1240 or don't iterate at all if there is no such mode. */
1241 #define FOR_EACH_2XWIDER_MODE(ITERATOR, START) \
1242 for ((ITERATOR) = (START), mode_iterator::get_2xwider (&(ITERATOR)); \
1243 mode_iterator::iterate_p (&(ITERATOR)); \
1244 mode_iterator::get_2xwider (&(ITERATOR)))
1246 template<typename T
>
1248 gt_ggc_mx (pod_mode
<T
> *)
1252 template<typename T
>
1254 gt_pch_nx (pod_mode
<T
> *)
1258 template<typename T
>
1260 gt_pch_nx (pod_mode
<T
> *, gt_pointer_operator
, void *)
1264 #endif /* not HAVE_MACHINE_MODES */