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