1 /* Generate the machine mode enumeration and associated tables.
2 Copyright (C) 2003-2015 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 */
75 bool need_bytesize_adj
; /* true if this mode need dynamic size
77 unsigned int int_n
; /* If nonzero, then __int<INT_N> will be defined */
80 static struct mode_data
*modes
[MAX_MODE_CLASS
];
81 static unsigned int n_modes
[MAX_MODE_CLASS
];
82 static struct mode_data
*void_mode
;
84 static const struct mode_data blank_mode
= {
85 0, "<unknown>", MAX_MODE_CLASS
,
88 "<unknown>", 0, 0, 0, 0, false, 0
91 static htab_t modes_by_name
;
93 /* Data structure for recording target-specified runtime adjustments
94 to a particular mode. We support varying the byte size, the
95 alignment, and the floating point format. */
98 struct mode_adjust
*next
;
99 struct mode_data
*mode
;
100 const char *adjustment
;
106 static struct mode_adjust
*adj_bytesize
;
107 static struct mode_adjust
*adj_alignment
;
108 static struct mode_adjust
*adj_format
;
109 static struct mode_adjust
*adj_ibit
;
110 static struct mode_adjust
*adj_fbit
;
112 /* Mode class operations. */
113 static enum mode_class
114 complex_class (enum mode_class c
)
118 case MODE_INT
: return MODE_COMPLEX_INT
;
119 case MODE_FLOAT
: return MODE_COMPLEX_FLOAT
;
121 error ("no complex class for class %s", mode_class_names
[c
]);
126 static enum mode_class
127 vector_class (enum mode_class cl
)
131 case MODE_INT
: return MODE_VECTOR_INT
;
132 case MODE_FLOAT
: return MODE_VECTOR_FLOAT
;
133 case MODE_FRACT
: return MODE_VECTOR_FRACT
;
134 case MODE_UFRACT
: return MODE_VECTOR_UFRACT
;
135 case MODE_ACCUM
: return MODE_VECTOR_ACCUM
;
136 case MODE_UACCUM
: return MODE_VECTOR_UACCUM
;
138 error ("no vector class for class %s", mode_class_names
[cl
]);
143 /* Utility routines. */
144 static inline struct mode_data
*
145 find_mode (const char *name
)
147 struct mode_data key
;
150 return (struct mode_data
*) htab_find (modes_by_name
, &key
);
153 static struct mode_data
*
154 new_mode (enum mode_class cl
, const char *name
,
155 const char *file
, unsigned int line
)
158 static unsigned int count
= 0;
160 m
= find_mode (name
);
163 error ("%s:%d: duplicate definition of mode \"%s\"",
164 trim_filename (file
), line
, name
);
165 error ("%s:%d: previous definition here", m
->file
, m
->line
);
169 m
= XNEW (struct mode_data
);
170 memcpy (m
, &blank_mode
, sizeof (struct mode_data
));
174 m
->file
= trim_filename (file
);
176 m
->counter
= count
++;
182 *htab_find_slot (modes_by_name
, m
, INSERT
) = m
;
188 hash_mode (const void *p
)
190 const struct mode_data
*m
= (const struct mode_data
*)p
;
191 return htab_hash_string (m
->name
);
195 eq_mode (const void *p
, const void *q
)
197 const struct mode_data
*a
= (const struct mode_data
*)p
;
198 const struct mode_data
*b
= (const struct mode_data
*)q
;
200 return !strcmp (a
->name
, b
->name
);
203 #define for_all_modes(C, M) \
204 for (C = 0; C < MAX_MODE_CLASS; C++) \
205 for (M = modes[C]; M; M = M->next)
207 static void ATTRIBUTE_UNUSED
208 new_adjust (const char *name
,
209 struct mode_adjust
**category
, const char *catname
,
210 const char *adjustment
,
211 enum mode_class required_class_from
,
212 enum mode_class required_class_to
,
213 const char *file
, unsigned int line
)
215 struct mode_data
*mode
= find_mode (name
);
216 struct mode_adjust
*a
;
218 file
= trim_filename (file
);
222 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
226 if (required_class_from
!= MODE_RANDOM
227 && (mode
->cl
< required_class_from
|| mode
->cl
> required_class_to
))
229 error ("%s:%d: mode \"%s\" is not among class {%s, %s}",
230 file
, line
, name
, mode_class_names
[required_class_from
] + 5,
231 mode_class_names
[required_class_to
] + 5);
235 for (a
= *category
; a
; a
= a
->next
)
238 error ("%s:%d: mode \"%s\" already has a %s adjustment",
239 file
, line
, name
, catname
);
240 error ("%s:%d: previous adjustment here", a
->file
, a
->line
);
244 a
= XNEW (struct mode_adjust
);
246 a
->adjustment
= adjustment
;
254 /* Diagnose failure to meet expectations in a partially filled out
256 enum requirement
{ SET
, UNSET
, OPTIONAL
};
258 #define validate_field_(mname, fname, req, val, unset, file, line) do { \
263 error ("%s:%d: (%s) field %s must be set", \
264 file, line, mname, fname); \
268 error ("%s:%d: (%s) field %s must not be set", \
269 file, line, mname, fname); \
275 #define validate_field(M, F) \
276 validate_field_(M->name, #F, r_##F, M->F, blank_mode.F, M->file, M->line)
279 validate_mode (struct mode_data
*m
,
280 enum requirement r_precision
,
281 enum requirement r_bytesize
,
282 enum requirement r_component
,
283 enum requirement r_ncomponents
,
284 enum requirement r_format
)
286 validate_field (m
, precision
);
287 validate_field (m
, bytesize
);
288 validate_field (m
, component
);
289 validate_field (m
, ncomponents
);
290 validate_field (m
, format
);
292 #undef validate_field
293 #undef validate_field_
295 /* Given a partially-filled-out mode structure, figure out what we can
296 and fill the rest of it in; die if it isn't enough. */
298 complete_mode (struct mode_data
*m
)
300 unsigned int alignment
;
304 error ("%s:%d: mode with no name", m
->file
, m
->line
);
307 if (m
->cl
== MAX_MODE_CLASS
)
309 error ("%s:%d: %smode has no mode class", m
->file
, m
->line
, m
->name
);
316 /* Nothing more need be said. */
317 if (!strcmp (m
->name
, "VOID"))
320 validate_mode (m
, UNSET
, UNSET
, UNSET
, UNSET
, UNSET
);
329 /* Again, nothing more need be said. For historical reasons,
330 the size of a CC mode is four units. */
331 validate_mode (m
, UNSET
, UNSET
, UNSET
, UNSET
, UNSET
);
339 case MODE_POINTER_BOUNDS
:
341 case MODE_DECIMAL_FLOAT
:
346 /* A scalar mode must have a byte size, may have a bit size,
347 and must not have components. A float mode must have a
349 validate_mode (m
, OPTIONAL
, SET
, UNSET
, UNSET
,
350 (m
->cl
== MODE_FLOAT
|| m
->cl
== MODE_DECIMAL_FLOAT
)
357 case MODE_PARTIAL_INT
:
358 /* A partial integer mode uses ->component to say what the
359 corresponding full-size integer mode is, and may also
360 specify a bit size. */
361 validate_mode (m
, OPTIONAL
, UNSET
, SET
, UNSET
, UNSET
);
363 m
->bytesize
= m
->component
->bytesize
;
368 case MODE_COMPLEX_INT
:
369 case MODE_COMPLEX_FLOAT
:
370 /* Complex modes should have a component indicated, but no more. */
371 validate_mode (m
, UNSET
, UNSET
, SET
, UNSET
, UNSET
);
373 if (m
->component
->precision
!= (unsigned int)-1)
374 m
->precision
= 2 * m
->component
->precision
;
375 m
->bytesize
= 2 * m
->component
->bytesize
;
378 case MODE_VECTOR_INT
:
379 case MODE_VECTOR_FLOAT
:
380 case MODE_VECTOR_FRACT
:
381 case MODE_VECTOR_UFRACT
:
382 case MODE_VECTOR_ACCUM
:
383 case MODE_VECTOR_UACCUM
:
384 /* Vector modes should have a component and a number of components. */
385 validate_mode (m
, UNSET
, UNSET
, SET
, SET
, UNSET
);
386 if (m
->component
->precision
!= (unsigned int)-1)
387 m
->precision
= m
->ncomponents
* m
->component
->precision
;
388 m
->bytesize
= m
->ncomponents
* m
->component
->bytesize
;
395 /* If not already specified, the mode alignment defaults to the largest
396 power of two that divides the size of the object. Complex types are
397 not more aligned than their contents. */
398 if (m
->cl
== MODE_COMPLEX_INT
|| m
->cl
== MODE_COMPLEX_FLOAT
)
399 alignment
= m
->component
->bytesize
;
401 alignment
= m
->bytesize
;
403 m
->alignment
= alignment
& (~alignment
+ 1);
405 /* If this mode has components, make the component mode point back
406 to this mode, for the sake of adjustments. */
409 m
->next_cont
= m
->component
->contained
;
410 m
->component
->contained
= m
;
415 complete_all_modes (void)
420 for_all_modes (cl
, m
)
424 /* For each mode in class CLASS, construct a corresponding complex mode. */
425 #define COMPLEX_MODES(C) make_complex_modes (MODE_##C, __FILE__, __LINE__)
427 make_complex_modes (enum mode_class cl
,
428 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
)
442 /* Skip BImode. FIXME: BImode probably shouldn't be MODE_INT. */
443 if (m
->precision
== 1)
446 m_len
= strlen (m
->name
);
447 /* The leading "1 +" is in case we prepend a "C" below. */
448 buf
= (char *) xmalloc (1 + m_len
+ 1);
450 /* Float complex modes are named SCmode, etc.
451 Int complex modes are named CSImode, etc.
452 This inconsistency should be eliminated. */
454 if (cl
== MODE_FLOAT
)
456 memcpy (buf
, m
->name
, m_len
+ 1);
457 p
= strchr (buf
, 'F');
458 if (p
== 0 && strchr (buf
, 'D') == 0)
460 error ("%s:%d: float mode \"%s\" has no 'F' or 'D'",
461 m
->file
, m
->line
, m
->name
);
471 memcpy (buf
+ 1, m
->name
, m_len
+ 1);
474 c
= new_mode (cclass
, buf
, file
, line
);
479 /* For all modes in class CL, construct vector modes of width
480 WIDTH, having as many components as necessary. */
481 #define VECTOR_MODES(C, W) make_vector_modes (MODE_##C, W, __FILE__, __LINE__)
482 static void ATTRIBUTE_UNUSED
483 make_vector_modes (enum mode_class cl
, unsigned int width
,
484 const char *file
, unsigned int line
)
489 unsigned int ncomponents
;
490 enum mode_class vclass
= vector_class (cl
);
492 if (vclass
== MODE_RANDOM
)
495 for (m
= modes
[cl
]; m
; m
= m
->next
)
497 /* Do not construct vector modes with only one element, or
498 vector modes where the element size doesn't divide the full
500 ncomponents
= width
/ m
->bytesize
;
503 if (width
% m
->bytesize
)
506 /* Skip QFmode and BImode. FIXME: this special case should
508 if (cl
== MODE_FLOAT
&& m
->bytesize
== 1)
510 if (cl
== MODE_INT
&& m
->precision
== 1)
513 if ((size_t)snprintf (buf
, sizeof buf
, "V%u%s", ncomponents
, m
->name
)
516 error ("%s:%d: mode name \"%s\" is too long",
517 m
->file
, m
->line
, m
->name
);
521 v
= new_mode (vclass
, xstrdup (buf
), file
, line
);
523 v
->ncomponents
= ncomponents
;
529 #define _SPECIAL_MODE(C, N) \
530 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 POINTER_BOUNDS_MODE(N, Y) \
542 make_pointer_bounds_mode (#N, Y, __FILE__, __LINE__)
544 static void ATTRIBUTE_UNUSED
545 make_pointer_bounds_mode (const char *name
,
546 unsigned int bytesize
,
547 const char *file
, unsigned int line
)
549 struct mode_data
*m
= new_mode (MODE_POINTER_BOUNDS
, name
, file
, line
);
550 m
->bytesize
= bytesize
;
554 #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y)
555 #define FRACTIONAL_INT_MODE(N, B, Y) \
556 make_int_mode (#N, B, Y, __FILE__, __LINE__)
559 make_int_mode (const char *name
,
560 unsigned int precision
, unsigned int bytesize
,
561 const char *file
, unsigned int line
)
563 struct mode_data
*m
= new_mode (MODE_INT
, name
, file
, line
);
564 m
->bytesize
= bytesize
;
565 m
->precision
= precision
;
568 #define FRACT_MODE(N, Y, F) \
569 make_fixed_point_mode (MODE_FRACT, #N, Y, 0, F, __FILE__, __LINE__)
571 #define UFRACT_MODE(N, Y, F) \
572 make_fixed_point_mode (MODE_UFRACT, #N, Y, 0, F, __FILE__, __LINE__)
574 #define ACCUM_MODE(N, Y, I, F) \
575 make_fixed_point_mode (MODE_ACCUM, #N, Y, I, F, __FILE__, __LINE__)
577 #define UACCUM_MODE(N, Y, I, F) \
578 make_fixed_point_mode (MODE_UACCUM, #N, Y, I, F, __FILE__, __LINE__)
580 /* Create a fixed-point mode by setting CL, NAME, BYTESIZE, IBIT, FBIT,
584 make_fixed_point_mode (enum mode_class cl
,
586 unsigned int bytesize
,
589 const char *file
, unsigned int line
)
591 struct mode_data
*m
= new_mode (cl
, name
, file
, line
);
592 m
->bytesize
= bytesize
;
597 #define FLOAT_MODE(N, Y, F) FRACTIONAL_FLOAT_MODE (N, -1U, Y, F)
598 #define FRACTIONAL_FLOAT_MODE(N, B, Y, F) \
599 make_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
602 make_float_mode (const char *name
,
603 unsigned int precision
, unsigned int bytesize
,
605 const char *file
, unsigned int line
)
607 struct mode_data
*m
= new_mode (MODE_FLOAT
, name
, file
, line
);
608 m
->bytesize
= bytesize
;
609 m
->precision
= precision
;
613 #define DECIMAL_FLOAT_MODE(N, Y, F) \
614 FRACTIONAL_DECIMAL_FLOAT_MODE (N, -1U, Y, F)
615 #define FRACTIONAL_DECIMAL_FLOAT_MODE(N, B, Y, F) \
616 make_decimal_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
619 make_decimal_float_mode (const char *name
,
620 unsigned int precision
, unsigned int bytesize
,
622 const char *file
, unsigned int line
)
624 struct mode_data
*m
= new_mode (MODE_DECIMAL_FLOAT
, name
, file
, line
);
625 m
->bytesize
= bytesize
;
626 m
->precision
= precision
;
630 #define RESET_FLOAT_FORMAT(N, F) \
631 reset_float_format (#N, #F, __FILE__, __LINE__)
632 static void ATTRIBUTE_UNUSED
633 reset_float_format (const char *name
, const char *format
,
634 const char *file
, unsigned int line
)
636 struct mode_data
*m
= find_mode (name
);
639 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
642 if (m
->cl
!= MODE_FLOAT
&& m
->cl
!= MODE_DECIMAL_FLOAT
)
644 error ("%s:%d: mode \"%s\" is not a FLOAT class", file
, line
, name
);
650 /* __intN support. */
651 #define INT_N(M,PREC) \
652 make_int_n (#M, PREC, __FILE__, __LINE__)
653 static void ATTRIBUTE_UNUSED
654 make_int_n (const char *m
, int bitsize
,
655 const char *file
, unsigned int line
)
657 struct mode_data
*component
= find_mode (m
);
660 error ("%s:%d: no mode \"%s\"", file
, line
, m
);
663 if (component
->cl
!= MODE_INT
664 && component
->cl
!= MODE_PARTIAL_INT
)
666 error ("%s:%d: mode \"%s\" is not class INT or PARTIAL_INT", file
, line
, m
);
669 if (component
->int_n
!= 0)
671 error ("%s:%d: mode \"%s\" already has an intN", file
, line
, m
);
675 component
->int_n
= bitsize
;
678 /* Partial integer modes are specified by relation to a full integer
680 #define PARTIAL_INT_MODE(M,PREC,NAME) \
681 make_partial_integer_mode (#M, #NAME, PREC, __FILE__, __LINE__)
682 static void ATTRIBUTE_UNUSED
683 make_partial_integer_mode (const char *base
, const char *name
,
684 unsigned int precision
,
685 const char *file
, unsigned int line
)
688 struct mode_data
*component
= find_mode (base
);
691 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
694 if (component
->cl
!= MODE_INT
)
696 error ("%s:%d: mode \"%s\" is not class INT", file
, line
, name
);
700 m
= new_mode (MODE_PARTIAL_INT
, name
, file
, line
);
701 m
->precision
= precision
;
702 m
->component
= component
;
705 /* A single vector mode can be specified by naming its component
706 mode and the number of components. */
707 #define VECTOR_MODE(C, M, N) \
708 make_vector_mode (MODE_##C, #M, N, __FILE__, __LINE__);
709 static void ATTRIBUTE_UNUSED
710 make_vector_mode (enum mode_class bclass
,
712 unsigned int ncomponents
,
713 const char *file
, unsigned int line
)
716 enum mode_class vclass
= vector_class (bclass
);
717 struct mode_data
*component
= find_mode (base
);
720 if (vclass
== MODE_RANDOM
)
724 error ("%s:%d: no mode \"%s\"", file
, line
, base
);
727 if (component
->cl
!= bclass
728 && (component
->cl
!= MODE_PARTIAL_INT
729 || bclass
!= MODE_INT
))
731 error ("%s:%d: mode \"%s\" is not class %s",
732 file
, line
, base
, mode_class_names
[bclass
] + 5);
736 if ((size_t)snprintf (namebuf
, sizeof namebuf
, "V%u%s",
737 ncomponents
, base
) >= sizeof namebuf
)
739 error ("%s:%d: mode name \"%s\" is too long",
744 v
= new_mode (vclass
, xstrdup (namebuf
), file
, line
);
745 v
->ncomponents
= ncomponents
;
746 v
->component
= component
;
750 #define _ADD_ADJUST(A, M, X, C1, C2) \
751 new_adjust (#M, &adj_##A, #A, #X, MODE_##C1, MODE_##C2, __FILE__, __LINE__)
753 #define ADJUST_BYTESIZE(M, X) _ADD_ADJUST (bytesize, M, X, RANDOM, RANDOM)
754 #define ADJUST_ALIGNMENT(M, X) _ADD_ADJUST (alignment, M, X, RANDOM, RANDOM)
755 #define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST (format, M, X, FLOAT, FLOAT)
756 #define ADJUST_IBIT(M, X) _ADD_ADJUST (ibit, M, X, ACCUM, UACCUM)
757 #define ADJUST_FBIT(M, X) _ADD_ADJUST (fbit, M, X, FRACT, UACCUM)
759 static int bits_per_unit
;
760 static int max_bitsize_mode_any_int
;
765 #include "machmode.def"
767 /* So put the default value unless the target needs a non standard
770 bits_per_unit
= BITS_PER_UNIT
;
775 #ifdef MAX_BITSIZE_MODE_ANY_INT
776 max_bitsize_mode_any_int
= MAX_BITSIZE_MODE_ANY_INT
;
778 max_bitsize_mode_any_int
= 0;
784 /* Sort a list of modes into the order needed for the WIDER field:
785 major sort by precision, minor sort by component precision.
788 QI < HI < SI < DI < TI
789 V4QI < V2HI < V8QI < V4HI < V2SI.
791 If the precision is not set, sort by the bytesize. A mode with
792 precision set gets sorted before a mode without precision set, if
793 they have the same bytesize; this is the right thing because
794 the precision must always be smaller than the bytesize * BITS_PER_UNIT.
795 We don't have to do anything special to get this done -- an unset
796 precision shows up as (unsigned int)-1, i.e. UINT_MAX. */
798 cmp_modes (const void *a
, const void *b
)
800 const struct mode_data
*const m
= *(const struct mode_data
*const*)a
;
801 const struct mode_data
*const n
= *(const struct mode_data
*const*)b
;
803 if (m
->bytesize
> n
->bytesize
)
805 else if (m
->bytesize
< n
->bytesize
)
808 if (m
->precision
> n
->precision
)
810 else if (m
->precision
< n
->precision
)
813 if (!m
->component
&& !n
->component
)
815 if (m
->counter
< n
->counter
)
821 if (m
->component
->bytesize
> n
->component
->bytesize
)
823 else if (m
->component
->bytesize
< n
->component
->bytesize
)
826 if (m
->component
->precision
> n
->component
->precision
)
828 else if (m
->component
->precision
< n
->component
->precision
)
831 if (m
->counter
< n
->counter
)
838 calc_wider_mode (void)
842 struct mode_data
**sortbuf
;
843 unsigned int max_n_modes
= 0;
846 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
847 max_n_modes
= MAX (max_n_modes
, n_modes
[c
]);
849 /* Allocate max_n_modes + 1 entries to leave room for the extra null
850 pointer assigned after the qsort call below. */
851 sortbuf
= XALLOCAVEC (struct mode_data
*, max_n_modes
+ 1);
853 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
855 /* "wider" is not meaningful for MODE_RANDOM and MODE_CC.
856 However, we want these in textual order, and we have
857 precisely the reverse. */
858 if (c
== MODE_RANDOM
|| c
== MODE_CC
)
860 struct mode_data
*prev
, *next
;
862 for (prev
= 0, m
= modes
[c
]; m
; m
= next
)
864 m
->wider
= void_mode
;
866 /* this is nreverse */
878 for (i
= 0, m
= modes
[c
]; m
; i
++, m
= m
->next
)
881 qsort (sortbuf
, i
, sizeof (struct mode_data
*), cmp_modes
);
884 for (j
= 0; j
< i
; j
++)
886 sortbuf
[j
]->next
= sortbuf
[j
+ 1];
887 if (c
== MODE_PARTIAL_INT
)
888 sortbuf
[j
]->wider
= sortbuf
[j
]->component
;
890 sortbuf
[j
]->wider
= sortbuf
[j
]->next
;
893 modes
[c
] = sortbuf
[0];
898 /* Output routines. */
900 #define tagged_printf(FMT, ARG, TAG) do { \
901 int count_ = printf (" " FMT ",", ARG); \
902 printf ("%*s/* %s */\n", 27 - count_, "", TAG); \
905 #define print_decl(TYPE, NAME, ASIZE) \
906 puts ("\nconst " TYPE " " NAME "[" ASIZE "] =\n{");
908 #define print_maybe_const_decl(TYPE, NAME, ASIZE, CATEGORY) \
909 printf ("\n" TYPE " " NAME "[" ASIZE "] = \n{\n", \
910 adj_##CATEGORY ? "" : "const ")
912 #define print_closer() puts ("};")
914 /* Compute the max bitsize of some of the classes of integers. It may
915 be that there are needs for the other integer classes, and this
916 code is easy to extend. */
920 unsigned int max
, mmax
;
926 printf ("#define BITS_PER_UNIT (%d)\n", bits_per_unit
);
928 if (max_bitsize_mode_any_int
== 0)
930 for (max
= 1, i
= modes
[MODE_INT
]; i
; i
= i
->next
)
931 if (max
< i
->bytesize
)
934 for (max
= 1, i
= modes
[MODE_PARTIAL_INT
]; i
; i
= i
->next
)
935 if (max
< i
->bytesize
)
939 printf ("#define MAX_BITSIZE_MODE_ANY_INT (%d*BITS_PER_UNIT)\n", mmax
);
942 printf ("#define MAX_BITSIZE_MODE_ANY_INT %d\n", max_bitsize_mode_any_int
);
945 for (j
= 0; j
< MAX_MODE_CLASS
; j
++)
946 for (i
= modes
[j
]; i
; i
= i
->next
)
947 if (mmax
< i
->bytesize
)
949 printf ("#define MAX_BITSIZE_MODE_ANY_MODE (%d*BITS_PER_UNIT)\n", mmax
);
952 /* Emit mode_size_inline routine into insn-modes.h header. */
954 emit_mode_size_inline (void)
957 struct mode_adjust
*a
;
960 /* Size adjustments must be propagated to all containing modes. */
961 for (a
= adj_bytesize
; a
; a
= a
->next
)
963 a
->mode
->need_bytesize_adj
= true;
964 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
965 m
->need_bytesize_adj
= true;
969 #ifdef __cplusplus\n\
970 inline __attribute__((__always_inline__))\n\
972 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
975 mode_size_inline (machine_mode mode)\n\
977 extern %sunsigned char mode_size[NUM_MACHINE_MODES];\n\
979 {\n", adj_bytesize
? "" : "const ");
982 if (!m
->need_bytesize_adj
)
983 printf (" case %smode: return %u;\n", m
->name
, m
->bytesize
);
986 default: return mode_size[mode];\n\
991 /* Emit mode_nunits_inline routine into insn-modes.h header. */
993 emit_mode_nunits_inline (void)
999 #ifdef __cplusplus\n\
1000 inline __attribute__((__always_inline__))\n\
1002 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1005 mode_nunits_inline (machine_mode mode)\n\
1007 extern const unsigned char mode_nunits[NUM_MACHINE_MODES];\n\
1011 for_all_modes (c
, m
)
1012 printf (" case %smode: return %u;\n", m
->name
, m
->ncomponents
);
1015 default: return mode_nunits[mode];\n\
1020 /* Emit mode_inner_inline routine into insn-modes.h header. */
1022 emit_mode_inner_inline (void)
1025 struct mode_data
*m
;
1028 #ifdef __cplusplus\n\
1029 inline __attribute__((__always_inline__))\n\
1031 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1034 mode_inner_inline (machine_mode mode)\n\
1036 extern const unsigned char mode_inner[NUM_MACHINE_MODES];\n\
1040 for_all_modes (c
, m
)
1041 printf (" case %smode: return %smode;\n", m
->name
,
1042 c
!= MODE_PARTIAL_INT
&& m
->component
1043 ? m
->component
->name
: void_mode
->name
);
1046 default: return mode_inner[mode];\n\
1052 emit_insn_modes_h (void)
1055 struct mode_data
*m
, *first
, *last
;
1056 int n_int_n_ents
= 0;
1058 printf ("/* Generated automatically from machmode.def%s%s\n",
1059 HAVE_EXTRA_MODES
? " and " : "",
1065 #ifndef GCC_INSN_MODES_H\n\
1066 #define GCC_INSN_MODES_H\n\
1068 enum machine_mode\n{");
1070 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1071 for (m
= modes
[c
]; m
; m
= m
->next
)
1073 int count_
= printf (" %smode,", m
->name
);
1074 printf ("%*s/* %s:%d */\n", 27 - count_
, "",
1075 trim_filename (m
->file
), m
->line
);
1076 printf ("#define HAVE_%smode\n", m
->name
);
1079 puts (" MAX_MACHINE_MODE,\n");
1081 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1085 for (m
= first
; m
; last
= m
, m
= m
->next
)
1088 /* Don't use BImode for MIN_MODE_INT, since otherwise the middle
1089 end will try to use it for bitfields in structures and the
1090 like, which we do not want. Only the target md file should
1091 generate BImode widgets. */
1092 if (first
&& first
->precision
== 1 && c
== MODE_INT
)
1093 first
= first
->next
;
1096 printf (" MIN_%s = %smode,\n MAX_%s = %smode,\n\n",
1097 mode_class_names
[c
], first
->name
,
1098 mode_class_names
[c
], last
->name
);
1100 printf (" MIN_%s = %smode,\n MAX_%s = %smode,\n\n",
1101 mode_class_names
[c
], void_mode
->name
,
1102 mode_class_names
[c
], void_mode
->name
);
1106 NUM_MACHINE_MODES = MAX_MACHINE_MODE\n\
1109 /* I can't think of a better idea, can you? */
1110 printf ("#define CONST_MODE_SIZE%s\n", adj_bytesize
? "" : " const");
1111 printf ("#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment
? "" : " const");
1112 #if 0 /* disabled for backward compatibility, temporary */
1113 printf ("#define CONST_REAL_FORMAT_FOR_MODE%s\n", adj_format
? "" :" const");
1115 printf ("#define CONST_MODE_IBIT%s\n", adj_ibit
? "" : " const");
1116 printf ("#define CONST_MODE_FBIT%s\n", adj_fbit
? "" : " const");
1119 for_all_modes (c
, m
)
1123 printf ("#define NUM_INT_N_ENTS %d\n", n_int_n_ents
);
1125 puts ("\n#if !defined (USED_FOR_TARGET) && GCC_VERSION >= 4001\n");
1126 emit_mode_size_inline ();
1127 emit_mode_nunits_inline ();
1128 emit_mode_inner_inline ();
1129 puts ("#endif /* GCC_VERSION >= 4001 */");
1133 #endif /* insn-modes.h */");
1137 emit_insn_modes_c_header (void)
1139 printf ("/* Generated automatically from machmode.def%s%s\n",
1140 HAVE_EXTRA_MODES
? " and " : "",
1146 #include \"config.h\"\n\
1147 #include \"system.h\"\n\
1148 #include \"coretypes.h\"\n\
1149 #include \"tm.h\"\n\
1150 #include \"machmode.h\"\n\
1151 #include \"real.h\"");
1155 emit_min_insn_modes_c_header (void)
1157 printf ("/* Generated automatically from machmode.def%s%s\n",
1158 HAVE_EXTRA_MODES
? " and " : "",
1164 #include \"bconfig.h\"\n\
1165 #include \"system.h\"\n\
1166 #include \"machmode.h\"");
1170 emit_mode_name (void)
1173 struct mode_data
*m
;
1175 print_decl ("char *const", "mode_name", "NUM_MACHINE_MODES");
1177 for_all_modes (c
, m
)
1178 printf (" \"%s\",\n", m
->name
);
1184 emit_mode_class (void)
1187 struct mode_data
*m
;
1189 print_decl ("unsigned char", "mode_class", "NUM_MACHINE_MODES");
1191 for_all_modes (c
, m
)
1192 tagged_printf ("%s", mode_class_names
[m
->cl
], m
->name
);
1198 emit_mode_precision (void)
1201 struct mode_data
*m
;
1203 print_decl ("unsigned short", "mode_precision", "NUM_MACHINE_MODES");
1205 for_all_modes (c
, m
)
1206 if (m
->precision
!= (unsigned int)-1)
1207 tagged_printf ("%u", m
->precision
, m
->name
);
1209 tagged_printf ("%u*BITS_PER_UNIT", m
->bytesize
, m
->name
);
1215 emit_mode_size (void)
1218 struct mode_data
*m
;
1220 print_maybe_const_decl ("%sunsigned char", "mode_size",
1221 "NUM_MACHINE_MODES", bytesize
);
1223 for_all_modes (c
, m
)
1224 tagged_printf ("%u", m
->bytesize
, m
->name
);
1230 emit_mode_nunits (void)
1233 struct mode_data
*m
;
1235 print_decl ("unsigned char", "mode_nunits", "NUM_MACHINE_MODES");
1237 for_all_modes (c
, m
)
1238 tagged_printf ("%u", m
->ncomponents
, m
->name
);
1244 emit_mode_wider (void)
1247 struct mode_data
*m
;
1249 print_decl ("unsigned char", "mode_wider", "NUM_MACHINE_MODES");
1251 for_all_modes (c
, m
)
1252 tagged_printf ("%smode",
1253 m
->wider
? m
->wider
->name
: void_mode
->name
,
1257 print_decl ("unsigned char", "mode_2xwider", "NUM_MACHINE_MODES");
1259 for_all_modes (c
, m
)
1261 struct mode_data
* m2
;
1264 m2
&& m2
!= void_mode
;
1267 if (m2
->bytesize
< 2 * m
->bytesize
)
1269 if (m
->precision
!= (unsigned int) -1)
1271 if (m2
->precision
!= 2 * m
->precision
)
1276 if (m2
->precision
!= (unsigned int) -1)
1280 /* For vectors we want twice the number of components,
1281 with the same element type. */
1282 if (m
->cl
== MODE_VECTOR_INT
1283 || m
->cl
== MODE_VECTOR_FLOAT
1284 || m
->cl
== MODE_VECTOR_FRACT
1285 || m
->cl
== MODE_VECTOR_UFRACT
1286 || m
->cl
== MODE_VECTOR_ACCUM
1287 || m
->cl
== MODE_VECTOR_UACCUM
)
1289 if (m2
->ncomponents
!= 2 * m
->ncomponents
)
1291 if (m
->component
!= m2
->component
)
1297 if (m2
== void_mode
)
1299 tagged_printf ("%smode",
1300 m2
? m2
->name
: void_mode
->name
,
1308 emit_mode_mask (void)
1311 struct mode_data
*m
;
1313 print_decl ("unsigned HOST_WIDE_INT", "mode_mask_array",
1314 "NUM_MACHINE_MODES");
1316 #define MODE_MASK(m) \\\n\
1317 ((m) >= HOST_BITS_PER_WIDE_INT) \\\n\
1318 ? ~(unsigned HOST_WIDE_INT) 0 \\\n\
1319 : ((unsigned HOST_WIDE_INT) 1 << (m)) - 1\n");
1321 for_all_modes (c
, m
)
1322 if (m
->precision
!= (unsigned int)-1)
1323 tagged_printf ("MODE_MASK (%u)", m
->precision
, m
->name
);
1325 tagged_printf ("MODE_MASK (%u*BITS_PER_UNIT)", m
->bytesize
, m
->name
);
1327 puts ("#undef MODE_MASK");
1332 emit_mode_inner (void)
1335 struct mode_data
*m
;
1337 print_decl ("unsigned char", "mode_inner", "NUM_MACHINE_MODES");
1339 for_all_modes (c
, m
)
1340 tagged_printf ("%smode",
1341 c
!= MODE_PARTIAL_INT
&& m
->component
1342 ? m
->component
->name
: void_mode
->name
,
1349 emit_mode_base_align (void)
1352 struct mode_data
*m
;
1354 print_maybe_const_decl ("%sunsigned char",
1355 "mode_base_align", "NUM_MACHINE_MODES",
1358 for_all_modes (c
, m
)
1359 tagged_printf ("%u", m
->alignment
, m
->name
);
1365 emit_class_narrowest_mode (void)
1369 print_decl ("unsigned char", "class_narrowest_mode", "MAX_MODE_CLASS");
1371 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1372 /* Bleah, all this to get the comment right for MIN_MODE_INT. */
1373 tagged_printf ("MIN_%s", mode_class_names
[c
],
1375 ? ((c
!= MODE_INT
|| modes
[c
]->precision
!= 1)
1378 ? modes
[c
]->next
->name
1386 emit_real_format_for_mode (void)
1388 struct mode_data
*m
;
1390 /* The entities pointed to by this table are constant, whether
1391 or not the table itself is constant.
1393 For backward compatibility this table is always writable
1394 (several targets modify it in TARGET_OPTION_OVERRIDE). FIXME:
1395 convert all said targets to use ADJUST_FORMAT instead. */
1397 print_maybe_const_decl ("const struct real_format *%s",
1398 "real_format_for_mode",
1399 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1",
1402 print_decl ("struct real_format *\n", "real_format_for_mode",
1403 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1 "
1404 "+ MAX_MODE_DECIMAL_FLOAT - MIN_MODE_DECIMAL_FLOAT + 1");
1407 /* The beginning of the table is entries for float modes. */
1408 for (m
= modes
[MODE_FLOAT
]; m
; m
= m
->next
)
1409 if (!strcmp (m
->format
, "0"))
1410 tagged_printf ("%s", m
->format
, m
->name
);
1412 tagged_printf ("&%s", m
->format
, m
->name
);
1414 /* The end of the table is entries for decimal float modes. */
1415 for (m
= modes
[MODE_DECIMAL_FLOAT
]; m
; m
= m
->next
)
1416 if (!strcmp (m
->format
, "0"))
1417 tagged_printf ("%s", m
->format
, m
->name
);
1419 tagged_printf ("&%s", m
->format
, m
->name
);
1425 emit_mode_adjustments (void)
1427 struct mode_adjust
*a
;
1428 struct mode_data
*m
;
1432 \ninit_adjust_machine_modes (void)\
1434 \n size_t s ATTRIBUTE_UNUSED;");
1436 /* Size adjustments must be propagated to all containing modes.
1437 A size adjustment forces us to recalculate the alignment too. */
1438 for (a
= adj_bytesize
; a
; a
= a
->next
)
1440 printf ("\n /* %s:%d */\n s = %s;\n",
1441 a
->file
, a
->line
, a
->adjustment
);
1442 printf (" mode_size[%smode] = s;\n", a
->mode
->name
);
1443 printf (" mode_base_align[%smode] = s & (~s + 1);\n",
1446 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1450 case MODE_COMPLEX_INT
:
1451 case MODE_COMPLEX_FLOAT
:
1452 printf (" mode_size[%smode] = 2*s;\n", m
->name
);
1453 printf (" mode_base_align[%smode] = s & (~s + 1);\n",
1457 case MODE_VECTOR_INT
:
1458 case MODE_VECTOR_FLOAT
:
1459 case MODE_VECTOR_FRACT
:
1460 case MODE_VECTOR_UFRACT
:
1461 case MODE_VECTOR_ACCUM
:
1462 case MODE_VECTOR_UACCUM
:
1463 printf (" mode_size[%smode] = %d*s;\n",
1464 m
->name
, m
->ncomponents
);
1465 printf (" mode_base_align[%smode] = (%d*s) & (~(%d*s)+1);\n",
1466 m
->name
, m
->ncomponents
, m
->ncomponents
);
1471 "mode %s is neither vector nor complex but contains %s",
1472 m
->name
, a
->mode
->name
);
1478 /* Alignment adjustments propagate too.
1479 ??? This may not be the right thing for vector modes. */
1480 for (a
= adj_alignment
; a
; a
= a
->next
)
1482 printf ("\n /* %s:%d */\n s = %s;\n",
1483 a
->file
, a
->line
, a
->adjustment
);
1484 printf (" mode_base_align[%smode] = s;\n", a
->mode
->name
);
1486 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1490 case MODE_COMPLEX_INT
:
1491 case MODE_COMPLEX_FLOAT
:
1492 printf (" mode_base_align[%smode] = s;\n", m
->name
);
1495 case MODE_VECTOR_INT
:
1496 case MODE_VECTOR_FLOAT
:
1497 case MODE_VECTOR_FRACT
:
1498 case MODE_VECTOR_UFRACT
:
1499 case MODE_VECTOR_ACCUM
:
1500 case MODE_VECTOR_UACCUM
:
1501 printf (" mode_base_align[%smode] = %d*s;\n",
1502 m
->name
, m
->ncomponents
);
1507 "mode %s is neither vector nor complex but contains %s",
1508 m
->name
, a
->mode
->name
);
1514 /* Ibit adjustments don't have to propagate. */
1515 for (a
= adj_ibit
; a
; a
= a
->next
)
1517 printf ("\n /* %s:%d */\n s = %s;\n",
1518 a
->file
, a
->line
, a
->adjustment
);
1519 printf (" mode_ibit[%smode] = s;\n", a
->mode
->name
);
1522 /* Fbit adjustments don't have to propagate. */
1523 for (a
= adj_fbit
; a
; a
= a
->next
)
1525 printf ("\n /* %s:%d */\n s = %s;\n",
1526 a
->file
, a
->line
, a
->adjustment
);
1527 printf (" mode_fbit[%smode] = s;\n", a
->mode
->name
);
1530 /* Real mode formats don't have to propagate anywhere. */
1531 for (a
= adj_format
; a
; a
= a
->next
)
1532 printf ("\n /* %s:%d */\n REAL_MODE_FORMAT (%smode) = %s;\n",
1533 a
->file
, a
->line
, a
->mode
->name
, a
->adjustment
);
1538 /* Emit ibit for all modes. */
1541 emit_mode_ibit (void)
1544 struct mode_data
*m
;
1546 print_maybe_const_decl ("%sunsigned char",
1547 "mode_ibit", "NUM_MACHINE_MODES",
1550 for_all_modes (c
, m
)
1551 tagged_printf ("%u", m
->ibit
, m
->name
);
1556 /* Emit fbit for all modes. */
1559 emit_mode_fbit (void)
1562 struct mode_data
*m
;
1564 print_maybe_const_decl ("%sunsigned char",
1565 "mode_fbit", "NUM_MACHINE_MODES",
1568 for_all_modes (c
, m
)
1569 tagged_printf ("%u", m
->fbit
, m
->name
);
1574 /* Emit __intN for all modes. */
1577 emit_mode_int_n (void)
1580 struct mode_data
*m
;
1581 struct mode_data
**mode_sort
;
1585 print_decl ("int_n_data_t", "int_n_data", "");
1588 for_all_modes (c
, m
)
1591 mode_sort
= XALLOCAVEC (struct mode_data
*, n_modes
);
1594 for_all_modes (c
, m
)
1596 mode_sort
[n_modes
++] = m
;
1598 /* Yes, this is a bubblesort, but there are at most four (and
1599 usually only 1-2) entries to sort. */
1600 for (i
= 0; i
<n_modes
- 1; i
++)
1601 for (j
= i
+ 1; j
< n_modes
; j
++)
1602 if (mode_sort
[i
]->int_n
> mode_sort
[j
]->int_n
)
1603 std::swap (mode_sort
[i
], mode_sort
[j
]);
1605 for (i
= 0; i
< n_modes
; i
++)
1609 tagged_printf ("%u", m
->int_n
, m
->name
);
1610 printf ("%smode,", m
->name
);
1619 emit_insn_modes_c (void)
1621 emit_insn_modes_c_header ();
1624 emit_mode_precision ();
1626 emit_mode_nunits ();
1630 emit_mode_base_align ();
1631 emit_class_narrowest_mode ();
1632 emit_real_format_for_mode ();
1633 emit_mode_adjustments ();
1640 emit_min_insn_modes_c (void)
1642 emit_min_insn_modes_c_header ();
1646 emit_class_narrowest_mode ();
1649 /* Master control. */
1651 main (int argc
, char **argv
)
1653 bool gen_header
= false, gen_min
= false;
1658 else if (argc
== 2 && !strcmp (argv
[1], "-h"))
1660 else if (argc
== 2 && !strcmp (argv
[1], "-m"))
1664 error ("usage: %s [-h|-m] > file", progname
);
1665 return FATAL_EXIT_CODE
;
1668 modes_by_name
= htab_create_alloc (64, hash_mode
, eq_mode
, 0, xcalloc
, free
);
1671 complete_all_modes ();
1674 return FATAL_EXIT_CODE
;
1679 emit_insn_modes_h ();
1681 emit_min_insn_modes_c ();
1683 emit_insn_modes_c ();
1685 if (fflush (stdout
) || fclose (stdout
))
1686 return FATAL_EXIT_CODE
;
1687 return SUCCESS_EXIT_CODE
;