1 /* Generate the machine mode enumeration and associated tables.
2 Copyright (C) 2003-2013 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
25 /* enum mode_class is normally defined by machmode.h but we can't
26 include that header here. */
27 #include "mode-classes.def"
29 #define DEF_MODE_CLASS(M) M
30 enum mode_class
{ MODE_CLASSES
, MAX_MODE_CLASS
};
33 /* Text names of mode classes, for output. */
34 #define DEF_MODE_CLASS(M) #M
35 static const char *const mode_class_names
[MAX_MODE_CLASS
] =
42 #ifdef EXTRA_MODES_FILE
43 # define HAVE_EXTRA_MODES 1
45 # define HAVE_EXTRA_MODES 0
46 # define EXTRA_MODES_FILE ""
49 /* Data structure for building up what we know about a mode.
50 They're clustered by mode class. */
53 struct mode_data
*next
; /* next this class - arbitrary order */
55 const char *name
; /* printable mode name -- SI, not SImode */
56 enum mode_class cl
; /* this mode class */
57 unsigned int precision
; /* size in bits, equiv to TYPE_PRECISION */
58 unsigned int bytesize
; /* storage size in addressable units */
59 unsigned int ncomponents
; /* number of subunits */
60 unsigned int alignment
; /* mode alignment */
61 const char *format
; /* floating point format - float modes only */
63 struct mode_data
*component
; /* mode of components */
64 struct mode_data
*wider
; /* next wider mode */
66 struct mode_data
*contained
; /* Pointer to list of modes that have
67 this mode as a component. */
68 struct mode_data
*next_cont
; /* Next mode in that list. */
70 const char *file
; /* file and line of definition, */
71 unsigned int line
; /* for error reporting */
72 unsigned int counter
; /* Rank ordering of modes */
73 unsigned int ibit
; /* the number of integral bits */
74 unsigned int fbit
; /* the number of fractional bits */
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
,
85 "<unknown>", 0, 0, 0, 0
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
;
106 static struct mode_adjust
*adj_ibit
;
107 static struct mode_adjust
*adj_fbit
;
109 /* Mode class operations. */
110 static enum mode_class
111 complex_class (enum mode_class c
)
115 case MODE_INT
: return MODE_COMPLEX_INT
;
116 case MODE_FLOAT
: return MODE_COMPLEX_FLOAT
;
118 error ("no complex class for class %s", mode_class_names
[c
]);
123 static enum mode_class
124 vector_class (enum mode_class cl
)
128 case MODE_INT
: return MODE_VECTOR_INT
;
129 case MODE_FLOAT
: return MODE_VECTOR_FLOAT
;
130 case MODE_FRACT
: return MODE_VECTOR_FRACT
;
131 case MODE_UFRACT
: return MODE_VECTOR_UFRACT
;
132 case MODE_ACCUM
: return MODE_VECTOR_ACCUM
;
133 case MODE_UACCUM
: return MODE_VECTOR_UACCUM
;
135 error ("no vector class for class %s", mode_class_names
[cl
]);
140 /* Utility routines. */
141 static inline struct mode_data
*
142 find_mode (const char *name
)
144 struct mode_data key
;
147 return (struct mode_data
*) htab_find (modes_by_name
, &key
);
150 static struct mode_data
*
151 new_mode (enum mode_class cl
, const char *name
,
152 const char *file
, unsigned int line
)
155 static unsigned int count
= 0;
157 m
= find_mode (name
);
160 error ("%s:%d: duplicate definition of mode \"%s\"",
161 trim_filename (file
), line
, name
);
162 error ("%s:%d: previous definition here", m
->file
, m
->line
);
166 m
= XNEW (struct mode_data
);
167 memcpy (m
, &blank_mode
, sizeof (struct mode_data
));
171 m
->file
= trim_filename (file
);
173 m
->counter
= count
++;
179 *htab_find_slot (modes_by_name
, m
, INSERT
) = m
;
185 hash_mode (const void *p
)
187 const struct mode_data
*m
= (const struct mode_data
*)p
;
188 return htab_hash_string (m
->name
);
192 eq_mode (const void *p
, const void *q
)
194 const struct mode_data
*a
= (const struct mode_data
*)p
;
195 const struct mode_data
*b
= (const struct mode_data
*)q
;
197 return !strcmp (a
->name
, b
->name
);
200 #define for_all_modes(C, M) \
201 for (C = 0; C < MAX_MODE_CLASS; C++) \
202 for (M = modes[C]; M; M = M->next)
204 static void ATTRIBUTE_UNUSED
205 new_adjust (const char *name
,
206 struct mode_adjust
**category
, const char *catname
,
207 const char *adjustment
,
208 enum mode_class required_class_from
,
209 enum mode_class required_class_to
,
210 const char *file
, unsigned int line
)
212 struct mode_data
*mode
= find_mode (name
);
213 struct mode_adjust
*a
;
215 file
= trim_filename (file
);
219 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
223 if (required_class_from
!= MODE_RANDOM
224 && (mode
->cl
< required_class_from
|| mode
->cl
> required_class_to
))
226 error ("%s:%d: mode \"%s\" is not among class {%s, %s}",
227 file
, line
, name
, mode_class_names
[required_class_from
] + 5,
228 mode_class_names
[required_class_to
] + 5);
232 for (a
= *category
; a
; a
= a
->next
)
235 error ("%s:%d: mode \"%s\" already has a %s adjustment",
236 file
, line
, name
, catname
);
237 error ("%s:%d: previous adjustment here", a
->file
, a
->line
);
241 a
= XNEW (struct mode_adjust
);
243 a
->adjustment
= adjustment
;
251 /* Diagnose failure to meet expectations in a partially filled out
253 enum requirement
{ SET
, UNSET
, OPTIONAL
};
255 #define validate_field_(mname, fname, req, val, unset, file, line) do { \
260 error ("%s:%d: (%s) field %s must be set", \
261 file, line, mname, fname); \
265 error ("%s:%d: (%s) field %s must not be set", \
266 file, line, mname, fname); \
272 #define validate_field(M, F) \
273 validate_field_(M->name, #F, r_##F, M->F, blank_mode.F, M->file, M->line)
276 validate_mode (struct mode_data
*m
,
277 enum requirement r_precision
,
278 enum requirement r_bytesize
,
279 enum requirement r_component
,
280 enum requirement r_ncomponents
,
281 enum requirement r_format
)
283 validate_field (m
, precision
);
284 validate_field (m
, bytesize
);
285 validate_field (m
, component
);
286 validate_field (m
, ncomponents
);
287 validate_field (m
, format
);
289 #undef validate_field
290 #undef validate_field_
292 /* Given a partially-filled-out mode structure, figure out what we can
293 and fill the rest of it in; die if it isn't enough. */
295 complete_mode (struct mode_data
*m
)
297 unsigned int alignment
;
301 error ("%s:%d: mode with no name", m
->file
, m
->line
);
304 if (m
->cl
== MAX_MODE_CLASS
)
306 error ("%s:%d: %smode has no mode class", m
->file
, m
->line
, m
->name
);
313 /* Nothing more need be said. */
314 if (!strcmp (m
->name
, "VOID"))
317 validate_mode (m
, UNSET
, UNSET
, UNSET
, UNSET
, UNSET
);
326 /* Again, nothing more need be said. For historical reasons,
327 the size of a CC mode is four units. */
328 validate_mode (m
, UNSET
, UNSET
, UNSET
, UNSET
, UNSET
);
337 case MODE_DECIMAL_FLOAT
:
342 /* A scalar mode must have a byte size, may have a bit size,
343 and must not have components. A float mode must have a
345 validate_mode (m
, OPTIONAL
, SET
, UNSET
, UNSET
,
346 (m
->cl
== MODE_FLOAT
|| m
->cl
== MODE_DECIMAL_FLOAT
)
353 case MODE_PARTIAL_INT
:
354 /* A partial integer mode uses ->component to say what the
355 corresponding full-size integer mode is, and may also
356 specify a bit size. */
357 validate_mode (m
, OPTIONAL
, UNSET
, SET
, UNSET
, UNSET
);
359 m
->bytesize
= m
->component
->bytesize
;
364 case MODE_COMPLEX_INT
:
365 case MODE_COMPLEX_FLOAT
:
366 /* Complex modes should have a component indicated, but no more. */
367 validate_mode (m
, UNSET
, UNSET
, SET
, UNSET
, UNSET
);
369 if (m
->component
->precision
!= (unsigned int)-1)
370 m
->precision
= 2 * m
->component
->precision
;
371 m
->bytesize
= 2 * m
->component
->bytesize
;
374 case MODE_VECTOR_INT
:
375 case MODE_VECTOR_FLOAT
:
376 case MODE_VECTOR_FRACT
:
377 case MODE_VECTOR_UFRACT
:
378 case MODE_VECTOR_ACCUM
:
379 case MODE_VECTOR_UACCUM
:
380 /* Vector modes should have a component and a number of components. */
381 validate_mode (m
, UNSET
, UNSET
, SET
, SET
, UNSET
);
382 if (m
->component
->precision
!= (unsigned int)-1)
383 m
->precision
= m
->ncomponents
* m
->component
->precision
;
384 m
->bytesize
= m
->ncomponents
* m
->component
->bytesize
;
391 /* If not already specified, the mode alignment defaults to the largest
392 power of two that divides the size of the object. Complex types are
393 not more aligned than their contents. */
394 if (m
->cl
== MODE_COMPLEX_INT
|| m
->cl
== MODE_COMPLEX_FLOAT
)
395 alignment
= m
->component
->bytesize
;
397 alignment
= m
->bytesize
;
399 m
->alignment
= alignment
& (~alignment
+ 1);
401 /* If this mode has components, make the component mode point back
402 to this mode, for the sake of adjustments. */
405 m
->next_cont
= m
->component
->contained
;
406 m
->component
->contained
= m
;
411 complete_all_modes (void)
416 for_all_modes (cl
, m
)
420 /* For each mode in class CLASS, construct a corresponding complex mode. */
421 #define COMPLEX_MODES(C) make_complex_modes(MODE_##C, __FILE__, __LINE__)
423 make_complex_modes (enum mode_class cl
,
424 const char *file
, unsigned int line
)
428 enum mode_class cclass
= complex_class (cl
);
430 if (cclass
== MODE_RANDOM
)
433 for (m
= modes
[cl
]; m
; m
= m
->next
)
438 /* Skip BImode. FIXME: BImode probably shouldn't be MODE_INT. */
439 if (m
->precision
== 1)
442 m_len
= strlen (m
->name
);
443 /* The leading "1 +" is in case we prepend a "C" below. */
444 buf
= (char *) xmalloc (1 + m_len
+ 1);
446 /* Float complex modes are named SCmode, etc.
447 Int complex modes are named CSImode, etc.
448 This inconsistency should be eliminated. */
450 if (cl
== MODE_FLOAT
)
452 memcpy (buf
, m
->name
, m_len
+ 1);
453 p
= strchr (buf
, 'F');
454 if (p
== 0 && strchr (buf
, 'D') == 0)
456 error ("%s:%d: float mode \"%s\" has no 'F' or 'D'",
457 m
->file
, m
->line
, m
->name
);
467 memcpy (buf
+ 1, m
->name
, m_len
+ 1);
470 c
= new_mode (cclass
, buf
, file
, line
);
475 /* For all modes in class CL, construct vector modes of width
476 WIDTH, having as many components as necessary. */
477 #define VECTOR_MODES(C, W) make_vector_modes(MODE_##C, W, __FILE__, __LINE__)
478 static void ATTRIBUTE_UNUSED
479 make_vector_modes (enum mode_class cl
, unsigned int width
,
480 const char *file
, unsigned int line
)
485 unsigned int ncomponents
;
486 enum mode_class vclass
= vector_class (cl
);
488 if (vclass
== MODE_RANDOM
)
491 for (m
= modes
[cl
]; m
; m
= m
->next
)
493 /* Do not construct vector modes with only one element, or
494 vector modes where the element size doesn't divide the full
496 ncomponents
= width
/ m
->bytesize
;
499 if (width
% m
->bytesize
)
502 /* Skip QFmode and BImode. FIXME: this special case should
504 if (cl
== MODE_FLOAT
&& m
->bytesize
== 1)
506 if (cl
== MODE_INT
&& m
->precision
== 1)
509 if ((size_t)snprintf (buf
, sizeof buf
, "V%u%s", ncomponents
, m
->name
)
512 error ("%s:%d: mode name \"%s\" is too long",
513 m
->file
, m
->line
, m
->name
);
517 v
= new_mode (vclass
, xstrdup (buf
), file
, line
);
519 v
->ncomponents
= ncomponents
;
525 #define _SPECIAL_MODE(C, N) make_special_mode(MODE_##C, #N, __FILE__, __LINE__)
526 #define RANDOM_MODE(N) _SPECIAL_MODE (RANDOM, N)
527 #define CC_MODE(N) _SPECIAL_MODE (CC, N)
530 make_special_mode (enum mode_class cl
, const char *name
,
531 const char *file
, unsigned int line
)
533 new_mode (cl
, name
, file
, line
);
536 #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y)
537 #define FRACTIONAL_INT_MODE(N, B, Y) \
538 make_int_mode (#N, B, Y, __FILE__, __LINE__)
541 make_int_mode (const char *name
,
542 unsigned int precision
, unsigned int bytesize
,
543 const char *file
, unsigned int line
)
545 struct mode_data
*m
= new_mode (MODE_INT
, name
, file
, line
);
546 m
->bytesize
= bytesize
;
547 m
->precision
= precision
;
550 #define FRACT_MODE(N, Y, F) \
551 make_fixed_point_mode (MODE_FRACT, #N, Y, 0, F, __FILE__, __LINE__)
553 #define UFRACT_MODE(N, Y, F) \
554 make_fixed_point_mode (MODE_UFRACT, #N, Y, 0, F, __FILE__, __LINE__)
556 #define ACCUM_MODE(N, Y, I, F) \
557 make_fixed_point_mode (MODE_ACCUM, #N, Y, I, F, __FILE__, __LINE__)
559 #define UACCUM_MODE(N, Y, I, F) \
560 make_fixed_point_mode (MODE_UACCUM, #N, Y, I, F, __FILE__, __LINE__)
562 /* Create a fixed-point mode by setting CL, NAME, BYTESIZE, IBIT, FBIT,
566 make_fixed_point_mode (enum mode_class cl
,
568 unsigned int bytesize
,
571 const char *file
, unsigned int line
)
573 struct mode_data
*m
= new_mode (cl
, name
, file
, line
);
574 m
->bytesize
= bytesize
;
579 #define FLOAT_MODE(N, Y, F) FRACTIONAL_FLOAT_MODE (N, -1U, Y, F)
580 #define FRACTIONAL_FLOAT_MODE(N, B, Y, F) \
581 make_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
584 make_float_mode (const char *name
,
585 unsigned int precision
, unsigned int bytesize
,
587 const char *file
, unsigned int line
)
589 struct mode_data
*m
= new_mode (MODE_FLOAT
, name
, file
, line
);
590 m
->bytesize
= bytesize
;
591 m
->precision
= precision
;
595 #define DECIMAL_FLOAT_MODE(N, Y, F) \
596 FRACTIONAL_DECIMAL_FLOAT_MODE (N, -1U, Y, F)
597 #define FRACTIONAL_DECIMAL_FLOAT_MODE(N, B, Y, F) \
598 make_decimal_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
601 make_decimal_float_mode (const char *name
,
602 unsigned int precision
, unsigned int bytesize
,
604 const char *file
, unsigned int line
)
606 struct mode_data
*m
= new_mode (MODE_DECIMAL_FLOAT
, name
, file
, line
);
607 m
->bytesize
= bytesize
;
608 m
->precision
= precision
;
612 #define RESET_FLOAT_FORMAT(N, F) \
613 reset_float_format (#N, #F, __FILE__, __LINE__)
614 static void ATTRIBUTE_UNUSED
615 reset_float_format (const char *name
, const char *format
,
616 const char *file
, unsigned int line
)
618 struct mode_data
*m
= find_mode (name
);
621 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
624 if (m
->cl
!= MODE_FLOAT
&& m
->cl
!= MODE_DECIMAL_FLOAT
)
626 error ("%s:%d: mode \"%s\" is not a FLOAT class", file
, line
, name
);
632 /* Partial integer modes are specified by relation to a full integer mode.
633 For now, we do not attempt to narrow down their bit sizes. */
634 #define PARTIAL_INT_MODE(M) \
635 make_partial_integer_mode (#M, "P" #M, -1U, __FILE__, __LINE__)
636 static void ATTRIBUTE_UNUSED
637 make_partial_integer_mode (const char *base
, const char *name
,
638 unsigned int precision
,
639 const char *file
, unsigned int line
)
642 struct mode_data
*component
= find_mode (base
);
645 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
648 if (component
->cl
!= MODE_INT
)
650 error ("%s:%d: mode \"%s\" is not class INT", file
, line
, name
);
654 m
= new_mode (MODE_PARTIAL_INT
, name
, file
, line
);
655 m
->precision
= precision
;
656 m
->component
= component
;
659 /* A single vector mode can be specified by naming its component
660 mode and the number of components. */
661 #define VECTOR_MODE(C, M, N) \
662 make_vector_mode (MODE_##C, #M, N, __FILE__, __LINE__);
663 static void ATTRIBUTE_UNUSED
664 make_vector_mode (enum mode_class bclass
,
666 unsigned int ncomponents
,
667 const char *file
, unsigned int line
)
670 enum mode_class vclass
= vector_class (bclass
);
671 struct mode_data
*component
= find_mode (base
);
674 if (vclass
== MODE_RANDOM
)
678 error ("%s:%d: no mode \"%s\"", file
, line
, base
);
681 if (component
->cl
!= bclass
682 && (component
->cl
!= MODE_PARTIAL_INT
683 || bclass
!= MODE_INT
))
685 error ("%s:%d: mode \"%s\" is not class %s",
686 file
, line
, base
, mode_class_names
[bclass
] + 5);
690 if ((size_t)snprintf (namebuf
, sizeof namebuf
, "V%u%s",
691 ncomponents
, base
) >= sizeof namebuf
)
693 error ("%s:%d: mode name \"%s\" is too long",
698 v
= new_mode (vclass
, xstrdup (namebuf
), file
, line
);
699 v
->ncomponents
= ncomponents
;
700 v
->component
= component
;
704 #define _ADD_ADJUST(A, M, X, C1, C2) \
705 new_adjust (#M, &adj_##A, #A, #X, MODE_##C1, MODE_##C2, __FILE__, __LINE__)
707 #define ADJUST_BYTESIZE(M, X) _ADD_ADJUST(bytesize, M, X, RANDOM, RANDOM)
708 #define ADJUST_ALIGNMENT(M, X) _ADD_ADJUST(alignment, M, X, RANDOM, RANDOM)
709 #define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST(format, M, X, FLOAT, FLOAT)
710 #define ADJUST_IBIT(M, X) _ADD_ADJUST(ibit, M, X, ACCUM, UACCUM)
711 #define ADJUST_FBIT(M, X) _ADD_ADJUST(fbit, M, X, FRACT, UACCUM)
716 #include "machmode.def"
721 /* Sort a list of modes into the order needed for the WIDER field:
722 major sort by precision, minor sort by component precision.
725 QI < HI < SI < DI < TI
726 V4QI < V2HI < V8QI < V4HI < V2SI.
728 If the precision is not set, sort by the bytesize. A mode with
729 precision set gets sorted before a mode without precision set, if
730 they have the same bytesize; this is the right thing because
731 the precision must always be smaller than the bytesize * BITS_PER_UNIT.
732 We don't have to do anything special to get this done -- an unset
733 precision shows up as (unsigned int)-1, i.e. UINT_MAX. */
735 cmp_modes (const void *a
, const void *b
)
737 const struct mode_data
*const m
= *(const struct mode_data
*const*)a
;
738 const struct mode_data
*const n
= *(const struct mode_data
*const*)b
;
740 if (m
->bytesize
> n
->bytesize
)
742 else if (m
->bytesize
< n
->bytesize
)
745 if (m
->precision
> n
->precision
)
747 else if (m
->precision
< n
->precision
)
750 if (!m
->component
&& !n
->component
)
752 if (m
->counter
< n
->counter
)
758 if (m
->component
->bytesize
> n
->component
->bytesize
)
760 else if (m
->component
->bytesize
< n
->component
->bytesize
)
763 if (m
->component
->precision
> n
->component
->precision
)
765 else if (m
->component
->precision
< n
->component
->precision
)
768 if (m
->counter
< n
->counter
)
775 calc_wider_mode (void)
779 struct mode_data
**sortbuf
;
780 unsigned int max_n_modes
= 0;
783 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
784 max_n_modes
= MAX (max_n_modes
, n_modes
[c
]);
786 /* Allocate max_n_modes + 1 entries to leave room for the extra null
787 pointer assigned after the qsort call below. */
788 sortbuf
= XALLOCAVEC (struct mode_data
*, max_n_modes
+ 1);
790 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
792 /* "wider" is not meaningful for MODE_RANDOM and MODE_CC.
793 However, we want these in textual order, and we have
794 precisely the reverse. */
795 if (c
== MODE_RANDOM
|| c
== MODE_CC
)
797 struct mode_data
*prev
, *next
;
799 for (prev
= 0, m
= modes
[c
]; m
; m
= next
)
801 m
->wider
= void_mode
;
803 /* this is nreverse */
815 for (i
= 0, m
= modes
[c
]; m
; i
++, m
= m
->next
)
818 qsort (sortbuf
, i
, sizeof (struct mode_data
*), cmp_modes
);
821 for (j
= 0; j
< i
; j
++)
823 sortbuf
[j
]->next
= sortbuf
[j
+ 1];
824 if (c
== MODE_PARTIAL_INT
)
825 sortbuf
[j
]->wider
= sortbuf
[j
]->component
;
827 sortbuf
[j
]->wider
= sortbuf
[j
]->next
;
830 modes
[c
] = sortbuf
[0];
835 /* Output routines. */
837 #define tagged_printf(FMT, ARG, TAG) do { \
838 int count_ = printf (" " FMT ",", ARG); \
839 printf ("%*s/* %s */\n", 27 - count_, "", TAG); \
842 #define print_decl(TYPE, NAME, ASIZE) \
843 puts ("\nconst " TYPE " " NAME "[" ASIZE "] =\n{");
845 #define print_maybe_const_decl(TYPE, NAME, ASIZE, CATEGORY) \
846 printf ("\n" TYPE " " NAME "[" ASIZE "] = \n{\n", \
847 adj_##CATEGORY ? "" : "const ")
849 #define print_closer() puts ("};")
851 /* Compute the max bitsize of some of the classes of integers. It may
852 be that there are needs for the other integer classes, and this
853 code is easy to extend. */
857 unsigned int max
, mmax
;
862 for (max
= 1, i
= modes
[MODE_INT
]; i
; i
= i
->next
)
863 if (max
< i
->bytesize
)
866 for (max
= 1, i
= modes
[MODE_PARTIAL_INT
]; i
; i
= i
->next
)
867 if (max
< i
->bytesize
)
871 printf ("#define MAX_BITSIZE_MODE_ANY_INT %d*BITS_PER_UNIT\n", mmax
);
874 for (j
= 0; j
< MAX_MODE_CLASS
; j
++)
875 for (i
= modes
[j
]; i
; i
= i
->next
)
876 if (mmax
< i
->bytesize
)
878 printf ("#define MAX_BITSIZE_MODE_ANY_MODE %d*BITS_PER_UNIT\n", mmax
);
882 emit_insn_modes_h (void)
885 struct mode_data
*m
, *first
, *last
;
887 printf ("/* Generated automatically from machmode.def%s%s\n",
888 HAVE_EXTRA_MODES
? " and " : "",
894 #ifndef GCC_INSN_MODES_H\n\
895 #define GCC_INSN_MODES_H\n\
897 enum machine_mode\n{");
899 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
900 for (m
= modes
[c
]; m
; m
= m
->next
)
902 int count_
= printf (" %smode,", m
->name
);
903 printf ("%*s/* %s:%d */\n", 27 - count_
, "",
904 trim_filename (m
->file
), m
->line
);
907 puts (" MAX_MACHINE_MODE,\n");
909 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
913 for (m
= first
; m
; last
= m
, m
= m
->next
)
916 /* Don't use BImode for MIN_MODE_INT, since otherwise the middle
917 end will try to use it for bitfields in structures and the
918 like, which we do not want. Only the target md file should
919 generate BImode widgets. */
920 if (first
&& first
->precision
== 1)
924 printf (" MIN_%s = %smode,\n MAX_%s = %smode,\n\n",
925 mode_class_names
[c
], first
->name
,
926 mode_class_names
[c
], last
->name
);
928 printf (" MIN_%s = %smode,\n MAX_%s = %smode,\n\n",
929 mode_class_names
[c
], void_mode
->name
,
930 mode_class_names
[c
], void_mode
->name
);
934 NUM_MACHINE_MODES = MAX_MACHINE_MODE\n\
937 /* I can't think of a better idea, can you? */
938 printf ("#define CONST_MODE_SIZE%s\n", adj_bytesize
? "" : " const");
939 printf ("#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment
? "" : " const");
940 #if 0 /* disabled for backward compatibility, temporary */
941 printf ("#define CONST_REAL_FORMAT_FOR_MODE%s\n", adj_format
? "" :" const");
943 printf ("#define CONST_MODE_IBIT%s\n", adj_ibit
? "" : " const");
944 printf ("#define CONST_MODE_FBIT%s\n", adj_fbit
? "" : " const");
948 #endif /* insn-modes.h */");
952 emit_insn_modes_c_header (void)
954 printf ("/* Generated automatically from machmode.def%s%s\n",
955 HAVE_EXTRA_MODES
? " and " : "",
961 #include \"config.h\"\n\
962 #include \"system.h\"\n\
963 #include \"coretypes.h\"\n\
965 #include \"machmode.h\"\n\
966 #include \"real.h\"");
970 emit_min_insn_modes_c_header (void)
972 printf ("/* Generated automatically from machmode.def%s%s\n",
973 HAVE_EXTRA_MODES
? " and " : "",
979 #include \"bconfig.h\"\n\
980 #include \"system.h\"\n\
981 #include \"machmode.h\"");
985 emit_mode_name (void)
990 print_decl ("char *const", "mode_name", "NUM_MACHINE_MODES");
993 printf (" \"%s\",\n", m
->name
);
999 emit_mode_class (void)
1002 struct mode_data
*m
;
1004 print_decl ("unsigned char", "mode_class", "NUM_MACHINE_MODES");
1006 for_all_modes (c
, m
)
1007 tagged_printf ("%s", mode_class_names
[m
->cl
], m
->name
);
1013 emit_mode_precision (void)
1016 struct mode_data
*m
;
1018 print_decl ("unsigned short", "mode_precision", "NUM_MACHINE_MODES");
1020 for_all_modes (c
, m
)
1021 if (m
->precision
!= (unsigned int)-1)
1022 tagged_printf ("%u", m
->precision
, m
->name
);
1024 tagged_printf ("%u*BITS_PER_UNIT", m
->bytesize
, m
->name
);
1030 emit_mode_size (void)
1033 struct mode_data
*m
;
1035 print_maybe_const_decl ("%sunsigned char", "mode_size",
1036 "NUM_MACHINE_MODES", bytesize
);
1038 for_all_modes (c
, m
)
1039 tagged_printf ("%u", m
->bytesize
, m
->name
);
1045 emit_mode_nunits (void)
1048 struct mode_data
*m
;
1050 print_decl ("unsigned char", "mode_nunits", "NUM_MACHINE_MODES");
1052 for_all_modes (c
, m
)
1053 tagged_printf ("%u", m
->ncomponents
, m
->name
);
1059 emit_mode_wider (void)
1062 struct mode_data
*m
;
1064 print_decl ("unsigned char", "mode_wider", "NUM_MACHINE_MODES");
1066 for_all_modes (c
, m
)
1067 tagged_printf ("%smode",
1068 m
->wider
? m
->wider
->name
: void_mode
->name
,
1072 print_decl ("unsigned char", "mode_2xwider", "NUM_MACHINE_MODES");
1074 for_all_modes (c
, m
)
1076 struct mode_data
* m2
;
1079 m2
&& m2
!= void_mode
;
1082 if (m2
->bytesize
< 2 * m
->bytesize
)
1084 if (m
->precision
!= (unsigned int) -1)
1086 if (m2
->precision
!= 2 * m
->precision
)
1091 if (m2
->precision
!= (unsigned int) -1)
1095 /* For vectors we want twice the number of components,
1096 with the same element type. */
1097 if (m
->cl
== MODE_VECTOR_INT
1098 || m
->cl
== MODE_VECTOR_FLOAT
1099 || m
->cl
== MODE_VECTOR_FRACT
1100 || m
->cl
== MODE_VECTOR_UFRACT
1101 || m
->cl
== MODE_VECTOR_ACCUM
1102 || m
->cl
== MODE_VECTOR_UACCUM
)
1104 if (m2
->ncomponents
!= 2 * m
->ncomponents
)
1106 if (m
->component
!= m2
->component
)
1112 if (m2
== void_mode
)
1114 tagged_printf ("%smode",
1115 m2
? m2
->name
: void_mode
->name
,
1123 emit_mode_mask (void)
1126 struct mode_data
*m
;
1128 print_decl ("unsigned HOST_WIDE_INT", "mode_mask_array",
1129 "NUM_MACHINE_MODES");
1131 #define MODE_MASK(m) \\\n\
1132 ((m) >= HOST_BITS_PER_WIDE_INT) \\\n\
1133 ? ~(unsigned HOST_WIDE_INT) 0 \\\n\
1134 : ((unsigned HOST_WIDE_INT) 1 << (m)) - 1\n");
1136 for_all_modes (c
, m
)
1137 if (m
->precision
!= (unsigned int)-1)
1138 tagged_printf ("MODE_MASK (%u)", m
->precision
, m
->name
);
1140 tagged_printf ("MODE_MASK (%u*BITS_PER_UNIT)", m
->bytesize
, m
->name
);
1142 puts ("#undef MODE_MASK");
1147 emit_mode_inner (void)
1150 struct mode_data
*m
;
1152 print_decl ("unsigned char", "mode_inner", "NUM_MACHINE_MODES");
1154 for_all_modes (c
, m
)
1155 tagged_printf ("%smode",
1156 c
!= MODE_PARTIAL_INT
&& m
->component
1157 ? m
->component
->name
: void_mode
->name
,
1164 emit_mode_base_align (void)
1167 struct mode_data
*m
;
1169 print_maybe_const_decl ("%sunsigned char",
1170 "mode_base_align", "NUM_MACHINE_MODES",
1173 for_all_modes (c
, m
)
1174 tagged_printf ("%u", m
->alignment
, m
->name
);
1180 emit_class_narrowest_mode (void)
1184 print_decl ("unsigned char", "class_narrowest_mode", "MAX_MODE_CLASS");
1186 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1187 /* Bleah, all this to get the comment right for MIN_MODE_INT. */
1188 tagged_printf ("MIN_%s", mode_class_names
[c
],
1190 ? (modes
[c
]->precision
!= 1
1193 ? modes
[c
]->next
->name
1201 emit_real_format_for_mode (void)
1203 struct mode_data
*m
;
1205 /* The entities pointed to by this table are constant, whether
1206 or not the table itself is constant.
1208 For backward compatibility this table is always writable
1209 (several targets modify it in TARGET_OPTION_OVERRIDE). FIXME:
1210 convert all said targets to use ADJUST_FORMAT instead. */
1212 print_maybe_const_decl ("const struct real_format *%s",
1213 "real_format_for_mode",
1214 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1",
1217 print_decl ("struct real_format *\n", "real_format_for_mode",
1218 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1 "
1219 "+ MAX_MODE_DECIMAL_FLOAT - MIN_MODE_DECIMAL_FLOAT + 1");
1222 /* The beginning of the table is entries for float modes. */
1223 for (m
= modes
[MODE_FLOAT
]; m
; m
= m
->next
)
1224 if (!strcmp (m
->format
, "0"))
1225 tagged_printf ("%s", m
->format
, m
->name
);
1227 tagged_printf ("&%s", m
->format
, m
->name
);
1229 /* The end of the table is entries for decimal float modes. */
1230 for (m
= modes
[MODE_DECIMAL_FLOAT
]; m
; m
= m
->next
)
1231 if (!strcmp (m
->format
, "0"))
1232 tagged_printf ("%s", m
->format
, m
->name
);
1234 tagged_printf ("&%s", m
->format
, m
->name
);
1240 emit_mode_adjustments (void)
1242 struct mode_adjust
*a
;
1243 struct mode_data
*m
;
1247 \ninit_adjust_machine_modes (void)\
1249 \n size_t s ATTRIBUTE_UNUSED;");
1251 /* Size adjustments must be propagated to all containing modes.
1252 A size adjustment forces us to recalculate the alignment too. */
1253 for (a
= adj_bytesize
; a
; a
= a
->next
)
1255 printf ("\n /* %s:%d */\n s = %s;\n",
1256 a
->file
, a
->line
, a
->adjustment
);
1257 printf (" mode_size[%smode] = s;\n", a
->mode
->name
);
1258 printf (" mode_base_align[%smode] = s & (~s + 1);\n",
1261 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1265 case MODE_COMPLEX_INT
:
1266 case MODE_COMPLEX_FLOAT
:
1267 printf (" mode_size[%smode] = 2*s;\n", m
->name
);
1268 printf (" mode_base_align[%smode] = s & (~s + 1);\n",
1272 case MODE_VECTOR_INT
:
1273 case MODE_VECTOR_FLOAT
:
1274 case MODE_VECTOR_FRACT
:
1275 case MODE_VECTOR_UFRACT
:
1276 case MODE_VECTOR_ACCUM
:
1277 case MODE_VECTOR_UACCUM
:
1278 printf (" mode_size[%smode] = %d*s;\n",
1279 m
->name
, m
->ncomponents
);
1280 printf (" mode_base_align[%smode] = (%d*s) & (~(%d*s)+1);\n",
1281 m
->name
, m
->ncomponents
, m
->ncomponents
);
1286 "mode %s is neither vector nor complex but contains %s",
1287 m
->name
, a
->mode
->name
);
1293 /* Alignment adjustments propagate too.
1294 ??? This may not be the right thing for vector modes. */
1295 for (a
= adj_alignment
; a
; a
= a
->next
)
1297 printf ("\n /* %s:%d */\n s = %s;\n",
1298 a
->file
, a
->line
, a
->adjustment
);
1299 printf (" mode_base_align[%smode] = s;\n", a
->mode
->name
);
1301 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1305 case MODE_COMPLEX_INT
:
1306 case MODE_COMPLEX_FLOAT
:
1307 printf (" mode_base_align[%smode] = s;\n", m
->name
);
1310 case MODE_VECTOR_INT
:
1311 case MODE_VECTOR_FLOAT
:
1312 case MODE_VECTOR_FRACT
:
1313 case MODE_VECTOR_UFRACT
:
1314 case MODE_VECTOR_ACCUM
:
1315 case MODE_VECTOR_UACCUM
:
1316 printf (" mode_base_align[%smode] = %d*s;\n",
1317 m
->name
, m
->ncomponents
);
1322 "mode %s is neither vector nor complex but contains %s",
1323 m
->name
, a
->mode
->name
);
1329 /* Ibit adjustments don't have to propagate. */
1330 for (a
= adj_ibit
; a
; a
= a
->next
)
1332 printf ("\n /* %s:%d */\n s = %s;\n",
1333 a
->file
, a
->line
, a
->adjustment
);
1334 printf (" mode_ibit[%smode] = s;\n", a
->mode
->name
);
1337 /* Fbit adjustments don't have to propagate. */
1338 for (a
= adj_fbit
; a
; a
= a
->next
)
1340 printf ("\n /* %s:%d */\n s = %s;\n",
1341 a
->file
, a
->line
, a
->adjustment
);
1342 printf (" mode_fbit[%smode] = s;\n", a
->mode
->name
);
1345 /* Real mode formats don't have to propagate anywhere. */
1346 for (a
= adj_format
; a
; a
= a
->next
)
1347 printf ("\n /* %s:%d */\n REAL_MODE_FORMAT (%smode) = %s;\n",
1348 a
->file
, a
->line
, a
->mode
->name
, a
->adjustment
);
1353 /* Emit ibit for all modes. */
1356 emit_mode_ibit (void)
1359 struct mode_data
*m
;
1361 print_maybe_const_decl ("%sunsigned char",
1362 "mode_ibit", "NUM_MACHINE_MODES",
1365 for_all_modes (c
, m
)
1366 tagged_printf ("%u", m
->ibit
, m
->name
);
1371 /* Emit fbit for all modes. */
1374 emit_mode_fbit (void)
1377 struct mode_data
*m
;
1379 print_maybe_const_decl ("%sunsigned char",
1380 "mode_fbit", "NUM_MACHINE_MODES",
1383 for_all_modes (c
, m
)
1384 tagged_printf ("%u", m
->fbit
, m
->name
);
1391 emit_insn_modes_c (void)
1393 emit_insn_modes_c_header ();
1396 emit_mode_precision ();
1398 emit_mode_nunits ();
1402 emit_mode_base_align ();
1403 emit_class_narrowest_mode ();
1404 emit_real_format_for_mode ();
1405 emit_mode_adjustments ();
1411 emit_min_insn_modes_c (void)
1413 emit_min_insn_modes_c_header ();
1417 emit_class_narrowest_mode ();
1420 /* Master control. */
1422 main (int argc
, char **argv
)
1424 bool gen_header
= false, gen_min
= false;
1429 else if (argc
== 2 && !strcmp (argv
[1], "-h"))
1431 else if (argc
== 2 && !strcmp (argv
[1], "-m"))
1435 error ("usage: %s [-h|-m] > file", progname
);
1436 return FATAL_EXIT_CODE
;
1439 modes_by_name
= htab_create_alloc (64, hash_mode
, eq_mode
, 0, xcalloc
, free
);
1442 complete_all_modes ();
1445 return FATAL_EXIT_CODE
;
1450 emit_insn_modes_h ();
1452 emit_min_insn_modes_c ();
1454 emit_insn_modes_c ();
1456 if (fflush (stdout
) || fclose (stdout
))
1457 return FATAL_EXIT_CODE
;
1458 return SUCCESS_EXIT_CODE
;