1 /* Generate the machine mode enumeration and associated tables.
2 Copyright (C) 2003-2022 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 */
84 static struct mode_data
*modes
[MAX_MODE_CLASS
];
85 static unsigned int n_modes
[MAX_MODE_CLASS
];
86 static struct mode_data
*void_mode
;
88 static const struct mode_data blank_mode
= {
89 0, "<unknown>", MAX_MODE_CLASS
,
90 0, -1U, -1U, -1U, -1U,
92 "<unknown>", 0, 0, 0, 0, false, false, 0,
96 static htab_t modes_by_name
;
98 /* Data structure for recording target-specified runtime adjustments
99 to a particular mode. We support varying the byte size, the
100 alignment, and the floating point format. */
103 struct mode_adjust
*next
;
104 struct mode_data
*mode
;
105 const char *adjustment
;
111 static struct mode_adjust
*adj_nunits
;
112 static struct mode_adjust
*adj_bytesize
;
113 static struct mode_adjust
*adj_alignment
;
114 static struct mode_adjust
*adj_format
;
115 static struct mode_adjust
*adj_ibit
;
116 static struct mode_adjust
*adj_fbit
;
118 /* Mode class operations. */
119 static enum mode_class
120 complex_class (enum mode_class c
)
124 case MODE_INT
: return MODE_COMPLEX_INT
;
125 case MODE_PARTIAL_INT
: return MODE_COMPLEX_INT
;
126 case MODE_FLOAT
: return MODE_COMPLEX_FLOAT
;
128 error ("no complex class for class %s", mode_class_names
[c
]);
133 static enum mode_class
134 vector_class (enum mode_class cl
)
138 case MODE_INT
: return MODE_VECTOR_INT
;
139 case MODE_FLOAT
: return MODE_VECTOR_FLOAT
;
140 case MODE_FRACT
: return MODE_VECTOR_FRACT
;
141 case MODE_UFRACT
: return MODE_VECTOR_UFRACT
;
142 case MODE_ACCUM
: return MODE_VECTOR_ACCUM
;
143 case MODE_UACCUM
: return MODE_VECTOR_UACCUM
;
145 error ("no vector class for class %s", mode_class_names
[cl
]);
150 /* Utility routines. */
151 static inline struct mode_data
*
152 find_mode (const char *name
)
154 struct mode_data key
;
157 return (struct mode_data
*) htab_find (modes_by_name
, &key
);
160 static struct mode_data
*
161 new_mode (enum mode_class cl
, const char *name
,
162 const char *file
, unsigned int line
)
165 static unsigned int count
= 0;
167 m
= find_mode (name
);
170 error ("%s:%d: duplicate definition of mode \"%s\"",
171 trim_filename (file
), line
, name
);
172 error ("%s:%d: previous definition here", m
->file
, m
->line
);
176 m
= XNEW (struct mode_data
);
177 memcpy (m
, &blank_mode
, sizeof (struct mode_data
));
181 m
->file
= trim_filename (file
);
183 m
->counter
= count
++;
189 *htab_find_slot (modes_by_name
, m
, INSERT
) = m
;
195 hash_mode (const void *p
)
197 const struct mode_data
*m
= (const struct mode_data
*)p
;
198 return htab_hash_string (m
->name
);
202 eq_mode (const void *p
, const void *q
)
204 const struct mode_data
*a
= (const struct mode_data
*)p
;
205 const struct mode_data
*b
= (const struct mode_data
*)q
;
207 return !strcmp (a
->name
, b
->name
);
210 #define for_all_modes(C, M) \
211 for (C = 0; C < MAX_MODE_CLASS; C++) \
212 for (M = modes[C]; M; M = M->next)
214 static void ATTRIBUTE_UNUSED
215 new_adjust (const char *name
,
216 struct mode_adjust
**category
, const char *catname
,
217 const char *adjustment
,
218 enum mode_class required_class_from
,
219 enum mode_class required_class_to
,
220 const char *file
, unsigned int line
)
222 struct mode_data
*mode
= find_mode (name
);
223 struct mode_adjust
*a
;
225 file
= trim_filename (file
);
229 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
233 if (required_class_from
!= MODE_RANDOM
234 && (mode
->cl
< required_class_from
|| mode
->cl
> required_class_to
))
236 error ("%s:%d: mode \"%s\" is not among class {%s, %s}",
237 file
, line
, name
, mode_class_names
[required_class_from
] + 5,
238 mode_class_names
[required_class_to
] + 5);
242 for (a
= *category
; a
; a
= a
->next
)
245 error ("%s:%d: mode \"%s\" already has a %s adjustment",
246 file
, line
, name
, catname
);
247 error ("%s:%d: previous adjustment here", a
->file
, a
->line
);
251 a
= XNEW (struct mode_adjust
);
253 a
->adjustment
= adjustment
;
261 /* Diagnose failure to meet expectations in a partially filled out
263 enum requirement
{ SET
, UNSET
, OPTIONAL
};
265 #define validate_field_(mname, fname, req, val, unset, file, line) do { \
270 error ("%s:%d: (%s) field %s must be set", \
271 file, line, mname, fname); \
275 error ("%s:%d: (%s) field %s must not be set", \
276 file, line, mname, fname); \
282 #define validate_field(M, F) \
283 validate_field_(M->name, #F, r_##F, M->F, blank_mode.F, M->file, M->line)
286 validate_mode (struct mode_data
*m
,
287 enum requirement r_precision
,
288 enum requirement r_bytesize
,
289 enum requirement r_component
,
290 enum requirement r_ncomponents
,
291 enum requirement r_format
)
293 validate_field (m
, precision
);
294 validate_field (m
, bytesize
);
295 validate_field (m
, component
);
296 validate_field (m
, ncomponents
);
297 validate_field (m
, format
);
299 #undef validate_field
300 #undef validate_field_
302 /* Given a partially-filled-out mode structure, figure out what we can
303 and fill the rest of it in; die if it isn't enough. */
305 complete_mode (struct mode_data
*m
)
307 unsigned int alignment
;
311 error ("%s:%d: mode with no name", m
->file
, m
->line
);
314 if (m
->cl
== MAX_MODE_CLASS
)
316 error ("%s:%d: %smode has no mode class", m
->file
, m
->line
, m
->name
);
323 /* Nothing more need be said. */
324 if (!strcmp (m
->name
, "VOID"))
327 validate_mode (m
, UNSET
, UNSET
, UNSET
, UNSET
, UNSET
);
336 /* Again, nothing more need be said. For historical reasons,
337 the size of a CC mode is four units. */
338 validate_mode (m
, UNSET
, UNSET
, UNSET
, UNSET
, UNSET
);
347 case MODE_DECIMAL_FLOAT
:
352 /* A scalar mode must have a byte size, may have a bit size,
353 and must not have components. A float mode must have a
355 validate_mode (m
, OPTIONAL
, SET
, UNSET
, UNSET
,
356 (m
->cl
== MODE_FLOAT
|| m
->cl
== MODE_DECIMAL_FLOAT
)
364 /* Opaque modes have size and precision. */
365 validate_mode (m
, OPTIONAL
, SET
, UNSET
, UNSET
, UNSET
);
371 case MODE_PARTIAL_INT
:
372 /* A partial integer mode uses ->component to say what the
373 corresponding full-size integer mode is, and may also
374 specify a bit size. */
375 validate_mode (m
, OPTIONAL
, UNSET
, SET
, UNSET
, UNSET
);
377 m
->bytesize
= m
->component
->bytesize
;
382 case MODE_COMPLEX_INT
:
383 case MODE_COMPLEX_FLOAT
:
384 /* Complex modes should have a component indicated, but no more. */
385 validate_mode (m
, UNSET
, UNSET
, SET
, UNSET
, UNSET
);
387 if (m
->component
->precision
!= (unsigned int)-1)
388 m
->precision
= 2 * m
->component
->precision
;
389 m
->bytesize
= 2 * m
->component
->bytesize
;
392 case MODE_VECTOR_BOOL
:
393 validate_mode (m
, UNSET
, SET
, SET
, SET
, UNSET
);
396 case MODE_VECTOR_INT
:
397 case MODE_VECTOR_FLOAT
:
398 case MODE_VECTOR_FRACT
:
399 case MODE_VECTOR_UFRACT
:
400 case MODE_VECTOR_ACCUM
:
401 case MODE_VECTOR_UACCUM
:
402 /* Vector modes should have a component and a number of components. */
403 validate_mode (m
, UNSET
, UNSET
, SET
, SET
, UNSET
);
404 if (m
->component
->precision
!= (unsigned int)-1)
405 m
->precision
= m
->ncomponents
* m
->component
->precision
;
406 m
->bytesize
= m
->ncomponents
* m
->component
->bytesize
;
413 /* If not already specified, the mode alignment defaults to the largest
414 power of two that divides the size of the object. Complex types are
415 not more aligned than their contents. */
416 if (m
->cl
== MODE_COMPLEX_INT
|| m
->cl
== MODE_COMPLEX_FLOAT
)
417 alignment
= m
->component
->bytesize
;
419 alignment
= m
->bytesize
;
421 m
->alignment
= alignment
& (~alignment
+ 1);
423 /* If this mode has components, make the component mode point back
424 to this mode, for the sake of adjustments. */
427 m
->next_cont
= m
->component
->contained
;
428 m
->component
->contained
= m
;
433 complete_all_modes (void)
438 for_all_modes (cl
, m
)
442 /* For each mode in class CLASS, construct a corresponding complex mode. */
443 #define COMPLEX_MODES(C) make_complex_modes (MODE_##C, __FILE__, __LINE__)
445 make_complex_modes (enum mode_class cl
,
446 const char *file
, unsigned int line
)
450 enum mode_class cclass
= complex_class (cl
);
452 if (cclass
== MODE_RANDOM
)
455 for (m
= modes
[cl
]; m
; m
= m
->next
)
460 /* Skip BImode. FIXME: BImode probably shouldn't be MODE_INT. */
464 m_len
= strlen (m
->name
);
465 /* The leading "1 +" is in case we prepend a "C" below. */
466 buf
= (char *) xmalloc (1 + m_len
+ 1);
468 /* Float complex modes are named SCmode, etc.
469 Int complex modes are named CSImode, etc.
470 This inconsistency should be eliminated. */
472 if (cl
== MODE_FLOAT
)
474 memcpy (buf
, m
->name
, m_len
+ 1);
475 p
= strchr (buf
, 'F');
476 if (p
== 0 && strchr (buf
, 'D') == 0)
478 error ("%s:%d: float mode \"%s\" has no 'F' or 'D'",
479 m
->file
, m
->line
, m
->name
);
489 memcpy (buf
+ 1, m
->name
, m_len
+ 1);
492 c
= new_mode (cclass
, buf
, file
, line
);
498 /* For all modes in class CL, construct vector modes of width WIDTH,
499 having as many components as necessary. ORDER is the sorting order
500 of the mode, with smaller numbers indicating a higher priority. */
501 #define VECTOR_MODES_WITH_PREFIX(PREFIX, C, W, ORDER) \
502 make_vector_modes (MODE_##C, #PREFIX, W, ORDER, __FILE__, __LINE__)
503 #define VECTOR_MODES(C, W) VECTOR_MODES_WITH_PREFIX (V, C, W, 0)
504 static void ATTRIBUTE_UNUSED
505 make_vector_modes (enum mode_class cl
, const char *prefix
, unsigned int width
,
506 unsigned int order
, const char *file
, unsigned int line
)
510 /* Big enough for a 32-bit UINT_MAX plus the text. */
512 unsigned int ncomponents
;
513 enum mode_class vclass
= vector_class (cl
);
515 if (vclass
== MODE_RANDOM
)
518 for (m
= modes
[cl
]; m
; m
= m
->next
)
520 /* Do not construct vector modes with only one element, or
521 vector modes where the element size doesn't divide the full
523 ncomponents
= width
/ m
->bytesize
;
526 if (width
% m
->bytesize
)
529 /* Skip QFmode and BImode. FIXME: this special case should
531 if (cl
== MODE_FLOAT
&& m
->bytesize
== 1)
536 if ((size_t) snprintf (buf
, sizeof buf
, "%s%u%s", prefix
,
537 ncomponents
, m
->name
) >= sizeof buf
)
539 error ("%s:%d: mode name \"%s\" is too long",
540 m
->file
, m
->line
, m
->name
);
544 v
= new_mode (vclass
, xstrdup (buf
), file
, line
);
547 v
->ncomponents
= ncomponents
;
551 /* Create a vector of booleans called NAME with COUNT elements and
552 BYTESIZE bytes in total. */
553 #define VECTOR_BOOL_MODE(NAME, COUNT, COMPONENT, BYTESIZE) \
554 make_vector_bool_mode (#NAME, COUNT, #COMPONENT, BYTESIZE, \
556 static void ATTRIBUTE_UNUSED
557 make_vector_bool_mode (const char *name
, unsigned int count
,
558 const char *component
, unsigned int bytesize
,
559 const char *file
, unsigned int line
)
561 struct mode_data
*m
= find_mode (component
);
564 error ("%s:%d: no mode \"%s\"", file
, line
, component
);
568 struct mode_data
*v
= new_mode (MODE_VECTOR_BOOL
, name
, file
, line
);
570 v
->ncomponents
= count
;
571 v
->bytesize
= bytesize
;
576 #define _SPECIAL_MODE(C, N) \
577 make_special_mode (MODE_##C, #N, __FILE__, __LINE__)
578 #define RANDOM_MODE(N) _SPECIAL_MODE (RANDOM, N)
579 #define CC_MODE(N) _SPECIAL_MODE (CC, N)
582 make_special_mode (enum mode_class cl
, const char *name
,
583 const char *file
, unsigned int line
)
585 new_mode (cl
, name
, file
, line
);
588 #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y)
589 #define FRACTIONAL_INT_MODE(N, B, Y) \
590 make_int_mode (#N, B, Y, __FILE__, __LINE__)
593 make_int_mode (const char *name
,
594 unsigned int precision
, unsigned int bytesize
,
595 const char *file
, unsigned int line
)
597 struct mode_data
*m
= new_mode (MODE_INT
, name
, file
, line
);
598 m
->bytesize
= bytesize
;
599 m
->precision
= precision
;
602 #define BOOL_MODE(N, B, Y) \
603 make_bool_mode (#N, B, Y, __FILE__, __LINE__)
606 make_bool_mode (const char *name
,
607 unsigned int precision
, unsigned int bytesize
,
608 const char *file
, unsigned int line
)
610 struct mode_data
*m
= new_mode (MODE_INT
, name
, file
, line
);
611 m
->bytesize
= bytesize
;
612 m
->precision
= precision
;
616 #define OPAQUE_MODE(N, B) \
617 make_opaque_mode (#N, -1U, B, __FILE__, __LINE__)
619 static void ATTRIBUTE_UNUSED
620 make_opaque_mode (const char *name
,
621 unsigned int precision
,
622 unsigned int bytesize
,
623 const char *file
, unsigned int line
)
625 struct mode_data
*m
= new_mode (MODE_OPAQUE
, name
, file
, line
);
626 m
->bytesize
= bytesize
;
627 m
->precision
= precision
;
630 #define FRACT_MODE(N, Y, F) \
631 make_fixed_point_mode (MODE_FRACT, #N, Y, 0, F, __FILE__, __LINE__)
633 #define UFRACT_MODE(N, Y, F) \
634 make_fixed_point_mode (MODE_UFRACT, #N, Y, 0, F, __FILE__, __LINE__)
636 #define ACCUM_MODE(N, Y, I, F) \
637 make_fixed_point_mode (MODE_ACCUM, #N, Y, I, F, __FILE__, __LINE__)
639 #define UACCUM_MODE(N, Y, I, F) \
640 make_fixed_point_mode (MODE_UACCUM, #N, Y, I, F, __FILE__, __LINE__)
642 /* Create a fixed-point mode by setting CL, NAME, BYTESIZE, IBIT, FBIT,
646 make_fixed_point_mode (enum mode_class cl
,
648 unsigned int bytesize
,
651 const char *file
, unsigned int line
)
653 struct mode_data
*m
= new_mode (cl
, name
, file
, line
);
654 m
->bytesize
= bytesize
;
659 #define FLOAT_MODE(N, Y, F) FRACTIONAL_FLOAT_MODE (N, -1U, Y, F)
660 #define FRACTIONAL_FLOAT_MODE(N, B, Y, F) \
661 make_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
664 make_float_mode (const char *name
,
665 unsigned int precision
, unsigned int bytesize
,
667 const char *file
, unsigned int line
)
669 struct mode_data
*m
= new_mode (MODE_FLOAT
, name
, file
, line
);
670 m
->bytesize
= bytesize
;
671 m
->precision
= precision
;
675 #define DECIMAL_FLOAT_MODE(N, Y, F) \
676 FRACTIONAL_DECIMAL_FLOAT_MODE (N, -1U, Y, F)
677 #define FRACTIONAL_DECIMAL_FLOAT_MODE(N, B, Y, F) \
678 make_decimal_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
681 make_decimal_float_mode (const char *name
,
682 unsigned int precision
, unsigned int bytesize
,
684 const char *file
, unsigned int line
)
686 struct mode_data
*m
= new_mode (MODE_DECIMAL_FLOAT
, name
, file
, line
);
687 m
->bytesize
= bytesize
;
688 m
->precision
= precision
;
692 #define RESET_FLOAT_FORMAT(N, F) \
693 reset_float_format (#N, #F, __FILE__, __LINE__)
694 static void ATTRIBUTE_UNUSED
695 reset_float_format (const char *name
, const char *format
,
696 const char *file
, unsigned int line
)
698 struct mode_data
*m
= find_mode (name
);
701 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
704 if (m
->cl
!= MODE_FLOAT
&& m
->cl
!= MODE_DECIMAL_FLOAT
)
706 error ("%s:%d: mode \"%s\" is not a FLOAT class", file
, line
, name
);
712 /* __intN support. */
713 #define INT_N(M,PREC) \
714 make_int_n (#M, PREC, __FILE__, __LINE__)
715 static void ATTRIBUTE_UNUSED
716 make_int_n (const char *m
, int bitsize
,
717 const char *file
, unsigned int line
)
719 struct mode_data
*component
= find_mode (m
);
722 error ("%s:%d: no mode \"%s\"", file
, line
, m
);
725 if (component
->cl
!= MODE_INT
726 && component
->cl
!= MODE_PARTIAL_INT
)
728 error ("%s:%d: mode \"%s\" is not class INT or PARTIAL_INT", file
, line
, m
);
731 if (component
->int_n
!= 0)
733 error ("%s:%d: mode \"%s\" already has an intN", file
, line
, m
);
737 component
->int_n
= bitsize
;
740 /* Partial integer modes are specified by relation to a full integer
742 #define PARTIAL_INT_MODE(M,PREC,NAME) \
743 make_partial_integer_mode (#M, #NAME, PREC, __FILE__, __LINE__)
744 static void ATTRIBUTE_UNUSED
745 make_partial_integer_mode (const char *base
, const char *name
,
746 unsigned int precision
,
747 const char *file
, unsigned int line
)
750 struct mode_data
*component
= find_mode (base
);
753 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
756 if (component
->cl
!= MODE_INT
)
758 error ("%s:%d: mode \"%s\" is not class INT", file
, line
, name
);
762 m
= new_mode (MODE_PARTIAL_INT
, name
, file
, line
);
763 m
->precision
= precision
;
764 m
->component
= component
;
767 /* A single vector mode can be specified by naming its component
768 mode and the number of components. */
769 #define VECTOR_MODE_WITH_PREFIX(PREFIX, C, M, N, ORDER) \
770 make_vector_mode (MODE_##C, #PREFIX, #M, N, ORDER, __FILE__, __LINE__);
771 #define VECTOR_MODE(C, M, N) VECTOR_MODE_WITH_PREFIX(V, C, M, N, 0);
772 static void ATTRIBUTE_UNUSED
773 make_vector_mode (enum mode_class bclass
,
776 unsigned int ncomponents
,
778 const char *file
, unsigned int line
)
781 enum mode_class vclass
= vector_class (bclass
);
782 struct mode_data
*component
= find_mode (base
);
785 if (vclass
== MODE_RANDOM
)
789 error ("%s:%d: no mode \"%s\"", file
, line
, base
);
792 if (component
->cl
!= bclass
793 && (component
->cl
!= MODE_PARTIAL_INT
794 || bclass
!= MODE_INT
))
796 error ("%s:%d: mode \"%s\" is not class %s",
797 file
, line
, base
, mode_class_names
[bclass
] + 5);
801 if ((size_t)snprintf (namebuf
, sizeof namebuf
, "%s%u%s", prefix
,
802 ncomponents
, base
) >= sizeof namebuf
)
804 error ("%s:%d: mode name \"%s\" is too long",
809 v
= new_mode (vclass
, xstrdup (namebuf
), file
, line
);
811 v
->ncomponents
= ncomponents
;
812 v
->component
= component
;
816 #define _ADD_ADJUST(A, M, X, C1, C2) \
817 new_adjust (#M, &adj_##A, #A, #X, MODE_##C1, MODE_##C2, __FILE__, __LINE__)
819 #define ADJUST_NUNITS(M, X) _ADD_ADJUST (nunits, M, X, RANDOM, RANDOM)
820 #define ADJUST_BYTESIZE(M, X) _ADD_ADJUST (bytesize, M, X, RANDOM, RANDOM)
821 #define ADJUST_ALIGNMENT(M, X) _ADD_ADJUST (alignment, M, X, RANDOM, RANDOM)
822 #define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST (format, M, X, FLOAT, FLOAT)
823 #define ADJUST_IBIT(M, X) _ADD_ADJUST (ibit, M, X, ACCUM, UACCUM)
824 #define ADJUST_FBIT(M, X) _ADD_ADJUST (fbit, M, X, FRACT, UACCUM)
826 static int bits_per_unit
;
827 static int max_bitsize_mode_any_int
;
828 static int max_bitsize_mode_any_mode
;
833 #include "machmode.def"
835 /* So put the default value unless the target needs a non standard
838 bits_per_unit
= BITS_PER_UNIT
;
843 #ifdef MAX_BITSIZE_MODE_ANY_INT
844 max_bitsize_mode_any_int
= MAX_BITSIZE_MODE_ANY_INT
;
846 max_bitsize_mode_any_int
= 0;
849 #ifdef MAX_BITSIZE_MODE_ANY_MODE
850 max_bitsize_mode_any_mode
= MAX_BITSIZE_MODE_ANY_MODE
;
852 max_bitsize_mode_any_mode
= 0;
856 #ifndef NUM_POLY_INT_COEFFS
857 #define NUM_POLY_INT_COEFFS 1
862 /* Sort a list of modes into the order needed for the WIDER field:
863 major sort by precision, minor sort by component precision.
866 QI < HI < SI < DI < TI
867 V4QI < V2HI < V8QI < V4HI < V2SI.
869 If the precision is not set, sort by the bytesize. A mode with
870 precision set gets sorted before a mode without precision set, if
871 they have the same bytesize; this is the right thing because
872 the precision must always be smaller than the bytesize * BITS_PER_UNIT.
873 We don't have to do anything special to get this done -- an unset
874 precision shows up as (unsigned int)-1, i.e. UINT_MAX. */
876 cmp_modes (const void *a
, const void *b
)
878 const struct mode_data
*const m
= *(const struct mode_data
*const*)a
;
879 const struct mode_data
*const n
= *(const struct mode_data
*const*)b
;
881 if (m
->order
> n
->order
)
883 else if (m
->order
< n
->order
)
886 if (m
->bytesize
> n
->bytesize
)
888 else if (m
->bytesize
< n
->bytesize
)
891 if (m
->precision
> n
->precision
)
893 else if (m
->precision
< n
->precision
)
896 if (!m
->component
&& !n
->component
)
898 if (m
->counter
< n
->counter
)
904 if (m
->component
->bytesize
> n
->component
->bytesize
)
906 else if (m
->component
->bytesize
< n
->component
->bytesize
)
909 if (m
->component
->precision
> n
->component
->precision
)
911 else if (m
->component
->precision
< n
->component
->precision
)
914 if (m
->counter
< n
->counter
)
921 calc_wider_mode (void)
925 struct mode_data
**sortbuf
;
926 unsigned int max_n_modes
= 0;
929 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
930 max_n_modes
= MAX (max_n_modes
, n_modes
[c
]);
932 /* Allocate max_n_modes + 1 entries to leave room for the extra null
933 pointer assigned after the qsort call below. */
934 sortbuf
= XALLOCAVEC (struct mode_data
*, max_n_modes
+ 1);
936 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
938 /* "wider" is not meaningful for MODE_RANDOM and MODE_CC.
939 However, we want these in textual order, and we have
940 precisely the reverse. */
941 if (c
== MODE_RANDOM
|| c
== MODE_CC
)
943 struct mode_data
*prev
, *next
;
945 for (prev
= 0, m
= modes
[c
]; m
; m
= next
)
947 m
->wider
= void_mode
;
949 /* this is nreverse */
961 for (i
= 0, m
= modes
[c
]; m
; i
++, m
= m
->next
)
964 (qsort
) (sortbuf
, i
, sizeof (struct mode_data
*), cmp_modes
);
967 for (j
= 0; j
< i
; j
++)
969 sortbuf
[j
]->next
= sortbuf
[j
+ 1];
970 if (c
== MODE_PARTIAL_INT
)
971 sortbuf
[j
]->wider
= sortbuf
[j
]->component
;
973 sortbuf
[j
]->wider
= sortbuf
[j
]->next
;
976 modes
[c
] = sortbuf
[0];
981 /* Text to add to the constant part of a poly_int_pod initializer in
982 order to fill out te whole structure. */
983 #if NUM_POLY_INT_COEFFS == 1
984 #define ZERO_COEFFS ""
985 #elif NUM_POLY_INT_COEFFS == 2
986 #define ZERO_COEFFS ", 0"
988 #error "Unknown value of NUM_POLY_INT_COEFFS"
991 /* Output routines. */
993 #define tagged_printf(FMT, ARG, TAG) do { \
994 int count_ = printf (" " FMT ",", ARG); \
995 printf ("%*s/* %s */\n", 27 - count_, "", TAG); \
998 #define print_decl(TYPE, NAME, ASIZE) \
999 puts ("\nconst " TYPE " " NAME "[" ASIZE "] =\n{");
1001 #define print_maybe_const_decl(TYPE, NAME, ASIZE, NEEDS_ADJ) \
1002 printf ("\n" TYPE " " NAME "[" ASIZE "] = \n{\n", \
1003 NEEDS_ADJ ? "" : "const ")
1005 #define print_closer() puts ("};")
1007 /* Compute the max bitsize of some of the classes of integers. It may
1008 be that there are needs for the other integer classes, and this
1009 code is easy to extend. */
1013 unsigned int max
, mmax
;
1014 struct mode_data
*i
;
1019 printf ("#define BITS_PER_UNIT (%d)\n", bits_per_unit
);
1021 if (max_bitsize_mode_any_int
== 0)
1023 for (max
= 1, i
= modes
[MODE_INT
]; i
; i
= i
->next
)
1024 if (max
< i
->bytesize
)
1027 for (max
= 1, i
= modes
[MODE_PARTIAL_INT
]; i
; i
= i
->next
)
1028 if (max
< i
->bytesize
)
1032 printf ("#define MAX_BITSIZE_MODE_ANY_INT (%d*BITS_PER_UNIT)\n", mmax
);
1035 printf ("#define MAX_BITSIZE_MODE_ANY_INT %d\n", max_bitsize_mode_any_int
);
1037 if (max_bitsize_mode_any_mode
== 0)
1040 for (j
= 0; j
< MAX_MODE_CLASS
; j
++)
1041 for (i
= modes
[j
]; i
; i
= i
->next
)
1042 if (mmax
< i
->bytesize
)
1044 printf ("#define MAX_BITSIZE_MODE_ANY_MODE (%d*BITS_PER_UNIT)\n", mmax
);
1047 printf ("#define MAX_BITSIZE_MODE_ANY_MODE %d\n",
1048 max_bitsize_mode_any_mode
);
1051 /* Emit mode_size_inline routine into insn-modes.h header. */
1053 emit_mode_size_inline (void)
1056 struct mode_adjust
*a
;
1057 struct mode_data
*m
;
1059 /* Size adjustments must be propagated to all containing modes. */
1060 for (a
= adj_bytesize
; a
; a
= a
->next
)
1062 a
->mode
->need_bytesize_adj
= true;
1063 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1064 m
->need_bytesize_adj
= true;
1067 /* Changing the number of units by a factor of X also changes the size
1068 by a factor of X. */
1069 for (mode_adjust
*a
= adj_nunits
; a
; a
= a
->next
)
1070 a
->mode
->need_bytesize_adj
= true;
1073 #ifdef __cplusplus\n\
1074 inline __attribute__((__always_inline__))\n\
1076 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1079 mode_size_inline (machine_mode mode)\n\
1081 extern %spoly_uint16_pod mode_size[NUM_MACHINE_MODES];\n\
1082 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1084 {\n", adj_nunits
|| adj_bytesize
? "" : "const ");
1086 for_all_modes (c
, m
)
1087 if (!m
->need_bytesize_adj
)
1088 printf (" case E_%smode: return %u;\n", m
->name
, m
->bytesize
);
1091 default: return mode_size[mode];\n\
1096 /* Emit mode_nunits_inline routine into insn-modes.h header. */
1098 emit_mode_nunits_inline (void)
1101 struct mode_data
*m
;
1103 for (mode_adjust
*a
= adj_nunits
; a
; a
= a
->next
)
1104 a
->mode
->need_nunits_adj
= true;
1107 #ifdef __cplusplus\n\
1108 inline __attribute__((__always_inline__))\n\
1110 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1113 mode_nunits_inline (machine_mode mode)\n\
1115 extern %spoly_uint16_pod mode_nunits[NUM_MACHINE_MODES];\n\
1117 {\n", adj_nunits
? "" : "const ");
1119 for_all_modes (c
, m
)
1120 if (!m
->need_nunits_adj
)
1121 printf (" case E_%smode: return %u;\n", m
->name
, m
->ncomponents
);
1124 default: return mode_nunits[mode];\n\
1129 /* Emit mode_inner_inline routine into insn-modes.h header. */
1131 emit_mode_inner_inline (void)
1134 struct mode_data
*m
;
1137 #ifdef __cplusplus\n\
1138 inline __attribute__((__always_inline__))\n\
1140 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1143 mode_inner_inline (machine_mode mode)\n\
1145 extern const unsigned char mode_inner[NUM_MACHINE_MODES];\n\
1146 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1150 for_all_modes (c
, m
)
1151 printf (" case E_%smode: return E_%smode;\n", m
->name
,
1152 c
!= MODE_PARTIAL_INT
&& m
->component
1153 ? m
->component
->name
: m
->name
);
1156 default: return mode_inner[mode];\n\
1161 /* Emit mode_unit_size_inline routine into insn-modes.h header. */
1163 emit_mode_unit_size_inline (void)
1166 struct mode_data
*m
;
1169 #ifdef __cplusplus\n\
1170 inline __attribute__((__always_inline__))\n\
1172 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1175 mode_unit_size_inline (machine_mode mode)\n\
1177 extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES];\
1179 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1183 for_all_modes (c
, m
)
1185 const char *name
= m
->name
;
1186 struct mode_data
*m2
= m
;
1187 if (c
!= MODE_PARTIAL_INT
&& m2
->component
)
1189 if (!m2
->need_bytesize_adj
)
1190 printf (" case E_%smode: return %u;\n", name
, m2
->bytesize
);
1194 default: return mode_unit_size[mode];\n\
1199 /* Emit mode_unit_precision_inline routine into insn-modes.h header. */
1201 emit_mode_unit_precision_inline (void)
1204 struct mode_data
*m
;
1207 #ifdef __cplusplus\n\
1208 inline __attribute__((__always_inline__))\n\
1210 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1213 mode_unit_precision_inline (machine_mode mode)\n\
1215 extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES];\n\
1216 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1220 for_all_modes (c
, m
)
1222 struct mode_data
*m2
1223 = (c
!= MODE_PARTIAL_INT
&& m
->component
) ? m
->component
: m
;
1224 if (m2
->precision
!= (unsigned int)-1)
1225 printf (" case E_%smode: return %u;\n", m
->name
, m2
->precision
);
1227 printf (" case E_%smode: return %u*BITS_PER_UNIT;\n",
1228 m
->name
, m2
->bytesize
);
1232 default: return mode_unit_precision[mode];\n\
1237 /* Return the best machine mode class for MODE, or null if machine_mode
1241 get_mode_class (struct mode_data
*mode
)
1246 case MODE_PARTIAL_INT
:
1247 return "scalar_int_mode";
1253 return "scalar_mode";
1256 case MODE_DECIMAL_FLOAT
:
1257 return "scalar_float_mode";
1259 case MODE_COMPLEX_INT
:
1260 case MODE_COMPLEX_FLOAT
:
1261 return "complex_mode";
1269 emit_insn_modes_h (void)
1272 struct mode_data
*m
, *first
, *last
;
1273 int n_int_n_ents
= 0;
1275 printf ("/* Generated automatically from machmode.def%s%s\n",
1276 HAVE_EXTRA_MODES
? " and " : "",
1282 #ifndef GCC_INSN_MODES_H\n\
1283 #define GCC_INSN_MODES_H\n\
1285 enum machine_mode\n{");
1287 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1288 for (m
= modes
[c
]; m
; m
= m
->next
)
1290 int count_
= printf (" E_%smode,", m
->name
);
1291 printf ("%*s/* %s:%d */\n", 27 - count_
, "",
1292 trim_filename (m
->file
), m
->line
);
1293 printf ("#define HAVE_%smode\n", m
->name
);
1294 printf ("#ifdef USE_ENUM_MODES\n");
1295 printf ("#define %smode E_%smode\n", m
->name
, m
->name
);
1297 if (const char *mode_class
= get_mode_class (m
))
1298 printf ("#define %smode (%s ((%s::from_int) E_%smode))\n",
1299 m
->name
, mode_class
, mode_class
, m
->name
);
1301 printf ("#define %smode ((void) 0, E_%smode)\n",
1303 printf ("#endif\n");
1306 puts (" MAX_MACHINE_MODE,\n");
1308 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1312 for (m
= first
; m
; last
= m
, m
= m
->next
)
1315 /* Don't use BImode for MIN_MODE_INT, since otherwise the middle
1316 end will try to use it for bitfields in structures and the
1317 like, which we do not want. Only the target md file should
1318 generate BImode widgets. Since some targets such as ARM/MVE
1319 define boolean modes with multiple bits, handle those too. */
1320 if (first
&& first
->boolean
)
1322 struct mode_data
*last_bool
= first
;
1323 printf (" MIN_MODE_BOOL = E_%smode,\n", first
->name
);
1325 while (first
&& first
->boolean
)
1328 first
= first
->next
;
1331 printf (" MAX_MODE_BOOL = E_%smode,\n\n", last_bool
->name
);
1335 printf (" MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n",
1336 mode_class_names
[c
], first
->name
,
1337 mode_class_names
[c
], last
->name
);
1339 printf (" MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n",
1340 mode_class_names
[c
], void_mode
->name
,
1341 mode_class_names
[c
], void_mode
->name
);
1345 NUM_MACHINE_MODES = MAX_MACHINE_MODE\n\
1348 /* Define a NUM_* macro for each mode class, giving the number of modes
1350 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1352 printf ("#define NUM_%s ", mode_class_names
[c
]);
1354 printf ("(MAX_%s - MIN_%s + 1)\n", mode_class_names
[c
],
1355 mode_class_names
[c
]);
1361 /* I can't think of a better idea, can you? */
1362 printf ("#define CONST_MODE_NUNITS%s\n", adj_nunits
? "" : " const");
1363 printf ("#define CONST_MODE_PRECISION%s\n", adj_nunits
? "" : " const");
1364 printf ("#define CONST_MODE_SIZE%s\n",
1365 adj_bytesize
|| adj_nunits
? "" : " const");
1366 printf ("#define CONST_MODE_UNIT_SIZE%s\n", adj_bytesize
? "" : " const");
1367 printf ("#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment
? "" : " const");
1368 #if 0 /* disabled for backward compatibility, temporary */
1369 printf ("#define CONST_REAL_FORMAT_FOR_MODE%s\n", adj_format
? "" :" const");
1371 printf ("#define CONST_MODE_IBIT%s\n", adj_ibit
? "" : " const");
1372 printf ("#define CONST_MODE_FBIT%s\n", adj_fbit
? "" : " const");
1373 printf ("#define CONST_MODE_MASK%s\n", adj_nunits
? "" : " const");
1376 for_all_modes (c
, m
)
1380 printf ("#define NUM_INT_N_ENTS %d\n", n_int_n_ents
);
1382 printf ("#define NUM_POLY_INT_COEFFS %d\n", NUM_POLY_INT_COEFFS
);
1386 #endif /* insn-modes.h */");
1390 emit_insn_modes_inline_h (void)
1392 printf ("/* Generated automatically from machmode.def%s%s\n",
1393 HAVE_EXTRA_MODES
? " and " : "",
1399 #ifndef GCC_INSN_MODES_INLINE_H\n\
1400 #define GCC_INSN_MODES_INLINE_H");
1402 puts ("\n#if !defined (USED_FOR_TARGET) && GCC_VERSION >= 4001\n");
1403 emit_mode_size_inline ();
1404 emit_mode_nunits_inline ();
1405 emit_mode_inner_inline ();
1406 emit_mode_unit_size_inline ();
1407 emit_mode_unit_precision_inline ();
1408 puts ("#endif /* GCC_VERSION >= 4001 */");
1412 #endif /* insn-modes-inline.h */");
1416 emit_insn_modes_c_header (void)
1418 printf ("/* Generated automatically from machmode.def%s%s\n",
1419 HAVE_EXTRA_MODES
? " and " : "",
1425 #include \"config.h\"\n\
1426 #include \"system.h\"\n\
1427 #include \"coretypes.h\"\n\
1428 #include \"tm.h\"\n\
1429 #include \"real.h\"");
1433 emit_min_insn_modes_c_header (void)
1435 printf ("/* Generated automatically from machmode.def%s%s\n",
1436 HAVE_EXTRA_MODES
? " and " : "",
1442 #include \"bconfig.h\"\n\
1443 #include \"system.h\"\n\
1444 #include \"coretypes.h\"");
1448 emit_mode_name (void)
1451 struct mode_data
*m
;
1453 print_decl ("char *const", "mode_name", "NUM_MACHINE_MODES");
1455 for_all_modes (c
, m
)
1456 printf (" \"%s\",\n", m
->name
);
1462 emit_mode_class (void)
1465 struct mode_data
*m
;
1467 print_decl ("unsigned char", "mode_class", "NUM_MACHINE_MODES");
1469 for_all_modes (c
, m
)
1470 tagged_printf ("%s", mode_class_names
[m
->cl
], m
->name
);
1476 emit_mode_precision (void)
1479 struct mode_data
*m
;
1481 print_maybe_const_decl ("%spoly_uint16_pod", "mode_precision",
1482 "NUM_MACHINE_MODES", adj_nunits
);
1484 for_all_modes (c
, m
)
1485 if (m
->precision
!= (unsigned int)-1)
1486 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->precision
, m
->name
);
1488 tagged_printf ("{ %u * BITS_PER_UNIT" ZERO_COEFFS
" }",
1489 m
->bytesize
, m
->name
);
1495 emit_mode_size (void)
1498 struct mode_data
*m
;
1500 print_maybe_const_decl ("%spoly_uint16_pod", "mode_size",
1501 "NUM_MACHINE_MODES", adj_nunits
|| adj_bytesize
);
1503 for_all_modes (c
, m
)
1504 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->bytesize
, m
->name
);
1510 emit_mode_nunits (void)
1513 struct mode_data
*m
;
1515 print_maybe_const_decl ("%spoly_uint16_pod", "mode_nunits",
1516 "NUM_MACHINE_MODES", adj_nunits
);
1518 for_all_modes (c
, m
)
1519 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->ncomponents
, m
->name
);
1525 emit_mode_wider (void)
1528 struct mode_data
*m
;
1530 print_decl ("unsigned char", "mode_next", "NUM_MACHINE_MODES");
1532 for_all_modes (c
, m
)
1533 tagged_printf ("E_%smode",
1534 m
->wider
? m
->wider
->name
: void_mode
->name
,
1538 print_decl ("unsigned char", "mode_wider", "NUM_MACHINE_MODES");
1540 for_all_modes (c
, m
)
1542 struct mode_data
*m2
= 0;
1544 if (m
->cl
== MODE_INT
1545 || m
->cl
== MODE_PARTIAL_INT
1546 || m
->cl
== MODE_FLOAT
1547 || m
->cl
== MODE_DECIMAL_FLOAT
1548 || m
->cl
== MODE_COMPLEX_FLOAT
1549 || m
->cl
== MODE_FRACT
1550 || m
->cl
== MODE_UFRACT
1551 || m
->cl
== MODE_ACCUM
1552 || m
->cl
== MODE_UACCUM
)
1553 for (m2
= m
->wider
; m2
&& m2
!= void_mode
; m2
= m2
->wider
)
1555 if (m2
->bytesize
== m
->bytesize
1556 && m2
->precision
== m
->precision
)
1561 if (m2
== void_mode
)
1563 tagged_printf ("E_%smode",
1564 m2
? m2
->name
: void_mode
->name
,
1569 print_decl ("unsigned char", "mode_2xwider", "NUM_MACHINE_MODES");
1571 for_all_modes (c
, m
)
1573 struct mode_data
* m2
;
1576 m2
&& m2
!= void_mode
;
1579 if (m2
->bytesize
< 2 * m
->bytesize
)
1581 if (m
->precision
!= (unsigned int) -1)
1583 if (m2
->precision
!= 2 * m
->precision
)
1588 if (m2
->precision
!= (unsigned int) -1)
1592 /* For vectors we want twice the number of components,
1593 with the same element type. */
1594 if (m
->cl
== MODE_VECTOR_BOOL
1595 || m
->cl
== MODE_VECTOR_INT
1596 || m
->cl
== MODE_VECTOR_FLOAT
1597 || m
->cl
== MODE_VECTOR_FRACT
1598 || m
->cl
== MODE_VECTOR_UFRACT
1599 || m
->cl
== MODE_VECTOR_ACCUM
1600 || m
->cl
== MODE_VECTOR_UACCUM
)
1602 if (m2
->ncomponents
!= 2 * m
->ncomponents
)
1604 if (m
->component
!= m2
->component
)
1610 if (m2
== void_mode
)
1612 tagged_printf ("E_%smode",
1613 m2
? m2
->name
: void_mode
->name
,
1621 emit_mode_complex (void)
1624 struct mode_data
*m
;
1626 print_decl ("unsigned char", "mode_complex", "NUM_MACHINE_MODES");
1628 for_all_modes (c
, m
)
1629 tagged_printf ("E_%smode",
1630 m
->complex ? m
->complex->name
: void_mode
->name
,
1637 emit_mode_mask (void)
1640 struct mode_data
*m
;
1642 print_maybe_const_decl ("%sunsigned HOST_WIDE_INT", "mode_mask_array",
1643 "NUM_MACHINE_MODES", adj_nunits
);
1645 #define MODE_MASK(m) \\\n\
1646 ((m) >= HOST_BITS_PER_WIDE_INT) \\\n\
1647 ? HOST_WIDE_INT_M1U \\\n\
1648 : (HOST_WIDE_INT_1U << (m)) - 1\n");
1650 for_all_modes (c
, m
)
1651 if (m
->precision
!= (unsigned int)-1)
1652 tagged_printf ("MODE_MASK (%u)", m
->precision
, m
->name
);
1654 tagged_printf ("MODE_MASK (%u*BITS_PER_UNIT)", m
->bytesize
, m
->name
);
1656 puts ("#undef MODE_MASK");
1661 emit_mode_inner (void)
1664 struct mode_data
*m
;
1666 print_decl ("unsigned char", "mode_inner", "NUM_MACHINE_MODES");
1668 for_all_modes (c
, m
)
1669 tagged_printf ("E_%smode",
1670 c
!= MODE_PARTIAL_INT
&& m
->component
1671 ? m
->component
->name
: m
->name
,
1677 /* Emit mode_unit_size array into insn-modes.cc file. */
1679 emit_mode_unit_size (void)
1682 struct mode_data
*m
;
1684 print_maybe_const_decl ("%sunsigned char", "mode_unit_size",
1685 "NUM_MACHINE_MODES", adj_bytesize
);
1687 for_all_modes (c
, m
)
1688 tagged_printf ("%u",
1689 c
!= MODE_PARTIAL_INT
&& m
->component
1690 ? m
->component
->bytesize
: m
->bytesize
, m
->name
);
1695 /* Emit mode_unit_precision array into insn-modes.cc file. */
1697 emit_mode_unit_precision (void)
1700 struct mode_data
*m
;
1702 print_decl ("unsigned short", "mode_unit_precision", "NUM_MACHINE_MODES");
1704 for_all_modes (c
, m
)
1706 struct mode_data
*m2
= (c
!= MODE_PARTIAL_INT
&& m
->component
) ?
1708 if (m2
->precision
!= (unsigned int)-1)
1709 tagged_printf ("%u", m2
->precision
, m
->name
);
1711 tagged_printf ("%u*BITS_PER_UNIT", m2
->bytesize
, m
->name
);
1719 emit_mode_base_align (void)
1722 struct mode_data
*m
;
1724 print_maybe_const_decl ("%sunsigned short",
1725 "mode_base_align", "NUM_MACHINE_MODES",
1728 for_all_modes (c
, m
)
1729 tagged_printf ("%u", m
->alignment
, m
->name
);
1735 emit_class_narrowest_mode (void)
1739 print_decl ("unsigned char", "class_narrowest_mode", "MAX_MODE_CLASS");
1741 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1743 /* Bleah, all this to get the comment right for MIN_MODE_INT. */
1744 struct mode_data
*m
= modes
[c
];
1745 while (m
&& m
->boolean
)
1747 const char *comment_name
= (m
? m
: void_mode
)->name
;
1749 tagged_printf ("MIN_%s", mode_class_names
[c
], comment_name
);
1756 emit_real_format_for_mode (void)
1758 struct mode_data
*m
;
1760 /* The entities pointed to by this table are constant, whether
1761 or not the table itself is constant.
1763 For backward compatibility this table is always writable
1764 (several targets modify it in TARGET_OPTION_OVERRIDE). FIXME:
1765 convert all said targets to use ADJUST_FORMAT instead. */
1767 print_maybe_const_decl ("const struct real_format *%s",
1768 "real_format_for_mode",
1769 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1",
1772 print_decl ("struct real_format *\n", "real_format_for_mode",
1773 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1 "
1774 "+ MAX_MODE_DECIMAL_FLOAT - MIN_MODE_DECIMAL_FLOAT + 1");
1777 /* The beginning of the table is entries for float modes. */
1778 for (m
= modes
[MODE_FLOAT
]; m
; m
= m
->next
)
1779 if (!strcmp (m
->format
, "0"))
1780 tagged_printf ("%s", m
->format
, m
->name
);
1782 tagged_printf ("&%s", m
->format
, m
->name
);
1784 /* The end of the table is entries for decimal float modes. */
1785 for (m
= modes
[MODE_DECIMAL_FLOAT
]; m
; m
= m
->next
)
1786 if (!strcmp (m
->format
, "0"))
1787 tagged_printf ("%s", m
->format
, m
->name
);
1789 tagged_printf ("&%s", m
->format
, m
->name
);
1795 emit_mode_adjustments (void)
1797 struct mode_adjust
*a
;
1798 struct mode_data
*m
;
1803 "adjust_mode_mask (machine_mode mode)\n"
1805 " unsigned int precision;\n"
1806 " if (GET_MODE_PRECISION (mode).is_constant (&precision)\n"
1807 " && precision < HOST_BITS_PER_WIDE_INT)\n"
1808 " mode_mask_array[mode] = (HOST_WIDE_INT_1U << precision) - 1;"
1811 " mode_mask_array[mode] = HOST_WIDE_INT_M1U;\n"
1816 \ninit_adjust_machine_modes (void)\
1818 \n poly_uint16 ps ATTRIBUTE_UNUSED;\n\
1819 size_t s ATTRIBUTE_UNUSED;");
1821 for (a
= adj_nunits
; a
; a
= a
->next
)
1826 " /* %s:%d */\n ps = %s;\n",
1827 a
->file
, a
->line
, a
->adjustment
);
1828 printf (" int old_factor = vector_element_size"
1829 " (mode_precision[E_%smode], mode_nunits[E_%smode]);\n",
1831 printf (" mode_precision[E_%smode] = ps * old_factor;\n", m
->name
);
1832 printf (" mode_size[E_%smode] = exact_div (mode_precision[E_%smode],"
1833 " BITS_PER_UNIT);\n", m
->name
, m
->name
);
1834 printf (" mode_nunits[E_%smode] = ps;\n", m
->name
);
1835 printf (" adjust_mode_mask (E_%smode);\n", m
->name
);
1839 /* Size adjustments must be propagated to all containing modes.
1840 A size adjustment forces us to recalculate the alignment too. */
1841 for (a
= adj_bytesize
; a
; a
= a
->next
)
1843 printf ("\n /* %s:%d */\n", a
->file
, a
->line
);
1844 switch (a
->mode
->cl
)
1846 case MODE_VECTOR_BOOL
:
1847 case MODE_VECTOR_INT
:
1848 case MODE_VECTOR_FLOAT
:
1849 case MODE_VECTOR_FRACT
:
1850 case MODE_VECTOR_UFRACT
:
1851 case MODE_VECTOR_ACCUM
:
1852 case MODE_VECTOR_UACCUM
:
1853 printf (" ps = %s;\n", a
->adjustment
);
1854 printf (" s = mode_unit_size[E_%smode];\n", a
->mode
->name
);
1858 printf (" ps = s = %s;\n", a
->adjustment
);
1859 printf (" mode_unit_size[E_%smode] = s;\n", a
->mode
->name
);
1862 printf (" mode_size[E_%smode] = ps;\n", a
->mode
->name
);
1863 printf (" mode_base_align[E_%smode] = known_alignment (ps);\n",
1866 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1870 case MODE_COMPLEX_INT
:
1871 case MODE_COMPLEX_FLOAT
:
1872 printf (" mode_size[E_%smode] = 2*s;\n", m
->name
);
1873 printf (" mode_unit_size[E_%smode] = s;\n", m
->name
);
1874 printf (" mode_base_align[E_%smode] = s & (~s + 1);\n",
1878 case MODE_VECTOR_BOOL
:
1879 /* Changes to BImode should not affect vector booleans. */
1882 case MODE_VECTOR_INT
:
1883 case MODE_VECTOR_FLOAT
:
1884 case MODE_VECTOR_FRACT
:
1885 case MODE_VECTOR_UFRACT
:
1886 case MODE_VECTOR_ACCUM
:
1887 case MODE_VECTOR_UACCUM
:
1888 printf (" mode_size[E_%smode] = %d * ps;\n",
1889 m
->name
, m
->ncomponents
);
1890 printf (" mode_unit_size[E_%smode] = s;\n", m
->name
);
1891 printf (" mode_base_align[E_%smode]"
1892 " = known_alignment (%d * ps);\n",
1893 m
->name
, m
->ncomponents
);
1898 "mode %s is neither vector nor complex but contains %s",
1899 m
->name
, a
->mode
->name
);
1905 /* Alignment adjustments propagate too.
1906 ??? This may not be the right thing for vector modes. */
1907 for (a
= adj_alignment
; a
; a
= a
->next
)
1909 printf ("\n /* %s:%d */\n s = %s;\n",
1910 a
->file
, a
->line
, a
->adjustment
);
1911 printf (" mode_base_align[E_%smode] = s;\n", a
->mode
->name
);
1913 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1917 case MODE_COMPLEX_INT
:
1918 case MODE_COMPLEX_FLOAT
:
1919 printf (" mode_base_align[E_%smode] = s;\n", m
->name
);
1922 case MODE_VECTOR_BOOL
:
1923 /* Changes to BImode should not affect vector booleans. */
1926 case MODE_VECTOR_INT
:
1927 case MODE_VECTOR_FLOAT
:
1928 case MODE_VECTOR_FRACT
:
1929 case MODE_VECTOR_UFRACT
:
1930 case MODE_VECTOR_ACCUM
:
1931 case MODE_VECTOR_UACCUM
:
1932 printf (" mode_base_align[E_%smode] = %d*s;\n",
1933 m
->name
, m
->ncomponents
);
1938 "mode %s is neither vector nor complex but contains %s",
1939 m
->name
, a
->mode
->name
);
1945 /* Ibit adjustments don't have to propagate. */
1946 for (a
= adj_ibit
; a
; a
= a
->next
)
1948 printf ("\n /* %s:%d */\n s = %s;\n",
1949 a
->file
, a
->line
, a
->adjustment
);
1950 printf (" mode_ibit[E_%smode] = s;\n", a
->mode
->name
);
1953 /* Fbit adjustments don't have to propagate. */
1954 for (a
= adj_fbit
; a
; a
= a
->next
)
1956 printf ("\n /* %s:%d */\n s = %s;\n",
1957 a
->file
, a
->line
, a
->adjustment
);
1958 printf (" mode_fbit[E_%smode] = s;\n", a
->mode
->name
);
1961 /* Real mode formats don't have to propagate anywhere. */
1962 for (a
= adj_format
; a
; a
= a
->next
)
1963 printf ("\n /* %s:%d */\n REAL_MODE_FORMAT (E_%smode) = %s;\n",
1964 a
->file
, a
->line
, a
->mode
->name
, a
->adjustment
);
1969 /* Emit ibit for all modes. */
1972 emit_mode_ibit (void)
1975 struct mode_data
*m
;
1977 print_maybe_const_decl ("%sunsigned char",
1978 "mode_ibit", "NUM_MACHINE_MODES",
1981 for_all_modes (c
, m
)
1982 tagged_printf ("%u", m
->ibit
, m
->name
);
1987 /* Emit fbit for all modes. */
1990 emit_mode_fbit (void)
1993 struct mode_data
*m
;
1995 print_maybe_const_decl ("%sunsigned char",
1996 "mode_fbit", "NUM_MACHINE_MODES",
1999 for_all_modes (c
, m
)
2000 tagged_printf ("%u", m
->fbit
, m
->name
);
2005 /* Emit __intN for all modes. */
2008 emit_mode_int_n (void)
2011 struct mode_data
*m
;
2012 struct mode_data
**mode_sort
;
2016 print_decl ("int_n_data_t", "int_n_data", "");
2019 for_all_modes (c
, m
)
2022 mode_sort
= XALLOCAVEC (struct mode_data
*, n_modes
);
2025 for_all_modes (c
, m
)
2027 mode_sort
[n_modes
++] = m
;
2029 /* Yes, this is a bubblesort, but there are at most four (and
2030 usually only 1-2) entries to sort. */
2031 for (i
= 0; i
<n_modes
- 1; i
++)
2032 for (j
= i
+ 1; j
< n_modes
; j
++)
2033 if (mode_sort
[i
]->int_n
> mode_sort
[j
]->int_n
)
2034 std::swap (mode_sort
[i
], mode_sort
[j
]);
2036 for (i
= 0; i
< n_modes
; i
++)
2040 tagged_printf ("%u", m
->int_n
, m
->name
);
2041 printf ("{ E_%smode },", m
->name
);
2050 emit_insn_modes_c (void)
2052 emit_insn_modes_c_header ();
2055 emit_mode_precision ();
2057 emit_mode_nunits ();
2059 emit_mode_complex ();
2062 emit_mode_unit_size ();
2063 emit_mode_unit_precision ();
2064 emit_mode_base_align ();
2065 emit_class_narrowest_mode ();
2066 emit_real_format_for_mode ();
2067 emit_mode_adjustments ();
2074 emit_min_insn_modes_c (void)
2076 emit_min_insn_modes_c_header ();
2079 emit_mode_nunits ();
2082 emit_class_narrowest_mode ();
2085 /* Master control. */
2087 main (int argc
, char **argv
)
2089 bool gen_header
= false, gen_inlines
= false, gen_min
= false;
2094 else if (argc
== 2 && !strcmp (argv
[1], "-h"))
2096 else if (argc
== 2 && !strcmp (argv
[1], "-i"))
2098 else if (argc
== 2 && !strcmp (argv
[1], "-m"))
2102 error ("usage: %s [-h|-i|-m] > file", progname
);
2103 return FATAL_EXIT_CODE
;
2106 modes_by_name
= htab_create_alloc (64, hash_mode
, eq_mode
, 0, xcalloc
, free
);
2109 complete_all_modes ();
2112 return FATAL_EXIT_CODE
;
2117 emit_insn_modes_h ();
2118 else if (gen_inlines
)
2119 emit_insn_modes_inline_h ();
2121 emit_min_insn_modes_c ();
2123 emit_insn_modes_c ();
2125 if (fflush (stdout
) || fclose (stdout
))
2126 return FATAL_EXIT_CODE
;
2127 return SUCCESS_EXIT_CODE
;