1 /* Generate the machine mode enumeration and associated tables.
2 Copyright (C) 2003-2020 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/>. */
24 /* enum mode_class is normally defined by machmode.h but we can't
25 include that header here. */
26 #include "mode-classes.def"
28 #define DEF_MODE_CLASS(M) M
29 enum mode_class
{ MODE_CLASSES
, MAX_MODE_CLASS
};
32 /* Text names of mode classes, for output. */
33 #define DEF_MODE_CLASS(M) #M
34 static const char *const mode_class_names
[MAX_MODE_CLASS
] =
41 #ifdef EXTRA_MODES_FILE
42 # define HAVE_EXTRA_MODES 1
44 # define HAVE_EXTRA_MODES 0
45 # define EXTRA_MODES_FILE ""
48 /* Data structure for building up what we know about a mode.
49 They're clustered by mode class. */
52 struct mode_data
*next
; /* next this class - arbitrary order */
54 const char *name
; /* printable mode name -- SI, not SImode */
55 enum mode_class cl
; /* this mode class */
56 unsigned int order
; /* top-level sorting order */
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 struct mode_data
*complex; /* complex type with mode as component. */
71 const char *file
; /* file and line of definition, */
72 unsigned int line
; /* for error reporting */
73 unsigned int counter
; /* Rank ordering of modes */
74 unsigned int ibit
; /* the number of integral bits */
75 unsigned int fbit
; /* the number of fractional bits */
76 bool need_nunits_adj
; /* true if this mode needs dynamic nunits
78 bool need_bytesize_adj
; /* true if this mode needs dynamic size
80 unsigned int int_n
; /* If nonzero, then __int<INT_N> will be defined */
83 static struct mode_data
*modes
[MAX_MODE_CLASS
];
84 static unsigned int n_modes
[MAX_MODE_CLASS
];
85 static struct mode_data
*void_mode
;
87 static const struct mode_data blank_mode
= {
88 0, "<unknown>", MAX_MODE_CLASS
,
89 0, -1U, -1U, -1U, -1U,
91 "<unknown>", 0, 0, 0, 0, false, false, 0
94 static htab_t modes_by_name
;
96 /* Data structure for recording target-specified runtime adjustments
97 to a particular mode. We support varying the byte size, the
98 alignment, and the floating point format. */
101 struct mode_adjust
*next
;
102 struct mode_data
*mode
;
103 const char *adjustment
;
109 static struct mode_adjust
*adj_nunits
;
110 static struct mode_adjust
*adj_bytesize
;
111 static struct mode_adjust
*adj_alignment
;
112 static struct mode_adjust
*adj_format
;
113 static struct mode_adjust
*adj_ibit
;
114 static struct mode_adjust
*adj_fbit
;
116 /* Mode class operations. */
117 static enum mode_class
118 complex_class (enum mode_class c
)
122 case MODE_INT
: return MODE_COMPLEX_INT
;
123 case MODE_PARTIAL_INT
: return MODE_COMPLEX_INT
;
124 case MODE_FLOAT
: return MODE_COMPLEX_FLOAT
;
126 error ("no complex class for class %s", mode_class_names
[c
]);
131 static enum mode_class
132 vector_class (enum mode_class cl
)
136 case MODE_INT
: return MODE_VECTOR_INT
;
137 case MODE_FLOAT
: return MODE_VECTOR_FLOAT
;
138 case MODE_FRACT
: return MODE_VECTOR_FRACT
;
139 case MODE_UFRACT
: return MODE_VECTOR_UFRACT
;
140 case MODE_ACCUM
: return MODE_VECTOR_ACCUM
;
141 case MODE_UACCUM
: return MODE_VECTOR_UACCUM
;
143 error ("no vector class for class %s", mode_class_names
[cl
]);
148 /* Utility routines. */
149 static inline struct mode_data
*
150 find_mode (const char *name
)
152 struct mode_data key
;
155 return (struct mode_data
*) htab_find (modes_by_name
, &key
);
158 static struct mode_data
*
159 new_mode (enum mode_class cl
, const char *name
,
160 const char *file
, unsigned int line
)
163 static unsigned int count
= 0;
165 m
= find_mode (name
);
168 error ("%s:%d: duplicate definition of mode \"%s\"",
169 trim_filename (file
), line
, name
);
170 error ("%s:%d: previous definition here", m
->file
, m
->line
);
174 m
= XNEW (struct mode_data
);
175 memcpy (m
, &blank_mode
, sizeof (struct mode_data
));
179 m
->file
= trim_filename (file
);
181 m
->counter
= count
++;
187 *htab_find_slot (modes_by_name
, m
, INSERT
) = m
;
193 hash_mode (const void *p
)
195 const struct mode_data
*m
= (const struct mode_data
*)p
;
196 return htab_hash_string (m
->name
);
200 eq_mode (const void *p
, const void *q
)
202 const struct mode_data
*a
= (const struct mode_data
*)p
;
203 const struct mode_data
*b
= (const struct mode_data
*)q
;
205 return !strcmp (a
->name
, b
->name
);
208 #define for_all_modes(C, M) \
209 for (C = 0; C < MAX_MODE_CLASS; C++) \
210 for (M = modes[C]; M; M = M->next)
212 static void ATTRIBUTE_UNUSED
213 new_adjust (const char *name
,
214 struct mode_adjust
**category
, const char *catname
,
215 const char *adjustment
,
216 enum mode_class required_class_from
,
217 enum mode_class required_class_to
,
218 const char *file
, unsigned int line
)
220 struct mode_data
*mode
= find_mode (name
);
221 struct mode_adjust
*a
;
223 file
= trim_filename (file
);
227 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
231 if (required_class_from
!= MODE_RANDOM
232 && (mode
->cl
< required_class_from
|| mode
->cl
> required_class_to
))
234 error ("%s:%d: mode \"%s\" is not among class {%s, %s}",
235 file
, line
, name
, mode_class_names
[required_class_from
] + 5,
236 mode_class_names
[required_class_to
] + 5);
240 for (a
= *category
; a
; a
= a
->next
)
243 error ("%s:%d: mode \"%s\" already has a %s adjustment",
244 file
, line
, name
, catname
);
245 error ("%s:%d: previous adjustment here", a
->file
, a
->line
);
249 a
= XNEW (struct mode_adjust
);
251 a
->adjustment
= adjustment
;
259 /* Diagnose failure to meet expectations in a partially filled out
261 enum requirement
{ SET
, UNSET
, OPTIONAL
};
263 #define validate_field_(mname, fname, req, val, unset, file, line) do { \
268 error ("%s:%d: (%s) field %s must be set", \
269 file, line, mname, fname); \
273 error ("%s:%d: (%s) field %s must not be set", \
274 file, line, mname, fname); \
280 #define validate_field(M, F) \
281 validate_field_(M->name, #F, r_##F, M->F, blank_mode.F, M->file, M->line)
284 validate_mode (struct mode_data
*m
,
285 enum requirement r_precision
,
286 enum requirement r_bytesize
,
287 enum requirement r_component
,
288 enum requirement r_ncomponents
,
289 enum requirement r_format
)
291 validate_field (m
, precision
);
292 validate_field (m
, bytesize
);
293 validate_field (m
, component
);
294 validate_field (m
, ncomponents
);
295 validate_field (m
, format
);
297 #undef validate_field
298 #undef validate_field_
300 /* Given a partially-filled-out mode structure, figure out what we can
301 and fill the rest of it in; die if it isn't enough. */
303 complete_mode (struct mode_data
*m
)
305 unsigned int alignment
;
309 error ("%s:%d: mode with no name", m
->file
, m
->line
);
312 if (m
->cl
== MAX_MODE_CLASS
)
314 error ("%s:%d: %smode has no mode class", m
->file
, m
->line
, m
->name
);
321 /* Nothing more need be said. */
322 if (!strcmp (m
->name
, "VOID"))
325 validate_mode (m
, UNSET
, UNSET
, UNSET
, UNSET
, UNSET
);
334 /* Again, nothing more need be said. For historical reasons,
335 the size of a CC mode is four units. */
336 validate_mode (m
, UNSET
, UNSET
, UNSET
, UNSET
, UNSET
);
345 case MODE_DECIMAL_FLOAT
:
350 /* A scalar mode must have a byte size, may have a bit size,
351 and must not have components. A float mode must have a
353 validate_mode (m
, OPTIONAL
, SET
, UNSET
, UNSET
,
354 (m
->cl
== MODE_FLOAT
|| m
->cl
== MODE_DECIMAL_FLOAT
)
361 case MODE_PARTIAL_INT
:
362 /* A partial integer mode uses ->component to say what the
363 corresponding full-size integer mode is, and may also
364 specify a bit size. */
365 validate_mode (m
, OPTIONAL
, UNSET
, SET
, UNSET
, UNSET
);
367 m
->bytesize
= m
->component
->bytesize
;
372 case MODE_COMPLEX_INT
:
373 case MODE_COMPLEX_FLOAT
:
374 /* Complex modes should have a component indicated, but no more. */
375 validate_mode (m
, UNSET
, UNSET
, SET
, UNSET
, UNSET
);
377 if (m
->component
->precision
!= (unsigned int)-1)
378 m
->precision
= 2 * m
->component
->precision
;
379 m
->bytesize
= 2 * m
->component
->bytesize
;
382 case MODE_VECTOR_BOOL
:
383 validate_mode (m
, UNSET
, SET
, SET
, SET
, UNSET
);
386 case MODE_VECTOR_INT
:
387 case MODE_VECTOR_FLOAT
:
388 case MODE_VECTOR_FRACT
:
389 case MODE_VECTOR_UFRACT
:
390 case MODE_VECTOR_ACCUM
:
391 case MODE_VECTOR_UACCUM
:
392 /* Vector modes should have a component and a number of components. */
393 validate_mode (m
, UNSET
, UNSET
, SET
, SET
, UNSET
);
394 if (m
->component
->precision
!= (unsigned int)-1)
395 m
->precision
= m
->ncomponents
* m
->component
->precision
;
396 m
->bytesize
= m
->ncomponents
* m
->component
->bytesize
;
403 /* If not already specified, the mode alignment defaults to the largest
404 power of two that divides the size of the object. Complex types are
405 not more aligned than their contents. */
406 if (m
->cl
== MODE_COMPLEX_INT
|| m
->cl
== MODE_COMPLEX_FLOAT
)
407 alignment
= m
->component
->bytesize
;
409 alignment
= m
->bytesize
;
411 m
->alignment
= alignment
& (~alignment
+ 1);
413 /* If this mode has components, make the component mode point back
414 to this mode, for the sake of adjustments. */
417 m
->next_cont
= m
->component
->contained
;
418 m
->component
->contained
= m
;
423 complete_all_modes (void)
428 for_all_modes (cl
, m
)
432 /* For each mode in class CLASS, construct a corresponding complex mode. */
433 #define COMPLEX_MODES(C) make_complex_modes (MODE_##C, __FILE__, __LINE__)
435 make_complex_modes (enum mode_class cl
,
436 const char *file
, unsigned int line
)
440 enum mode_class cclass
= complex_class (cl
);
442 if (cclass
== MODE_RANDOM
)
445 for (m
= modes
[cl
]; m
; m
= m
->next
)
450 /* Skip BImode. FIXME: BImode probably shouldn't be MODE_INT. */
451 if (m
->precision
== 1)
454 m_len
= strlen (m
->name
);
455 /* The leading "1 +" is in case we prepend a "C" below. */
456 buf
= (char *) xmalloc (1 + m_len
+ 1);
458 /* Float complex modes are named SCmode, etc.
459 Int complex modes are named CSImode, etc.
460 This inconsistency should be eliminated. */
462 if (cl
== MODE_FLOAT
)
464 memcpy (buf
, m
->name
, m_len
+ 1);
465 p
= strchr (buf
, 'F');
466 if (p
== 0 && strchr (buf
, 'D') == 0)
468 error ("%s:%d: float mode \"%s\" has no 'F' or 'D'",
469 m
->file
, m
->line
, m
->name
);
479 memcpy (buf
+ 1, m
->name
, m_len
+ 1);
482 c
= new_mode (cclass
, buf
, file
, line
);
488 /* For all modes in class CL, construct vector modes of width WIDTH,
489 having as many components as necessary. ORDER is the sorting order
490 of the mode, with smaller numbers indicating a higher priority. */
491 #define VECTOR_MODES_WITH_PREFIX(PREFIX, C, W, ORDER) \
492 make_vector_modes (MODE_##C, #PREFIX, W, ORDER, __FILE__, __LINE__)
493 #define VECTOR_MODES(C, W) VECTOR_MODES_WITH_PREFIX (V, C, W, 0)
494 static void ATTRIBUTE_UNUSED
495 make_vector_modes (enum mode_class cl
, const char *prefix
, unsigned int width
,
496 unsigned int order
, const char *file
, unsigned int line
)
500 /* Big enough for a 32-bit UINT_MAX plus the text. */
502 unsigned int ncomponents
;
503 enum mode_class vclass
= vector_class (cl
);
505 if (vclass
== MODE_RANDOM
)
508 for (m
= modes
[cl
]; m
; m
= m
->next
)
510 /* Do not construct vector modes with only one element, or
511 vector modes where the element size doesn't divide the full
513 ncomponents
= width
/ m
->bytesize
;
516 if (width
% m
->bytesize
)
519 /* Skip QFmode and BImode. FIXME: this special case should
521 if (cl
== MODE_FLOAT
&& m
->bytesize
== 1)
523 if (cl
== MODE_INT
&& m
->precision
== 1)
526 if ((size_t) snprintf (buf
, sizeof buf
, "%s%u%s", prefix
,
527 ncomponents
, m
->name
) >= sizeof buf
)
529 error ("%s:%d: mode name \"%s\" is too long",
530 m
->file
, m
->line
, m
->name
);
534 v
= new_mode (vclass
, xstrdup (buf
), file
, line
);
537 v
->ncomponents
= ncomponents
;
541 /* Create a vector of booleans called NAME with COUNT elements and
542 BYTESIZE bytes in total. */
543 #define VECTOR_BOOL_MODE(NAME, COUNT, BYTESIZE) \
544 make_vector_bool_mode (#NAME, COUNT, BYTESIZE, __FILE__, __LINE__)
545 static void ATTRIBUTE_UNUSED
546 make_vector_bool_mode (const char *name
, unsigned int count
,
547 unsigned int bytesize
, const char *file
,
550 struct mode_data
*m
= find_mode ("BI");
553 error ("%s:%d: no mode \"BI\"", file
, line
);
557 struct mode_data
*v
= new_mode (MODE_VECTOR_BOOL
, name
, file
, line
);
559 v
->ncomponents
= count
;
560 v
->bytesize
= bytesize
;
565 #define _SPECIAL_MODE(C, N) \
566 make_special_mode (MODE_##C, #N, __FILE__, __LINE__)
567 #define RANDOM_MODE(N) _SPECIAL_MODE (RANDOM, N)
568 #define CC_MODE(N) _SPECIAL_MODE (CC, N)
571 make_special_mode (enum mode_class cl
, const char *name
,
572 const char *file
, unsigned int line
)
574 new_mode (cl
, name
, file
, line
);
577 #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y)
578 #define FRACTIONAL_INT_MODE(N, B, Y) \
579 make_int_mode (#N, B, Y, __FILE__, __LINE__)
582 make_int_mode (const char *name
,
583 unsigned int precision
, unsigned int bytesize
,
584 const char *file
, unsigned int line
)
586 struct mode_data
*m
= new_mode (MODE_INT
, name
, file
, line
);
587 m
->bytesize
= bytesize
;
588 m
->precision
= precision
;
591 #define FRACT_MODE(N, Y, F) \
592 make_fixed_point_mode (MODE_FRACT, #N, Y, 0, F, __FILE__, __LINE__)
594 #define UFRACT_MODE(N, Y, F) \
595 make_fixed_point_mode (MODE_UFRACT, #N, Y, 0, F, __FILE__, __LINE__)
597 #define ACCUM_MODE(N, Y, I, F) \
598 make_fixed_point_mode (MODE_ACCUM, #N, Y, I, F, __FILE__, __LINE__)
600 #define UACCUM_MODE(N, Y, I, F) \
601 make_fixed_point_mode (MODE_UACCUM, #N, Y, I, F, __FILE__, __LINE__)
603 /* Create a fixed-point mode by setting CL, NAME, BYTESIZE, IBIT, FBIT,
607 make_fixed_point_mode (enum mode_class cl
,
609 unsigned int bytesize
,
612 const char *file
, unsigned int line
)
614 struct mode_data
*m
= new_mode (cl
, name
, file
, line
);
615 m
->bytesize
= bytesize
;
620 #define FLOAT_MODE(N, Y, F) FRACTIONAL_FLOAT_MODE (N, -1U, Y, F)
621 #define FRACTIONAL_FLOAT_MODE(N, B, Y, F) \
622 make_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
625 make_float_mode (const char *name
,
626 unsigned int precision
, unsigned int bytesize
,
628 const char *file
, unsigned int line
)
630 struct mode_data
*m
= new_mode (MODE_FLOAT
, name
, file
, line
);
631 m
->bytesize
= bytesize
;
632 m
->precision
= precision
;
636 #define DECIMAL_FLOAT_MODE(N, Y, F) \
637 FRACTIONAL_DECIMAL_FLOAT_MODE (N, -1U, Y, F)
638 #define FRACTIONAL_DECIMAL_FLOAT_MODE(N, B, Y, F) \
639 make_decimal_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
642 make_decimal_float_mode (const char *name
,
643 unsigned int precision
, unsigned int bytesize
,
645 const char *file
, unsigned int line
)
647 struct mode_data
*m
= new_mode (MODE_DECIMAL_FLOAT
, name
, file
, line
);
648 m
->bytesize
= bytesize
;
649 m
->precision
= precision
;
653 #define RESET_FLOAT_FORMAT(N, F) \
654 reset_float_format (#N, #F, __FILE__, __LINE__)
655 static void ATTRIBUTE_UNUSED
656 reset_float_format (const char *name
, const char *format
,
657 const char *file
, unsigned int line
)
659 struct mode_data
*m
= find_mode (name
);
662 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
665 if (m
->cl
!= MODE_FLOAT
&& m
->cl
!= MODE_DECIMAL_FLOAT
)
667 error ("%s:%d: mode \"%s\" is not a FLOAT class", file
, line
, name
);
673 /* __intN support. */
674 #define INT_N(M,PREC) \
675 make_int_n (#M, PREC, __FILE__, __LINE__)
676 static void ATTRIBUTE_UNUSED
677 make_int_n (const char *m
, int bitsize
,
678 const char *file
, unsigned int line
)
680 struct mode_data
*component
= find_mode (m
);
683 error ("%s:%d: no mode \"%s\"", file
, line
, m
);
686 if (component
->cl
!= MODE_INT
687 && component
->cl
!= MODE_PARTIAL_INT
)
689 error ("%s:%d: mode \"%s\" is not class INT or PARTIAL_INT", file
, line
, m
);
692 if (component
->int_n
!= 0)
694 error ("%s:%d: mode \"%s\" already has an intN", file
, line
, m
);
698 component
->int_n
= bitsize
;
701 /* Partial integer modes are specified by relation to a full integer
703 #define PARTIAL_INT_MODE(M,PREC,NAME) \
704 make_partial_integer_mode (#M, #NAME, PREC, __FILE__, __LINE__)
705 static void ATTRIBUTE_UNUSED
706 make_partial_integer_mode (const char *base
, const char *name
,
707 unsigned int precision
,
708 const char *file
, unsigned int line
)
711 struct mode_data
*component
= find_mode (base
);
714 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
717 if (component
->cl
!= MODE_INT
)
719 error ("%s:%d: mode \"%s\" is not class INT", file
, line
, name
);
723 m
= new_mode (MODE_PARTIAL_INT
, name
, file
, line
);
724 m
->precision
= precision
;
725 m
->component
= component
;
728 /* A single vector mode can be specified by naming its component
729 mode and the number of components. */
730 #define VECTOR_MODE(C, M, N) \
731 make_vector_mode (MODE_##C, #M, N, __FILE__, __LINE__);
732 static void ATTRIBUTE_UNUSED
733 make_vector_mode (enum mode_class bclass
,
735 unsigned int ncomponents
,
736 const char *file
, unsigned int line
)
739 enum mode_class vclass
= vector_class (bclass
);
740 struct mode_data
*component
= find_mode (base
);
743 if (vclass
== MODE_RANDOM
)
747 error ("%s:%d: no mode \"%s\"", file
, line
, base
);
750 if (component
->cl
!= bclass
751 && (component
->cl
!= MODE_PARTIAL_INT
752 || bclass
!= MODE_INT
))
754 error ("%s:%d: mode \"%s\" is not class %s",
755 file
, line
, base
, mode_class_names
[bclass
] + 5);
759 if ((size_t)snprintf (namebuf
, sizeof namebuf
, "V%u%s",
760 ncomponents
, base
) >= sizeof namebuf
)
762 error ("%s:%d: mode name \"%s\" is too long",
767 v
= new_mode (vclass
, xstrdup (namebuf
), file
, line
);
768 v
->ncomponents
= ncomponents
;
769 v
->component
= component
;
773 #define _ADD_ADJUST(A, M, X, C1, C2) \
774 new_adjust (#M, &adj_##A, #A, #X, MODE_##C1, MODE_##C2, __FILE__, __LINE__)
776 #define ADJUST_NUNITS(M, X) _ADD_ADJUST (nunits, M, X, RANDOM, RANDOM)
777 #define ADJUST_BYTESIZE(M, X) _ADD_ADJUST (bytesize, M, X, RANDOM, RANDOM)
778 #define ADJUST_ALIGNMENT(M, X) _ADD_ADJUST (alignment, M, X, RANDOM, RANDOM)
779 #define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST (format, M, X, FLOAT, FLOAT)
780 #define ADJUST_IBIT(M, X) _ADD_ADJUST (ibit, M, X, ACCUM, UACCUM)
781 #define ADJUST_FBIT(M, X) _ADD_ADJUST (fbit, M, X, FRACT, UACCUM)
783 static int bits_per_unit
;
784 static int max_bitsize_mode_any_int
;
785 static int max_bitsize_mode_any_mode
;
790 #include "machmode.def"
792 /* So put the default value unless the target needs a non standard
795 bits_per_unit
= BITS_PER_UNIT
;
800 #ifdef MAX_BITSIZE_MODE_ANY_INT
801 max_bitsize_mode_any_int
= MAX_BITSIZE_MODE_ANY_INT
;
803 max_bitsize_mode_any_int
= 0;
806 #ifdef MAX_BITSIZE_MODE_ANY_MODE
807 max_bitsize_mode_any_mode
= MAX_BITSIZE_MODE_ANY_MODE
;
809 max_bitsize_mode_any_mode
= 0;
813 #ifndef NUM_POLY_INT_COEFFS
814 #define NUM_POLY_INT_COEFFS 1
819 /* Sort a list of modes into the order needed for the WIDER field:
820 major sort by precision, minor sort by component precision.
823 QI < HI < SI < DI < TI
824 V4QI < V2HI < V8QI < V4HI < V2SI.
826 If the precision is not set, sort by the bytesize. A mode with
827 precision set gets sorted before a mode without precision set, if
828 they have the same bytesize; this is the right thing because
829 the precision must always be smaller than the bytesize * BITS_PER_UNIT.
830 We don't have to do anything special to get this done -- an unset
831 precision shows up as (unsigned int)-1, i.e. UINT_MAX. */
833 cmp_modes (const void *a
, const void *b
)
835 const struct mode_data
*const m
= *(const struct mode_data
*const*)a
;
836 const struct mode_data
*const n
= *(const struct mode_data
*const*)b
;
838 if (m
->order
> n
->order
)
840 else if (m
->order
< n
->order
)
843 if (m
->bytesize
> n
->bytesize
)
845 else if (m
->bytesize
< n
->bytesize
)
848 if (m
->precision
> n
->precision
)
850 else if (m
->precision
< n
->precision
)
853 if (!m
->component
&& !n
->component
)
855 if (m
->counter
< n
->counter
)
861 if (m
->component
->bytesize
> n
->component
->bytesize
)
863 else if (m
->component
->bytesize
< n
->component
->bytesize
)
866 if (m
->component
->precision
> n
->component
->precision
)
868 else if (m
->component
->precision
< n
->component
->precision
)
871 if (m
->counter
< n
->counter
)
878 calc_wider_mode (void)
882 struct mode_data
**sortbuf
;
883 unsigned int max_n_modes
= 0;
886 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
887 max_n_modes
= MAX (max_n_modes
, n_modes
[c
]);
889 /* Allocate max_n_modes + 1 entries to leave room for the extra null
890 pointer assigned after the qsort call below. */
891 sortbuf
= XALLOCAVEC (struct mode_data
*, max_n_modes
+ 1);
893 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
895 /* "wider" is not meaningful for MODE_RANDOM and MODE_CC.
896 However, we want these in textual order, and we have
897 precisely the reverse. */
898 if (c
== MODE_RANDOM
|| c
== MODE_CC
)
900 struct mode_data
*prev
, *next
;
902 for (prev
= 0, m
= modes
[c
]; m
; m
= next
)
904 m
->wider
= void_mode
;
906 /* this is nreverse */
918 for (i
= 0, m
= modes
[c
]; m
; i
++, m
= m
->next
)
921 (qsort
) (sortbuf
, i
, sizeof (struct mode_data
*), cmp_modes
);
924 for (j
= 0; j
< i
; j
++)
926 sortbuf
[j
]->next
= sortbuf
[j
+ 1];
927 if (c
== MODE_PARTIAL_INT
)
928 sortbuf
[j
]->wider
= sortbuf
[j
]->component
;
930 sortbuf
[j
]->wider
= sortbuf
[j
]->next
;
933 modes
[c
] = sortbuf
[0];
938 /* Text to add to the constant part of a poly_int_pod initializer in
939 order to fill out te whole structure. */
940 #if NUM_POLY_INT_COEFFS == 1
941 #define ZERO_COEFFS ""
942 #elif NUM_POLY_INT_COEFFS == 2
943 #define ZERO_COEFFS ", 0"
945 #error "Unknown value of NUM_POLY_INT_COEFFS"
948 /* Output routines. */
950 #define tagged_printf(FMT, ARG, TAG) do { \
951 int count_ = printf (" " FMT ",", ARG); \
952 printf ("%*s/* %s */\n", 27 - count_, "", TAG); \
955 #define print_decl(TYPE, NAME, ASIZE) \
956 puts ("\nconst " TYPE " " NAME "[" ASIZE "] =\n{");
958 #define print_maybe_const_decl(TYPE, NAME, ASIZE, NEEDS_ADJ) \
959 printf ("\n" TYPE " " NAME "[" ASIZE "] = \n{\n", \
960 NEEDS_ADJ ? "" : "const ")
962 #define print_closer() puts ("};")
964 /* Compute the max bitsize of some of the classes of integers. It may
965 be that there are needs for the other integer classes, and this
966 code is easy to extend. */
970 unsigned int max
, mmax
;
976 printf ("#define BITS_PER_UNIT (%d)\n", bits_per_unit
);
978 if (max_bitsize_mode_any_int
== 0)
980 for (max
= 1, i
= modes
[MODE_INT
]; i
; i
= i
->next
)
981 if (max
< i
->bytesize
)
984 for (max
= 1, i
= modes
[MODE_PARTIAL_INT
]; i
; i
= i
->next
)
985 if (max
< i
->bytesize
)
989 printf ("#define MAX_BITSIZE_MODE_ANY_INT (%d*BITS_PER_UNIT)\n", mmax
);
992 printf ("#define MAX_BITSIZE_MODE_ANY_INT %d\n", max_bitsize_mode_any_int
);
994 if (max_bitsize_mode_any_mode
== 0)
997 for (j
= 0; j
< MAX_MODE_CLASS
; j
++)
998 for (i
= modes
[j
]; i
; i
= i
->next
)
999 if (mmax
< i
->bytesize
)
1001 printf ("#define MAX_BITSIZE_MODE_ANY_MODE (%d*BITS_PER_UNIT)\n", mmax
);
1004 printf ("#define MAX_BITSIZE_MODE_ANY_MODE %d\n",
1005 max_bitsize_mode_any_mode
);
1008 /* Emit mode_size_inline routine into insn-modes.h header. */
1010 emit_mode_size_inline (void)
1013 struct mode_adjust
*a
;
1014 struct mode_data
*m
;
1016 /* Size adjustments must be propagated to all containing modes. */
1017 for (a
= adj_bytesize
; a
; a
= a
->next
)
1019 a
->mode
->need_bytesize_adj
= true;
1020 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1021 m
->need_bytesize_adj
= true;
1024 /* Changing the number of units by a factor of X also changes the size
1025 by a factor of X. */
1026 for (mode_adjust
*a
= adj_nunits
; a
; a
= a
->next
)
1027 a
->mode
->need_bytesize_adj
= true;
1030 #ifdef __cplusplus\n\
1031 inline __attribute__((__always_inline__))\n\
1033 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1036 mode_size_inline (machine_mode mode)\n\
1038 extern %spoly_uint16_pod mode_size[NUM_MACHINE_MODES];\n\
1039 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1041 {\n", adj_nunits
|| adj_bytesize
? "" : "const ");
1043 for_all_modes (c
, m
)
1044 if (!m
->need_bytesize_adj
)
1045 printf (" case E_%smode: return %u;\n", m
->name
, m
->bytesize
);
1048 default: return mode_size[mode];\n\
1053 /* Emit mode_nunits_inline routine into insn-modes.h header. */
1055 emit_mode_nunits_inline (void)
1058 struct mode_data
*m
;
1060 for (mode_adjust
*a
= adj_nunits
; a
; a
= a
->next
)
1061 a
->mode
->need_nunits_adj
= true;
1064 #ifdef __cplusplus\n\
1065 inline __attribute__((__always_inline__))\n\
1067 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1070 mode_nunits_inline (machine_mode mode)\n\
1072 extern %spoly_uint16_pod mode_nunits[NUM_MACHINE_MODES];\n\
1074 {\n", adj_nunits
? "" : "const ");
1076 for_all_modes (c
, m
)
1077 if (!m
->need_nunits_adj
)
1078 printf (" case E_%smode: return %u;\n", m
->name
, m
->ncomponents
);
1081 default: return mode_nunits[mode];\n\
1086 /* Emit mode_inner_inline routine into insn-modes.h header. */
1088 emit_mode_inner_inline (void)
1091 struct mode_data
*m
;
1094 #ifdef __cplusplus\n\
1095 inline __attribute__((__always_inline__))\n\
1097 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1100 mode_inner_inline (machine_mode mode)\n\
1102 extern const unsigned char mode_inner[NUM_MACHINE_MODES];\n\
1103 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1107 for_all_modes (c
, m
)
1108 printf (" case E_%smode: return E_%smode;\n", m
->name
,
1109 c
!= MODE_PARTIAL_INT
&& m
->component
1110 ? m
->component
->name
: m
->name
);
1113 default: return mode_inner[mode];\n\
1118 /* Emit mode_unit_size_inline routine into insn-modes.h header. */
1120 emit_mode_unit_size_inline (void)
1123 struct mode_data
*m
;
1126 #ifdef __cplusplus\n\
1127 inline __attribute__((__always_inline__))\n\
1129 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1132 mode_unit_size_inline (machine_mode mode)\n\
1134 extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES];\
1136 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1140 for_all_modes (c
, m
)
1142 const char *name
= m
->name
;
1143 struct mode_data
*m2
= m
;
1144 if (c
!= MODE_PARTIAL_INT
&& m2
->component
)
1146 if (!m2
->need_bytesize_adj
)
1147 printf (" case E_%smode: return %u;\n", name
, m2
->bytesize
);
1151 default: return mode_unit_size[mode];\n\
1156 /* Emit mode_unit_precision_inline routine into insn-modes.h header. */
1158 emit_mode_unit_precision_inline (void)
1161 struct mode_data
*m
;
1164 #ifdef __cplusplus\n\
1165 inline __attribute__((__always_inline__))\n\
1167 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1170 mode_unit_precision_inline (machine_mode mode)\n\
1172 extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES];\n\
1173 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1177 for_all_modes (c
, m
)
1179 struct mode_data
*m2
1180 = (c
!= MODE_PARTIAL_INT
&& m
->component
) ? m
->component
: m
;
1181 if (m2
->precision
!= (unsigned int)-1)
1182 printf (" case E_%smode: return %u;\n", m
->name
, m2
->precision
);
1184 printf (" case E_%smode: return %u*BITS_PER_UNIT;\n",
1185 m
->name
, m2
->bytesize
);
1189 default: return mode_unit_precision[mode];\n\
1194 /* Return the best machine mode class for MODE, or null if machine_mode
1198 get_mode_class (struct mode_data
*mode
)
1203 case MODE_PARTIAL_INT
:
1204 return "scalar_int_mode";
1210 return "scalar_mode";
1213 case MODE_DECIMAL_FLOAT
:
1214 return "scalar_float_mode";
1216 case MODE_COMPLEX_INT
:
1217 case MODE_COMPLEX_FLOAT
:
1218 return "complex_mode";
1226 emit_insn_modes_h (void)
1229 struct mode_data
*m
, *first
, *last
;
1230 int n_int_n_ents
= 0;
1232 printf ("/* Generated automatically from machmode.def%s%s\n",
1233 HAVE_EXTRA_MODES
? " and " : "",
1239 #ifndef GCC_INSN_MODES_H\n\
1240 #define GCC_INSN_MODES_H\n\
1242 enum machine_mode\n{");
1244 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1245 for (m
= modes
[c
]; m
; m
= m
->next
)
1247 int count_
= printf (" E_%smode,", m
->name
);
1248 printf ("%*s/* %s:%d */\n", 27 - count_
, "",
1249 trim_filename (m
->file
), m
->line
);
1250 printf ("#define HAVE_%smode\n", m
->name
);
1251 printf ("#ifdef USE_ENUM_MODES\n");
1252 printf ("#define %smode E_%smode\n", m
->name
, m
->name
);
1254 if (const char *mode_class
= get_mode_class (m
))
1255 printf ("#define %smode (%s ((%s::from_int) E_%smode))\n",
1256 m
->name
, mode_class
, mode_class
, m
->name
);
1258 printf ("#define %smode ((void) 0, E_%smode)\n",
1260 printf ("#endif\n");
1263 puts (" MAX_MACHINE_MODE,\n");
1265 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1269 for (m
= first
; m
; last
= m
, m
= m
->next
)
1272 /* Don't use BImode for MIN_MODE_INT, since otherwise the middle
1273 end will try to use it for bitfields in structures and the
1274 like, which we do not want. Only the target md file should
1275 generate BImode widgets. */
1276 if (first
&& first
->precision
== 1 && c
== MODE_INT
)
1277 first
= first
->next
;
1280 printf (" MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n",
1281 mode_class_names
[c
], first
->name
,
1282 mode_class_names
[c
], last
->name
);
1284 printf (" MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n",
1285 mode_class_names
[c
], void_mode
->name
,
1286 mode_class_names
[c
], void_mode
->name
);
1290 NUM_MACHINE_MODES = MAX_MACHINE_MODE\n\
1293 /* I can't think of a better idea, can you? */
1294 printf ("#define CONST_MODE_NUNITS%s\n", adj_nunits
? "" : " const");
1295 printf ("#define CONST_MODE_PRECISION%s\n", adj_nunits
? "" : " const");
1296 printf ("#define CONST_MODE_SIZE%s\n",
1297 adj_bytesize
|| adj_nunits
? "" : " const");
1298 printf ("#define CONST_MODE_UNIT_SIZE%s\n", adj_bytesize
? "" : " const");
1299 printf ("#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment
? "" : " const");
1300 #if 0 /* disabled for backward compatibility, temporary */
1301 printf ("#define CONST_REAL_FORMAT_FOR_MODE%s\n", adj_format
? "" :" const");
1303 printf ("#define CONST_MODE_IBIT%s\n", adj_ibit
? "" : " const");
1304 printf ("#define CONST_MODE_FBIT%s\n", adj_fbit
? "" : " const");
1307 for_all_modes (c
, m
)
1311 printf ("#define NUM_INT_N_ENTS %d\n", n_int_n_ents
);
1313 printf ("#define NUM_POLY_INT_COEFFS %d\n", NUM_POLY_INT_COEFFS
);
1317 #endif /* insn-modes.h */");
1321 emit_insn_modes_inline_h (void)
1323 printf ("/* Generated automatically from machmode.def%s%s\n",
1324 HAVE_EXTRA_MODES
? " and " : "",
1330 #ifndef GCC_INSN_MODES_INLINE_H\n\
1331 #define GCC_INSN_MODES_INLINE_H");
1333 puts ("\n#if !defined (USED_FOR_TARGET) && GCC_VERSION >= 4001\n");
1334 emit_mode_size_inline ();
1335 emit_mode_nunits_inline ();
1336 emit_mode_inner_inline ();
1337 emit_mode_unit_size_inline ();
1338 emit_mode_unit_precision_inline ();
1339 puts ("#endif /* GCC_VERSION >= 4001 */");
1343 #endif /* insn-modes-inline.h */");
1347 emit_insn_modes_c_header (void)
1349 printf ("/* Generated automatically from machmode.def%s%s\n",
1350 HAVE_EXTRA_MODES
? " and " : "",
1356 #include \"config.h\"\n\
1357 #include \"system.h\"\n\
1358 #include \"coretypes.h\"\n\
1359 #include \"tm.h\"\n\
1360 #include \"real.h\"");
1364 emit_min_insn_modes_c_header (void)
1366 printf ("/* Generated automatically from machmode.def%s%s\n",
1367 HAVE_EXTRA_MODES
? " and " : "",
1373 #include \"bconfig.h\"\n\
1374 #include \"system.h\"\n\
1375 #include \"coretypes.h\"");
1379 emit_mode_name (void)
1382 struct mode_data
*m
;
1384 print_decl ("char *const", "mode_name", "NUM_MACHINE_MODES");
1386 for_all_modes (c
, m
)
1387 printf (" \"%s\",\n", m
->name
);
1393 emit_mode_class (void)
1396 struct mode_data
*m
;
1398 print_decl ("unsigned char", "mode_class", "NUM_MACHINE_MODES");
1400 for_all_modes (c
, m
)
1401 tagged_printf ("%s", mode_class_names
[m
->cl
], m
->name
);
1407 emit_mode_precision (void)
1410 struct mode_data
*m
;
1412 print_maybe_const_decl ("%spoly_uint16_pod", "mode_precision",
1413 "NUM_MACHINE_MODES", adj_nunits
);
1415 for_all_modes (c
, m
)
1416 if (m
->precision
!= (unsigned int)-1)
1417 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->precision
, m
->name
);
1419 tagged_printf ("{ %u * BITS_PER_UNIT" ZERO_COEFFS
" }",
1420 m
->bytesize
, m
->name
);
1426 emit_mode_size (void)
1429 struct mode_data
*m
;
1431 print_maybe_const_decl ("%spoly_uint16_pod", "mode_size",
1432 "NUM_MACHINE_MODES", adj_nunits
|| adj_bytesize
);
1434 for_all_modes (c
, m
)
1435 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->bytesize
, m
->name
);
1441 emit_mode_nunits (void)
1444 struct mode_data
*m
;
1446 print_maybe_const_decl ("%spoly_uint16_pod", "mode_nunits",
1447 "NUM_MACHINE_MODES", adj_nunits
);
1449 for_all_modes (c
, m
)
1450 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->ncomponents
, m
->name
);
1456 emit_mode_wider (void)
1459 struct mode_data
*m
;
1461 print_decl ("unsigned char", "mode_wider", "NUM_MACHINE_MODES");
1463 for_all_modes (c
, m
)
1464 tagged_printf ("E_%smode",
1465 m
->wider
? m
->wider
->name
: void_mode
->name
,
1469 print_decl ("unsigned char", "mode_2xwider", "NUM_MACHINE_MODES");
1471 for_all_modes (c
, m
)
1473 struct mode_data
* m2
;
1476 m2
&& m2
!= void_mode
;
1479 if (m2
->bytesize
< 2 * m
->bytesize
)
1481 if (m
->precision
!= (unsigned int) -1)
1483 if (m2
->precision
!= 2 * m
->precision
)
1488 if (m2
->precision
!= (unsigned int) -1)
1492 /* For vectors we want twice the number of components,
1493 with the same element type. */
1494 if (m
->cl
== MODE_VECTOR_BOOL
1495 || m
->cl
== MODE_VECTOR_INT
1496 || m
->cl
== MODE_VECTOR_FLOAT
1497 || m
->cl
== MODE_VECTOR_FRACT
1498 || m
->cl
== MODE_VECTOR_UFRACT
1499 || m
->cl
== MODE_VECTOR_ACCUM
1500 || m
->cl
== MODE_VECTOR_UACCUM
)
1502 if (m2
->ncomponents
!= 2 * m
->ncomponents
)
1504 if (m
->component
!= m2
->component
)
1510 if (m2
== void_mode
)
1512 tagged_printf ("E_%smode",
1513 m2
? m2
->name
: void_mode
->name
,
1521 emit_mode_complex (void)
1524 struct mode_data
*m
;
1526 print_decl ("unsigned char", "mode_complex", "NUM_MACHINE_MODES");
1528 for_all_modes (c
, m
)
1529 tagged_printf ("E_%smode",
1530 m
->complex ? m
->complex->name
: void_mode
->name
,
1537 emit_mode_mask (void)
1540 struct mode_data
*m
;
1542 print_decl ("unsigned HOST_WIDE_INT", "mode_mask_array",
1543 "NUM_MACHINE_MODES");
1545 #define MODE_MASK(m) \\\n\
1546 ((m) >= HOST_BITS_PER_WIDE_INT) \\\n\
1547 ? HOST_WIDE_INT_M1U \\\n\
1548 : (HOST_WIDE_INT_1U << (m)) - 1\n");
1550 for_all_modes (c
, m
)
1551 if (m
->precision
!= (unsigned int)-1)
1552 tagged_printf ("MODE_MASK (%u)", m
->precision
, m
->name
);
1554 tagged_printf ("MODE_MASK (%u*BITS_PER_UNIT)", m
->bytesize
, m
->name
);
1556 puts ("#undef MODE_MASK");
1561 emit_mode_inner (void)
1564 struct mode_data
*m
;
1566 print_decl ("unsigned char", "mode_inner", "NUM_MACHINE_MODES");
1568 for_all_modes (c
, m
)
1569 tagged_printf ("E_%smode",
1570 c
!= MODE_PARTIAL_INT
&& m
->component
1571 ? m
->component
->name
: m
->name
,
1577 /* Emit mode_unit_size array into insn-modes.c file. */
1579 emit_mode_unit_size (void)
1582 struct mode_data
*m
;
1584 print_maybe_const_decl ("%sunsigned char", "mode_unit_size",
1585 "NUM_MACHINE_MODES", adj_bytesize
);
1587 for_all_modes (c
, m
)
1588 tagged_printf ("%u",
1589 c
!= MODE_PARTIAL_INT
&& m
->component
1590 ? m
->component
->bytesize
: m
->bytesize
, m
->name
);
1595 /* Emit mode_unit_precision array into insn-modes.c file. */
1597 emit_mode_unit_precision (void)
1600 struct mode_data
*m
;
1602 print_decl ("unsigned short", "mode_unit_precision", "NUM_MACHINE_MODES");
1604 for_all_modes (c
, m
)
1606 struct mode_data
*m2
= (c
!= MODE_PARTIAL_INT
&& m
->component
) ?
1608 if (m2
->precision
!= (unsigned int)-1)
1609 tagged_printf ("%u", m2
->precision
, m
->name
);
1611 tagged_printf ("%u*BITS_PER_UNIT", m2
->bytesize
, m
->name
);
1619 emit_mode_base_align (void)
1622 struct mode_data
*m
;
1624 print_maybe_const_decl ("%sunsigned short",
1625 "mode_base_align", "NUM_MACHINE_MODES",
1628 for_all_modes (c
, m
)
1629 tagged_printf ("%u", m
->alignment
, m
->name
);
1635 emit_class_narrowest_mode (void)
1639 print_decl ("unsigned char", "class_narrowest_mode", "MAX_MODE_CLASS");
1641 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1642 /* Bleah, all this to get the comment right for MIN_MODE_INT. */
1643 tagged_printf ("MIN_%s", mode_class_names
[c
],
1645 ? ((c
!= MODE_INT
|| modes
[c
]->precision
!= 1)
1648 ? modes
[c
]->next
->name
1656 emit_real_format_for_mode (void)
1658 struct mode_data
*m
;
1660 /* The entities pointed to by this table are constant, whether
1661 or not the table itself is constant.
1663 For backward compatibility this table is always writable
1664 (several targets modify it in TARGET_OPTION_OVERRIDE). FIXME:
1665 convert all said targets to use ADJUST_FORMAT instead. */
1667 print_maybe_const_decl ("const struct real_format *%s",
1668 "real_format_for_mode",
1669 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1",
1672 print_decl ("struct real_format *\n", "real_format_for_mode",
1673 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1 "
1674 "+ MAX_MODE_DECIMAL_FLOAT - MIN_MODE_DECIMAL_FLOAT + 1");
1677 /* The beginning of the table is entries for float modes. */
1678 for (m
= modes
[MODE_FLOAT
]; m
; m
= m
->next
)
1679 if (!strcmp (m
->format
, "0"))
1680 tagged_printf ("%s", m
->format
, m
->name
);
1682 tagged_printf ("&%s", m
->format
, m
->name
);
1684 /* The end of the table is entries for decimal float modes. */
1685 for (m
= modes
[MODE_DECIMAL_FLOAT
]; m
; m
= m
->next
)
1686 if (!strcmp (m
->format
, "0"))
1687 tagged_printf ("%s", m
->format
, m
->name
);
1689 tagged_printf ("&%s", m
->format
, m
->name
);
1695 emit_mode_adjustments (void)
1697 struct mode_adjust
*a
;
1698 struct mode_data
*m
;
1702 \ninit_adjust_machine_modes (void)\
1704 \n poly_uint16 ps ATTRIBUTE_UNUSED;\n\
1705 size_t s ATTRIBUTE_UNUSED;");
1707 for (a
= adj_nunits
; a
; a
= a
->next
)
1712 " /* %s:%d */\n ps = %s;\n",
1713 a
->file
, a
->line
, a
->adjustment
);
1714 printf (" int old_factor = vector_element_size"
1715 " (mode_precision[E_%smode], mode_nunits[E_%smode]);\n",
1717 printf (" mode_precision[E_%smode] = ps * old_factor;\n", m
->name
);
1718 printf (" mode_size[E_%smode] = exact_div (mode_precision[E_%smode],"
1719 " BITS_PER_UNIT);\n", m
->name
, m
->name
);
1720 printf (" mode_nunits[E_%smode] = ps;\n", m
->name
);
1724 /* Size adjustments must be propagated to all containing modes.
1725 A size adjustment forces us to recalculate the alignment too. */
1726 for (a
= adj_bytesize
; a
; a
= a
->next
)
1728 printf ("\n /* %s:%d */\n", a
->file
, a
->line
);
1729 switch (a
->mode
->cl
)
1731 case MODE_VECTOR_BOOL
:
1732 case MODE_VECTOR_INT
:
1733 case MODE_VECTOR_FLOAT
:
1734 case MODE_VECTOR_FRACT
:
1735 case MODE_VECTOR_UFRACT
:
1736 case MODE_VECTOR_ACCUM
:
1737 case MODE_VECTOR_UACCUM
:
1738 printf (" ps = %s;\n", a
->adjustment
);
1739 printf (" s = mode_unit_size[E_%smode];\n", a
->mode
->name
);
1743 printf (" ps = s = %s;\n", a
->adjustment
);
1744 printf (" mode_unit_size[E_%smode] = s;\n", a
->mode
->name
);
1747 printf (" mode_size[E_%smode] = ps;\n", a
->mode
->name
);
1748 printf (" mode_base_align[E_%smode] = known_alignment (ps);\n",
1751 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1755 case MODE_COMPLEX_INT
:
1756 case MODE_COMPLEX_FLOAT
:
1757 printf (" mode_size[E_%smode] = 2*s;\n", m
->name
);
1758 printf (" mode_unit_size[E_%smode] = s;\n", m
->name
);
1759 printf (" mode_base_align[E_%smode] = s & (~s + 1);\n",
1763 case MODE_VECTOR_BOOL
:
1764 /* Changes to BImode should not affect vector booleans. */
1767 case MODE_VECTOR_INT
:
1768 case MODE_VECTOR_FLOAT
:
1769 case MODE_VECTOR_FRACT
:
1770 case MODE_VECTOR_UFRACT
:
1771 case MODE_VECTOR_ACCUM
:
1772 case MODE_VECTOR_UACCUM
:
1773 printf (" mode_size[E_%smode] = %d * ps;\n",
1774 m
->name
, m
->ncomponents
);
1775 printf (" mode_unit_size[E_%smode] = s;\n", m
->name
);
1776 printf (" mode_base_align[E_%smode]"
1777 " = known_alignment (%d * ps);\n",
1778 m
->name
, m
->ncomponents
);
1783 "mode %s is neither vector nor complex but contains %s",
1784 m
->name
, a
->mode
->name
);
1790 /* Alignment adjustments propagate too.
1791 ??? This may not be the right thing for vector modes. */
1792 for (a
= adj_alignment
; a
; a
= a
->next
)
1794 printf ("\n /* %s:%d */\n s = %s;\n",
1795 a
->file
, a
->line
, a
->adjustment
);
1796 printf (" mode_base_align[E_%smode] = s;\n", a
->mode
->name
);
1798 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1802 case MODE_COMPLEX_INT
:
1803 case MODE_COMPLEX_FLOAT
:
1804 printf (" mode_base_align[E_%smode] = s;\n", m
->name
);
1807 case MODE_VECTOR_BOOL
:
1808 /* Changes to BImode should not affect vector booleans. */
1811 case MODE_VECTOR_INT
:
1812 case MODE_VECTOR_FLOAT
:
1813 case MODE_VECTOR_FRACT
:
1814 case MODE_VECTOR_UFRACT
:
1815 case MODE_VECTOR_ACCUM
:
1816 case MODE_VECTOR_UACCUM
:
1817 printf (" mode_base_align[E_%smode] = %d*s;\n",
1818 m
->name
, m
->ncomponents
);
1823 "mode %s is neither vector nor complex but contains %s",
1824 m
->name
, a
->mode
->name
);
1830 /* Ibit adjustments don't have to propagate. */
1831 for (a
= adj_ibit
; a
; a
= a
->next
)
1833 printf ("\n /* %s:%d */\n s = %s;\n",
1834 a
->file
, a
->line
, a
->adjustment
);
1835 printf (" mode_ibit[E_%smode] = s;\n", a
->mode
->name
);
1838 /* Fbit adjustments don't have to propagate. */
1839 for (a
= adj_fbit
; a
; a
= a
->next
)
1841 printf ("\n /* %s:%d */\n s = %s;\n",
1842 a
->file
, a
->line
, a
->adjustment
);
1843 printf (" mode_fbit[E_%smode] = s;\n", a
->mode
->name
);
1846 /* Real mode formats don't have to propagate anywhere. */
1847 for (a
= adj_format
; a
; a
= a
->next
)
1848 printf ("\n /* %s:%d */\n REAL_MODE_FORMAT (E_%smode) = %s;\n",
1849 a
->file
, a
->line
, a
->mode
->name
, a
->adjustment
);
1854 /* Emit ibit for all modes. */
1857 emit_mode_ibit (void)
1860 struct mode_data
*m
;
1862 print_maybe_const_decl ("%sunsigned char",
1863 "mode_ibit", "NUM_MACHINE_MODES",
1866 for_all_modes (c
, m
)
1867 tagged_printf ("%u", m
->ibit
, m
->name
);
1872 /* Emit fbit for all modes. */
1875 emit_mode_fbit (void)
1878 struct mode_data
*m
;
1880 print_maybe_const_decl ("%sunsigned char",
1881 "mode_fbit", "NUM_MACHINE_MODES",
1884 for_all_modes (c
, m
)
1885 tagged_printf ("%u", m
->fbit
, m
->name
);
1890 /* Emit __intN for all modes. */
1893 emit_mode_int_n (void)
1896 struct mode_data
*m
;
1897 struct mode_data
**mode_sort
;
1901 print_decl ("int_n_data_t", "int_n_data", "");
1904 for_all_modes (c
, m
)
1907 mode_sort
= XALLOCAVEC (struct mode_data
*, n_modes
);
1910 for_all_modes (c
, m
)
1912 mode_sort
[n_modes
++] = m
;
1914 /* Yes, this is a bubblesort, but there are at most four (and
1915 usually only 1-2) entries to sort. */
1916 for (i
= 0; i
<n_modes
- 1; i
++)
1917 for (j
= i
+ 1; j
< n_modes
; j
++)
1918 if (mode_sort
[i
]->int_n
> mode_sort
[j
]->int_n
)
1919 std::swap (mode_sort
[i
], mode_sort
[j
]);
1921 for (i
= 0; i
< n_modes
; i
++)
1925 tagged_printf ("%u", m
->int_n
, m
->name
);
1926 printf ("{ E_%smode },", m
->name
);
1935 emit_insn_modes_c (void)
1937 emit_insn_modes_c_header ();
1940 emit_mode_precision ();
1942 emit_mode_nunits ();
1944 emit_mode_complex ();
1947 emit_mode_unit_size ();
1948 emit_mode_unit_precision ();
1949 emit_mode_base_align ();
1950 emit_class_narrowest_mode ();
1951 emit_real_format_for_mode ();
1952 emit_mode_adjustments ();
1959 emit_min_insn_modes_c (void)
1961 emit_min_insn_modes_c_header ();
1964 emit_mode_nunits ();
1967 emit_class_narrowest_mode ();
1970 /* Master control. */
1972 main (int argc
, char **argv
)
1974 bool gen_header
= false, gen_inlines
= false, gen_min
= false;
1979 else if (argc
== 2 && !strcmp (argv
[1], "-h"))
1981 else if (argc
== 2 && !strcmp (argv
[1], "-i"))
1983 else if (argc
== 2 && !strcmp (argv
[1], "-m"))
1987 error ("usage: %s [-h|-i|-m] > file", progname
);
1988 return FATAL_EXIT_CODE
;
1991 modes_by_name
= htab_create_alloc (64, hash_mode
, eq_mode
, 0, xcalloc
, free
);
1994 complete_all_modes ();
1997 return FATAL_EXIT_CODE
;
2002 emit_insn_modes_h ();
2003 else if (gen_inlines
)
2004 emit_insn_modes_inline_h ();
2006 emit_min_insn_modes_c ();
2008 emit_insn_modes_c ();
2010 if (fflush (stdout
) || fclose (stdout
))
2011 return FATAL_EXIT_CODE
;
2012 return SUCCESS_EXIT_CODE
;