1 /* Generate the machine mode enumeration and associated tables.
2 Copyright (C) 2003, 2004
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
27 /* enum mode_class is normally defined by machmode.h but we can't
28 include that header here. */
29 #include "mode-classes.def"
31 #define DEF_MODE_CLASS(M) M
32 enum mode_class
{ MODE_CLASSES
, MAX_MODE_CLASS
};
35 /* Text names of mode classes, for output. */
36 #define DEF_MODE_CLASS(M) #M
37 static const char *const mode_class_names
[MAX_MODE_CLASS
] =
44 #ifdef EXTRA_MODES_FILE
45 # define HAVE_EXTRA_MODES 1
47 # define HAVE_EXTRA_MODES 0
48 # define EXTRA_MODES_FILE ""
51 /* Data structure for building up what we know about a mode.
52 They're clustered by mode class. */
55 struct mode_data
*next
; /* next this class - arbitrary order */
57 const char *name
; /* printable mode name -- SI, not SImode */
58 enum mode_class cl
; /* this mode class */
59 unsigned int precision
; /* size in bits, equiv to TYPE_PRECISION */
60 unsigned int bytesize
; /* storage size in addressable units */
61 unsigned int ncomponents
; /* number of subunits */
62 unsigned int alignment
; /* mode alignment */
63 const char *format
; /* floating point format - float modes only */
65 struct mode_data
*component
; /* mode of components */
66 struct mode_data
*wider
; /* next wider mode */
67 struct mode_data
*wider_2x
; /* 2x wider mode */
69 struct mode_data
*contained
; /* Pointer to list of modes that have
70 this mode as a component. */
71 struct mode_data
*next_cont
; /* Next mode in that list. */
73 const char *file
; /* file and line of definition, */
74 unsigned int line
; /* for error reporting */
75 unsigned int counter
; /* Rank ordering of modes */
78 static struct mode_data
*modes
[MAX_MODE_CLASS
];
79 static unsigned int n_modes
[MAX_MODE_CLASS
];
80 static struct mode_data
*void_mode
;
82 static const struct mode_data blank_mode
= {
83 0, "<unknown>", MAX_MODE_CLASS
,
89 static htab_t modes_by_name
;
91 /* Data structure for recording target-specified runtime adjustments
92 to a particular mode. We support varying the byte size, the
93 alignment, and the floating point format. */
96 struct mode_adjust
*next
;
97 struct mode_data
*mode
;
98 const char *adjustment
;
104 static struct mode_adjust
*adj_bytesize
;
105 static struct mode_adjust
*adj_alignment
;
106 static struct mode_adjust
*adj_format
;
108 /* Mode class operations. */
109 static enum mode_class
110 complex_class (enum mode_class c
)
114 case MODE_INT
: return MODE_COMPLEX_INT
;
115 case MODE_FLOAT
: return MODE_COMPLEX_FLOAT
;
117 error ("no complex class for class %s", mode_class_names
[c
]);
122 static enum mode_class
123 vector_class (enum mode_class cl
)
127 case MODE_INT
: return MODE_VECTOR_INT
;
128 case MODE_FLOAT
: return MODE_VECTOR_FLOAT
;
130 error ("no vector class for class %s", mode_class_names
[cl
]);
135 /* Utility routines. */
136 static inline struct mode_data
*
137 find_mode (const char *name
)
139 struct mode_data key
;
142 return (struct mode_data
*) htab_find (modes_by_name
, &key
);
145 static struct mode_data
*
146 new_mode (enum mode_class cl
, const char *name
,
147 const char *file
, unsigned int line
)
150 static unsigned int count
= 0;
152 m
= find_mode (name
);
155 error ("%s:%d: duplicate definition of mode \"%s\"",
156 trim_filename (file
), line
, name
);
157 error ("%s:%d: previous definition here", m
->file
, m
->line
);
161 m
= XNEW (struct mode_data
);
162 memcpy (m
, &blank_mode
, sizeof (struct mode_data
));
166 m
->file
= trim_filename (file
);
168 m
->counter
= count
++;
174 *htab_find_slot (modes_by_name
, m
, INSERT
) = m
;
180 hash_mode (const void *p
)
182 const struct mode_data
*m
= (const struct mode_data
*)p
;
183 return htab_hash_string (m
->name
);
187 eq_mode (const void *p
, const void *q
)
189 const struct mode_data
*a
= (const struct mode_data
*)p
;
190 const struct mode_data
*b
= (const struct mode_data
*)q
;
192 return !strcmp (a
->name
, b
->name
);
195 #define for_all_modes(C, M) \
196 for (C = 0; C < MAX_MODE_CLASS; C++) \
197 for (M = modes[C]; M; M = M->next)
199 static void ATTRIBUTE_UNUSED
200 new_adjust (const char *name
,
201 struct mode_adjust
**category
, const char *catname
,
202 const char *adjustment
,
203 enum mode_class required_class
,
204 const char *file
, unsigned int line
)
206 struct mode_data
*mode
= find_mode (name
);
207 struct mode_adjust
*a
;
209 file
= trim_filename (file
);
213 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
217 if (required_class
!= MODE_RANDOM
&& mode
->cl
!= required_class
)
219 error ("%s:%d: mode \"%s\" is not class %s",
220 file
, line
, name
, mode_class_names
[required_class
] + 5);
224 for (a
= *category
; a
; a
= a
->next
)
227 error ("%s:%d: mode \"%s\" already has a %s adjustment",
228 file
, line
, name
, catname
);
229 error ("%s:%d: previous adjustment here", a
->file
, a
->line
);
233 a
= XNEW (struct mode_adjust
);
235 a
->adjustment
= adjustment
;
243 /* Diagnose failure to meet expectations in a partially filled out
245 enum requirement
{ SET
, UNSET
, OPTIONAL
};
247 #define validate_field_(mname, fname, req, val, unset, file, line) do { \
252 error ("%s:%d: (%s) field %s must be set", \
253 file, line, mname, fname); \
257 error ("%s:%d: (%s) field %s must not be set", \
258 file, line, mname, fname); \
264 #define validate_field(M, F) \
265 validate_field_(M->name, #F, r_##F, M->F, blank_mode.F, M->file, M->line)
268 validate_mode (struct mode_data
*m
,
269 enum requirement r_precision
,
270 enum requirement r_bytesize
,
271 enum requirement r_component
,
272 enum requirement r_ncomponents
,
273 enum requirement r_format
)
275 validate_field (m
, precision
);
276 validate_field (m
, bytesize
);
277 validate_field (m
, component
);
278 validate_field (m
, ncomponents
);
279 validate_field (m
, format
);
281 #undef validate_field
282 #undef validate_field_
284 /* Given a partially-filled-out mode structure, figure out what we can
285 and fill the rest of it in; die if it isn't enough. */
287 complete_mode (struct mode_data
*m
)
289 unsigned int alignment
;
293 error ("%s:%d: mode with no name", m
->file
, m
->line
);
296 if (m
->cl
== MAX_MODE_CLASS
)
298 error ("%s:%d: %smode has no mode class", m
->file
, m
->line
, m
->name
);
305 /* Nothing more need be said. */
306 if (!strcmp (m
->name
, "VOID"))
309 validate_mode (m
, UNSET
, UNSET
, UNSET
, UNSET
, UNSET
);
318 /* Again, nothing more need be said. For historical reasons,
319 the size of a CC mode is four units. */
320 validate_mode (m
, UNSET
, UNSET
, UNSET
, UNSET
, UNSET
);
329 case MODE_DECIMAL_FLOAT
:
330 /* A scalar mode must have a byte size, may have a bit size,
331 and must not have components. A float mode must have a
333 validate_mode (m
, OPTIONAL
, SET
, UNSET
, UNSET
,
334 m
->cl
!= MODE_INT
? SET
: UNSET
);
340 case MODE_PARTIAL_INT
:
341 /* A partial integer mode uses ->component to say what the
342 corresponding full-size integer mode is, and may also
343 specify a bit size. */
344 validate_mode (m
, OPTIONAL
, UNSET
, SET
, UNSET
, UNSET
);
346 m
->bytesize
= m
->component
->bytesize
;
349 m
->component
= 0; /* ??? preserve this */
352 case MODE_COMPLEX_INT
:
353 case MODE_COMPLEX_FLOAT
:
354 /* Complex modes should have a component indicated, but no more. */
355 validate_mode (m
, UNSET
, UNSET
, SET
, UNSET
, UNSET
);
357 if (m
->component
->precision
!= (unsigned int)-1)
358 m
->precision
= 2 * m
->component
->precision
;
359 m
->bytesize
= 2 * m
->component
->bytesize
;
362 case MODE_VECTOR_INT
:
363 case MODE_VECTOR_FLOAT
:
364 /* Vector modes should have a component and a number of components. */
365 validate_mode (m
, UNSET
, UNSET
, SET
, SET
, UNSET
);
366 if (m
->component
->precision
!= (unsigned int)-1)
367 m
->precision
= m
->ncomponents
* m
->component
->precision
;
368 m
->bytesize
= m
->ncomponents
* m
->component
->bytesize
;
375 /* If not already specified, the mode alignment defaults to the largest
376 power of two that divides the size of the object. Complex types are
377 not more aligned than their contents. */
378 if (m
->cl
== MODE_COMPLEX_INT
|| m
->cl
== MODE_COMPLEX_FLOAT
)
379 alignment
= m
->component
->bytesize
;
381 alignment
= m
->bytesize
;
383 m
->alignment
= alignment
& (~alignment
+ 1);
385 /* If this mode has components, make the component mode point back
386 to this mode, for the sake of adjustments. */
389 m
->next_cont
= m
->component
->contained
;
390 m
->component
->contained
= m
;
395 complete_all_modes (void)
400 for_all_modes (cl
, m
)
404 /* For each mode in class CLASS, construct a corresponding complex mode. */
405 #define COMPLEX_MODES(C) make_complex_modes(MODE_##C, __FILE__, __LINE__)
407 make_complex_modes (enum mode_class cl
,
408 const char *file
, unsigned int line
)
413 enum mode_class cclass
= complex_class (cl
);
415 if (cclass
== MODE_RANDOM
)
418 for (m
= modes
[cl
]; m
; m
= m
->next
)
420 /* Skip BImode. FIXME: BImode probably shouldn't be MODE_INT. */
421 if (m
->precision
== 1)
424 if (strlen (m
->name
) >= sizeof buf
)
426 error ("%s:%d:mode name \"%s\" is too long",
427 m
->file
, m
->line
, m
->name
);
431 /* Float complex modes are named SCmode, etc.
432 Int complex modes are named CSImode, etc.
433 This inconsistency should be eliminated. */
434 if (cl
== MODE_FLOAT
)
437 strncpy (buf
, m
->name
, sizeof buf
);
438 p
= strchr (buf
, 'F');
440 q
= strchr (buf
, 'D');
441 if (p
== 0 && q
== 0)
443 error ("%s:%d: float mode \"%s\" has no 'F' or 'D'",
444 m
->file
, m
->line
, m
->name
);
451 snprintf (buf
, sizeof buf
, "C%s", m
->name
);
454 snprintf (buf
, sizeof buf
, "C%s", m
->name
);
456 c
= new_mode (cclass
, xstrdup (buf
), file
, line
);
461 /* For all modes in class CL, construct vector modes of width
462 WIDTH, having as many components as necessary. */
463 #define VECTOR_MODES(C, W) make_vector_modes(MODE_##C, W, __FILE__, __LINE__)
464 static void ATTRIBUTE_UNUSED
465 make_vector_modes (enum mode_class cl
, unsigned int width
,
466 const char *file
, unsigned int line
)
471 unsigned int ncomponents
;
472 enum mode_class vclass
= vector_class (cl
);
474 if (vclass
== MODE_RANDOM
)
477 for (m
= modes
[cl
]; m
; m
= m
->next
)
479 /* Do not construct vector modes with only one element, or
480 vector modes where the element size doesn't divide the full
482 ncomponents
= width
/ m
->bytesize
;
485 if (width
% m
->bytesize
)
488 /* Skip QFmode and BImode. FIXME: this special case should
490 if (cl
== MODE_FLOAT
&& m
->bytesize
== 1)
492 if (cl
== MODE_INT
&& m
->precision
== 1)
495 if ((size_t)snprintf (buf
, sizeof buf
, "V%u%s", ncomponents
, m
->name
)
498 error ("%s:%d: mode name \"%s\" is too long",
499 m
->file
, m
->line
, m
->name
);
503 v
= new_mode (vclass
, xstrdup (buf
), file
, line
);
505 v
->ncomponents
= ncomponents
;
511 #define _SPECIAL_MODE(C, N) make_special_mode(MODE_##C, #N, __FILE__, __LINE__)
512 #define RANDOM_MODE(N) _SPECIAL_MODE (RANDOM, N)
513 #define CC_MODE(N) _SPECIAL_MODE (CC, N)
516 make_special_mode (enum mode_class cl
, const char *name
,
517 const char *file
, unsigned int line
)
519 new_mode (cl
, name
, file
, line
);
522 #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y)
523 #define FRACTIONAL_INT_MODE(N, B, Y) \
524 make_int_mode (#N, B, Y, __FILE__, __LINE__)
527 make_int_mode (const char *name
,
528 unsigned int precision
, unsigned int bytesize
,
529 const char *file
, unsigned int line
)
531 struct mode_data
*m
= new_mode (MODE_INT
, name
, file
, line
);
532 m
->bytesize
= bytesize
;
533 m
->precision
= precision
;
536 #define FLOAT_MODE(N, Y, F) FRACTIONAL_FLOAT_MODE (N, -1U, Y, F)
537 #define FRACTIONAL_FLOAT_MODE(N, B, Y, F) \
538 make_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
541 make_float_mode (const char *name
,
542 unsigned int precision
, unsigned int bytesize
,
544 const char *file
, unsigned int line
)
546 struct mode_data
*m
= new_mode (MODE_FLOAT
, name
, file
, line
);
547 m
->bytesize
= bytesize
;
548 m
->precision
= precision
;
552 #define DECIMAL_FLOAT_MODE(N, Y, F) \
553 FRACTIONAL_DECIMAL_FLOAT_MODE (N, -1U, Y, F)
554 #define FRACTIONAL_DECIMAL_FLOAT_MODE(N, B, Y, F) \
555 make_decimal_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
558 make_decimal_float_mode (const char *name
,
559 unsigned int precision
, unsigned int bytesize
,
561 const char *file
, unsigned int line
)
563 struct mode_data
*m
= new_mode (MODE_DECIMAL_FLOAT
, name
, file
, line
);
564 m
->bytesize
= bytesize
;
565 m
->precision
= precision
;
569 #define RESET_FLOAT_FORMAT(N, F) \
570 reset_float_format (#N, #F, __FILE__, __LINE__)
571 static void ATTRIBUTE_UNUSED
572 reset_float_format (const char *name
, const char *format
,
573 const char *file
, unsigned int line
)
575 struct mode_data
*m
= find_mode (name
);
578 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
581 if (m
->cl
!= MODE_FLOAT
&& m
->cl
!= MODE_DECIMAL_FLOAT
)
583 error ("%s:%d: mode \"%s\" is not a FLOAT class", file
, line
, name
);
589 /* Partial integer modes are specified by relation to a full integer mode.
590 For now, we do not attempt to narrow down their bit sizes. */
591 #define PARTIAL_INT_MODE(M) \
592 make_partial_integer_mode (#M, "P" #M, -1U, __FILE__, __LINE__)
593 static void ATTRIBUTE_UNUSED
594 make_partial_integer_mode (const char *base
, const char *name
,
595 unsigned int precision
,
596 const char *file
, unsigned int line
)
599 struct mode_data
*component
= find_mode (base
);
602 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
605 if (component
->cl
!= MODE_INT
)
607 error ("%s:%d: mode \"%s\" is not class INT", file
, line
, name
);
611 m
= new_mode (MODE_PARTIAL_INT
, name
, file
, line
);
612 m
->precision
= precision
;
613 m
->component
= component
;
616 /* A single vector mode can be specified by naming its component
617 mode and the number of components. */
618 #define VECTOR_MODE(C, M, N) \
619 make_vector_mode (MODE_##C, #M, N, __FILE__, __LINE__);
620 static void ATTRIBUTE_UNUSED
621 make_vector_mode (enum mode_class bclass
,
623 unsigned int ncomponents
,
624 const char *file
, unsigned int line
)
627 enum mode_class vclass
= vector_class (bclass
);
628 struct mode_data
*component
= find_mode (base
);
631 if (vclass
== MODE_RANDOM
)
635 error ("%s:%d: no mode \"%s\"", file
, line
, base
);
638 if (component
->cl
!= bclass
)
640 error ("%s:%d: mode \"%s\" is not class %s",
641 file
, line
, base
, mode_class_names
[bclass
] + 5);
645 if ((size_t)snprintf (namebuf
, sizeof namebuf
, "V%u%s",
646 ncomponents
, base
) >= sizeof namebuf
)
648 error ("%s:%d: mode name \"%s\" is too long",
653 v
= new_mode (vclass
, xstrdup (namebuf
), file
, line
);
654 v
->ncomponents
= ncomponents
;
655 v
->component
= component
;
659 #define _ADD_ADJUST(A, M, X, C) \
660 new_adjust (#M, &adj_##A, #A, #X, MODE_##C, __FILE__, __LINE__)
662 #define ADJUST_BYTESIZE(M, X) _ADD_ADJUST(bytesize, M, X, RANDOM)
663 #define ADJUST_ALIGNMENT(M, X) _ADD_ADJUST(alignment, M, X, RANDOM)
664 #define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST(format, M, X, FLOAT)
669 #include "machmode.def"
674 /* Sort a list of modes into the order needed for the WIDER field:
675 major sort by precision, minor sort by component precision.
678 QI < HI < SI < DI < TI
679 V4QI < V2HI < V8QI < V4HI < V2SI.
681 If the precision is not set, sort by the bytesize. A mode with
682 precision set gets sorted before a mode without precision set, if
683 they have the same bytesize; this is the right thing because
684 the precision must always be smaller than the bytesize * BITS_PER_UNIT.
685 We don't have to do anything special to get this done -- an unset
686 precision shows up as (unsigned int)-1, i.e. UINT_MAX. */
688 cmp_modes (const void *a
, const void *b
)
690 struct mode_data
*m
= *(struct mode_data
**)a
;
691 struct mode_data
*n
= *(struct mode_data
**)b
;
693 if (m
->bytesize
> n
->bytesize
)
695 else if (m
->bytesize
< n
->bytesize
)
698 if (m
->precision
> n
->precision
)
700 else if (m
->precision
< n
->precision
)
703 if (!m
->component
&& !n
->component
)
705 if (m
->counter
< n
->counter
)
711 if (m
->component
->bytesize
> n
->component
->bytesize
)
713 else if (m
->component
->bytesize
< n
->component
->bytesize
)
716 if (m
->component
->precision
> n
->component
->precision
)
718 else if (m
->component
->precision
< n
->component
->precision
)
721 if (m
->counter
< n
->counter
)
728 calc_wider_mode (void)
732 struct mode_data
**sortbuf
;
733 unsigned int max_n_modes
= 0;
736 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
737 max_n_modes
= MAX (max_n_modes
, n_modes
[c
]);
739 /* Allocate max_n_modes + 1 entries to leave room for the extra null
740 pointer assigned after the qsort call below. */
741 sortbuf
= (struct mode_data
**) alloca ((max_n_modes
+ 1) * sizeof (struct mode_data
*));
743 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
745 /* "wider" is not meaningful for MODE_RANDOM and MODE_CC.
746 However, we want these in textual order, and we have
747 precisely the reverse. */
748 if (c
== MODE_RANDOM
|| c
== MODE_CC
)
750 struct mode_data
*prev
, *next
;
752 for (prev
= 0, m
= modes
[c
]; m
; m
= next
)
754 m
->wider
= void_mode
;
755 m
->wider_2x
= void_mode
;
757 /* this is nreverse */
769 for (i
= 0, m
= modes
[c
]; m
; i
++, m
= m
->next
)
772 qsort (sortbuf
, i
, sizeof (struct mode_data
*), cmp_modes
);
775 for (j
= 0; j
< i
; j
++)
776 sortbuf
[j
]->next
= sortbuf
[j
]->wider
= sortbuf
[j
+ 1];
779 modes
[c
] = sortbuf
[0];
784 /* Output routines. */
786 #define tagged_printf(FMT, ARG, TAG) do { \
788 printf (" " FMT ",%n", ARG, &count_); \
789 printf ("%*s/* %s */\n", 27 - count_, "", TAG); \
792 #define print_decl(TYPE, NAME, ASIZE) \
793 puts ("\nconst " TYPE " " NAME "[" ASIZE "] =\n{");
795 #define print_maybe_const_decl(TYPE, NAME, ASIZE, CATEGORY) \
796 printf ("\n" TYPE " " NAME "[" ASIZE "] = \n{\n", \
797 adj_##CATEGORY ? "" : "const ")
799 #define print_closer() puts ("};")
802 emit_insn_modes_h (void)
805 struct mode_data
*m
, *first
, *last
;
807 printf ("/* Generated automatically from machmode.def%s%s\n",
808 HAVE_EXTRA_MODES
? " and " : "",
814 #ifndef GCC_INSN_MODES_H\n\
815 #define GCC_INSN_MODES_H\n\
817 enum machine_mode\n{");
819 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
820 for (m
= modes
[c
]; m
; m
= m
->next
)
823 printf (" %smode,%n", m
->name
, &count_
);
824 printf ("%*s/* %s:%d */\n", 27 - count_
, "",
825 trim_filename (m
->file
), m
->line
);
828 puts (" MAX_MACHINE_MODE,\n");
830 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
834 for (m
= first
; m
; last
= m
, m
= m
->next
)
837 /* Don't use BImode for MIN_MODE_INT, since otherwise the middle
838 end will try to use it for bitfields in structures and the
839 like, which we do not want. Only the target md file should
840 generate BImode widgets. */
841 if (first
&& first
->precision
== 1)
845 printf (" MIN_%s = %smode,\n MAX_%s = %smode,\n\n",
846 mode_class_names
[c
], first
->name
,
847 mode_class_names
[c
], last
->name
);
849 printf (" MIN_%s = %smode,\n MAX_%s = %smode,\n\n",
850 mode_class_names
[c
], void_mode
->name
,
851 mode_class_names
[c
], void_mode
->name
);
855 NUM_MACHINE_MODES = MAX_MACHINE_MODE\n\
858 /* I can't think of a better idea, can you? */
859 printf ("#define CONST_MODE_SIZE%s\n", adj_bytesize
? "" : " const");
860 printf ("#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment
? "" : " const");
861 #if 0 /* disabled for backward compatibility, temporary */
862 printf ("#define CONST_REAL_FORMAT_FOR_MODE%s\n", adj_format
? "" :" const");
866 #endif /* insn-modes.h */");
870 emit_insn_modes_c_header (void)
872 printf ("/* Generated automatically from machmode.def%s%s\n",
873 HAVE_EXTRA_MODES
? " and " : "",
879 #include \"config.h\"\n\
880 #include \"system.h\"\n\
881 #include \"coretypes.h\"\n\
883 #include \"machmode.h\"\n\
884 #include \"real.h\"");
888 emit_min_insn_modes_c_header (void)
890 printf ("/* Generated automatically from machmode.def%s%s\n",
891 HAVE_EXTRA_MODES
? " and " : "",
897 #include \"bconfig.h\"\n\
898 #include \"system.h\"\n\
899 #include \"machmode.h\"");
903 emit_mode_name (void)
908 print_decl ("char *const", "mode_name", "NUM_MACHINE_MODES");
911 printf (" \"%s\",\n", m
->name
);
917 emit_mode_class (void)
922 print_decl ("unsigned char", "mode_class", "NUM_MACHINE_MODES");
925 tagged_printf ("%s", mode_class_names
[m
->cl
], m
->name
);
931 emit_mode_precision (void)
936 print_decl ("unsigned short", "mode_precision", "NUM_MACHINE_MODES");
939 if (m
->precision
!= (unsigned int)-1)
940 tagged_printf ("%u", m
->precision
, m
->name
);
942 tagged_printf ("%u*BITS_PER_UNIT", m
->bytesize
, m
->name
);
948 emit_mode_size (void)
953 print_maybe_const_decl ("%sunsigned char", "mode_size",
954 "NUM_MACHINE_MODES", bytesize
);
957 tagged_printf ("%u", m
->bytesize
, m
->name
);
963 emit_mode_nunits (void)
968 print_decl ("unsigned char", "mode_nunits", "NUM_MACHINE_MODES");
971 tagged_printf ("%u", m
->ncomponents
, m
->name
);
977 emit_mode_wider (void)
982 print_decl ("unsigned char", "mode_wider", "NUM_MACHINE_MODES");
985 tagged_printf ("%smode",
986 m
->wider
? m
->wider
->name
: void_mode
->name
,
990 print_decl ("unsigned char", "mode_2xwider", "NUM_MACHINE_MODES");
994 struct mode_data
* m2
;
997 m2
&& m2
!= void_mode
;
1000 if (m2
->bytesize
< 2 * m
->bytesize
)
1002 if (m
->precision
!= (unsigned int) -1)
1004 if (m2
->precision
!= 2 * m
->precision
)
1009 if (m2
->precision
!= (unsigned int) -1)
1015 if (m2
== void_mode
)
1017 tagged_printf ("%smode",
1018 m2
? m2
->name
: void_mode
->name
,
1026 emit_mode_mask (void)
1029 struct mode_data
*m
;
1031 print_decl ("unsigned HOST_WIDE_INT", "mode_mask_array",
1032 "NUM_MACHINE_MODES");
1034 #define MODE_MASK(m) \\\n\
1035 ((m) >= HOST_BITS_PER_WIDE_INT) \\\n\
1036 ? ~(unsigned HOST_WIDE_INT) 0 \\\n\
1037 : ((unsigned HOST_WIDE_INT) 1 << (m)) - 1\n");
1039 for_all_modes (c
, m
)
1040 if (m
->precision
!= (unsigned int)-1)
1041 tagged_printf ("MODE_MASK (%u)", m
->precision
, m
->name
);
1043 tagged_printf ("MODE_MASK (%u*BITS_PER_UNIT)", m
->bytesize
, m
->name
);
1045 puts ("#undef MODE_MASK");
1050 emit_mode_inner (void)
1053 struct mode_data
*m
;
1055 print_decl ("unsigned char", "mode_inner", "NUM_MACHINE_MODES");
1057 for_all_modes (c
, m
)
1058 tagged_printf ("%smode",
1059 m
->component
? m
->component
->name
: void_mode
->name
,
1066 emit_mode_base_align (void)
1069 struct mode_data
*m
;
1071 print_maybe_const_decl ("%sunsigned char",
1072 "mode_base_align", "NUM_MACHINE_MODES",
1075 for_all_modes (c
, m
)
1076 tagged_printf ("%u", m
->alignment
, m
->name
);
1082 emit_class_narrowest_mode (void)
1086 print_decl ("unsigned char", "class_narrowest_mode", "MAX_MODE_CLASS");
1088 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1089 /* Bleah, all this to get the comment right for MIN_MODE_INT. */
1090 tagged_printf ("MIN_%s", mode_class_names
[c
],
1092 ? (modes
[c
]->precision
!= 1
1095 ? modes
[c
]->next
->name
1103 emit_real_format_for_mode (void)
1105 struct mode_data
*m
;
1107 /* The entities pointed to by this table are constant, whether
1108 or not the table itself is constant.
1110 For backward compatibility this table is always writable
1111 (several targets modify it in OVERRIDE_OPTIONS). FIXME:
1112 convert all said targets to use ADJUST_FORMAT instead. */
1114 print_maybe_const_decl ("const struct real_format *%s",
1115 "real_format_for_mode",
1116 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1",
1119 print_decl ("struct real_format *\n", "real_format_for_mode",
1120 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1 "
1121 "+ MAX_MODE_DECIMAL_FLOAT - MIN_MODE_DECIMAL_FLOAT + 1");
1124 /* The beginning of the table is entries for float modes. */
1125 for (m
= modes
[MODE_FLOAT
]; m
; m
= m
->next
)
1126 if (!strcmp (m
->format
, "0"))
1127 tagged_printf ("%s", m
->format
, m
->name
);
1129 tagged_printf ("&%s", m
->format
, m
->name
);
1131 /* The end of the table is entries for decimal float modes. */
1132 for (m
= modes
[MODE_DECIMAL_FLOAT
]; m
; m
= m
->next
)
1133 if (!strcmp (m
->format
, "0"))
1134 tagged_printf ("%s", m
->format
, m
->name
);
1136 tagged_printf ("&%s", m
->format
, m
->name
);
1142 emit_mode_adjustments (void)
1144 struct mode_adjust
*a
;
1145 struct mode_data
*m
;
1149 \ninit_adjust_machine_modes (void)\
1151 \n size_t s ATTRIBUTE_UNUSED;");
1153 /* Size adjustments must be propagated to all containing modes.
1154 A size adjustment forces us to recalculate the alignment too. */
1155 for (a
= adj_bytesize
; a
; a
= a
->next
)
1157 printf ("\n /* %s:%d */\n s = %s;\n",
1158 a
->file
, a
->line
, a
->adjustment
);
1159 printf (" mode_size[%smode] = s;\n", a
->mode
->name
);
1160 printf (" mode_base_align[%smode] = s & (~s + 1);\n",
1163 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1167 case MODE_COMPLEX_INT
:
1168 case MODE_COMPLEX_FLOAT
:
1169 printf (" mode_size[%smode] = 2*s;\n", m
->name
);
1170 printf (" mode_base_align[%smode] = s & (~s + 1);\n",
1174 case MODE_VECTOR_INT
:
1175 case MODE_VECTOR_FLOAT
:
1176 printf (" mode_size[%smode] = %d*s;\n",
1177 m
->name
, m
->ncomponents
);
1178 printf (" mode_base_align[%smode] = (%d*s) & (~(%d*s)+1);\n",
1179 m
->name
, m
->ncomponents
, m
->ncomponents
);
1184 "mode %s is neither vector nor complex but contains %s",
1185 m
->name
, a
->mode
->name
);
1191 /* Alignment adjustments propagate too.
1192 ??? This may not be the right thing for vector modes. */
1193 for (a
= adj_alignment
; a
; a
= a
->next
)
1195 printf ("\n /* %s:%d */\n s = %s;\n",
1196 a
->file
, a
->line
, a
->adjustment
);
1197 printf (" mode_base_align[%smode] = s;\n", a
->mode
->name
);
1199 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1203 case MODE_COMPLEX_INT
:
1204 case MODE_COMPLEX_FLOAT
:
1205 printf (" mode_base_align[%smode] = s;\n", m
->name
);
1208 case MODE_VECTOR_INT
:
1209 case MODE_VECTOR_FLOAT
:
1210 printf (" mode_base_align[%smode] = %d*s;\n",
1211 m
->name
, m
->ncomponents
);
1216 "mode %s is neither vector nor complex but contains %s",
1217 m
->name
, a
->mode
->name
);
1223 /* Real mode formats don't have to propagate anywhere. */
1224 for (a
= adj_format
; a
; a
= a
->next
)
1225 printf ("\n /* %s:%d */\n REAL_MODE_FORMAT (%smode) = %s;\n",
1226 a
->file
, a
->line
, a
->mode
->name
, a
->adjustment
);
1232 emit_insn_modes_c (void)
1234 emit_insn_modes_c_header ();
1237 emit_mode_precision ();
1239 emit_mode_nunits ();
1243 emit_mode_base_align ();
1244 emit_class_narrowest_mode ();
1245 emit_real_format_for_mode ();
1246 emit_mode_adjustments ();
1250 emit_min_insn_modes_c (void)
1252 emit_min_insn_modes_c_header ();
1256 emit_class_narrowest_mode ();
1259 /* Master control. */
1261 main(int argc
, char **argv
)
1263 bool gen_header
= false, gen_min
= false;
1268 else if (argc
== 2 && !strcmp (argv
[1], "-h"))
1270 else if (argc
== 2 && !strcmp (argv
[1], "-m"))
1274 error ("usage: %s [-h|-m] > file", progname
);
1275 return FATAL_EXIT_CODE
;
1278 modes_by_name
= htab_create_alloc (64, hash_mode
, eq_mode
, 0, xcalloc
, free
);
1281 complete_all_modes ();
1284 return FATAL_EXIT_CODE
;
1289 emit_insn_modes_h ();
1291 emit_min_insn_modes_c ();
1293 emit_insn_modes_c ();
1295 if (fflush (stdout
) || fclose (stdout
))
1296 return FATAL_EXIT_CODE
;
1297 return SUCCESS_EXIT_CODE
;