1 /* Generate the machine mode enumeration and associated tables.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010
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 */
75 unsigned int ibit
; /* the number of integral bits */
76 unsigned int fbit
; /* the number of fractional bits */
79 static struct mode_data
*modes
[MAX_MODE_CLASS
];
80 static unsigned int n_modes
[MAX_MODE_CLASS
];
81 static struct mode_data
*void_mode
;
83 static const struct mode_data blank_mode
= {
84 0, "<unknown>", MAX_MODE_CLASS
,
87 "<unknown>", 0, 0, 0, 0
90 static htab_t modes_by_name
;
92 /* Data structure for recording target-specified runtime adjustments
93 to a particular mode. We support varying the byte size, the
94 alignment, and the floating point format. */
97 struct mode_adjust
*next
;
98 struct mode_data
*mode
;
99 const char *adjustment
;
105 static struct mode_adjust
*adj_bytesize
;
106 static struct mode_adjust
*adj_alignment
;
107 static struct mode_adjust
*adj_format
;
108 static struct mode_adjust
*adj_ibit
;
109 static struct mode_adjust
*adj_fbit
;
111 /* Mode class operations. */
112 static enum mode_class
113 complex_class (enum mode_class c
)
117 case MODE_INT
: return MODE_COMPLEX_INT
;
118 case MODE_FLOAT
: return MODE_COMPLEX_FLOAT
;
120 error ("no complex class for class %s", mode_class_names
[c
]);
125 static enum mode_class
126 vector_class (enum mode_class cl
)
130 case MODE_INT
: return MODE_VECTOR_INT
;
131 case MODE_FLOAT
: return MODE_VECTOR_FLOAT
;
132 case MODE_FRACT
: return MODE_VECTOR_FRACT
;
133 case MODE_UFRACT
: return MODE_VECTOR_UFRACT
;
134 case MODE_ACCUM
: return MODE_VECTOR_ACCUM
;
135 case MODE_UACCUM
: return MODE_VECTOR_UACCUM
;
137 error ("no vector class for class %s", mode_class_names
[cl
]);
142 /* Utility routines. */
143 static inline struct mode_data
*
144 find_mode (const char *name
)
146 struct mode_data key
;
149 return (struct mode_data
*) htab_find (modes_by_name
, &key
);
152 static struct mode_data
*
153 new_mode (enum mode_class cl
, const char *name
,
154 const char *file
, unsigned int line
)
157 static unsigned int count
= 0;
159 m
= find_mode (name
);
162 error ("%s:%d: duplicate definition of mode \"%s\"",
163 trim_filename (file
), line
, name
);
164 error ("%s:%d: previous definition here", m
->file
, m
->line
);
168 m
= XNEW (struct mode_data
);
169 memcpy (m
, &blank_mode
, sizeof (struct mode_data
));
173 m
->file
= trim_filename (file
);
175 m
->counter
= count
++;
181 *htab_find_slot (modes_by_name
, m
, INSERT
) = m
;
187 hash_mode (const void *p
)
189 const struct mode_data
*m
= (const struct mode_data
*)p
;
190 return htab_hash_string (m
->name
);
194 eq_mode (const void *p
, const void *q
)
196 const struct mode_data
*a
= (const struct mode_data
*)p
;
197 const struct mode_data
*b
= (const struct mode_data
*)q
;
199 return !strcmp (a
->name
, b
->name
);
202 #define for_all_modes(C, M) \
203 for (C = 0; C < MAX_MODE_CLASS; C++) \
204 for (M = modes[C]; M; M = M->next)
206 static void ATTRIBUTE_UNUSED
207 new_adjust (const char *name
,
208 struct mode_adjust
**category
, const char *catname
,
209 const char *adjustment
,
210 enum mode_class required_class_from
,
211 enum mode_class required_class_to
,
212 const char *file
, unsigned int line
)
214 struct mode_data
*mode
= find_mode (name
);
215 struct mode_adjust
*a
;
217 file
= trim_filename (file
);
221 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
225 if (required_class_from
!= MODE_RANDOM
226 && (mode
->cl
< required_class_from
|| mode
->cl
> required_class_to
))
228 error ("%s:%d: mode \"%s\" is not among class {%s, %s}",
229 file
, line
, name
, mode_class_names
[required_class_from
] + 5,
230 mode_class_names
[required_class_to
] + 5);
234 for (a
= *category
; a
; a
= a
->next
)
237 error ("%s:%d: mode \"%s\" already has a %s adjustment",
238 file
, line
, name
, catname
);
239 error ("%s:%d: previous adjustment here", a
->file
, a
->line
);
243 a
= XNEW (struct mode_adjust
);
245 a
->adjustment
= adjustment
;
253 /* Diagnose failure to meet expectations in a partially filled out
255 enum requirement
{ SET
, UNSET
, OPTIONAL
};
257 #define validate_field_(mname, fname, req, val, unset, file, line) do { \
262 error ("%s:%d: (%s) field %s must be set", \
263 file, line, mname, fname); \
267 error ("%s:%d: (%s) field %s must not be set", \
268 file, line, mname, fname); \
274 #define validate_field(M, F) \
275 validate_field_(M->name, #F, r_##F, M->F, blank_mode.F, M->file, M->line)
278 validate_mode (struct mode_data
*m
,
279 enum requirement r_precision
,
280 enum requirement r_bytesize
,
281 enum requirement r_component
,
282 enum requirement r_ncomponents
,
283 enum requirement r_format
)
285 validate_field (m
, precision
);
286 validate_field (m
, bytesize
);
287 validate_field (m
, component
);
288 validate_field (m
, ncomponents
);
289 validate_field (m
, format
);
291 #undef validate_field
292 #undef validate_field_
294 /* Given a partially-filled-out mode structure, figure out what we can
295 and fill the rest of it in; die if it isn't enough. */
297 complete_mode (struct mode_data
*m
)
299 unsigned int alignment
;
303 error ("%s:%d: mode with no name", m
->file
, m
->line
);
306 if (m
->cl
== MAX_MODE_CLASS
)
308 error ("%s:%d: %smode has no mode class", m
->file
, m
->line
, m
->name
);
315 /* Nothing more need be said. */
316 if (!strcmp (m
->name
, "VOID"))
319 validate_mode (m
, UNSET
, UNSET
, UNSET
, UNSET
, UNSET
);
328 /* Again, nothing more need be said. For historical reasons,
329 the size of a CC mode is four units. */
330 validate_mode (m
, UNSET
, UNSET
, UNSET
, UNSET
, UNSET
);
339 case MODE_DECIMAL_FLOAT
:
344 /* A scalar mode must have a byte size, may have a bit size,
345 and must not have components. A float mode must have a
347 validate_mode (m
, OPTIONAL
, SET
, UNSET
, UNSET
,
348 (m
->cl
== MODE_FLOAT
|| m
->cl
== MODE_DECIMAL_FLOAT
)
355 case MODE_PARTIAL_INT
:
356 /* A partial integer mode uses ->component to say what the
357 corresponding full-size integer mode is, and may also
358 specify a bit size. */
359 validate_mode (m
, OPTIONAL
, UNSET
, SET
, UNSET
, UNSET
);
361 m
->bytesize
= m
->component
->bytesize
;
364 m
->component
= 0; /* ??? preserve this */
367 case MODE_COMPLEX_INT
:
368 case MODE_COMPLEX_FLOAT
:
369 /* Complex modes should have a component indicated, but no more. */
370 validate_mode (m
, UNSET
, UNSET
, SET
, UNSET
, UNSET
);
372 if (m
->component
->precision
!= (unsigned int)-1)
373 m
->precision
= 2 * m
->component
->precision
;
374 m
->bytesize
= 2 * m
->component
->bytesize
;
377 case MODE_VECTOR_INT
:
378 case MODE_VECTOR_FLOAT
:
379 case MODE_VECTOR_FRACT
:
380 case MODE_VECTOR_UFRACT
:
381 case MODE_VECTOR_ACCUM
:
382 case MODE_VECTOR_UACCUM
:
383 /* Vector modes should have a component and a number of components. */
384 validate_mode (m
, UNSET
, UNSET
, SET
, SET
, UNSET
);
385 if (m
->component
->precision
!= (unsigned int)-1)
386 m
->precision
= m
->ncomponents
* m
->component
->precision
;
387 m
->bytesize
= m
->ncomponents
* m
->component
->bytesize
;
394 /* If not already specified, the mode alignment defaults to the largest
395 power of two that divides the size of the object. Complex types are
396 not more aligned than their contents. */
397 if (m
->cl
== MODE_COMPLEX_INT
|| m
->cl
== MODE_COMPLEX_FLOAT
)
398 alignment
= m
->component
->bytesize
;
400 alignment
= m
->bytesize
;
402 m
->alignment
= alignment
& (~alignment
+ 1);
404 /* If this mode has components, make the component mode point back
405 to this mode, for the sake of adjustments. */
408 m
->next_cont
= m
->component
->contained
;
409 m
->component
->contained
= m
;
414 complete_all_modes (void)
419 for_all_modes (cl
, m
)
423 /* For each mode in class CLASS, construct a corresponding complex mode. */
424 #define COMPLEX_MODES(C) make_complex_modes(MODE_##C, __FILE__, __LINE__)
426 make_complex_modes (enum mode_class cl
,
427 const char *file
, unsigned int line
)
432 enum mode_class cclass
= complex_class (cl
);
434 if (cclass
== MODE_RANDOM
)
437 for (m
= modes
[cl
]; m
; m
= m
->next
)
439 /* Skip BImode. FIXME: BImode probably shouldn't be MODE_INT. */
440 if (m
->precision
== 1)
443 if (strlen (m
->name
) >= sizeof buf
)
445 error ("%s:%d:mode name \"%s\" is too long",
446 m
->file
, m
->line
, m
->name
);
450 /* Float complex modes are named SCmode, etc.
451 Int complex modes are named CSImode, etc.
452 This inconsistency should be eliminated. */
453 if (cl
== MODE_FLOAT
)
456 strncpy (buf
, m
->name
, sizeof buf
);
457 p
= strchr (buf
, 'F');
459 q
= strchr (buf
, 'D');
460 if (p
== 0 && q
== 0)
462 error ("%s:%d: float mode \"%s\" has no 'F' or 'D'",
463 m
->file
, m
->line
, m
->name
);
470 snprintf (buf
, sizeof buf
, "C%s", m
->name
);
473 snprintf (buf
, sizeof buf
, "C%s", m
->name
);
475 c
= new_mode (cclass
, xstrdup (buf
), file
, line
);
480 /* For all modes in class CL, construct vector modes of width
481 WIDTH, having as many components as necessary. */
482 #define VECTOR_MODES(C, W) make_vector_modes(MODE_##C, W, __FILE__, __LINE__)
483 static void ATTRIBUTE_UNUSED
484 make_vector_modes (enum mode_class cl
, unsigned int width
,
485 const char *file
, unsigned int line
)
490 unsigned int ncomponents
;
491 enum mode_class vclass
= vector_class (cl
);
493 if (vclass
== MODE_RANDOM
)
496 for (m
= modes
[cl
]; m
; m
= m
->next
)
498 /* Do not construct vector modes with only one element, or
499 vector modes where the element size doesn't divide the full
501 ncomponents
= width
/ m
->bytesize
;
504 if (width
% m
->bytesize
)
507 /* Skip QFmode and BImode. FIXME: this special case should
509 if (cl
== MODE_FLOAT
&& m
->bytesize
== 1)
511 if (cl
== MODE_INT
&& m
->precision
== 1)
514 if ((size_t)snprintf (buf
, sizeof buf
, "V%u%s", ncomponents
, m
->name
)
517 error ("%s:%d: mode name \"%s\" is too long",
518 m
->file
, m
->line
, m
->name
);
522 v
= new_mode (vclass
, xstrdup (buf
), file
, line
);
524 v
->ncomponents
= ncomponents
;
530 #define _SPECIAL_MODE(C, N) make_special_mode(MODE_##C, #N, __FILE__, __LINE__)
531 #define RANDOM_MODE(N) _SPECIAL_MODE (RANDOM, N)
532 #define CC_MODE(N) _SPECIAL_MODE (CC, N)
535 make_special_mode (enum mode_class cl
, const char *name
,
536 const char *file
, unsigned int line
)
538 new_mode (cl
, name
, file
, line
);
541 #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y)
542 #define FRACTIONAL_INT_MODE(N, B, Y) \
543 make_int_mode (#N, B, Y, __FILE__, __LINE__)
546 make_int_mode (const char *name
,
547 unsigned int precision
, unsigned int bytesize
,
548 const char *file
, unsigned int line
)
550 struct mode_data
*m
= new_mode (MODE_INT
, name
, file
, line
);
551 m
->bytesize
= bytesize
;
552 m
->precision
= precision
;
555 #define FRACT_MODE(N, Y, F) \
556 make_fixed_point_mode (MODE_FRACT, #N, Y, 0, F, __FILE__, __LINE__)
558 #define UFRACT_MODE(N, Y, F) \
559 make_fixed_point_mode (MODE_UFRACT, #N, Y, 0, F, __FILE__, __LINE__)
561 #define ACCUM_MODE(N, Y, I, F) \
562 make_fixed_point_mode (MODE_ACCUM, #N, Y, I, F, __FILE__, __LINE__)
564 #define UACCUM_MODE(N, Y, I, F) \
565 make_fixed_point_mode (MODE_UACCUM, #N, Y, I, F, __FILE__, __LINE__)
567 /* Create a fixed-point mode by setting CL, NAME, BYTESIZE, IBIT, FBIT,
571 make_fixed_point_mode (enum mode_class cl
,
573 unsigned int bytesize
,
576 const char *file
, unsigned int line
)
578 struct mode_data
*m
= new_mode (cl
, name
, file
, line
);
579 m
->bytesize
= bytesize
;
584 #define FLOAT_MODE(N, Y, F) FRACTIONAL_FLOAT_MODE (N, -1U, Y, F)
585 #define FRACTIONAL_FLOAT_MODE(N, B, Y, F) \
586 make_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
589 make_float_mode (const char *name
,
590 unsigned int precision
, unsigned int bytesize
,
592 const char *file
, unsigned int line
)
594 struct mode_data
*m
= new_mode (MODE_FLOAT
, name
, file
, line
);
595 m
->bytesize
= bytesize
;
596 m
->precision
= precision
;
600 #define DECIMAL_FLOAT_MODE(N, Y, F) \
601 FRACTIONAL_DECIMAL_FLOAT_MODE (N, -1U, Y, F)
602 #define FRACTIONAL_DECIMAL_FLOAT_MODE(N, B, Y, F) \
603 make_decimal_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
606 make_decimal_float_mode (const char *name
,
607 unsigned int precision
, unsigned int bytesize
,
609 const char *file
, unsigned int line
)
611 struct mode_data
*m
= new_mode (MODE_DECIMAL_FLOAT
, name
, file
, line
);
612 m
->bytesize
= bytesize
;
613 m
->precision
= precision
;
617 #define RESET_FLOAT_FORMAT(N, F) \
618 reset_float_format (#N, #F, __FILE__, __LINE__)
619 static void ATTRIBUTE_UNUSED
620 reset_float_format (const char *name
, const char *format
,
621 const char *file
, unsigned int line
)
623 struct mode_data
*m
= find_mode (name
);
626 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
629 if (m
->cl
!= MODE_FLOAT
&& m
->cl
!= MODE_DECIMAL_FLOAT
)
631 error ("%s:%d: mode \"%s\" is not a FLOAT class", file
, line
, name
);
637 /* Partial integer modes are specified by relation to a full integer mode.
638 For now, we do not attempt to narrow down their bit sizes. */
639 #define PARTIAL_INT_MODE(M) \
640 make_partial_integer_mode (#M, "P" #M, -1U, __FILE__, __LINE__)
641 static void ATTRIBUTE_UNUSED
642 make_partial_integer_mode (const char *base
, const char *name
,
643 unsigned int precision
,
644 const char *file
, unsigned int line
)
647 struct mode_data
*component
= find_mode (base
);
650 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
653 if (component
->cl
!= MODE_INT
)
655 error ("%s:%d: mode \"%s\" is not class INT", file
, line
, name
);
659 m
= new_mode (MODE_PARTIAL_INT
, name
, file
, line
);
660 m
->precision
= precision
;
661 m
->component
= component
;
664 /* A single vector mode can be specified by naming its component
665 mode and the number of components. */
666 #define VECTOR_MODE(C, M, N) \
667 make_vector_mode (MODE_##C, #M, N, __FILE__, __LINE__);
668 static void ATTRIBUTE_UNUSED
669 make_vector_mode (enum mode_class bclass
,
671 unsigned int ncomponents
,
672 const char *file
, unsigned int line
)
675 enum mode_class vclass
= vector_class (bclass
);
676 struct mode_data
*component
= find_mode (base
);
679 if (vclass
== MODE_RANDOM
)
683 error ("%s:%d: no mode \"%s\"", file
, line
, base
);
686 if (component
->cl
!= bclass
687 && (component
->cl
!= MODE_PARTIAL_INT
688 || bclass
!= MODE_INT
))
690 error ("%s:%d: mode \"%s\" is not class %s",
691 file
, line
, base
, mode_class_names
[bclass
] + 5);
695 if ((size_t)snprintf (namebuf
, sizeof namebuf
, "V%u%s",
696 ncomponents
, base
) >= sizeof namebuf
)
698 error ("%s:%d: mode name \"%s\" is too long",
703 v
= new_mode (vclass
, xstrdup (namebuf
), file
, line
);
704 v
->ncomponents
= ncomponents
;
705 v
->component
= component
;
709 #define _ADD_ADJUST(A, M, X, C1, C2) \
710 new_adjust (#M, &adj_##A, #A, #X, MODE_##C1, MODE_##C2, __FILE__, __LINE__)
712 #define ADJUST_BYTESIZE(M, X) _ADD_ADJUST(bytesize, M, X, RANDOM, RANDOM)
713 #define ADJUST_ALIGNMENT(M, X) _ADD_ADJUST(alignment, M, X, RANDOM, RANDOM)
714 #define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST(format, M, X, FLOAT, FLOAT)
715 #define ADJUST_IBIT(M, X) _ADD_ADJUST(ibit, M, X, ACCUM, UACCUM)
716 #define ADJUST_FBIT(M, X) _ADD_ADJUST(fbit, M, X, FRACT, UACCUM)
721 #include "machmode.def"
726 /* Sort a list of modes into the order needed for the WIDER field:
727 major sort by precision, minor sort by component precision.
730 QI < HI < SI < DI < TI
731 V4QI < V2HI < V8QI < V4HI < V2SI.
733 If the precision is not set, sort by the bytesize. A mode with
734 precision set gets sorted before a mode without precision set, if
735 they have the same bytesize; this is the right thing because
736 the precision must always be smaller than the bytesize * BITS_PER_UNIT.
737 We don't have to do anything special to get this done -- an unset
738 precision shows up as (unsigned int)-1, i.e. UINT_MAX. */
740 cmp_modes (const void *a
, const void *b
)
742 const struct mode_data
*const m
= *(const struct mode_data
*const*)a
;
743 const struct mode_data
*const n
= *(const struct mode_data
*const*)b
;
745 if (m
->bytesize
> n
->bytesize
)
747 else if (m
->bytesize
< n
->bytesize
)
750 if (m
->precision
> n
->precision
)
752 else if (m
->precision
< n
->precision
)
755 if (!m
->component
&& !n
->component
)
757 if (m
->counter
< n
->counter
)
763 if (m
->component
->bytesize
> n
->component
->bytesize
)
765 else if (m
->component
->bytesize
< n
->component
->bytesize
)
768 if (m
->component
->precision
> n
->component
->precision
)
770 else if (m
->component
->precision
< n
->component
->precision
)
773 if (m
->counter
< n
->counter
)
780 calc_wider_mode (void)
784 struct mode_data
**sortbuf
;
785 unsigned int max_n_modes
= 0;
788 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
789 max_n_modes
= MAX (max_n_modes
, n_modes
[c
]);
791 /* Allocate max_n_modes + 1 entries to leave room for the extra null
792 pointer assigned after the qsort call below. */
793 sortbuf
= (struct mode_data
**) alloca ((max_n_modes
+ 1) * sizeof (struct mode_data
*));
795 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
797 /* "wider" is not meaningful for MODE_RANDOM and MODE_CC.
798 However, we want these in textual order, and we have
799 precisely the reverse. */
800 if (c
== MODE_RANDOM
|| c
== MODE_CC
)
802 struct mode_data
*prev
, *next
;
804 for (prev
= 0, m
= modes
[c
]; m
; m
= next
)
806 m
->wider
= void_mode
;
807 m
->wider_2x
= void_mode
;
809 /* this is nreverse */
821 for (i
= 0, m
= modes
[c
]; m
; i
++, m
= m
->next
)
824 qsort (sortbuf
, i
, sizeof (struct mode_data
*), cmp_modes
);
827 for (j
= 0; j
< i
; j
++)
828 sortbuf
[j
]->next
= sortbuf
[j
]->wider
= sortbuf
[j
+ 1];
831 modes
[c
] = sortbuf
[0];
836 /* Output routines. */
838 #define tagged_printf(FMT, ARG, TAG) do { \
839 int count_ = printf (" " FMT ",", ARG); \
840 printf ("%*s/* %s */\n", 27 - count_, "", TAG); \
843 #define print_decl(TYPE, NAME, ASIZE) \
844 puts ("\nconst " TYPE " " NAME "[" ASIZE "] =\n{");
846 #define print_maybe_const_decl(TYPE, NAME, ASIZE, CATEGORY) \
847 printf ("\n" TYPE " " NAME "[" ASIZE "] = \n{\n", \
848 adj_##CATEGORY ? "" : "const ")
850 #define print_closer() puts ("};")
853 emit_insn_modes_h (void)
856 struct mode_data
*m
, *first
, *last
;
858 printf ("/* Generated automatically from machmode.def%s%s\n",
859 HAVE_EXTRA_MODES
? " and " : "",
865 #ifndef GCC_INSN_MODES_H\n\
866 #define GCC_INSN_MODES_H\n\
868 enum machine_mode\n{");
870 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
871 for (m
= modes
[c
]; m
; m
= m
->next
)
873 int count_
= printf (" %smode,", m
->name
);
874 printf ("%*s/* %s:%d */\n", 27 - count_
, "",
875 trim_filename (m
->file
), m
->line
);
878 puts (" MAX_MACHINE_MODE,\n");
880 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
884 for (m
= first
; m
; last
= m
, m
= m
->next
)
887 /* Don't use BImode for MIN_MODE_INT, since otherwise the middle
888 end will try to use it for bitfields in structures and the
889 like, which we do not want. Only the target md file should
890 generate BImode widgets. */
891 if (first
&& first
->precision
== 1)
895 printf (" MIN_%s = %smode,\n MAX_%s = %smode,\n\n",
896 mode_class_names
[c
], first
->name
,
897 mode_class_names
[c
], last
->name
);
899 printf (" MIN_%s = %smode,\n MAX_%s = %smode,\n\n",
900 mode_class_names
[c
], void_mode
->name
,
901 mode_class_names
[c
], void_mode
->name
);
905 NUM_MACHINE_MODES = MAX_MACHINE_MODE\n\
908 /* I can't think of a better idea, can you? */
909 printf ("#define CONST_MODE_SIZE%s\n", adj_bytesize
? "" : " const");
910 printf ("#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment
? "" : " const");
911 #if 0 /* disabled for backward compatibility, temporary */
912 printf ("#define CONST_REAL_FORMAT_FOR_MODE%s\n", adj_format
? "" :" const");
914 printf ("#define CONST_MODE_IBIT%s\n", adj_ibit
? "" : " const");
915 printf ("#define CONST_MODE_FBIT%s\n", adj_fbit
? "" : " const");
918 #endif /* insn-modes.h */");
922 emit_insn_modes_c_header (void)
924 printf ("/* Generated automatically from machmode.def%s%s\n",
925 HAVE_EXTRA_MODES
? " and " : "",
931 #include \"config.h\"\n\
932 #include \"system.h\"\n\
933 #include \"coretypes.h\"\n\
935 #include \"machmode.h\"\n\
936 #include \"real.h\"");
940 emit_min_insn_modes_c_header (void)
942 printf ("/* Generated automatically from machmode.def%s%s\n",
943 HAVE_EXTRA_MODES
? " and " : "",
949 #include \"bconfig.h\"\n\
950 #include \"system.h\"\n\
951 #include \"machmode.h\"");
955 emit_mode_name (void)
960 print_decl ("char *const", "mode_name", "NUM_MACHINE_MODES");
963 printf (" \"%s\",\n", m
->name
);
969 emit_mode_class (void)
974 print_decl ("unsigned char", "mode_class", "NUM_MACHINE_MODES");
977 tagged_printf ("%s", mode_class_names
[m
->cl
], m
->name
);
983 emit_mode_precision (void)
988 print_decl ("unsigned short", "mode_precision", "NUM_MACHINE_MODES");
991 if (m
->precision
!= (unsigned int)-1)
992 tagged_printf ("%u", m
->precision
, m
->name
);
994 tagged_printf ("%u*BITS_PER_UNIT", m
->bytesize
, m
->name
);
1000 emit_mode_size (void)
1003 struct mode_data
*m
;
1005 print_maybe_const_decl ("%sunsigned char", "mode_size",
1006 "NUM_MACHINE_MODES", bytesize
);
1008 for_all_modes (c
, m
)
1009 tagged_printf ("%u", m
->bytesize
, m
->name
);
1015 emit_mode_nunits (void)
1018 struct mode_data
*m
;
1020 print_decl ("unsigned char", "mode_nunits", "NUM_MACHINE_MODES");
1022 for_all_modes (c
, m
)
1023 tagged_printf ("%u", m
->ncomponents
, m
->name
);
1029 emit_mode_wider (void)
1032 struct mode_data
*m
;
1034 print_decl ("unsigned char", "mode_wider", "NUM_MACHINE_MODES");
1036 for_all_modes (c
, m
)
1037 tagged_printf ("%smode",
1038 m
->wider
? m
->wider
->name
: void_mode
->name
,
1042 print_decl ("unsigned char", "mode_2xwider", "NUM_MACHINE_MODES");
1044 for_all_modes (c
, m
)
1046 struct mode_data
* m2
;
1049 m2
&& m2
!= void_mode
;
1052 if (m2
->bytesize
< 2 * m
->bytesize
)
1054 if (m
->precision
!= (unsigned int) -1)
1056 if (m2
->precision
!= 2 * m
->precision
)
1061 if (m2
->precision
!= (unsigned int) -1)
1067 if (m2
== void_mode
)
1069 tagged_printf ("%smode",
1070 m2
? m2
->name
: void_mode
->name
,
1078 emit_mode_mask (void)
1081 struct mode_data
*m
;
1083 print_decl ("unsigned HOST_WIDE_INT", "mode_mask_array",
1084 "NUM_MACHINE_MODES");
1086 #define MODE_MASK(m) \\\n\
1087 ((m) >= HOST_BITS_PER_WIDE_INT) \\\n\
1088 ? ~(unsigned HOST_WIDE_INT) 0 \\\n\
1089 : ((unsigned HOST_WIDE_INT) 1 << (m)) - 1\n");
1091 for_all_modes (c
, m
)
1092 if (m
->precision
!= (unsigned int)-1)
1093 tagged_printf ("MODE_MASK (%u)", m
->precision
, m
->name
);
1095 tagged_printf ("MODE_MASK (%u*BITS_PER_UNIT)", m
->bytesize
, m
->name
);
1097 puts ("#undef MODE_MASK");
1102 emit_mode_inner (void)
1105 struct mode_data
*m
;
1107 print_decl ("unsigned char", "mode_inner", "NUM_MACHINE_MODES");
1109 for_all_modes (c
, m
)
1110 tagged_printf ("%smode",
1111 m
->component
? m
->component
->name
: void_mode
->name
,
1118 emit_mode_base_align (void)
1121 struct mode_data
*m
;
1123 print_maybe_const_decl ("%sunsigned char",
1124 "mode_base_align", "NUM_MACHINE_MODES",
1127 for_all_modes (c
, m
)
1128 tagged_printf ("%u", m
->alignment
, m
->name
);
1134 emit_class_narrowest_mode (void)
1138 print_decl ("unsigned char", "class_narrowest_mode", "MAX_MODE_CLASS");
1140 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1141 /* Bleah, all this to get the comment right for MIN_MODE_INT. */
1142 tagged_printf ("MIN_%s", mode_class_names
[c
],
1144 ? (modes
[c
]->precision
!= 1
1147 ? modes
[c
]->next
->name
1155 emit_real_format_for_mode (void)
1157 struct mode_data
*m
;
1159 /* The entities pointed to by this table are constant, whether
1160 or not the table itself is constant.
1162 For backward compatibility this table is always writable
1163 (several targets modify it in TARGET_OPTION_OVERRIDE). FIXME:
1164 convert all said targets to use ADJUST_FORMAT instead. */
1166 print_maybe_const_decl ("const struct real_format *%s",
1167 "real_format_for_mode",
1168 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1",
1171 print_decl ("struct real_format *\n", "real_format_for_mode",
1172 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1 "
1173 "+ MAX_MODE_DECIMAL_FLOAT - MIN_MODE_DECIMAL_FLOAT + 1");
1176 /* The beginning of the table is entries for float modes. */
1177 for (m
= modes
[MODE_FLOAT
]; m
; m
= m
->next
)
1178 if (!strcmp (m
->format
, "0"))
1179 tagged_printf ("%s", m
->format
, m
->name
);
1181 tagged_printf ("&%s", m
->format
, m
->name
);
1183 /* The end of the table is entries for decimal float modes. */
1184 for (m
= modes
[MODE_DECIMAL_FLOAT
]; m
; m
= m
->next
)
1185 if (!strcmp (m
->format
, "0"))
1186 tagged_printf ("%s", m
->format
, m
->name
);
1188 tagged_printf ("&%s", m
->format
, m
->name
);
1194 emit_mode_adjustments (void)
1196 struct mode_adjust
*a
;
1197 struct mode_data
*m
;
1201 \ninit_adjust_machine_modes (void)\
1203 \n size_t s ATTRIBUTE_UNUSED;");
1205 /* Size adjustments must be propagated to all containing modes.
1206 A size adjustment forces us to recalculate the alignment too. */
1207 for (a
= adj_bytesize
; a
; a
= a
->next
)
1209 printf ("\n /* %s:%d */\n s = %s;\n",
1210 a
->file
, a
->line
, a
->adjustment
);
1211 printf (" mode_size[%smode] = s;\n", a
->mode
->name
);
1212 printf (" mode_base_align[%smode] = s & (~s + 1);\n",
1215 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1219 case MODE_COMPLEX_INT
:
1220 case MODE_COMPLEX_FLOAT
:
1221 printf (" mode_size[%smode] = 2*s;\n", m
->name
);
1222 printf (" mode_base_align[%smode] = s & (~s + 1);\n",
1226 case MODE_VECTOR_INT
:
1227 case MODE_VECTOR_FLOAT
:
1228 case MODE_VECTOR_FRACT
:
1229 case MODE_VECTOR_UFRACT
:
1230 case MODE_VECTOR_ACCUM
:
1231 case MODE_VECTOR_UACCUM
:
1232 printf (" mode_size[%smode] = %d*s;\n",
1233 m
->name
, m
->ncomponents
);
1234 printf (" mode_base_align[%smode] = (%d*s) & (~(%d*s)+1);\n",
1235 m
->name
, m
->ncomponents
, m
->ncomponents
);
1240 "mode %s is neither vector nor complex but contains %s",
1241 m
->name
, a
->mode
->name
);
1247 /* Alignment adjustments propagate too.
1248 ??? This may not be the right thing for vector modes. */
1249 for (a
= adj_alignment
; a
; a
= a
->next
)
1251 printf ("\n /* %s:%d */\n s = %s;\n",
1252 a
->file
, a
->line
, a
->adjustment
);
1253 printf (" mode_base_align[%smode] = s;\n", a
->mode
->name
);
1255 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1259 case MODE_COMPLEX_INT
:
1260 case MODE_COMPLEX_FLOAT
:
1261 printf (" mode_base_align[%smode] = s;\n", m
->name
);
1264 case MODE_VECTOR_INT
:
1265 case MODE_VECTOR_FLOAT
:
1266 case MODE_VECTOR_FRACT
:
1267 case MODE_VECTOR_UFRACT
:
1268 case MODE_VECTOR_ACCUM
:
1269 case MODE_VECTOR_UACCUM
:
1270 printf (" mode_base_align[%smode] = %d*s;\n",
1271 m
->name
, m
->ncomponents
);
1276 "mode %s is neither vector nor complex but contains %s",
1277 m
->name
, a
->mode
->name
);
1283 /* Ibit adjustments don't have to propagate. */
1284 for (a
= adj_ibit
; a
; a
= a
->next
)
1286 printf ("\n /* %s:%d */\n s = %s;\n",
1287 a
->file
, a
->line
, a
->adjustment
);
1288 printf (" mode_ibit[%smode] = s;\n", a
->mode
->name
);
1291 /* Fbit adjustments don't have to propagate. */
1292 for (a
= adj_fbit
; a
; a
= a
->next
)
1294 printf ("\n /* %s:%d */\n s = %s;\n",
1295 a
->file
, a
->line
, a
->adjustment
);
1296 printf (" mode_fbit[%smode] = s;\n", a
->mode
->name
);
1299 /* Real mode formats don't have to propagate anywhere. */
1300 for (a
= adj_format
; a
; a
= a
->next
)
1301 printf ("\n /* %s:%d */\n REAL_MODE_FORMAT (%smode) = %s;\n",
1302 a
->file
, a
->line
, a
->mode
->name
, a
->adjustment
);
1307 /* Emit ibit for all modes. */
1310 emit_mode_ibit (void)
1313 struct mode_data
*m
;
1315 print_maybe_const_decl ("%sunsigned char",
1316 "mode_ibit", "NUM_MACHINE_MODES",
1319 for_all_modes (c
, m
)
1320 tagged_printf ("%u", m
->ibit
, m
->name
);
1325 /* Emit fbit for all modes. */
1328 emit_mode_fbit (void)
1331 struct mode_data
*m
;
1333 print_maybe_const_decl ("%sunsigned char",
1334 "mode_fbit", "NUM_MACHINE_MODES",
1337 for_all_modes (c
, m
)
1338 tagged_printf ("%u", m
->fbit
, m
->name
);
1345 emit_insn_modes_c (void)
1347 emit_insn_modes_c_header ();
1350 emit_mode_precision ();
1352 emit_mode_nunits ();
1356 emit_mode_base_align ();
1357 emit_class_narrowest_mode ();
1358 emit_real_format_for_mode ();
1359 emit_mode_adjustments ();
1365 emit_min_insn_modes_c (void)
1367 emit_min_insn_modes_c_header ();
1371 emit_class_narrowest_mode ();
1374 /* Master control. */
1376 main (int argc
, char **argv
)
1378 bool gen_header
= false, gen_min
= false;
1383 else if (argc
== 2 && !strcmp (argv
[1], "-h"))
1385 else if (argc
== 2 && !strcmp (argv
[1], "-m"))
1389 error ("usage: %s [-h|-m] > file", progname
);
1390 return FATAL_EXIT_CODE
;
1393 modes_by_name
= htab_create_alloc (64, hash_mode
, eq_mode
, 0, xcalloc
, free
);
1396 complete_all_modes ();
1399 return FATAL_EXIT_CODE
;
1404 emit_insn_modes_h ();
1406 emit_min_insn_modes_c ();
1408 emit_insn_modes_c ();
1410 if (fflush (stdout
) || fclose (stdout
))
1411 return FATAL_EXIT_CODE
;
1412 return SUCCESS_EXIT_CODE
;