i386: Rewrite check for AVX512 features
[official-gcc.git] / gcc / machmode.h
blob4b861ac41dd3f9b92b50bd73ec372aa2b571914e
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 /* Get the name of mode MODE as a string. */
25 extern const char * const mode_name[NUM_MACHINE_MODES];
26 #define GET_MODE_NAME(MODE) mode_name[MODE]
28 /* Mode classes. */
30 #include "mode-classes.def"
31 #define DEF_MODE_CLASS(M) M
32 enum mode_class { MODE_CLASSES, MAX_MODE_CLASS };
33 #undef DEF_MODE_CLASS
34 #undef MODE_CLASSES
36 /* Get the general kind of object that mode MODE represents
37 (integer, floating, complex, etc.) */
39 extern const unsigned char mode_class[NUM_MACHINE_MODES];
40 #define GET_MODE_CLASS(MODE) ((enum mode_class) mode_class[MODE])
42 /* Nonzero if MODE is an integral mode. */
43 #define INTEGRAL_MODE_P(MODE) \
44 (GET_MODE_CLASS (MODE) == MODE_INT \
45 || GET_MODE_CLASS (MODE) == MODE_PARTIAL_INT \
46 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_INT \
47 || GET_MODE_CLASS (MODE) == MODE_VECTOR_INT)
49 /* Nonzero if MODE is a floating-point mode. */
50 #define FLOAT_MODE_P(MODE) \
51 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
52 || GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT \
53 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT \
54 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT)
56 /* Nonzero if MODE is a complex mode. */
57 #define COMPLEX_MODE_P(MODE) \
58 (GET_MODE_CLASS (MODE) == MODE_COMPLEX_INT \
59 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT)
61 /* Nonzero if MODE is a vector mode. */
62 #define VECTOR_MODE_P(MODE) \
63 (GET_MODE_CLASS (MODE) == MODE_VECTOR_INT \
64 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT \
65 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FRACT \
66 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UFRACT \
67 || GET_MODE_CLASS (MODE) == MODE_VECTOR_ACCUM \
68 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UACCUM)
70 /* Nonzero if MODE is a scalar integral mode. */
71 #define SCALAR_INT_MODE_P(MODE) \
72 (GET_MODE_CLASS (MODE) == MODE_INT \
73 || GET_MODE_CLASS (MODE) == MODE_PARTIAL_INT)
75 /* Nonzero if MODE is a scalar floating point mode. */
76 #define SCALAR_FLOAT_MODE_P(MODE) \
77 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
78 || GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT)
80 /* Nonzero if MODE is a decimal floating point mode. */
81 #define DECIMAL_FLOAT_MODE_P(MODE) \
82 (GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT)
84 /* Nonzero if MODE is a scalar fract mode. */
85 #define SCALAR_FRACT_MODE_P(MODE) \
86 (GET_MODE_CLASS (MODE) == MODE_FRACT)
88 /* Nonzero if MODE is a scalar ufract mode. */
89 #define SCALAR_UFRACT_MODE_P(MODE) \
90 (GET_MODE_CLASS (MODE) == MODE_UFRACT)
92 /* Nonzero if MODE is a scalar fract or ufract mode. */
93 #define ALL_SCALAR_FRACT_MODE_P(MODE) \
94 (SCALAR_FRACT_MODE_P (MODE) || SCALAR_UFRACT_MODE_P (MODE))
96 /* Nonzero if MODE is a scalar accum mode. */
97 #define SCALAR_ACCUM_MODE_P(MODE) \
98 (GET_MODE_CLASS (MODE) == MODE_ACCUM)
100 /* Nonzero if MODE is a scalar uaccum mode. */
101 #define SCALAR_UACCUM_MODE_P(MODE) \
102 (GET_MODE_CLASS (MODE) == MODE_UACCUM)
104 /* Nonzero if MODE is a scalar accum or uaccum mode. */
105 #define ALL_SCALAR_ACCUM_MODE_P(MODE) \
106 (SCALAR_ACCUM_MODE_P (MODE) || SCALAR_UACCUM_MODE_P (MODE))
108 /* Nonzero if MODE is a scalar fract or accum mode. */
109 #define SIGNED_SCALAR_FIXED_POINT_MODE_P(MODE) \
110 (SCALAR_FRACT_MODE_P (MODE) || SCALAR_ACCUM_MODE_P (MODE))
112 /* Nonzero if MODE is a scalar ufract or uaccum mode. */
113 #define UNSIGNED_SCALAR_FIXED_POINT_MODE_P(MODE) \
114 (SCALAR_UFRACT_MODE_P (MODE) || SCALAR_UACCUM_MODE_P (MODE))
116 /* Nonzero if MODE is a scalar fract, ufract, accum or uaccum mode. */
117 #define ALL_SCALAR_FIXED_POINT_MODE_P(MODE) \
118 (SIGNED_SCALAR_FIXED_POINT_MODE_P (MODE) \
119 || UNSIGNED_SCALAR_FIXED_POINT_MODE_P (MODE))
121 /* Nonzero if MODE is a scalar/vector fract mode. */
122 #define FRACT_MODE_P(MODE) \
123 (GET_MODE_CLASS (MODE) == MODE_FRACT \
124 || GET_MODE_CLASS (MODE) == MODE_VECTOR_FRACT)
126 /* Nonzero if MODE is a scalar/vector ufract mode. */
127 #define UFRACT_MODE_P(MODE) \
128 (GET_MODE_CLASS (MODE) == MODE_UFRACT \
129 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UFRACT)
131 /* Nonzero if MODE is a scalar/vector fract or ufract mode. */
132 #define ALL_FRACT_MODE_P(MODE) \
133 (FRACT_MODE_P (MODE) || UFRACT_MODE_P (MODE))
135 /* Nonzero if MODE is a scalar/vector accum mode. */
136 #define ACCUM_MODE_P(MODE) \
137 (GET_MODE_CLASS (MODE) == MODE_ACCUM \
138 || GET_MODE_CLASS (MODE) == MODE_VECTOR_ACCUM)
140 /* Nonzero if MODE is a scalar/vector uaccum mode. */
141 #define UACCUM_MODE_P(MODE) \
142 (GET_MODE_CLASS (MODE) == MODE_UACCUM \
143 || GET_MODE_CLASS (MODE) == MODE_VECTOR_UACCUM)
145 /* Nonzero if MODE is a scalar/vector accum or uaccum mode. */
146 #define ALL_ACCUM_MODE_P(MODE) \
147 (ACCUM_MODE_P (MODE) || UACCUM_MODE_P (MODE))
149 /* Nonzero if MODE is a scalar/vector fract or accum mode. */
150 #define SIGNED_FIXED_POINT_MODE_P(MODE) \
151 (FRACT_MODE_P (MODE) || ACCUM_MODE_P (MODE))
153 /* Nonzero if MODE is a scalar/vector ufract or uaccum mode. */
154 #define UNSIGNED_FIXED_POINT_MODE_P(MODE) \
155 (UFRACT_MODE_P (MODE) || UACCUM_MODE_P (MODE))
157 /* Nonzero if MODE is a scalar/vector fract, ufract, accum or uaccum mode. */
158 #define ALL_FIXED_POINT_MODE_P(MODE) \
159 (SIGNED_FIXED_POINT_MODE_P (MODE) \
160 || UNSIGNED_FIXED_POINT_MODE_P (MODE))
162 /* Nonzero if CLASS modes can be widened. */
163 #define CLASS_HAS_WIDER_MODES_P(CLASS) \
164 (CLASS == MODE_INT \
165 || CLASS == MODE_PARTIAL_INT \
166 || CLASS == MODE_FLOAT \
167 || CLASS == MODE_DECIMAL_FLOAT \
168 || CLASS == MODE_COMPLEX_FLOAT \
169 || CLASS == MODE_FRACT \
170 || CLASS == MODE_UFRACT \
171 || CLASS == MODE_ACCUM \
172 || CLASS == MODE_UACCUM)
174 #define POINTER_BOUNDS_MODE_P(MODE) \
175 (GET_MODE_CLASS (MODE) == MODE_POINTER_BOUNDS)
177 /* Get the size in bytes and bits of an object of mode MODE. */
179 extern CONST_MODE_SIZE unsigned short mode_size[NUM_MACHINE_MODES];
180 #if GCC_VERSION >= 4001
181 #define GET_MODE_SIZE(MODE) \
182 ((unsigned short) (__builtin_constant_p (MODE) \
183 ? mode_size_inline (MODE) : mode_size[MODE]))
184 #else
185 #define GET_MODE_SIZE(MODE) ((unsigned short) mode_size[MODE])
186 #endif
187 #define GET_MODE_BITSIZE(MODE) \
188 ((unsigned short) (GET_MODE_SIZE (MODE) * BITS_PER_UNIT))
190 /* Get the number of value bits of an object of mode MODE. */
191 extern const unsigned short mode_precision[NUM_MACHINE_MODES];
192 #define GET_MODE_PRECISION(MODE) mode_precision[MODE]
194 /* Get the number of integral bits of an object of mode MODE. */
195 extern CONST_MODE_IBIT unsigned char mode_ibit[NUM_MACHINE_MODES];
196 #define GET_MODE_IBIT(MODE) mode_ibit[MODE]
198 /* Get the number of fractional bits of an object of mode MODE. */
199 extern CONST_MODE_FBIT unsigned char mode_fbit[NUM_MACHINE_MODES];
200 #define GET_MODE_FBIT(MODE) mode_fbit[MODE]
202 /* Get a bitmask containing 1 for all bits in a word
203 that fit within mode MODE. */
205 extern const unsigned HOST_WIDE_INT mode_mask_array[NUM_MACHINE_MODES];
207 #define GET_MODE_MASK(MODE) mode_mask_array[MODE]
209 /* Return the mode of the basic parts of MODE. For vector modes this is the
210 mode of the vector elements. For complex modes it is the mode of the real
211 and imaginary parts. For other modes it is MODE itself. */
213 extern const unsigned char mode_inner[NUM_MACHINE_MODES];
214 #if GCC_VERSION >= 4001
215 #define GET_MODE_INNER(MODE) \
216 ((machine_mode) (__builtin_constant_p (MODE) \
217 ? mode_inner_inline (MODE) : mode_inner[MODE]))
218 #else
219 #define GET_MODE_INNER(MODE) ((machine_mode) mode_inner[MODE])
220 #endif
222 /* Get the size in bytes or bits of the basic parts of an
223 object of mode MODE. */
225 extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES];
226 #if GCC_VERSION >= 4001
227 #define GET_MODE_UNIT_SIZE(MODE) \
228 ((unsigned char) (__builtin_constant_p (MODE) \
229 ? mode_unit_size_inline (MODE) : mode_unit_size[MODE]))
230 #else
231 #define GET_MODE_UNIT_SIZE(MODE) mode_unit_size[MODE]
232 #endif
234 #define GET_MODE_UNIT_BITSIZE(MODE) \
235 ((unsigned short) (GET_MODE_UNIT_SIZE (MODE) * BITS_PER_UNIT))
237 extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES];
238 #if GCC_VERSION >= 4001
239 #define GET_MODE_UNIT_PRECISION(MODE) \
240 ((unsigned short) (__builtin_constant_p (MODE) \
241 ? mode_unit_precision_inline (MODE)\
242 : mode_unit_precision[MODE]))
243 #else
244 #define GET_MODE_UNIT_PRECISION(MODE) mode_unit_precision[MODE]
245 #endif
248 /* Get the number of units in the object. */
250 extern const unsigned char mode_nunits[NUM_MACHINE_MODES];
251 #if GCC_VERSION >= 4001
252 #define GET_MODE_NUNITS(MODE) \
253 ((unsigned char) (__builtin_constant_p (MODE) \
254 ? mode_nunits_inline (MODE) : mode_nunits[MODE]))
255 #else
256 #define GET_MODE_NUNITS(MODE) mode_nunits[MODE]
257 #endif
259 /* Get the next wider natural mode (eg, QI -> HI -> SI -> DI -> TI). */
261 extern const unsigned char mode_wider[NUM_MACHINE_MODES];
262 #define GET_MODE_WIDER_MODE(MODE) ((machine_mode) mode_wider[MODE])
264 /* For scalars, this is a mode with twice the precision. For vectors,
265 this is a mode with the same inner mode but with twice the elements. */
266 extern const unsigned char mode_2xwider[NUM_MACHINE_MODES];
267 #define GET_MODE_2XWIDER_MODE(MODE) ((machine_mode) mode_2xwider[MODE])
269 /* Get the complex mode from the component mode. */
270 extern const unsigned char mode_complex[NUM_MACHINE_MODES];
271 #define GET_MODE_COMPLEX_MODE(MODE) ((machine_mode) mode_complex[MODE])
273 /* Return the mode for data of a given size SIZE and mode class CLASS.
274 If LIMIT is nonzero, then don't use modes bigger than MAX_FIXED_MODE_SIZE.
275 The value is BLKmode if no other mode is found. */
277 extern machine_mode mode_for_size (unsigned int, enum mode_class, int);
279 /* Similar, but find the smallest mode for a given width. */
281 extern machine_mode smallest_mode_for_size (unsigned int,
282 enum mode_class);
285 /* Return an integer mode of the exact same size as the input mode,
286 or BLKmode on failure. */
288 extern machine_mode int_mode_for_mode (machine_mode);
290 extern machine_mode bitwise_mode_for_mode (machine_mode);
292 /* Return a mode that is suitable for representing a vector,
293 or BLKmode on failure. */
295 extern machine_mode mode_for_vector (machine_mode, unsigned);
297 /* A class for iterating through possible bitfield modes. */
298 class bit_field_mode_iterator
300 public:
301 bit_field_mode_iterator (HOST_WIDE_INT, HOST_WIDE_INT,
302 HOST_WIDE_INT, HOST_WIDE_INT,
303 unsigned int, bool);
304 bool next_mode (machine_mode *);
305 bool prefer_smaller_modes ();
307 private:
308 machine_mode m_mode;
309 /* We use signed values here because the bit position can be negative
310 for invalid input such as gcc.dg/pr48335-8.c. */
311 HOST_WIDE_INT m_bitsize;
312 HOST_WIDE_INT m_bitpos;
313 HOST_WIDE_INT m_bitregion_start;
314 HOST_WIDE_INT m_bitregion_end;
315 unsigned int m_align;
316 bool m_volatilep;
317 int m_count;
320 /* Find the best mode to use to access a bit field. */
322 extern machine_mode get_best_mode (int, int,
323 unsigned HOST_WIDE_INT,
324 unsigned HOST_WIDE_INT,
325 unsigned int,
326 machine_mode, bool);
328 /* Determine alignment, 1<=result<=BIGGEST_ALIGNMENT. */
330 extern CONST_MODE_BASE_ALIGN unsigned short mode_base_align[NUM_MACHINE_MODES];
332 extern unsigned get_mode_alignment (machine_mode);
334 #define GET_MODE_ALIGNMENT(MODE) get_mode_alignment (MODE)
336 /* For each class, get the narrowest mode in that class. */
338 extern const unsigned char class_narrowest_mode[MAX_MODE_CLASS];
339 #define GET_CLASS_NARROWEST_MODE(CLASS) \
340 ((machine_mode) class_narrowest_mode[CLASS])
342 /* Define the integer modes whose sizes are BITS_PER_UNIT and BITS_PER_WORD
343 and the mode whose class is Pmode and whose size is POINTER_SIZE. */
345 extern machine_mode byte_mode;
346 extern machine_mode word_mode;
347 extern machine_mode ptr_mode;
349 /* Target-dependent machine mode initialization - in insn-modes.c. */
350 extern void init_adjust_machine_modes (void);
352 #define TRULY_NOOP_TRUNCATION_MODES_P(MODE1, MODE2) \
353 TRULY_NOOP_TRUNCATION (GET_MODE_PRECISION (MODE1), \
354 GET_MODE_PRECISION (MODE2))
356 #define HWI_COMPUTABLE_MODE_P(MODE) \
357 (SCALAR_INT_MODE_P (MODE) \
358 && GET_MODE_PRECISION (MODE) <= HOST_BITS_PER_WIDE_INT)
360 struct int_n_data_t {
361 /* These parts are initailized by genmodes output */
362 unsigned int bitsize;
363 machine_mode m;
364 /* RID_* is RID_INTN_BASE + index into this array */
367 /* This is also in tree.h. genmodes.c guarantees the're sorted from
368 smallest bitsize to largest bitsize. */
369 extern bool int_n_enabled_p[NUM_INT_N_ENTS];
370 extern const int_n_data_t int_n_data[NUM_INT_N_ENTS];
372 #endif /* not HAVE_MACHINE_MODES */