1 /* Generate the machine mode enumeration and associated tables.
2 Copyright (C) 2003-2018 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 precision
; /* size in bits, equiv to TYPE_PRECISION */
57 unsigned int bytesize
; /* storage size in addressable units */
58 unsigned int ncomponents
; /* number of subunits */
59 unsigned int alignment
; /* mode alignment */
60 const char *format
; /* floating point format - float modes only */
62 struct mode_data
*component
; /* mode of components */
63 struct mode_data
*wider
; /* next wider mode */
65 struct mode_data
*contained
; /* Pointer to list of modes that have
66 this mode as a component. */
67 struct mode_data
*next_cont
; /* Next mode in that list. */
69 struct mode_data
*complex; /* complex type with mode as component. */
70 const char *file
; /* file and line of definition, */
71 unsigned int line
; /* for error reporting */
72 unsigned int counter
; /* Rank ordering of modes */
73 unsigned int ibit
; /* the number of integral bits */
74 unsigned int fbit
; /* the number of fractional bits */
75 bool need_nunits_adj
; /* true if this mode needs dynamic nunits
77 bool need_bytesize_adj
; /* true if this mode needs dynamic size
79 unsigned int int_n
; /* If nonzero, then __int<INT_N> will be defined */
82 static struct mode_data
*modes
[MAX_MODE_CLASS
];
83 static unsigned int n_modes
[MAX_MODE_CLASS
];
84 static struct mode_data
*void_mode
;
86 static const struct mode_data blank_mode
= {
87 0, "<unknown>", MAX_MODE_CLASS
,
90 "<unknown>", 0, 0, 0, 0, false, false, 0
93 static htab_t modes_by_name
;
95 /* Data structure for recording target-specified runtime adjustments
96 to a particular mode. We support varying the byte size, the
97 alignment, and the floating point format. */
100 struct mode_adjust
*next
;
101 struct mode_data
*mode
;
102 const char *adjustment
;
108 static struct mode_adjust
*adj_nunits
;
109 static struct mode_adjust
*adj_bytesize
;
110 static struct mode_adjust
*adj_alignment
;
111 static struct mode_adjust
*adj_format
;
112 static struct mode_adjust
*adj_ibit
;
113 static struct mode_adjust
*adj_fbit
;
115 /* Mode class operations. */
116 static enum mode_class
117 complex_class (enum mode_class c
)
121 case MODE_INT
: return MODE_COMPLEX_INT
;
122 case MODE_PARTIAL_INT
: return MODE_COMPLEX_INT
;
123 case MODE_FLOAT
: return MODE_COMPLEX_FLOAT
;
125 error ("no complex class for class %s", mode_class_names
[c
]);
130 static enum mode_class
131 vector_class (enum mode_class cl
)
135 case MODE_INT
: return MODE_VECTOR_INT
;
136 case MODE_FLOAT
: return MODE_VECTOR_FLOAT
;
137 case MODE_FRACT
: return MODE_VECTOR_FRACT
;
138 case MODE_UFRACT
: return MODE_VECTOR_UFRACT
;
139 case MODE_ACCUM
: return MODE_VECTOR_ACCUM
;
140 case MODE_UACCUM
: return MODE_VECTOR_UACCUM
;
142 error ("no vector class for class %s", mode_class_names
[cl
]);
147 /* Utility routines. */
148 static inline struct mode_data
*
149 find_mode (const char *name
)
151 struct mode_data key
;
154 return (struct mode_data
*) htab_find (modes_by_name
, &key
);
157 static struct mode_data
*
158 new_mode (enum mode_class cl
, const char *name
,
159 const char *file
, unsigned int line
)
162 static unsigned int count
= 0;
164 m
= find_mode (name
);
167 error ("%s:%d: duplicate definition of mode \"%s\"",
168 trim_filename (file
), line
, name
);
169 error ("%s:%d: previous definition here", m
->file
, m
->line
);
173 m
= XNEW (struct mode_data
);
174 memcpy (m
, &blank_mode
, sizeof (struct mode_data
));
178 m
->file
= trim_filename (file
);
180 m
->counter
= count
++;
186 *htab_find_slot (modes_by_name
, m
, INSERT
) = m
;
192 hash_mode (const void *p
)
194 const struct mode_data
*m
= (const struct mode_data
*)p
;
195 return htab_hash_string (m
->name
);
199 eq_mode (const void *p
, const void *q
)
201 const struct mode_data
*a
= (const struct mode_data
*)p
;
202 const struct mode_data
*b
= (const struct mode_data
*)q
;
204 return !strcmp (a
->name
, b
->name
);
207 #define for_all_modes(C, M) \
208 for (C = 0; C < MAX_MODE_CLASS; C++) \
209 for (M = modes[C]; M; M = M->next)
211 static void ATTRIBUTE_UNUSED
212 new_adjust (const char *name
,
213 struct mode_adjust
**category
, const char *catname
,
214 const char *adjustment
,
215 enum mode_class required_class_from
,
216 enum mode_class required_class_to
,
217 const char *file
, unsigned int line
)
219 struct mode_data
*mode
= find_mode (name
);
220 struct mode_adjust
*a
;
222 file
= trim_filename (file
);
226 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
230 if (required_class_from
!= MODE_RANDOM
231 && (mode
->cl
< required_class_from
|| mode
->cl
> required_class_to
))
233 error ("%s:%d: mode \"%s\" is not among class {%s, %s}",
234 file
, line
, name
, mode_class_names
[required_class_from
] + 5,
235 mode_class_names
[required_class_to
] + 5);
239 for (a
= *category
; a
; a
= a
->next
)
242 error ("%s:%d: mode \"%s\" already has a %s adjustment",
243 file
, line
, name
, catname
);
244 error ("%s:%d: previous adjustment here", a
->file
, a
->line
);
248 a
= XNEW (struct mode_adjust
);
250 a
->adjustment
= adjustment
;
258 /* Diagnose failure to meet expectations in a partially filled out
260 enum requirement
{ SET
, UNSET
, OPTIONAL
};
262 #define validate_field_(mname, fname, req, val, unset, file, line) do { \
267 error ("%s:%d: (%s) field %s must be set", \
268 file, line, mname, fname); \
272 error ("%s:%d: (%s) field %s must not be set", \
273 file, line, mname, fname); \
279 #define validate_field(M, F) \
280 validate_field_(M->name, #F, r_##F, M->F, blank_mode.F, M->file, M->line)
283 validate_mode (struct mode_data
*m
,
284 enum requirement r_precision
,
285 enum requirement r_bytesize
,
286 enum requirement r_component
,
287 enum requirement r_ncomponents
,
288 enum requirement r_format
)
290 validate_field (m
, precision
);
291 validate_field (m
, bytesize
);
292 validate_field (m
, component
);
293 validate_field (m
, ncomponents
);
294 validate_field (m
, format
);
296 #undef validate_field
297 #undef validate_field_
299 /* Given a partially-filled-out mode structure, figure out what we can
300 and fill the rest of it in; die if it isn't enough. */
302 complete_mode (struct mode_data
*m
)
304 unsigned int alignment
;
308 error ("%s:%d: mode with no name", m
->file
, m
->line
);
311 if (m
->cl
== MAX_MODE_CLASS
)
313 error ("%s:%d: %smode has no mode class", m
->file
, m
->line
, m
->name
);
320 /* Nothing more need be said. */
321 if (!strcmp (m
->name
, "VOID"))
324 validate_mode (m
, UNSET
, UNSET
, UNSET
, UNSET
, UNSET
);
333 /* Again, nothing more need be said. For historical reasons,
334 the size of a CC mode is four units. */
335 validate_mode (m
, UNSET
, UNSET
, UNSET
, UNSET
, UNSET
);
343 case MODE_POINTER_BOUNDS
:
345 case MODE_DECIMAL_FLOAT
:
350 /* A scalar mode must have a byte size, may have a bit size,
351 and must not have components. A float mode must have a
353 validate_mode (m
, OPTIONAL
, SET
, UNSET
, UNSET
,
354 (m
->cl
== MODE_FLOAT
|| m
->cl
== MODE_DECIMAL_FLOAT
)
361 case MODE_PARTIAL_INT
:
362 /* A partial integer mode uses ->component to say what the
363 corresponding full-size integer mode is, and may also
364 specify a bit size. */
365 validate_mode (m
, OPTIONAL
, UNSET
, SET
, UNSET
, UNSET
);
367 m
->bytesize
= m
->component
->bytesize
;
372 case MODE_COMPLEX_INT
:
373 case MODE_COMPLEX_FLOAT
:
374 /* Complex modes should have a component indicated, but no more. */
375 validate_mode (m
, UNSET
, UNSET
, SET
, UNSET
, UNSET
);
377 if (m
->component
->precision
!= (unsigned int)-1)
378 m
->precision
= 2 * m
->component
->precision
;
379 m
->bytesize
= 2 * m
->component
->bytesize
;
382 case MODE_VECTOR_BOOL
:
383 validate_mode (m
, UNSET
, SET
, SET
, SET
, UNSET
);
386 case MODE_VECTOR_INT
:
387 case MODE_VECTOR_FLOAT
:
388 case MODE_VECTOR_FRACT
:
389 case MODE_VECTOR_UFRACT
:
390 case MODE_VECTOR_ACCUM
:
391 case MODE_VECTOR_UACCUM
:
392 /* Vector modes should have a component and a number of components. */
393 validate_mode (m
, UNSET
, UNSET
, SET
, SET
, UNSET
);
394 if (m
->component
->precision
!= (unsigned int)-1)
395 m
->precision
= m
->ncomponents
* m
->component
->precision
;
396 m
->bytesize
= m
->ncomponents
* m
->component
->bytesize
;
403 /* If not already specified, the mode alignment defaults to the largest
404 power of two that divides the size of the object. Complex types are
405 not more aligned than their contents. */
406 if (m
->cl
== MODE_COMPLEX_INT
|| m
->cl
== MODE_COMPLEX_FLOAT
)
407 alignment
= m
->component
->bytesize
;
409 alignment
= m
->bytesize
;
411 m
->alignment
= alignment
& (~alignment
+ 1);
413 /* If this mode has components, make the component mode point back
414 to this mode, for the sake of adjustments. */
417 m
->next_cont
= m
->component
->contained
;
418 m
->component
->contained
= m
;
423 complete_all_modes (void)
428 for_all_modes (cl
, m
)
432 /* For each mode in class CLASS, construct a corresponding complex mode. */
433 #define COMPLEX_MODES(C) make_complex_modes (MODE_##C, __FILE__, __LINE__)
435 make_complex_modes (enum mode_class cl
,
436 const char *file
, unsigned int line
)
440 enum mode_class cclass
= complex_class (cl
);
442 if (cclass
== MODE_RANDOM
)
445 for (m
= modes
[cl
]; m
; m
= m
->next
)
450 /* Skip BImode. FIXME: BImode probably shouldn't be MODE_INT. */
451 if (m
->precision
== 1)
454 m_len
= strlen (m
->name
);
455 /* The leading "1 +" is in case we prepend a "C" below. */
456 buf
= (char *) xmalloc (1 + m_len
+ 1);
458 /* Float complex modes are named SCmode, etc.
459 Int complex modes are named CSImode, etc.
460 This inconsistency should be eliminated. */
462 if (cl
== MODE_FLOAT
)
464 memcpy (buf
, m
->name
, m_len
+ 1);
465 p
= strchr (buf
, 'F');
466 if (p
== 0 && strchr (buf
, 'D') == 0)
468 error ("%s:%d: float mode \"%s\" has no 'F' or 'D'",
469 m
->file
, m
->line
, m
->name
);
479 memcpy (buf
+ 1, m
->name
, m_len
+ 1);
482 c
= new_mode (cclass
, buf
, file
, line
);
488 /* For all modes in class CL, construct vector modes of width
489 WIDTH, having as many components as necessary. */
490 #define VECTOR_MODES_WITH_PREFIX(PREFIX, C, W) \
491 make_vector_modes (MODE_##C, #PREFIX, W, __FILE__, __LINE__)
492 #define VECTOR_MODES(C, W) VECTOR_MODES_WITH_PREFIX (V, C, W)
493 static void ATTRIBUTE_UNUSED
494 make_vector_modes (enum mode_class cl
, const char *prefix
, unsigned int width
,
495 const char *file
, unsigned int line
)
499 /* Big enough for a 32-bit UINT_MAX plus the text. */
501 unsigned int ncomponents
;
502 enum mode_class vclass
= vector_class (cl
);
504 if (vclass
== MODE_RANDOM
)
507 for (m
= modes
[cl
]; m
; m
= m
->next
)
509 /* Do not construct vector modes with only one element, or
510 vector modes where the element size doesn't divide the full
512 ncomponents
= width
/ m
->bytesize
;
515 if (width
% m
->bytesize
)
518 /* Skip QFmode and BImode. FIXME: this special case should
520 if (cl
== MODE_FLOAT
&& m
->bytesize
== 1)
522 if (cl
== MODE_INT
&& m
->precision
== 1)
525 if ((size_t) snprintf (buf
, sizeof buf
, "%s%u%s", prefix
,
526 ncomponents
, m
->name
) >= sizeof buf
)
528 error ("%s:%d: mode name \"%s\" is too long",
529 m
->file
, m
->line
, m
->name
);
533 v
= new_mode (vclass
, xstrdup (buf
), file
, line
);
535 v
->ncomponents
= ncomponents
;
539 /* Create a vector of booleans called NAME with COUNT elements and
540 BYTESIZE bytes in total. */
541 #define VECTOR_BOOL_MODE(NAME, COUNT, BYTESIZE) \
542 make_vector_bool_mode (#NAME, COUNT, BYTESIZE, __FILE__, __LINE__)
543 static void ATTRIBUTE_UNUSED
544 make_vector_bool_mode (const char *name
, unsigned int count
,
545 unsigned int bytesize
, const char *file
,
548 struct mode_data
*m
= find_mode ("BI");
551 error ("%s:%d: no mode \"BI\"", file
, line
);
555 struct mode_data
*v
= new_mode (MODE_VECTOR_BOOL
, name
, file
, line
);
557 v
->ncomponents
= count
;
558 v
->bytesize
= bytesize
;
563 #define _SPECIAL_MODE(C, N) \
564 make_special_mode (MODE_##C, #N, __FILE__, __LINE__)
565 #define RANDOM_MODE(N) _SPECIAL_MODE (RANDOM, N)
566 #define CC_MODE(N) _SPECIAL_MODE (CC, N)
569 make_special_mode (enum mode_class cl
, const char *name
,
570 const char *file
, unsigned int line
)
572 new_mode (cl
, name
, file
, line
);
575 #define POINTER_BOUNDS_MODE(N, Y) \
576 make_pointer_bounds_mode (#N, Y, __FILE__, __LINE__)
578 static void ATTRIBUTE_UNUSED
579 make_pointer_bounds_mode (const char *name
,
580 unsigned int bytesize
,
581 const char *file
, unsigned int line
)
583 struct mode_data
*m
= new_mode (MODE_POINTER_BOUNDS
, name
, file
, line
);
584 m
->bytesize
= bytesize
;
588 #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y)
589 #define FRACTIONAL_INT_MODE(N, B, Y) \
590 make_int_mode (#N, B, Y, __FILE__, __LINE__)
593 make_int_mode (const char *name
,
594 unsigned int precision
, unsigned int bytesize
,
595 const char *file
, unsigned int line
)
597 struct mode_data
*m
= new_mode (MODE_INT
, name
, file
, line
);
598 m
->bytesize
= bytesize
;
599 m
->precision
= precision
;
602 #define FRACT_MODE(N, Y, F) \
603 make_fixed_point_mode (MODE_FRACT, #N, Y, 0, F, __FILE__, __LINE__)
605 #define UFRACT_MODE(N, Y, F) \
606 make_fixed_point_mode (MODE_UFRACT, #N, Y, 0, F, __FILE__, __LINE__)
608 #define ACCUM_MODE(N, Y, I, F) \
609 make_fixed_point_mode (MODE_ACCUM, #N, Y, I, F, __FILE__, __LINE__)
611 #define UACCUM_MODE(N, Y, I, F) \
612 make_fixed_point_mode (MODE_UACCUM, #N, Y, I, F, __FILE__, __LINE__)
614 /* Create a fixed-point mode by setting CL, NAME, BYTESIZE, IBIT, FBIT,
618 make_fixed_point_mode (enum mode_class cl
,
620 unsigned int bytesize
,
623 const char *file
, unsigned int line
)
625 struct mode_data
*m
= new_mode (cl
, name
, file
, line
);
626 m
->bytesize
= bytesize
;
631 #define FLOAT_MODE(N, Y, F) FRACTIONAL_FLOAT_MODE (N, -1U, Y, F)
632 #define FRACTIONAL_FLOAT_MODE(N, B, Y, F) \
633 make_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
636 make_float_mode (const char *name
,
637 unsigned int precision
, unsigned int bytesize
,
639 const char *file
, unsigned int line
)
641 struct mode_data
*m
= new_mode (MODE_FLOAT
, name
, file
, line
);
642 m
->bytesize
= bytesize
;
643 m
->precision
= precision
;
647 #define DECIMAL_FLOAT_MODE(N, Y, F) \
648 FRACTIONAL_DECIMAL_FLOAT_MODE (N, -1U, Y, F)
649 #define FRACTIONAL_DECIMAL_FLOAT_MODE(N, B, Y, F) \
650 make_decimal_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
653 make_decimal_float_mode (const char *name
,
654 unsigned int precision
, unsigned int bytesize
,
656 const char *file
, unsigned int line
)
658 struct mode_data
*m
= new_mode (MODE_DECIMAL_FLOAT
, name
, file
, line
);
659 m
->bytesize
= bytesize
;
660 m
->precision
= precision
;
664 #define RESET_FLOAT_FORMAT(N, F) \
665 reset_float_format (#N, #F, __FILE__, __LINE__)
666 static void ATTRIBUTE_UNUSED
667 reset_float_format (const char *name
, const char *format
,
668 const char *file
, unsigned int line
)
670 struct mode_data
*m
= find_mode (name
);
673 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
676 if (m
->cl
!= MODE_FLOAT
&& m
->cl
!= MODE_DECIMAL_FLOAT
)
678 error ("%s:%d: mode \"%s\" is not a FLOAT class", file
, line
, name
);
684 /* __intN support. */
685 #define INT_N(M,PREC) \
686 make_int_n (#M, PREC, __FILE__, __LINE__)
687 static void ATTRIBUTE_UNUSED
688 make_int_n (const char *m
, int bitsize
,
689 const char *file
, unsigned int line
)
691 struct mode_data
*component
= find_mode (m
);
694 error ("%s:%d: no mode \"%s\"", file
, line
, m
);
697 if (component
->cl
!= MODE_INT
698 && component
->cl
!= MODE_PARTIAL_INT
)
700 error ("%s:%d: mode \"%s\" is not class INT or PARTIAL_INT", file
, line
, m
);
703 if (component
->int_n
!= 0)
705 error ("%s:%d: mode \"%s\" already has an intN", file
, line
, m
);
709 component
->int_n
= bitsize
;
712 /* Partial integer modes are specified by relation to a full integer
714 #define PARTIAL_INT_MODE(M,PREC,NAME) \
715 make_partial_integer_mode (#M, #NAME, PREC, __FILE__, __LINE__)
716 static void ATTRIBUTE_UNUSED
717 make_partial_integer_mode (const char *base
, const char *name
,
718 unsigned int precision
,
719 const char *file
, unsigned int line
)
722 struct mode_data
*component
= find_mode (base
);
725 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
728 if (component
->cl
!= MODE_INT
)
730 error ("%s:%d: mode \"%s\" is not class INT", file
, line
, name
);
734 m
= new_mode (MODE_PARTIAL_INT
, name
, file
, line
);
735 m
->precision
= precision
;
736 m
->component
= component
;
739 /* A single vector mode can be specified by naming its component
740 mode and the number of components. */
741 #define VECTOR_MODE(C, M, N) \
742 make_vector_mode (MODE_##C, #M, N, __FILE__, __LINE__);
743 static void ATTRIBUTE_UNUSED
744 make_vector_mode (enum mode_class bclass
,
746 unsigned int ncomponents
,
747 const char *file
, unsigned int line
)
750 enum mode_class vclass
= vector_class (bclass
);
751 struct mode_data
*component
= find_mode (base
);
754 if (vclass
== MODE_RANDOM
)
758 error ("%s:%d: no mode \"%s\"", file
, line
, base
);
761 if (component
->cl
!= bclass
762 && (component
->cl
!= MODE_PARTIAL_INT
763 || bclass
!= MODE_INT
))
765 error ("%s:%d: mode \"%s\" is not class %s",
766 file
, line
, base
, mode_class_names
[bclass
] + 5);
770 if ((size_t)snprintf (namebuf
, sizeof namebuf
, "V%u%s",
771 ncomponents
, base
) >= sizeof namebuf
)
773 error ("%s:%d: mode name \"%s\" is too long",
778 v
= new_mode (vclass
, xstrdup (namebuf
), file
, line
);
779 v
->ncomponents
= ncomponents
;
780 v
->component
= component
;
784 #define _ADD_ADJUST(A, M, X, C1, C2) \
785 new_adjust (#M, &adj_##A, #A, #X, MODE_##C1, MODE_##C2, __FILE__, __LINE__)
787 #define ADJUST_NUNITS(M, X) _ADD_ADJUST (nunits, M, X, RANDOM, RANDOM)
788 #define ADJUST_BYTESIZE(M, X) _ADD_ADJUST (bytesize, M, X, RANDOM, RANDOM)
789 #define ADJUST_ALIGNMENT(M, X) _ADD_ADJUST (alignment, M, X, RANDOM, RANDOM)
790 #define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST (format, M, X, FLOAT, FLOAT)
791 #define ADJUST_IBIT(M, X) _ADD_ADJUST (ibit, M, X, ACCUM, UACCUM)
792 #define ADJUST_FBIT(M, X) _ADD_ADJUST (fbit, M, X, FRACT, UACCUM)
794 static int bits_per_unit
;
795 static int max_bitsize_mode_any_int
;
796 static int max_bitsize_mode_any_mode
;
801 #include "machmode.def"
803 /* So put the default value unless the target needs a non standard
806 bits_per_unit
= BITS_PER_UNIT
;
811 #ifdef MAX_BITSIZE_MODE_ANY_INT
812 max_bitsize_mode_any_int
= MAX_BITSIZE_MODE_ANY_INT
;
814 max_bitsize_mode_any_int
= 0;
817 #ifdef MAX_BITSIZE_MODE_ANY_MODE
818 max_bitsize_mode_any_mode
= MAX_BITSIZE_MODE_ANY_MODE
;
820 max_bitsize_mode_any_mode
= 0;
824 #ifndef NUM_POLY_INT_COEFFS
825 #define NUM_POLY_INT_COEFFS 1
830 /* Sort a list of modes into the order needed for the WIDER field:
831 major sort by precision, minor sort by component precision.
834 QI < HI < SI < DI < TI
835 V4QI < V2HI < V8QI < V4HI < V2SI.
837 If the precision is not set, sort by the bytesize. A mode with
838 precision set gets sorted before a mode without precision set, if
839 they have the same bytesize; this is the right thing because
840 the precision must always be smaller than the bytesize * BITS_PER_UNIT.
841 We don't have to do anything special to get this done -- an unset
842 precision shows up as (unsigned int)-1, i.e. UINT_MAX. */
844 cmp_modes (const void *a
, const void *b
)
846 const struct mode_data
*const m
= *(const struct mode_data
*const*)a
;
847 const struct mode_data
*const n
= *(const struct mode_data
*const*)b
;
849 if (m
->bytesize
> n
->bytesize
)
851 else if (m
->bytesize
< n
->bytesize
)
854 if (m
->precision
> n
->precision
)
856 else if (m
->precision
< n
->precision
)
859 if (!m
->component
&& !n
->component
)
861 if (m
->counter
< n
->counter
)
867 if (m
->component
->bytesize
> n
->component
->bytesize
)
869 else if (m
->component
->bytesize
< n
->component
->bytesize
)
872 if (m
->component
->precision
> n
->component
->precision
)
874 else if (m
->component
->precision
< n
->component
->precision
)
877 if (m
->counter
< n
->counter
)
884 calc_wider_mode (void)
888 struct mode_data
**sortbuf
;
889 unsigned int max_n_modes
= 0;
892 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
893 max_n_modes
= MAX (max_n_modes
, n_modes
[c
]);
895 /* Allocate max_n_modes + 1 entries to leave room for the extra null
896 pointer assigned after the qsort call below. */
897 sortbuf
= XALLOCAVEC (struct mode_data
*, max_n_modes
+ 1);
899 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
901 /* "wider" is not meaningful for MODE_RANDOM and MODE_CC.
902 However, we want these in textual order, and we have
903 precisely the reverse. */
904 if (c
== MODE_RANDOM
|| c
== MODE_CC
)
906 struct mode_data
*prev
, *next
;
908 for (prev
= 0, m
= modes
[c
]; m
; m
= next
)
910 m
->wider
= void_mode
;
912 /* this is nreverse */
924 for (i
= 0, m
= modes
[c
]; m
; i
++, m
= m
->next
)
927 (qsort
) (sortbuf
, i
, sizeof (struct mode_data
*), cmp_modes
);
930 for (j
= 0; j
< i
; j
++)
932 sortbuf
[j
]->next
= sortbuf
[j
+ 1];
933 if (c
== MODE_PARTIAL_INT
)
934 sortbuf
[j
]->wider
= sortbuf
[j
]->component
;
936 sortbuf
[j
]->wider
= sortbuf
[j
]->next
;
939 modes
[c
] = sortbuf
[0];
944 /* Text to add to the constant part of a poly_int_pod initializer in
945 order to fill out te whole structure. */
946 #if NUM_POLY_INT_COEFFS == 1
947 #define ZERO_COEFFS ""
948 #elif NUM_POLY_INT_COEFFS == 2
949 #define ZERO_COEFFS ", 0"
951 #error "Unknown value of NUM_POLY_INT_COEFFS"
954 /* Output routines. */
956 #define tagged_printf(FMT, ARG, TAG) do { \
957 int count_ = printf (" " FMT ",", ARG); \
958 printf ("%*s/* %s */\n", 27 - count_, "", TAG); \
961 #define print_decl(TYPE, NAME, ASIZE) \
962 puts ("\nconst " TYPE " " NAME "[" ASIZE "] =\n{");
964 #define print_maybe_const_decl(TYPE, NAME, ASIZE, NEEDS_ADJ) \
965 printf ("\n" TYPE " " NAME "[" ASIZE "] = \n{\n", \
966 NEEDS_ADJ ? "" : "const ")
968 #define print_closer() puts ("};")
970 /* Compute the max bitsize of some of the classes of integers. It may
971 be that there are needs for the other integer classes, and this
972 code is easy to extend. */
976 unsigned int max
, mmax
;
982 printf ("#define BITS_PER_UNIT (%d)\n", bits_per_unit
);
984 if (max_bitsize_mode_any_int
== 0)
986 for (max
= 1, i
= modes
[MODE_INT
]; i
; i
= i
->next
)
987 if (max
< i
->bytesize
)
990 for (max
= 1, i
= modes
[MODE_PARTIAL_INT
]; i
; i
= i
->next
)
991 if (max
< i
->bytesize
)
995 printf ("#define MAX_BITSIZE_MODE_ANY_INT (%d*BITS_PER_UNIT)\n", mmax
);
998 printf ("#define MAX_BITSIZE_MODE_ANY_INT %d\n", max_bitsize_mode_any_int
);
1000 if (max_bitsize_mode_any_mode
== 0)
1003 for (j
= 0; j
< MAX_MODE_CLASS
; j
++)
1004 for (i
= modes
[j
]; i
; i
= i
->next
)
1005 if (mmax
< i
->bytesize
)
1007 printf ("#define MAX_BITSIZE_MODE_ANY_MODE (%d*BITS_PER_UNIT)\n", mmax
);
1010 printf ("#define MAX_BITSIZE_MODE_ANY_MODE %d\n",
1011 max_bitsize_mode_any_mode
);
1014 /* Emit mode_size_inline routine into insn-modes.h header. */
1016 emit_mode_size_inline (void)
1019 struct mode_adjust
*a
;
1020 struct mode_data
*m
;
1022 /* Size adjustments must be propagated to all containing modes. */
1023 for (a
= adj_bytesize
; a
; a
= a
->next
)
1025 a
->mode
->need_bytesize_adj
= true;
1026 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1027 m
->need_bytesize_adj
= true;
1030 /* Changing the number of units by a factor of X also changes the size
1031 by a factor of X. */
1032 for (mode_adjust
*a
= adj_nunits
; a
; a
= a
->next
)
1033 a
->mode
->need_bytesize_adj
= true;
1036 #ifdef __cplusplus\n\
1037 inline __attribute__((__always_inline__))\n\
1039 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1042 mode_size_inline (machine_mode mode)\n\
1044 extern %spoly_uint16_pod mode_size[NUM_MACHINE_MODES];\n\
1045 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1047 {\n", adj_nunits
|| adj_bytesize
? "" : "const ");
1049 for_all_modes (c
, m
)
1050 if (!m
->need_bytesize_adj
)
1051 printf (" case E_%smode: return %u;\n", m
->name
, m
->bytesize
);
1054 default: return mode_size[mode];\n\
1059 /* Emit mode_nunits_inline routine into insn-modes.h header. */
1061 emit_mode_nunits_inline (void)
1064 struct mode_data
*m
;
1066 for (mode_adjust
*a
= adj_nunits
; a
; a
= a
->next
)
1067 a
->mode
->need_nunits_adj
= true;
1070 #ifdef __cplusplus\n\
1071 inline __attribute__((__always_inline__))\n\
1073 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1076 mode_nunits_inline (machine_mode mode)\n\
1078 extern %spoly_uint16_pod mode_nunits[NUM_MACHINE_MODES];\n\
1080 {\n", adj_nunits
? "" : "const ");
1082 for_all_modes (c
, m
)
1083 if (!m
->need_nunits_adj
)
1084 printf (" case E_%smode: return %u;\n", m
->name
, m
->ncomponents
);
1087 default: return mode_nunits[mode];\n\
1092 /* Emit mode_inner_inline routine into insn-modes.h header. */
1094 emit_mode_inner_inline (void)
1097 struct mode_data
*m
;
1100 #ifdef __cplusplus\n\
1101 inline __attribute__((__always_inline__))\n\
1103 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1106 mode_inner_inline (machine_mode mode)\n\
1108 extern const unsigned char mode_inner[NUM_MACHINE_MODES];\n\
1109 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1113 for_all_modes (c
, m
)
1114 printf (" case E_%smode: return E_%smode;\n", m
->name
,
1115 c
!= MODE_PARTIAL_INT
&& m
->component
1116 ? m
->component
->name
: m
->name
);
1119 default: return mode_inner[mode];\n\
1124 /* Emit mode_unit_size_inline routine into insn-modes.h header. */
1126 emit_mode_unit_size_inline (void)
1129 struct mode_data
*m
;
1132 #ifdef __cplusplus\n\
1133 inline __attribute__((__always_inline__))\n\
1135 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1138 mode_unit_size_inline (machine_mode mode)\n\
1140 extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES];\
1142 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1146 for_all_modes (c
, m
)
1148 const char *name
= m
->name
;
1149 struct mode_data
*m2
= m
;
1150 if (c
!= MODE_PARTIAL_INT
&& m2
->component
)
1152 if (!m2
->need_bytesize_adj
)
1153 printf (" case E_%smode: return %u;\n", name
, m2
->bytesize
);
1157 default: return mode_unit_size[mode];\n\
1162 /* Emit mode_unit_precision_inline routine into insn-modes.h header. */
1164 emit_mode_unit_precision_inline (void)
1167 struct mode_data
*m
;
1170 #ifdef __cplusplus\n\
1171 inline __attribute__((__always_inline__))\n\
1173 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1176 mode_unit_precision_inline (machine_mode mode)\n\
1178 extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES];\n\
1179 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1183 for_all_modes (c
, m
)
1185 struct mode_data
*m2
1186 = (c
!= MODE_PARTIAL_INT
&& m
->component
) ? m
->component
: m
;
1187 if (m2
->precision
!= (unsigned int)-1)
1188 printf (" case E_%smode: return %u;\n", m
->name
, m2
->precision
);
1190 printf (" case E_%smode: return %u*BITS_PER_UNIT;\n",
1191 m
->name
, m2
->bytesize
);
1195 default: return mode_unit_precision[mode];\n\
1200 /* Return the best machine mode class for MODE, or null if machine_mode
1204 get_mode_class (struct mode_data
*mode
)
1209 case MODE_PARTIAL_INT
:
1210 return "scalar_int_mode";
1216 case MODE_POINTER_BOUNDS
:
1217 return "scalar_mode";
1220 case MODE_DECIMAL_FLOAT
:
1221 return "scalar_float_mode";
1223 case MODE_COMPLEX_INT
:
1224 case MODE_COMPLEX_FLOAT
:
1225 return "complex_mode";
1233 emit_insn_modes_h (void)
1236 struct mode_data
*m
, *first
, *last
;
1237 int n_int_n_ents
= 0;
1239 printf ("/* Generated automatically from machmode.def%s%s\n",
1240 HAVE_EXTRA_MODES
? " and " : "",
1246 #ifndef GCC_INSN_MODES_H\n\
1247 #define GCC_INSN_MODES_H\n\
1249 enum machine_mode\n{");
1251 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1252 for (m
= modes
[c
]; m
; m
= m
->next
)
1254 int count_
= printf (" E_%smode,", m
->name
);
1255 printf ("%*s/* %s:%d */\n", 27 - count_
, "",
1256 trim_filename (m
->file
), m
->line
);
1257 printf ("#define HAVE_%smode\n", m
->name
);
1258 printf ("#ifdef USE_ENUM_MODES\n");
1259 printf ("#define %smode E_%smode\n", m
->name
, m
->name
);
1261 if (const char *mode_class
= get_mode_class (m
))
1262 printf ("#define %smode (%s ((%s::from_int) E_%smode))\n",
1263 m
->name
, mode_class
, mode_class
, m
->name
);
1265 printf ("#define %smode ((void) 0, E_%smode)\n",
1267 printf ("#endif\n");
1270 puts (" MAX_MACHINE_MODE,\n");
1272 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1276 for (m
= first
; m
; last
= m
, m
= m
->next
)
1279 /* Don't use BImode for MIN_MODE_INT, since otherwise the middle
1280 end will try to use it for bitfields in structures and the
1281 like, which we do not want. Only the target md file should
1282 generate BImode widgets. */
1283 if (first
&& first
->precision
== 1 && c
== MODE_INT
)
1284 first
= first
->next
;
1287 printf (" MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n",
1288 mode_class_names
[c
], first
->name
,
1289 mode_class_names
[c
], last
->name
);
1291 printf (" MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n",
1292 mode_class_names
[c
], void_mode
->name
,
1293 mode_class_names
[c
], void_mode
->name
);
1297 NUM_MACHINE_MODES = MAX_MACHINE_MODE\n\
1300 /* I can't think of a better idea, can you? */
1301 printf ("#define CONST_MODE_NUNITS%s\n", adj_nunits
? "" : " const");
1302 printf ("#define CONST_MODE_PRECISION%s\n", adj_nunits
? "" : " const");
1303 printf ("#define CONST_MODE_SIZE%s\n",
1304 adj_bytesize
|| adj_nunits
? "" : " const");
1305 printf ("#define CONST_MODE_UNIT_SIZE%s\n", adj_bytesize
? "" : " const");
1306 printf ("#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment
? "" : " const");
1307 #if 0 /* disabled for backward compatibility, temporary */
1308 printf ("#define CONST_REAL_FORMAT_FOR_MODE%s\n", adj_format
? "" :" const");
1310 printf ("#define CONST_MODE_IBIT%s\n", adj_ibit
? "" : " const");
1311 printf ("#define CONST_MODE_FBIT%s\n", adj_fbit
? "" : " const");
1314 for_all_modes (c
, m
)
1318 printf ("#define NUM_INT_N_ENTS %d\n", n_int_n_ents
);
1320 printf ("#define NUM_POLY_INT_COEFFS %d\n", NUM_POLY_INT_COEFFS
);
1324 #endif /* insn-modes.h */");
1328 emit_insn_modes_inline_h (void)
1330 printf ("/* Generated automatically from machmode.def%s%s\n",
1331 HAVE_EXTRA_MODES
? " and " : "",
1337 #ifndef GCC_INSN_MODES_INLINE_H\n\
1338 #define GCC_INSN_MODES_INLINE_H");
1340 puts ("\n#if !defined (USED_FOR_TARGET) && GCC_VERSION >= 4001\n");
1341 emit_mode_size_inline ();
1342 emit_mode_nunits_inline ();
1343 emit_mode_inner_inline ();
1344 emit_mode_unit_size_inline ();
1345 emit_mode_unit_precision_inline ();
1346 puts ("#endif /* GCC_VERSION >= 4001 */");
1350 #endif /* insn-modes-inline.h */");
1354 emit_insn_modes_c_header (void)
1356 printf ("/* Generated automatically from machmode.def%s%s\n",
1357 HAVE_EXTRA_MODES
? " and " : "",
1363 #include \"config.h\"\n\
1364 #include \"system.h\"\n\
1365 #include \"coretypes.h\"\n\
1366 #include \"tm.h\"\n\
1367 #include \"real.h\"");
1371 emit_min_insn_modes_c_header (void)
1373 printf ("/* Generated automatically from machmode.def%s%s\n",
1374 HAVE_EXTRA_MODES
? " and " : "",
1380 #include \"bconfig.h\"\n\
1381 #include \"system.h\"\n\
1382 #include \"coretypes.h\"");
1386 emit_mode_name (void)
1389 struct mode_data
*m
;
1391 print_decl ("char *const", "mode_name", "NUM_MACHINE_MODES");
1393 for_all_modes (c
, m
)
1394 printf (" \"%s\",\n", m
->name
);
1400 emit_mode_class (void)
1403 struct mode_data
*m
;
1405 print_decl ("unsigned char", "mode_class", "NUM_MACHINE_MODES");
1407 for_all_modes (c
, m
)
1408 tagged_printf ("%s", mode_class_names
[m
->cl
], m
->name
);
1414 emit_mode_precision (void)
1417 struct mode_data
*m
;
1419 print_maybe_const_decl ("%spoly_uint16_pod", "mode_precision",
1420 "NUM_MACHINE_MODES", adj_nunits
);
1422 for_all_modes (c
, m
)
1423 if (m
->precision
!= (unsigned int)-1)
1424 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->precision
, m
->name
);
1426 tagged_printf ("{ %u * BITS_PER_UNIT" ZERO_COEFFS
" }",
1427 m
->bytesize
, m
->name
);
1433 emit_mode_size (void)
1436 struct mode_data
*m
;
1438 print_maybe_const_decl ("%spoly_uint16_pod", "mode_size",
1439 "NUM_MACHINE_MODES", adj_nunits
|| adj_bytesize
);
1441 for_all_modes (c
, m
)
1442 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->bytesize
, m
->name
);
1448 emit_mode_nunits (void)
1451 struct mode_data
*m
;
1453 print_maybe_const_decl ("%spoly_uint16_pod", "mode_nunits",
1454 "NUM_MACHINE_MODES", adj_nunits
);
1456 for_all_modes (c
, m
)
1457 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->ncomponents
, m
->name
);
1463 emit_mode_wider (void)
1466 struct mode_data
*m
;
1468 print_decl ("unsigned char", "mode_wider", "NUM_MACHINE_MODES");
1470 for_all_modes (c
, m
)
1471 tagged_printf ("E_%smode",
1472 m
->wider
? m
->wider
->name
: void_mode
->name
,
1476 print_decl ("unsigned char", "mode_2xwider", "NUM_MACHINE_MODES");
1478 for_all_modes (c
, m
)
1480 struct mode_data
* m2
;
1483 m2
&& m2
!= void_mode
;
1486 if (m2
->bytesize
< 2 * m
->bytesize
)
1488 if (m
->precision
!= (unsigned int) -1)
1490 if (m2
->precision
!= 2 * m
->precision
)
1495 if (m2
->precision
!= (unsigned int) -1)
1499 /* For vectors we want twice the number of components,
1500 with the same element type. */
1501 if (m
->cl
== MODE_VECTOR_BOOL
1502 || m
->cl
== MODE_VECTOR_INT
1503 || m
->cl
== MODE_VECTOR_FLOAT
1504 || m
->cl
== MODE_VECTOR_FRACT
1505 || m
->cl
== MODE_VECTOR_UFRACT
1506 || m
->cl
== MODE_VECTOR_ACCUM
1507 || m
->cl
== MODE_VECTOR_UACCUM
)
1509 if (m2
->ncomponents
!= 2 * m
->ncomponents
)
1511 if (m
->component
!= m2
->component
)
1517 if (m2
== void_mode
)
1519 tagged_printf ("E_%smode",
1520 m2
? m2
->name
: void_mode
->name
,
1528 emit_mode_complex (void)
1531 struct mode_data
*m
;
1533 print_decl ("unsigned char", "mode_complex", "NUM_MACHINE_MODES");
1535 for_all_modes (c
, m
)
1536 tagged_printf ("E_%smode",
1537 m
->complex ? m
->complex->name
: void_mode
->name
,
1544 emit_mode_mask (void)
1547 struct mode_data
*m
;
1549 print_decl ("unsigned HOST_WIDE_INT", "mode_mask_array",
1550 "NUM_MACHINE_MODES");
1552 #define MODE_MASK(m) \\\n\
1553 ((m) >= HOST_BITS_PER_WIDE_INT) \\\n\
1554 ? HOST_WIDE_INT_M1U \\\n\
1555 : (HOST_WIDE_INT_1U << (m)) - 1\n");
1557 for_all_modes (c
, m
)
1558 if (m
->precision
!= (unsigned int)-1)
1559 tagged_printf ("MODE_MASK (%u)", m
->precision
, m
->name
);
1561 tagged_printf ("MODE_MASK (%u*BITS_PER_UNIT)", m
->bytesize
, m
->name
);
1563 puts ("#undef MODE_MASK");
1568 emit_mode_inner (void)
1571 struct mode_data
*m
;
1573 print_decl ("unsigned char", "mode_inner", "NUM_MACHINE_MODES");
1575 for_all_modes (c
, m
)
1576 tagged_printf ("E_%smode",
1577 c
!= MODE_PARTIAL_INT
&& m
->component
1578 ? m
->component
->name
: m
->name
,
1584 /* Emit mode_unit_size array into insn-modes.c file. */
1586 emit_mode_unit_size (void)
1589 struct mode_data
*m
;
1591 print_maybe_const_decl ("%sunsigned char", "mode_unit_size",
1592 "NUM_MACHINE_MODES", adj_bytesize
);
1594 for_all_modes (c
, m
)
1595 tagged_printf ("%u",
1596 c
!= MODE_PARTIAL_INT
&& m
->component
1597 ? m
->component
->bytesize
: m
->bytesize
, m
->name
);
1602 /* Emit mode_unit_precision array into insn-modes.c file. */
1604 emit_mode_unit_precision (void)
1607 struct mode_data
*m
;
1609 print_decl ("unsigned short", "mode_unit_precision", "NUM_MACHINE_MODES");
1611 for_all_modes (c
, m
)
1613 struct mode_data
*m2
= (c
!= MODE_PARTIAL_INT
&& m
->component
) ?
1615 if (m2
->precision
!= (unsigned int)-1)
1616 tagged_printf ("%u", m2
->precision
, m
->name
);
1618 tagged_printf ("%u*BITS_PER_UNIT", m2
->bytesize
, m
->name
);
1626 emit_mode_base_align (void)
1629 struct mode_data
*m
;
1631 print_maybe_const_decl ("%sunsigned short",
1632 "mode_base_align", "NUM_MACHINE_MODES",
1635 for_all_modes (c
, m
)
1636 tagged_printf ("%u", m
->alignment
, m
->name
);
1642 emit_class_narrowest_mode (void)
1646 print_decl ("unsigned char", "class_narrowest_mode", "MAX_MODE_CLASS");
1648 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1649 /* Bleah, all this to get the comment right for MIN_MODE_INT. */
1650 tagged_printf ("MIN_%s", mode_class_names
[c
],
1652 ? ((c
!= MODE_INT
|| modes
[c
]->precision
!= 1)
1655 ? modes
[c
]->next
->name
1663 emit_real_format_for_mode (void)
1665 struct mode_data
*m
;
1667 /* The entities pointed to by this table are constant, whether
1668 or not the table itself is constant.
1670 For backward compatibility this table is always writable
1671 (several targets modify it in TARGET_OPTION_OVERRIDE). FIXME:
1672 convert all said targets to use ADJUST_FORMAT instead. */
1674 print_maybe_const_decl ("const struct real_format *%s",
1675 "real_format_for_mode",
1676 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1",
1679 print_decl ("struct real_format *\n", "real_format_for_mode",
1680 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1 "
1681 "+ MAX_MODE_DECIMAL_FLOAT - MIN_MODE_DECIMAL_FLOAT + 1");
1684 /* The beginning of the table is entries for float modes. */
1685 for (m
= modes
[MODE_FLOAT
]; m
; m
= m
->next
)
1686 if (!strcmp (m
->format
, "0"))
1687 tagged_printf ("%s", m
->format
, m
->name
);
1689 tagged_printf ("&%s", m
->format
, m
->name
);
1691 /* The end of the table is entries for decimal float modes. */
1692 for (m
= modes
[MODE_DECIMAL_FLOAT
]; m
; m
= m
->next
)
1693 if (!strcmp (m
->format
, "0"))
1694 tagged_printf ("%s", m
->format
, m
->name
);
1696 tagged_printf ("&%s", m
->format
, m
->name
);
1702 emit_mode_adjustments (void)
1704 struct mode_adjust
*a
;
1705 struct mode_data
*m
;
1709 \ninit_adjust_machine_modes (void)\
1711 \n poly_uint16 ps ATTRIBUTE_UNUSED;\n\
1712 size_t s ATTRIBUTE_UNUSED;");
1714 for (a
= adj_nunits
; a
; a
= a
->next
)
1719 " /* %s:%d */\n ps = %s;\n",
1720 a
->file
, a
->line
, a
->adjustment
);
1721 printf (" int old_factor = vector_element_size"
1722 " (mode_precision[E_%smode], mode_nunits[E_%smode]);\n",
1724 printf (" mode_precision[E_%smode] = ps * old_factor;\n", m
->name
);
1725 printf (" mode_size[E_%smode] = exact_div (mode_precision[E_%smode],"
1726 " BITS_PER_UNIT);\n", m
->name
, m
->name
);
1727 printf (" mode_nunits[E_%smode] = ps;\n", m
->name
);
1731 /* Size adjustments must be propagated to all containing modes.
1732 A size adjustment forces us to recalculate the alignment too. */
1733 for (a
= adj_bytesize
; a
; a
= a
->next
)
1735 printf ("\n /* %s:%d */\n", a
->file
, a
->line
);
1736 switch (a
->mode
->cl
)
1738 case MODE_VECTOR_BOOL
:
1739 case MODE_VECTOR_INT
:
1740 case MODE_VECTOR_FLOAT
:
1741 case MODE_VECTOR_FRACT
:
1742 case MODE_VECTOR_UFRACT
:
1743 case MODE_VECTOR_ACCUM
:
1744 case MODE_VECTOR_UACCUM
:
1745 printf (" ps = %s;\n", a
->adjustment
);
1746 printf (" s = mode_unit_size[E_%smode];\n", a
->mode
->name
);
1750 printf (" ps = s = %s;\n", a
->adjustment
);
1751 printf (" mode_unit_size[E_%smode] = s;\n", a
->mode
->name
);
1754 printf (" mode_size[E_%smode] = ps;\n", a
->mode
->name
);
1755 printf (" mode_base_align[E_%smode] = known_alignment (ps);\n",
1758 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1762 case MODE_COMPLEX_INT
:
1763 case MODE_COMPLEX_FLOAT
:
1764 printf (" mode_size[E_%smode] = 2*s;\n", m
->name
);
1765 printf (" mode_unit_size[E_%smode] = s;\n", m
->name
);
1766 printf (" mode_base_align[E_%smode] = s & (~s + 1);\n",
1770 case MODE_VECTOR_BOOL
:
1771 /* Changes to BImode should not affect vector booleans. */
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 (" mode_size[E_%smode] = %d * ps;\n",
1781 m
->name
, m
->ncomponents
);
1782 printf (" mode_unit_size[E_%smode] = s;\n", m
->name
);
1783 printf (" mode_base_align[E_%smode]"
1784 " = known_alignment (%d * ps);\n",
1785 m
->name
, m
->ncomponents
);
1790 "mode %s is neither vector nor complex but contains %s",
1791 m
->name
, a
->mode
->name
);
1797 /* Alignment adjustments propagate too.
1798 ??? This may not be the right thing for vector modes. */
1799 for (a
= adj_alignment
; a
; a
= a
->next
)
1801 printf ("\n /* %s:%d */\n s = %s;\n",
1802 a
->file
, a
->line
, a
->adjustment
);
1803 printf (" mode_base_align[E_%smode] = s;\n", a
->mode
->name
);
1805 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1809 case MODE_COMPLEX_INT
:
1810 case MODE_COMPLEX_FLOAT
:
1811 printf (" mode_base_align[E_%smode] = s;\n", m
->name
);
1814 case MODE_VECTOR_BOOL
:
1815 /* Changes to BImode should not affect vector booleans. */
1818 case MODE_VECTOR_INT
:
1819 case MODE_VECTOR_FLOAT
:
1820 case MODE_VECTOR_FRACT
:
1821 case MODE_VECTOR_UFRACT
:
1822 case MODE_VECTOR_ACCUM
:
1823 case MODE_VECTOR_UACCUM
:
1824 printf (" mode_base_align[E_%smode] = %d*s;\n",
1825 m
->name
, m
->ncomponents
);
1830 "mode %s is neither vector nor complex but contains %s",
1831 m
->name
, a
->mode
->name
);
1837 /* Ibit adjustments don't have to propagate. */
1838 for (a
= adj_ibit
; a
; a
= a
->next
)
1840 printf ("\n /* %s:%d */\n s = %s;\n",
1841 a
->file
, a
->line
, a
->adjustment
);
1842 printf (" mode_ibit[E_%smode] = s;\n", a
->mode
->name
);
1845 /* Fbit adjustments don't have to propagate. */
1846 for (a
= adj_fbit
; a
; a
= a
->next
)
1848 printf ("\n /* %s:%d */\n s = %s;\n",
1849 a
->file
, a
->line
, a
->adjustment
);
1850 printf (" mode_fbit[E_%smode] = s;\n", a
->mode
->name
);
1853 /* Real mode formats don't have to propagate anywhere. */
1854 for (a
= adj_format
; a
; a
= a
->next
)
1855 printf ("\n /* %s:%d */\n REAL_MODE_FORMAT (E_%smode) = %s;\n",
1856 a
->file
, a
->line
, a
->mode
->name
, a
->adjustment
);
1861 /* Emit ibit for all modes. */
1864 emit_mode_ibit (void)
1867 struct mode_data
*m
;
1869 print_maybe_const_decl ("%sunsigned char",
1870 "mode_ibit", "NUM_MACHINE_MODES",
1873 for_all_modes (c
, m
)
1874 tagged_printf ("%u", m
->ibit
, m
->name
);
1879 /* Emit fbit for all modes. */
1882 emit_mode_fbit (void)
1885 struct mode_data
*m
;
1887 print_maybe_const_decl ("%sunsigned char",
1888 "mode_fbit", "NUM_MACHINE_MODES",
1891 for_all_modes (c
, m
)
1892 tagged_printf ("%u", m
->fbit
, m
->name
);
1897 /* Emit __intN for all modes. */
1900 emit_mode_int_n (void)
1903 struct mode_data
*m
;
1904 struct mode_data
**mode_sort
;
1908 print_decl ("int_n_data_t", "int_n_data", "");
1911 for_all_modes (c
, m
)
1914 mode_sort
= XALLOCAVEC (struct mode_data
*, n_modes
);
1917 for_all_modes (c
, m
)
1919 mode_sort
[n_modes
++] = m
;
1921 /* Yes, this is a bubblesort, but there are at most four (and
1922 usually only 1-2) entries to sort. */
1923 for (i
= 0; i
<n_modes
- 1; i
++)
1924 for (j
= i
+ 1; j
< n_modes
; j
++)
1925 if (mode_sort
[i
]->int_n
> mode_sort
[j
]->int_n
)
1926 std::swap (mode_sort
[i
], mode_sort
[j
]);
1928 for (i
= 0; i
< n_modes
; i
++)
1932 tagged_printf ("%u", m
->int_n
, m
->name
);
1933 printf ("{ E_%smode },", m
->name
);
1942 emit_insn_modes_c (void)
1944 emit_insn_modes_c_header ();
1947 emit_mode_precision ();
1949 emit_mode_nunits ();
1951 emit_mode_complex ();
1954 emit_mode_unit_size ();
1955 emit_mode_unit_precision ();
1956 emit_mode_base_align ();
1957 emit_class_narrowest_mode ();
1958 emit_real_format_for_mode ();
1959 emit_mode_adjustments ();
1966 emit_min_insn_modes_c (void)
1968 emit_min_insn_modes_c_header ();
1971 emit_mode_nunits ();
1974 emit_class_narrowest_mode ();
1977 /* Master control. */
1979 main (int argc
, char **argv
)
1981 bool gen_header
= false, gen_inlines
= false, gen_min
= false;
1986 else if (argc
== 2 && !strcmp (argv
[1], "-h"))
1988 else if (argc
== 2 && !strcmp (argv
[1], "-i"))
1990 else if (argc
== 2 && !strcmp (argv
[1], "-m"))
1994 error ("usage: %s [-h|-i|-m] > file", progname
);
1995 return FATAL_EXIT_CODE
;
1998 modes_by_name
= htab_create_alloc (64, hash_mode
, eq_mode
, 0, xcalloc
, free
);
2001 complete_all_modes ();
2004 return FATAL_EXIT_CODE
;
2009 emit_insn_modes_h ();
2010 else if (gen_inlines
)
2011 emit_insn_modes_inline_h ();
2013 emit_min_insn_modes_c ();
2015 emit_insn_modes_c ();
2017 if (fflush (stdout
) || fclose (stdout
))
2018 return FATAL_EXIT_CODE
;
2019 return SUCCESS_EXIT_CODE
;