1 /* Generate the machine mode enumeration and associated tables.
2 Copyright (C) 2003-2021 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
)
362 /* Opaque modes have size and precision. */
363 validate_mode (m
, OPTIONAL
, SET
, UNSET
, UNSET
, UNSET
);
369 case MODE_PARTIAL_INT
:
370 /* A partial integer mode uses ->component to say what the
371 corresponding full-size integer mode is, and may also
372 specify a bit size. */
373 validate_mode (m
, OPTIONAL
, UNSET
, SET
, UNSET
, UNSET
);
375 m
->bytesize
= m
->component
->bytesize
;
380 case MODE_COMPLEX_INT
:
381 case MODE_COMPLEX_FLOAT
:
382 /* Complex modes should have a component indicated, but no more. */
383 validate_mode (m
, UNSET
, UNSET
, SET
, UNSET
, UNSET
);
385 if (m
->component
->precision
!= (unsigned int)-1)
386 m
->precision
= 2 * m
->component
->precision
;
387 m
->bytesize
= 2 * m
->component
->bytesize
;
390 case MODE_VECTOR_BOOL
:
391 validate_mode (m
, UNSET
, SET
, SET
, SET
, UNSET
);
394 case MODE_VECTOR_INT
:
395 case MODE_VECTOR_FLOAT
:
396 case MODE_VECTOR_FRACT
:
397 case MODE_VECTOR_UFRACT
:
398 case MODE_VECTOR_ACCUM
:
399 case MODE_VECTOR_UACCUM
:
400 /* Vector modes should have a component and a number of components. */
401 validate_mode (m
, UNSET
, UNSET
, SET
, SET
, UNSET
);
402 if (m
->component
->precision
!= (unsigned int)-1)
403 m
->precision
= m
->ncomponents
* m
->component
->precision
;
404 m
->bytesize
= m
->ncomponents
* m
->component
->bytesize
;
411 /* If not already specified, the mode alignment defaults to the largest
412 power of two that divides the size of the object. Complex types are
413 not more aligned than their contents. */
414 if (m
->cl
== MODE_COMPLEX_INT
|| m
->cl
== MODE_COMPLEX_FLOAT
)
415 alignment
= m
->component
->bytesize
;
417 alignment
= m
->bytesize
;
419 m
->alignment
= alignment
& (~alignment
+ 1);
421 /* If this mode has components, make the component mode point back
422 to this mode, for the sake of adjustments. */
425 m
->next_cont
= m
->component
->contained
;
426 m
->component
->contained
= m
;
431 complete_all_modes (void)
436 for_all_modes (cl
, m
)
440 /* For each mode in class CLASS, construct a corresponding complex mode. */
441 #define COMPLEX_MODES(C) make_complex_modes (MODE_##C, __FILE__, __LINE__)
443 make_complex_modes (enum mode_class cl
,
444 const char *file
, unsigned int line
)
448 enum mode_class cclass
= complex_class (cl
);
450 if (cclass
== MODE_RANDOM
)
453 for (m
= modes
[cl
]; m
; m
= m
->next
)
458 /* Skip BImode. FIXME: BImode probably shouldn't be MODE_INT. */
459 if (m
->precision
== 1)
462 m_len
= strlen (m
->name
);
463 /* The leading "1 +" is in case we prepend a "C" below. */
464 buf
= (char *) xmalloc (1 + m_len
+ 1);
466 /* Float complex modes are named SCmode, etc.
467 Int complex modes are named CSImode, etc.
468 This inconsistency should be eliminated. */
470 if (cl
== MODE_FLOAT
)
472 memcpy (buf
, m
->name
, m_len
+ 1);
473 p
= strchr (buf
, 'F');
474 if (p
== 0 && strchr (buf
, 'D') == 0)
476 error ("%s:%d: float mode \"%s\" has no 'F' or 'D'",
477 m
->file
, m
->line
, m
->name
);
487 memcpy (buf
+ 1, m
->name
, m_len
+ 1);
490 c
= new_mode (cclass
, buf
, file
, line
);
496 /* For all modes in class CL, construct vector modes of width WIDTH,
497 having as many components as necessary. ORDER is the sorting order
498 of the mode, with smaller numbers indicating a higher priority. */
499 #define VECTOR_MODES_WITH_PREFIX(PREFIX, C, W, ORDER) \
500 make_vector_modes (MODE_##C, #PREFIX, W, ORDER, __FILE__, __LINE__)
501 #define VECTOR_MODES(C, W) VECTOR_MODES_WITH_PREFIX (V, C, W, 0)
502 static void ATTRIBUTE_UNUSED
503 make_vector_modes (enum mode_class cl
, const char *prefix
, unsigned int width
,
504 unsigned int order
, const char *file
, unsigned int line
)
508 /* Big enough for a 32-bit UINT_MAX plus the text. */
510 unsigned int ncomponents
;
511 enum mode_class vclass
= vector_class (cl
);
513 if (vclass
== MODE_RANDOM
)
516 for (m
= modes
[cl
]; m
; m
= m
->next
)
518 /* Do not construct vector modes with only one element, or
519 vector modes where the element size doesn't divide the full
521 ncomponents
= width
/ m
->bytesize
;
524 if (width
% m
->bytesize
)
527 /* Skip QFmode and BImode. FIXME: this special case should
529 if (cl
== MODE_FLOAT
&& m
->bytesize
== 1)
531 if (cl
== MODE_INT
&& m
->precision
== 1)
534 if ((size_t) snprintf (buf
, sizeof buf
, "%s%u%s", prefix
,
535 ncomponents
, m
->name
) >= sizeof buf
)
537 error ("%s:%d: mode name \"%s\" is too long",
538 m
->file
, m
->line
, m
->name
);
542 v
= new_mode (vclass
, xstrdup (buf
), file
, line
);
545 v
->ncomponents
= ncomponents
;
549 /* Create a vector of booleans called NAME with COUNT elements and
550 BYTESIZE bytes in total. */
551 #define VECTOR_BOOL_MODE(NAME, COUNT, BYTESIZE) \
552 make_vector_bool_mode (#NAME, COUNT, BYTESIZE, __FILE__, __LINE__)
553 static void ATTRIBUTE_UNUSED
554 make_vector_bool_mode (const char *name
, unsigned int count
,
555 unsigned int bytesize
, const char *file
,
558 struct mode_data
*m
= find_mode ("BI");
561 error ("%s:%d: no mode \"BI\"", file
, line
);
565 struct mode_data
*v
= new_mode (MODE_VECTOR_BOOL
, name
, file
, line
);
567 v
->ncomponents
= count
;
568 v
->bytesize
= bytesize
;
573 #define _SPECIAL_MODE(C, N) \
574 make_special_mode (MODE_##C, #N, __FILE__, __LINE__)
575 #define RANDOM_MODE(N) _SPECIAL_MODE (RANDOM, N)
576 #define CC_MODE(N) _SPECIAL_MODE (CC, N)
579 make_special_mode (enum mode_class cl
, const char *name
,
580 const char *file
, unsigned int line
)
582 new_mode (cl
, name
, file
, line
);
585 #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y)
586 #define FRACTIONAL_INT_MODE(N, B, Y) \
587 make_int_mode (#N, B, Y, __FILE__, __LINE__)
590 make_int_mode (const char *name
,
591 unsigned int precision
, unsigned int bytesize
,
592 const char *file
, unsigned int line
)
594 struct mode_data
*m
= new_mode (MODE_INT
, name
, file
, line
);
595 m
->bytesize
= bytesize
;
596 m
->precision
= precision
;
599 #define OPAQUE_MODE(N, B) \
600 make_opaque_mode (#N, -1U, B, __FILE__, __LINE__)
602 static void ATTRIBUTE_UNUSED
603 make_opaque_mode (const char *name
,
604 unsigned int precision
,
605 unsigned int bytesize
,
606 const char *file
, unsigned int line
)
608 struct mode_data
*m
= new_mode (MODE_OPAQUE
, name
, file
, line
);
609 m
->bytesize
= bytesize
;
610 m
->precision
= precision
;
613 #define FRACT_MODE(N, Y, F) \
614 make_fixed_point_mode (MODE_FRACT, #N, Y, 0, F, __FILE__, __LINE__)
616 #define UFRACT_MODE(N, Y, F) \
617 make_fixed_point_mode (MODE_UFRACT, #N, Y, 0, F, __FILE__, __LINE__)
619 #define ACCUM_MODE(N, Y, I, F) \
620 make_fixed_point_mode (MODE_ACCUM, #N, Y, I, F, __FILE__, __LINE__)
622 #define UACCUM_MODE(N, Y, I, F) \
623 make_fixed_point_mode (MODE_UACCUM, #N, Y, I, F, __FILE__, __LINE__)
625 /* Create a fixed-point mode by setting CL, NAME, BYTESIZE, IBIT, FBIT,
629 make_fixed_point_mode (enum mode_class cl
,
631 unsigned int bytesize
,
634 const char *file
, unsigned int line
)
636 struct mode_data
*m
= new_mode (cl
, name
, file
, line
);
637 m
->bytesize
= bytesize
;
642 #define FLOAT_MODE(N, Y, F) FRACTIONAL_FLOAT_MODE (N, -1U, Y, F)
643 #define FRACTIONAL_FLOAT_MODE(N, B, Y, F) \
644 make_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
647 make_float_mode (const char *name
,
648 unsigned int precision
, unsigned int bytesize
,
650 const char *file
, unsigned int line
)
652 struct mode_data
*m
= new_mode (MODE_FLOAT
, name
, file
, line
);
653 m
->bytesize
= bytesize
;
654 m
->precision
= precision
;
658 #define DECIMAL_FLOAT_MODE(N, Y, F) \
659 FRACTIONAL_DECIMAL_FLOAT_MODE (N, -1U, Y, F)
660 #define FRACTIONAL_DECIMAL_FLOAT_MODE(N, B, Y, F) \
661 make_decimal_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
664 make_decimal_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_DECIMAL_FLOAT
, name
, file
, line
);
670 m
->bytesize
= bytesize
;
671 m
->precision
= precision
;
675 #define RESET_FLOAT_FORMAT(N, F) \
676 reset_float_format (#N, #F, __FILE__, __LINE__)
677 static void ATTRIBUTE_UNUSED
678 reset_float_format (const char *name
, const char *format
,
679 const char *file
, unsigned int line
)
681 struct mode_data
*m
= find_mode (name
);
684 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
687 if (m
->cl
!= MODE_FLOAT
&& m
->cl
!= MODE_DECIMAL_FLOAT
)
689 error ("%s:%d: mode \"%s\" is not a FLOAT class", file
, line
, name
);
695 /* __intN support. */
696 #define INT_N(M,PREC) \
697 make_int_n (#M, PREC, __FILE__, __LINE__)
698 static void ATTRIBUTE_UNUSED
699 make_int_n (const char *m
, int bitsize
,
700 const char *file
, unsigned int line
)
702 struct mode_data
*component
= find_mode (m
);
705 error ("%s:%d: no mode \"%s\"", file
, line
, m
);
708 if (component
->cl
!= MODE_INT
709 && component
->cl
!= MODE_PARTIAL_INT
)
711 error ("%s:%d: mode \"%s\" is not class INT or PARTIAL_INT", file
, line
, m
);
714 if (component
->int_n
!= 0)
716 error ("%s:%d: mode \"%s\" already has an intN", file
, line
, m
);
720 component
->int_n
= bitsize
;
723 /* Partial integer modes are specified by relation to a full integer
725 #define PARTIAL_INT_MODE(M,PREC,NAME) \
726 make_partial_integer_mode (#M, #NAME, PREC, __FILE__, __LINE__)
727 static void ATTRIBUTE_UNUSED
728 make_partial_integer_mode (const char *base
, const char *name
,
729 unsigned int precision
,
730 const char *file
, unsigned int line
)
733 struct mode_data
*component
= find_mode (base
);
736 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
739 if (component
->cl
!= MODE_INT
)
741 error ("%s:%d: mode \"%s\" is not class INT", file
, line
, name
);
745 m
= new_mode (MODE_PARTIAL_INT
, name
, file
, line
);
746 m
->precision
= precision
;
747 m
->component
= component
;
750 /* A single vector mode can be specified by naming its component
751 mode and the number of components. */
752 #define VECTOR_MODE_WITH_PREFIX(PREFIX, C, M, N, ORDER) \
753 make_vector_mode (MODE_##C, #PREFIX, #M, N, ORDER, __FILE__, __LINE__);
754 #define VECTOR_MODE(C, M, N) VECTOR_MODE_WITH_PREFIX(V, C, M, N, 0);
755 static void ATTRIBUTE_UNUSED
756 make_vector_mode (enum mode_class bclass
,
759 unsigned int ncomponents
,
761 const char *file
, unsigned int line
)
764 enum mode_class vclass
= vector_class (bclass
);
765 struct mode_data
*component
= find_mode (base
);
768 if (vclass
== MODE_RANDOM
)
772 error ("%s:%d: no mode \"%s\"", file
, line
, base
);
775 if (component
->cl
!= bclass
776 && (component
->cl
!= MODE_PARTIAL_INT
777 || bclass
!= MODE_INT
))
779 error ("%s:%d: mode \"%s\" is not class %s",
780 file
, line
, base
, mode_class_names
[bclass
] + 5);
784 if ((size_t)snprintf (namebuf
, sizeof namebuf
, "%s%u%s", prefix
,
785 ncomponents
, base
) >= sizeof namebuf
)
787 error ("%s:%d: mode name \"%s\" is too long",
792 v
= new_mode (vclass
, xstrdup (namebuf
), file
, line
);
794 v
->ncomponents
= ncomponents
;
795 v
->component
= component
;
799 #define _ADD_ADJUST(A, M, X, C1, C2) \
800 new_adjust (#M, &adj_##A, #A, #X, MODE_##C1, MODE_##C2, __FILE__, __LINE__)
802 #define ADJUST_NUNITS(M, X) _ADD_ADJUST (nunits, M, X, RANDOM, RANDOM)
803 #define ADJUST_BYTESIZE(M, X) _ADD_ADJUST (bytesize, M, X, RANDOM, RANDOM)
804 #define ADJUST_ALIGNMENT(M, X) _ADD_ADJUST (alignment, M, X, RANDOM, RANDOM)
805 #define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST (format, M, X, FLOAT, FLOAT)
806 #define ADJUST_IBIT(M, X) _ADD_ADJUST (ibit, M, X, ACCUM, UACCUM)
807 #define ADJUST_FBIT(M, X) _ADD_ADJUST (fbit, M, X, FRACT, UACCUM)
809 static int bits_per_unit
;
810 static int max_bitsize_mode_any_int
;
811 static int max_bitsize_mode_any_mode
;
816 #include "machmode.def"
818 /* So put the default value unless the target needs a non standard
821 bits_per_unit
= BITS_PER_UNIT
;
826 #ifdef MAX_BITSIZE_MODE_ANY_INT
827 max_bitsize_mode_any_int
= MAX_BITSIZE_MODE_ANY_INT
;
829 max_bitsize_mode_any_int
= 0;
832 #ifdef MAX_BITSIZE_MODE_ANY_MODE
833 max_bitsize_mode_any_mode
= MAX_BITSIZE_MODE_ANY_MODE
;
835 max_bitsize_mode_any_mode
= 0;
839 #ifndef NUM_POLY_INT_COEFFS
840 #define NUM_POLY_INT_COEFFS 1
845 /* Sort a list of modes into the order needed for the WIDER field:
846 major sort by precision, minor sort by component precision.
849 QI < HI < SI < DI < TI
850 V4QI < V2HI < V8QI < V4HI < V2SI.
852 If the precision is not set, sort by the bytesize. A mode with
853 precision set gets sorted before a mode without precision set, if
854 they have the same bytesize; this is the right thing because
855 the precision must always be smaller than the bytesize * BITS_PER_UNIT.
856 We don't have to do anything special to get this done -- an unset
857 precision shows up as (unsigned int)-1, i.e. UINT_MAX. */
859 cmp_modes (const void *a
, const void *b
)
861 const struct mode_data
*const m
= *(const struct mode_data
*const*)a
;
862 const struct mode_data
*const n
= *(const struct mode_data
*const*)b
;
864 if (m
->order
> n
->order
)
866 else if (m
->order
< n
->order
)
869 if (m
->bytesize
> n
->bytesize
)
871 else if (m
->bytesize
< n
->bytesize
)
874 if (m
->precision
> n
->precision
)
876 else if (m
->precision
< n
->precision
)
879 if (!m
->component
&& !n
->component
)
881 if (m
->counter
< n
->counter
)
887 if (m
->component
->bytesize
> n
->component
->bytesize
)
889 else if (m
->component
->bytesize
< n
->component
->bytesize
)
892 if (m
->component
->precision
> n
->component
->precision
)
894 else if (m
->component
->precision
< n
->component
->precision
)
897 if (m
->counter
< n
->counter
)
904 calc_wider_mode (void)
908 struct mode_data
**sortbuf
;
909 unsigned int max_n_modes
= 0;
912 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
913 max_n_modes
= MAX (max_n_modes
, n_modes
[c
]);
915 /* Allocate max_n_modes + 1 entries to leave room for the extra null
916 pointer assigned after the qsort call below. */
917 sortbuf
= XALLOCAVEC (struct mode_data
*, max_n_modes
+ 1);
919 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
921 /* "wider" is not meaningful for MODE_RANDOM and MODE_CC.
922 However, we want these in textual order, and we have
923 precisely the reverse. */
924 if (c
== MODE_RANDOM
|| c
== MODE_CC
)
926 struct mode_data
*prev
, *next
;
928 for (prev
= 0, m
= modes
[c
]; m
; m
= next
)
930 m
->wider
= void_mode
;
932 /* this is nreverse */
944 for (i
= 0, m
= modes
[c
]; m
; i
++, m
= m
->next
)
947 (qsort
) (sortbuf
, i
, sizeof (struct mode_data
*), cmp_modes
);
950 for (j
= 0; j
< i
; j
++)
952 sortbuf
[j
]->next
= sortbuf
[j
+ 1];
953 if (c
== MODE_PARTIAL_INT
)
954 sortbuf
[j
]->wider
= sortbuf
[j
]->component
;
956 sortbuf
[j
]->wider
= sortbuf
[j
]->next
;
959 modes
[c
] = sortbuf
[0];
964 /* Text to add to the constant part of a poly_int_pod initializer in
965 order to fill out te whole structure. */
966 #if NUM_POLY_INT_COEFFS == 1
967 #define ZERO_COEFFS ""
968 #elif NUM_POLY_INT_COEFFS == 2
969 #define ZERO_COEFFS ", 0"
971 #error "Unknown value of NUM_POLY_INT_COEFFS"
974 /* Output routines. */
976 #define tagged_printf(FMT, ARG, TAG) do { \
977 int count_ = printf (" " FMT ",", ARG); \
978 printf ("%*s/* %s */\n", 27 - count_, "", TAG); \
981 #define print_decl(TYPE, NAME, ASIZE) \
982 puts ("\nconst " TYPE " " NAME "[" ASIZE "] =\n{");
984 #define print_maybe_const_decl(TYPE, NAME, ASIZE, NEEDS_ADJ) \
985 printf ("\n" TYPE " " NAME "[" ASIZE "] = \n{\n", \
986 NEEDS_ADJ ? "" : "const ")
988 #define print_closer() puts ("};")
990 /* Compute the max bitsize of some of the classes of integers. It may
991 be that there are needs for the other integer classes, and this
992 code is easy to extend. */
996 unsigned int max
, mmax
;
1002 printf ("#define BITS_PER_UNIT (%d)\n", bits_per_unit
);
1004 if (max_bitsize_mode_any_int
== 0)
1006 for (max
= 1, i
= modes
[MODE_INT
]; i
; i
= i
->next
)
1007 if (max
< i
->bytesize
)
1010 for (max
= 1, i
= modes
[MODE_PARTIAL_INT
]; i
; i
= i
->next
)
1011 if (max
< i
->bytesize
)
1015 printf ("#define MAX_BITSIZE_MODE_ANY_INT (%d*BITS_PER_UNIT)\n", mmax
);
1018 printf ("#define MAX_BITSIZE_MODE_ANY_INT %d\n", max_bitsize_mode_any_int
);
1020 if (max_bitsize_mode_any_mode
== 0)
1023 for (j
= 0; j
< MAX_MODE_CLASS
; j
++)
1024 for (i
= modes
[j
]; i
; i
= i
->next
)
1025 if (mmax
< i
->bytesize
)
1027 printf ("#define MAX_BITSIZE_MODE_ANY_MODE (%d*BITS_PER_UNIT)\n", mmax
);
1030 printf ("#define MAX_BITSIZE_MODE_ANY_MODE %d\n",
1031 max_bitsize_mode_any_mode
);
1034 /* Emit mode_size_inline routine into insn-modes.h header. */
1036 emit_mode_size_inline (void)
1039 struct mode_adjust
*a
;
1040 struct mode_data
*m
;
1042 /* Size adjustments must be propagated to all containing modes. */
1043 for (a
= adj_bytesize
; a
; a
= a
->next
)
1045 a
->mode
->need_bytesize_adj
= true;
1046 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1047 m
->need_bytesize_adj
= true;
1050 /* Changing the number of units by a factor of X also changes the size
1051 by a factor of X. */
1052 for (mode_adjust
*a
= adj_nunits
; a
; a
= a
->next
)
1053 a
->mode
->need_bytesize_adj
= true;
1056 #ifdef __cplusplus\n\
1057 inline __attribute__((__always_inline__))\n\
1059 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1062 mode_size_inline (machine_mode mode)\n\
1064 extern %spoly_uint16_pod mode_size[NUM_MACHINE_MODES];\n\
1065 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1067 {\n", adj_nunits
|| adj_bytesize
? "" : "const ");
1069 for_all_modes (c
, m
)
1070 if (!m
->need_bytesize_adj
)
1071 printf (" case E_%smode: return %u;\n", m
->name
, m
->bytesize
);
1074 default: return mode_size[mode];\n\
1079 /* Emit mode_nunits_inline routine into insn-modes.h header. */
1081 emit_mode_nunits_inline (void)
1084 struct mode_data
*m
;
1086 for (mode_adjust
*a
= adj_nunits
; a
; a
= a
->next
)
1087 a
->mode
->need_nunits_adj
= true;
1090 #ifdef __cplusplus\n\
1091 inline __attribute__((__always_inline__))\n\
1093 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1096 mode_nunits_inline (machine_mode mode)\n\
1098 extern %spoly_uint16_pod mode_nunits[NUM_MACHINE_MODES];\n\
1100 {\n", adj_nunits
? "" : "const ");
1102 for_all_modes (c
, m
)
1103 if (!m
->need_nunits_adj
)
1104 printf (" case E_%smode: return %u;\n", m
->name
, m
->ncomponents
);
1107 default: return mode_nunits[mode];\n\
1112 /* Emit mode_inner_inline routine into insn-modes.h header. */
1114 emit_mode_inner_inline (void)
1117 struct mode_data
*m
;
1120 #ifdef __cplusplus\n\
1121 inline __attribute__((__always_inline__))\n\
1123 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1126 mode_inner_inline (machine_mode mode)\n\
1128 extern const unsigned char mode_inner[NUM_MACHINE_MODES];\n\
1129 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1133 for_all_modes (c
, m
)
1134 printf (" case E_%smode: return E_%smode;\n", m
->name
,
1135 c
!= MODE_PARTIAL_INT
&& m
->component
1136 ? m
->component
->name
: m
->name
);
1139 default: return mode_inner[mode];\n\
1144 /* Emit mode_unit_size_inline routine into insn-modes.h header. */
1146 emit_mode_unit_size_inline (void)
1149 struct mode_data
*m
;
1152 #ifdef __cplusplus\n\
1153 inline __attribute__((__always_inline__))\n\
1155 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1158 mode_unit_size_inline (machine_mode mode)\n\
1160 extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES];\
1162 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1166 for_all_modes (c
, m
)
1168 const char *name
= m
->name
;
1169 struct mode_data
*m2
= m
;
1170 if (c
!= MODE_PARTIAL_INT
&& m2
->component
)
1172 if (!m2
->need_bytesize_adj
)
1173 printf (" case E_%smode: return %u;\n", name
, m2
->bytesize
);
1177 default: return mode_unit_size[mode];\n\
1182 /* Emit mode_unit_precision_inline routine into insn-modes.h header. */
1184 emit_mode_unit_precision_inline (void)
1187 struct mode_data
*m
;
1190 #ifdef __cplusplus\n\
1191 inline __attribute__((__always_inline__))\n\
1193 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1196 mode_unit_precision_inline (machine_mode mode)\n\
1198 extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES];\n\
1199 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1203 for_all_modes (c
, m
)
1205 struct mode_data
*m2
1206 = (c
!= MODE_PARTIAL_INT
&& m
->component
) ? m
->component
: m
;
1207 if (m2
->precision
!= (unsigned int)-1)
1208 printf (" case E_%smode: return %u;\n", m
->name
, m2
->precision
);
1210 printf (" case E_%smode: return %u*BITS_PER_UNIT;\n",
1211 m
->name
, m2
->bytesize
);
1215 default: return mode_unit_precision[mode];\n\
1220 /* Return the best machine mode class for MODE, or null if machine_mode
1224 get_mode_class (struct mode_data
*mode
)
1229 case MODE_PARTIAL_INT
:
1230 return "scalar_int_mode";
1236 return "scalar_mode";
1239 case MODE_DECIMAL_FLOAT
:
1240 return "scalar_float_mode";
1242 case MODE_COMPLEX_INT
:
1243 case MODE_COMPLEX_FLOAT
:
1244 return "complex_mode";
1252 emit_insn_modes_h (void)
1255 struct mode_data
*m
, *first
, *last
;
1256 int n_int_n_ents
= 0;
1258 printf ("/* Generated automatically from machmode.def%s%s\n",
1259 HAVE_EXTRA_MODES
? " and " : "",
1265 #ifndef GCC_INSN_MODES_H\n\
1266 #define GCC_INSN_MODES_H\n\
1268 enum machine_mode\n{");
1270 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1271 for (m
= modes
[c
]; m
; m
= m
->next
)
1273 int count_
= printf (" E_%smode,", m
->name
);
1274 printf ("%*s/* %s:%d */\n", 27 - count_
, "",
1275 trim_filename (m
->file
), m
->line
);
1276 printf ("#define HAVE_%smode\n", m
->name
);
1277 printf ("#ifdef USE_ENUM_MODES\n");
1278 printf ("#define %smode E_%smode\n", m
->name
, m
->name
);
1280 if (const char *mode_class
= get_mode_class (m
))
1281 printf ("#define %smode (%s ((%s::from_int) E_%smode))\n",
1282 m
->name
, mode_class
, mode_class
, m
->name
);
1284 printf ("#define %smode ((void) 0, E_%smode)\n",
1286 printf ("#endif\n");
1289 puts (" MAX_MACHINE_MODE,\n");
1291 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1295 for (m
= first
; m
; last
= m
, m
= m
->next
)
1298 /* Don't use BImode for MIN_MODE_INT, since otherwise the middle
1299 end will try to use it for bitfields in structures and the
1300 like, which we do not want. Only the target md file should
1301 generate BImode widgets. */
1302 if (first
&& first
->precision
== 1 && c
== MODE_INT
)
1303 first
= first
->next
;
1306 printf (" MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n",
1307 mode_class_names
[c
], first
->name
,
1308 mode_class_names
[c
], last
->name
);
1310 printf (" MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n",
1311 mode_class_names
[c
], void_mode
->name
,
1312 mode_class_names
[c
], void_mode
->name
);
1316 NUM_MACHINE_MODES = MAX_MACHINE_MODE\n\
1319 /* I can't think of a better idea, can you? */
1320 printf ("#define CONST_MODE_NUNITS%s\n", adj_nunits
? "" : " const");
1321 printf ("#define CONST_MODE_PRECISION%s\n", adj_nunits
? "" : " const");
1322 printf ("#define CONST_MODE_SIZE%s\n",
1323 adj_bytesize
|| adj_nunits
? "" : " const");
1324 printf ("#define CONST_MODE_UNIT_SIZE%s\n", adj_bytesize
? "" : " const");
1325 printf ("#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment
? "" : " const");
1326 #if 0 /* disabled for backward compatibility, temporary */
1327 printf ("#define CONST_REAL_FORMAT_FOR_MODE%s\n", adj_format
? "" :" const");
1329 printf ("#define CONST_MODE_IBIT%s\n", adj_ibit
? "" : " const");
1330 printf ("#define CONST_MODE_FBIT%s\n", adj_fbit
? "" : " const");
1331 printf ("#define CONST_MODE_MASK%s\n", adj_nunits
? "" : " const");
1334 for_all_modes (c
, m
)
1338 printf ("#define NUM_INT_N_ENTS %d\n", n_int_n_ents
);
1340 printf ("#define NUM_POLY_INT_COEFFS %d\n", NUM_POLY_INT_COEFFS
);
1344 #endif /* insn-modes.h */");
1348 emit_insn_modes_inline_h (void)
1350 printf ("/* Generated automatically from machmode.def%s%s\n",
1351 HAVE_EXTRA_MODES
? " and " : "",
1357 #ifndef GCC_INSN_MODES_INLINE_H\n\
1358 #define GCC_INSN_MODES_INLINE_H");
1360 puts ("\n#if !defined (USED_FOR_TARGET) && GCC_VERSION >= 4001\n");
1361 emit_mode_size_inline ();
1362 emit_mode_nunits_inline ();
1363 emit_mode_inner_inline ();
1364 emit_mode_unit_size_inline ();
1365 emit_mode_unit_precision_inline ();
1366 puts ("#endif /* GCC_VERSION >= 4001 */");
1370 #endif /* insn-modes-inline.h */");
1374 emit_insn_modes_c_header (void)
1376 printf ("/* Generated automatically from machmode.def%s%s\n",
1377 HAVE_EXTRA_MODES
? " and " : "",
1383 #include \"config.h\"\n\
1384 #include \"system.h\"\n\
1385 #include \"coretypes.h\"\n\
1386 #include \"tm.h\"\n\
1387 #include \"real.h\"");
1391 emit_min_insn_modes_c_header (void)
1393 printf ("/* Generated automatically from machmode.def%s%s\n",
1394 HAVE_EXTRA_MODES
? " and " : "",
1400 #include \"bconfig.h\"\n\
1401 #include \"system.h\"\n\
1402 #include \"coretypes.h\"");
1406 emit_mode_name (void)
1409 struct mode_data
*m
;
1411 print_decl ("char *const", "mode_name", "NUM_MACHINE_MODES");
1413 for_all_modes (c
, m
)
1414 printf (" \"%s\",\n", m
->name
);
1420 emit_mode_class (void)
1423 struct mode_data
*m
;
1425 print_decl ("unsigned char", "mode_class", "NUM_MACHINE_MODES");
1427 for_all_modes (c
, m
)
1428 tagged_printf ("%s", mode_class_names
[m
->cl
], m
->name
);
1434 emit_mode_precision (void)
1437 struct mode_data
*m
;
1439 print_maybe_const_decl ("%spoly_uint16_pod", "mode_precision",
1440 "NUM_MACHINE_MODES", adj_nunits
);
1442 for_all_modes (c
, m
)
1443 if (m
->precision
!= (unsigned int)-1)
1444 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->precision
, m
->name
);
1446 tagged_printf ("{ %u * BITS_PER_UNIT" ZERO_COEFFS
" }",
1447 m
->bytesize
, m
->name
);
1453 emit_mode_size (void)
1456 struct mode_data
*m
;
1458 print_maybe_const_decl ("%spoly_uint16_pod", "mode_size",
1459 "NUM_MACHINE_MODES", adj_nunits
|| adj_bytesize
);
1461 for_all_modes (c
, m
)
1462 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->bytesize
, m
->name
);
1468 emit_mode_nunits (void)
1471 struct mode_data
*m
;
1473 print_maybe_const_decl ("%spoly_uint16_pod", "mode_nunits",
1474 "NUM_MACHINE_MODES", adj_nunits
);
1476 for_all_modes (c
, m
)
1477 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->ncomponents
, m
->name
);
1483 emit_mode_wider (void)
1486 struct mode_data
*m
;
1488 print_decl ("unsigned char", "mode_wider", "NUM_MACHINE_MODES");
1490 for_all_modes (c
, m
)
1491 tagged_printf ("E_%smode",
1492 m
->wider
? m
->wider
->name
: void_mode
->name
,
1496 print_decl ("unsigned char", "mode_2xwider", "NUM_MACHINE_MODES");
1498 for_all_modes (c
, m
)
1500 struct mode_data
* m2
;
1503 m2
&& m2
!= void_mode
;
1506 if (m2
->bytesize
< 2 * m
->bytesize
)
1508 if (m
->precision
!= (unsigned int) -1)
1510 if (m2
->precision
!= 2 * m
->precision
)
1515 if (m2
->precision
!= (unsigned int) -1)
1519 /* For vectors we want twice the number of components,
1520 with the same element type. */
1521 if (m
->cl
== MODE_VECTOR_BOOL
1522 || m
->cl
== MODE_VECTOR_INT
1523 || m
->cl
== MODE_VECTOR_FLOAT
1524 || m
->cl
== MODE_VECTOR_FRACT
1525 || m
->cl
== MODE_VECTOR_UFRACT
1526 || m
->cl
== MODE_VECTOR_ACCUM
1527 || m
->cl
== MODE_VECTOR_UACCUM
)
1529 if (m2
->ncomponents
!= 2 * m
->ncomponents
)
1531 if (m
->component
!= m2
->component
)
1537 if (m2
== void_mode
)
1539 tagged_printf ("E_%smode",
1540 m2
? m2
->name
: void_mode
->name
,
1548 emit_mode_complex (void)
1551 struct mode_data
*m
;
1553 print_decl ("unsigned char", "mode_complex", "NUM_MACHINE_MODES");
1555 for_all_modes (c
, m
)
1556 tagged_printf ("E_%smode",
1557 m
->complex ? m
->complex->name
: void_mode
->name
,
1564 emit_mode_mask (void)
1567 struct mode_data
*m
;
1569 print_maybe_const_decl ("%sunsigned HOST_WIDE_INT", "mode_mask_array",
1570 "NUM_MACHINE_MODES", adj_nunits
);
1572 #define MODE_MASK(m) \\\n\
1573 ((m) >= HOST_BITS_PER_WIDE_INT) \\\n\
1574 ? HOST_WIDE_INT_M1U \\\n\
1575 : (HOST_WIDE_INT_1U << (m)) - 1\n");
1577 for_all_modes (c
, m
)
1578 if (m
->precision
!= (unsigned int)-1)
1579 tagged_printf ("MODE_MASK (%u)", m
->precision
, m
->name
);
1581 tagged_printf ("MODE_MASK (%u*BITS_PER_UNIT)", m
->bytesize
, m
->name
);
1583 puts ("#undef MODE_MASK");
1588 emit_mode_inner (void)
1591 struct mode_data
*m
;
1593 print_decl ("unsigned char", "mode_inner", "NUM_MACHINE_MODES");
1595 for_all_modes (c
, m
)
1596 tagged_printf ("E_%smode",
1597 c
!= MODE_PARTIAL_INT
&& m
->component
1598 ? m
->component
->name
: m
->name
,
1604 /* Emit mode_unit_size array into insn-modes.c file. */
1606 emit_mode_unit_size (void)
1609 struct mode_data
*m
;
1611 print_maybe_const_decl ("%sunsigned char", "mode_unit_size",
1612 "NUM_MACHINE_MODES", adj_bytesize
);
1614 for_all_modes (c
, m
)
1615 tagged_printf ("%u",
1616 c
!= MODE_PARTIAL_INT
&& m
->component
1617 ? m
->component
->bytesize
: m
->bytesize
, m
->name
);
1622 /* Emit mode_unit_precision array into insn-modes.c file. */
1624 emit_mode_unit_precision (void)
1627 struct mode_data
*m
;
1629 print_decl ("unsigned short", "mode_unit_precision", "NUM_MACHINE_MODES");
1631 for_all_modes (c
, m
)
1633 struct mode_data
*m2
= (c
!= MODE_PARTIAL_INT
&& m
->component
) ?
1635 if (m2
->precision
!= (unsigned int)-1)
1636 tagged_printf ("%u", m2
->precision
, m
->name
);
1638 tagged_printf ("%u*BITS_PER_UNIT", m2
->bytesize
, m
->name
);
1646 emit_mode_base_align (void)
1649 struct mode_data
*m
;
1651 print_maybe_const_decl ("%sunsigned short",
1652 "mode_base_align", "NUM_MACHINE_MODES",
1655 for_all_modes (c
, m
)
1656 tagged_printf ("%u", m
->alignment
, m
->name
);
1662 emit_class_narrowest_mode (void)
1666 print_decl ("unsigned char", "class_narrowest_mode", "MAX_MODE_CLASS");
1668 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1669 /* Bleah, all this to get the comment right for MIN_MODE_INT. */
1670 tagged_printf ("MIN_%s", mode_class_names
[c
],
1672 ? ((c
!= MODE_INT
|| modes
[c
]->precision
!= 1)
1675 ? modes
[c
]->next
->name
1683 emit_real_format_for_mode (void)
1685 struct mode_data
*m
;
1687 /* The entities pointed to by this table are constant, whether
1688 or not the table itself is constant.
1690 For backward compatibility this table is always writable
1691 (several targets modify it in TARGET_OPTION_OVERRIDE). FIXME:
1692 convert all said targets to use ADJUST_FORMAT instead. */
1694 print_maybe_const_decl ("const struct real_format *%s",
1695 "real_format_for_mode",
1696 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1",
1699 print_decl ("struct real_format *\n", "real_format_for_mode",
1700 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1 "
1701 "+ MAX_MODE_DECIMAL_FLOAT - MIN_MODE_DECIMAL_FLOAT + 1");
1704 /* The beginning of the table is entries for float modes. */
1705 for (m
= modes
[MODE_FLOAT
]; m
; m
= m
->next
)
1706 if (!strcmp (m
->format
, "0"))
1707 tagged_printf ("%s", m
->format
, m
->name
);
1709 tagged_printf ("&%s", m
->format
, m
->name
);
1711 /* The end of the table is entries for decimal float modes. */
1712 for (m
= modes
[MODE_DECIMAL_FLOAT
]; m
; m
= m
->next
)
1713 if (!strcmp (m
->format
, "0"))
1714 tagged_printf ("%s", m
->format
, m
->name
);
1716 tagged_printf ("&%s", m
->format
, m
->name
);
1722 emit_mode_adjustments (void)
1724 struct mode_adjust
*a
;
1725 struct mode_data
*m
;
1730 "adjust_mode_mask (machine_mode mode)\n"
1732 " unsigned int precision;\n"
1733 " if (GET_MODE_PRECISION (mode).is_constant (&precision)\n"
1734 " && precision < HOST_BITS_PER_WIDE_INT)\n"
1735 " mode_mask_array[mode] = (HOST_WIDE_INT_1U << precision) - 1;"
1738 " mode_mask_array[mode] = HOST_WIDE_INT_M1U;\n"
1743 \ninit_adjust_machine_modes (void)\
1745 \n poly_uint16 ps ATTRIBUTE_UNUSED;\n\
1746 size_t s ATTRIBUTE_UNUSED;");
1748 for (a
= adj_nunits
; a
; a
= a
->next
)
1753 " /* %s:%d */\n ps = %s;\n",
1754 a
->file
, a
->line
, a
->adjustment
);
1755 printf (" int old_factor = vector_element_size"
1756 " (mode_precision[E_%smode], mode_nunits[E_%smode]);\n",
1758 printf (" mode_precision[E_%smode] = ps * old_factor;\n", m
->name
);
1759 printf (" mode_size[E_%smode] = exact_div (mode_precision[E_%smode],"
1760 " BITS_PER_UNIT);\n", m
->name
, m
->name
);
1761 printf (" mode_nunits[E_%smode] = ps;\n", m
->name
);
1762 printf (" adjust_mode_mask (E_%smode);\n", m
->name
);
1766 /* Size adjustments must be propagated to all containing modes.
1767 A size adjustment forces us to recalculate the alignment too. */
1768 for (a
= adj_bytesize
; a
; a
= a
->next
)
1770 printf ("\n /* %s:%d */\n", a
->file
, a
->line
);
1771 switch (a
->mode
->cl
)
1773 case MODE_VECTOR_BOOL
:
1774 case MODE_VECTOR_INT
:
1775 case MODE_VECTOR_FLOAT
:
1776 case MODE_VECTOR_FRACT
:
1777 case MODE_VECTOR_UFRACT
:
1778 case MODE_VECTOR_ACCUM
:
1779 case MODE_VECTOR_UACCUM
:
1780 printf (" ps = %s;\n", a
->adjustment
);
1781 printf (" s = mode_unit_size[E_%smode];\n", a
->mode
->name
);
1785 printf (" ps = s = %s;\n", a
->adjustment
);
1786 printf (" mode_unit_size[E_%smode] = s;\n", a
->mode
->name
);
1789 printf (" mode_size[E_%smode] = ps;\n", a
->mode
->name
);
1790 printf (" mode_base_align[E_%smode] = known_alignment (ps);\n",
1793 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1797 case MODE_COMPLEX_INT
:
1798 case MODE_COMPLEX_FLOAT
:
1799 printf (" mode_size[E_%smode] = 2*s;\n", m
->name
);
1800 printf (" mode_unit_size[E_%smode] = s;\n", m
->name
);
1801 printf (" mode_base_align[E_%smode] = s & (~s + 1);\n",
1805 case MODE_VECTOR_BOOL
:
1806 /* Changes to BImode should not affect vector booleans. */
1809 case MODE_VECTOR_INT
:
1810 case MODE_VECTOR_FLOAT
:
1811 case MODE_VECTOR_FRACT
:
1812 case MODE_VECTOR_UFRACT
:
1813 case MODE_VECTOR_ACCUM
:
1814 case MODE_VECTOR_UACCUM
:
1815 printf (" mode_size[E_%smode] = %d * ps;\n",
1816 m
->name
, m
->ncomponents
);
1817 printf (" mode_unit_size[E_%smode] = s;\n", m
->name
);
1818 printf (" mode_base_align[E_%smode]"
1819 " = known_alignment (%d * ps);\n",
1820 m
->name
, m
->ncomponents
);
1825 "mode %s is neither vector nor complex but contains %s",
1826 m
->name
, a
->mode
->name
);
1832 /* Alignment adjustments propagate too.
1833 ??? This may not be the right thing for vector modes. */
1834 for (a
= adj_alignment
; a
; a
= a
->next
)
1836 printf ("\n /* %s:%d */\n s = %s;\n",
1837 a
->file
, a
->line
, a
->adjustment
);
1838 printf (" mode_base_align[E_%smode] = s;\n", a
->mode
->name
);
1840 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1844 case MODE_COMPLEX_INT
:
1845 case MODE_COMPLEX_FLOAT
:
1846 printf (" mode_base_align[E_%smode] = s;\n", m
->name
);
1849 case MODE_VECTOR_BOOL
:
1850 /* Changes to BImode should not affect vector booleans. */
1853 case MODE_VECTOR_INT
:
1854 case MODE_VECTOR_FLOAT
:
1855 case MODE_VECTOR_FRACT
:
1856 case MODE_VECTOR_UFRACT
:
1857 case MODE_VECTOR_ACCUM
:
1858 case MODE_VECTOR_UACCUM
:
1859 printf (" mode_base_align[E_%smode] = %d*s;\n",
1860 m
->name
, m
->ncomponents
);
1865 "mode %s is neither vector nor complex but contains %s",
1866 m
->name
, a
->mode
->name
);
1872 /* Ibit adjustments don't have to propagate. */
1873 for (a
= adj_ibit
; a
; a
= a
->next
)
1875 printf ("\n /* %s:%d */\n s = %s;\n",
1876 a
->file
, a
->line
, a
->adjustment
);
1877 printf (" mode_ibit[E_%smode] = s;\n", a
->mode
->name
);
1880 /* Fbit adjustments don't have to propagate. */
1881 for (a
= adj_fbit
; a
; a
= a
->next
)
1883 printf ("\n /* %s:%d */\n s = %s;\n",
1884 a
->file
, a
->line
, a
->adjustment
);
1885 printf (" mode_fbit[E_%smode] = s;\n", a
->mode
->name
);
1888 /* Real mode formats don't have to propagate anywhere. */
1889 for (a
= adj_format
; a
; a
= a
->next
)
1890 printf ("\n /* %s:%d */\n REAL_MODE_FORMAT (E_%smode) = %s;\n",
1891 a
->file
, a
->line
, a
->mode
->name
, a
->adjustment
);
1896 /* Emit ibit for all modes. */
1899 emit_mode_ibit (void)
1902 struct mode_data
*m
;
1904 print_maybe_const_decl ("%sunsigned char",
1905 "mode_ibit", "NUM_MACHINE_MODES",
1908 for_all_modes (c
, m
)
1909 tagged_printf ("%u", m
->ibit
, m
->name
);
1914 /* Emit fbit for all modes. */
1917 emit_mode_fbit (void)
1920 struct mode_data
*m
;
1922 print_maybe_const_decl ("%sunsigned char",
1923 "mode_fbit", "NUM_MACHINE_MODES",
1926 for_all_modes (c
, m
)
1927 tagged_printf ("%u", m
->fbit
, m
->name
);
1932 /* Emit __intN for all modes. */
1935 emit_mode_int_n (void)
1938 struct mode_data
*m
;
1939 struct mode_data
**mode_sort
;
1943 print_decl ("int_n_data_t", "int_n_data", "");
1946 for_all_modes (c
, m
)
1949 mode_sort
= XALLOCAVEC (struct mode_data
*, n_modes
);
1952 for_all_modes (c
, m
)
1954 mode_sort
[n_modes
++] = m
;
1956 /* Yes, this is a bubblesort, but there are at most four (and
1957 usually only 1-2) entries to sort. */
1958 for (i
= 0; i
<n_modes
- 1; i
++)
1959 for (j
= i
+ 1; j
< n_modes
; j
++)
1960 if (mode_sort
[i
]->int_n
> mode_sort
[j
]->int_n
)
1961 std::swap (mode_sort
[i
], mode_sort
[j
]);
1963 for (i
= 0; i
< n_modes
; i
++)
1967 tagged_printf ("%u", m
->int_n
, m
->name
);
1968 printf ("{ E_%smode },", m
->name
);
1977 emit_insn_modes_c (void)
1979 emit_insn_modes_c_header ();
1982 emit_mode_precision ();
1984 emit_mode_nunits ();
1986 emit_mode_complex ();
1989 emit_mode_unit_size ();
1990 emit_mode_unit_precision ();
1991 emit_mode_base_align ();
1992 emit_class_narrowest_mode ();
1993 emit_real_format_for_mode ();
1994 emit_mode_adjustments ();
2001 emit_min_insn_modes_c (void)
2003 emit_min_insn_modes_c_header ();
2006 emit_mode_nunits ();
2009 emit_class_narrowest_mode ();
2012 /* Master control. */
2014 main (int argc
, char **argv
)
2016 bool gen_header
= false, gen_inlines
= false, gen_min
= false;
2021 else if (argc
== 2 && !strcmp (argv
[1], "-h"))
2023 else if (argc
== 2 && !strcmp (argv
[1], "-i"))
2025 else if (argc
== 2 && !strcmp (argv
[1], "-m"))
2029 error ("usage: %s [-h|-i|-m] > file", progname
);
2030 return FATAL_EXIT_CODE
;
2033 modes_by_name
= htab_create_alloc (64, hash_mode
, eq_mode
, 0, xcalloc
, free
);
2036 complete_all_modes ();
2039 return FATAL_EXIT_CODE
;
2044 emit_insn_modes_h ();
2045 else if (gen_inlines
)
2046 emit_insn_modes_inline_h ();
2048 emit_min_insn_modes_c ();
2050 emit_insn_modes_c ();
2052 if (fflush (stdout
) || fclose (stdout
))
2053 return FATAL_EXIT_CODE
;
2054 return SUCCESS_EXIT_CODE
;