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
);
344 case MODE_DECIMAL_FLOAT
:
349 /* A scalar mode must have a byte size, may have a bit size,
350 and must not have components. A float mode must have a
352 validate_mode (m
, OPTIONAL
, SET
, UNSET
, UNSET
,
353 (m
->cl
== MODE_FLOAT
|| m
->cl
== MODE_DECIMAL_FLOAT
)
360 case MODE_PARTIAL_INT
:
361 /* A partial integer mode uses ->component to say what the
362 corresponding full-size integer mode is, and may also
363 specify a bit size. */
364 validate_mode (m
, OPTIONAL
, UNSET
, SET
, UNSET
, UNSET
);
366 m
->bytesize
= m
->component
->bytesize
;
371 case MODE_COMPLEX_INT
:
372 case MODE_COMPLEX_FLOAT
:
373 /* Complex modes should have a component indicated, but no more. */
374 validate_mode (m
, UNSET
, UNSET
, SET
, UNSET
, UNSET
);
376 if (m
->component
->precision
!= (unsigned int)-1)
377 m
->precision
= 2 * m
->component
->precision
;
378 m
->bytesize
= 2 * m
->component
->bytesize
;
381 case MODE_VECTOR_BOOL
:
382 validate_mode (m
, UNSET
, SET
, SET
, SET
, UNSET
);
385 case MODE_VECTOR_INT
:
386 case MODE_VECTOR_FLOAT
:
387 case MODE_VECTOR_FRACT
:
388 case MODE_VECTOR_UFRACT
:
389 case MODE_VECTOR_ACCUM
:
390 case MODE_VECTOR_UACCUM
:
391 /* Vector modes should have a component and a number of components. */
392 validate_mode (m
, UNSET
, UNSET
, SET
, SET
, UNSET
);
393 if (m
->component
->precision
!= (unsigned int)-1)
394 m
->precision
= m
->ncomponents
* m
->component
->precision
;
395 m
->bytesize
= m
->ncomponents
* m
->component
->bytesize
;
402 /* If not already specified, the mode alignment defaults to the largest
403 power of two that divides the size of the object. Complex types are
404 not more aligned than their contents. */
405 if (m
->cl
== MODE_COMPLEX_INT
|| m
->cl
== MODE_COMPLEX_FLOAT
)
406 alignment
= m
->component
->bytesize
;
408 alignment
= m
->bytesize
;
410 m
->alignment
= alignment
& (~alignment
+ 1);
412 /* If this mode has components, make the component mode point back
413 to this mode, for the sake of adjustments. */
416 m
->next_cont
= m
->component
->contained
;
417 m
->component
->contained
= m
;
422 complete_all_modes (void)
427 for_all_modes (cl
, m
)
431 /* For each mode in class CLASS, construct a corresponding complex mode. */
432 #define COMPLEX_MODES(C) make_complex_modes (MODE_##C, __FILE__, __LINE__)
434 make_complex_modes (enum mode_class cl
,
435 const char *file
, unsigned int line
)
439 enum mode_class cclass
= complex_class (cl
);
441 if (cclass
== MODE_RANDOM
)
444 for (m
= modes
[cl
]; m
; m
= m
->next
)
449 /* Skip BImode. FIXME: BImode probably shouldn't be MODE_INT. */
450 if (m
->precision
== 1)
453 m_len
= strlen (m
->name
);
454 /* The leading "1 +" is in case we prepend a "C" below. */
455 buf
= (char *) xmalloc (1 + m_len
+ 1);
457 /* Float complex modes are named SCmode, etc.
458 Int complex modes are named CSImode, etc.
459 This inconsistency should be eliminated. */
461 if (cl
== MODE_FLOAT
)
463 memcpy (buf
, m
->name
, m_len
+ 1);
464 p
= strchr (buf
, 'F');
465 if (p
== 0 && strchr (buf
, 'D') == 0)
467 error ("%s:%d: float mode \"%s\" has no 'F' or 'D'",
468 m
->file
, m
->line
, m
->name
);
478 memcpy (buf
+ 1, m
->name
, m_len
+ 1);
481 c
= new_mode (cclass
, buf
, file
, line
);
487 /* For all modes in class CL, construct vector modes of width
488 WIDTH, having as many components as necessary. */
489 #define VECTOR_MODES_WITH_PREFIX(PREFIX, C, W) \
490 make_vector_modes (MODE_##C, #PREFIX, W, __FILE__, __LINE__)
491 #define VECTOR_MODES(C, W) VECTOR_MODES_WITH_PREFIX (V, C, W)
492 static void ATTRIBUTE_UNUSED
493 make_vector_modes (enum mode_class cl
, const char *prefix
, unsigned int width
,
494 const char *file
, unsigned int line
)
498 /* Big enough for a 32-bit UINT_MAX plus the text. */
500 unsigned int ncomponents
;
501 enum mode_class vclass
= vector_class (cl
);
503 if (vclass
== MODE_RANDOM
)
506 for (m
= modes
[cl
]; m
; m
= m
->next
)
508 /* Do not construct vector modes with only one element, or
509 vector modes where the element size doesn't divide the full
511 ncomponents
= width
/ m
->bytesize
;
514 if (width
% m
->bytesize
)
517 /* Skip QFmode and BImode. FIXME: this special case should
519 if (cl
== MODE_FLOAT
&& m
->bytesize
== 1)
521 if (cl
== MODE_INT
&& m
->precision
== 1)
524 if ((size_t) snprintf (buf
, sizeof buf
, "%s%u%s", prefix
,
525 ncomponents
, m
->name
) >= sizeof buf
)
527 error ("%s:%d: mode name \"%s\" is too long",
528 m
->file
, m
->line
, m
->name
);
532 v
= new_mode (vclass
, xstrdup (buf
), file
, line
);
534 v
->ncomponents
= ncomponents
;
538 /* Create a vector of booleans called NAME with COUNT elements and
539 BYTESIZE bytes in total. */
540 #define VECTOR_BOOL_MODE(NAME, COUNT, BYTESIZE) \
541 make_vector_bool_mode (#NAME, COUNT, BYTESIZE, __FILE__, __LINE__)
542 static void ATTRIBUTE_UNUSED
543 make_vector_bool_mode (const char *name
, unsigned int count
,
544 unsigned int bytesize
, const char *file
,
547 struct mode_data
*m
= find_mode ("BI");
550 error ("%s:%d: no mode \"BI\"", file
, line
);
554 struct mode_data
*v
= new_mode (MODE_VECTOR_BOOL
, name
, file
, line
);
556 v
->ncomponents
= count
;
557 v
->bytesize
= bytesize
;
562 #define _SPECIAL_MODE(C, N) \
563 make_special_mode (MODE_##C, #N, __FILE__, __LINE__)
564 #define RANDOM_MODE(N) _SPECIAL_MODE (RANDOM, N)
565 #define CC_MODE(N) _SPECIAL_MODE (CC, N)
568 make_special_mode (enum mode_class cl
, const char *name
,
569 const char *file
, unsigned int line
)
571 new_mode (cl
, name
, file
, line
);
574 #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y)
575 #define FRACTIONAL_INT_MODE(N, B, Y) \
576 make_int_mode (#N, B, Y, __FILE__, __LINE__)
579 make_int_mode (const char *name
,
580 unsigned int precision
, unsigned int bytesize
,
581 const char *file
, unsigned int line
)
583 struct mode_data
*m
= new_mode (MODE_INT
, name
, file
, line
);
584 m
->bytesize
= bytesize
;
585 m
->precision
= precision
;
588 #define FRACT_MODE(N, Y, F) \
589 make_fixed_point_mode (MODE_FRACT, #N, Y, 0, F, __FILE__, __LINE__)
591 #define UFRACT_MODE(N, Y, F) \
592 make_fixed_point_mode (MODE_UFRACT, #N, Y, 0, F, __FILE__, __LINE__)
594 #define ACCUM_MODE(N, Y, I, F) \
595 make_fixed_point_mode (MODE_ACCUM, #N, Y, I, F, __FILE__, __LINE__)
597 #define UACCUM_MODE(N, Y, I, F) \
598 make_fixed_point_mode (MODE_UACCUM, #N, Y, I, F, __FILE__, __LINE__)
600 /* Create a fixed-point mode by setting CL, NAME, BYTESIZE, IBIT, FBIT,
604 make_fixed_point_mode (enum mode_class cl
,
606 unsigned int bytesize
,
609 const char *file
, unsigned int line
)
611 struct mode_data
*m
= new_mode (cl
, name
, file
, line
);
612 m
->bytesize
= bytesize
;
617 #define FLOAT_MODE(N, Y, F) FRACTIONAL_FLOAT_MODE (N, -1U, Y, F)
618 #define FRACTIONAL_FLOAT_MODE(N, B, Y, F) \
619 make_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
622 make_float_mode (const char *name
,
623 unsigned int precision
, unsigned int bytesize
,
625 const char *file
, unsigned int line
)
627 struct mode_data
*m
= new_mode (MODE_FLOAT
, name
, file
, line
);
628 m
->bytesize
= bytesize
;
629 m
->precision
= precision
;
633 #define DECIMAL_FLOAT_MODE(N, Y, F) \
634 FRACTIONAL_DECIMAL_FLOAT_MODE (N, -1U, Y, F)
635 #define FRACTIONAL_DECIMAL_FLOAT_MODE(N, B, Y, F) \
636 make_decimal_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
639 make_decimal_float_mode (const char *name
,
640 unsigned int precision
, unsigned int bytesize
,
642 const char *file
, unsigned int line
)
644 struct mode_data
*m
= new_mode (MODE_DECIMAL_FLOAT
, name
, file
, line
);
645 m
->bytesize
= bytesize
;
646 m
->precision
= precision
;
650 #define RESET_FLOAT_FORMAT(N, F) \
651 reset_float_format (#N, #F, __FILE__, __LINE__)
652 static void ATTRIBUTE_UNUSED
653 reset_float_format (const char *name
, const char *format
,
654 const char *file
, unsigned int line
)
656 struct mode_data
*m
= find_mode (name
);
659 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
662 if (m
->cl
!= MODE_FLOAT
&& m
->cl
!= MODE_DECIMAL_FLOAT
)
664 error ("%s:%d: mode \"%s\" is not a FLOAT class", file
, line
, name
);
670 /* __intN support. */
671 #define INT_N(M,PREC) \
672 make_int_n (#M, PREC, __FILE__, __LINE__)
673 static void ATTRIBUTE_UNUSED
674 make_int_n (const char *m
, int bitsize
,
675 const char *file
, unsigned int line
)
677 struct mode_data
*component
= find_mode (m
);
680 error ("%s:%d: no mode \"%s\"", file
, line
, m
);
683 if (component
->cl
!= MODE_INT
684 && component
->cl
!= MODE_PARTIAL_INT
)
686 error ("%s:%d: mode \"%s\" is not class INT or PARTIAL_INT", file
, line
, m
);
689 if (component
->int_n
!= 0)
691 error ("%s:%d: mode \"%s\" already has an intN", file
, line
, m
);
695 component
->int_n
= bitsize
;
698 /* Partial integer modes are specified by relation to a full integer
700 #define PARTIAL_INT_MODE(M,PREC,NAME) \
701 make_partial_integer_mode (#M, #NAME, PREC, __FILE__, __LINE__)
702 static void ATTRIBUTE_UNUSED
703 make_partial_integer_mode (const char *base
, const char *name
,
704 unsigned int precision
,
705 const char *file
, unsigned int line
)
708 struct mode_data
*component
= find_mode (base
);
711 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
714 if (component
->cl
!= MODE_INT
)
716 error ("%s:%d: mode \"%s\" is not class INT", file
, line
, name
);
720 m
= new_mode (MODE_PARTIAL_INT
, name
, file
, line
);
721 m
->precision
= precision
;
722 m
->component
= component
;
725 /* A single vector mode can be specified by naming its component
726 mode and the number of components. */
727 #define VECTOR_MODE(C, M, N) \
728 make_vector_mode (MODE_##C, #M, N, __FILE__, __LINE__);
729 static void ATTRIBUTE_UNUSED
730 make_vector_mode (enum mode_class bclass
,
732 unsigned int ncomponents
,
733 const char *file
, unsigned int line
)
736 enum mode_class vclass
= vector_class (bclass
);
737 struct mode_data
*component
= find_mode (base
);
740 if (vclass
== MODE_RANDOM
)
744 error ("%s:%d: no mode \"%s\"", file
, line
, base
);
747 if (component
->cl
!= bclass
748 && (component
->cl
!= MODE_PARTIAL_INT
749 || bclass
!= MODE_INT
))
751 error ("%s:%d: mode \"%s\" is not class %s",
752 file
, line
, base
, mode_class_names
[bclass
] + 5);
756 if ((size_t)snprintf (namebuf
, sizeof namebuf
, "V%u%s",
757 ncomponents
, base
) >= sizeof namebuf
)
759 error ("%s:%d: mode name \"%s\" is too long",
764 v
= new_mode (vclass
, xstrdup (namebuf
), file
, line
);
765 v
->ncomponents
= ncomponents
;
766 v
->component
= component
;
770 #define _ADD_ADJUST(A, M, X, C1, C2) \
771 new_adjust (#M, &adj_##A, #A, #X, MODE_##C1, MODE_##C2, __FILE__, __LINE__)
773 #define ADJUST_NUNITS(M, X) _ADD_ADJUST (nunits, M, X, RANDOM, RANDOM)
774 #define ADJUST_BYTESIZE(M, X) _ADD_ADJUST (bytesize, M, X, RANDOM, RANDOM)
775 #define ADJUST_ALIGNMENT(M, X) _ADD_ADJUST (alignment, M, X, RANDOM, RANDOM)
776 #define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST (format, M, X, FLOAT, FLOAT)
777 #define ADJUST_IBIT(M, X) _ADD_ADJUST (ibit, M, X, ACCUM, UACCUM)
778 #define ADJUST_FBIT(M, X) _ADD_ADJUST (fbit, M, X, FRACT, UACCUM)
780 static int bits_per_unit
;
781 static int max_bitsize_mode_any_int
;
782 static int max_bitsize_mode_any_mode
;
787 #include "machmode.def"
789 /* So put the default value unless the target needs a non standard
792 bits_per_unit
= BITS_PER_UNIT
;
797 #ifdef MAX_BITSIZE_MODE_ANY_INT
798 max_bitsize_mode_any_int
= MAX_BITSIZE_MODE_ANY_INT
;
800 max_bitsize_mode_any_int
= 0;
803 #ifdef MAX_BITSIZE_MODE_ANY_MODE
804 max_bitsize_mode_any_mode
= MAX_BITSIZE_MODE_ANY_MODE
;
806 max_bitsize_mode_any_mode
= 0;
810 #ifndef NUM_POLY_INT_COEFFS
811 #define NUM_POLY_INT_COEFFS 1
816 /* Sort a list of modes into the order needed for the WIDER field:
817 major sort by precision, minor sort by component precision.
820 QI < HI < SI < DI < TI
821 V4QI < V2HI < V8QI < V4HI < V2SI.
823 If the precision is not set, sort by the bytesize. A mode with
824 precision set gets sorted before a mode without precision set, if
825 they have the same bytesize; this is the right thing because
826 the precision must always be smaller than the bytesize * BITS_PER_UNIT.
827 We don't have to do anything special to get this done -- an unset
828 precision shows up as (unsigned int)-1, i.e. UINT_MAX. */
830 cmp_modes (const void *a
, const void *b
)
832 const struct mode_data
*const m
= *(const struct mode_data
*const*)a
;
833 const struct mode_data
*const n
= *(const struct mode_data
*const*)b
;
835 if (m
->bytesize
> n
->bytesize
)
837 else if (m
->bytesize
< n
->bytesize
)
840 if (m
->precision
> n
->precision
)
842 else if (m
->precision
< n
->precision
)
845 if (!m
->component
&& !n
->component
)
847 if (m
->counter
< n
->counter
)
853 if (m
->component
->bytesize
> n
->component
->bytesize
)
855 else if (m
->component
->bytesize
< n
->component
->bytesize
)
858 if (m
->component
->precision
> n
->component
->precision
)
860 else if (m
->component
->precision
< n
->component
->precision
)
863 if (m
->counter
< n
->counter
)
870 calc_wider_mode (void)
874 struct mode_data
**sortbuf
;
875 unsigned int max_n_modes
= 0;
878 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
879 max_n_modes
= MAX (max_n_modes
, n_modes
[c
]);
881 /* Allocate max_n_modes + 1 entries to leave room for the extra null
882 pointer assigned after the qsort call below. */
883 sortbuf
= XALLOCAVEC (struct mode_data
*, max_n_modes
+ 1);
885 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
887 /* "wider" is not meaningful for MODE_RANDOM and MODE_CC.
888 However, we want these in textual order, and we have
889 precisely the reverse. */
890 if (c
== MODE_RANDOM
|| c
== MODE_CC
)
892 struct mode_data
*prev
, *next
;
894 for (prev
= 0, m
= modes
[c
]; m
; m
= next
)
896 m
->wider
= void_mode
;
898 /* this is nreverse */
910 for (i
= 0, m
= modes
[c
]; m
; i
++, m
= m
->next
)
913 (qsort
) (sortbuf
, i
, sizeof (struct mode_data
*), cmp_modes
);
916 for (j
= 0; j
< i
; j
++)
918 sortbuf
[j
]->next
= sortbuf
[j
+ 1];
919 if (c
== MODE_PARTIAL_INT
)
920 sortbuf
[j
]->wider
= sortbuf
[j
]->component
;
922 sortbuf
[j
]->wider
= sortbuf
[j
]->next
;
925 modes
[c
] = sortbuf
[0];
930 /* Text to add to the constant part of a poly_int_pod initializer in
931 order to fill out te whole structure. */
932 #if NUM_POLY_INT_COEFFS == 1
933 #define ZERO_COEFFS ""
934 #elif NUM_POLY_INT_COEFFS == 2
935 #define ZERO_COEFFS ", 0"
937 #error "Unknown value of NUM_POLY_INT_COEFFS"
940 /* Output routines. */
942 #define tagged_printf(FMT, ARG, TAG) do { \
943 int count_ = printf (" " FMT ",", ARG); \
944 printf ("%*s/* %s */\n", 27 - count_, "", TAG); \
947 #define print_decl(TYPE, NAME, ASIZE) \
948 puts ("\nconst " TYPE " " NAME "[" ASIZE "] =\n{");
950 #define print_maybe_const_decl(TYPE, NAME, ASIZE, NEEDS_ADJ) \
951 printf ("\n" TYPE " " NAME "[" ASIZE "] = \n{\n", \
952 NEEDS_ADJ ? "" : "const ")
954 #define print_closer() puts ("};")
956 /* Compute the max bitsize of some of the classes of integers. It may
957 be that there are needs for the other integer classes, and this
958 code is easy to extend. */
962 unsigned int max
, mmax
;
968 printf ("#define BITS_PER_UNIT (%d)\n", bits_per_unit
);
970 if (max_bitsize_mode_any_int
== 0)
972 for (max
= 1, i
= modes
[MODE_INT
]; i
; i
= i
->next
)
973 if (max
< i
->bytesize
)
976 for (max
= 1, i
= modes
[MODE_PARTIAL_INT
]; i
; i
= i
->next
)
977 if (max
< i
->bytesize
)
981 printf ("#define MAX_BITSIZE_MODE_ANY_INT (%d*BITS_PER_UNIT)\n", mmax
);
984 printf ("#define MAX_BITSIZE_MODE_ANY_INT %d\n", max_bitsize_mode_any_int
);
986 if (max_bitsize_mode_any_mode
== 0)
989 for (j
= 0; j
< MAX_MODE_CLASS
; j
++)
990 for (i
= modes
[j
]; i
; i
= i
->next
)
991 if (mmax
< i
->bytesize
)
993 printf ("#define MAX_BITSIZE_MODE_ANY_MODE (%d*BITS_PER_UNIT)\n", mmax
);
996 printf ("#define MAX_BITSIZE_MODE_ANY_MODE %d\n",
997 max_bitsize_mode_any_mode
);
1000 /* Emit mode_size_inline routine into insn-modes.h header. */
1002 emit_mode_size_inline (void)
1005 struct mode_adjust
*a
;
1006 struct mode_data
*m
;
1008 /* Size adjustments must be propagated to all containing modes. */
1009 for (a
= adj_bytesize
; a
; a
= a
->next
)
1011 a
->mode
->need_bytesize_adj
= true;
1012 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1013 m
->need_bytesize_adj
= true;
1016 /* Changing the number of units by a factor of X also changes the size
1017 by a factor of X. */
1018 for (mode_adjust
*a
= adj_nunits
; a
; a
= a
->next
)
1019 a
->mode
->need_bytesize_adj
= true;
1022 #ifdef __cplusplus\n\
1023 inline __attribute__((__always_inline__))\n\
1025 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1028 mode_size_inline (machine_mode mode)\n\
1030 extern %spoly_uint16_pod mode_size[NUM_MACHINE_MODES];\n\
1031 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1033 {\n", adj_nunits
|| adj_bytesize
? "" : "const ");
1035 for_all_modes (c
, m
)
1036 if (!m
->need_bytesize_adj
)
1037 printf (" case E_%smode: return %u;\n", m
->name
, m
->bytesize
);
1040 default: return mode_size[mode];\n\
1045 /* Emit mode_nunits_inline routine into insn-modes.h header. */
1047 emit_mode_nunits_inline (void)
1050 struct mode_data
*m
;
1052 for (mode_adjust
*a
= adj_nunits
; a
; a
= a
->next
)
1053 a
->mode
->need_nunits_adj
= true;
1056 #ifdef __cplusplus\n\
1057 inline __attribute__((__always_inline__))\n\
1059 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1062 mode_nunits_inline (machine_mode mode)\n\
1064 extern %spoly_uint16_pod mode_nunits[NUM_MACHINE_MODES];\n\
1066 {\n", adj_nunits
? "" : "const ");
1068 for_all_modes (c
, m
)
1069 if (!m
->need_nunits_adj
)
1070 printf (" case E_%smode: return %u;\n", m
->name
, m
->ncomponents
);
1073 default: return mode_nunits[mode];\n\
1078 /* Emit mode_inner_inline routine into insn-modes.h header. */
1080 emit_mode_inner_inline (void)
1083 struct mode_data
*m
;
1086 #ifdef __cplusplus\n\
1087 inline __attribute__((__always_inline__))\n\
1089 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1092 mode_inner_inline (machine_mode mode)\n\
1094 extern const unsigned char mode_inner[NUM_MACHINE_MODES];\n\
1095 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1099 for_all_modes (c
, m
)
1100 printf (" case E_%smode: return E_%smode;\n", m
->name
,
1101 c
!= MODE_PARTIAL_INT
&& m
->component
1102 ? m
->component
->name
: m
->name
);
1105 default: return mode_inner[mode];\n\
1110 /* Emit mode_unit_size_inline routine into insn-modes.h header. */
1112 emit_mode_unit_size_inline (void)
1115 struct mode_data
*m
;
1118 #ifdef __cplusplus\n\
1119 inline __attribute__((__always_inline__))\n\
1121 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1124 mode_unit_size_inline (machine_mode mode)\n\
1126 extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES];\
1128 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1132 for_all_modes (c
, m
)
1134 const char *name
= m
->name
;
1135 struct mode_data
*m2
= m
;
1136 if (c
!= MODE_PARTIAL_INT
&& m2
->component
)
1138 if (!m2
->need_bytesize_adj
)
1139 printf (" case E_%smode: return %u;\n", name
, m2
->bytesize
);
1143 default: return mode_unit_size[mode];\n\
1148 /* Emit mode_unit_precision_inline routine into insn-modes.h header. */
1150 emit_mode_unit_precision_inline (void)
1153 struct mode_data
*m
;
1156 #ifdef __cplusplus\n\
1157 inline __attribute__((__always_inline__))\n\
1159 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1162 mode_unit_precision_inline (machine_mode mode)\n\
1164 extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES];\n\
1165 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1169 for_all_modes (c
, m
)
1171 struct mode_data
*m2
1172 = (c
!= MODE_PARTIAL_INT
&& m
->component
) ? m
->component
: m
;
1173 if (m2
->precision
!= (unsigned int)-1)
1174 printf (" case E_%smode: return %u;\n", m
->name
, m2
->precision
);
1176 printf (" case E_%smode: return %u*BITS_PER_UNIT;\n",
1177 m
->name
, m2
->bytesize
);
1181 default: return mode_unit_precision[mode];\n\
1186 /* Return the best machine mode class for MODE, or null if machine_mode
1190 get_mode_class (struct mode_data
*mode
)
1195 case MODE_PARTIAL_INT
:
1196 return "scalar_int_mode";
1202 return "scalar_mode";
1205 case MODE_DECIMAL_FLOAT
:
1206 return "scalar_float_mode";
1208 case MODE_COMPLEX_INT
:
1209 case MODE_COMPLEX_FLOAT
:
1210 return "complex_mode";
1218 emit_insn_modes_h (void)
1221 struct mode_data
*m
, *first
, *last
;
1222 int n_int_n_ents
= 0;
1224 printf ("/* Generated automatically from machmode.def%s%s\n",
1225 HAVE_EXTRA_MODES
? " and " : "",
1231 #ifndef GCC_INSN_MODES_H\n\
1232 #define GCC_INSN_MODES_H\n\
1234 enum machine_mode\n{");
1236 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1237 for (m
= modes
[c
]; m
; m
= m
->next
)
1239 int count_
= printf (" E_%smode,", m
->name
);
1240 printf ("%*s/* %s:%d */\n", 27 - count_
, "",
1241 trim_filename (m
->file
), m
->line
);
1242 printf ("#define HAVE_%smode\n", m
->name
);
1243 printf ("#ifdef USE_ENUM_MODES\n");
1244 printf ("#define %smode E_%smode\n", m
->name
, m
->name
);
1246 if (const char *mode_class
= get_mode_class (m
))
1247 printf ("#define %smode (%s ((%s::from_int) E_%smode))\n",
1248 m
->name
, mode_class
, mode_class
, m
->name
);
1250 printf ("#define %smode ((void) 0, E_%smode)\n",
1252 printf ("#endif\n");
1255 puts (" MAX_MACHINE_MODE,\n");
1257 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1261 for (m
= first
; m
; last
= m
, m
= m
->next
)
1264 /* Don't use BImode for MIN_MODE_INT, since otherwise the middle
1265 end will try to use it for bitfields in structures and the
1266 like, which we do not want. Only the target md file should
1267 generate BImode widgets. */
1268 if (first
&& first
->precision
== 1 && c
== MODE_INT
)
1269 first
= first
->next
;
1272 printf (" MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n",
1273 mode_class_names
[c
], first
->name
,
1274 mode_class_names
[c
], last
->name
);
1276 printf (" MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n",
1277 mode_class_names
[c
], void_mode
->name
,
1278 mode_class_names
[c
], void_mode
->name
);
1282 NUM_MACHINE_MODES = MAX_MACHINE_MODE\n\
1285 /* I can't think of a better idea, can you? */
1286 printf ("#define CONST_MODE_NUNITS%s\n", adj_nunits
? "" : " const");
1287 printf ("#define CONST_MODE_PRECISION%s\n", adj_nunits
? "" : " const");
1288 printf ("#define CONST_MODE_SIZE%s\n",
1289 adj_bytesize
|| adj_nunits
? "" : " const");
1290 printf ("#define CONST_MODE_UNIT_SIZE%s\n", adj_bytesize
? "" : " const");
1291 printf ("#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment
? "" : " const");
1292 #if 0 /* disabled for backward compatibility, temporary */
1293 printf ("#define CONST_REAL_FORMAT_FOR_MODE%s\n", adj_format
? "" :" const");
1295 printf ("#define CONST_MODE_IBIT%s\n", adj_ibit
? "" : " const");
1296 printf ("#define CONST_MODE_FBIT%s\n", adj_fbit
? "" : " const");
1299 for_all_modes (c
, m
)
1303 printf ("#define NUM_INT_N_ENTS %d\n", n_int_n_ents
);
1305 printf ("#define NUM_POLY_INT_COEFFS %d\n", NUM_POLY_INT_COEFFS
);
1309 #endif /* insn-modes.h */");
1313 emit_insn_modes_inline_h (void)
1315 printf ("/* Generated automatically from machmode.def%s%s\n",
1316 HAVE_EXTRA_MODES
? " and " : "",
1322 #ifndef GCC_INSN_MODES_INLINE_H\n\
1323 #define GCC_INSN_MODES_INLINE_H");
1325 puts ("\n#if !defined (USED_FOR_TARGET) && GCC_VERSION >= 4001\n");
1326 emit_mode_size_inline ();
1327 emit_mode_nunits_inline ();
1328 emit_mode_inner_inline ();
1329 emit_mode_unit_size_inline ();
1330 emit_mode_unit_precision_inline ();
1331 puts ("#endif /* GCC_VERSION >= 4001 */");
1335 #endif /* insn-modes-inline.h */");
1339 emit_insn_modes_c_header (void)
1341 printf ("/* Generated automatically from machmode.def%s%s\n",
1342 HAVE_EXTRA_MODES
? " and " : "",
1348 #include \"config.h\"\n\
1349 #include \"system.h\"\n\
1350 #include \"coretypes.h\"\n\
1351 #include \"tm.h\"\n\
1352 #include \"real.h\"");
1356 emit_min_insn_modes_c_header (void)
1358 printf ("/* Generated automatically from machmode.def%s%s\n",
1359 HAVE_EXTRA_MODES
? " and " : "",
1365 #include \"bconfig.h\"\n\
1366 #include \"system.h\"\n\
1367 #include \"coretypes.h\"");
1371 emit_mode_name (void)
1374 struct mode_data
*m
;
1376 print_decl ("char *const", "mode_name", "NUM_MACHINE_MODES");
1378 for_all_modes (c
, m
)
1379 printf (" \"%s\",\n", m
->name
);
1385 emit_mode_class (void)
1388 struct mode_data
*m
;
1390 print_decl ("unsigned char", "mode_class", "NUM_MACHINE_MODES");
1392 for_all_modes (c
, m
)
1393 tagged_printf ("%s", mode_class_names
[m
->cl
], m
->name
);
1399 emit_mode_precision (void)
1402 struct mode_data
*m
;
1404 print_maybe_const_decl ("%spoly_uint16_pod", "mode_precision",
1405 "NUM_MACHINE_MODES", adj_nunits
);
1407 for_all_modes (c
, m
)
1408 if (m
->precision
!= (unsigned int)-1)
1409 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->precision
, m
->name
);
1411 tagged_printf ("{ %u * BITS_PER_UNIT" ZERO_COEFFS
" }",
1412 m
->bytesize
, m
->name
);
1418 emit_mode_size (void)
1421 struct mode_data
*m
;
1423 print_maybe_const_decl ("%spoly_uint16_pod", "mode_size",
1424 "NUM_MACHINE_MODES", adj_nunits
|| adj_bytesize
);
1426 for_all_modes (c
, m
)
1427 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->bytesize
, m
->name
);
1433 emit_mode_nunits (void)
1436 struct mode_data
*m
;
1438 print_maybe_const_decl ("%spoly_uint16_pod", "mode_nunits",
1439 "NUM_MACHINE_MODES", adj_nunits
);
1441 for_all_modes (c
, m
)
1442 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->ncomponents
, m
->name
);
1448 emit_mode_wider (void)
1451 struct mode_data
*m
;
1453 print_decl ("unsigned char", "mode_wider", "NUM_MACHINE_MODES");
1455 for_all_modes (c
, m
)
1456 tagged_printf ("E_%smode",
1457 m
->wider
? m
->wider
->name
: void_mode
->name
,
1461 print_decl ("unsigned char", "mode_2xwider", "NUM_MACHINE_MODES");
1463 for_all_modes (c
, m
)
1465 struct mode_data
* m2
;
1468 m2
&& m2
!= void_mode
;
1471 if (m2
->bytesize
< 2 * m
->bytesize
)
1473 if (m
->precision
!= (unsigned int) -1)
1475 if (m2
->precision
!= 2 * m
->precision
)
1480 if (m2
->precision
!= (unsigned int) -1)
1484 /* For vectors we want twice the number of components,
1485 with the same element type. */
1486 if (m
->cl
== MODE_VECTOR_BOOL
1487 || m
->cl
== MODE_VECTOR_INT
1488 || m
->cl
== MODE_VECTOR_FLOAT
1489 || m
->cl
== MODE_VECTOR_FRACT
1490 || m
->cl
== MODE_VECTOR_UFRACT
1491 || m
->cl
== MODE_VECTOR_ACCUM
1492 || m
->cl
== MODE_VECTOR_UACCUM
)
1494 if (m2
->ncomponents
!= 2 * m
->ncomponents
)
1496 if (m
->component
!= m2
->component
)
1502 if (m2
== void_mode
)
1504 tagged_printf ("E_%smode",
1505 m2
? m2
->name
: void_mode
->name
,
1513 emit_mode_complex (void)
1516 struct mode_data
*m
;
1518 print_decl ("unsigned char", "mode_complex", "NUM_MACHINE_MODES");
1520 for_all_modes (c
, m
)
1521 tagged_printf ("E_%smode",
1522 m
->complex ? m
->complex->name
: void_mode
->name
,
1529 emit_mode_mask (void)
1532 struct mode_data
*m
;
1534 print_decl ("unsigned HOST_WIDE_INT", "mode_mask_array",
1535 "NUM_MACHINE_MODES");
1537 #define MODE_MASK(m) \\\n\
1538 ((m) >= HOST_BITS_PER_WIDE_INT) \\\n\
1539 ? HOST_WIDE_INT_M1U \\\n\
1540 : (HOST_WIDE_INT_1U << (m)) - 1\n");
1542 for_all_modes (c
, m
)
1543 if (m
->precision
!= (unsigned int)-1)
1544 tagged_printf ("MODE_MASK (%u)", m
->precision
, m
->name
);
1546 tagged_printf ("MODE_MASK (%u*BITS_PER_UNIT)", m
->bytesize
, m
->name
);
1548 puts ("#undef MODE_MASK");
1553 emit_mode_inner (void)
1556 struct mode_data
*m
;
1558 print_decl ("unsigned char", "mode_inner", "NUM_MACHINE_MODES");
1560 for_all_modes (c
, m
)
1561 tagged_printf ("E_%smode",
1562 c
!= MODE_PARTIAL_INT
&& m
->component
1563 ? m
->component
->name
: m
->name
,
1569 /* Emit mode_unit_size array into insn-modes.c file. */
1571 emit_mode_unit_size (void)
1574 struct mode_data
*m
;
1576 print_maybe_const_decl ("%sunsigned char", "mode_unit_size",
1577 "NUM_MACHINE_MODES", adj_bytesize
);
1579 for_all_modes (c
, m
)
1580 tagged_printf ("%u",
1581 c
!= MODE_PARTIAL_INT
&& m
->component
1582 ? m
->component
->bytesize
: m
->bytesize
, m
->name
);
1587 /* Emit mode_unit_precision array into insn-modes.c file. */
1589 emit_mode_unit_precision (void)
1592 struct mode_data
*m
;
1594 print_decl ("unsigned short", "mode_unit_precision", "NUM_MACHINE_MODES");
1596 for_all_modes (c
, m
)
1598 struct mode_data
*m2
= (c
!= MODE_PARTIAL_INT
&& m
->component
) ?
1600 if (m2
->precision
!= (unsigned int)-1)
1601 tagged_printf ("%u", m2
->precision
, m
->name
);
1603 tagged_printf ("%u*BITS_PER_UNIT", m2
->bytesize
, m
->name
);
1611 emit_mode_base_align (void)
1614 struct mode_data
*m
;
1616 print_maybe_const_decl ("%sunsigned short",
1617 "mode_base_align", "NUM_MACHINE_MODES",
1620 for_all_modes (c
, m
)
1621 tagged_printf ("%u", m
->alignment
, m
->name
);
1627 emit_class_narrowest_mode (void)
1631 print_decl ("unsigned char", "class_narrowest_mode", "MAX_MODE_CLASS");
1633 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1634 /* Bleah, all this to get the comment right for MIN_MODE_INT. */
1635 tagged_printf ("MIN_%s", mode_class_names
[c
],
1637 ? ((c
!= MODE_INT
|| modes
[c
]->precision
!= 1)
1640 ? modes
[c
]->next
->name
1648 emit_real_format_for_mode (void)
1650 struct mode_data
*m
;
1652 /* The entities pointed to by this table are constant, whether
1653 or not the table itself is constant.
1655 For backward compatibility this table is always writable
1656 (several targets modify it in TARGET_OPTION_OVERRIDE). FIXME:
1657 convert all said targets to use ADJUST_FORMAT instead. */
1659 print_maybe_const_decl ("const struct real_format *%s",
1660 "real_format_for_mode",
1661 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1",
1664 print_decl ("struct real_format *\n", "real_format_for_mode",
1665 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1 "
1666 "+ MAX_MODE_DECIMAL_FLOAT - MIN_MODE_DECIMAL_FLOAT + 1");
1669 /* The beginning of the table is entries for float modes. */
1670 for (m
= modes
[MODE_FLOAT
]; m
; m
= m
->next
)
1671 if (!strcmp (m
->format
, "0"))
1672 tagged_printf ("%s", m
->format
, m
->name
);
1674 tagged_printf ("&%s", m
->format
, m
->name
);
1676 /* The end of the table is entries for decimal float modes. */
1677 for (m
= modes
[MODE_DECIMAL_FLOAT
]; m
; m
= m
->next
)
1678 if (!strcmp (m
->format
, "0"))
1679 tagged_printf ("%s", m
->format
, m
->name
);
1681 tagged_printf ("&%s", m
->format
, m
->name
);
1687 emit_mode_adjustments (void)
1689 struct mode_adjust
*a
;
1690 struct mode_data
*m
;
1694 \ninit_adjust_machine_modes (void)\
1696 \n poly_uint16 ps ATTRIBUTE_UNUSED;\n\
1697 size_t s ATTRIBUTE_UNUSED;");
1699 for (a
= adj_nunits
; a
; a
= a
->next
)
1704 " /* %s:%d */\n ps = %s;\n",
1705 a
->file
, a
->line
, a
->adjustment
);
1706 printf (" int old_factor = vector_element_size"
1707 " (mode_precision[E_%smode], mode_nunits[E_%smode]);\n",
1709 printf (" mode_precision[E_%smode] = ps * old_factor;\n", m
->name
);
1710 printf (" mode_size[E_%smode] = exact_div (mode_precision[E_%smode],"
1711 " BITS_PER_UNIT);\n", m
->name
, m
->name
);
1712 printf (" mode_nunits[E_%smode] = ps;\n", m
->name
);
1716 /* Size adjustments must be propagated to all containing modes.
1717 A size adjustment forces us to recalculate the alignment too. */
1718 for (a
= adj_bytesize
; a
; a
= a
->next
)
1720 printf ("\n /* %s:%d */\n", a
->file
, a
->line
);
1721 switch (a
->mode
->cl
)
1723 case MODE_VECTOR_BOOL
:
1724 case MODE_VECTOR_INT
:
1725 case MODE_VECTOR_FLOAT
:
1726 case MODE_VECTOR_FRACT
:
1727 case MODE_VECTOR_UFRACT
:
1728 case MODE_VECTOR_ACCUM
:
1729 case MODE_VECTOR_UACCUM
:
1730 printf (" ps = %s;\n", a
->adjustment
);
1731 printf (" s = mode_unit_size[E_%smode];\n", a
->mode
->name
);
1735 printf (" ps = s = %s;\n", a
->adjustment
);
1736 printf (" mode_unit_size[E_%smode] = s;\n", a
->mode
->name
);
1739 printf (" mode_size[E_%smode] = ps;\n", a
->mode
->name
);
1740 printf (" mode_base_align[E_%smode] = known_alignment (ps);\n",
1743 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1747 case MODE_COMPLEX_INT
:
1748 case MODE_COMPLEX_FLOAT
:
1749 printf (" mode_size[E_%smode] = 2*s;\n", m
->name
);
1750 printf (" mode_unit_size[E_%smode] = s;\n", m
->name
);
1751 printf (" mode_base_align[E_%smode] = s & (~s + 1);\n",
1755 case MODE_VECTOR_BOOL
:
1756 /* Changes to BImode should not affect vector booleans. */
1759 case MODE_VECTOR_INT
:
1760 case MODE_VECTOR_FLOAT
:
1761 case MODE_VECTOR_FRACT
:
1762 case MODE_VECTOR_UFRACT
:
1763 case MODE_VECTOR_ACCUM
:
1764 case MODE_VECTOR_UACCUM
:
1765 printf (" mode_size[E_%smode] = %d * ps;\n",
1766 m
->name
, m
->ncomponents
);
1767 printf (" mode_unit_size[E_%smode] = s;\n", m
->name
);
1768 printf (" mode_base_align[E_%smode]"
1769 " = known_alignment (%d * ps);\n",
1770 m
->name
, m
->ncomponents
);
1775 "mode %s is neither vector nor complex but contains %s",
1776 m
->name
, a
->mode
->name
);
1782 /* Alignment adjustments propagate too.
1783 ??? This may not be the right thing for vector modes. */
1784 for (a
= adj_alignment
; a
; a
= a
->next
)
1786 printf ("\n /* %s:%d */\n s = %s;\n",
1787 a
->file
, a
->line
, a
->adjustment
);
1788 printf (" mode_base_align[E_%smode] = s;\n", a
->mode
->name
);
1790 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1794 case MODE_COMPLEX_INT
:
1795 case MODE_COMPLEX_FLOAT
:
1796 printf (" mode_base_align[E_%smode] = s;\n", m
->name
);
1799 case MODE_VECTOR_BOOL
:
1800 /* Changes to BImode should not affect vector booleans. */
1803 case MODE_VECTOR_INT
:
1804 case MODE_VECTOR_FLOAT
:
1805 case MODE_VECTOR_FRACT
:
1806 case MODE_VECTOR_UFRACT
:
1807 case MODE_VECTOR_ACCUM
:
1808 case MODE_VECTOR_UACCUM
:
1809 printf (" mode_base_align[E_%smode] = %d*s;\n",
1810 m
->name
, m
->ncomponents
);
1815 "mode %s is neither vector nor complex but contains %s",
1816 m
->name
, a
->mode
->name
);
1822 /* Ibit adjustments don't have to propagate. */
1823 for (a
= adj_ibit
; a
; a
= a
->next
)
1825 printf ("\n /* %s:%d */\n s = %s;\n",
1826 a
->file
, a
->line
, a
->adjustment
);
1827 printf (" mode_ibit[E_%smode] = s;\n", a
->mode
->name
);
1830 /* Fbit adjustments don't have to propagate. */
1831 for (a
= adj_fbit
; a
; a
= a
->next
)
1833 printf ("\n /* %s:%d */\n s = %s;\n",
1834 a
->file
, a
->line
, a
->adjustment
);
1835 printf (" mode_fbit[E_%smode] = s;\n", a
->mode
->name
);
1838 /* Real mode formats don't have to propagate anywhere. */
1839 for (a
= adj_format
; a
; a
= a
->next
)
1840 printf ("\n /* %s:%d */\n REAL_MODE_FORMAT (E_%smode) = %s;\n",
1841 a
->file
, a
->line
, a
->mode
->name
, a
->adjustment
);
1846 /* Emit ibit for all modes. */
1849 emit_mode_ibit (void)
1852 struct mode_data
*m
;
1854 print_maybe_const_decl ("%sunsigned char",
1855 "mode_ibit", "NUM_MACHINE_MODES",
1858 for_all_modes (c
, m
)
1859 tagged_printf ("%u", m
->ibit
, m
->name
);
1864 /* Emit fbit for all modes. */
1867 emit_mode_fbit (void)
1870 struct mode_data
*m
;
1872 print_maybe_const_decl ("%sunsigned char",
1873 "mode_fbit", "NUM_MACHINE_MODES",
1876 for_all_modes (c
, m
)
1877 tagged_printf ("%u", m
->fbit
, m
->name
);
1882 /* Emit __intN for all modes. */
1885 emit_mode_int_n (void)
1888 struct mode_data
*m
;
1889 struct mode_data
**mode_sort
;
1893 print_decl ("int_n_data_t", "int_n_data", "");
1896 for_all_modes (c
, m
)
1899 mode_sort
= XALLOCAVEC (struct mode_data
*, n_modes
);
1902 for_all_modes (c
, m
)
1904 mode_sort
[n_modes
++] = m
;
1906 /* Yes, this is a bubblesort, but there are at most four (and
1907 usually only 1-2) entries to sort. */
1908 for (i
= 0; i
<n_modes
- 1; i
++)
1909 for (j
= i
+ 1; j
< n_modes
; j
++)
1910 if (mode_sort
[i
]->int_n
> mode_sort
[j
]->int_n
)
1911 std::swap (mode_sort
[i
], mode_sort
[j
]);
1913 for (i
= 0; i
< n_modes
; i
++)
1917 tagged_printf ("%u", m
->int_n
, m
->name
);
1918 printf ("{ E_%smode },", m
->name
);
1927 emit_insn_modes_c (void)
1929 emit_insn_modes_c_header ();
1932 emit_mode_precision ();
1934 emit_mode_nunits ();
1936 emit_mode_complex ();
1939 emit_mode_unit_size ();
1940 emit_mode_unit_precision ();
1941 emit_mode_base_align ();
1942 emit_class_narrowest_mode ();
1943 emit_real_format_for_mode ();
1944 emit_mode_adjustments ();
1951 emit_min_insn_modes_c (void)
1953 emit_min_insn_modes_c_header ();
1956 emit_mode_nunits ();
1959 emit_class_narrowest_mode ();
1962 /* Master control. */
1964 main (int argc
, char **argv
)
1966 bool gen_header
= false, gen_inlines
= false, gen_min
= false;
1971 else if (argc
== 2 && !strcmp (argv
[1], "-h"))
1973 else if (argc
== 2 && !strcmp (argv
[1], "-i"))
1975 else if (argc
== 2 && !strcmp (argv
[1], "-m"))
1979 error ("usage: %s [-h|-i|-m] > file", progname
);
1980 return FATAL_EXIT_CODE
;
1983 modes_by_name
= htab_create_alloc (64, hash_mode
, eq_mode
, 0, xcalloc
, free
);
1986 complete_all_modes ();
1989 return FATAL_EXIT_CODE
;
1994 emit_insn_modes_h ();
1995 else if (gen_inlines
)
1996 emit_insn_modes_inline_h ();
1998 emit_min_insn_modes_c ();
2000 emit_insn_modes_c ();
2002 if (fflush (stdout
) || fclose (stdout
))
2003 return FATAL_EXIT_CODE
;
2004 return SUCCESS_EXIT_CODE
;