1 /* Generate the machine mode enumeration and associated tables.
2 Copyright (C) 2003-2024 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
24 /* enum mode_class is normally defined by machmode.h but we can't
25 include that header here. */
26 #include "mode-classes.def"
28 #define DEF_MODE_CLASS(M) M
29 enum mode_class
{ MODE_CLASSES
, MAX_MODE_CLASS
};
32 /* Text names of mode classes, for output. */
33 #define DEF_MODE_CLASS(M) #M
34 static const char *const mode_class_names
[MAX_MODE_CLASS
] =
41 #ifdef EXTRA_MODES_FILE
42 # define HAVE_EXTRA_MODES 1
44 # define HAVE_EXTRA_MODES 0
45 # define EXTRA_MODES_FILE ""
48 /* Data structure for building up what we know about a mode.
49 They're clustered by mode class. */
52 struct mode_data
*next
; /* next this class - arbitrary order */
54 const char *name
; /* printable mode name -- SI, not SImode */
55 enum mode_class cl
; /* this mode class */
56 unsigned int order
; /* top-level sorting order */
57 unsigned int precision
; /* size in bits, equiv to TYPE_PRECISION */
58 unsigned int bytesize
; /* storage size in addressable units */
59 unsigned int ncomponents
; /* number of subunits */
60 unsigned int alignment
; /* mode alignment */
61 const char *format
; /* floating point format - float modes only */
63 struct mode_data
*component
; /* mode of components */
64 struct mode_data
*wider
; /* next wider mode */
66 struct mode_data
*contained
; /* Pointer to list of modes that have
67 this mode as a component. */
68 struct mode_data
*next_cont
; /* Next mode in that list. */
70 struct mode_data
*complex; /* complex type with mode as component. */
71 const char *file
; /* file and line of definition, */
72 unsigned int line
; /* for error reporting */
73 unsigned int counter
; /* Rank ordering of modes */
74 unsigned int ibit
; /* the number of integral bits */
75 unsigned int fbit
; /* the number of fractional bits */
76 bool need_nunits_adj
; /* true if this mode needs dynamic nunits
78 bool need_bytesize_adj
; /* true if this mode needs dynamic size
80 unsigned int int_n
; /* If nonzero, then __int<INT_N> will be defined */
84 static struct mode_data
*modes
[MAX_MODE_CLASS
];
85 static unsigned int n_modes
[MAX_MODE_CLASS
];
86 static struct mode_data
*void_mode
;
88 static const struct mode_data blank_mode
= {
89 0, "<unknown>", MAX_MODE_CLASS
,
90 0, -1U, -1U, -1U, -1U,
92 "<unknown>", 0, 0, 0, 0, false, false, 0,
96 static htab_t modes_by_name
;
98 /* Data structure for recording target-specified runtime adjustments
99 to a particular mode. We support varying the byte size, the
100 alignment, and the floating point format. */
103 struct mode_adjust
*next
;
104 struct mode_data
*mode
;
105 const char *adjustment
;
111 static struct mode_adjust
*adj_nunits
;
112 static struct mode_adjust
*adj_bytesize
;
113 static struct mode_adjust
*adj_alignment
;
114 static struct mode_adjust
*adj_format
;
115 static struct mode_adjust
*adj_ibit
;
116 static struct mode_adjust
*adj_fbit
;
117 static struct mode_adjust
*adj_precision
;
119 /* Mode class operations. */
120 static enum mode_class
121 complex_class (enum mode_class c
)
125 case MODE_INT
: return MODE_COMPLEX_INT
;
126 case MODE_PARTIAL_INT
: return MODE_COMPLEX_INT
;
127 case MODE_FLOAT
: return MODE_COMPLEX_FLOAT
;
129 error ("no complex class for class %s", mode_class_names
[c
]);
134 static enum mode_class
135 vector_class (enum mode_class cl
)
139 case MODE_INT
: return MODE_VECTOR_INT
;
140 case MODE_FLOAT
: return MODE_VECTOR_FLOAT
;
141 case MODE_FRACT
: return MODE_VECTOR_FRACT
;
142 case MODE_UFRACT
: return MODE_VECTOR_UFRACT
;
143 case MODE_ACCUM
: return MODE_VECTOR_ACCUM
;
144 case MODE_UACCUM
: return MODE_VECTOR_UACCUM
;
146 error ("no vector class for class %s", mode_class_names
[cl
]);
151 /* Utility routines. */
152 static inline struct mode_data
*
153 find_mode (const char *name
)
155 struct mode_data key
;
158 return (struct mode_data
*) htab_find (modes_by_name
, &key
);
161 static struct mode_data
*
162 new_mode (enum mode_class cl
, const char *name
,
163 const char *file
, unsigned int line
)
166 static unsigned int count
= 0;
168 m
= find_mode (name
);
171 error ("%s:%d: duplicate definition of mode \"%s\"",
172 trim_filename (file
), line
, name
);
173 error ("%s:%d: previous definition here", m
->file
, m
->line
);
177 m
= XNEW (struct mode_data
);
178 memcpy (m
, &blank_mode
, sizeof (struct mode_data
));
182 m
->file
= trim_filename (file
);
184 m
->counter
= count
++;
190 *htab_find_slot (modes_by_name
, m
, INSERT
) = m
;
196 hash_mode (const void *p
)
198 const struct mode_data
*m
= (const struct mode_data
*)p
;
199 return htab_hash_string (m
->name
);
203 eq_mode (const void *p
, const void *q
)
205 const struct mode_data
*a
= (const struct mode_data
*)p
;
206 const struct mode_data
*b
= (const struct mode_data
*)q
;
208 return !strcmp (a
->name
, b
->name
);
211 #define for_all_modes(C, M) \
212 for (C = 0; C < MAX_MODE_CLASS; C++) \
213 for (M = modes[C]; M; M = M->next)
215 static void ATTRIBUTE_UNUSED
216 new_adjust (const char *name
,
217 struct mode_adjust
**category
, const char *catname
,
218 const char *adjustment
,
219 enum mode_class required_class_from
,
220 enum mode_class required_class_to
,
221 const char *file
, unsigned int line
)
223 struct mode_data
*mode
= find_mode (name
);
224 struct mode_adjust
*a
;
226 file
= trim_filename (file
);
230 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
234 if (required_class_from
!= MODE_RANDOM
235 && (mode
->cl
< required_class_from
|| mode
->cl
> required_class_to
))
237 error ("%s:%d: mode \"%s\" is not among class {%s, %s}",
238 file
, line
, name
, mode_class_names
[required_class_from
] + 5,
239 mode_class_names
[required_class_to
] + 5);
243 for (a
= *category
; a
; a
= a
->next
)
246 error ("%s:%d: mode \"%s\" already has a %s adjustment",
247 file
, line
, name
, catname
);
248 error ("%s:%d: previous adjustment here", a
->file
, a
->line
);
252 a
= XNEW (struct mode_adjust
);
254 a
->adjustment
= adjustment
;
262 /* Diagnose failure to meet expectations in a partially filled out
264 enum requirement
{ SET
, UNSET
, OPTIONAL
};
266 #define validate_field_(mname, fname, req, val, unset, file, line) do { \
271 error ("%s:%d: (%s) field %s must be set", \
272 file, line, mname, fname); \
276 error ("%s:%d: (%s) field %s must not be set", \
277 file, line, mname, fname); \
283 #define validate_field(M, F) \
284 validate_field_(M->name, #F, r_##F, M->F, blank_mode.F, M->file, M->line)
287 validate_mode (struct mode_data
*m
,
288 enum requirement r_precision
,
289 enum requirement r_bytesize
,
290 enum requirement r_component
,
291 enum requirement r_ncomponents
,
292 enum requirement r_format
)
294 validate_field (m
, precision
);
295 validate_field (m
, bytesize
);
296 validate_field (m
, component
);
297 validate_field (m
, ncomponents
);
298 validate_field (m
, format
);
300 #undef validate_field
301 #undef validate_field_
303 /* Given a partially-filled-out mode structure, figure out what we can
304 and fill the rest of it in; die if it isn't enough. */
306 complete_mode (struct mode_data
*m
)
308 unsigned int alignment
;
312 error ("%s:%d: mode with no name", m
->file
, m
->line
);
315 if (m
->cl
== MAX_MODE_CLASS
)
317 error ("%s:%d: %smode has no mode class", m
->file
, m
->line
, m
->name
);
324 /* Nothing more need be said. */
325 if (!strcmp (m
->name
, "VOID"))
328 validate_mode (m
, UNSET
, UNSET
, UNSET
, UNSET
, UNSET
);
337 /* Again, nothing more need be said. For historical reasons,
338 the size of a CC mode is four units. */
339 validate_mode (m
, UNSET
, UNSET
, UNSET
, UNSET
, UNSET
);
348 case MODE_DECIMAL_FLOAT
:
353 /* A scalar mode must have a byte size, may have a bit size,
354 and must not have components. A float mode must have a
356 validate_mode (m
, OPTIONAL
, SET
, UNSET
, UNSET
,
357 (m
->cl
== MODE_FLOAT
|| m
->cl
== MODE_DECIMAL_FLOAT
)
365 /* Opaque modes have size and precision. */
366 validate_mode (m
, OPTIONAL
, SET
, UNSET
, UNSET
, UNSET
);
372 case MODE_PARTIAL_INT
:
373 /* A partial integer mode uses ->component to say what the
374 corresponding full-size integer mode is, and may also
375 specify a bit size. */
376 validate_mode (m
, OPTIONAL
, UNSET
, SET
, UNSET
, UNSET
);
378 m
->bytesize
= m
->component
->bytesize
;
383 case MODE_COMPLEX_INT
:
384 case MODE_COMPLEX_FLOAT
:
385 /* Complex modes should have a component indicated, but no more. */
386 validate_mode (m
, UNSET
, UNSET
, SET
, UNSET
, UNSET
);
388 if (m
->component
->precision
!= (unsigned int)-1)
389 m
->precision
= 2 * m
->component
->precision
;
390 m
->bytesize
= 2 * m
->component
->bytesize
;
393 case MODE_VECTOR_BOOL
:
394 validate_mode (m
, UNSET
, SET
, SET
, SET
, UNSET
);
397 case MODE_VECTOR_INT
:
398 case MODE_VECTOR_FLOAT
:
399 case MODE_VECTOR_FRACT
:
400 case MODE_VECTOR_UFRACT
:
401 case MODE_VECTOR_ACCUM
:
402 case MODE_VECTOR_UACCUM
:
403 /* Vector modes should have a component and a number of components. */
404 validate_mode (m
, UNSET
, UNSET
, SET
, SET
, UNSET
);
405 if (m
->component
->precision
!= (unsigned int)-1)
406 m
->precision
= m
->ncomponents
* m
->component
->precision
;
407 m
->bytesize
= m
->ncomponents
* m
->component
->bytesize
;
414 /* If not already specified, the mode alignment defaults to the largest
415 power of two that divides the size of the object. Complex types are
416 not more aligned than their contents. */
417 if (m
->cl
== MODE_COMPLEX_INT
|| m
->cl
== MODE_COMPLEX_FLOAT
)
418 alignment
= m
->component
->bytesize
;
420 alignment
= m
->bytesize
;
422 m
->alignment
= alignment
& (~alignment
+ 1);
424 /* If this mode has components, make the component mode point back
425 to this mode, for the sake of adjustments. */
428 m
->next_cont
= m
->component
->contained
;
429 m
->component
->contained
= m
;
434 complete_all_modes (void)
439 for_all_modes (cl
, m
)
443 /* For each mode in class CLASS, construct a corresponding complex mode. */
444 #define COMPLEX_MODES(C) make_complex_modes (MODE_##C, __FILE__, __LINE__)
446 make_complex_modes (enum mode_class cl
,
447 const char *file
, unsigned int line
)
451 enum mode_class cclass
= complex_class (cl
);
453 if (cclass
== MODE_RANDOM
)
456 for (m
= modes
[cl
]; m
; m
= m
->next
)
461 /* Skip BImode. FIXME: BImode probably shouldn't be MODE_INT. */
465 m_len
= strlen (m
->name
);
466 /* The leading "1 +" is in case we prepend a "C" below. */
467 buf
= (char *) xmalloc (1 + m_len
+ 1);
469 /* Float complex modes are named SCmode, etc.
470 Int complex modes are named CSImode, etc.
471 This inconsistency should be eliminated. */
473 if (cl
== MODE_FLOAT
)
475 memcpy (buf
, m
->name
, m_len
+ 1);
476 p
= strchr (buf
, 'F');
477 if (p
== 0 && strchr (buf
, 'D') == 0)
479 error ("%s:%d: float mode \"%s\" has no 'F' or 'D'",
480 m
->file
, m
->line
, m
->name
);
490 memcpy (buf
+ 1, m
->name
, m_len
+ 1);
493 c
= new_mode (cclass
, buf
, file
, line
);
499 /* For all modes in class CL, construct vector modes of width WIDTH,
500 having as many components as necessary. ORDER is the sorting order
501 of the mode, with smaller numbers indicating a higher priority. */
502 #define VECTOR_MODES_WITH_PREFIX(PREFIX, C, W, ORDER) \
503 make_vector_modes (MODE_##C, #PREFIX, W, ORDER, __FILE__, __LINE__)
504 #define VECTOR_MODES(C, W) VECTOR_MODES_WITH_PREFIX (V, C, W, 0)
505 static void ATTRIBUTE_UNUSED
506 make_vector_modes (enum mode_class cl
, const char *prefix
, unsigned int width
,
507 unsigned int order
, const char *file
, unsigned int line
)
511 /* Big enough for a 32-bit UINT_MAX plus the text. */
513 unsigned int ncomponents
;
514 enum mode_class vclass
= vector_class (cl
);
516 if (vclass
== MODE_RANDOM
)
519 for (m
= modes
[cl
]; m
; m
= m
->next
)
521 /* Do not construct vector modes with only one element, or
522 vector modes where the element size doesn't divide the full
524 ncomponents
= width
/ m
->bytesize
;
527 if (width
% m
->bytesize
)
530 /* Skip QFmode and BImode. FIXME: this special case should
532 if (cl
== MODE_FLOAT
&& m
->bytesize
== 1)
537 if ((size_t) snprintf (buf
, sizeof buf
, "%s%u%s", prefix
,
538 ncomponents
, m
->name
) >= sizeof buf
)
540 error ("%s:%d: mode name \"%s\" is too long",
541 m
->file
, m
->line
, m
->name
);
545 v
= new_mode (vclass
, xstrdup (buf
), file
, line
);
548 v
->ncomponents
= ncomponents
;
552 /* Create a vector of booleans called NAME with COUNT elements and
553 BYTESIZE bytes in total. */
554 #define VECTOR_BOOL_MODE(NAME, COUNT, COMPONENT, BYTESIZE) \
555 make_vector_bool_mode (#NAME, COUNT, #COMPONENT, BYTESIZE, \
557 static void ATTRIBUTE_UNUSED
558 make_vector_bool_mode (const char *name
, unsigned int count
,
559 const char *component
, unsigned int bytesize
,
560 const char *file
, unsigned int line
)
562 struct mode_data
*m
= find_mode (component
);
565 error ("%s:%d: no mode \"%s\"", file
, line
, component
);
569 struct mode_data
*v
= new_mode (MODE_VECTOR_BOOL
, name
, file
, line
);
571 v
->ncomponents
= count
;
572 v
->bytesize
= bytesize
;
577 #define _SPECIAL_MODE(C, N) \
578 make_special_mode (MODE_##C, #N, __FILE__, __LINE__)
579 #define RANDOM_MODE(N) _SPECIAL_MODE (RANDOM, N)
580 #define CC_MODE(N) _SPECIAL_MODE (CC, N)
583 make_special_mode (enum mode_class cl
, const char *name
,
584 const char *file
, unsigned int line
)
586 new_mode (cl
, name
, file
, line
);
589 #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y)
590 #define FRACTIONAL_INT_MODE(N, B, Y) \
591 make_int_mode (#N, B, Y, __FILE__, __LINE__)
594 make_int_mode (const char *name
,
595 unsigned int precision
, unsigned int bytesize
,
596 const char *file
, unsigned int line
)
598 struct mode_data
*m
= new_mode (MODE_INT
, name
, file
, line
);
599 m
->bytesize
= bytesize
;
600 m
->precision
= precision
;
603 #define BOOL_MODE(N, B, Y) \
604 make_bool_mode (#N, B, Y, __FILE__, __LINE__)
607 make_bool_mode (const char *name
,
608 unsigned int precision
, unsigned int bytesize
,
609 const char *file
, unsigned int line
)
611 struct mode_data
*m
= new_mode (MODE_INT
, name
, file
, line
);
612 m
->bytesize
= bytesize
;
613 m
->precision
= precision
;
617 #define OPAQUE_MODE(N, B) \
618 make_opaque_mode (#N, -1U, B, __FILE__, __LINE__)
620 static void ATTRIBUTE_UNUSED
621 make_opaque_mode (const char *name
,
622 unsigned int precision
,
623 unsigned int bytesize
,
624 const char *file
, unsigned int line
)
626 struct mode_data
*m
= new_mode (MODE_OPAQUE
, name
, file
, line
);
627 m
->bytesize
= bytesize
;
628 m
->precision
= precision
;
631 #define FRACT_MODE(N, Y, F) \
632 make_fixed_point_mode (MODE_FRACT, #N, Y, 0, F, __FILE__, __LINE__)
634 #define UFRACT_MODE(N, Y, F) \
635 make_fixed_point_mode (MODE_UFRACT, #N, Y, 0, F, __FILE__, __LINE__)
637 #define ACCUM_MODE(N, Y, I, F) \
638 make_fixed_point_mode (MODE_ACCUM, #N, Y, I, F, __FILE__, __LINE__)
640 #define UACCUM_MODE(N, Y, I, F) \
641 make_fixed_point_mode (MODE_UACCUM, #N, Y, I, F, __FILE__, __LINE__)
643 /* Create a fixed-point mode by setting CL, NAME, BYTESIZE, IBIT, FBIT,
647 make_fixed_point_mode (enum mode_class cl
,
649 unsigned int bytesize
,
652 const char *file
, unsigned int line
)
654 struct mode_data
*m
= new_mode (cl
, name
, file
, line
);
655 m
->bytesize
= bytesize
;
660 #define FLOAT_MODE(N, Y, F) FRACTIONAL_FLOAT_MODE (N, -1U, Y, F)
661 #define FRACTIONAL_FLOAT_MODE(N, B, Y, F) \
662 make_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
665 make_float_mode (const char *name
,
666 unsigned int precision
, unsigned int bytesize
,
668 const char *file
, unsigned int line
)
670 struct mode_data
*m
= new_mode (MODE_FLOAT
, name
, file
, line
);
671 m
->bytesize
= bytesize
;
672 m
->precision
= precision
;
676 #define DECIMAL_FLOAT_MODE(N, Y, F) \
677 FRACTIONAL_DECIMAL_FLOAT_MODE (N, -1U, Y, F)
678 #define FRACTIONAL_DECIMAL_FLOAT_MODE(N, B, Y, F) \
679 make_decimal_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
682 make_decimal_float_mode (const char *name
,
683 unsigned int precision
, unsigned int bytesize
,
685 const char *file
, unsigned int line
)
687 struct mode_data
*m
= new_mode (MODE_DECIMAL_FLOAT
, name
, file
, line
);
688 m
->bytesize
= bytesize
;
689 m
->precision
= precision
;
693 #define RESET_FLOAT_FORMAT(N, F) \
694 reset_float_format (#N, #F, __FILE__, __LINE__)
695 static void ATTRIBUTE_UNUSED
696 reset_float_format (const char *name
, const char *format
,
697 const char *file
, unsigned int line
)
699 struct mode_data
*m
= find_mode (name
);
702 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
705 if (m
->cl
!= MODE_FLOAT
&& m
->cl
!= MODE_DECIMAL_FLOAT
)
707 error ("%s:%d: mode \"%s\" is not a FLOAT class", file
, line
, name
);
713 /* __intN support. */
714 #define INT_N(M,PREC) \
715 make_int_n (#M, PREC, __FILE__, __LINE__)
716 static void ATTRIBUTE_UNUSED
717 make_int_n (const char *m
, int bitsize
,
718 const char *file
, unsigned int line
)
720 struct mode_data
*component
= find_mode (m
);
723 error ("%s:%d: no mode \"%s\"", file
, line
, m
);
726 if (component
->cl
!= MODE_INT
727 && component
->cl
!= MODE_PARTIAL_INT
)
729 error ("%s:%d: mode \"%s\" is not class INT or PARTIAL_INT", file
, line
, m
);
732 if (component
->int_n
!= 0)
734 error ("%s:%d: mode \"%s\" already has an intN", file
, line
, m
);
738 component
->int_n
= bitsize
;
741 /* Partial integer modes are specified by relation to a full integer
743 #define PARTIAL_INT_MODE(M,PREC,NAME) \
744 make_partial_integer_mode (#M, #NAME, PREC, __FILE__, __LINE__)
745 static void ATTRIBUTE_UNUSED
746 make_partial_integer_mode (const char *base
, const char *name
,
747 unsigned int precision
,
748 const char *file
, unsigned int line
)
751 struct mode_data
*component
= find_mode (base
);
754 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
757 if (component
->cl
!= MODE_INT
)
759 error ("%s:%d: mode \"%s\" is not class INT", file
, line
, name
);
763 m
= new_mode (MODE_PARTIAL_INT
, name
, file
, line
);
764 m
->precision
= precision
;
765 m
->component
= component
;
768 /* A single vector mode can be specified by naming its component
769 mode and the number of components. */
770 #define VECTOR_MODE_WITH_PREFIX(PREFIX, C, M, N, ORDER) \
771 make_vector_mode (MODE_##C, #PREFIX, #M, N, ORDER, __FILE__, __LINE__);
772 #define VECTOR_MODE(C, M, N) VECTOR_MODE_WITH_PREFIX(V, C, M, N, 0);
773 static void ATTRIBUTE_UNUSED
774 make_vector_mode (enum mode_class bclass
,
777 unsigned int ncomponents
,
779 const char *file
, unsigned int line
)
782 enum mode_class vclass
= vector_class (bclass
);
783 struct mode_data
*component
= find_mode (base
);
786 if (vclass
== MODE_RANDOM
)
790 error ("%s:%d: no mode \"%s\"", file
, line
, base
);
793 if (component
->cl
!= bclass
794 && (component
->cl
!= MODE_PARTIAL_INT
795 || bclass
!= MODE_INT
))
797 error ("%s:%d: mode \"%s\" is not class %s",
798 file
, line
, base
, mode_class_names
[bclass
] + 5);
802 if ((size_t)snprintf (namebuf
, sizeof namebuf
, "%s%u%s", prefix
,
803 ncomponents
, base
) >= sizeof namebuf
)
805 error ("%s:%d: mode name \"%s\" is too long",
810 v
= new_mode (vclass
, xstrdup (namebuf
), file
, line
);
812 v
->ncomponents
= ncomponents
;
813 v
->component
= component
;
817 #define _ADD_ADJUST(A, M, X, C1, C2) \
818 new_adjust (#M, &adj_##A, #A, #X, MODE_##C1, MODE_##C2, __FILE__, __LINE__)
820 #define ADJUST_NUNITS(M, X) _ADD_ADJUST (nunits, M, X, RANDOM, RANDOM)
821 #define ADJUST_BYTESIZE(M, X) _ADD_ADJUST (bytesize, M, X, RANDOM, RANDOM)
822 #define ADJUST_ALIGNMENT(M, X) _ADD_ADJUST (alignment, M, X, RANDOM, RANDOM)
823 #define ADJUST_PRECISION(M, X) _ADD_ADJUST (precision, M, X, RANDOM, RANDOM)
824 #define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST (format, M, X, FLOAT, FLOAT)
825 #define ADJUST_IBIT(M, X) _ADD_ADJUST (ibit, M, X, ACCUM, UACCUM)
826 #define ADJUST_FBIT(M, X) _ADD_ADJUST (fbit, M, X, FRACT, UACCUM)
828 static int bits_per_unit
;
829 static int max_bitsize_mode_any_int
;
830 static int max_bitsize_mode_any_mode
;
835 #include "machmode.def"
837 /* So put the default value unless the target needs a non standard
840 bits_per_unit
= BITS_PER_UNIT
;
845 #ifdef MAX_BITSIZE_MODE_ANY_INT
846 max_bitsize_mode_any_int
= MAX_BITSIZE_MODE_ANY_INT
;
848 max_bitsize_mode_any_int
= 0;
851 #ifdef MAX_BITSIZE_MODE_ANY_MODE
852 max_bitsize_mode_any_mode
= MAX_BITSIZE_MODE_ANY_MODE
;
854 max_bitsize_mode_any_mode
= 0;
858 #ifndef NUM_POLY_INT_COEFFS
859 #define NUM_POLY_INT_COEFFS 1
864 /* Sort a list of modes into the order needed for the WIDER field:
865 major sort by precision, minor sort by component precision.
868 QI < HI < SI < DI < TI
869 V4QI < V2HI < V8QI < V4HI < V2SI.
871 If the precision is not set, sort by the bytesize. A mode with
872 precision set gets sorted before a mode without precision set, if
873 they have the same bytesize; this is the right thing because
874 the precision must always be smaller than the bytesize * BITS_PER_UNIT.
875 We don't have to do anything special to get this done -- an unset
876 precision shows up as (unsigned int)-1, i.e. UINT_MAX. */
878 cmp_modes (const void *a
, const void *b
)
880 const struct mode_data
*const m
= *(const struct mode_data
*const*)a
;
881 const struct mode_data
*const n
= *(const struct mode_data
*const*)b
;
883 if (m
->order
> n
->order
)
885 else if (m
->order
< n
->order
)
888 if (m
->bytesize
> n
->bytesize
)
890 else if (m
->bytesize
< n
->bytesize
)
893 if (m
->precision
> n
->precision
)
895 else if (m
->precision
< n
->precision
)
898 if (!m
->component
&& !n
->component
)
900 if (m
->counter
< n
->counter
)
906 if (m
->component
->bytesize
> n
->component
->bytesize
)
908 else if (m
->component
->bytesize
< n
->component
->bytesize
)
911 if (m
->component
->precision
> n
->component
->precision
)
913 else if (m
->component
->precision
< n
->component
->precision
)
916 if (m
->counter
< n
->counter
)
923 calc_wider_mode (void)
927 struct mode_data
**sortbuf
;
928 unsigned int max_n_modes
= 0;
931 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
932 max_n_modes
= MAX (max_n_modes
, n_modes
[c
]);
934 /* Allocate max_n_modes + 1 entries to leave room for the extra null
935 pointer assigned after the qsort call below. */
936 sortbuf
= XALLOCAVEC (struct mode_data
*, max_n_modes
+ 1);
938 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
940 /* "wider" is not meaningful for MODE_RANDOM and MODE_CC.
941 However, we want these in textual order, and we have
942 precisely the reverse. */
943 if (c
== MODE_RANDOM
|| c
== MODE_CC
)
945 struct mode_data
*prev
, *next
;
947 for (prev
= 0, m
= modes
[c
]; m
; m
= next
)
949 m
->wider
= void_mode
;
951 /* this is nreverse */
963 for (i
= 0, m
= modes
[c
]; m
; i
++, m
= m
->next
)
966 (qsort
) (sortbuf
, i
, sizeof (struct mode_data
*), cmp_modes
);
969 for (j
= 0; j
< i
; j
++)
971 sortbuf
[j
]->next
= sortbuf
[j
+ 1];
972 if (c
== MODE_PARTIAL_INT
)
973 sortbuf
[j
]->wider
= sortbuf
[j
]->component
;
975 sortbuf
[j
]->wider
= sortbuf
[j
]->next
;
978 modes
[c
] = sortbuf
[0];
983 /* Text to add to the constant part of a poly_int initializer in
984 order to fill out te whole structure. */
985 #if NUM_POLY_INT_COEFFS == 1
986 #define ZERO_COEFFS ""
987 #elif NUM_POLY_INT_COEFFS == 2
988 #define ZERO_COEFFS ", 0"
990 #error "Unknown value of NUM_POLY_INT_COEFFS"
993 /* Output routines. */
995 #define tagged_printf(FMT, ARG, TAG) do { \
996 int count_ = printf (" " FMT ",", ARG); \
997 printf ("%*s/* %s */\n", 27 - count_, "", TAG); \
1000 #define print_decl(TYPE, NAME, ASIZE) \
1001 puts ("\nconst " TYPE " " NAME "[" ASIZE "] =\n{");
1003 #define print_maybe_const_decl(TYPE, NAME, ASIZE, NEEDS_ADJ) \
1004 printf ("\n" TYPE " " NAME "[" ASIZE "] = \n{\n", \
1005 NEEDS_ADJ ? "" : "const ")
1007 #define print_closer() puts ("};")
1009 /* Compute the max bitsize of some of the classes of integers. It may
1010 be that there are needs for the other integer classes, and this
1011 code is easy to extend. */
1015 unsigned int max
, mmax
;
1016 struct mode_data
*i
;
1021 printf ("#define BITS_PER_UNIT (%d)\n", bits_per_unit
);
1023 if (max_bitsize_mode_any_int
== 0)
1025 for (max
= 1, i
= modes
[MODE_INT
]; i
; i
= i
->next
)
1026 if (max
< i
->bytesize
)
1029 for (max
= 1, i
= modes
[MODE_PARTIAL_INT
]; i
; i
= i
->next
)
1030 if (max
< i
->bytesize
)
1034 printf ("#define MAX_BITSIZE_MODE_ANY_INT (%d*BITS_PER_UNIT)\n", mmax
);
1037 printf ("#define MAX_BITSIZE_MODE_ANY_INT %d\n", max_bitsize_mode_any_int
);
1039 if (max_bitsize_mode_any_mode
== 0)
1042 for (j
= 0; j
< MAX_MODE_CLASS
; j
++)
1043 for (i
= modes
[j
]; i
; i
= i
->next
)
1044 if (mmax
< i
->bytesize
)
1046 printf ("#define MAX_BITSIZE_MODE_ANY_MODE (%d*BITS_PER_UNIT)\n", mmax
);
1049 printf ("#define MAX_BITSIZE_MODE_ANY_MODE %d\n",
1050 max_bitsize_mode_any_mode
);
1053 /* Emit mode_size_inline routine into insn-modes.h header. */
1055 emit_mode_size_inline (void)
1058 struct mode_adjust
*a
;
1059 struct mode_data
*m
;
1061 /* Size adjustments must be propagated to all containing modes. */
1062 for (a
= adj_bytesize
; a
; a
= a
->next
)
1064 a
->mode
->need_bytesize_adj
= true;
1065 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1066 m
->need_bytesize_adj
= true;
1069 /* Changing the number of units by a factor of X also changes the size
1070 by a factor of X. */
1071 for (mode_adjust
*a
= adj_nunits
; a
; a
= a
->next
)
1072 a
->mode
->need_bytesize_adj
= true;
1075 #ifdef __cplusplus\n\
1076 inline __attribute__((__always_inline__))\n\
1078 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1081 mode_size_inline (machine_mode mode)\n\
1083 extern %spoly_uint16 mode_size[NUM_MACHINE_MODES];\n\
1084 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1086 {\n", adj_nunits
|| adj_bytesize
? "" : "const ");
1088 for_all_modes (c
, m
)
1089 if (!m
->need_bytesize_adj
)
1090 printf (" case E_%smode: return %u;\n", m
->name
, m
->bytesize
);
1093 default: return mode_size[mode];\n\
1098 /* Emit mode_nunits_inline routine into insn-modes.h header. */
1100 emit_mode_nunits_inline (void)
1103 struct mode_data
*m
;
1105 for (mode_adjust
*a
= adj_nunits
; a
; a
= a
->next
)
1106 a
->mode
->need_nunits_adj
= true;
1109 #ifdef __cplusplus\n\
1110 inline __attribute__((__always_inline__))\n\
1112 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1115 mode_nunits_inline (machine_mode mode)\n\
1117 extern %spoly_uint16 mode_nunits[NUM_MACHINE_MODES];\n\
1119 {\n", adj_nunits
? "" : "const ");
1121 for_all_modes (c
, m
)
1122 if (!m
->need_nunits_adj
)
1123 printf (" case E_%smode: return %u;\n", m
->name
, m
->ncomponents
);
1126 default: return mode_nunits[mode];\n\
1131 /* Emit mode_inner_inline routine into insn-modes.h header. */
1133 emit_mode_inner_inline (void)
1136 struct mode_data
*m
;
1139 #ifdef __cplusplus\n\
1140 inline __attribute__((__always_inline__))\n\
1142 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1145 mode_inner_inline (machine_mode mode)\n\
1147 extern const unsigned short mode_inner[NUM_MACHINE_MODES];\n\
1148 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1152 for_all_modes (c
, m
)
1153 printf (" case E_%smode: return E_%smode;\n", m
->name
,
1154 c
!= MODE_PARTIAL_INT
&& m
->component
1155 ? m
->component
->name
: m
->name
);
1158 default: return mode_inner[mode];\n\
1163 /* Emit mode_unit_size_inline routine into insn-modes.h header. */
1165 emit_mode_unit_size_inline (void)
1168 struct mode_data
*m
;
1171 #ifdef __cplusplus\n\
1172 inline __attribute__((__always_inline__))\n\
1174 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1177 mode_unit_size_inline (machine_mode mode)\n\
1179 extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES];\
1181 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1185 for_all_modes (c
, m
)
1187 const char *name
= m
->name
;
1188 struct mode_data
*m2
= m
;
1189 if (c
!= MODE_PARTIAL_INT
&& m2
->component
)
1191 if (!m2
->need_bytesize_adj
)
1192 printf (" case E_%smode: return %u;\n", name
, m2
->bytesize
);
1196 default: return mode_unit_size[mode];\n\
1201 /* Emit mode_unit_precision_inline routine into insn-modes.h header. */
1203 emit_mode_unit_precision_inline (void)
1206 struct mode_data
*m
;
1209 #ifdef __cplusplus\n\
1210 inline __attribute__((__always_inline__))\n\
1212 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1215 mode_unit_precision_inline (machine_mode mode)\n\
1217 extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES];\n\
1218 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1222 for_all_modes (c
, m
)
1224 struct mode_data
*m2
1225 = (c
!= MODE_PARTIAL_INT
&& m
->component
) ? m
->component
: m
;
1226 if (m2
->precision
!= (unsigned int)-1)
1227 printf (" case E_%smode: return %u;\n", m
->name
, m2
->precision
);
1229 printf (" case E_%smode: return %u*BITS_PER_UNIT;\n",
1230 m
->name
, m2
->bytesize
);
1234 default: return mode_unit_precision[mode];\n\
1239 /* Return the best machine mode class for MODE, or null if machine_mode
1243 get_mode_class (struct mode_data
*mode
)
1248 case MODE_PARTIAL_INT
:
1249 return "scalar_int_mode";
1255 return "scalar_mode";
1258 case MODE_DECIMAL_FLOAT
:
1259 return "scalar_float_mode";
1261 case MODE_COMPLEX_INT
:
1262 case MODE_COMPLEX_FLOAT
:
1263 return "complex_mode";
1271 emit_insn_modes_h (void)
1274 struct mode_data
*m
, *first
, *last
;
1275 int n_int_n_ents
= 0;
1277 printf ("/* Generated automatically from machmode.def%s%s\n",
1278 HAVE_EXTRA_MODES
? " and " : "",
1284 #ifndef GCC_INSN_MODES_H\n\
1285 #define GCC_INSN_MODES_H\n\
1287 enum machine_mode\n{");
1289 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1290 for (m
= modes
[c
]; m
; m
= m
->next
)
1292 int count_
= printf (" E_%smode,", m
->name
);
1293 printf ("%*s/* %s:%d */\n", 27 - count_
, "",
1294 trim_filename (m
->file
), m
->line
);
1295 printf ("#define HAVE_%smode\n", m
->name
);
1296 printf ("#ifdef USE_ENUM_MODES\n");
1297 printf ("#define %smode E_%smode\n", m
->name
, m
->name
);
1299 if (const char *mode_class
= get_mode_class (m
))
1300 printf ("#define %smode (%s ((%s::from_int) E_%smode))\n",
1301 m
->name
, mode_class
, mode_class
, m
->name
);
1303 printf ("#define %smode ((void) 0, E_%smode)\n",
1305 printf ("#endif\n");
1308 puts (" MAX_MACHINE_MODE,\n");
1310 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1314 for (m
= first
; m
; last
= m
, m
= m
->next
)
1317 /* Don't use BImode for MIN_MODE_INT, since otherwise the middle
1318 end will try to use it for bitfields in structures and the
1319 like, which we do not want. Only the target md file should
1320 generate BImode widgets. Since some targets such as ARM/MVE
1321 define boolean modes with multiple bits, handle those too. */
1322 if (first
&& first
->boolean
)
1324 struct mode_data
*last_bool
= first
;
1325 printf (" MIN_MODE_BOOL = E_%smode,\n", first
->name
);
1327 while (first
&& first
->boolean
)
1330 first
= first
->next
;
1333 printf (" MAX_MODE_BOOL = E_%smode,\n\n", last_bool
->name
);
1337 printf (" MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n",
1338 mode_class_names
[c
], first
->name
,
1339 mode_class_names
[c
], last
->name
);
1341 printf (" MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n",
1342 mode_class_names
[c
], void_mode
->name
,
1343 mode_class_names
[c
], void_mode
->name
);
1347 NUM_MACHINE_MODES = MAX_MACHINE_MODE\n\
1350 /* Define a NUM_* macro for each mode class, giving the number of modes
1352 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1354 printf ("#define NUM_%s ", mode_class_names
[c
]);
1356 printf ("(MAX_%s - MIN_%s + 1)\n", mode_class_names
[c
],
1357 mode_class_names
[c
]);
1363 /* I can't think of a better idea, can you? */
1364 printf ("#define CONST_MODE_NUNITS%s\n", adj_nunits
? "" : " const");
1365 printf ("#define CONST_MODE_PRECISION%s\n", adj_nunits
? "" : " const");
1366 printf ("#define CONST_MODE_SIZE%s\n",
1367 adj_bytesize
|| adj_nunits
? "" : " const");
1368 printf ("#define CONST_MODE_UNIT_SIZE%s\n", adj_bytesize
? "" : " const");
1369 printf ("#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment
? "" : " const");
1370 #if 0 /* disabled for backward compatibility, temporary */
1371 printf ("#define CONST_REAL_FORMAT_FOR_MODE%s\n", adj_format
? "" :" const");
1373 printf ("#define CONST_MODE_IBIT%s\n", adj_ibit
? "" : " const");
1374 printf ("#define CONST_MODE_FBIT%s\n", adj_fbit
? "" : " const");
1375 printf ("#define CONST_MODE_MASK%s\n", adj_nunits
? "" : " const");
1378 for_all_modes (c
, m
)
1382 printf ("#define NUM_INT_N_ENTS %d\n", n_int_n_ents
);
1384 printf ("#define NUM_POLY_INT_COEFFS %d\n", NUM_POLY_INT_COEFFS
);
1388 #endif /* insn-modes.h */");
1392 emit_insn_modes_inline_h (void)
1394 printf ("/* Generated automatically from machmode.def%s%s\n",
1395 HAVE_EXTRA_MODES
? " and " : "",
1401 #ifndef GCC_INSN_MODES_INLINE_H\n\
1402 #define GCC_INSN_MODES_INLINE_H");
1404 puts ("\n#if !defined (USED_FOR_TARGET) && GCC_VERSION >= 4001\n");
1405 emit_mode_size_inline ();
1406 emit_mode_nunits_inline ();
1407 emit_mode_inner_inline ();
1408 emit_mode_unit_size_inline ();
1409 emit_mode_unit_precision_inline ();
1410 puts ("#endif /* GCC_VERSION >= 4001 */");
1414 #endif /* insn-modes-inline.h */");
1418 emit_insn_modes_c_header (void)
1420 printf ("/* Generated automatically from machmode.def%s%s\n",
1421 HAVE_EXTRA_MODES
? " and " : "",
1427 #include \"config.h\"\n\
1428 #include \"system.h\"\n\
1429 #include \"coretypes.h\"\n\
1430 #include \"tm.h\"\n\
1431 #include \"real.h\"");
1435 emit_min_insn_modes_c_header (void)
1437 printf ("/* Generated automatically from machmode.def%s%s\n",
1438 HAVE_EXTRA_MODES
? " and " : "",
1444 #include \"bconfig.h\"\n\
1445 #include \"system.h\"\n\
1446 #include \"coretypes.h\"");
1450 emit_mode_name (void)
1453 struct mode_data
*m
;
1455 print_decl ("char *const", "mode_name", "NUM_MACHINE_MODES");
1457 for_all_modes (c
, m
)
1458 printf (" \"%s\",\n", m
->name
);
1464 emit_mode_class (void)
1467 struct mode_data
*m
;
1469 print_decl ("unsigned char", "mode_class", "NUM_MACHINE_MODES");
1471 for_all_modes (c
, m
)
1472 tagged_printf ("%s", mode_class_names
[m
->cl
], m
->name
);
1478 emit_mode_precision (void)
1481 struct mode_data
*m
;
1483 print_maybe_const_decl ("%spoly_uint16", "mode_precision",
1484 "NUM_MACHINE_MODES", adj_nunits
);
1486 for_all_modes (c
, m
)
1487 if (m
->precision
!= (unsigned int)-1)
1488 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->precision
, m
->name
);
1490 tagged_printf ("{ %u * BITS_PER_UNIT" ZERO_COEFFS
" }",
1491 m
->bytesize
, m
->name
);
1497 emit_mode_size (void)
1500 struct mode_data
*m
;
1502 print_maybe_const_decl ("%spoly_uint16", "mode_size",
1503 "NUM_MACHINE_MODES", adj_nunits
|| adj_bytesize
);
1505 for_all_modes (c
, m
)
1506 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->bytesize
, m
->name
);
1512 emit_mode_nunits (void)
1515 struct mode_data
*m
;
1517 print_maybe_const_decl ("%spoly_uint16", "mode_nunits",
1518 "NUM_MACHINE_MODES", adj_nunits
);
1520 for_all_modes (c
, m
)
1521 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->ncomponents
, m
->name
);
1527 emit_mode_wider (void)
1530 struct mode_data
*m
;
1532 print_decl ("unsigned short", "mode_next", "NUM_MACHINE_MODES");
1534 for_all_modes (c
, m
)
1535 tagged_printf ("E_%smode",
1536 m
->wider
? m
->wider
->name
: void_mode
->name
,
1540 print_decl ("unsigned short", "mode_wider", "NUM_MACHINE_MODES");
1542 for_all_modes (c
, m
)
1544 struct mode_data
*m2
= 0;
1546 if (m
->cl
== MODE_INT
1547 || m
->cl
== MODE_PARTIAL_INT
1548 || m
->cl
== MODE_FLOAT
1549 || m
->cl
== MODE_DECIMAL_FLOAT
1550 || m
->cl
== MODE_COMPLEX_FLOAT
1551 || m
->cl
== MODE_FRACT
1552 || m
->cl
== MODE_UFRACT
1553 || m
->cl
== MODE_ACCUM
1554 || m
->cl
== MODE_UACCUM
)
1555 for (m2
= m
->wider
; m2
&& m2
!= void_mode
; m2
= m2
->wider
)
1557 if (m2
->bytesize
== m
->bytesize
1558 && m2
->precision
== m
->precision
)
1563 if (m2
== void_mode
)
1565 tagged_printf ("E_%smode",
1566 m2
? m2
->name
: void_mode
->name
,
1571 print_decl ("unsigned short", "mode_2xwider", "NUM_MACHINE_MODES");
1573 for_all_modes (c
, m
)
1575 struct mode_data
* m2
;
1578 m2
&& m2
!= void_mode
;
1581 if (m2
->bytesize
< 2 * m
->bytesize
)
1583 if (m
->precision
!= (unsigned int) -1)
1585 if (m2
->precision
!= 2 * m
->precision
)
1590 if (m2
->precision
!= (unsigned int) -1)
1594 /* For vectors we want twice the number of components,
1595 with the same element type. */
1596 if (m
->cl
== MODE_VECTOR_BOOL
1597 || m
->cl
== MODE_VECTOR_INT
1598 || m
->cl
== MODE_VECTOR_FLOAT
1599 || m
->cl
== MODE_VECTOR_FRACT
1600 || m
->cl
== MODE_VECTOR_UFRACT
1601 || m
->cl
== MODE_VECTOR_ACCUM
1602 || m
->cl
== MODE_VECTOR_UACCUM
)
1604 if (m2
->ncomponents
!= 2 * m
->ncomponents
)
1606 if (m
->component
!= m2
->component
)
1612 if (m2
== void_mode
)
1614 tagged_printf ("E_%smode",
1615 m2
? m2
->name
: void_mode
->name
,
1623 emit_mode_complex (void)
1626 struct mode_data
*m
;
1628 print_decl ("unsigned short", "mode_complex", "NUM_MACHINE_MODES");
1630 for_all_modes (c
, m
)
1631 tagged_printf ("E_%smode",
1632 m
->complex ? m
->complex->name
: void_mode
->name
,
1639 emit_mode_mask (void)
1642 struct mode_data
*m
;
1644 print_maybe_const_decl ("%sunsigned HOST_WIDE_INT", "mode_mask_array",
1645 "NUM_MACHINE_MODES", adj_nunits
);
1647 #define MODE_MASK(m) \\\n\
1648 ((m) >= HOST_BITS_PER_WIDE_INT) \\\n\
1649 ? HOST_WIDE_INT_M1U \\\n\
1650 : (HOST_WIDE_INT_1U << (m)) - 1\n");
1652 for_all_modes (c
, m
)
1653 if (m
->precision
!= (unsigned int)-1)
1654 tagged_printf ("MODE_MASK (%u)", m
->precision
, m
->name
);
1656 tagged_printf ("MODE_MASK (%u*BITS_PER_UNIT)", m
->bytesize
, m
->name
);
1658 puts ("#undef MODE_MASK");
1663 emit_mode_inner (void)
1666 struct mode_data
*m
;
1668 print_decl ("unsigned short", "mode_inner", "NUM_MACHINE_MODES");
1670 for_all_modes (c
, m
)
1671 tagged_printf ("E_%smode",
1672 c
!= MODE_PARTIAL_INT
&& m
->component
1673 ? m
->component
->name
: m
->name
,
1679 /* Emit mode_unit_size array into insn-modes.cc file. */
1681 emit_mode_unit_size (void)
1684 struct mode_data
*m
;
1686 print_maybe_const_decl ("%sunsigned char", "mode_unit_size",
1687 "NUM_MACHINE_MODES", adj_bytesize
);
1689 for_all_modes (c
, m
)
1690 tagged_printf ("%u",
1691 c
!= MODE_PARTIAL_INT
&& m
->component
1692 ? m
->component
->bytesize
: m
->bytesize
, m
->name
);
1697 /* Emit mode_unit_precision array into insn-modes.cc file. */
1699 emit_mode_unit_precision (void)
1702 struct mode_data
*m
;
1704 print_decl ("unsigned short", "mode_unit_precision", "NUM_MACHINE_MODES");
1706 for_all_modes (c
, m
)
1708 struct mode_data
*m2
= (c
!= MODE_PARTIAL_INT
&& m
->component
) ?
1710 if (m2
->precision
!= (unsigned int)-1)
1711 tagged_printf ("%u", m2
->precision
, m
->name
);
1713 tagged_printf ("%u*BITS_PER_UNIT", m2
->bytesize
, m
->name
);
1721 emit_mode_base_align (void)
1724 struct mode_data
*m
;
1726 print_maybe_const_decl ("%sunsigned short",
1727 "mode_base_align", "NUM_MACHINE_MODES",
1730 for_all_modes (c
, m
)
1731 tagged_printf ("%u", m
->alignment
, m
->name
);
1737 emit_class_narrowest_mode (void)
1741 print_decl ("unsigned short", "class_narrowest_mode", "MAX_MODE_CLASS");
1743 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1745 /* Bleah, all this to get the comment right for MIN_MODE_INT. */
1746 struct mode_data
*m
= modes
[c
];
1747 while (m
&& m
->boolean
)
1749 const char *comment_name
= (m
? m
: void_mode
)->name
;
1751 tagged_printf ("MIN_%s", mode_class_names
[c
], comment_name
);
1758 emit_real_format_for_mode (void)
1760 struct mode_data
*m
;
1762 /* The entities pointed to by this table are constant, whether
1763 or not the table itself is constant.
1765 For backward compatibility this table is always writable
1766 (several targets modify it in TARGET_OPTION_OVERRIDE). FIXME:
1767 convert all said targets to use ADJUST_FORMAT instead. */
1769 print_maybe_const_decl ("const struct real_format *%s",
1770 "real_format_for_mode",
1771 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1",
1774 print_decl ("struct real_format *\n", "real_format_for_mode",
1775 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1 "
1776 "+ MAX_MODE_DECIMAL_FLOAT - MIN_MODE_DECIMAL_FLOAT + 1");
1779 /* The beginning of the table is entries for float modes. */
1780 for (m
= modes
[MODE_FLOAT
]; m
; m
= m
->next
)
1781 if (!strcmp (m
->format
, "0"))
1782 tagged_printf ("%s", m
->format
, m
->name
);
1784 tagged_printf ("&%s", m
->format
, m
->name
);
1786 /* The end of the table is entries for decimal float modes. */
1787 for (m
= modes
[MODE_DECIMAL_FLOAT
]; m
; m
= m
->next
)
1788 if (!strcmp (m
->format
, "0"))
1789 tagged_printf ("%s", m
->format
, m
->name
);
1791 tagged_printf ("&%s", m
->format
, m
->name
);
1797 emit_mode_adjustments (void)
1800 struct mode_adjust
*a
;
1801 struct mode_data
*m
;
1806 "adjust_mode_mask (machine_mode mode)\n"
1808 " unsigned int precision;\n"
1809 " if (GET_MODE_PRECISION (mode).is_constant (&precision)\n"
1810 " && precision < HOST_BITS_PER_WIDE_INT)\n"
1811 " mode_mask_array[mode] = (HOST_WIDE_INT_1U << precision) - 1;"
1814 " mode_mask_array[mode] = HOST_WIDE_INT_M1U;\n"
1819 \ninit_adjust_machine_modes (void)\
1821 \n poly_uint16 ps ATTRIBUTE_UNUSED;\n\
1822 size_t s ATTRIBUTE_UNUSED;");
1824 for (a
= adj_nunits
; a
; a
= a
->next
)
1829 " /* %s:%d */\n ps = %s;\n",
1830 a
->file
, a
->line
, a
->adjustment
);
1831 printf (" int old_factor = vector_element_size"
1832 " (mode_precision[E_%smode], mode_nunits[E_%smode]);\n",
1834 printf (" mode_precision[E_%smode] = ps * old_factor;\n", m
->name
);
1835 printf (" if (!multiple_p (mode_precision[E_%smode],"
1836 " BITS_PER_UNIT, &mode_size[E_%smode]))\n", m
->name
, m
->name
);
1837 printf (" mode_size[E_%smode] = -1;\n", m
->name
);
1838 printf (" mode_nunits[E_%smode] = ps;\n", m
->name
);
1839 printf (" adjust_mode_mask (E_%smode);\n", m
->name
);
1843 /* Size adjustments must be propagated to all containing modes.
1844 A size adjustment forces us to recalculate the alignment too. */
1845 for (a
= adj_bytesize
; a
; a
= a
->next
)
1847 printf ("\n /* %s:%d */\n", a
->file
, a
->line
);
1848 switch (a
->mode
->cl
)
1850 case MODE_VECTOR_BOOL
:
1851 case MODE_VECTOR_INT
:
1852 case MODE_VECTOR_FLOAT
:
1853 case MODE_VECTOR_FRACT
:
1854 case MODE_VECTOR_UFRACT
:
1855 case MODE_VECTOR_ACCUM
:
1856 case MODE_VECTOR_UACCUM
:
1857 printf (" ps = %s;\n", a
->adjustment
);
1858 printf (" s = mode_unit_size[E_%smode];\n", a
->mode
->name
);
1862 printf (" ps = s = %s;\n", a
->adjustment
);
1863 printf (" mode_unit_size[E_%smode] = s;\n", a
->mode
->name
);
1866 printf (" mode_size[E_%smode] = ps;\n", a
->mode
->name
);
1867 printf (" mode_base_align[E_%smode] = known_alignment (ps);\n",
1870 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1874 case MODE_COMPLEX_INT
:
1875 case MODE_COMPLEX_FLOAT
:
1876 printf (" mode_size[E_%smode] = 2*s;\n", m
->name
);
1877 printf (" mode_unit_size[E_%smode] = s;\n", m
->name
);
1878 printf (" mode_base_align[E_%smode] = s & (~s + 1);\n",
1882 case MODE_VECTOR_BOOL
:
1883 /* Changes to BImode should not affect vector booleans. */
1886 case MODE_VECTOR_INT
:
1887 case MODE_VECTOR_FLOAT
:
1888 case MODE_VECTOR_FRACT
:
1889 case MODE_VECTOR_UFRACT
:
1890 case MODE_VECTOR_ACCUM
:
1891 case MODE_VECTOR_UACCUM
:
1892 printf (" mode_size[E_%smode] = %d * ps;\n",
1893 m
->name
, m
->ncomponents
);
1894 printf (" mode_unit_size[E_%smode] = s;\n", m
->name
);
1895 printf (" mode_base_align[E_%smode]"
1896 " = known_alignment (%d * ps);\n",
1897 m
->name
, m
->ncomponents
);
1902 "mode %s is neither vector nor complex but contains %s",
1903 m
->name
, a
->mode
->name
);
1909 /* Alignment adjustments propagate too.
1910 ??? This may not be the right thing for vector modes. */
1911 for (a
= adj_alignment
; a
; a
= a
->next
)
1913 printf ("\n /* %s:%d */\n s = %s;\n",
1914 a
->file
, a
->line
, a
->adjustment
);
1915 printf (" mode_base_align[E_%smode] = s;\n", a
->mode
->name
);
1917 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1921 case MODE_COMPLEX_INT
:
1922 case MODE_COMPLEX_FLOAT
:
1923 printf (" mode_base_align[E_%smode] = s;\n", m
->name
);
1926 case MODE_VECTOR_BOOL
:
1927 /* Changes to BImode should not affect vector booleans. */
1930 case MODE_VECTOR_INT
:
1931 case MODE_VECTOR_FLOAT
:
1932 case MODE_VECTOR_FRACT
:
1933 case MODE_VECTOR_UFRACT
:
1934 case MODE_VECTOR_ACCUM
:
1935 case MODE_VECTOR_UACCUM
:
1936 printf (" mode_base_align[E_%smode] = %d*s;\n",
1937 m
->name
, m
->ncomponents
);
1942 "mode %s is neither vector nor complex but contains %s",
1943 m
->name
, a
->mode
->name
);
1949 /* Ibit adjustments don't have to propagate. */
1950 for (a
= adj_ibit
; a
; a
= a
->next
)
1952 printf ("\n /* %s:%d */\n s = %s;\n",
1953 a
->file
, a
->line
, a
->adjustment
);
1954 printf (" mode_ibit[E_%smode] = s;\n", a
->mode
->name
);
1957 /* Fbit adjustments don't have to propagate. */
1958 for (a
= adj_fbit
; a
; a
= a
->next
)
1960 printf ("\n /* %s:%d */\n s = %s;\n",
1961 a
->file
, a
->line
, a
->adjustment
);
1962 printf (" mode_fbit[E_%smode] = s;\n", a
->mode
->name
);
1965 /* Real mode formats don't have to propagate anywhere. */
1966 for (a
= adj_format
; a
; a
= a
->next
)
1967 printf ("\n /* %s:%d */\n REAL_MODE_FORMAT (E_%smode) = %s;\n",
1968 a
->file
, a
->line
, a
->mode
->name
, a
->adjustment
);
1970 /* Adjust precision to the actual bits size. */
1971 for (a
= adj_precision
; a
; a
= a
->next
)
1972 switch (a
->mode
->cl
)
1974 case MODE_VECTOR_BOOL
:
1975 printf ("\n /* %s:%d. */\n ps = %s;\n", a
->file
, a
->line
,
1977 printf (" mode_precision[E_%smode] = ps;\n", a
->mode
->name
);
1980 internal_error ("invalid use of ADJUST_PRECISION for mode %s",
1985 /* Ensure there is no mode size equals -1. */
1986 for_all_modes (c
, m
)
1987 printf ("\n gcc_assert (maybe_ne (mode_size[E_%smode], -1));\n",
1993 /* Emit ibit for all modes. */
1996 emit_mode_ibit (void)
1999 struct mode_data
*m
;
2001 print_maybe_const_decl ("%sunsigned char",
2002 "mode_ibit", "NUM_MACHINE_MODES",
2005 for_all_modes (c
, m
)
2006 tagged_printf ("%u", m
->ibit
, m
->name
);
2011 /* Emit fbit for all modes. */
2014 emit_mode_fbit (void)
2017 struct mode_data
*m
;
2019 print_maybe_const_decl ("%sunsigned char",
2020 "mode_fbit", "NUM_MACHINE_MODES",
2023 for_all_modes (c
, m
)
2024 tagged_printf ("%u", m
->fbit
, m
->name
);
2029 /* Emit __intN for all modes. */
2032 emit_mode_int_n (void)
2035 struct mode_data
*m
;
2036 struct mode_data
**mode_sort
;
2040 print_decl ("int_n_data_t", "int_n_data", "");
2043 for_all_modes (c
, m
)
2046 mode_sort
= XALLOCAVEC (struct mode_data
*, n_modes
);
2049 for_all_modes (c
, m
)
2051 mode_sort
[n_modes
++] = m
;
2053 /* Yes, this is a bubblesort, but there are at most four (and
2054 usually only 1-2) entries to sort. */
2055 for (i
= 0; i
<n_modes
- 1; i
++)
2056 for (j
= i
+ 1; j
< n_modes
; j
++)
2057 if (mode_sort
[i
]->int_n
> mode_sort
[j
]->int_n
)
2058 std::swap (mode_sort
[i
], mode_sort
[j
]);
2060 for (i
= 0; i
< n_modes
; i
++)
2064 tagged_printf ("%u", m
->int_n
, m
->name
);
2065 printf ("{ E_%smode },", m
->name
);
2074 emit_insn_modes_c (void)
2076 emit_insn_modes_c_header ();
2079 emit_mode_precision ();
2081 emit_mode_nunits ();
2083 emit_mode_complex ();
2086 emit_mode_unit_size ();
2087 emit_mode_unit_precision ();
2088 emit_mode_base_align ();
2089 emit_class_narrowest_mode ();
2090 emit_real_format_for_mode ();
2091 emit_mode_adjustments ();
2098 emit_min_insn_modes_c (void)
2100 emit_min_insn_modes_c_header ();
2103 emit_mode_nunits ();
2106 emit_class_narrowest_mode ();
2109 /* Master control. */
2111 main (int argc
, char **argv
)
2113 bool gen_header
= false, gen_inlines
= false, gen_min
= false;
2118 else if (argc
== 2 && !strcmp (argv
[1], "-h"))
2120 else if (argc
== 2 && !strcmp (argv
[1], "-i"))
2122 else if (argc
== 2 && !strcmp (argv
[1], "-m"))
2126 error ("usage: %s [-h|-i|-m] > file", progname
);
2127 return FATAL_EXIT_CODE
;
2130 modes_by_name
= htab_create_alloc (64, hash_mode
, eq_mode
, 0, xcalloc
, free
);
2133 complete_all_modes ();
2136 return FATAL_EXIT_CODE
;
2141 emit_insn_modes_h ();
2142 else if (gen_inlines
)
2143 emit_insn_modes_inline_h ();
2145 emit_min_insn_modes_c ();
2147 emit_insn_modes_c ();
2149 if (fflush (stdout
) || fclose (stdout
))
2150 return FATAL_EXIT_CODE
;
2151 return SUCCESS_EXIT_CODE
;