1 /* Generate the machine mode enumeration and associated tables.
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, 59 Temple Place - Suite 330, 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
class; /* 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 - MODE_FLOAT only */
65 struct mode_data
*component
; /* mode of components */
66 struct mode_data
*wider
; /* next 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 */
76 static struct mode_data
*modes
[MAX_MODE_CLASS
];
77 static unsigned int n_modes
[MAX_MODE_CLASS
];
78 static struct mode_data
*void_mode
;
80 static const struct mode_data blank_mode
= {
81 0, "<unknown>", MAX_MODE_CLASS
,
87 static htab_t modes_by_name
;
89 /* Data structure for recording target-specified runtime adjustments
90 to a particular mode. We support varying the byte size, the
91 alignment, and the floating point format. */
94 struct mode_adjust
*next
;
95 struct mode_data
*mode
;
96 const char *adjustment
;
102 static struct mode_adjust
*adj_bytesize
;
103 static struct mode_adjust
*adj_alignment
;
104 static struct mode_adjust
*adj_format
;
106 /* Mode class operations. */
107 static enum mode_class
108 complex_class (enum mode_class
class)
112 case MODE_INT
: return MODE_COMPLEX_INT
;
113 case MODE_FLOAT
: return MODE_COMPLEX_FLOAT
;
115 error ("no complex class for class %s", mode_class_names
[class]);
120 static enum mode_class
121 vector_class (enum mode_class
class)
125 case MODE_INT
: return MODE_VECTOR_INT
;
126 case MODE_FLOAT
: return MODE_VECTOR_FLOAT
;
128 error ("no vector class for class %s", mode_class_names
[class]);
133 /* Utility routines. */
134 static inline struct mode_data
*
135 find_mode (const char *name
)
137 struct mode_data key
;
140 return htab_find (modes_by_name
, &key
);
143 static struct mode_data
*
144 new_mode (enum mode_class
class, const char *name
,
145 const char *file
, unsigned int line
)
149 m
= find_mode (name
);
152 error ("%s:%d: duplicate definition of mode \"%s\"",
153 trim_filename (file
), line
, name
);
154 error ("%s:%d: previous definition here", m
->file
, m
->line
);
158 m
= xmalloc (sizeof (struct mode_data
));
159 memcpy (m
, &blank_mode
, sizeof (struct mode_data
));
163 m
->file
= trim_filename (file
);
166 m
->next
= modes
[class];
170 *htab_find_slot (modes_by_name
, m
, INSERT
) = m
;
176 hash_mode (const void *p
)
178 const struct mode_data
*m
= (const struct mode_data
*)p
;
179 return htab_hash_string (m
->name
);
183 eq_mode (const void *p
, const void *q
)
185 const struct mode_data
*a
= (const struct mode_data
*)p
;
186 const struct mode_data
*b
= (const struct mode_data
*)q
;
188 return !strcmp (a
->name
, b
->name
);
191 #define for_all_modes(C, M) \
192 for (C = 0; C < MAX_MODE_CLASS; C++) \
193 for (M = modes[C]; M; M = M->next)
195 static void ATTRIBUTE_UNUSED
196 new_adjust (const char *name
,
197 struct mode_adjust
**category
, const char *catname
,
198 const char *adjustment
,
199 enum mode_class required_class
,
200 const char *file
, unsigned int line
)
202 struct mode_data
*mode
= find_mode (name
);
203 struct mode_adjust
*a
;
205 file
= trim_filename (file
);
209 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
213 if (required_class
!= MODE_RANDOM
&& mode
->class != required_class
)
215 error ("%s:%d: mode \"%s\" is not class %s",
216 file
, line
, name
, mode_class_names
[required_class
] + 5);
220 for (a
= *category
; a
; a
= a
->next
)
223 error ("%s:%d: mode \"%s\" already has a %s adjustment",
224 file
, line
, name
, catname
);
225 error ("%s:%d: previous adjustment here", a
->file
, a
->line
);
229 a
= xmalloc (sizeof (struct mode_adjust
));
231 a
->adjustment
= adjustment
;
239 /* Diagnose failure to meet expectations in a partially filled out
241 enum requirement
{ SET
, UNSET
, OPTIONAL
};
243 #define validate_field_(mname, fname, req, val, unset, file, line) do { \
248 error ("%s:%d: (%s) field %s must be set", \
249 file, line, mname, fname); \
253 error ("%s:%d: (%s) field %s must not be set", \
254 file, line, mname, fname); \
260 #define validate_field(M, F) \
261 validate_field_(M->name, #F, r_##F, M->F, blank_mode.F, M->file, M->line)
264 validate_mode (struct mode_data
*m
,
265 enum requirement r_precision
,
266 enum requirement r_bytesize
,
267 enum requirement r_component
,
268 enum requirement r_ncomponents
,
269 enum requirement r_format
)
271 validate_field (m
, precision
);
272 validate_field (m
, bytesize
);
273 validate_field (m
, component
);
274 validate_field (m
, ncomponents
);
275 validate_field (m
, format
);
277 #undef validate_field
278 #undef validate_field_
280 /* Given a partially-filled-out mode structure, figure out what we can
281 and fill the rest of it in; die if it isn't enough. */
283 complete_mode (struct mode_data
*m
)
285 unsigned int alignment
;
289 error ("%s:%d: mode with no name", m
->file
, m
->line
);
292 if (m
->class == MAX_MODE_CLASS
)
294 error ("%s:%d: %smode has no mode class", m
->file
, m
->line
, m
->name
);
301 /* Nothing more need be said. */
302 if (!strcmp (m
->name
, "VOID"))
305 validate_mode (m
, UNSET
, UNSET
, UNSET
, UNSET
, UNSET
);
314 /* Again, nothing more need be said. For historical reasons,
315 the size of a CC mode is four units. */
316 validate_mode (m
, UNSET
, UNSET
, UNSET
, UNSET
, UNSET
);
325 /* A scalar mode must have a byte size, may have a bit size,
326 and must not have components. A float mode must have a
328 validate_mode (m
, OPTIONAL
, SET
, UNSET
, UNSET
,
329 m
->class == MODE_FLOAT
? SET
: UNSET
);
335 case MODE_PARTIAL_INT
:
336 /* A partial integer mode uses ->component to say what the
337 corresponding full-size integer mode is, and may also
338 specify a bit size. */
339 validate_mode (m
, OPTIONAL
, UNSET
, SET
, UNSET
, UNSET
);
341 m
->bytesize
= m
->component
->bytesize
;
344 m
->component
= 0; /* ??? preserve this */
347 case MODE_COMPLEX_INT
:
348 case MODE_COMPLEX_FLOAT
:
349 /* Complex modes should have a component indicated, but no more. */
350 validate_mode (m
, UNSET
, UNSET
, SET
, UNSET
, UNSET
);
352 if (m
->component
->precision
!= (unsigned int)-1)
353 m
->precision
= 2 * m
->component
->precision
;
354 m
->bytesize
= 2 * m
->component
->bytesize
;
357 case MODE_VECTOR_INT
:
358 case MODE_VECTOR_FLOAT
:
359 /* Vector modes should have a component and a number of components. */
360 validate_mode (m
, UNSET
, UNSET
, SET
, SET
, UNSET
);
361 if (m
->component
->precision
!= (unsigned int)-1)
362 m
->precision
= m
->ncomponents
* m
->component
->precision
;
363 m
->bytesize
= m
->ncomponents
* m
->component
->bytesize
;
370 /* If not already specified, the mode alignment defaults to the largest
371 power of two that divides the size of the object. Complex types are
372 not more aligned than their contents. */
373 if (m
->class == MODE_COMPLEX_INT
|| m
->class == MODE_COMPLEX_FLOAT
)
374 alignment
= m
->component
->bytesize
;
376 alignment
= m
->bytesize
;
378 m
->alignment
= alignment
& (~alignment
+ 1);
380 /* If this mode has components, make the component mode point back
381 to this mode, for the sake of adjustments. */
384 m
->next_cont
= m
->component
->contained
;
385 m
->component
->contained
= m
;
390 complete_all_modes (void)
399 /* For each mode in class CLASS, construct a corresponding complex mode. */
400 #define COMPLEX_MODES(C) make_complex_modes(MODE_##C, __FILE__, __LINE__)
402 make_complex_modes (enum mode_class
class,
403 const char *file
, unsigned int line
)
408 enum mode_class cclass
= complex_class (class);
410 if (cclass
== MODE_RANDOM
)
413 for (m
= modes
[class]; m
; m
= m
->next
)
415 /* Skip BImode. FIXME: BImode probably shouldn't be MODE_INT. */
416 if (m
->precision
== 1)
419 if (strlen (m
->name
) >= sizeof buf
)
421 error ("%s:%d:mode name \"%s\" is too long",
422 m
->file
, m
->line
, m
->name
);
426 /* Float complex modes are named SCmode, etc.
427 Int complex modes are named CSImode, etc.
428 This inconsistency should be eliminated. */
429 if (class == MODE_FLOAT
)
432 strncpy (buf
, m
->name
, sizeof buf
);
433 p
= strchr (buf
, 'F');
436 error ("%s:%d: float mode \"%s\" has no 'F'",
437 m
->file
, m
->line
, m
->name
);
444 snprintf (buf
, sizeof buf
, "C%s", m
->name
);
446 c
= new_mode (cclass
, xstrdup (buf
), file
, line
);
451 /* For all modes in class CLASS, construct vector modes of width
452 WIDTH, having as many components as necessary. */
453 #define VECTOR_MODES(C, W) make_vector_modes(MODE_##C, W, __FILE__, __LINE__)
455 make_vector_modes (enum mode_class
class, unsigned int width
,
456 const char *file
, unsigned int line
)
461 unsigned int ncomponents
;
462 enum mode_class vclass
= vector_class (class);
464 if (vclass
== MODE_RANDOM
)
467 for (m
= modes
[class]; m
; m
= m
->next
)
469 /* Do not construct vector modes with only one element, or
470 vector modes where the element size doesn't divide the full
472 ncomponents
= width
/ m
->bytesize
;
475 if (width
% m
->bytesize
)
478 /* Skip QFmode and BImode. FIXME: this special case should
480 if (class == MODE_FLOAT
&& m
->bytesize
== 1)
482 if (class == MODE_INT
&& m
->precision
== 1)
485 if ((size_t)snprintf (buf
, sizeof buf
, "V%u%s", ncomponents
, m
->name
)
488 error ("%s:%d: mode name \"%s\" is too long",
489 m
->file
, m
->line
, m
->name
);
493 v
= new_mode (vclass
, xstrdup (buf
), file
, line
);
495 v
->ncomponents
= ncomponents
;
501 #define _SPECIAL_MODE(C, N) make_special_mode(MODE_##C, #N, __FILE__, __LINE__)
502 #define RANDOM_MODE(N) _SPECIAL_MODE (RANDOM, N)
503 #define CC_MODE(N) _SPECIAL_MODE (CC, N)
506 make_special_mode (enum mode_class
class, const char *name
,
507 const char *file
, unsigned int line
)
509 new_mode (class, name
, file
, line
);
512 #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1, Y)
513 #define FRACTIONAL_INT_MODE(N, B, Y) \
514 make_int_mode (#N, B, Y, __FILE__, __LINE__)
517 make_int_mode (const char *name
,
518 unsigned int precision
, unsigned int bytesize
,
519 const char *file
, unsigned int line
)
521 struct mode_data
*m
= new_mode (MODE_INT
, name
, file
, line
);
522 m
->bytesize
= bytesize
;
523 m
->precision
= precision
;
526 #define FLOAT_MODE(N, Y, F) FRACTIONAL_FLOAT_MODE (N, -1, Y, F)
527 #define FRACTIONAL_FLOAT_MODE(N, B, Y, F) \
528 make_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
531 make_float_mode (const char *name
,
532 unsigned int precision
, unsigned int bytesize
,
534 const char *file
, unsigned int line
)
536 struct mode_data
*m
= new_mode (MODE_FLOAT
, name
, file
, line
);
537 m
->bytesize
= bytesize
;
538 m
->precision
= precision
;
542 #define RESET_FLOAT_FORMAT(N, F) \
543 reset_float_format (#N, #F, __FILE__, __LINE__)
544 static void ATTRIBUTE_UNUSED
545 reset_float_format (const char *name
, const char *format
,
546 const char *file
, unsigned int line
)
548 struct mode_data
*m
= find_mode (name
);
551 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
554 if (m
->class != MODE_FLOAT
)
556 error ("%s:%d: mode \"%s\" is not class FLOAT", file
, line
, name
);
562 /* Partial integer modes are specified by relation to a full integer mode.
563 For now, we do not attempt to narrow down their bit sizes. */
564 #define PARTIAL_INT_MODE(M) \
565 make_partial_integer_mode (#M, "P" #M, -1, __FILE__, __LINE__)
566 static void ATTRIBUTE_UNUSED
567 make_partial_integer_mode (const char *base
, const char *name
,
568 unsigned int precision
,
569 const char *file
, unsigned int line
)
572 struct mode_data
*component
= find_mode (base
);
575 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
578 if (component
->class != MODE_INT
)
580 error ("%s:%d: mode \"%s\" is not class INT", file
, line
, name
);
584 m
= new_mode (MODE_PARTIAL_INT
, name
, file
, line
);
585 m
->precision
= precision
;
586 m
->component
= component
;
589 /* A single vector mode can be specified by naming its component
590 mode and the number of components. */
591 #define VECTOR_MODE(C, M, N) \
592 make_vector_mode (MODE_##C, #M, N, __FILE__, __LINE__);
593 static void ATTRIBUTE_UNUSED
594 make_vector_mode (enum mode_class bclass
,
596 unsigned int ncomponents
,
597 const char *file
, unsigned int line
)
600 enum mode_class vclass
= vector_class (bclass
);
601 struct mode_data
*component
= find_mode (base
);
604 if (vclass
== MODE_RANDOM
)
608 error ("%s:%d: no mode \"%s\"", file
, line
, base
);
611 if (component
->class != bclass
)
613 error ("%s:%d: mode \"%s\" is not class %s",
614 file
, line
, base
, mode_class_names
[bclass
] + 5);
618 if ((size_t)snprintf (namebuf
, sizeof namebuf
, "V%u%s",
619 ncomponents
, base
) >= sizeof namebuf
)
621 error ("%s:%d: mode name \"%s\" is too long",
626 v
= new_mode (vclass
, xstrdup (namebuf
), file
, line
);
627 v
->ncomponents
= ncomponents
;
628 v
->component
= component
;
632 #define _ADD_ADJUST(A, M, X, C) \
633 new_adjust (#M, &adj_##A, #A, #X, MODE_##C, __FILE__, __LINE__)
635 #define ADJUST_BYTESIZE(M, X) _ADD_ADJUST(bytesize, M, X, RANDOM)
636 #define ADJUST_ALIGNMENT(M, X) _ADD_ADJUST(alignment, M, X, RANDOM)
637 #define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST(format, M, X, FLOAT)
642 #include "machmode.def"
647 /* Sort a list of modes into the order needed for the WIDER field:
648 major sort by precision, minor sort by component precision.
651 QI < HI < SI < DI < TI
652 V4QI < V2HI < V8QI < V4HI < V2SI.
654 If the precision is not set, sort by the bytesize. A mode with
655 precision set gets sorted before a mode without precision set, if
656 they have the same bytesize; this is the right thing because
657 the precision must always be smaller than the bytesize * BITS_PER_UNIT.
658 We don't have to do anything special to get this done -- an unset
659 precision shows up as (unsigned int)-1, i.e. UINT_MAX. */
661 cmp_modes (const void *a
, const void *b
)
663 struct mode_data
*m
= *(struct mode_data
**)a
;
664 struct mode_data
*n
= *(struct mode_data
**)b
;
666 if (m
->bytesize
> n
->bytesize
)
668 else if (m
->bytesize
< n
->bytesize
)
671 if (m
->precision
> n
->precision
)
673 else if (m
->precision
< n
->precision
)
676 if (!m
->component
&& !n
->component
)
679 if (m
->component
->bytesize
> n
->component
->bytesize
)
681 else if (m
->component
->bytesize
< n
->component
->bytesize
)
684 if (m
->component
->precision
> n
->component
->precision
)
686 else if (m
->component
->precision
< n
->component
->precision
)
693 calc_wider_mode (void)
697 struct mode_data
**sortbuf
;
698 unsigned int max_n_modes
= 0;
701 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
702 max_n_modes
= MAX (max_n_modes
, n_modes
[c
]);
704 /* Allocate max_n_modes + 1 entries to leave room for the extra null
705 pointer assigned after the qsort call below. */
706 sortbuf
= alloca ((max_n_modes
+ 1) * sizeof (struct mode_data
*));
708 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
710 /* "wider" is not meaningful for MODE_RANDOM and MODE_CC.
711 However, we want these in textual order, and we have
712 precisely the reverse. */
713 if (c
== MODE_RANDOM
|| c
== MODE_CC
)
715 struct mode_data
*prev
, *next
;
717 for (prev
= 0, m
= modes
[c
]; m
; m
= next
)
719 m
->wider
= void_mode
;
721 /* this is nreverse */
733 for (i
= 0, m
= modes
[c
]; m
; i
++, m
= m
->next
)
736 qsort (sortbuf
, i
, sizeof (struct mode_data
*), cmp_modes
);
739 for (j
= 0; j
< i
; j
++)
740 sortbuf
[j
]->next
= sortbuf
[j
]->wider
= sortbuf
[j
+ 1];
743 modes
[c
] = sortbuf
[0];
748 /* Output routines. */
750 #define tagged_printf(FMT, ARG, TAG) do { \
752 printf (" " FMT ",%n", ARG, &count_); \
753 printf ("%*s/* %s */\n", 27 - count_, "", TAG); \
756 #define print_decl(TYPE, NAME, ASIZE) \
757 puts ("\nconst " TYPE " " NAME "[" ASIZE "] =\n{");
759 #define print_maybe_const_decl(TYPE, NAME, ASIZE, CATEGORY) \
760 printf ("\n" TYPE " " NAME "[" ASIZE "] = \n{\n", \
761 adj_##CATEGORY ? "" : "const ")
763 #define print_closer() puts ("};")
766 emit_insn_modes_h (void)
769 struct mode_data
*m
, *first
, *last
;
771 printf ("/* Generated automatically from machmode.def%s%s\n",
772 HAVE_EXTRA_MODES
? " and " : "",
778 #ifndef GCC_INSN_MODES_H\n\
779 #define GCC_INSN_MODES_H\n\
781 enum machine_mode\n{");
783 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
784 for (m
= modes
[c
]; m
; m
= m
->next
)
787 printf (" %smode,%n", m
->name
, &count_
);
788 printf ("%*s/* %s:%d */\n", 27 - count_
, "",
789 trim_filename (m
->file
), m
->line
);
792 puts (" MAX_MACHINE_MODE,\n");
794 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
798 for (m
= first
; m
; last
= m
, m
= m
->next
)
801 /* Don't use BImode for MIN_MODE_INT, since otherwise the middle
802 end will try to use it for bitfields in structures and the
803 like, which we do not want. Only the target md file should
804 generate BImode widgets. */
805 if (first
&& first
->precision
== 1)
809 printf (" MIN_%s = %smode,\n MAX_%s = %smode,\n\n",
810 mode_class_names
[c
], first
->name
,
811 mode_class_names
[c
], last
->name
);
813 printf (" MIN_%s = %smode,\n MAX_%s = %smode,\n\n",
814 mode_class_names
[c
], void_mode
->name
,
815 mode_class_names
[c
], void_mode
->name
);
819 NUM_MACHINE_MODES = MAX_MACHINE_MODE\n\
822 /* I can't think of a better idea, can you? */
823 printf ("#define CONST_MODE_SIZE%s\n", adj_bytesize
? "" : " const");
824 printf ("#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment
? "" : " const");
825 #if 0 /* disabled for backward compatibility, temporary */
826 printf ("#define CONST_REAL_FORMAT_FOR_MODE%s\n", adj_format
? "" :" const");
830 #endif /* insn-modes.h */");
834 emit_insn_modes_c_header (void)
836 printf ("/* Generated automatically from machmode.def%s%s\n",
837 HAVE_EXTRA_MODES
? " and " : "",
843 #include \"config.h\"\n\
844 #include \"system.h\"\n\
845 #include \"coretypes.h\"\n\
847 #include \"machmode.h\"\n\
848 #include \"real.h\"");
852 emit_min_insn_modes_c_header (void)
854 printf ("/* Generated automatically from machmode.def%s%s\n",
855 HAVE_EXTRA_MODES
? " and " : "",
861 #include \"bconfig.h\"\n\
862 #include \"system.h\"\n\
863 #include \"machmode.h\"");
867 emit_mode_name (void)
872 print_decl ("char *const", "mode_name", "NUM_MACHINE_MODES");
875 printf (" \"%s\",\n", m
->name
);
881 emit_mode_class (void)
886 print_decl ("unsigned char", "mode_class", "NUM_MACHINE_MODES");
889 tagged_printf ("%s", mode_class_names
[m
->class], m
->name
);
895 emit_mode_precision (void)
900 print_decl ("unsigned short", "mode_precision", "NUM_MACHINE_MODES");
903 if (m
->precision
!= (unsigned int)-1)
904 tagged_printf ("%u", m
->precision
, m
->name
);
906 tagged_printf ("%u*BITS_PER_UNIT", m
->bytesize
, m
->name
);
912 emit_mode_size (void)
917 print_maybe_const_decl ("%sunsigned char", "mode_size",
918 "NUM_MACHINE_MODES", bytesize
);
921 tagged_printf ("%u", m
->bytesize
, m
->name
);
927 emit_mode_nunits (void)
932 print_decl ("unsigned char", "mode_nunits", "NUM_MACHINE_MODES");
935 tagged_printf ("%u", m
->ncomponents
, m
->name
);
941 emit_mode_wider (void)
946 print_decl ("unsigned char", "mode_wider", "NUM_MACHINE_MODES");
949 tagged_printf ("%smode",
950 m
->wider
? m
->wider
->name
: void_mode
->name
,
957 emit_mode_mask (void)
962 print_decl ("unsigned HOST_WIDE_INT", "mode_mask_array",
963 "NUM_MACHINE_MODES");
965 #define MODE_MASK(m) \\\n\
966 ((m) >= HOST_BITS_PER_WIDE_INT) \\\n\
967 ? ~(unsigned HOST_WIDE_INT) 0 \\\n\
968 : ((unsigned HOST_WIDE_INT) 1 << (m)) - 1\n");
971 if (m
->precision
!= (unsigned int)-1)
972 tagged_printf ("MODE_MASK (%u)", m
->precision
, m
->name
);
974 tagged_printf ("MODE_MASK (%u*BITS_PER_UNIT)", m
->bytesize
, m
->name
);
976 puts ("#undef MODE_MASK");
981 emit_mode_inner (void)
986 print_decl ("unsigned char", "mode_inner", "NUM_MACHINE_MODES");
989 tagged_printf ("%smode",
990 m
->component
? m
->component
->name
: void_mode
->name
,
997 emit_mode_base_align (void)
1000 struct mode_data
*m
;
1002 print_maybe_const_decl ("%sunsigned char",
1003 "mode_base_align", "NUM_MACHINE_MODES",
1006 for_all_modes (c
, m
)
1007 tagged_printf ("%u", m
->alignment
, m
->name
);
1013 emit_class_narrowest_mode (void)
1017 print_decl ("unsigned char", "class_narrowest_mode", "MAX_MODE_CLASS");
1019 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1020 /* Bleah, all this to get the comment right for MIN_MODE_INT. */
1021 tagged_printf ("MIN_%s", mode_class_names
[c
],
1023 ? (modes
[c
]->precision
!= 1
1026 ? modes
[c
]->next
->name
1034 emit_real_format_for_mode (void)
1036 struct mode_data
*m
;
1038 /* The entities pointed to by this table are constant, whether
1039 or not the table itself is constant.
1041 For backward compatibility this table is always writable
1042 (several targets modify it in OVERRIDE_OPTIONS). FIXME:
1043 convert all said targets to use ADJUST_FORMAT instead. */
1045 print_maybe_const_decl ("const struct real_format *%s",
1046 "real_format_for_mode",
1047 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1",
1050 print_decl ("struct real_format *\n", "real_format_for_mode",
1051 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1");
1054 for (m
= modes
[MODE_FLOAT
]; m
; m
= m
->next
)
1055 if (!strcmp (m
->format
, "0"))
1056 tagged_printf ("%s", m
->format
, m
->name
);
1058 tagged_printf ("&%s", m
->format
, m
->name
);
1064 emit_mode_adjustments (void)
1066 struct mode_adjust
*a
;
1067 struct mode_data
*m
;
1071 \ninit_adjust_machine_modes (void)\
1073 \n size_t s ATTRIBUTE_UNUSED;");
1075 /* Size adjustments must be propagated to all containing modes.
1076 A size adjustment forces us to recalculate the alignment too. */
1077 for (a
= adj_bytesize
; a
; a
= a
->next
)
1079 printf ("\n /* %s:%d */\n s = %s;\n",
1080 a
->file
, a
->line
, a
->adjustment
);
1081 printf (" mode_size[%smode] = s;\n", a
->mode
->name
);
1082 printf (" mode_base_align[%smode] = s & (~s + 1);\n",
1085 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1089 case MODE_COMPLEX_INT
:
1090 case MODE_COMPLEX_FLOAT
:
1091 printf (" mode_size[%smode] = 2*s;\n", m
->name
);
1092 printf (" mode_base_align[%smode] = s & (~s + 1);\n",
1096 case MODE_VECTOR_INT
:
1097 case MODE_VECTOR_FLOAT
:
1098 printf (" mode_size[%smode] = %d*s;\n",
1099 m
->name
, m
->ncomponents
);
1100 printf (" mode_base_align[%smode] = (%d*s) & (~(%d*s)+1);\n",
1101 m
->name
, m
->ncomponents
, m
->ncomponents
);
1106 "mode %s is neither vector nor complex but contains %s",
1107 m
->name
, a
->mode
->name
);
1113 /* Alignment adjustments propagate too.
1114 ??? This may not be the right thing for vector modes. */
1115 for (a
= adj_alignment
; a
; a
= a
->next
)
1117 printf ("\n /* %s:%d */\n s = %s;\n",
1118 a
->file
, a
->line
, a
->adjustment
);
1119 printf (" mode_base_align[%smode] = s;\n", a
->mode
->name
);
1121 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1125 case MODE_COMPLEX_INT
:
1126 case MODE_COMPLEX_FLOAT
:
1127 printf (" mode_base_align[%smode] = s;\n", m
->name
);
1130 case MODE_VECTOR_INT
:
1131 case MODE_VECTOR_FLOAT
:
1132 printf (" mode_base_align[%smode] = %d*s;\n",
1133 m
->name
, m
->ncomponents
);
1138 "mode %s is neither vector nor complex but contains %s",
1139 m
->name
, a
->mode
->name
);
1145 /* Real mode formats don't have to propagate anywhere. */
1146 for (a
= adj_format
; a
; a
= a
->next
)
1147 printf ("\n /* %s:%d */\n REAL_MODE_FORMAT (%smode) = %s;\n",
1148 a
->file
, a
->line
, a
->mode
->name
, a
->adjustment
);
1154 emit_insn_modes_c (void)
1156 emit_insn_modes_c_header ();
1159 emit_mode_precision ();
1161 emit_mode_nunits ();
1165 emit_mode_base_align ();
1166 emit_class_narrowest_mode ();
1167 emit_real_format_for_mode ();
1168 emit_mode_adjustments ();
1172 emit_min_insn_modes_c (void)
1174 emit_min_insn_modes_c_header ();
1178 emit_class_narrowest_mode ();
1181 /* Master control. */
1183 main(int argc
, char **argv
)
1185 bool gen_header
= false, gen_min
= false;
1190 else if (argc
== 2 && !strcmp (argv
[1], "-h"))
1192 else if (argc
== 2 && !strcmp (argv
[1], "-m"))
1196 error ("usage: %s [-h|-m] > file", progname
);
1197 return FATAL_EXIT_CODE
;
1200 modes_by_name
= htab_create_alloc (64, hash_mode
, eq_mode
, 0, xcalloc
, free
);
1203 complete_all_modes ();
1206 return FATAL_EXIT_CODE
;
1211 emit_insn_modes_h ();
1213 emit_min_insn_modes_c ();
1215 emit_insn_modes_c ();
1217 if (fflush (stdout
) || fclose (stdout
))
1218 return FATAL_EXIT_CODE
;
1219 return SUCCESS_EXIT_CODE
;