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 /* Define a NUM_* macro for each mode class, giving the number of modes
1321 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1323 printf ("#define NUM_%s ", mode_class_names
[c
]);
1325 printf ("(MAX_%s - MIN_%s + 1)\n", mode_class_names
[c
],
1326 mode_class_names
[c
]);
1332 /* I can't think of a better idea, can you? */
1333 printf ("#define CONST_MODE_NUNITS%s\n", adj_nunits
? "" : " const");
1334 printf ("#define CONST_MODE_PRECISION%s\n", adj_nunits
? "" : " const");
1335 printf ("#define CONST_MODE_SIZE%s\n",
1336 adj_bytesize
|| adj_nunits
? "" : " const");
1337 printf ("#define CONST_MODE_UNIT_SIZE%s\n", adj_bytesize
? "" : " const");
1338 printf ("#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment
? "" : " const");
1339 #if 0 /* disabled for backward compatibility, temporary */
1340 printf ("#define CONST_REAL_FORMAT_FOR_MODE%s\n", adj_format
? "" :" const");
1342 printf ("#define CONST_MODE_IBIT%s\n", adj_ibit
? "" : " const");
1343 printf ("#define CONST_MODE_FBIT%s\n", adj_fbit
? "" : " const");
1344 printf ("#define CONST_MODE_MASK%s\n", adj_nunits
? "" : " const");
1347 for_all_modes (c
, m
)
1351 printf ("#define NUM_INT_N_ENTS %d\n", n_int_n_ents
);
1353 printf ("#define NUM_POLY_INT_COEFFS %d\n", NUM_POLY_INT_COEFFS
);
1357 #endif /* insn-modes.h */");
1361 emit_insn_modes_inline_h (void)
1363 printf ("/* Generated automatically from machmode.def%s%s\n",
1364 HAVE_EXTRA_MODES
? " and " : "",
1370 #ifndef GCC_INSN_MODES_INLINE_H\n\
1371 #define GCC_INSN_MODES_INLINE_H");
1373 puts ("\n#if !defined (USED_FOR_TARGET) && GCC_VERSION >= 4001\n");
1374 emit_mode_size_inline ();
1375 emit_mode_nunits_inline ();
1376 emit_mode_inner_inline ();
1377 emit_mode_unit_size_inline ();
1378 emit_mode_unit_precision_inline ();
1379 puts ("#endif /* GCC_VERSION >= 4001 */");
1383 #endif /* insn-modes-inline.h */");
1387 emit_insn_modes_c_header (void)
1389 printf ("/* Generated automatically from machmode.def%s%s\n",
1390 HAVE_EXTRA_MODES
? " and " : "",
1396 #include \"config.h\"\n\
1397 #include \"system.h\"\n\
1398 #include \"coretypes.h\"\n\
1399 #include \"tm.h\"\n\
1400 #include \"real.h\"");
1404 emit_min_insn_modes_c_header (void)
1406 printf ("/* Generated automatically from machmode.def%s%s\n",
1407 HAVE_EXTRA_MODES
? " and " : "",
1413 #include \"bconfig.h\"\n\
1414 #include \"system.h\"\n\
1415 #include \"coretypes.h\"");
1419 emit_mode_name (void)
1422 struct mode_data
*m
;
1424 print_decl ("char *const", "mode_name", "NUM_MACHINE_MODES");
1426 for_all_modes (c
, m
)
1427 printf (" \"%s\",\n", m
->name
);
1433 emit_mode_class (void)
1436 struct mode_data
*m
;
1438 print_decl ("unsigned char", "mode_class", "NUM_MACHINE_MODES");
1440 for_all_modes (c
, m
)
1441 tagged_printf ("%s", mode_class_names
[m
->cl
], m
->name
);
1447 emit_mode_precision (void)
1450 struct mode_data
*m
;
1452 print_maybe_const_decl ("%spoly_uint16_pod", "mode_precision",
1453 "NUM_MACHINE_MODES", adj_nunits
);
1455 for_all_modes (c
, m
)
1456 if (m
->precision
!= (unsigned int)-1)
1457 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->precision
, m
->name
);
1459 tagged_printf ("{ %u * BITS_PER_UNIT" ZERO_COEFFS
" }",
1460 m
->bytesize
, m
->name
);
1466 emit_mode_size (void)
1469 struct mode_data
*m
;
1471 print_maybe_const_decl ("%spoly_uint16_pod", "mode_size",
1472 "NUM_MACHINE_MODES", adj_nunits
|| adj_bytesize
);
1474 for_all_modes (c
, m
)
1475 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->bytesize
, m
->name
);
1481 emit_mode_nunits (void)
1484 struct mode_data
*m
;
1486 print_maybe_const_decl ("%spoly_uint16_pod", "mode_nunits",
1487 "NUM_MACHINE_MODES", adj_nunits
);
1489 for_all_modes (c
, m
)
1490 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->ncomponents
, m
->name
);
1496 emit_mode_wider (void)
1499 struct mode_data
*m
;
1501 print_decl ("unsigned char", "mode_wider", "NUM_MACHINE_MODES");
1503 for_all_modes (c
, m
)
1504 tagged_printf ("E_%smode",
1505 m
->wider
? m
->wider
->name
: void_mode
->name
,
1509 print_decl ("unsigned char", "mode_2xwider", "NUM_MACHINE_MODES");
1511 for_all_modes (c
, m
)
1513 struct mode_data
* m2
;
1516 m2
&& m2
!= void_mode
;
1519 if (m2
->bytesize
< 2 * m
->bytesize
)
1521 if (m
->precision
!= (unsigned int) -1)
1523 if (m2
->precision
!= 2 * m
->precision
)
1528 if (m2
->precision
!= (unsigned int) -1)
1532 /* For vectors we want twice the number of components,
1533 with the same element type. */
1534 if (m
->cl
== MODE_VECTOR_BOOL
1535 || m
->cl
== MODE_VECTOR_INT
1536 || m
->cl
== MODE_VECTOR_FLOAT
1537 || m
->cl
== MODE_VECTOR_FRACT
1538 || m
->cl
== MODE_VECTOR_UFRACT
1539 || m
->cl
== MODE_VECTOR_ACCUM
1540 || m
->cl
== MODE_VECTOR_UACCUM
)
1542 if (m2
->ncomponents
!= 2 * m
->ncomponents
)
1544 if (m
->component
!= m2
->component
)
1550 if (m2
== void_mode
)
1552 tagged_printf ("E_%smode",
1553 m2
? m2
->name
: void_mode
->name
,
1561 emit_mode_complex (void)
1564 struct mode_data
*m
;
1566 print_decl ("unsigned char", "mode_complex", "NUM_MACHINE_MODES");
1568 for_all_modes (c
, m
)
1569 tagged_printf ("E_%smode",
1570 m
->complex ? m
->complex->name
: void_mode
->name
,
1577 emit_mode_mask (void)
1580 struct mode_data
*m
;
1582 print_maybe_const_decl ("%sunsigned HOST_WIDE_INT", "mode_mask_array",
1583 "NUM_MACHINE_MODES", adj_nunits
);
1585 #define MODE_MASK(m) \\\n\
1586 ((m) >= HOST_BITS_PER_WIDE_INT) \\\n\
1587 ? HOST_WIDE_INT_M1U \\\n\
1588 : (HOST_WIDE_INT_1U << (m)) - 1\n");
1590 for_all_modes (c
, m
)
1591 if (m
->precision
!= (unsigned int)-1)
1592 tagged_printf ("MODE_MASK (%u)", m
->precision
, m
->name
);
1594 tagged_printf ("MODE_MASK (%u*BITS_PER_UNIT)", m
->bytesize
, m
->name
);
1596 puts ("#undef MODE_MASK");
1601 emit_mode_inner (void)
1604 struct mode_data
*m
;
1606 print_decl ("unsigned char", "mode_inner", "NUM_MACHINE_MODES");
1608 for_all_modes (c
, m
)
1609 tagged_printf ("E_%smode",
1610 c
!= MODE_PARTIAL_INT
&& m
->component
1611 ? m
->component
->name
: m
->name
,
1617 /* Emit mode_unit_size array into insn-modes.c file. */
1619 emit_mode_unit_size (void)
1622 struct mode_data
*m
;
1624 print_maybe_const_decl ("%sunsigned char", "mode_unit_size",
1625 "NUM_MACHINE_MODES", adj_bytesize
);
1627 for_all_modes (c
, m
)
1628 tagged_printf ("%u",
1629 c
!= MODE_PARTIAL_INT
&& m
->component
1630 ? m
->component
->bytesize
: m
->bytesize
, m
->name
);
1635 /* Emit mode_unit_precision array into insn-modes.c file. */
1637 emit_mode_unit_precision (void)
1640 struct mode_data
*m
;
1642 print_decl ("unsigned short", "mode_unit_precision", "NUM_MACHINE_MODES");
1644 for_all_modes (c
, m
)
1646 struct mode_data
*m2
= (c
!= MODE_PARTIAL_INT
&& m
->component
) ?
1648 if (m2
->precision
!= (unsigned int)-1)
1649 tagged_printf ("%u", m2
->precision
, m
->name
);
1651 tagged_printf ("%u*BITS_PER_UNIT", m2
->bytesize
, m
->name
);
1659 emit_mode_base_align (void)
1662 struct mode_data
*m
;
1664 print_maybe_const_decl ("%sunsigned short",
1665 "mode_base_align", "NUM_MACHINE_MODES",
1668 for_all_modes (c
, m
)
1669 tagged_printf ("%u", m
->alignment
, m
->name
);
1675 emit_class_narrowest_mode (void)
1679 print_decl ("unsigned char", "class_narrowest_mode", "MAX_MODE_CLASS");
1681 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1682 /* Bleah, all this to get the comment right for MIN_MODE_INT. */
1683 tagged_printf ("MIN_%s", mode_class_names
[c
],
1685 ? ((c
!= MODE_INT
|| modes
[c
]->precision
!= 1)
1688 ? modes
[c
]->next
->name
1696 emit_real_format_for_mode (void)
1698 struct mode_data
*m
;
1700 /* The entities pointed to by this table are constant, whether
1701 or not the table itself is constant.
1703 For backward compatibility this table is always writable
1704 (several targets modify it in TARGET_OPTION_OVERRIDE). FIXME:
1705 convert all said targets to use ADJUST_FORMAT instead. */
1707 print_maybe_const_decl ("const struct real_format *%s",
1708 "real_format_for_mode",
1709 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1",
1712 print_decl ("struct real_format *\n", "real_format_for_mode",
1713 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1 "
1714 "+ MAX_MODE_DECIMAL_FLOAT - MIN_MODE_DECIMAL_FLOAT + 1");
1717 /* The beginning of the table is entries for float modes. */
1718 for (m
= modes
[MODE_FLOAT
]; m
; m
= m
->next
)
1719 if (!strcmp (m
->format
, "0"))
1720 tagged_printf ("%s", m
->format
, m
->name
);
1722 tagged_printf ("&%s", m
->format
, m
->name
);
1724 /* The end of the table is entries for decimal float modes. */
1725 for (m
= modes
[MODE_DECIMAL_FLOAT
]; m
; m
= m
->next
)
1726 if (!strcmp (m
->format
, "0"))
1727 tagged_printf ("%s", m
->format
, m
->name
);
1729 tagged_printf ("&%s", m
->format
, m
->name
);
1735 emit_mode_adjustments (void)
1737 struct mode_adjust
*a
;
1738 struct mode_data
*m
;
1743 "adjust_mode_mask (machine_mode mode)\n"
1745 " unsigned int precision;\n"
1746 " if (GET_MODE_PRECISION (mode).is_constant (&precision)\n"
1747 " && precision < HOST_BITS_PER_WIDE_INT)\n"
1748 " mode_mask_array[mode] = (HOST_WIDE_INT_1U << precision) - 1;"
1751 " mode_mask_array[mode] = HOST_WIDE_INT_M1U;\n"
1756 \ninit_adjust_machine_modes (void)\
1758 \n poly_uint16 ps ATTRIBUTE_UNUSED;\n\
1759 size_t s ATTRIBUTE_UNUSED;");
1761 for (a
= adj_nunits
; a
; a
= a
->next
)
1766 " /* %s:%d */\n ps = %s;\n",
1767 a
->file
, a
->line
, a
->adjustment
);
1768 printf (" int old_factor = vector_element_size"
1769 " (mode_precision[E_%smode], mode_nunits[E_%smode]);\n",
1771 printf (" mode_precision[E_%smode] = ps * old_factor;\n", m
->name
);
1772 printf (" mode_size[E_%smode] = exact_div (mode_precision[E_%smode],"
1773 " BITS_PER_UNIT);\n", m
->name
, m
->name
);
1774 printf (" mode_nunits[E_%smode] = ps;\n", m
->name
);
1775 printf (" adjust_mode_mask (E_%smode);\n", m
->name
);
1779 /* Size adjustments must be propagated to all containing modes.
1780 A size adjustment forces us to recalculate the alignment too. */
1781 for (a
= adj_bytesize
; a
; a
= a
->next
)
1783 printf ("\n /* %s:%d */\n", a
->file
, a
->line
);
1784 switch (a
->mode
->cl
)
1786 case MODE_VECTOR_BOOL
:
1787 case MODE_VECTOR_INT
:
1788 case MODE_VECTOR_FLOAT
:
1789 case MODE_VECTOR_FRACT
:
1790 case MODE_VECTOR_UFRACT
:
1791 case MODE_VECTOR_ACCUM
:
1792 case MODE_VECTOR_UACCUM
:
1793 printf (" ps = %s;\n", a
->adjustment
);
1794 printf (" s = mode_unit_size[E_%smode];\n", a
->mode
->name
);
1798 printf (" ps = s = %s;\n", a
->adjustment
);
1799 printf (" mode_unit_size[E_%smode] = s;\n", a
->mode
->name
);
1802 printf (" mode_size[E_%smode] = ps;\n", a
->mode
->name
);
1803 printf (" mode_base_align[E_%smode] = known_alignment (ps);\n",
1806 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1810 case MODE_COMPLEX_INT
:
1811 case MODE_COMPLEX_FLOAT
:
1812 printf (" mode_size[E_%smode] = 2*s;\n", m
->name
);
1813 printf (" mode_unit_size[E_%smode] = s;\n", m
->name
);
1814 printf (" mode_base_align[E_%smode] = s & (~s + 1);\n",
1818 case MODE_VECTOR_BOOL
:
1819 /* Changes to BImode should not affect vector booleans. */
1822 case MODE_VECTOR_INT
:
1823 case MODE_VECTOR_FLOAT
:
1824 case MODE_VECTOR_FRACT
:
1825 case MODE_VECTOR_UFRACT
:
1826 case MODE_VECTOR_ACCUM
:
1827 case MODE_VECTOR_UACCUM
:
1828 printf (" mode_size[E_%smode] = %d * ps;\n",
1829 m
->name
, m
->ncomponents
);
1830 printf (" mode_unit_size[E_%smode] = s;\n", m
->name
);
1831 printf (" mode_base_align[E_%smode]"
1832 " = known_alignment (%d * ps);\n",
1833 m
->name
, m
->ncomponents
);
1838 "mode %s is neither vector nor complex but contains %s",
1839 m
->name
, a
->mode
->name
);
1845 /* Alignment adjustments propagate too.
1846 ??? This may not be the right thing for vector modes. */
1847 for (a
= adj_alignment
; a
; a
= a
->next
)
1849 printf ("\n /* %s:%d */\n s = %s;\n",
1850 a
->file
, a
->line
, a
->adjustment
);
1851 printf (" mode_base_align[E_%smode] = s;\n", a
->mode
->name
);
1853 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1857 case MODE_COMPLEX_INT
:
1858 case MODE_COMPLEX_FLOAT
:
1859 printf (" mode_base_align[E_%smode] = s;\n", m
->name
);
1862 case MODE_VECTOR_BOOL
:
1863 /* Changes to BImode should not affect vector booleans. */
1866 case MODE_VECTOR_INT
:
1867 case MODE_VECTOR_FLOAT
:
1868 case MODE_VECTOR_FRACT
:
1869 case MODE_VECTOR_UFRACT
:
1870 case MODE_VECTOR_ACCUM
:
1871 case MODE_VECTOR_UACCUM
:
1872 printf (" mode_base_align[E_%smode] = %d*s;\n",
1873 m
->name
, m
->ncomponents
);
1878 "mode %s is neither vector nor complex but contains %s",
1879 m
->name
, a
->mode
->name
);
1885 /* Ibit adjustments don't have to propagate. */
1886 for (a
= adj_ibit
; a
; a
= a
->next
)
1888 printf ("\n /* %s:%d */\n s = %s;\n",
1889 a
->file
, a
->line
, a
->adjustment
);
1890 printf (" mode_ibit[E_%smode] = s;\n", a
->mode
->name
);
1893 /* Fbit adjustments don't have to propagate. */
1894 for (a
= adj_fbit
; a
; a
= a
->next
)
1896 printf ("\n /* %s:%d */\n s = %s;\n",
1897 a
->file
, a
->line
, a
->adjustment
);
1898 printf (" mode_fbit[E_%smode] = s;\n", a
->mode
->name
);
1901 /* Real mode formats don't have to propagate anywhere. */
1902 for (a
= adj_format
; a
; a
= a
->next
)
1903 printf ("\n /* %s:%d */\n REAL_MODE_FORMAT (E_%smode) = %s;\n",
1904 a
->file
, a
->line
, a
->mode
->name
, a
->adjustment
);
1909 /* Emit ibit for all modes. */
1912 emit_mode_ibit (void)
1915 struct mode_data
*m
;
1917 print_maybe_const_decl ("%sunsigned char",
1918 "mode_ibit", "NUM_MACHINE_MODES",
1921 for_all_modes (c
, m
)
1922 tagged_printf ("%u", m
->ibit
, m
->name
);
1927 /* Emit fbit for all modes. */
1930 emit_mode_fbit (void)
1933 struct mode_data
*m
;
1935 print_maybe_const_decl ("%sunsigned char",
1936 "mode_fbit", "NUM_MACHINE_MODES",
1939 for_all_modes (c
, m
)
1940 tagged_printf ("%u", m
->fbit
, m
->name
);
1945 /* Emit __intN for all modes. */
1948 emit_mode_int_n (void)
1951 struct mode_data
*m
;
1952 struct mode_data
**mode_sort
;
1956 print_decl ("int_n_data_t", "int_n_data", "");
1959 for_all_modes (c
, m
)
1962 mode_sort
= XALLOCAVEC (struct mode_data
*, n_modes
);
1965 for_all_modes (c
, m
)
1967 mode_sort
[n_modes
++] = m
;
1969 /* Yes, this is a bubblesort, but there are at most four (and
1970 usually only 1-2) entries to sort. */
1971 for (i
= 0; i
<n_modes
- 1; i
++)
1972 for (j
= i
+ 1; j
< n_modes
; j
++)
1973 if (mode_sort
[i
]->int_n
> mode_sort
[j
]->int_n
)
1974 std::swap (mode_sort
[i
], mode_sort
[j
]);
1976 for (i
= 0; i
< n_modes
; i
++)
1980 tagged_printf ("%u", m
->int_n
, m
->name
);
1981 printf ("{ E_%smode },", m
->name
);
1990 emit_insn_modes_c (void)
1992 emit_insn_modes_c_header ();
1995 emit_mode_precision ();
1997 emit_mode_nunits ();
1999 emit_mode_complex ();
2002 emit_mode_unit_size ();
2003 emit_mode_unit_precision ();
2004 emit_mode_base_align ();
2005 emit_class_narrowest_mode ();
2006 emit_real_format_for_mode ();
2007 emit_mode_adjustments ();
2014 emit_min_insn_modes_c (void)
2016 emit_min_insn_modes_c_header ();
2019 emit_mode_nunits ();
2022 emit_class_narrowest_mode ();
2025 /* Master control. */
2027 main (int argc
, char **argv
)
2029 bool gen_header
= false, gen_inlines
= false, gen_min
= false;
2034 else if (argc
== 2 && !strcmp (argv
[1], "-h"))
2036 else if (argc
== 2 && !strcmp (argv
[1], "-i"))
2038 else if (argc
== 2 && !strcmp (argv
[1], "-m"))
2042 error ("usage: %s [-h|-i|-m] > file", progname
);
2043 return FATAL_EXIT_CODE
;
2046 modes_by_name
= htab_create_alloc (64, hash_mode
, eq_mode
, 0, xcalloc
, free
);
2049 complete_all_modes ();
2052 return FATAL_EXIT_CODE
;
2057 emit_insn_modes_h ();
2058 else if (gen_inlines
)
2059 emit_insn_modes_inline_h ();
2061 emit_min_insn_modes_c ();
2063 emit_insn_modes_c ();
2065 if (fflush (stdout
) || fclose (stdout
))
2066 return FATAL_EXIT_CODE
;
2067 return SUCCESS_EXIT_CODE
;