1 /* Generate the machine mode enumeration and associated tables.
2 Copyright (C) 2003, 2004, 2007
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 3, 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 COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
26 /* enum mode_class is normally defined by machmode.h but we can't
27 include that header here. */
28 #include "mode-classes.def"
30 #define DEF_MODE_CLASS(M) M
31 enum mode_class
{ MODE_CLASSES
, MAX_MODE_CLASS
};
34 /* Text names of mode classes, for output. */
35 #define DEF_MODE_CLASS(M) #M
36 static const char *const mode_class_names
[MAX_MODE_CLASS
] =
43 #ifdef EXTRA_MODES_FILE
44 # define HAVE_EXTRA_MODES 1
46 # define HAVE_EXTRA_MODES 0
47 # define EXTRA_MODES_FILE ""
50 /* Data structure for building up what we know about a mode.
51 They're clustered by mode class. */
54 struct mode_data
*next
; /* next this class - arbitrary order */
56 const char *name
; /* printable mode name -- SI, not SImode */
57 enum mode_class cl
; /* this mode class */
58 unsigned int precision
; /* size in bits, equiv to TYPE_PRECISION */
59 unsigned int bytesize
; /* storage size in addressable units */
60 unsigned int ncomponents
; /* number of subunits */
61 unsigned int alignment
; /* mode alignment */
62 const char *format
; /* floating point format - float modes only */
64 struct mode_data
*component
; /* mode of components */
65 struct mode_data
*wider
; /* next wider mode */
66 struct mode_data
*wider_2x
; /* 2x wider mode */
68 struct mode_data
*contained
; /* Pointer to list of modes that have
69 this mode as a component. */
70 struct mode_data
*next_cont
; /* Next mode in that list. */
72 const char *file
; /* file and line of definition, */
73 unsigned int line
; /* for error reporting */
74 unsigned int counter
; /* Rank ordering of modes */
77 static struct mode_data
*modes
[MAX_MODE_CLASS
];
78 static unsigned int n_modes
[MAX_MODE_CLASS
];
79 static struct mode_data
*void_mode
;
81 static const struct mode_data blank_mode
= {
82 0, "<unknown>", MAX_MODE_CLASS
,
88 static htab_t modes_by_name
;
90 /* Data structure for recording target-specified runtime adjustments
91 to a particular mode. We support varying the byte size, the
92 alignment, and the floating point format. */
95 struct mode_adjust
*next
;
96 struct mode_data
*mode
;
97 const char *adjustment
;
103 static struct mode_adjust
*adj_bytesize
;
104 static struct mode_adjust
*adj_alignment
;
105 static struct mode_adjust
*adj_format
;
107 /* Mode class operations. */
108 static enum mode_class
109 complex_class (enum mode_class c
)
113 case MODE_INT
: return MODE_COMPLEX_INT
;
114 case MODE_FLOAT
: return MODE_COMPLEX_FLOAT
;
116 error ("no complex class for class %s", mode_class_names
[c
]);
121 static enum mode_class
122 vector_class (enum mode_class cl
)
126 case MODE_INT
: return MODE_VECTOR_INT
;
127 case MODE_FLOAT
: return MODE_VECTOR_FLOAT
;
129 error ("no vector class for class %s", mode_class_names
[cl
]);
134 /* Utility routines. */
135 static inline struct mode_data
*
136 find_mode (const char *name
)
138 struct mode_data key
;
141 return (struct mode_data
*) htab_find (modes_by_name
, &key
);
144 static struct mode_data
*
145 new_mode (enum mode_class cl
, const char *name
,
146 const char *file
, unsigned int line
)
149 static unsigned int count
= 0;
151 m
= find_mode (name
);
154 error ("%s:%d: duplicate definition of mode \"%s\"",
155 trim_filename (file
), line
, name
);
156 error ("%s:%d: previous definition here", m
->file
, m
->line
);
160 m
= XNEW (struct mode_data
);
161 memcpy (m
, &blank_mode
, sizeof (struct mode_data
));
165 m
->file
= trim_filename (file
);
167 m
->counter
= count
++;
173 *htab_find_slot (modes_by_name
, m
, INSERT
) = m
;
179 hash_mode (const void *p
)
181 const struct mode_data
*m
= (const struct mode_data
*)p
;
182 return htab_hash_string (m
->name
);
186 eq_mode (const void *p
, const void *q
)
188 const struct mode_data
*a
= (const struct mode_data
*)p
;
189 const struct mode_data
*b
= (const struct mode_data
*)q
;
191 return !strcmp (a
->name
, b
->name
);
194 #define for_all_modes(C, M) \
195 for (C = 0; C < MAX_MODE_CLASS; C++) \
196 for (M = modes[C]; M; M = M->next)
198 static void ATTRIBUTE_UNUSED
199 new_adjust (const char *name
,
200 struct mode_adjust
**category
, const char *catname
,
201 const char *adjustment
,
202 enum mode_class required_class
,
203 const char *file
, unsigned int line
)
205 struct mode_data
*mode
= find_mode (name
);
206 struct mode_adjust
*a
;
208 file
= trim_filename (file
);
212 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
216 if (required_class
!= MODE_RANDOM
&& mode
->cl
!= required_class
)
218 error ("%s:%d: mode \"%s\" is not class %s",
219 file
, line
, name
, mode_class_names
[required_class
] + 5);
223 for (a
= *category
; a
; a
= a
->next
)
226 error ("%s:%d: mode \"%s\" already has a %s adjustment",
227 file
, line
, name
, catname
);
228 error ("%s:%d: previous adjustment here", a
->file
, a
->line
);
232 a
= XNEW (struct mode_adjust
);
234 a
->adjustment
= adjustment
;
242 /* Diagnose failure to meet expectations in a partially filled out
244 enum requirement
{ SET
, UNSET
, OPTIONAL
};
246 #define validate_field_(mname, fname, req, val, unset, file, line) do { \
251 error ("%s:%d: (%s) field %s must be set", \
252 file, line, mname, fname); \
256 error ("%s:%d: (%s) field %s must not be set", \
257 file, line, mname, fname); \
263 #define validate_field(M, F) \
264 validate_field_(M->name, #F, r_##F, M->F, blank_mode.F, M->file, M->line)
267 validate_mode (struct mode_data
*m
,
268 enum requirement r_precision
,
269 enum requirement r_bytesize
,
270 enum requirement r_component
,
271 enum requirement r_ncomponents
,
272 enum requirement r_format
)
274 validate_field (m
, precision
);
275 validate_field (m
, bytesize
);
276 validate_field (m
, component
);
277 validate_field (m
, ncomponents
);
278 validate_field (m
, format
);
280 #undef validate_field
281 #undef validate_field_
283 /* Given a partially-filled-out mode structure, figure out what we can
284 and fill the rest of it in; die if it isn't enough. */
286 complete_mode (struct mode_data
*m
)
288 unsigned int alignment
;
292 error ("%s:%d: mode with no name", m
->file
, m
->line
);
295 if (m
->cl
== MAX_MODE_CLASS
)
297 error ("%s:%d: %smode has no mode class", m
->file
, m
->line
, m
->name
);
304 /* Nothing more need be said. */
305 if (!strcmp (m
->name
, "VOID"))
308 validate_mode (m
, UNSET
, UNSET
, UNSET
, UNSET
, UNSET
);
317 /* Again, nothing more need be said. For historical reasons,
318 the size of a CC mode is four units. */
319 validate_mode (m
, UNSET
, UNSET
, UNSET
, UNSET
, UNSET
);
328 case MODE_DECIMAL_FLOAT
:
329 /* A scalar mode must have a byte size, may have a bit size,
330 and must not have components. A float mode must have a
332 validate_mode (m
, OPTIONAL
, SET
, UNSET
, UNSET
,
333 m
->cl
!= MODE_INT
? SET
: UNSET
);
339 case MODE_PARTIAL_INT
:
340 /* A partial integer mode uses ->component to say what the
341 corresponding full-size integer mode is, and may also
342 specify a bit size. */
343 validate_mode (m
, OPTIONAL
, UNSET
, SET
, UNSET
, UNSET
);
345 m
->bytesize
= m
->component
->bytesize
;
348 m
->component
= 0; /* ??? preserve this */
351 case MODE_COMPLEX_INT
:
352 case MODE_COMPLEX_FLOAT
:
353 /* Complex modes should have a component indicated, but no more. */
354 validate_mode (m
, UNSET
, UNSET
, SET
, UNSET
, UNSET
);
356 if (m
->component
->precision
!= (unsigned int)-1)
357 m
->precision
= 2 * m
->component
->precision
;
358 m
->bytesize
= 2 * m
->component
->bytesize
;
361 case MODE_VECTOR_INT
:
362 case MODE_VECTOR_FLOAT
:
363 /* Vector modes should have a component and a number of components. */
364 validate_mode (m
, UNSET
, UNSET
, SET
, SET
, UNSET
);
365 if (m
->component
->precision
!= (unsigned int)-1)
366 m
->precision
= m
->ncomponents
* m
->component
->precision
;
367 m
->bytesize
= m
->ncomponents
* m
->component
->bytesize
;
374 /* If not already specified, the mode alignment defaults to the largest
375 power of two that divides the size of the object. Complex types are
376 not more aligned than their contents. */
377 if (m
->cl
== MODE_COMPLEX_INT
|| m
->cl
== MODE_COMPLEX_FLOAT
)
378 alignment
= m
->component
->bytesize
;
380 alignment
= m
->bytesize
;
382 m
->alignment
= alignment
& (~alignment
+ 1);
384 /* If this mode has components, make the component mode point back
385 to this mode, for the sake of adjustments. */
388 m
->next_cont
= m
->component
->contained
;
389 m
->component
->contained
= m
;
394 complete_all_modes (void)
399 for_all_modes (cl
, m
)
403 /* For each mode in class CLASS, construct a corresponding complex mode. */
404 #define COMPLEX_MODES(C) make_complex_modes(MODE_##C, __FILE__, __LINE__)
406 make_complex_modes (enum mode_class cl
,
407 const char *file
, unsigned int line
)
412 enum mode_class cclass
= complex_class (cl
);
414 if (cclass
== MODE_RANDOM
)
417 for (m
= modes
[cl
]; m
; m
= m
->next
)
419 /* Skip BImode. FIXME: BImode probably shouldn't be MODE_INT. */
420 if (m
->precision
== 1)
423 if (strlen (m
->name
) >= sizeof buf
)
425 error ("%s:%d:mode name \"%s\" is too long",
426 m
->file
, m
->line
, m
->name
);
430 /* Float complex modes are named SCmode, etc.
431 Int complex modes are named CSImode, etc.
432 This inconsistency should be eliminated. */
433 if (cl
== MODE_FLOAT
)
436 strncpy (buf
, m
->name
, sizeof buf
);
437 p
= strchr (buf
, 'F');
439 q
= strchr (buf
, 'D');
440 if (p
== 0 && q
== 0)
442 error ("%s:%d: float mode \"%s\" has no 'F' or 'D'",
443 m
->file
, m
->line
, m
->name
);
450 snprintf (buf
, sizeof buf
, "C%s", m
->name
);
453 snprintf (buf
, sizeof buf
, "C%s", m
->name
);
455 c
= new_mode (cclass
, xstrdup (buf
), file
, line
);
460 /* For all modes in class CL, construct vector modes of width
461 WIDTH, having as many components as necessary. */
462 #define VECTOR_MODES(C, W) make_vector_modes(MODE_##C, W, __FILE__, __LINE__)
463 static void ATTRIBUTE_UNUSED
464 make_vector_modes (enum mode_class cl
, unsigned int width
,
465 const char *file
, unsigned int line
)
470 unsigned int ncomponents
;
471 enum mode_class vclass
= vector_class (cl
);
473 if (vclass
== MODE_RANDOM
)
476 for (m
= modes
[cl
]; m
; m
= m
->next
)
478 /* Do not construct vector modes with only one element, or
479 vector modes where the element size doesn't divide the full
481 ncomponents
= width
/ m
->bytesize
;
484 if (width
% m
->bytesize
)
487 /* Skip QFmode and BImode. FIXME: this special case should
489 if (cl
== MODE_FLOAT
&& m
->bytesize
== 1)
491 if (cl
== MODE_INT
&& m
->precision
== 1)
494 if ((size_t)snprintf (buf
, sizeof buf
, "V%u%s", ncomponents
, m
->name
)
497 error ("%s:%d: mode name \"%s\" is too long",
498 m
->file
, m
->line
, m
->name
);
502 v
= new_mode (vclass
, xstrdup (buf
), file
, line
);
504 v
->ncomponents
= ncomponents
;
510 #define _SPECIAL_MODE(C, N) make_special_mode(MODE_##C, #N, __FILE__, __LINE__)
511 #define RANDOM_MODE(N) _SPECIAL_MODE (RANDOM, N)
512 #define CC_MODE(N) _SPECIAL_MODE (CC, N)
515 make_special_mode (enum mode_class cl
, const char *name
,
516 const char *file
, unsigned int line
)
518 new_mode (cl
, name
, file
, line
);
521 #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y)
522 #define FRACTIONAL_INT_MODE(N, B, Y) \
523 make_int_mode (#N, B, Y, __FILE__, __LINE__)
526 make_int_mode (const char *name
,
527 unsigned int precision
, unsigned int bytesize
,
528 const char *file
, unsigned int line
)
530 struct mode_data
*m
= new_mode (MODE_INT
, name
, file
, line
);
531 m
->bytesize
= bytesize
;
532 m
->precision
= precision
;
535 #define FLOAT_MODE(N, Y, F) FRACTIONAL_FLOAT_MODE (N, -1U, Y, F)
536 #define FRACTIONAL_FLOAT_MODE(N, B, Y, F) \
537 make_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
540 make_float_mode (const char *name
,
541 unsigned int precision
, unsigned int bytesize
,
543 const char *file
, unsigned int line
)
545 struct mode_data
*m
= new_mode (MODE_FLOAT
, name
, file
, line
);
546 m
->bytesize
= bytesize
;
547 m
->precision
= precision
;
551 #define DECIMAL_FLOAT_MODE(N, Y, F) \
552 FRACTIONAL_DECIMAL_FLOAT_MODE (N, -1U, Y, F)
553 #define FRACTIONAL_DECIMAL_FLOAT_MODE(N, B, Y, F) \
554 make_decimal_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
557 make_decimal_float_mode (const char *name
,
558 unsigned int precision
, unsigned int bytesize
,
560 const char *file
, unsigned int line
)
562 struct mode_data
*m
= new_mode (MODE_DECIMAL_FLOAT
, name
, file
, line
);
563 m
->bytesize
= bytesize
;
564 m
->precision
= precision
;
568 #define RESET_FLOAT_FORMAT(N, F) \
569 reset_float_format (#N, #F, __FILE__, __LINE__)
570 static void ATTRIBUTE_UNUSED
571 reset_float_format (const char *name
, const char *format
,
572 const char *file
, unsigned int line
)
574 struct mode_data
*m
= find_mode (name
);
577 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
580 if (m
->cl
!= MODE_FLOAT
&& m
->cl
!= MODE_DECIMAL_FLOAT
)
582 error ("%s:%d: mode \"%s\" is not a FLOAT class", file
, line
, name
);
588 /* Partial integer modes are specified by relation to a full integer mode.
589 For now, we do not attempt to narrow down their bit sizes. */
590 #define PARTIAL_INT_MODE(M) \
591 make_partial_integer_mode (#M, "P" #M, -1U, __FILE__, __LINE__)
592 static void ATTRIBUTE_UNUSED
593 make_partial_integer_mode (const char *base
, const char *name
,
594 unsigned int precision
,
595 const char *file
, unsigned int line
)
598 struct mode_data
*component
= find_mode (base
);
601 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
604 if (component
->cl
!= MODE_INT
)
606 error ("%s:%d: mode \"%s\" is not class INT", file
, line
, name
);
610 m
= new_mode (MODE_PARTIAL_INT
, name
, file
, line
);
611 m
->precision
= precision
;
612 m
->component
= component
;
615 /* A single vector mode can be specified by naming its component
616 mode and the number of components. */
617 #define VECTOR_MODE(C, M, N) \
618 make_vector_mode (MODE_##C, #M, N, __FILE__, __LINE__);
619 static void ATTRIBUTE_UNUSED
620 make_vector_mode (enum mode_class bclass
,
622 unsigned int ncomponents
,
623 const char *file
, unsigned int line
)
626 enum mode_class vclass
= vector_class (bclass
);
627 struct mode_data
*component
= find_mode (base
);
630 if (vclass
== MODE_RANDOM
)
634 error ("%s:%d: no mode \"%s\"", file
, line
, base
);
637 if (component
->cl
!= bclass
638 && (component
->cl
!= MODE_PARTIAL_INT
639 || bclass
!= MODE_INT
))
641 error ("%s:%d: mode \"%s\" is not class %s",
642 file
, line
, base
, mode_class_names
[bclass
] + 5);
646 if ((size_t)snprintf (namebuf
, sizeof namebuf
, "V%u%s",
647 ncomponents
, base
) >= sizeof namebuf
)
649 error ("%s:%d: mode name \"%s\" is too long",
654 v
= new_mode (vclass
, xstrdup (namebuf
), file
, line
);
655 v
->ncomponents
= ncomponents
;
656 v
->component
= component
;
660 #define _ADD_ADJUST(A, M, X, C) \
661 new_adjust (#M, &adj_##A, #A, #X, MODE_##C, __FILE__, __LINE__)
663 #define ADJUST_BYTESIZE(M, X) _ADD_ADJUST(bytesize, M, X, RANDOM)
664 #define ADJUST_ALIGNMENT(M, X) _ADD_ADJUST(alignment, M, X, RANDOM)
665 #define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST(format, M, X, FLOAT)
670 #include "machmode.def"
675 /* Sort a list of modes into the order needed for the WIDER field:
676 major sort by precision, minor sort by component precision.
679 QI < HI < SI < DI < TI
680 V4QI < V2HI < V8QI < V4HI < V2SI.
682 If the precision is not set, sort by the bytesize. A mode with
683 precision set gets sorted before a mode without precision set, if
684 they have the same bytesize; this is the right thing because
685 the precision must always be smaller than the bytesize * BITS_PER_UNIT.
686 We don't have to do anything special to get this done -- an unset
687 precision shows up as (unsigned int)-1, i.e. UINT_MAX. */
689 cmp_modes (const void *a
, const void *b
)
691 struct mode_data
*m
= *(struct mode_data
**)a
;
692 struct mode_data
*n
= *(struct mode_data
**)b
;
694 if (m
->bytesize
> n
->bytesize
)
696 else if (m
->bytesize
< n
->bytesize
)
699 if (m
->precision
> n
->precision
)
701 else if (m
->precision
< n
->precision
)
704 if (!m
->component
&& !n
->component
)
706 if (m
->counter
< n
->counter
)
712 if (m
->component
->bytesize
> n
->component
->bytesize
)
714 else if (m
->component
->bytesize
< n
->component
->bytesize
)
717 if (m
->component
->precision
> n
->component
->precision
)
719 else if (m
->component
->precision
< n
->component
->precision
)
722 if (m
->counter
< n
->counter
)
729 calc_wider_mode (void)
733 struct mode_data
**sortbuf
;
734 unsigned int max_n_modes
= 0;
737 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
738 max_n_modes
= MAX (max_n_modes
, n_modes
[c
]);
740 /* Allocate max_n_modes + 1 entries to leave room for the extra null
741 pointer assigned after the qsort call below. */
742 sortbuf
= (struct mode_data
**) alloca ((max_n_modes
+ 1) * sizeof (struct mode_data
*));
744 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
746 /* "wider" is not meaningful for MODE_RANDOM and MODE_CC.
747 However, we want these in textual order, and we have
748 precisely the reverse. */
749 if (c
== MODE_RANDOM
|| c
== MODE_CC
)
751 struct mode_data
*prev
, *next
;
753 for (prev
= 0, m
= modes
[c
]; m
; m
= next
)
755 m
->wider
= void_mode
;
756 m
->wider_2x
= void_mode
;
758 /* this is nreverse */
770 for (i
= 0, m
= modes
[c
]; m
; i
++, m
= m
->next
)
773 qsort (sortbuf
, i
, sizeof (struct mode_data
*), cmp_modes
);
776 for (j
= 0; j
< i
; j
++)
777 sortbuf
[j
]->next
= sortbuf
[j
]->wider
= sortbuf
[j
+ 1];
780 modes
[c
] = sortbuf
[0];
785 /* Output routines. */
787 #define tagged_printf(FMT, ARG, TAG) do { \
789 printf (" " FMT ",%n", ARG, &count_); \
790 printf ("%*s/* %s */\n", 27 - count_, "", TAG); \
793 #define print_decl(TYPE, NAME, ASIZE) \
794 puts ("\nconst " TYPE " " NAME "[" ASIZE "] =\n{");
796 #define print_maybe_const_decl(TYPE, NAME, ASIZE, CATEGORY) \
797 printf ("\n" TYPE " " NAME "[" ASIZE "] = \n{\n", \
798 adj_##CATEGORY ? "" : "const ")
800 #define print_closer() puts ("};")
803 emit_insn_modes_h (void)
806 struct mode_data
*m
, *first
, *last
;
808 printf ("/* Generated automatically from machmode.def%s%s\n",
809 HAVE_EXTRA_MODES
? " and " : "",
815 #ifndef GCC_INSN_MODES_H\n\
816 #define GCC_INSN_MODES_H\n\
818 enum machine_mode\n{");
820 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
821 for (m
= modes
[c
]; m
; m
= m
->next
)
824 printf (" %smode,%n", m
->name
, &count_
);
825 printf ("%*s/* %s:%d */\n", 27 - count_
, "",
826 trim_filename (m
->file
), m
->line
);
829 puts (" MAX_MACHINE_MODE,\n");
831 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
835 for (m
= first
; m
; last
= m
, m
= m
->next
)
838 /* Don't use BImode for MIN_MODE_INT, since otherwise the middle
839 end will try to use it for bitfields in structures and the
840 like, which we do not want. Only the target md file should
841 generate BImode widgets. */
842 if (first
&& first
->precision
== 1)
846 printf (" MIN_%s = %smode,\n MAX_%s = %smode,\n\n",
847 mode_class_names
[c
], first
->name
,
848 mode_class_names
[c
], last
->name
);
850 printf (" MIN_%s = %smode,\n MAX_%s = %smode,\n\n",
851 mode_class_names
[c
], void_mode
->name
,
852 mode_class_names
[c
], void_mode
->name
);
856 NUM_MACHINE_MODES = MAX_MACHINE_MODE\n\
859 /* I can't think of a better idea, can you? */
860 printf ("#define CONST_MODE_SIZE%s\n", adj_bytesize
? "" : " const");
861 printf ("#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment
? "" : " const");
862 #if 0 /* disabled for backward compatibility, temporary */
863 printf ("#define CONST_REAL_FORMAT_FOR_MODE%s\n", adj_format
? "" :" const");
867 #endif /* insn-modes.h */");
871 emit_insn_modes_c_header (void)
873 printf ("/* Generated automatically from machmode.def%s%s\n",
874 HAVE_EXTRA_MODES
? " and " : "",
880 #include \"config.h\"\n\
881 #include \"system.h\"\n\
882 #include \"coretypes.h\"\n\
884 #include \"machmode.h\"\n\
885 #include \"real.h\"");
889 emit_min_insn_modes_c_header (void)
891 printf ("/* Generated automatically from machmode.def%s%s\n",
892 HAVE_EXTRA_MODES
? " and " : "",
898 #include \"bconfig.h\"\n\
899 #include \"system.h\"\n\
900 #include \"machmode.h\"");
904 emit_mode_name (void)
909 print_decl ("char *const", "mode_name", "NUM_MACHINE_MODES");
912 printf (" \"%s\",\n", m
->name
);
918 emit_mode_class (void)
923 print_decl ("unsigned char", "mode_class", "NUM_MACHINE_MODES");
926 tagged_printf ("%s", mode_class_names
[m
->cl
], m
->name
);
932 emit_mode_precision (void)
937 print_decl ("unsigned short", "mode_precision", "NUM_MACHINE_MODES");
940 if (m
->precision
!= (unsigned int)-1)
941 tagged_printf ("%u", m
->precision
, m
->name
);
943 tagged_printf ("%u*BITS_PER_UNIT", m
->bytesize
, m
->name
);
949 emit_mode_size (void)
954 print_maybe_const_decl ("%sunsigned char", "mode_size",
955 "NUM_MACHINE_MODES", bytesize
);
958 tagged_printf ("%u", m
->bytesize
, m
->name
);
964 emit_mode_nunits (void)
969 print_decl ("unsigned char", "mode_nunits", "NUM_MACHINE_MODES");
972 tagged_printf ("%u", m
->ncomponents
, m
->name
);
978 emit_mode_wider (void)
983 print_decl ("unsigned char", "mode_wider", "NUM_MACHINE_MODES");
986 tagged_printf ("%smode",
987 m
->wider
? m
->wider
->name
: void_mode
->name
,
991 print_decl ("unsigned char", "mode_2xwider", "NUM_MACHINE_MODES");
995 struct mode_data
* m2
;
998 m2
&& m2
!= void_mode
;
1001 if (m2
->bytesize
< 2 * m
->bytesize
)
1003 if (m
->precision
!= (unsigned int) -1)
1005 if (m2
->precision
!= 2 * m
->precision
)
1010 if (m2
->precision
!= (unsigned int) -1)
1016 if (m2
== void_mode
)
1018 tagged_printf ("%smode",
1019 m2
? m2
->name
: void_mode
->name
,
1027 emit_mode_mask (void)
1030 struct mode_data
*m
;
1032 print_decl ("unsigned HOST_WIDE_INT", "mode_mask_array",
1033 "NUM_MACHINE_MODES");
1035 #define MODE_MASK(m) \\\n\
1036 ((m) >= HOST_BITS_PER_WIDE_INT) \\\n\
1037 ? ~(unsigned HOST_WIDE_INT) 0 \\\n\
1038 : ((unsigned HOST_WIDE_INT) 1 << (m)) - 1\n");
1040 for_all_modes (c
, m
)
1041 if (m
->precision
!= (unsigned int)-1)
1042 tagged_printf ("MODE_MASK (%u)", m
->precision
, m
->name
);
1044 tagged_printf ("MODE_MASK (%u*BITS_PER_UNIT)", m
->bytesize
, m
->name
);
1046 puts ("#undef MODE_MASK");
1051 emit_mode_inner (void)
1054 struct mode_data
*m
;
1056 print_decl ("unsigned char", "mode_inner", "NUM_MACHINE_MODES");
1058 for_all_modes (c
, m
)
1059 tagged_printf ("%smode",
1060 m
->component
? m
->component
->name
: void_mode
->name
,
1067 emit_mode_base_align (void)
1070 struct mode_data
*m
;
1072 print_maybe_const_decl ("%sunsigned char",
1073 "mode_base_align", "NUM_MACHINE_MODES",
1076 for_all_modes (c
, m
)
1077 tagged_printf ("%u", m
->alignment
, m
->name
);
1083 emit_class_narrowest_mode (void)
1087 print_decl ("unsigned char", "class_narrowest_mode", "MAX_MODE_CLASS");
1089 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1090 /* Bleah, all this to get the comment right for MIN_MODE_INT. */
1091 tagged_printf ("MIN_%s", mode_class_names
[c
],
1093 ? (modes
[c
]->precision
!= 1
1096 ? modes
[c
]->next
->name
1104 emit_real_format_for_mode (void)
1106 struct mode_data
*m
;
1108 /* The entities pointed to by this table are constant, whether
1109 or not the table itself is constant.
1111 For backward compatibility this table is always writable
1112 (several targets modify it in OVERRIDE_OPTIONS). FIXME:
1113 convert all said targets to use ADJUST_FORMAT instead. */
1115 print_maybe_const_decl ("const struct real_format *%s",
1116 "real_format_for_mode",
1117 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1",
1120 print_decl ("struct real_format *\n", "real_format_for_mode",
1121 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1 "
1122 "+ MAX_MODE_DECIMAL_FLOAT - MIN_MODE_DECIMAL_FLOAT + 1");
1125 /* The beginning of the table is entries for float modes. */
1126 for (m
= modes
[MODE_FLOAT
]; m
; m
= m
->next
)
1127 if (!strcmp (m
->format
, "0"))
1128 tagged_printf ("%s", m
->format
, m
->name
);
1130 tagged_printf ("&%s", m
->format
, m
->name
);
1132 /* The end of the table is entries for decimal float modes. */
1133 for (m
= modes
[MODE_DECIMAL_FLOAT
]; m
; m
= m
->next
)
1134 if (!strcmp (m
->format
, "0"))
1135 tagged_printf ("%s", m
->format
, m
->name
);
1137 tagged_printf ("&%s", m
->format
, m
->name
);
1143 emit_mode_adjustments (void)
1145 struct mode_adjust
*a
;
1146 struct mode_data
*m
;
1150 \ninit_adjust_machine_modes (void)\
1152 \n size_t s ATTRIBUTE_UNUSED;");
1154 /* Size adjustments must be propagated to all containing modes.
1155 A size adjustment forces us to recalculate the alignment too. */
1156 for (a
= adj_bytesize
; a
; a
= a
->next
)
1158 printf ("\n /* %s:%d */\n s = %s;\n",
1159 a
->file
, a
->line
, a
->adjustment
);
1160 printf (" mode_size[%smode] = s;\n", a
->mode
->name
);
1161 printf (" mode_base_align[%smode] = s & (~s + 1);\n",
1164 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1168 case MODE_COMPLEX_INT
:
1169 case MODE_COMPLEX_FLOAT
:
1170 printf (" mode_size[%smode] = 2*s;\n", m
->name
);
1171 printf (" mode_base_align[%smode] = s & (~s + 1);\n",
1175 case MODE_VECTOR_INT
:
1176 case MODE_VECTOR_FLOAT
:
1177 printf (" mode_size[%smode] = %d*s;\n",
1178 m
->name
, m
->ncomponents
);
1179 printf (" mode_base_align[%smode] = (%d*s) & (~(%d*s)+1);\n",
1180 m
->name
, m
->ncomponents
, m
->ncomponents
);
1185 "mode %s is neither vector nor complex but contains %s",
1186 m
->name
, a
->mode
->name
);
1192 /* Alignment adjustments propagate too.
1193 ??? This may not be the right thing for vector modes. */
1194 for (a
= adj_alignment
; a
; a
= a
->next
)
1196 printf ("\n /* %s:%d */\n s = %s;\n",
1197 a
->file
, a
->line
, a
->adjustment
);
1198 printf (" mode_base_align[%smode] = s;\n", a
->mode
->name
);
1200 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1204 case MODE_COMPLEX_INT
:
1205 case MODE_COMPLEX_FLOAT
:
1206 printf (" mode_base_align[%smode] = s;\n", m
->name
);
1209 case MODE_VECTOR_INT
:
1210 case MODE_VECTOR_FLOAT
:
1211 printf (" mode_base_align[%smode] = %d*s;\n",
1212 m
->name
, m
->ncomponents
);
1217 "mode %s is neither vector nor complex but contains %s",
1218 m
->name
, a
->mode
->name
);
1224 /* Real mode formats don't have to propagate anywhere. */
1225 for (a
= adj_format
; a
; a
= a
->next
)
1226 printf ("\n /* %s:%d */\n REAL_MODE_FORMAT (%smode) = %s;\n",
1227 a
->file
, a
->line
, a
->mode
->name
, a
->adjustment
);
1233 emit_insn_modes_c (void)
1235 emit_insn_modes_c_header ();
1238 emit_mode_precision ();
1240 emit_mode_nunits ();
1244 emit_mode_base_align ();
1245 emit_class_narrowest_mode ();
1246 emit_real_format_for_mode ();
1247 emit_mode_adjustments ();
1251 emit_min_insn_modes_c (void)
1253 emit_min_insn_modes_c_header ();
1257 emit_class_narrowest_mode ();
1260 /* Master control. */
1262 main(int argc
, char **argv
)
1264 bool gen_header
= false, gen_min
= false;
1269 else if (argc
== 2 && !strcmp (argv
[1], "-h"))
1271 else if (argc
== 2 && !strcmp (argv
[1], "-m"))
1275 error ("usage: %s [-h|-m] > file", progname
);
1276 return FATAL_EXIT_CODE
;
1279 modes_by_name
= htab_create_alloc (64, hash_mode
, eq_mode
, 0, xcalloc
, free
);
1282 complete_all_modes ();
1285 return FATAL_EXIT_CODE
;
1290 emit_insn_modes_h ();
1292 emit_min_insn_modes_c ();
1294 emit_insn_modes_c ();
1296 if (fflush (stdout
) || fclose (stdout
))
1297 return FATAL_EXIT_CODE
;
1298 return SUCCESS_EXIT_CODE
;