[3/77] Allow machine modes to be classes
[official-gcc.git] / gcc / machmode.h
blob330fdf9e6b1de1ac82eaf3cb8cbfdc3b1993f4bd
1 /* Machine mode definitions for GCC; included by rtl.h and tree.h.
2 Copyright (C) 1991-2017 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef HAVE_MACHINE_MODES
21 #define HAVE_MACHINE_MODES
23 extern CONST_MODE_SIZE unsigned short mode_size[NUM_MACHINE_MODES];
24 extern const unsigned short mode_precision[NUM_MACHINE_MODES];
25 extern const unsigned char mode_inner[NUM_MACHINE_MODES];
26 extern const unsigned char mode_nunits[NUM_MACHINE_MODES];
27 extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES];
28 extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES];
29 extern const unsigned char mode_wider[NUM_MACHINE_MODES];
30 extern const unsigned char mode_2xwider[NUM_MACHINE_MODES];
32 /* Get the name of mode MODE as a string. */
34 extern const char * const mode_name[NUM_MACHINE_MODES];
35 #define GET_MODE_NAME(MODE) mode_name[MODE]
37 /* Mode classes. */
39 #include "mode-classes.def"
40 #define DEF_MODE_CLASS(M) M
41 enum mode_class { MODE_CLASSES, MAX_MODE_CLASS };
42 #undef DEF_MODE_CLASS
43 #undef MODE_CLASSES
45 /* Get the general kind of object that mode MODE represents
46 (integer, floating, complex, etc.) */
48 extern const unsigned char mode_class[NUM_MACHINE_MODES];
49 #define GET_MODE_CLASS(MODE) ((enum mode_class) mode_class[MODE])
51 /* Nonzero if MODE is an integral mode. */
52 #define INTEGRAL_MODE_P(MODE) \
53 (GET_MODE_CLASS (MODE) == MODE_INT \
54 || GET_MODE_CLASS (MODE) == MODE_PARTIAL_INT \
55 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_INT \
56 || GET_MODE_CLASS (MODE) == MODE_VECTOR_INT)
58 /* Nonzero if MODE is a floating-point mode. */
59 #define FLOAT_MODE_P(MODE) \
60 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
61 || GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT \
62 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT \
63 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT)
65 /* Nonzero if MODE is a complex mode. */
66 #define COMPLEX_MODE_P(MODE) \
67 (GET_MODE_CLASS (MODE) == MODE_COMPLEX_INT \
68 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT)
70 /* Nonzero if MODE is a vector mode. */
71 #define VECTOR_MODE_P(MODE) \
72 (GET_MODE_CLASS (MODE) == MODE_VECTOR_INT \
73 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT \
74 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FRACT \
75 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UFRACT \
76 || GET_MODE_CLASS (MODE) == MODE_VECTOR_ACCUM \
77 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UACCUM)
79 /* Nonzero if MODE is a scalar integral mode. */
80 #define SCALAR_INT_MODE_P(MODE) \
81 (GET_MODE_CLASS (MODE) == MODE_INT \
82 || GET_MODE_CLASS (MODE) == MODE_PARTIAL_INT)
84 /* Nonzero if MODE is a scalar floating point mode. */
85 #define SCALAR_FLOAT_MODE_P(MODE) \
86 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
87 || GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT)
89 /* Nonzero if MODE is a decimal floating point mode. */
90 #define DECIMAL_FLOAT_MODE_P(MODE) \
91 (GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT)
93 /* Nonzero if MODE is a scalar fract mode. */
94 #define SCALAR_FRACT_MODE_P(MODE) \
95 (GET_MODE_CLASS (MODE) == MODE_FRACT)
97 /* Nonzero if MODE is a scalar ufract mode. */
98 #define SCALAR_UFRACT_MODE_P(MODE) \
99 (GET_MODE_CLASS (MODE) == MODE_UFRACT)
101 /* Nonzero if MODE is a scalar fract or ufract mode. */
102 #define ALL_SCALAR_FRACT_MODE_P(MODE) \
103 (SCALAR_FRACT_MODE_P (MODE) || SCALAR_UFRACT_MODE_P (MODE))
105 /* Nonzero if MODE is a scalar accum mode. */
106 #define SCALAR_ACCUM_MODE_P(MODE) \
107 (GET_MODE_CLASS (MODE) == MODE_ACCUM)
109 /* Nonzero if MODE is a scalar uaccum mode. */
110 #define SCALAR_UACCUM_MODE_P(MODE) \
111 (GET_MODE_CLASS (MODE) == MODE_UACCUM)
113 /* Nonzero if MODE is a scalar accum or uaccum mode. */
114 #define ALL_SCALAR_ACCUM_MODE_P(MODE) \
115 (SCALAR_ACCUM_MODE_P (MODE) || SCALAR_UACCUM_MODE_P (MODE))
117 /* Nonzero if MODE is a scalar fract or accum mode. */
118 #define SIGNED_SCALAR_FIXED_POINT_MODE_P(MODE) \
119 (SCALAR_FRACT_MODE_P (MODE) || SCALAR_ACCUM_MODE_P (MODE))
121 /* Nonzero if MODE is a scalar ufract or uaccum mode. */
122 #define UNSIGNED_SCALAR_FIXED_POINT_MODE_P(MODE) \
123 (SCALAR_UFRACT_MODE_P (MODE) || SCALAR_UACCUM_MODE_P (MODE))
125 /* Nonzero if MODE is a scalar fract, ufract, accum or uaccum mode. */
126 #define ALL_SCALAR_FIXED_POINT_MODE_P(MODE) \
127 (SIGNED_SCALAR_FIXED_POINT_MODE_P (MODE) \
128 || UNSIGNED_SCALAR_FIXED_POINT_MODE_P (MODE))
130 /* Nonzero if MODE is a scalar/vector fract mode. */
131 #define FRACT_MODE_P(MODE) \
132 (GET_MODE_CLASS (MODE) == MODE_FRACT \
133 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FRACT)
135 /* Nonzero if MODE is a scalar/vector ufract mode. */
136 #define UFRACT_MODE_P(MODE) \
137 (GET_MODE_CLASS (MODE) == MODE_UFRACT \
138 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UFRACT)
140 /* Nonzero if MODE is a scalar/vector fract or ufract mode. */
141 #define ALL_FRACT_MODE_P(MODE) \
142 (FRACT_MODE_P (MODE) || UFRACT_MODE_P (MODE))
144 /* Nonzero if MODE is a scalar/vector accum mode. */
145 #define ACCUM_MODE_P(MODE) \
146 (GET_MODE_CLASS (MODE) == MODE_ACCUM \
147 || GET_MODE_CLASS (MODE) == MODE_VECTOR_ACCUM)
149 /* Nonzero if MODE is a scalar/vector uaccum mode. */
150 #define UACCUM_MODE_P(MODE) \
151 (GET_MODE_CLASS (MODE) == MODE_UACCUM \
152 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UACCUM)
154 /* Nonzero if MODE is a scalar/vector accum or uaccum mode. */
155 #define ALL_ACCUM_MODE_P(MODE) \
156 (ACCUM_MODE_P (MODE) || UACCUM_MODE_P (MODE))
158 /* Nonzero if MODE is a scalar/vector fract or accum mode. */
159 #define SIGNED_FIXED_POINT_MODE_P(MODE) \
160 (FRACT_MODE_P (MODE) || ACCUM_MODE_P (MODE))
162 /* Nonzero if MODE is a scalar/vector ufract or uaccum mode. */
163 #define UNSIGNED_FIXED_POINT_MODE_P(MODE) \
164 (UFRACT_MODE_P (MODE) || UACCUM_MODE_P (MODE))
166 /* Nonzero if MODE is a scalar/vector fract, ufract, accum or uaccum mode. */
167 #define ALL_FIXED_POINT_MODE_P(MODE) \
168 (SIGNED_FIXED_POINT_MODE_P (MODE) \
169 || UNSIGNED_FIXED_POINT_MODE_P (MODE))
171 /* Nonzero if CLASS modes can be widened. */
172 #define CLASS_HAS_WIDER_MODES_P(CLASS) \
173 (CLASS == MODE_INT \
174 || CLASS == MODE_PARTIAL_INT \
175 || CLASS == MODE_FLOAT \
176 || CLASS == MODE_DECIMAL_FLOAT \
177 || CLASS == MODE_COMPLEX_FLOAT \
178 || CLASS == MODE_FRACT \
179 || CLASS == MODE_UFRACT \
180 || CLASS == MODE_ACCUM \
181 || CLASS == MODE_UACCUM)
183 #define POINTER_BOUNDS_MODE_P(MODE) \
184 (GET_MODE_CLASS (MODE) == MODE_POINTER_BOUNDS)
186 /* Return the base GET_MODE_SIZE value for MODE. */
188 ALWAYS_INLINE unsigned short
189 mode_to_bytes (machine_mode mode)
191 #if GCC_VERSION >= 4001
192 return (__builtin_constant_p (mode)
193 ? mode_size_inline (mode) : mode_size[mode]);
194 #else
195 return mode_size[mode];
196 #endif
199 /* Return the base GET_MODE_BITSIZE value for MODE. */
201 ALWAYS_INLINE unsigned short
202 mode_to_bits (machine_mode mode)
204 return mode_to_bytes (mode) * BITS_PER_UNIT;
207 /* Return the base GET_MODE_PRECISION value for MODE. */
209 ALWAYS_INLINE unsigned short
210 mode_to_precision (machine_mode mode)
212 return mode_precision[mode];
215 /* Return the base GET_MODE_INNER value for MODE. */
217 ALWAYS_INLINE machine_mode
218 mode_to_inner (machine_mode mode)
220 #if GCC_VERSION >= 4001
221 return (machine_mode) (__builtin_constant_p (mode)
222 ? mode_inner_inline (mode) : mode_inner[mode]);
223 #else
224 return (machine_mode) mode_inner[mode];
225 #endif
228 /* Return the base GET_MODE_UNIT_SIZE value for MODE. */
230 ALWAYS_INLINE unsigned char
231 mode_to_unit_size (machine_mode mode)
233 #if GCC_VERSION >= 4001
234 return (__builtin_constant_p (mode)
235 ? mode_unit_size_inline (mode) : mode_unit_size[mode]);
236 #else
237 return mode_unit_size[mode];
238 #endif
241 /* Return the base GET_MODE_UNIT_PRECISION value for MODE. */
243 ALWAYS_INLINE unsigned short
244 mode_to_unit_precision (machine_mode mode)
246 #if GCC_VERSION >= 4001
247 return (__builtin_constant_p (mode)
248 ? mode_unit_precision_inline (mode) : mode_unit_precision[mode]);
249 #else
250 return mode_unit_precision[mode];
251 #endif
254 /* Return the base GET_MODE_NUNITS value for MODE. */
256 ALWAYS_INLINE unsigned short
257 mode_to_nunits (machine_mode mode)
259 #if GCC_VERSION >= 4001
260 return (__builtin_constant_p (mode)
261 ? mode_nunits_inline (mode) : mode_nunits[mode]);
262 #else
263 return mode_nunits[mode];
264 #endif
267 /* Get the size in bytes of an object of mode MODE. */
269 #define GET_MODE_SIZE(MODE) (mode_to_bytes (MODE))
271 /* Get the size in bits of an object of mode MODE. */
273 #define GET_MODE_BITSIZE(MODE) (mode_to_bits (MODE))
275 /* Get the number of value bits of an object of mode MODE. */
277 #define GET_MODE_PRECISION(MODE) (mode_to_precision (MODE))
279 /* Get the number of integral bits of an object of mode MODE. */
280 extern CONST_MODE_IBIT unsigned char mode_ibit[NUM_MACHINE_MODES];
281 #define GET_MODE_IBIT(MODE) mode_ibit[MODE]
283 /* Get the number of fractional bits of an object of mode MODE. */
284 extern CONST_MODE_FBIT unsigned char mode_fbit[NUM_MACHINE_MODES];
285 #define GET_MODE_FBIT(MODE) mode_fbit[MODE]
287 /* Get a bitmask containing 1 for all bits in a word
288 that fit within mode MODE. */
290 extern const unsigned HOST_WIDE_INT mode_mask_array[NUM_MACHINE_MODES];
292 #define GET_MODE_MASK(MODE) mode_mask_array[MODE]
294 /* Return the mode of the basic parts of MODE. For vector modes this is the
295 mode of the vector elements. For complex modes it is the mode of the real
296 and imaginary parts. For other modes it is MODE itself. */
298 #define GET_MODE_INNER(MODE) (mode_to_inner (MODE))
300 /* Get the size in bytes or bits of the basic parts of an
301 object of mode MODE. */
303 #define GET_MODE_UNIT_SIZE(MODE) mode_to_unit_size (MODE)
305 #define GET_MODE_UNIT_BITSIZE(MODE) \
306 ((unsigned short) (GET_MODE_UNIT_SIZE (MODE) * BITS_PER_UNIT))
308 #define GET_MODE_UNIT_PRECISION(MODE) (mode_to_unit_precision (MODE))
310 /* Get the number of units in an object of mode MODE. This is 2 for
311 complex modes and the number of elements for vector modes. */
313 #define GET_MODE_NUNITS(MODE) (mode_to_nunits (MODE))
315 /* Get the next wider natural mode (eg, QI -> HI -> SI -> DI -> TI). */
317 extern const unsigned char mode_wider[NUM_MACHINE_MODES];
318 #define GET_MODE_WIDER_MODE(MODE) ((machine_mode) mode_wider[MODE])
320 /* For scalars, this is a mode with twice the precision. For vectors,
321 this is a mode with the same inner mode but with twice the elements. */
322 extern const unsigned char mode_2xwider[NUM_MACHINE_MODES];
323 #define GET_MODE_2XWIDER_MODE(MODE) ((machine_mode) mode_2xwider[MODE])
325 /* Get the complex mode from the component mode. */
326 extern const unsigned char mode_complex[NUM_MACHINE_MODES];
327 #define GET_MODE_COMPLEX_MODE(MODE) ((machine_mode) mode_complex[MODE])
329 /* Return the mode for data of a given size SIZE and mode class CLASS.
330 If LIMIT is nonzero, then don't use modes bigger than MAX_FIXED_MODE_SIZE.
331 The value is BLKmode if no other mode is found. */
333 extern machine_mode mode_for_size (unsigned int, enum mode_class, int);
335 /* Similar, but find the smallest mode for a given width. */
337 extern machine_mode smallest_mode_for_size (unsigned int,
338 enum mode_class);
341 /* Return an integer mode of the exact same size as the input mode,
342 or BLKmode on failure. */
344 extern machine_mode int_mode_for_mode (machine_mode);
346 extern machine_mode bitwise_mode_for_mode (machine_mode);
348 /* Return a mode that is suitable for representing a vector,
349 or BLKmode on failure. */
351 extern machine_mode mode_for_vector (machine_mode, unsigned);
353 /* A class for iterating through possible bitfield modes. */
354 class bit_field_mode_iterator
356 public:
357 bit_field_mode_iterator (HOST_WIDE_INT, HOST_WIDE_INT,
358 HOST_WIDE_INT, HOST_WIDE_INT,
359 unsigned int, bool);
360 bool next_mode (machine_mode *);
361 bool prefer_smaller_modes ();
363 private:
364 machine_mode m_mode;
365 /* We use signed values here because the bit position can be negative
366 for invalid input such as gcc.dg/pr48335-8.c. */
367 HOST_WIDE_INT m_bitsize;
368 HOST_WIDE_INT m_bitpos;
369 HOST_WIDE_INT m_bitregion_start;
370 HOST_WIDE_INT m_bitregion_end;
371 unsigned int m_align;
372 bool m_volatilep;
373 int m_count;
376 /* Find the best mode to use to access a bit field. */
378 extern machine_mode get_best_mode (int, int,
379 unsigned HOST_WIDE_INT,
380 unsigned HOST_WIDE_INT,
381 unsigned int,
382 machine_mode, bool);
384 /* Determine alignment, 1<=result<=BIGGEST_ALIGNMENT. */
386 extern CONST_MODE_BASE_ALIGN unsigned short mode_base_align[NUM_MACHINE_MODES];
388 extern unsigned get_mode_alignment (machine_mode);
390 #define GET_MODE_ALIGNMENT(MODE) get_mode_alignment (MODE)
392 /* For each class, get the narrowest mode in that class. */
394 extern const unsigned char class_narrowest_mode[MAX_MODE_CLASS];
395 #define GET_CLASS_NARROWEST_MODE(CLASS) \
396 ((machine_mode) class_narrowest_mode[CLASS])
398 /* Define the integer modes whose sizes are BITS_PER_UNIT and BITS_PER_WORD
399 and the mode whose class is Pmode and whose size is POINTER_SIZE. */
401 extern machine_mode byte_mode;
402 extern machine_mode word_mode;
403 extern machine_mode ptr_mode;
405 /* Target-dependent machine mode initialization - in insn-modes.c. */
406 extern void init_adjust_machine_modes (void);
408 #define TRULY_NOOP_TRUNCATION_MODES_P(MODE1, MODE2) \
409 TRULY_NOOP_TRUNCATION (GET_MODE_PRECISION (MODE1), \
410 GET_MODE_PRECISION (MODE2))
412 #define HWI_COMPUTABLE_MODE_P(MODE) \
413 (SCALAR_INT_MODE_P (MODE) \
414 && GET_MODE_PRECISION (MODE) <= HOST_BITS_PER_WIDE_INT)
416 struct int_n_data_t {
417 /* These parts are initailized by genmodes output */
418 unsigned int bitsize;
419 machine_mode m;
420 /* RID_* is RID_INTN_BASE + index into this array */
423 /* This is also in tree.h. genmodes.c guarantees the're sorted from
424 smallest bitsize to largest bitsize. */
425 extern bool int_n_enabled_p[NUM_INT_N_ENTS];
426 extern const int_n_data_t int_n_data[NUM_INT_N_ENTS];
428 #endif /* not HAVE_MACHINE_MODES */