]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/genmodes.c
* config/mips/mips.c (mips_final_postscan_insn): Modify call
[thirdparty/gcc.git] / gcc / genmodes.c
CommitLineData
47a2c1d4 1/* Generate the machine mode enumeration and associated tables.
fbd26352 2 Copyright (C) 2003-2019 Free Software Foundation, Inc.
47a2c1d4 3
4This file is part of GCC.
5
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
8c4c00c1 8Software Foundation; either version 3, or (at your option) any later
47a2c1d4 9version.
10
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.
15
16You should have received a copy of the GNU General Public License
8c4c00c1 17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
47a2c1d4 19
20#include "bconfig.h"
21#include "system.h"
22#include "errors.h"
23
24/* enum mode_class is normally defined by machmode.h but we can't
25 include that header here. */
26#include "mode-classes.def"
27
28#define DEF_MODE_CLASS(M) M
29enum mode_class { MODE_CLASSES, MAX_MODE_CLASS };
30#undef DEF_MODE_CLASS
31
32/* Text names of mode classes, for output. */
33#define DEF_MODE_CLASS(M) #M
34static const char *const mode_class_names[MAX_MODE_CLASS] =
35{
36 MODE_CLASSES
37};
38#undef DEF_MODE_CLASS
39#undef MODE_CLASSES
40
41#ifdef EXTRA_MODES_FILE
42# define HAVE_EXTRA_MODES 1
43#else
44# define HAVE_EXTRA_MODES 0
45# define EXTRA_MODES_FILE ""
46#endif
47
48/* Data structure for building up what we know about a mode.
49 They're clustered by mode class. */
50struct mode_data
51{
52 struct mode_data *next; /* next this class - arbitrary order */
53
54 const char *name; /* printable mode name -- SI, not SImode */
e916c70c 55 enum mode_class cl; /* this mode class */
7c0390e7 56 unsigned int precision; /* size in bits, equiv to TYPE_PRECISION */
47a2c1d4 57 unsigned int bytesize; /* storage size in addressable units */
58 unsigned int ncomponents; /* number of subunits */
59 unsigned int alignment; /* mode alignment */
3c28f41a 60 const char *format; /* floating point format - float modes only */
47a2c1d4 61
62 struct mode_data *component; /* mode of components */
63 struct mode_data *wider; /* next wider mode */
64
b8bc42e9 65 struct mode_data *contained; /* Pointer to list of modes that have
66 this mode as a component. */
67 struct mode_data *next_cont; /* Next mode in that list. */
68
3c62cae0 69 struct mode_data *complex; /* complex type with mode as component. */
47a2c1d4 70 const char *file; /* file and line of definition, */
71 unsigned int line; /* for error reporting */
3c28f41a 72 unsigned int counter; /* Rank ordering of modes */
c559c639 73 unsigned int ibit; /* the number of integral bits */
74 unsigned int fbit; /* the number of fractional bits */
b75c5ec0 75 bool need_nunits_adj; /* true if this mode needs dynamic nunits
76 adjustment */
77 bool need_bytesize_adj; /* true if this mode needs dynamic size
e2ec52ca 78 adjustment */
9f75f026 79 unsigned int int_n; /* If nonzero, then __int<INT_N> will be defined */
47a2c1d4 80};
81
f58875bf 82static struct mode_data *modes[MAX_MODE_CLASS];
47a2c1d4 83static unsigned int n_modes[MAX_MODE_CLASS];
84static struct mode_data *void_mode;
85
86static const struct mode_data blank_mode = {
87 0, "<unknown>", MAX_MODE_CLASS,
e916c70c 88 -1U, -1U, -1U, -1U,
3c62cae0 89 0, 0, 0, 0, 0, 0,
b75c5ec0 90 "<unknown>", 0, 0, 0, 0, false, false, 0
47a2c1d4 91};
92
f58875bf 93static htab_t modes_by_name;
94
95/* Data structure for recording target-specified runtime adjustments
96 to a particular mode. We support varying the byte size, the
97 alignment, and the floating point format. */
98struct mode_adjust
99{
100 struct mode_adjust *next;
101 struct mode_data *mode;
102 const char *adjustment;
103
104 const char *file;
105 unsigned int line;
106};
107
b75c5ec0 108static struct mode_adjust *adj_nunits;
f58875bf 109static struct mode_adjust *adj_bytesize;
110static struct mode_adjust *adj_alignment;
111static struct mode_adjust *adj_format;
c559c639 112static struct mode_adjust *adj_ibit;
113static struct mode_adjust *adj_fbit;
f58875bf 114
47a2c1d4 115/* Mode class operations. */
116static enum mode_class
e916c70c 117complex_class (enum mode_class c)
47a2c1d4 118{
e916c70c 119 switch (c)
47a2c1d4 120 {
121 case MODE_INT: return MODE_COMPLEX_INT;
dff73565 122 case MODE_PARTIAL_INT: return MODE_COMPLEX_INT;
47a2c1d4 123 case MODE_FLOAT: return MODE_COMPLEX_FLOAT;
124 default:
e916c70c 125 error ("no complex class for class %s", mode_class_names[c]);
47a2c1d4 126 return MODE_RANDOM;
127 }
128}
129
130static enum mode_class
e916c70c 131vector_class (enum mode_class cl)
47a2c1d4 132{
e916c70c 133 switch (cl)
47a2c1d4 134 {
135 case MODE_INT: return MODE_VECTOR_INT;
136 case MODE_FLOAT: return MODE_VECTOR_FLOAT;
c559c639 137 case MODE_FRACT: return MODE_VECTOR_FRACT;
138 case MODE_UFRACT: return MODE_VECTOR_UFRACT;
139 case MODE_ACCUM: return MODE_VECTOR_ACCUM;
140 case MODE_UACCUM: return MODE_VECTOR_UACCUM;
47a2c1d4 141 default:
e916c70c 142 error ("no vector class for class %s", mode_class_names[cl]);
47a2c1d4 143 return MODE_RANDOM;
144 }
145}
146
f58875bf 147/* Utility routines. */
148static inline struct mode_data *
149find_mode (const char *name)
47a2c1d4 150{
f58875bf 151 struct mode_data key;
47a2c1d4 152
f58875bf 153 key.name = name;
e916c70c 154 return (struct mode_data *) htab_find (modes_by_name, &key);
47a2c1d4 155}
156
157static struct mode_data *
e916c70c 158new_mode (enum mode_class cl, const char *name,
47a2c1d4 159 const char *file, unsigned int line)
160{
161 struct mode_data *m;
3c28f41a 162 static unsigned int count = 0;
47a2c1d4 163
f58875bf 164 m = find_mode (name);
47a2c1d4 165 if (m)
166 {
167 error ("%s:%d: duplicate definition of mode \"%s\"",
168 trim_filename (file), line, name);
169 error ("%s:%d: previous definition here", m->file, m->line);
170 return m;
171 }
172
e916c70c 173 m = XNEW (struct mode_data);
47a2c1d4 174 memcpy (m, &blank_mode, sizeof (struct mode_data));
e916c70c 175 m->cl = cl;
47a2c1d4 176 m->name = name;
177 if (file)
178 m->file = trim_filename (file);
179 m->line = line;
3c28f41a 180 m->counter = count++;
47a2c1d4 181
e916c70c 182 m->next = modes[cl];
183 modes[cl] = m;
184 n_modes[cl]++;
f58875bf 185
186 *htab_find_slot (modes_by_name, m, INSERT) = m;
48e1416a 187
47a2c1d4 188 return m;
189}
190
f58875bf 191static hashval_t
192hash_mode (const void *p)
193{
194 const struct mode_data *m = (const struct mode_data *)p;
195 return htab_hash_string (m->name);
196}
197
198static int
199eq_mode (const void *p, const void *q)
200{
201 const struct mode_data *a = (const struct mode_data *)p;
202 const struct mode_data *b = (const struct mode_data *)q;
203
204 return !strcmp (a->name, b->name);
205}
206
47a2c1d4 207#define for_all_modes(C, M) \
208 for (C = 0; C < MAX_MODE_CLASS; C++) \
f58875bf 209 for (M = modes[C]; M; M = M->next)
210
211static void ATTRIBUTE_UNUSED
212new_adjust (const char *name,
213 struct mode_adjust **category, const char *catname,
214 const char *adjustment,
c559c639 215 enum mode_class required_class_from,
216 enum mode_class required_class_to,
f58875bf 217 const char *file, unsigned int line)
218{
219 struct mode_data *mode = find_mode (name);
220 struct mode_adjust *a;
221
222 file = trim_filename (file);
223
224 if (!mode)
225 {
226 error ("%s:%d: no mode \"%s\"", file, line, name);
227 return;
228 }
229
c559c639 230 if (required_class_from != MODE_RANDOM
231 && (mode->cl < required_class_from || mode->cl > required_class_to))
f58875bf 232 {
c559c639 233 error ("%s:%d: mode \"%s\" is not among class {%s, %s}",
234 file, line, name, mode_class_names[required_class_from] + 5,
235 mode_class_names[required_class_to] + 5);
f58875bf 236 return;
237 }
48e1416a 238
f58875bf 239 for (a = *category; a; a = a->next)
240 if (a->mode == mode)
241 {
242 error ("%s:%d: mode \"%s\" already has a %s adjustment",
243 file, line, name, catname);
244 error ("%s:%d: previous adjustment here", a->file, a->line);
245 return;
246 }
247
9318f22c 248 a = XNEW (struct mode_adjust);
f58875bf 249 a->mode = mode;
250 a->adjustment = adjustment;
251 a->file = file;
252 a->line = line;
253
254 a->next = *category;
255 *category = a;
256}
47a2c1d4 257
258/* Diagnose failure to meet expectations in a partially filled out
259 mode structure. */
260enum requirement { SET, UNSET, OPTIONAL };
261
262#define validate_field_(mname, fname, req, val, unset, file, line) do { \
263 switch (req) \
264 { \
265 case SET: \
266 if (val == unset) \
267 error ("%s:%d: (%s) field %s must be set", \
268 file, line, mname, fname); \
269 break; \
270 case UNSET: \
271 if (val != unset) \
272 error ("%s:%d: (%s) field %s must not be set", \
273 file, line, mname, fname); \
274 case OPTIONAL: \
275 break; \
276 } \
277} while (0)
278
279#define validate_field(M, F) \
280 validate_field_(M->name, #F, r_##F, M->F, blank_mode.F, M->file, M->line)
281
282static void
283validate_mode (struct mode_data *m,
7c0390e7 284 enum requirement r_precision,
47a2c1d4 285 enum requirement r_bytesize,
286 enum requirement r_component,
15460c97 287 enum requirement r_ncomponents,
288 enum requirement r_format)
47a2c1d4 289{
7c0390e7 290 validate_field (m, precision);
47a2c1d4 291 validate_field (m, bytesize);
292 validate_field (m, component);
293 validate_field (m, ncomponents);
15460c97 294 validate_field (m, format);
47a2c1d4 295}
296#undef validate_field
297#undef validate_field_
298
299/* Given a partially-filled-out mode structure, figure out what we can
300 and fill the rest of it in; die if it isn't enough. */
301static void
302complete_mode (struct mode_data *m)
303{
304 unsigned int alignment;
305
306 if (!m->name)
307 {
308 error ("%s:%d: mode with no name", m->file, m->line);
309 return;
310 }
e916c70c 311 if (m->cl == MAX_MODE_CLASS)
47a2c1d4 312 {
313 error ("%s:%d: %smode has no mode class", m->file, m->line, m->name);
314 return;
315 }
316
e916c70c 317 switch (m->cl)
47a2c1d4 318 {
319 case MODE_RANDOM:
320 /* Nothing more need be said. */
321 if (!strcmp (m->name, "VOID"))
322 void_mode = m;
323
15460c97 324 validate_mode (m, UNSET, UNSET, UNSET, UNSET, UNSET);
47a2c1d4 325
7c0390e7 326 m->precision = 0;
47a2c1d4 327 m->bytesize = 0;
328 m->ncomponents = 0;
329 m->component = 0;
330 break;
331
332 case MODE_CC:
333 /* Again, nothing more need be said. For historical reasons,
334 the size of a CC mode is four units. */
15460c97 335 validate_mode (m, UNSET, UNSET, UNSET, UNSET, UNSET);
47a2c1d4 336
337 m->bytesize = 4;
24b7dafb 338 m->ncomponents = 1;
47a2c1d4 339 m->component = 0;
340 break;
341
342 case MODE_INT:
343 case MODE_FLOAT:
3c28f41a 344 case MODE_DECIMAL_FLOAT:
c559c639 345 case MODE_FRACT:
346 case MODE_UFRACT:
347 case MODE_ACCUM:
348 case MODE_UACCUM:
47a2c1d4 349 /* A scalar mode must have a byte size, may have a bit size,
15460c97 350 and must not have components. A float mode must have a
351 format. */
352 validate_mode (m, OPTIONAL, SET, UNSET, UNSET,
c559c639 353 (m->cl == MODE_FLOAT || m->cl == MODE_DECIMAL_FLOAT)
354 ? SET : UNSET);
47a2c1d4 355
24b7dafb 356 m->ncomponents = 1;
47a2c1d4 357 m->component = 0;
358 break;
359
360 case MODE_PARTIAL_INT:
361 /* A partial integer mode uses ->component to say what the
362 corresponding full-size integer mode is, and may also
363 specify a bit size. */
15460c97 364 validate_mode (m, OPTIONAL, UNSET, SET, UNSET, UNSET);
47a2c1d4 365
366 m->bytesize = m->component->bytesize;
367
24b7dafb 368 m->ncomponents = 1;
47a2c1d4 369 break;
370
371 case MODE_COMPLEX_INT:
372 case MODE_COMPLEX_FLOAT:
373 /* Complex modes should have a component indicated, but no more. */
15460c97 374 validate_mode (m, UNSET, UNSET, SET, UNSET, UNSET);
47a2c1d4 375 m->ncomponents = 2;
7c0390e7 376 if (m->component->precision != (unsigned int)-1)
377 m->precision = 2 * m->component->precision;
47a2c1d4 378 m->bytesize = 2 * m->component->bytesize;
379 break;
380
8464736b 381 case MODE_VECTOR_BOOL:
382 validate_mode (m, UNSET, SET, SET, SET, UNSET);
383 break;
384
47a2c1d4 385 case MODE_VECTOR_INT:
386 case MODE_VECTOR_FLOAT:
c559c639 387 case MODE_VECTOR_FRACT:
388 case MODE_VECTOR_UFRACT:
389 case MODE_VECTOR_ACCUM:
390 case MODE_VECTOR_UACCUM:
47a2c1d4 391 /* Vector modes should have a component and a number of components. */
15460c97 392 validate_mode (m, UNSET, UNSET, SET, SET, UNSET);
7c0390e7 393 if (m->component->precision != (unsigned int)-1)
394 m->precision = m->ncomponents * m->component->precision;
47a2c1d4 395 m->bytesize = m->ncomponents * m->component->bytesize;
396 break;
397
398 default:
e0a4c0c2 399 gcc_unreachable ();
47a2c1d4 400 }
401
402 /* If not already specified, the mode alignment defaults to the largest
403 power of two that divides the size of the object. Complex types are
404 not more aligned than their contents. */
e916c70c 405 if (m->cl == MODE_COMPLEX_INT || m->cl == MODE_COMPLEX_FLOAT)
47a2c1d4 406 alignment = m->component->bytesize;
407 else
408 alignment = m->bytesize;
409
410 m->alignment = alignment & (~alignment + 1);
b8bc42e9 411
412 /* If this mode has components, make the component mode point back
413 to this mode, for the sake of adjustments. */
414 if (m->component)
415 {
416 m->next_cont = m->component->contained;
417 m->component->contained = m;
418 }
47a2c1d4 419}
420
421static void
422complete_all_modes (void)
423{
424 struct mode_data *m;
e916c70c 425 int cl;
426
427 for_all_modes (cl, m)
47a2c1d4 428 complete_mode (m);
429}
430
431/* For each mode in class CLASS, construct a corresponding complex mode. */
9af5ce0c 432#define COMPLEX_MODES(C) make_complex_modes (MODE_##C, __FILE__, __LINE__)
47a2c1d4 433static void
e916c70c 434make_complex_modes (enum mode_class cl,
47a2c1d4 435 const char *file, unsigned int line)
436{
437 struct mode_data *m;
438 struct mode_data *c;
e916c70c 439 enum mode_class cclass = complex_class (cl);
47a2c1d4 440
441 if (cclass == MODE_RANDOM)
442 return;
e916c70c 443
444 for (m = modes[cl]; m; m = m->next)
47a2c1d4 445 {
cdf7d299 446 char *p, *buf;
2e045eaa 447 size_t m_len;
448
47a2c1d4 449 /* Skip BImode. FIXME: BImode probably shouldn't be MODE_INT. */
7c0390e7 450 if (m->precision == 1)
47a2c1d4 451 continue;
452
2e045eaa 453 m_len = strlen (m->name);
cdf7d299 454 /* The leading "1 +" is in case we prepend a "C" below. */
455 buf = (char *) xmalloc (1 + m_len + 1);
47a2c1d4 456
457 /* Float complex modes are named SCmode, etc.
458 Int complex modes are named CSImode, etc.
459 This inconsistency should be eliminated. */
cdf7d299 460 p = 0;
e916c70c 461 if (cl == MODE_FLOAT)
47a2c1d4 462 {
2e045eaa 463 memcpy (buf, m->name, m_len + 1);
47a2c1d4 464 p = strchr (buf, 'F');
cdf7d299 465 if (p == 0 && strchr (buf, 'D') == 0)
47a2c1d4 466 {
3c28f41a 467 error ("%s:%d: float mode \"%s\" has no 'F' or 'D'",
47a2c1d4 468 m->file, m->line, m->name);
cdf7d299 469 free (buf);
47a2c1d4 470 continue;
471 }
47a2c1d4 472 }
cdf7d299 473 if (p != 0)
474 *p = 'C';
47a2c1d4 475 else
cdf7d299 476 {
477 buf[0] = 'C';
478 memcpy (buf + 1, m->name, m_len + 1);
479 }
47a2c1d4 480
cdf7d299 481 c = new_mode (cclass, buf, file, line);
47a2c1d4 482 c->component = m;
3c62cae0 483 m->complex = c;
47a2c1d4 484 }
485}
486
e916c70c 487/* For all modes in class CL, construct vector modes of width
47a2c1d4 488 WIDTH, having as many components as necessary. */
486626ef 489#define VECTOR_MODES_WITH_PREFIX(PREFIX, C, W) \
490 make_vector_modes (MODE_##C, #PREFIX, W, __FILE__, __LINE__)
491#define VECTOR_MODES(C, W) VECTOR_MODES_WITH_PREFIX (V, C, W)
259ff179 492static void ATTRIBUTE_UNUSED
486626ef 493make_vector_modes (enum mode_class cl, const char *prefix, unsigned int width,
47a2c1d4 494 const char *file, unsigned int line)
495{
496 struct mode_data *m;
497 struct mode_data *v;
b18dea91 498 /* Big enough for a 32-bit UINT_MAX plus the text. */
499 char buf[12];
47a2c1d4 500 unsigned int ncomponents;
e916c70c 501 enum mode_class vclass = vector_class (cl);
47a2c1d4 502
503 if (vclass == MODE_RANDOM)
504 return;
505
e916c70c 506 for (m = modes[cl]; m; m = m->next)
47a2c1d4 507 {
508 /* Do not construct vector modes with only one element, or
509 vector modes where the element size doesn't divide the full
510 size evenly. */
511 ncomponents = width / m->bytesize;
512 if (ncomponents < 2)
513 continue;
514 if (width % m->bytesize)
515 continue;
516
517 /* Skip QFmode and BImode. FIXME: this special case should
518 not be necessary. */
e916c70c 519 if (cl == MODE_FLOAT && m->bytesize == 1)
47a2c1d4 520 continue;
e916c70c 521 if (cl == MODE_INT && m->precision == 1)
47a2c1d4 522 continue;
523
486626ef 524 if ((size_t) snprintf (buf, sizeof buf, "%s%u%s", prefix,
525 ncomponents, m->name) >= sizeof buf)
47a2c1d4 526 {
527 error ("%s:%d: mode name \"%s\" is too long",
528 m->file, m->line, m->name);
529 continue;
530 }
531
532 v = new_mode (vclass, xstrdup (buf), file, line);
533 v->component = m;
534 v->ncomponents = ncomponents;
535 }
536}
537
8464736b 538/* Create a vector of booleans called NAME with COUNT elements and
539 BYTESIZE bytes in total. */
540#define VECTOR_BOOL_MODE(NAME, COUNT, BYTESIZE) \
541 make_vector_bool_mode (#NAME, COUNT, BYTESIZE, __FILE__, __LINE__)
542static void ATTRIBUTE_UNUSED
543make_vector_bool_mode (const char *name, unsigned int count,
544 unsigned int bytesize, const char *file,
545 unsigned int line)
546{
547 struct mode_data *m = find_mode ("BI");
548 if (!m)
549 {
550 error ("%s:%d: no mode \"BI\"", file, line);
551 return;
552 }
553
554 struct mode_data *v = new_mode (MODE_VECTOR_BOOL, name, file, line);
555 v->component = m;
556 v->ncomponents = count;
557 v->bytesize = bytesize;
558}
559
47a2c1d4 560/* Input. */
561
9af5ce0c 562#define _SPECIAL_MODE(C, N) \
563 make_special_mode (MODE_##C, #N, __FILE__, __LINE__)
47a2c1d4 564#define RANDOM_MODE(N) _SPECIAL_MODE (RANDOM, N)
565#define CC_MODE(N) _SPECIAL_MODE (CC, N)
566
567static void
e916c70c 568make_special_mode (enum mode_class cl, const char *name,
47a2c1d4 569 const char *file, unsigned int line)
570{
e916c70c 571 new_mode (cl, name, file, line);
47a2c1d4 572}
573
e916c70c 574#define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y)
15460c97 575#define FRACTIONAL_INT_MODE(N, B, Y) \
576 make_int_mode (#N, B, Y, __FILE__, __LINE__)
47a2c1d4 577
15460c97 578static void
579make_int_mode (const char *name,
7c0390e7 580 unsigned int precision, unsigned int bytesize,
15460c97 581 const char *file, unsigned int line)
582{
583 struct mode_data *m = new_mode (MODE_INT, name, file, line);
584 m->bytesize = bytesize;
7c0390e7 585 m->precision = precision;
15460c97 586}
587
c559c639 588#define FRACT_MODE(N, Y, F) \
589 make_fixed_point_mode (MODE_FRACT, #N, Y, 0, F, __FILE__, __LINE__)
590
591#define UFRACT_MODE(N, Y, F) \
592 make_fixed_point_mode (MODE_UFRACT, #N, Y, 0, F, __FILE__, __LINE__)
593
594#define ACCUM_MODE(N, Y, I, F) \
595 make_fixed_point_mode (MODE_ACCUM, #N, Y, I, F, __FILE__, __LINE__)
596
597#define UACCUM_MODE(N, Y, I, F) \
598 make_fixed_point_mode (MODE_UACCUM, #N, Y, I, F, __FILE__, __LINE__)
599
600/* Create a fixed-point mode by setting CL, NAME, BYTESIZE, IBIT, FBIT,
601 FILE, and LINE. */
602
603static void
604make_fixed_point_mode (enum mode_class cl,
605 const char *name,
606 unsigned int bytesize,
607 unsigned int ibit,
608 unsigned int fbit,
609 const char *file, unsigned int line)
610{
611 struct mode_data *m = new_mode (cl, name, file, line);
612 m->bytesize = bytesize;
613 m->ibit = ibit;
614 m->fbit = fbit;
615}
616
e916c70c 617#define FLOAT_MODE(N, Y, F) FRACTIONAL_FLOAT_MODE (N, -1U, Y, F)
15460c97 618#define FRACTIONAL_FLOAT_MODE(N, B, Y, F) \
619 make_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
47a2c1d4 620
621static void
15460c97 622make_float_mode (const char *name,
7c0390e7 623 unsigned int precision, unsigned int bytesize,
15460c97 624 const char *format,
625 const char *file, unsigned int line)
47a2c1d4 626{
15460c97 627 struct mode_data *m = new_mode (MODE_FLOAT, name, file, line);
47a2c1d4 628 m->bytesize = bytesize;
7c0390e7 629 m->precision = precision;
15460c97 630 m->format = format;
631}
632
3c28f41a 633#define DECIMAL_FLOAT_MODE(N, Y, F) \
634 FRACTIONAL_DECIMAL_FLOAT_MODE (N, -1U, Y, F)
635#define FRACTIONAL_DECIMAL_FLOAT_MODE(N, B, Y, F) \
636 make_decimal_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
637
638static void
639make_decimal_float_mode (const char *name,
640 unsigned int precision, unsigned int bytesize,
641 const char *format,
642 const char *file, unsigned int line)
643{
644 struct mode_data *m = new_mode (MODE_DECIMAL_FLOAT, name, file, line);
645 m->bytesize = bytesize;
646 m->precision = precision;
647 m->format = format;
648}
649
15460c97 650#define RESET_FLOAT_FORMAT(N, F) \
651 reset_float_format (#N, #F, __FILE__, __LINE__)
652static void ATTRIBUTE_UNUSED
653reset_float_format (const char *name, const char *format,
f58875bf 654 const char *file, unsigned int line)
15460c97 655{
f58875bf 656 struct mode_data *m = find_mode (name);
15460c97 657 if (!m)
658 {
f58875bf 659 error ("%s:%d: no mode \"%s\"", file, line, name);
660 return;
661 }
3c28f41a 662 if (m->cl != MODE_FLOAT && m->cl != MODE_DECIMAL_FLOAT)
f58875bf 663 {
3c28f41a 664 error ("%s:%d: mode \"%s\" is not a FLOAT class", file, line, name);
15460c97 665 return;
666 }
667 m->format = format;
47a2c1d4 668}
669
9f75f026 670/* __intN support. */
671#define INT_N(M,PREC) \
672 make_int_n (#M, PREC, __FILE__, __LINE__)
673static void ATTRIBUTE_UNUSED
674make_int_n (const char *m, int bitsize,
675 const char *file, unsigned int line)
676{
677 struct mode_data *component = find_mode (m);
678 if (!component)
679 {
680 error ("%s:%d: no mode \"%s\"", file, line, m);
681 return;
682 }
683 if (component->cl != MODE_INT
684 && component->cl != MODE_PARTIAL_INT)
685 {
686 error ("%s:%d: mode \"%s\" is not class INT or PARTIAL_INT", file, line, m);
687 return;
688 }
689 if (component->int_n != 0)
690 {
691 error ("%s:%d: mode \"%s\" already has an intN", file, line, m);
692 return;
693 }
694
695 component->int_n = bitsize;
696}
697
0d58d930 698/* Partial integer modes are specified by relation to a full integer
699 mode. */
700#define PARTIAL_INT_MODE(M,PREC,NAME) \
701 make_partial_integer_mode (#M, #NAME, PREC, __FILE__, __LINE__)
47a2c1d4 702static void ATTRIBUTE_UNUSED
703make_partial_integer_mode (const char *base, const char *name,
7c0390e7 704 unsigned int precision,
47a2c1d4 705 const char *file, unsigned int line)
706{
707 struct mode_data *m;
f58875bf 708 struct mode_data *component = find_mode (base);
47a2c1d4 709 if (!component)
710 {
f58875bf 711 error ("%s:%d: no mode \"%s\"", file, line, name);
712 return;
713 }
e916c70c 714 if (component->cl != MODE_INT)
f58875bf 715 {
716 error ("%s:%d: mode \"%s\" is not class INT", file, line, name);
47a2c1d4 717 return;
718 }
e916c70c 719
47a2c1d4 720 m = new_mode (MODE_PARTIAL_INT, name, file, line);
7c0390e7 721 m->precision = precision;
47a2c1d4 722 m->component = component;
723}
724
725/* A single vector mode can be specified by naming its component
726 mode and the number of components. */
727#define VECTOR_MODE(C, M, N) \
728 make_vector_mode (MODE_##C, #M, N, __FILE__, __LINE__);
729static void ATTRIBUTE_UNUSED
730make_vector_mode (enum mode_class bclass,
731 const char *base,
732 unsigned int ncomponents,
733 const char *file, unsigned int line)
734{
735 struct mode_data *v;
736 enum mode_class vclass = vector_class (bclass);
f58875bf 737 struct mode_data *component = find_mode (base);
0d58d930 738 char namebuf[16];
47a2c1d4 739
740 if (vclass == MODE_RANDOM)
741 return;
742 if (component == 0)
743 {
f58875bf 744 error ("%s:%d: no mode \"%s\"", file, line, base);
745 return;
746 }
0bdbecff 747 if (component->cl != bclass
748 && (component->cl != MODE_PARTIAL_INT
749 || bclass != MODE_INT))
f58875bf 750 {
751 error ("%s:%d: mode \"%s\" is not class %s",
47a2c1d4 752 file, line, base, mode_class_names[bclass] + 5);
753 return;
754 }
755
756 if ((size_t)snprintf (namebuf, sizeof namebuf, "V%u%s",
757 ncomponents, base) >= sizeof namebuf)
758 {
759 error ("%s:%d: mode name \"%s\" is too long",
99cb7891 760 file, line, base);
47a2c1d4 761 return;
762 }
763
764 v = new_mode (vclass, xstrdup (namebuf), file, line);
765 v->ncomponents = ncomponents;
766 v->component = component;
767}
f58875bf 768
769/* Adjustability. */
c559c639 770#define _ADD_ADJUST(A, M, X, C1, C2) \
771 new_adjust (#M, &adj_##A, #A, #X, MODE_##C1, MODE_##C2, __FILE__, __LINE__)
f58875bf 772
b75c5ec0 773#define ADJUST_NUNITS(M, X) _ADD_ADJUST (nunits, M, X, RANDOM, RANDOM)
9af5ce0c 774#define ADJUST_BYTESIZE(M, X) _ADD_ADJUST (bytesize, M, X, RANDOM, RANDOM)
775#define ADJUST_ALIGNMENT(M, X) _ADD_ADJUST (alignment, M, X, RANDOM, RANDOM)
776#define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST (format, M, X, FLOAT, FLOAT)
777#define ADJUST_IBIT(M, X) _ADD_ADJUST (ibit, M, X, ACCUM, UACCUM)
778#define ADJUST_FBIT(M, X) _ADD_ADJUST (fbit, M, X, FRACT, UACCUM)
47a2c1d4 779
2cb32abf 780static int bits_per_unit;
781static int max_bitsize_mode_any_int;
cbc28e8e 782static int max_bitsize_mode_any_mode;
2cb32abf 783
47a2c1d4 784static void
785create_modes (void)
786{
787#include "machmode.def"
2cb32abf 788
789 /* So put the default value unless the target needs a non standard
790 value. */
791#ifdef BITS_PER_UNIT
792 bits_per_unit = BITS_PER_UNIT;
793#else
794 bits_per_unit = 8;
795#endif
796
797#ifdef MAX_BITSIZE_MODE_ANY_INT
798 max_bitsize_mode_any_int = MAX_BITSIZE_MODE_ANY_INT;
799#else
800 max_bitsize_mode_any_int = 0;
801#endif
cbc28e8e 802
803#ifdef MAX_BITSIZE_MODE_ANY_MODE
804 max_bitsize_mode_any_mode = MAX_BITSIZE_MODE_ANY_MODE;
805#else
806 max_bitsize_mode_any_mode = 0;
807#endif
47a2c1d4 808}
809
466432a3 810#ifndef NUM_POLY_INT_COEFFS
811#define NUM_POLY_INT_COEFFS 1
812#endif
813
47a2c1d4 814/* Processing. */
815
816/* Sort a list of modes into the order needed for the WIDER field:
7c0390e7 817 major sort by precision, minor sort by component precision.
47a2c1d4 818
819 For instance:
820 QI < HI < SI < DI < TI
821 V4QI < V2HI < V8QI < V4HI < V2SI.
822
7c0390e7 823 If the precision is not set, sort by the bytesize. A mode with
824 precision set gets sorted before a mode without precision set, if
47a2c1d4 825 they have the same bytesize; this is the right thing because
7c0390e7 826 the precision must always be smaller than the bytesize * BITS_PER_UNIT.
47a2c1d4 827 We don't have to do anything special to get this done -- an unset
7c0390e7 828 precision shows up as (unsigned int)-1, i.e. UINT_MAX. */
47a2c1d4 829static int
830cmp_modes (const void *a, const void *b)
831{
aae87fc3 832 const struct mode_data *const m = *(const struct mode_data *const*)a;
833 const struct mode_data *const n = *(const struct mode_data *const*)b;
47a2c1d4 834
835 if (m->bytesize > n->bytesize)
836 return 1;
837 else if (m->bytesize < n->bytesize)
838 return -1;
839
7c0390e7 840 if (m->precision > n->precision)
47a2c1d4 841 return 1;
7c0390e7 842 else if (m->precision < n->precision)
47a2c1d4 843 return -1;
844
845 if (!m->component && !n->component)
3c28f41a 846 {
847 if (m->counter < n->counter)
848 return -1;
849 else
850 return 1;
851 }
47a2c1d4 852
853 if (m->component->bytesize > n->component->bytesize)
854 return 1;
855 else if (m->component->bytesize < n->component->bytesize)
856 return -1;
857
7c0390e7 858 if (m->component->precision > n->component->precision)
47a2c1d4 859 return 1;
7c0390e7 860 else if (m->component->precision < n->component->precision)
47a2c1d4 861 return -1;
862
3c28f41a 863 if (m->counter < n->counter)
864 return -1;
865 else
866 return 1;
47a2c1d4 867}
868
869static void
870calc_wider_mode (void)
871{
e916c70c 872 int c;
47a2c1d4 873 struct mode_data *m;
874 struct mode_data **sortbuf;
875 unsigned int max_n_modes = 0;
876 unsigned int i, j;
877
878 for (c = 0; c < MAX_MODE_CLASS; c++)
879 max_n_modes = MAX (max_n_modes, n_modes[c]);
880
f0873ccc 881 /* Allocate max_n_modes + 1 entries to leave room for the extra null
882 pointer assigned after the qsort call below. */
de44e2b0 883 sortbuf = XALLOCAVEC (struct mode_data *, max_n_modes + 1);
47a2c1d4 884
885 for (c = 0; c < MAX_MODE_CLASS; c++)
886 {
887 /* "wider" is not meaningful for MODE_RANDOM and MODE_CC.
888 However, we want these in textual order, and we have
889 precisely the reverse. */
890 if (c == MODE_RANDOM || c == MODE_CC)
891 {
892 struct mode_data *prev, *next;
893
f58875bf 894 for (prev = 0, m = modes[c]; m; m = next)
47a2c1d4 895 {
896 m->wider = void_mode;
897
898 /* this is nreverse */
899 next = m->next;
900 m->next = prev;
901 prev = m;
902 }
f58875bf 903 modes[c] = prev;
47a2c1d4 904 }
905 else
906 {
f58875bf 907 if (!modes[c])
47a2c1d4 908 continue;
909
f58875bf 910 for (i = 0, m = modes[c]; m; i++, m = m->next)
47a2c1d4 911 sortbuf[i] = m;
912
c3808779 913 (qsort) (sortbuf, i, sizeof (struct mode_data *), cmp_modes);
47a2c1d4 914
915 sortbuf[i] = 0;
916 for (j = 0; j < i; j++)
c8076084 917 {
918 sortbuf[j]->next = sortbuf[j + 1];
919 if (c == MODE_PARTIAL_INT)
920 sortbuf[j]->wider = sortbuf[j]->component;
921 else
922 sortbuf[j]->wider = sortbuf[j]->next;
923 }
47a2c1d4 924
f58875bf 925 modes[c] = sortbuf[0];
47a2c1d4 926 }
927 }
928}
929
ba7efd65 930/* Text to add to the constant part of a poly_int_pod initializer in
931 order to fill out te whole structure. */
932#if NUM_POLY_INT_COEFFS == 1
933#define ZERO_COEFFS ""
934#elif NUM_POLY_INT_COEFFS == 2
935#define ZERO_COEFFS ", 0"
936#else
937#error "Unknown value of NUM_POLY_INT_COEFFS"
938#endif
939
47a2c1d4 940/* Output routines. */
941
942#define tagged_printf(FMT, ARG, TAG) do { \
cc253ec9 943 int count_ = printf (" " FMT ",", ARG); \
47a2c1d4 944 printf ("%*s/* %s */\n", 27 - count_, "", TAG); \
945} while (0)
946
947#define print_decl(TYPE, NAME, ASIZE) \
f58875bf 948 puts ("\nconst " TYPE " " NAME "[" ASIZE "] =\n{");
949
b75c5ec0 950#define print_maybe_const_decl(TYPE, NAME, ASIZE, NEEDS_ADJ) \
f58875bf 951 printf ("\n" TYPE " " NAME "[" ASIZE "] = \n{\n", \
b75c5ec0 952 NEEDS_ADJ ? "" : "const ")
47a2c1d4 953
954#define print_closer() puts ("};")
955
f9cb58ae 956/* Compute the max bitsize of some of the classes of integers. It may
957 be that there are needs for the other integer classes, and this
958 code is easy to extend. */
959static void
960emit_max_int (void)
961{
962 unsigned int max, mmax;
963 struct mode_data *i;
964 int j;
965
966 puts ("");
2cb32abf 967
968 printf ("#define BITS_PER_UNIT (%d)\n", bits_per_unit);
969
970 if (max_bitsize_mode_any_int == 0)
971 {
972 for (max = 1, i = modes[MODE_INT]; i; i = i->next)
973 if (max < i->bytesize)
974 max = i->bytesize;
975 mmax = max;
976 for (max = 1, i = modes[MODE_PARTIAL_INT]; i; i = i->next)
977 if (max < i->bytesize)
978 max = i->bytesize;
979 if (max > mmax)
980 mmax = max;
502c7fa9 981 printf ("#define MAX_BITSIZE_MODE_ANY_INT (%d*BITS_PER_UNIT)\n", mmax);
2cb32abf 982 }
983 else
984 printf ("#define MAX_BITSIZE_MODE_ANY_INT %d\n", max_bitsize_mode_any_int);
f9cb58ae 985
cbc28e8e 986 if (max_bitsize_mode_any_mode == 0)
987 {
988 mmax = 0;
989 for (j = 0; j < MAX_MODE_CLASS; j++)
990 for (i = modes[j]; i; i = i->next)
991 if (mmax < i->bytesize)
992 mmax = i->bytesize;
993 printf ("#define MAX_BITSIZE_MODE_ANY_MODE (%d*BITS_PER_UNIT)\n", mmax);
994 }
995 else
996 printf ("#define MAX_BITSIZE_MODE_ANY_MODE %d\n",
997 max_bitsize_mode_any_mode);
f9cb58ae 998}
999
e2ec52ca 1000/* Emit mode_size_inline routine into insn-modes.h header. */
1001static void
1002emit_mode_size_inline (void)
1003{
1004 int c;
1005 struct mode_adjust *a;
1006 struct mode_data *m;
1007
1008 /* Size adjustments must be propagated to all containing modes. */
1009 for (a = adj_bytesize; a; a = a->next)
1010 {
1011 a->mode->need_bytesize_adj = true;
1012 for (m = a->mode->contained; m; m = m->next_cont)
1013 m->need_bytesize_adj = true;
1014 }
1015
b75c5ec0 1016 /* Changing the number of units by a factor of X also changes the size
1017 by a factor of X. */
1018 for (mode_adjust *a = adj_nunits; a; a = a->next)
1019 a->mode->need_bytesize_adj = true;
1020
e2ec52ca 1021 printf ("\
1022#ifdef __cplusplus\n\
1023inline __attribute__((__always_inline__))\n\
1024#else\n\
1025extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1026#endif\n\
52acb7ae 1027poly_uint16\n\
3754d046 1028mode_size_inline (machine_mode mode)\n\
e2ec52ca 1029{\n\
52acb7ae 1030 extern %spoly_uint16_pod mode_size[NUM_MACHINE_MODES];\n\
7e1856f1 1031 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
e2ec52ca 1032 switch (mode)\n\
b75c5ec0 1033 {\n", adj_nunits || adj_bytesize ? "" : "const ");
e2ec52ca 1034
1035 for_all_modes (c, m)
1036 if (!m->need_bytesize_adj)
1e0295b9 1037 printf (" case E_%smode: return %u;\n", m->name, m->bytesize);
e2ec52ca 1038
1039 puts ("\
1040 default: return mode_size[mode];\n\
1041 }\n\
1042}\n");
1043}
1044
1045/* Emit mode_nunits_inline routine into insn-modes.h header. */
1046static void
1047emit_mode_nunits_inline (void)
1048{
1049 int c;
1050 struct mode_data *m;
1051
b75c5ec0 1052 for (mode_adjust *a = adj_nunits; a; a = a->next)
1053 a->mode->need_nunits_adj = true;
1054
1055 printf ("\
e2ec52ca 1056#ifdef __cplusplus\n\
1057inline __attribute__((__always_inline__))\n\
1058#else\n\
1059extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1060#endif\n\
ba7efd65 1061poly_uint16\n\
3754d046 1062mode_nunits_inline (machine_mode mode)\n\
e2ec52ca 1063{\n\
b75c5ec0 1064 extern %spoly_uint16_pod mode_nunits[NUM_MACHINE_MODES];\n\
e2ec52ca 1065 switch (mode)\n\
b75c5ec0 1066 {\n", adj_nunits ? "" : "const ");
e2ec52ca 1067
1068 for_all_modes (c, m)
b75c5ec0 1069 if (!m->need_nunits_adj)
1070 printf (" case E_%smode: return %u;\n", m->name, m->ncomponents);
e2ec52ca 1071
1072 puts ("\
1073 default: return mode_nunits[mode];\n\
1074 }\n\
1075}\n");
1076}
1077
1078/* Emit mode_inner_inline routine into insn-modes.h header. */
1079static void
1080emit_mode_inner_inline (void)
1081{
1082 int c;
1083 struct mode_data *m;
1084
1085 puts ("\
1086#ifdef __cplusplus\n\
1087inline __attribute__((__always_inline__))\n\
1088#else\n\
1089extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1090#endif\n\
1091unsigned char\n\
3754d046 1092mode_inner_inline (machine_mode mode)\n\
e2ec52ca 1093{\n\
1094 extern const unsigned char mode_inner[NUM_MACHINE_MODES];\n\
7e1856f1 1095 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
e2ec52ca 1096 switch (mode)\n\
1097 {");
1098
1099 for_all_modes (c, m)
1e0295b9 1100 printf (" case E_%smode: return E_%smode;\n", m->name,
e2ec52ca 1101 c != MODE_PARTIAL_INT && m->component
d145b68b 1102 ? m->component->name : m->name);
e2ec52ca 1103
1104 puts ("\
1105 default: return mode_inner[mode];\n\
1106 }\n\
1107}\n");
1108}
1109
a0509d0e 1110/* Emit mode_unit_size_inline routine into insn-modes.h header. */
1111static void
1112emit_mode_unit_size_inline (void)
1113{
1114 int c;
1115 struct mode_data *m;
1116
1117 puts ("\
1118#ifdef __cplusplus\n\
1119inline __attribute__((__always_inline__))\n\
1120#else\n\
1121extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1122#endif\n\
1123unsigned char\n\
1124mode_unit_size_inline (machine_mode mode)\n\
1125{\n\
6c090767 1126 extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES];\
1127\n\
7e1856f1 1128 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
a0509d0e 1129 switch (mode)\n\
1130 {");
1131
1132 for_all_modes (c, m)
1133 {
1134 const char *name = m->name;
1135 struct mode_data *m2 = m;
1136 if (c != MODE_PARTIAL_INT && m2->component)
1137 m2 = m2->component;
1138 if (!m2->need_bytesize_adj)
1e0295b9 1139 printf (" case E_%smode: return %u;\n", name, m2->bytesize);
a0509d0e 1140 }
1141
1142 puts ("\
1143 default: return mode_unit_size[mode];\n\
1144 }\n\
1145}\n");
1146}
1147
1148/* Emit mode_unit_precision_inline routine into insn-modes.h header. */
1149static void
1150emit_mode_unit_precision_inline (void)
1151{
1152 int c;
1153 struct mode_data *m;
1154
1155 puts ("\
1156#ifdef __cplusplus\n\
1157inline __attribute__((__always_inline__))\n\
1158#else\n\
1159extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1160#endif\n\
1161unsigned short\n\
1162mode_unit_precision_inline (machine_mode mode)\n\
1163{\n\
1164 extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES];\n\
7e1856f1 1165 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
a0509d0e 1166 switch (mode)\n\
1167 {");
1168
1169 for_all_modes (c, m)
1170 {
1171 struct mode_data *m2
1172 = (c != MODE_PARTIAL_INT && m->component) ? m->component : m;
1173 if (m2->precision != (unsigned int)-1)
1e0295b9 1174 printf (" case E_%smode: return %u;\n", m->name, m2->precision);
a0509d0e 1175 else
1e0295b9 1176 printf (" case E_%smode: return %u*BITS_PER_UNIT;\n",
a0509d0e 1177 m->name, m2->bytesize);
1178 }
1179
1180 puts ("\
1181 default: return mode_unit_precision[mode];\n\
1182 }\n\
1183}\n");
1184}
1185
47fbdc12 1186/* Return the best machine mode class for MODE, or null if machine_mode
1187 should be used. */
1188
1189static const char *
1190get_mode_class (struct mode_data *mode)
1191{
1192 switch (mode->cl)
1193 {
af8303fa 1194 case MODE_INT:
1195 case MODE_PARTIAL_INT:
1196 return "scalar_int_mode";
1197
9fcae33e 1198 case MODE_FRACT:
1199 case MODE_UFRACT:
1200 case MODE_ACCUM:
1201 case MODE_UACCUM:
9fcae33e 1202 return "scalar_mode";
1203
47fbdc12 1204 case MODE_FLOAT:
1205 case MODE_DECIMAL_FLOAT:
1206 return "scalar_float_mode";
1207
430c243d 1208 case MODE_COMPLEX_INT:
1209 case MODE_COMPLEX_FLOAT:
1210 return "complex_mode";
1211
47fbdc12 1212 default:
1213 return NULL;
1214 }
1215}
1216
47a2c1d4 1217static void
1218emit_insn_modes_h (void)
1219{
e916c70c 1220 int c;
47a2c1d4 1221 struct mode_data *m, *first, *last;
9f75f026 1222 int n_int_n_ents = 0;
47a2c1d4 1223
1224 printf ("/* Generated automatically from machmode.def%s%s\n",
1225 HAVE_EXTRA_MODES ? " and " : "",
1226 EXTRA_MODES_FILE);
1227
1228 puts ("\
1229 by genmodes. */\n\
1230\n\
1231#ifndef GCC_INSN_MODES_H\n\
1232#define GCC_INSN_MODES_H\n\
1233\n\
1234enum machine_mode\n{");
1235
1236 for (c = 0; c < MAX_MODE_CLASS; c++)
f58875bf 1237 for (m = modes[c]; m; m = m->next)
47a2c1d4 1238 {
1e0295b9 1239 int count_ = printf (" E_%smode,", m->name);
47a2c1d4 1240 printf ("%*s/* %s:%d */\n", 27 - count_, "",
1241 trim_filename (m->file), m->line);
d5957f0d 1242 printf ("#define HAVE_%smode\n", m->name);
fb398229 1243 printf ("#ifdef USE_ENUM_MODES\n");
1244 printf ("#define %smode E_%smode\n", m->name, m->name);
1245 printf ("#else\n");
47fbdc12 1246 if (const char *mode_class = get_mode_class (m))
1247 printf ("#define %smode (%s ((%s::from_int) E_%smode))\n",
1248 m->name, mode_class, mode_class, m->name);
1249 else
1250 printf ("#define %smode ((void) 0, E_%smode)\n",
1251 m->name, m->name);
fb398229 1252 printf ("#endif\n");
47a2c1d4 1253 }
1254
1255 puts (" MAX_MACHINE_MODE,\n");
1256
1257 for (c = 0; c < MAX_MODE_CLASS; c++)
1258 {
f58875bf 1259 first = modes[c];
47a2c1d4 1260 last = 0;
1261 for (m = first; m; last = m, m = m->next)
1262 ;
1263
1264 /* Don't use BImode for MIN_MODE_INT, since otherwise the middle
1265 end will try to use it for bitfields in structures and the
1266 like, which we do not want. Only the target md file should
1267 generate BImode widgets. */
0d58d930 1268 if (first && first->precision == 1 && c == MODE_INT)
47a2c1d4 1269 first = first->next;
1270
1271 if (first && last)
1e0295b9 1272 printf (" MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n",
47a2c1d4 1273 mode_class_names[c], first->name,
1274 mode_class_names[c], last->name);
1275 else
1e0295b9 1276 printf (" MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n",
47a2c1d4 1277 mode_class_names[c], void_mode->name,
1278 mode_class_names[c], void_mode->name);
1279 }
1280
1281 puts ("\
1282 NUM_MACHINE_MODES = MAX_MACHINE_MODE\n\
f58875bf 1283};\n");
1284
1285 /* I can't think of a better idea, can you? */
b75c5ec0 1286 printf ("#define CONST_MODE_NUNITS%s\n", adj_nunits ? "" : " const");
1287 printf ("#define CONST_MODE_PRECISION%s\n", adj_nunits ? "" : " const");
1288 printf ("#define CONST_MODE_SIZE%s\n",
1289 adj_bytesize || adj_nunits ? "" : " const");
a0509d0e 1290 printf ("#define CONST_MODE_UNIT_SIZE%s\n", adj_bytesize ? "" : " const");
f58875bf 1291 printf ("#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment ? "" : " const");
1292#if 0 /* disabled for backward compatibility, temporary */
1293 printf ("#define CONST_REAL_FORMAT_FOR_MODE%s\n", adj_format ? "" :" const");
1294#endif
c559c639 1295 printf ("#define CONST_MODE_IBIT%s\n", adj_ibit ? "" : " const");
1296 printf ("#define CONST_MODE_FBIT%s\n", adj_fbit ? "" : " const");
f9cb58ae 1297 emit_max_int ();
9f75f026 1298
1299 for_all_modes (c, m)
1300 if (m->int_n)
1301 n_int_n_ents ++;
1302
1303 printf ("#define NUM_INT_N_ENTS %d\n", n_int_n_ents);
1304
466432a3 1305 printf ("#define NUM_POLY_INT_COEFFS %d\n", NUM_POLY_INT_COEFFS);
1306
8734172d 1307 puts ("\
1308\n\
1309#endif /* insn-modes.h */");
1310}
1311
1312static void
1313emit_insn_modes_inline_h (void)
1314{
1315 printf ("/* Generated automatically from machmode.def%s%s\n",
1316 HAVE_EXTRA_MODES ? " and " : "",
1317 EXTRA_MODES_FILE);
1318
1319 puts ("\
1320 by genmodes. */\n\
1321\n\
1322#ifndef GCC_INSN_MODES_INLINE_H\n\
1323#define GCC_INSN_MODES_INLINE_H");
1324
3754d046 1325 puts ("\n#if !defined (USED_FOR_TARGET) && GCC_VERSION >= 4001\n");
e2ec52ca 1326 emit_mode_size_inline ();
1327 emit_mode_nunits_inline ();
1328 emit_mode_inner_inline ();
a0509d0e 1329 emit_mode_unit_size_inline ();
1330 emit_mode_unit_precision_inline ();
e2ec52ca 1331 puts ("#endif /* GCC_VERSION >= 4001 */");
1332
f58875bf 1333 puts ("\
47a2c1d4 1334\n\
8734172d 1335#endif /* insn-modes-inline.h */");
47a2c1d4 1336}
1337
1338static void
1339emit_insn_modes_c_header (void)
1340{
1341 printf ("/* Generated automatically from machmode.def%s%s\n",
1342 HAVE_EXTRA_MODES ? " and " : "",
1343 EXTRA_MODES_FILE);
1344
1345 puts ("\
1346 by genmodes. */\n\
1347\n\
47a2c1d4 1348#include \"config.h\"\n\
1349#include \"system.h\"\n\
1350#include \"coretypes.h\"\n\
1351#include \"tm.h\"\n\
15460c97 1352#include \"real.h\"");
1353}
1354
1355static void
1356emit_min_insn_modes_c_header (void)
1357{
1358 printf ("/* Generated automatically from machmode.def%s%s\n",
1359 HAVE_EXTRA_MODES ? " and " : "",
1360 EXTRA_MODES_FILE);
1361
1362 puts ("\
1363 by genmodes. */\n\
1364\n\
1365#include \"bconfig.h\"\n\
1366#include \"system.h\"\n\
8734172d 1367#include \"coretypes.h\"");
47a2c1d4 1368}
1369
1370static void
1371emit_mode_name (void)
1372{
e916c70c 1373 int c;
47a2c1d4 1374 struct mode_data *m;
1375
1376 print_decl ("char *const", "mode_name", "NUM_MACHINE_MODES");
1377
1378 for_all_modes (c, m)
1379 printf (" \"%s\",\n", m->name);
1380
1381 print_closer ();
1382}
1383
1384static void
1385emit_mode_class (void)
1386{
e916c70c 1387 int c;
47a2c1d4 1388 struct mode_data *m;
1389
1390 print_decl ("unsigned char", "mode_class", "NUM_MACHINE_MODES");
1391
1392 for_all_modes (c, m)
e916c70c 1393 tagged_printf ("%s", mode_class_names[m->cl], m->name);
47a2c1d4 1394
1395 print_closer ();
1396}
1397
1398static void
7c0390e7 1399emit_mode_precision (void)
47a2c1d4 1400{
e916c70c 1401 int c;
47a2c1d4 1402 struct mode_data *m;
1403
b75c5ec0 1404 print_maybe_const_decl ("%spoly_uint16_pod", "mode_precision",
1405 "NUM_MACHINE_MODES", adj_nunits);
47a2c1d4 1406
1407 for_all_modes (c, m)
7c0390e7 1408 if (m->precision != (unsigned int)-1)
3ce67adc 1409 tagged_printf ("{ %u" ZERO_COEFFS " }", m->precision, m->name);
47a2c1d4 1410 else
3ce67adc 1411 tagged_printf ("{ %u * BITS_PER_UNIT" ZERO_COEFFS " }",
1412 m->bytesize, m->name);
47a2c1d4 1413
1414 print_closer ();
1415}
1416
1417static void
1418emit_mode_size (void)
1419{
e916c70c 1420 int c;
47a2c1d4 1421 struct mode_data *m;
1422
52acb7ae 1423 print_maybe_const_decl ("%spoly_uint16_pod", "mode_size",
b75c5ec0 1424 "NUM_MACHINE_MODES", adj_nunits || adj_bytesize);
47a2c1d4 1425
1426 for_all_modes (c, m)
52acb7ae 1427 tagged_printf ("{ %u" ZERO_COEFFS " }", m->bytesize, m->name);
47a2c1d4 1428
1429 print_closer ();
1430}
1431
1432static void
b8bc42e9 1433emit_mode_nunits (void)
47a2c1d4 1434{
e916c70c 1435 int c;
47a2c1d4 1436 struct mode_data *m;
1437
b75c5ec0 1438 print_maybe_const_decl ("%spoly_uint16_pod", "mode_nunits",
1439 "NUM_MACHINE_MODES", adj_nunits);
47a2c1d4 1440
1441 for_all_modes (c, m)
ba7efd65 1442 tagged_printf ("{ %u" ZERO_COEFFS " }", m->ncomponents, m->name);
47a2c1d4 1443
1444 print_closer ();
1445}
1446
1447static void
1448emit_mode_wider (void)
1449{
e916c70c 1450 int c;
47a2c1d4 1451 struct mode_data *m;
1452
1453 print_decl ("unsigned char", "mode_wider", "NUM_MACHINE_MODES");
1454
1455 for_all_modes (c, m)
1e0295b9 1456 tagged_printf ("E_%smode",
47a2c1d4 1457 m->wider ? m->wider->name : void_mode->name,
1458 m->name);
1459
1460 print_closer ();
06633980 1461 print_decl ("unsigned char", "mode_2xwider", "NUM_MACHINE_MODES");
1462
1463 for_all_modes (c, m)
1464 {
1465 struct mode_data * m2;
1466
1467 for (m2 = m;
1468 m2 && m2 != void_mode;
1469 m2 = m2->wider)
1470 {
1471 if (m2->bytesize < 2 * m->bytesize)
1472 continue;
1473 if (m->precision != (unsigned int) -1)
1474 {
1475 if (m2->precision != 2 * m->precision)
1476 continue;
1477 }
1478 else
1479 {
1480 if (m2->precision != (unsigned int) -1)
1481 continue;
1482 }
1483
de44e2b0 1484 /* For vectors we want twice the number of components,
1485 with the same element type. */
8464736b 1486 if (m->cl == MODE_VECTOR_BOOL
1487 || m->cl == MODE_VECTOR_INT
de44e2b0 1488 || m->cl == MODE_VECTOR_FLOAT
1489 || m->cl == MODE_VECTOR_FRACT
1490 || m->cl == MODE_VECTOR_UFRACT
1491 || m->cl == MODE_VECTOR_ACCUM
1492 || m->cl == MODE_VECTOR_UACCUM)
1493 {
1494 if (m2->ncomponents != 2 * m->ncomponents)
1495 continue;
1496 if (m->component != m2->component)
1497 continue;
1498 }
1499
06633980 1500 break;
1501 }
1502 if (m2 == void_mode)
1503 m2 = 0;
1e0295b9 1504 tagged_printf ("E_%smode",
06633980 1505 m2 ? m2->name : void_mode->name,
1506 m->name);
1507 }
1508
1509 print_closer ();
47a2c1d4 1510}
1511
3c62cae0 1512static void
1513emit_mode_complex (void)
1514{
1515 int c;
1516 struct mode_data *m;
1517
1518 print_decl ("unsigned char", "mode_complex", "NUM_MACHINE_MODES");
1519
1520 for_all_modes (c, m)
1e0295b9 1521 tagged_printf ("E_%smode",
3c62cae0 1522 m->complex ? m->complex->name : void_mode->name,
1523 m->name);
1524
1525 print_closer ();
1526}
1527
47a2c1d4 1528static void
1529emit_mode_mask (void)
1530{
e916c70c 1531 int c;
47a2c1d4 1532 struct mode_data *m;
1533
1534 print_decl ("unsigned HOST_WIDE_INT", "mode_mask_array",
1535 "NUM_MACHINE_MODES");
1536 puts ("\
63bebd18 1537#define MODE_MASK(m) \\\n\
47a2c1d4 1538 ((m) >= HOST_BITS_PER_WIDE_INT) \\\n\
7097b942 1539 ? HOST_WIDE_INT_M1U \\\n\
edc19fd0 1540 : (HOST_WIDE_INT_1U << (m)) - 1\n");
47a2c1d4 1541
1542 for_all_modes (c, m)
7c0390e7 1543 if (m->precision != (unsigned int)-1)
1544 tagged_printf ("MODE_MASK (%u)", m->precision, m->name);
47a2c1d4 1545 else
63bebd18 1546 tagged_printf ("MODE_MASK (%u*BITS_PER_UNIT)", m->bytesize, m->name);
47a2c1d4 1547
63bebd18 1548 puts ("#undef MODE_MASK");
47a2c1d4 1549 print_closer ();
1550}
1551
1552static void
1553emit_mode_inner (void)
1554{
e916c70c 1555 int c;
47a2c1d4 1556 struct mode_data *m;
1557
1558 print_decl ("unsigned char", "mode_inner", "NUM_MACHINE_MODES");
1559
1560 for_all_modes (c, m)
1e0295b9 1561 tagged_printf ("E_%smode",
c8076084 1562 c != MODE_PARTIAL_INT && m->component
d145b68b 1563 ? m->component->name : m->name,
47a2c1d4 1564 m->name);
1565
1566 print_closer ();
1567}
1568
a0509d0e 1569/* Emit mode_unit_size array into insn-modes.c file. */
1570static void
1571emit_mode_unit_size (void)
1572{
1573 int c;
1574 struct mode_data *m;
1575
1576 print_maybe_const_decl ("%sunsigned char", "mode_unit_size",
b75c5ec0 1577 "NUM_MACHINE_MODES", adj_bytesize);
a0509d0e 1578
1579 for_all_modes (c, m)
1580 tagged_printf ("%u",
1581 c != MODE_PARTIAL_INT && m->component
1582 ? m->component->bytesize : m->bytesize, m->name);
1583
1584 print_closer ();
1585}
1586
1587/* Emit mode_unit_precision array into insn-modes.c file. */
1588static void
1589emit_mode_unit_precision (void)
1590{
1591 int c;
1592 struct mode_data *m;
1593
1594 print_decl ("unsigned short", "mode_unit_precision", "NUM_MACHINE_MODES");
1595
1596 for_all_modes (c, m)
1597 {
1598 struct mode_data *m2 = (c != MODE_PARTIAL_INT && m->component) ?
1599 m->component : m;
1600 if (m2->precision != (unsigned int)-1)
1601 tagged_printf ("%u", m2->precision, m->name);
1602 else
1603 tagged_printf ("%u*BITS_PER_UNIT", m2->bytesize, m->name);
1604 }
1605
1606 print_closer ();
1607}
1608
1609
47a2c1d4 1610static void
1611emit_mode_base_align (void)
1612{
e916c70c 1613 int c;
47a2c1d4 1614 struct mode_data *m;
1615
37d0f067 1616 print_maybe_const_decl ("%sunsigned short",
f58875bf 1617 "mode_base_align", "NUM_MACHINE_MODES",
b75c5ec0 1618 adj_alignment);
47a2c1d4 1619
1620 for_all_modes (c, m)
1621 tagged_printf ("%u", m->alignment, m->name);
1622
1623 print_closer ();
1624}
1625
1626static void
1627emit_class_narrowest_mode (void)
1628{
e916c70c 1629 int c;
47a2c1d4 1630
1631 print_decl ("unsigned char", "class_narrowest_mode", "MAX_MODE_CLASS");
1632
1633 for (c = 0; c < MAX_MODE_CLASS; c++)
1634 /* Bleah, all this to get the comment right for MIN_MODE_INT. */
1635 tagged_printf ("MIN_%s", mode_class_names[c],
f58875bf 1636 modes[c]
0d58d930 1637 ? ((c != MODE_INT || modes[c]->precision != 1)
f58875bf 1638 ? modes[c]->name
1639 : (modes[c]->next
1640 ? modes[c]->next->name
47a2c1d4 1641 : void_mode->name))
1642 : void_mode->name);
48e1416a 1643
47a2c1d4 1644 print_closer ();
1645}
1646
15460c97 1647static void
1648emit_real_format_for_mode (void)
1649{
1650 struct mode_data *m;
1651
f58875bf 1652 /* The entities pointed to by this table are constant, whether
1653 or not the table itself is constant.
1654
1655 For backward compatibility this table is always writable
4c834714 1656 (several targets modify it in TARGET_OPTION_OVERRIDE). FIXME:
f58875bf 1657 convert all said targets to use ADJUST_FORMAT instead. */
1658#if 0
1659 print_maybe_const_decl ("const struct real_format *%s",
1660 "real_format_for_mode",
1661 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1",
1662 format);
1663#else
1664 print_decl ("struct real_format *\n", "real_format_for_mode",
3c28f41a 1665 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1 "
1666 "+ MAX_MODE_DECIMAL_FLOAT - MIN_MODE_DECIMAL_FLOAT + 1");
f58875bf 1667#endif
15460c97 1668
3c28f41a 1669 /* The beginning of the table is entries for float modes. */
f58875bf 1670 for (m = modes[MODE_FLOAT]; m; m = m->next)
15460c97 1671 if (!strcmp (m->format, "0"))
1672 tagged_printf ("%s", m->format, m->name);
1673 else
1674 tagged_printf ("&%s", m->format, m->name);
1675
3c28f41a 1676 /* The end of the table is entries for decimal float modes. */
1677 for (m = modes[MODE_DECIMAL_FLOAT]; m; m = m->next)
1678 if (!strcmp (m->format, "0"))
1679 tagged_printf ("%s", m->format, m->name);
1680 else
1681 tagged_printf ("&%s", m->format, m->name);
1682
15460c97 1683 print_closer ();
1684}
1685
f58875bf 1686static void
1687emit_mode_adjustments (void)
1688{
1689 struct mode_adjust *a;
b8bc42e9 1690 struct mode_data *m;
f58875bf 1691
b8bc42e9 1692 puts ("\
1693\nvoid\
1694\ninit_adjust_machine_modes (void)\
1695\n{\
52acb7ae 1696\n poly_uint16 ps ATTRIBUTE_UNUSED;\n\
1697 size_t s ATTRIBUTE_UNUSED;");
f58875bf 1698
b75c5ec0 1699 for (a = adj_nunits; a; a = a->next)
1700 {
1701 m = a->mode;
1702 printf ("\n"
1703 " {\n"
1704 " /* %s:%d */\n ps = %s;\n",
1705 a->file, a->line, a->adjustment);
1706 printf (" int old_factor = vector_element_size"
1707 " (mode_precision[E_%smode], mode_nunits[E_%smode]);\n",
1708 m->name, m->name);
1709 printf (" mode_precision[E_%smode] = ps * old_factor;\n", m->name);
1710 printf (" mode_size[E_%smode] = exact_div (mode_precision[E_%smode],"
1711 " BITS_PER_UNIT);\n", m->name, m->name);
1712 printf (" mode_nunits[E_%smode] = ps;\n", m->name);
1713 printf (" }\n");
1714 }
1715
b8bc42e9 1716 /* Size adjustments must be propagated to all containing modes.
1717 A size adjustment forces us to recalculate the alignment too. */
f58875bf 1718 for (a = adj_bytesize; a; a = a->next)
b8bc42e9 1719 {
52acb7ae 1720 printf ("\n /* %s:%d */\n", a->file, a->line);
1721 switch (a->mode->cl)
1722 {
8464736b 1723 case MODE_VECTOR_BOOL:
52acb7ae 1724 case MODE_VECTOR_INT:
1725 case MODE_VECTOR_FLOAT:
1726 case MODE_VECTOR_FRACT:
1727 case MODE_VECTOR_UFRACT:
1728 case MODE_VECTOR_ACCUM:
1729 case MODE_VECTOR_UACCUM:
1730 printf (" ps = %s;\n", a->adjustment);
1731 printf (" s = mode_unit_size[E_%smode];\n", a->mode->name);
1732 break;
1733
1734 default:
1735 printf (" ps = s = %s;\n", a->adjustment);
1736 printf (" mode_unit_size[E_%smode] = s;\n", a->mode->name);
1737 break;
1738 }
1739 printf (" mode_size[E_%smode] = ps;\n", a->mode->name);
1740 printf (" mode_base_align[E_%smode] = known_alignment (ps);\n",
b8bc42e9 1741 a->mode->name);
1742
1743 for (m = a->mode->contained; m; m = m->next_cont)
1744 {
e916c70c 1745 switch (m->cl)
b8bc42e9 1746 {
1747 case MODE_COMPLEX_INT:
1748 case MODE_COMPLEX_FLOAT:
1e0295b9 1749 printf (" mode_size[E_%smode] = 2*s;\n", m->name);
1750 printf (" mode_unit_size[E_%smode] = s;\n", m->name);
1751 printf (" mode_base_align[E_%smode] = s & (~s + 1);\n",
b8bc42e9 1752 m->name);
1753 break;
1754
8464736b 1755 case MODE_VECTOR_BOOL:
1756 /* Changes to BImode should not affect vector booleans. */
1757 break;
1758
b8bc42e9 1759 case MODE_VECTOR_INT:
1760 case MODE_VECTOR_FLOAT:
c559c639 1761 case MODE_VECTOR_FRACT:
1762 case MODE_VECTOR_UFRACT:
1763 case MODE_VECTOR_ACCUM:
1764 case MODE_VECTOR_UACCUM:
52acb7ae 1765 printf (" mode_size[E_%smode] = %d * ps;\n",
b8bc42e9 1766 m->name, m->ncomponents);
1e0295b9 1767 printf (" mode_unit_size[E_%smode] = s;\n", m->name);
52acb7ae 1768 printf (" mode_base_align[E_%smode]"
1769 " = known_alignment (%d * ps);\n",
1770 m->name, m->ncomponents);
b8bc42e9 1771 break;
1772
1773 default:
1774 internal_error (
1775 "mode %s is neither vector nor complex but contains %s",
1776 m->name, a->mode->name);
1777 /* NOTREACHED */
1778 }
1779 }
1780 }
f58875bf 1781
b8bc42e9 1782 /* Alignment adjustments propagate too.
1783 ??? This may not be the right thing for vector modes. */
f58875bf 1784 for (a = adj_alignment; a; a = a->next)
b8bc42e9 1785 {
1786 printf ("\n /* %s:%d */\n s = %s;\n",
1787 a->file, a->line, a->adjustment);
1e0295b9 1788 printf (" mode_base_align[E_%smode] = s;\n", a->mode->name);
f58875bf 1789
b8bc42e9 1790 for (m = a->mode->contained; m; m = m->next_cont)
1791 {
e916c70c 1792 switch (m->cl)
b8bc42e9 1793 {
1794 case MODE_COMPLEX_INT:
1795 case MODE_COMPLEX_FLOAT:
1e0295b9 1796 printf (" mode_base_align[E_%smode] = s;\n", m->name);
b8bc42e9 1797 break;
1798
8464736b 1799 case MODE_VECTOR_BOOL:
1800 /* Changes to BImode should not affect vector booleans. */
1801 break;
1802
b8bc42e9 1803 case MODE_VECTOR_INT:
1804 case MODE_VECTOR_FLOAT:
c559c639 1805 case MODE_VECTOR_FRACT:
1806 case MODE_VECTOR_UFRACT:
1807 case MODE_VECTOR_ACCUM:
1808 case MODE_VECTOR_UACCUM:
1e0295b9 1809 printf (" mode_base_align[E_%smode] = %d*s;\n",
b8bc42e9 1810 m->name, m->ncomponents);
1811 break;
1812
1813 default:
1814 internal_error (
1815 "mode %s is neither vector nor complex but contains %s",
1816 m->name, a->mode->name);
1817 /* NOTREACHED */
1818 }
1819 }
1820 }
c559c639 1821
1822 /* Ibit adjustments don't have to propagate. */
1823 for (a = adj_ibit; a; a = a->next)
1824 {
1825 printf ("\n /* %s:%d */\n s = %s;\n",
1826 a->file, a->line, a->adjustment);
1e0295b9 1827 printf (" mode_ibit[E_%smode] = s;\n", a->mode->name);
c559c639 1828 }
1829
1830 /* Fbit adjustments don't have to propagate. */
1831 for (a = adj_fbit; a; a = a->next)
1832 {
1833 printf ("\n /* %s:%d */\n s = %s;\n",
1834 a->file, a->line, a->adjustment);
1e0295b9 1835 printf (" mode_fbit[E_%smode] = s;\n", a->mode->name);
c559c639 1836 }
48e1416a 1837
b8bc42e9 1838 /* Real mode formats don't have to propagate anywhere. */
f58875bf 1839 for (a = adj_format; a; a = a->next)
1e0295b9 1840 printf ("\n /* %s:%d */\n REAL_MODE_FORMAT (E_%smode) = %s;\n",
f58875bf 1841 a->file, a->line, a->mode->name, a->adjustment);
1842
1843 puts ("}");
1844}
1845
c559c639 1846/* Emit ibit for all modes. */
1847
1848static void
1849emit_mode_ibit (void)
1850{
1851 int c;
1852 struct mode_data *m;
1853
1854 print_maybe_const_decl ("%sunsigned char",
1855 "mode_ibit", "NUM_MACHINE_MODES",
b75c5ec0 1856 adj_ibit);
c559c639 1857
1858 for_all_modes (c, m)
1859 tagged_printf ("%u", m->ibit, m->name);
1860
1861 print_closer ();
1862}
1863
1864/* Emit fbit for all modes. */
1865
1866static void
1867emit_mode_fbit (void)
1868{
1869 int c;
1870 struct mode_data *m;
1871
1872 print_maybe_const_decl ("%sunsigned char",
1873 "mode_fbit", "NUM_MACHINE_MODES",
b75c5ec0 1874 adj_fbit);
c559c639 1875
1876 for_all_modes (c, m)
1877 tagged_printf ("%u", m->fbit, m->name);
1878
1879 print_closer ();
1880}
1881
9f75f026 1882/* Emit __intN for all modes. */
1883
1884static void
1885emit_mode_int_n (void)
1886{
1887 int c;
1888 struct mode_data *m;
1889 struct mode_data **mode_sort;
1890 int n_modes = 0;
1891 int i, j;
1892
1893 print_decl ("int_n_data_t", "int_n_data", "");
1894
1895 n_modes = 0;
1896 for_all_modes (c, m)
1897 if (m->int_n)
1898 n_modes ++;
1899 mode_sort = XALLOCAVEC (struct mode_data *, n_modes);
1900
1901 n_modes = 0;
1902 for_all_modes (c, m)
1903 if (m->int_n)
1904 mode_sort[n_modes++] = m;
1905
1906 /* Yes, this is a bubblesort, but there are at most four (and
1907 usually only 1-2) entries to sort. */
1908 for (i = 0; i<n_modes - 1; i++)
1909 for (j = i + 1; j < n_modes; j++)
1910 if (mode_sort[i]->int_n > mode_sort[j]->int_n)
dfcf26a5 1911 std::swap (mode_sort[i], mode_sort[j]);
9f75f026 1912
1913 for (i = 0; i < n_modes; i ++)
1914 {
1915 m = mode_sort[i];
1916 printf(" {\n");
1917 tagged_printf ("%u", m->int_n, m->name);
ced5293f 1918 printf ("{ E_%smode },", m->name);
9f75f026 1919 printf(" },\n");
1920 }
1921
1922 print_closer ();
1923}
1924
c559c639 1925
47a2c1d4 1926static void
1927emit_insn_modes_c (void)
1928{
1929 emit_insn_modes_c_header ();
1930 emit_mode_name ();
1931 emit_mode_class ();
7c0390e7 1932 emit_mode_precision ();
47a2c1d4 1933 emit_mode_size ();
b8bc42e9 1934 emit_mode_nunits ();
47a2c1d4 1935 emit_mode_wider ();
3c62cae0 1936 emit_mode_complex ();
47a2c1d4 1937 emit_mode_mask ();
1938 emit_mode_inner ();
a0509d0e 1939 emit_mode_unit_size ();
1940 emit_mode_unit_precision ();
47a2c1d4 1941 emit_mode_base_align ();
1942 emit_class_narrowest_mode ();
15460c97 1943 emit_real_format_for_mode ();
f58875bf 1944 emit_mode_adjustments ();
c559c639 1945 emit_mode_ibit ();
1946 emit_mode_fbit ();
9f75f026 1947 emit_mode_int_n ();
15460c97 1948}
1949
1950static void
1951emit_min_insn_modes_c (void)
1952{
1953 emit_min_insn_modes_c_header ();
1954 emit_mode_name ();
1955 emit_mode_class ();
9b067f04 1956 emit_mode_nunits ();
15460c97 1957 emit_mode_wider ();
9b067f04 1958 emit_mode_inner ();
15460c97 1959 emit_class_narrowest_mode ();
47a2c1d4 1960}
1961
1962/* Master control. */
1963int
d4473c84 1964main (int argc, char **argv)
47a2c1d4 1965{
8734172d 1966 bool gen_header = false, gen_inlines = false, gen_min = false;
47a2c1d4 1967 progname = argv[0];
1968
1969 if (argc == 1)
15460c97 1970 ;
47a2c1d4 1971 else if (argc == 2 && !strcmp (argv[1], "-h"))
1972 gen_header = true;
8734172d 1973 else if (argc == 2 && !strcmp (argv[1], "-i"))
1974 gen_inlines = true;
15460c97 1975 else if (argc == 2 && !strcmp (argv[1], "-m"))
1976 gen_min = true;
47a2c1d4 1977 else
1978 {
8734172d 1979 error ("usage: %s [-h|-i|-m] > file", progname);
47a2c1d4 1980 return FATAL_EXIT_CODE;
1981 }
1982
f58875bf 1983 modes_by_name = htab_create_alloc (64, hash_mode, eq_mode, 0, xcalloc, free);
1984
47a2c1d4 1985 create_modes ();
1986 complete_all_modes ();
1987
1988 if (have_error)
1989 return FATAL_EXIT_CODE;
48e1416a 1990
47a2c1d4 1991 calc_wider_mode ();
1992
1993 if (gen_header)
1994 emit_insn_modes_h ();
8734172d 1995 else if (gen_inlines)
1996 emit_insn_modes_inline_h ();
15460c97 1997 else if (gen_min)
1998 emit_min_insn_modes_c ();
47a2c1d4 1999 else
2000 emit_insn_modes_c ();
2001
2002 if (fflush (stdout) || fclose (stdout))
2003 return FATAL_EXIT_CODE;
2004 return SUCCESS_EXIT_CODE;
2005}