1 /* Machine mode definitions for GCC; included by rtl.h and tree.h.
2    Copyright (C) 1991-2020 Free Software Foundation, Inc.
3 
4 This file is part of GCC.
5 
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.
10 
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.
15 
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/>.  */
19 
20 #ifndef HAVE_MACHINE_MODES
21 #define HAVE_MACHINE_MODES
22 
23 typedef opt_mode<machine_mode> opt_machine_mode;
24 
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];
33 
34 template<typename T>
35 struct mode_traits
36 {
37   /* For use by the machmode support code only.
38 
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:
43 
44        return typename mode_traits<T>::from_int (mode);
45 
46      when returning a T and:
47 
48        res = T (typename mode_traits<T>::from_int (mode));
49 
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.
63 
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
70 };
71 
72 template<>
73 struct mode_traits<machine_mode>
74 {
75   /* machine_mode itself needs no conversion.  */
76   typedef machine_mode from_int;
77 };
78 
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
86 
87 /* Get the name of mode MODE as a string.  */
88 
89 extern const char * const mode_name[NUM_MACHINE_MODES];
90 #define GET_MODE_NAME(MODE)  mode_name[MODE]
91 
92 /* Mode classes.  */
93 
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
99 
100 /* Get the general kind of object that mode MODE represents
101    (integer, floating, complex, etc.)  */
102 
103 extern const unsigned char mode_class[NUM_MACHINE_MODES];
104 #define GET_MODE_CLASS(MODE)  ((enum mode_class) mode_class[MODE])
105 
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)
113 
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)
120 
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)
125 
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)
135 
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)
140 
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)
145 
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)
149 
150 /* Nonzero if MODE is a scalar fract mode.  */
151 #define SCALAR_FRACT_MODE_P(MODE)	\
152   (GET_MODE_CLASS (MODE) == MODE_FRACT)
153 
154 /* Nonzero if MODE is a scalar ufract mode.  */
155 #define SCALAR_UFRACT_MODE_P(MODE)	\
156   (GET_MODE_CLASS (MODE) == MODE_UFRACT)
157 
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))
161 
162 /* Nonzero if MODE is a scalar accum mode.  */
163 #define SCALAR_ACCUM_MODE_P(MODE)	\
164   (GET_MODE_CLASS (MODE) == MODE_ACCUM)
165 
166 /* Nonzero if MODE is a scalar uaccum mode.  */
167 #define SCALAR_UACCUM_MODE_P(MODE)	\
168   (GET_MODE_CLASS (MODE) == MODE_UACCUM)
169 
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))
173 
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))
177 
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))
181 
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))
186 
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)
191 
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)
196 
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))
200 
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)
205 
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)
210 
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))
214 
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))
218 
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))
222 
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))
227 
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)
239 
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
243 {
244 public:
245   enum from_int { dummy = MAX_MACHINE_MODE };
246 
247   ALWAYS_INLINE CONSTEXPR opt_mode () : m_mode (E_VOIDmode) {}
248   ALWAYS_INLINE CONSTEXPR opt_mode (const T &m) : m_mode (m) {}
249   template<typename U>
250   ALWAYS_INLINE CONSTEXPR opt_mode (const U &m) : m_mode (T (m)) {}
251   ALWAYS_INLINE CONSTEXPR opt_mode (from_int m) : m_mode (machine_mode (m)) {}
252 
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;
257 
258   bool exists () const;
259   template<typename U> bool exists (U *) const;
260 
261   bool operator== (const T &m) const { return m_mode == m; }
262   bool operator!= (const T &m) const { return m_mode != m; }
263 
264 private:
265   machine_mode m_mode;
266 };
267 
268 /* If the object contains a T, return its enum value, otherwise return
269    E_VOIDmode.  */
270 
271 template<typename T>
272 ALWAYS_INLINE machine_mode
273 opt_mode<T>::else_void () const
274 {
275   return m_mode;
276 }
277 
278 /* If the T exists, return its enum value, otherwise return FALLBACK.  */
279 
280 template<typename T>
281 inline machine_mode
282 opt_mode<T>::else_mode (machine_mode fallback) const
283 {
284   return m_mode == E_VOIDmode ? fallback : m_mode;
285 }
286 
287 /* Assert that the object contains a T and return it.  */
288 
289 template<typename T>
290 inline T
291 opt_mode<T>::require () const
292 {
293   gcc_checking_assert (m_mode != E_VOIDmode);
294   return typename mode_traits<T>::from_int (m_mode);
295 }
296 
297 /* Return true if the object contains a T rather than nothing.  */
298 
299 template<typename T>
300 ALWAYS_INLINE bool
301 opt_mode<T>::exists () const
302 {
303   return m_mode != E_VOIDmode;
304 }
305 
306 /* Return true if the object contains a T, storing it in *MODE if so.  */
307 
308 template<typename T>
309 template<typename U>
310 inline bool
311 opt_mode<T>::exists (U *mode) const
312 {
313   if (m_mode != E_VOIDmode)
314     {
315       *mode = T (typename mode_traits<T>::from_int (m_mode));
316       return true;
317     }
318   return false;
319 }
320 
321 /* A POD version of mode class T.  */
322 
323 template<typename T>
324 struct pod_mode
325 {
326   typedef typename mode_traits<T>::from_int from_int;
327   typedef typename T::measurement_type measurement_type;
328 
329   machine_mode m_mode;
330   ALWAYS_INLINE CONSTEXPR
331   operator machine_mode () const { return m_mode; }
332 
333   ALWAYS_INLINE CONSTEXPR
334   operator T () const { return from_int (m_mode); }
335 
336   ALWAYS_INLINE pod_mode &operator = (const T &m) { m_mode = m; return *this; }
337 };
338 
339 /* Return true if mode M has type T.  */
340 
341 template<typename T>
342 inline bool
343 is_a (machine_mode m)
344 {
345   return T::includes_p (m);
346 }
347 
348 template<typename T, typename U>
349 inline bool
350 is_a (const opt_mode<U> &m)
351 {
352   return T::includes_p (m.else_void ());
353 }
354 
355 /* Assert that mode M has type T, and return it in that form.  */
356 
357 template<typename T>
358 inline T
359 as_a (machine_mode m)
360 {
361   gcc_checking_assert (T::includes_p (m));
362   return typename mode_traits<T>::from_int (m);
363 }
364 
365 template<typename T, typename U>
366 inline T
367 as_a (const opt_mode<U> &m)
368 {
369   return as_a <T> (m.else_void ());
370 }
371 
372 /* Convert M to an opt_mode<T>.  */
373 
374 template<typename T>
375 inline opt_mode<T>
376 dyn_cast (machine_mode m)
377 {
378   if (T::includes_p (m))
379     return T (typename mode_traits<T>::from_int (m));
380   return opt_mode<T> ();
381 }
382 
383 template<typename T, typename U>
384 inline opt_mode<T>
385 dyn_cast (const opt_mode<U> &m)
386 {
387   return dyn_cast <T> (m.else_void ());
388 }
389 
390 /* Return true if mode M has type T, storing it as a T in *RESULT
391    if so.  */
392 
393 template<typename T, typename U>
394 inline bool
395 is_a (machine_mode m, U *result)
396 {
397   if (T::includes_p (m))
398     {
399       *result = T (typename mode_traits<T>::from_int (m));
400       return true;
401     }
402   return false;
403 }
404 
405 /* Represents a machine mode that is known to be a SCALAR_INT_MODE_P.  */
406 class scalar_int_mode
407 {
408 public:
409   typedef mode_traits<scalar_int_mode>::from_int from_int;
410   typedef unsigned short measurement_type;
411 
412   ALWAYS_INLINE scalar_int_mode () {}
413 
414   ALWAYS_INLINE CONSTEXPR
415   scalar_int_mode (from_int m) : m_mode (machine_mode (m)) {}
416 
417   ALWAYS_INLINE CONSTEXPR operator machine_mode () const { return m_mode; }
418 
419   static bool includes_p (machine_mode);
420 
421 protected:
422   machine_mode m_mode;
423 };
424 
425 /* Return true if M is a scalar_int_mode.  */
426 
427 inline bool
428 scalar_int_mode::includes_p (machine_mode m)
429 {
430   return SCALAR_INT_MODE_P (m);
431 }
432 
433 /* Represents a machine mode that is known to be a SCALAR_FLOAT_MODE_P.  */
434 class scalar_float_mode
435 {
436 public:
437   typedef mode_traits<scalar_float_mode>::from_int from_int;
438   typedef unsigned short measurement_type;
439 
440   ALWAYS_INLINE scalar_float_mode () {}
441 
442   ALWAYS_INLINE CONSTEXPR
443   scalar_float_mode (from_int m) : m_mode (machine_mode (m)) {}
444 
445   ALWAYS_INLINE CONSTEXPR operator machine_mode () const { return m_mode; }
446 
447   static bool includes_p (machine_mode);
448 
449 protected:
450   machine_mode m_mode;
451 };
452 
453 /* Return true if M is a scalar_float_mode.  */
454 
455 inline bool
456 scalar_float_mode::includes_p (machine_mode m)
457 {
458   return SCALAR_FLOAT_MODE_P (m);
459 }
460 
461 /* Represents a machine mode that is known to be scalar.  */
462 class scalar_mode
463 {
464 public:
465   typedef mode_traits<scalar_mode>::from_int from_int;
466   typedef unsigned short measurement_type;
467 
468   ALWAYS_INLINE scalar_mode () {}
469 
470   ALWAYS_INLINE CONSTEXPR
471   scalar_mode (from_int m) : m_mode (machine_mode (m)) {}
472 
473   ALWAYS_INLINE CONSTEXPR
474   scalar_mode (const scalar_int_mode &m) : m_mode (m) {}
475 
476   ALWAYS_INLINE CONSTEXPR
477   scalar_mode (const scalar_float_mode &m) : m_mode (m) {}
478 
479   ALWAYS_INLINE CONSTEXPR
480   scalar_mode (const scalar_int_mode_pod &m) : m_mode (m) {}
481 
482   ALWAYS_INLINE CONSTEXPR operator machine_mode () const { return m_mode; }
483 
484   static bool includes_p (machine_mode);
485 
486 protected:
487   machine_mode m_mode;
488 };
489 
490 /* Return true if M represents some kind of scalar value.  */
491 
492 inline bool
493 scalar_mode::includes_p (machine_mode m)
494 {
495   switch (GET_MODE_CLASS (m))
496     {
497     case MODE_INT:
498     case MODE_PARTIAL_INT:
499     case MODE_FRACT:
500     case MODE_UFRACT:
501     case MODE_ACCUM:
502     case MODE_UACCUM:
503     case MODE_FLOAT:
504     case MODE_DECIMAL_FLOAT:
505       return true;
506     default:
507       return false;
508     }
509 }
510 
511 /* Represents a machine mode that is known to be a COMPLEX_MODE_P.  */
512 class complex_mode
513 {
514 public:
515   typedef mode_traits<complex_mode>::from_int from_int;
516   typedef unsigned short measurement_type;
517 
518   ALWAYS_INLINE complex_mode () {}
519 
520   ALWAYS_INLINE CONSTEXPR
521   complex_mode (from_int m) : m_mode (machine_mode (m)) {}
522 
523   ALWAYS_INLINE CONSTEXPR operator machine_mode () const { return m_mode; }
524 
525   static bool includes_p (machine_mode);
526 
527 protected:
528   machine_mode m_mode;
529 };
530 
531 /* Return true if M is a complex_mode.  */
532 
533 inline bool
534 complex_mode::includes_p (machine_mode m)
535 {
536   return COMPLEX_MODE_P (m);
537 }
538 
539 /* Return the base GET_MODE_SIZE value for MODE.  */
540 
541 ALWAYS_INLINE poly_uint16
542 mode_to_bytes (machine_mode mode)
543 {
544 #if GCC_VERSION >= 4001
545   return (__builtin_constant_p (mode)
546 	  ? mode_size_inline (mode) : mode_size[mode]);
547 #else
548   return mode_size[mode];
549 #endif
550 }
551 
552 /* Return the base GET_MODE_BITSIZE value for MODE.  */
553 
554 ALWAYS_INLINE poly_uint16
555 mode_to_bits (machine_mode mode)
556 {
557   return mode_to_bytes (mode) * BITS_PER_UNIT;
558 }
559 
560 /* Return the base GET_MODE_PRECISION value for MODE.  */
561 
562 ALWAYS_INLINE poly_uint16
563 mode_to_precision (machine_mode mode)
564 {
565   return mode_precision[mode];
566 }
567 
568 /* Return the base GET_MODE_INNER value for MODE.  */
569 
570 ALWAYS_INLINE scalar_mode
571 mode_to_inner (machine_mode mode)
572 {
573 #if GCC_VERSION >= 4001
574   return scalar_mode::from_int (__builtin_constant_p (mode)
575 				? mode_inner_inline (mode)
576 				: mode_inner[mode]);
577 #else
578   return scalar_mode::from_int (mode_inner[mode]);
579 #endif
580 }
581 
582 /* Return the base GET_MODE_UNIT_SIZE value for MODE.  */
583 
584 ALWAYS_INLINE unsigned char
585 mode_to_unit_size (machine_mode mode)
586 {
587 #if GCC_VERSION >= 4001
588   return (__builtin_constant_p (mode)
589 	  ? mode_unit_size_inline (mode) : mode_unit_size[mode]);
590 #else
591   return mode_unit_size[mode];
592 #endif
593 }
594 
595 /* Return the base GET_MODE_UNIT_PRECISION value for MODE.  */
596 
597 ALWAYS_INLINE unsigned short
598 mode_to_unit_precision (machine_mode mode)
599 {
600 #if GCC_VERSION >= 4001
601   return (__builtin_constant_p (mode)
602 	  ? mode_unit_precision_inline (mode) : mode_unit_precision[mode]);
603 #else
604   return mode_unit_precision[mode];
605 #endif
606 }
607 
608 /* Return the base GET_MODE_NUNITS value for MODE.  */
609 
610 ALWAYS_INLINE poly_uint16
611 mode_to_nunits (machine_mode mode)
612 {
613 #if GCC_VERSION >= 4001
614   return (__builtin_constant_p (mode)
615 	  ? mode_nunits_inline (mode) : mode_nunits[mode]);
616 #else
617   return mode_nunits[mode];
618 #endif
619 }
620 
621 /* Get the size in bytes of an object of mode MODE.  */
622 
623 #if ONLY_FIXED_SIZE_MODES
624 #define GET_MODE_SIZE(MODE) ((unsigned short) mode_to_bytes (MODE).coeffs[0])
625 #else
626 ALWAYS_INLINE poly_uint16
627 GET_MODE_SIZE (machine_mode mode)
628 {
629   return mode_to_bytes (mode);
630 }
631 
632 template<typename T>
633 ALWAYS_INLINE typename if_poly<typename T::measurement_type>::type
634 GET_MODE_SIZE (const T &mode)
635 {
636   return mode_to_bytes (mode);
637 }
638 
639 template<typename T>
640 ALWAYS_INLINE typename if_nonpoly<typename T::measurement_type>::type
641 GET_MODE_SIZE (const T &mode)
642 {
643   return mode_to_bytes (mode).coeffs[0];
644 }
645 #endif
646 
647 /* Get the size in bits of an object of mode MODE.  */
648 
649 #if ONLY_FIXED_SIZE_MODES
650 #define GET_MODE_BITSIZE(MODE) ((unsigned short) mode_to_bits (MODE).coeffs[0])
651 #else
652 ALWAYS_INLINE poly_uint16
653 GET_MODE_BITSIZE (machine_mode mode)
654 {
655   return mode_to_bits (mode);
656 }
657 
658 template<typename T>
659 ALWAYS_INLINE typename if_poly<typename T::measurement_type>::type
660 GET_MODE_BITSIZE (const T &mode)
661 {
662   return mode_to_bits (mode);
663 }
664 
665 template<typename T>
666 ALWAYS_INLINE typename if_nonpoly<typename T::measurement_type>::type
667 GET_MODE_BITSIZE (const T &mode)
668 {
669   return mode_to_bits (mode).coeffs[0];
670 }
671 #endif
672 
673 /* Get the number of value bits of an object of mode MODE.  */
674 
675 #if ONLY_FIXED_SIZE_MODES
676 #define GET_MODE_PRECISION(MODE) \
677   ((unsigned short) mode_to_precision (MODE).coeffs[0])
678 #else
679 ALWAYS_INLINE poly_uint16
680 GET_MODE_PRECISION (machine_mode mode)
681 {
682   return mode_to_precision (mode);
683 }
684 
685 template<typename T>
686 ALWAYS_INLINE typename if_poly<typename T::measurement_type>::type
687 GET_MODE_PRECISION (const T &mode)
688 {
689   return mode_to_precision (mode);
690 }
691 
692 template<typename T>
693 ALWAYS_INLINE typename if_nonpoly<typename T::measurement_type>::type
694 GET_MODE_PRECISION (const T &mode)
695 {
696   return mode_to_precision (mode).coeffs[0];
697 }
698 #endif
699 
700 /* Get the number of integral bits of an object of mode MODE.  */
701 extern CONST_MODE_IBIT unsigned char mode_ibit[NUM_MACHINE_MODES];
702 #define GET_MODE_IBIT(MODE) mode_ibit[MODE]
703 
704 /* Get the number of fractional bits of an object of mode MODE.  */
705 extern CONST_MODE_FBIT unsigned char mode_fbit[NUM_MACHINE_MODES];
706 #define GET_MODE_FBIT(MODE) mode_fbit[MODE]
707 
708 /* Get a bitmask containing 1 for all bits in a word
709    that fit within mode MODE.  */
710 
711 extern CONST_MODE_MASK unsigned HOST_WIDE_INT
712   mode_mask_array[NUM_MACHINE_MODES];
713 
714 #define GET_MODE_MASK(MODE) mode_mask_array[MODE]
715 
716 /* Return the mode of the basic parts of MODE.  For vector modes this is the
717    mode of the vector elements.  For complex modes it is the mode of the real
718    and imaginary parts.  For other modes it is MODE itself.  */
719 
720 #define GET_MODE_INNER(MODE) (mode_to_inner (MODE))
721 
722 /* Get the size in bytes or bits of the basic parts of an
723    object of mode MODE.  */
724 
725 #define GET_MODE_UNIT_SIZE(MODE) mode_to_unit_size (MODE)
726 
727 #define GET_MODE_UNIT_BITSIZE(MODE) \
728   ((unsigned short) (GET_MODE_UNIT_SIZE (MODE) * BITS_PER_UNIT))
729 
730 #define GET_MODE_UNIT_PRECISION(MODE) (mode_to_unit_precision (MODE))
731 
732 /* Get the number of units in an object of mode MODE.  This is 2 for
733    complex modes and the number of elements for vector modes.  */
734 
735 #if ONLY_FIXED_SIZE_MODES
736 #define GET_MODE_NUNITS(MODE) (mode_to_nunits (MODE).coeffs[0])
737 #else
738 ALWAYS_INLINE poly_uint16
739 GET_MODE_NUNITS (machine_mode mode)
740 {
741   return mode_to_nunits (mode);
742 }
743 
744 template<typename T>
745 ALWAYS_INLINE typename if_poly<typename T::measurement_type>::type
746 GET_MODE_NUNITS (const T &mode)
747 {
748   return mode_to_nunits (mode);
749 }
750 
751 template<typename T>
752 ALWAYS_INLINE typename if_nonpoly<typename T::measurement_type>::type
753 GET_MODE_NUNITS (const T &mode)
754 {
755   return mode_to_nunits (mode).coeffs[0];
756 }
757 #endif
758 
759 /* Get the next wider natural mode (eg, QI -> HI -> SI -> DI -> TI).  */
760 
761 template<typename T>
762 ALWAYS_INLINE opt_mode<T>
763 GET_MODE_WIDER_MODE (const T &m)
764 {
765   return typename opt_mode<T>::from_int (mode_wider[m]);
766 }
767 
768 /* For scalars, this is a mode with twice the precision.  For vectors,
769    this is a mode with the same inner mode but with twice the elements.  */
770 
771 template<typename T>
772 ALWAYS_INLINE opt_mode<T>
773 GET_MODE_2XWIDER_MODE (const T &m)
774 {
775   return typename opt_mode<T>::from_int (mode_2xwider[m]);
776 }
777 
778 /* Get the complex mode from the component mode.  */
779 extern const unsigned char mode_complex[NUM_MACHINE_MODES];
780 #define GET_MODE_COMPLEX_MODE(MODE) ((machine_mode) mode_complex[MODE])
781 
782 /* Represents a machine mode that must have a fixed size.  The main
783    use of this class is to represent the modes of objects that always
784    have static storage duration, such as constant pool entries.
785    (No current target supports the concept of variable-size static data.)  */
786 class fixed_size_mode
787 {
788 public:
789   typedef mode_traits<fixed_size_mode>::from_int from_int;
790   typedef unsigned short measurement_type;
791 
792   ALWAYS_INLINE fixed_size_mode () {}
793 
794   ALWAYS_INLINE CONSTEXPR
795   fixed_size_mode (from_int m) : m_mode (machine_mode (m)) {}
796 
797   ALWAYS_INLINE CONSTEXPR
798   fixed_size_mode (const scalar_mode &m) : m_mode (m) {}
799 
800   ALWAYS_INLINE CONSTEXPR
801   fixed_size_mode (const scalar_int_mode &m) : m_mode (m) {}
802 
803   ALWAYS_INLINE CONSTEXPR
804   fixed_size_mode (const scalar_float_mode &m) : m_mode (m) {}
805 
806   ALWAYS_INLINE CONSTEXPR
807   fixed_size_mode (const scalar_mode_pod &m) : m_mode (m) {}
808 
809   ALWAYS_INLINE CONSTEXPR
810   fixed_size_mode (const scalar_int_mode_pod &m) : m_mode (m) {}
811 
812   ALWAYS_INLINE CONSTEXPR
813   fixed_size_mode (const complex_mode &m) : m_mode (m) {}
814 
815   ALWAYS_INLINE CONSTEXPR operator machine_mode () const { return m_mode; }
816 
817   static bool includes_p (machine_mode);
818 
819 protected:
820   machine_mode m_mode;
821 };
822 
823 /* Return true if MODE has a fixed size.  */
824 
825 inline bool
826 fixed_size_mode::includes_p (machine_mode mode)
827 {
828   return mode_to_bytes (mode).is_constant ();
829 }
830 
831 /* Wrapper for mode arguments to target macros, so that if a target
832    doesn't need polynomial-sized modes, its header file can continue
833    to treat everything as fixed_size_mode.  This should go away once
834    macros are moved to target hooks.  It shouldn't be used in other
835    contexts.  */
836 #if NUM_POLY_INT_COEFFS == 1
837 #define MACRO_MODE(MODE) (as_a <fixed_size_mode> (MODE))
838 #else
839 #define MACRO_MODE(MODE) (MODE)
840 #endif
841 
842 extern opt_machine_mode mode_for_size (poly_uint64, enum mode_class, int);
843 
844 /* Return the machine mode to use for a MODE_INT of SIZE bits, if one
845    exists.  If LIMIT is nonzero, modes wider than MAX_FIXED_MODE_SIZE
846    will not be used.  */
847 
848 inline opt_scalar_int_mode
849 int_mode_for_size (poly_uint64 size, int limit)
850 {
851   return dyn_cast <scalar_int_mode> (mode_for_size (size, MODE_INT, limit));
852 }
853 
854 /* Return the machine mode to use for a MODE_FLOAT of SIZE bits, if one
855    exists.  */
856 
857 inline opt_scalar_float_mode
858 float_mode_for_size (poly_uint64 size)
859 {
860   return dyn_cast <scalar_float_mode> (mode_for_size (size, MODE_FLOAT, 0));
861 }
862 
863 /* Likewise for MODE_DECIMAL_FLOAT.  */
864 
865 inline opt_scalar_float_mode
866 decimal_float_mode_for_size (unsigned int size)
867 {
868   return dyn_cast <scalar_float_mode>
869     (mode_for_size (size, MODE_DECIMAL_FLOAT, 0));
870 }
871 
872 extern machine_mode smallest_mode_for_size (poly_uint64, enum mode_class);
873 
874 /* Find the narrowest integer mode that contains at least SIZE bits.
875    Such a mode must exist.  */
876 
877 inline scalar_int_mode
878 smallest_int_mode_for_size (poly_uint64 size)
879 {
880   return as_a <scalar_int_mode> (smallest_mode_for_size (size, MODE_INT));
881 }
882 
883 extern opt_scalar_int_mode int_mode_for_mode (machine_mode);
884 extern opt_machine_mode bitwise_mode_for_mode (machine_mode);
885 extern opt_machine_mode mode_for_vector (scalar_mode, poly_uint64);
886 extern opt_machine_mode related_vector_mode (machine_mode, scalar_mode,
887 					     poly_uint64 = 0);
888 extern opt_machine_mode related_int_vector_mode (machine_mode);
889 
890 /* A class for iterating through possible bitfield modes.  */
891 class bit_field_mode_iterator
892 {
893 public:
894   bit_field_mode_iterator (HOST_WIDE_INT, HOST_WIDE_INT,
895 			   poly_int64, poly_int64,
896 			   unsigned int, bool);
897   bool next_mode (scalar_int_mode *);
898   bool prefer_smaller_modes ();
899 
900 private:
901   opt_scalar_int_mode m_mode;
902   /* We use signed values here because the bit position can be negative
903      for invalid input such as gcc.dg/pr48335-8.c.  */
904   HOST_WIDE_INT m_bitsize;
905   HOST_WIDE_INT m_bitpos;
906   poly_int64 m_bitregion_start;
907   poly_int64 m_bitregion_end;
908   unsigned int m_align;
909   bool m_volatilep;
910   int m_count;
911 };
912 
913 /* Find the best mode to use to access a bit field.  */
914 
915 extern bool get_best_mode (int, int, poly_uint64, poly_uint64, unsigned int,
916 			   unsigned HOST_WIDE_INT, bool, scalar_int_mode *);
917 
918 /* Determine alignment, 1<=result<=BIGGEST_ALIGNMENT.  */
919 
920 extern CONST_MODE_BASE_ALIGN unsigned short mode_base_align[NUM_MACHINE_MODES];
921 
922 extern unsigned get_mode_alignment (machine_mode);
923 
924 #define GET_MODE_ALIGNMENT(MODE) get_mode_alignment (MODE)
925 
926 /* For each class, get the narrowest mode in that class.  */
927 
928 extern const unsigned char class_narrowest_mode[MAX_MODE_CLASS];
929 #define GET_CLASS_NARROWEST_MODE(CLASS) \
930   ((machine_mode) class_narrowest_mode[CLASS])
931 
932 /* The narrowest full integer mode available on the target.  */
933 
934 #define NARROWEST_INT_MODE \
935   (scalar_int_mode \
936    (scalar_int_mode::from_int (class_narrowest_mode[MODE_INT])))
937 
938 /* Return the narrowest mode in T's class.  */
939 
940 template<typename T>
941 inline T
942 get_narrowest_mode (T mode)
943 {
944   return typename mode_traits<T>::from_int
945     (class_narrowest_mode[GET_MODE_CLASS (mode)]);
946 }
947 
948 /* Define the integer modes whose sizes are BITS_PER_UNIT and BITS_PER_WORD
949    and the mode whose class is Pmode and whose size is POINTER_SIZE.  */
950 
951 extern scalar_int_mode byte_mode;
952 extern scalar_int_mode word_mode;
953 extern scalar_int_mode ptr_mode;
954 
955 /* Target-dependent machine mode initialization - in insn-modes.c.  */
956 extern void init_adjust_machine_modes (void);
957 
958 #define TRULY_NOOP_TRUNCATION_MODES_P(MODE1, MODE2) \
959   (targetm.truly_noop_truncation (GET_MODE_PRECISION (MODE1), \
960 				  GET_MODE_PRECISION (MODE2)))
961 
962 /* Return true if MODE is a scalar integer mode that fits in a
963    HOST_WIDE_INT.  */
964 
965 inline bool
966 HWI_COMPUTABLE_MODE_P (machine_mode mode)
967 {
968   machine_mode mme = mode;
969   return (SCALAR_INT_MODE_P (mme)
970 	  && mode_to_precision (mme).coeffs[0] <= HOST_BITS_PER_WIDE_INT);
971 }
972 
973 inline bool
974 HWI_COMPUTABLE_MODE_P (scalar_int_mode mode)
975 {
976   return GET_MODE_PRECISION (mode) <= HOST_BITS_PER_WIDE_INT;
977 }
978 
979 struct int_n_data_t {
980   /* These parts are initailized by genmodes output */
981   unsigned int bitsize;
982   scalar_int_mode_pod m;
983   /* RID_* is RID_INTN_BASE + index into this array */
984 };
985 
986 /* This is also in tree.h.  genmodes.c guarantees the're sorted from
987    smallest bitsize to largest bitsize. */
988 extern bool int_n_enabled_p[NUM_INT_N_ENTS];
989 extern const int_n_data_t int_n_data[NUM_INT_N_ENTS];
990 
991 /* Return true if MODE has class MODE_INT, storing it as a scalar_int_mode
992    in *INT_MODE if so.  */
993 
994 template<typename T>
995 inline bool
996 is_int_mode (machine_mode mode, T *int_mode)
997 {
998   if (GET_MODE_CLASS (mode) == MODE_INT)
999     {
1000       *int_mode = scalar_int_mode (scalar_int_mode::from_int (mode));
1001       return true;
1002     }
1003   return false;
1004 }
1005 
1006 /* Return true if MODE has class MODE_FLOAT, storing it as a
1007    scalar_float_mode in *FLOAT_MODE if so.  */
1008 
1009 template<typename T>
1010 inline bool
1011 is_float_mode (machine_mode mode, T *float_mode)
1012 {
1013   if (GET_MODE_CLASS (mode) == MODE_FLOAT)
1014     {
1015       *float_mode = scalar_float_mode (scalar_float_mode::from_int (mode));
1016       return true;
1017     }
1018   return false;
1019 }
1020 
1021 /* Return true if MODE has class MODE_COMPLEX_INT, storing it as
1022    a complex_mode in *CMODE if so.  */
1023 
1024 template<typename T>
1025 inline bool
1026 is_complex_int_mode (machine_mode mode, T *cmode)
1027 {
1028   if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
1029     {
1030       *cmode = complex_mode (complex_mode::from_int (mode));
1031       return true;
1032     }
1033   return false;
1034 }
1035 
1036 /* Return true if MODE has class MODE_COMPLEX_FLOAT, storing it as
1037    a complex_mode in *CMODE if so.  */
1038 
1039 template<typename T>
1040 inline bool
1041 is_complex_float_mode (machine_mode mode, T *cmode)
1042 {
1043   if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
1044     {
1045       *cmode = complex_mode (complex_mode::from_int (mode));
1046       return true;
1047     }
1048   return false;
1049 }
1050 
1051 /* Return true if MODE is a scalar integer mode with a precision
1052    smaller than LIMIT's precision.  */
1053 
1054 inline bool
1055 is_narrower_int_mode (machine_mode mode, scalar_int_mode limit)
1056 {
1057   scalar_int_mode int_mode;
1058   return (is_a <scalar_int_mode> (mode, &int_mode)
1059 	  && GET_MODE_PRECISION (int_mode) < GET_MODE_PRECISION (limit));
1060 }
1061 
1062 namespace mode_iterator
1063 {
1064   /* Start mode iterator *ITER at the first mode in class MCLASS, if any.  */
1065 
1066   template<typename T>
1067   inline void
1068   start (opt_mode<T> *iter, enum mode_class mclass)
1069   {
1070     if (GET_CLASS_NARROWEST_MODE (mclass) == E_VOIDmode)
1071       *iter = opt_mode<T> ();
1072     else
1073       *iter = as_a<T> (GET_CLASS_NARROWEST_MODE (mclass));
1074   }
1075 
1076   inline void
1077   start (machine_mode *iter, enum mode_class mclass)
1078   {
1079     *iter = GET_CLASS_NARROWEST_MODE (mclass);
1080   }
1081 
1082   /* Return true if mode iterator *ITER has not reached the end.  */
1083 
1084   template<typename T>
1085   inline bool
1086   iterate_p (opt_mode<T> *iter)
1087   {
1088     return iter->exists ();
1089   }
1090 
1091   inline bool
1092   iterate_p (machine_mode *iter)
1093   {
1094     return *iter != E_VOIDmode;
1095   }
1096 
1097   /* Set mode iterator *ITER to the next widest mode in the same class,
1098      if any.  */
1099 
1100   template<typename T>
1101   inline void
1102   get_wider (opt_mode<T> *iter)
1103   {
1104     *iter = GET_MODE_WIDER_MODE (iter->require ());
1105   }
1106 
1107   inline void
1108   get_wider (machine_mode *iter)
1109   {
1110     *iter = GET_MODE_WIDER_MODE (*iter).else_void ();
1111   }
1112 
1113   /* Set mode iterator *ITER to the next widest mode in the same class.
1114      Such a mode is known to exist.  */
1115 
1116   template<typename T>
1117   inline void
1118   get_known_wider (T *iter)
1119   {
1120     *iter = GET_MODE_WIDER_MODE (*iter).require ();
1121   }
1122 
1123   /* Set mode iterator *ITER to the mode that is two times wider than the
1124      current one, if such a mode exists.  */
1125 
1126   template<typename T>
1127   inline void
1128   get_2xwider (opt_mode<T> *iter)
1129   {
1130     *iter = GET_MODE_2XWIDER_MODE (iter->require ());
1131   }
1132 
1133   inline void
1134   get_2xwider (machine_mode *iter)
1135   {
1136     *iter = GET_MODE_2XWIDER_MODE (*iter).else_void ();
1137   }
1138 }
1139 
1140 /* Make ITERATOR iterate over all the modes in mode class CLASS,
1141    from narrowest to widest.  */
1142 #define FOR_EACH_MODE_IN_CLASS(ITERATOR, CLASS)  \
1143   for (mode_iterator::start (&(ITERATOR), CLASS); \
1144        mode_iterator::iterate_p (&(ITERATOR)); \
1145        mode_iterator::get_wider (&(ITERATOR)))
1146 
1147 /* Make ITERATOR iterate over all the modes in the range [START, END),
1148    in order of increasing width.  */
1149 #define FOR_EACH_MODE(ITERATOR, START, END) \
1150   for ((ITERATOR) = (START); \
1151        (ITERATOR) != (END); \
1152        mode_iterator::get_known_wider (&(ITERATOR)))
1153 
1154 /* Make ITERATOR iterate over START and all wider modes in the same
1155    class, in order of increasing width.  */
1156 #define FOR_EACH_MODE_FROM(ITERATOR, START) \
1157   for ((ITERATOR) = (START); \
1158        mode_iterator::iterate_p (&(ITERATOR)); \
1159        mode_iterator::get_wider (&(ITERATOR)))
1160 
1161 /* Make ITERATOR iterate over modes in the range [NARROWEST, END)
1162    in order of increasing width, where NARROWEST is the narrowest mode
1163    in END's class.  */
1164 #define FOR_EACH_MODE_UNTIL(ITERATOR, END) \
1165   FOR_EACH_MODE (ITERATOR, get_narrowest_mode (END), END)
1166 
1167 /* Make ITERATOR iterate over modes in the same class as MODE, in order
1168    of increasing width.  Start at the first mode wider than START,
1169    or don't iterate at all if there is no wider mode.  */
1170 #define FOR_EACH_WIDER_MODE(ITERATOR, START) \
1171   for ((ITERATOR) = (START), mode_iterator::get_wider (&(ITERATOR)); \
1172        mode_iterator::iterate_p (&(ITERATOR)); \
1173        mode_iterator::get_wider (&(ITERATOR)))
1174 
1175 /* Make ITERATOR iterate over modes in the same class as MODE, in order
1176    of increasing width, and with each mode being twice the width of the
1177    previous mode.  Start at the mode that is two times wider than START,
1178    or don't iterate at all if there is no such mode.  */
1179 #define FOR_EACH_2XWIDER_MODE(ITERATOR, START) \
1180   for ((ITERATOR) = (START), mode_iterator::get_2xwider (&(ITERATOR)); \
1181        mode_iterator::iterate_p (&(ITERATOR)); \
1182        mode_iterator::get_2xwider (&(ITERATOR)))
1183 
1184 template<typename T>
1185 void
1186 gt_ggc_mx (pod_mode<T> *)
1187 {
1188 }
1189 
1190 template<typename T>
1191 void
1192 gt_pch_nx (pod_mode<T> *)
1193 {
1194 }
1195 
1196 template<typename T>
1197 void
1198 gt_pch_nx (pod_mode<T> *, void (*) (void *, void *), void *)
1199 {
1200 }
1201 
1202 #endif /* not HAVE_MACHINE_MODES */
1203