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_FLOAT
: return MODE_COMPLEX_FLOAT
;
124 error ("no complex class for class %s", mode_class_names
[c
]);
129 static enum mode_class
130 vector_class (enum mode_class cl
)
134 case MODE_INT
: return MODE_VECTOR_INT
;
135 case MODE_FLOAT
: return MODE_VECTOR_FLOAT
;
136 case MODE_FRACT
: return MODE_VECTOR_FRACT
;
137 case MODE_UFRACT
: return MODE_VECTOR_UFRACT
;
138 case MODE_ACCUM
: return MODE_VECTOR_ACCUM
;
139 case MODE_UACCUM
: return MODE_VECTOR_UACCUM
;
141 error ("no vector class for class %s", mode_class_names
[cl
]);
146 /* Utility routines. */
147 static inline struct mode_data
*
148 find_mode (const char *name
)
150 struct mode_data key
;
153 return (struct mode_data
*) htab_find (modes_by_name
, &key
);
156 static struct mode_data
*
157 new_mode (enum mode_class cl
, const char *name
,
158 const char *file
, unsigned int line
)
161 static unsigned int count
= 0;
163 m
= find_mode (name
);
166 error ("%s:%d: duplicate definition of mode \"%s\"",
167 trim_filename (file
), line
, name
);
168 error ("%s:%d: previous definition here", m
->file
, m
->line
);
172 m
= XNEW (struct mode_data
);
173 memcpy (m
, &blank_mode
, sizeof (struct mode_data
));
177 m
->file
= trim_filename (file
);
179 m
->counter
= count
++;
185 *htab_find_slot (modes_by_name
, m
, INSERT
) = m
;
191 hash_mode (const void *p
)
193 const struct mode_data
*m
= (const struct mode_data
*)p
;
194 return htab_hash_string (m
->name
);
198 eq_mode (const void *p
, const void *q
)
200 const struct mode_data
*a
= (const struct mode_data
*)p
;
201 const struct mode_data
*b
= (const struct mode_data
*)q
;
203 return !strcmp (a
->name
, b
->name
);
206 #define for_all_modes(C, M) \
207 for (C = 0; C < MAX_MODE_CLASS; C++) \
208 for (M = modes[C]; M; M = M->next)
210 static void ATTRIBUTE_UNUSED
211 new_adjust (const char *name
,
212 struct mode_adjust
**category
, const char *catname
,
213 const char *adjustment
,
214 enum mode_class required_class_from
,
215 enum mode_class required_class_to
,
216 const char *file
, unsigned int line
)
218 struct mode_data
*mode
= find_mode (name
);
219 struct mode_adjust
*a
;
221 file
= trim_filename (file
);
225 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
229 if (required_class_from
!= MODE_RANDOM
230 && (mode
->cl
< required_class_from
|| mode
->cl
> required_class_to
))
232 error ("%s:%d: mode \"%s\" is not among class {%s, %s}",
233 file
, line
, name
, mode_class_names
[required_class_from
] + 5,
234 mode_class_names
[required_class_to
] + 5);
238 for (a
= *category
; a
; a
= a
->next
)
241 error ("%s:%d: mode \"%s\" already has a %s adjustment",
242 file
, line
, name
, catname
);
243 error ("%s:%d: previous adjustment here", a
->file
, a
->line
);
247 a
= XNEW (struct mode_adjust
);
249 a
->adjustment
= adjustment
;
257 /* Diagnose failure to meet expectations in a partially filled out
259 enum requirement
{ SET
, UNSET
, OPTIONAL
};
261 #define validate_field_(mname, fname, req, val, unset, file, line) do { \
266 error ("%s:%d: (%s) field %s must be set", \
267 file, line, mname, fname); \
271 error ("%s:%d: (%s) field %s must not be set", \
272 file, line, mname, fname); \
278 #define validate_field(M, F) \
279 validate_field_(M->name, #F, r_##F, M->F, blank_mode.F, M->file, M->line)
282 validate_mode (struct mode_data
*m
,
283 enum requirement r_precision
,
284 enum requirement r_bytesize
,
285 enum requirement r_component
,
286 enum requirement r_ncomponents
,
287 enum requirement r_format
)
289 validate_field (m
, precision
);
290 validate_field (m
, bytesize
);
291 validate_field (m
, component
);
292 validate_field (m
, ncomponents
);
293 validate_field (m
, format
);
295 #undef validate_field
296 #undef validate_field_
298 /* Given a partially-filled-out mode structure, figure out what we can
299 and fill the rest of it in; die if it isn't enough. */
301 complete_mode (struct mode_data
*m
)
303 unsigned int alignment
;
307 error ("%s:%d: mode with no name", m
->file
, m
->line
);
310 if (m
->cl
== MAX_MODE_CLASS
)
312 error ("%s:%d: %smode has no mode class", m
->file
, m
->line
, m
->name
);
319 /* Nothing more need be said. */
320 if (!strcmp (m
->name
, "VOID"))
323 validate_mode (m
, UNSET
, UNSET
, UNSET
, UNSET
, UNSET
);
332 /* Again, nothing more need be said. For historical reasons,
333 the size of a CC mode is four units. */
334 validate_mode (m
, UNSET
, UNSET
, UNSET
, UNSET
, UNSET
);
342 case MODE_POINTER_BOUNDS
:
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 POINTER_BOUNDS_MODE(N, Y) \
575 make_pointer_bounds_mode (#N, Y, __FILE__, __LINE__)
577 static void ATTRIBUTE_UNUSED
578 make_pointer_bounds_mode (const char *name
,
579 unsigned int bytesize
,
580 const char *file
, unsigned int line
)
582 struct mode_data
*m
= new_mode (MODE_POINTER_BOUNDS
, name
, file
, line
);
583 m
->bytesize
= bytesize
;
587 #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y)
588 #define FRACTIONAL_INT_MODE(N, B, Y) \
589 make_int_mode (#N, B, Y, __FILE__, __LINE__)
592 make_int_mode (const char *name
,
593 unsigned int precision
, unsigned int bytesize
,
594 const char *file
, unsigned int line
)
596 struct mode_data
*m
= new_mode (MODE_INT
, name
, file
, line
);
597 m
->bytesize
= bytesize
;
598 m
->precision
= precision
;
601 #define FRACT_MODE(N, Y, F) \
602 make_fixed_point_mode (MODE_FRACT, #N, Y, 0, F, __FILE__, __LINE__)
604 #define UFRACT_MODE(N, Y, F) \
605 make_fixed_point_mode (MODE_UFRACT, #N, Y, 0, F, __FILE__, __LINE__)
607 #define ACCUM_MODE(N, Y, I, F) \
608 make_fixed_point_mode (MODE_ACCUM, #N, Y, I, F, __FILE__, __LINE__)
610 #define UACCUM_MODE(N, Y, I, F) \
611 make_fixed_point_mode (MODE_UACCUM, #N, Y, I, F, __FILE__, __LINE__)
613 /* Create a fixed-point mode by setting CL, NAME, BYTESIZE, IBIT, FBIT,
617 make_fixed_point_mode (enum mode_class cl
,
619 unsigned int bytesize
,
622 const char *file
, unsigned int line
)
624 struct mode_data
*m
= new_mode (cl
, name
, file
, line
);
625 m
->bytesize
= bytesize
;
630 #define FLOAT_MODE(N, Y, F) FRACTIONAL_FLOAT_MODE (N, -1U, Y, F)
631 #define FRACTIONAL_FLOAT_MODE(N, B, Y, F) \
632 make_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
635 make_float_mode (const char *name
,
636 unsigned int precision
, unsigned int bytesize
,
638 const char *file
, unsigned int line
)
640 struct mode_data
*m
= new_mode (MODE_FLOAT
, name
, file
, line
);
641 m
->bytesize
= bytesize
;
642 m
->precision
= precision
;
646 #define DECIMAL_FLOAT_MODE(N, Y, F) \
647 FRACTIONAL_DECIMAL_FLOAT_MODE (N, -1U, Y, F)
648 #define FRACTIONAL_DECIMAL_FLOAT_MODE(N, B, Y, F) \
649 make_decimal_float_mode (#N, B, Y, #F, __FILE__, __LINE__)
652 make_decimal_float_mode (const char *name
,
653 unsigned int precision
, unsigned int bytesize
,
655 const char *file
, unsigned int line
)
657 struct mode_data
*m
= new_mode (MODE_DECIMAL_FLOAT
, name
, file
, line
);
658 m
->bytesize
= bytesize
;
659 m
->precision
= precision
;
663 #define RESET_FLOAT_FORMAT(N, F) \
664 reset_float_format (#N, #F, __FILE__, __LINE__)
665 static void ATTRIBUTE_UNUSED
666 reset_float_format (const char *name
, const char *format
,
667 const char *file
, unsigned int line
)
669 struct mode_data
*m
= find_mode (name
);
672 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
675 if (m
->cl
!= MODE_FLOAT
&& m
->cl
!= MODE_DECIMAL_FLOAT
)
677 error ("%s:%d: mode \"%s\" is not a FLOAT class", file
, line
, name
);
683 /* __intN support. */
684 #define INT_N(M,PREC) \
685 make_int_n (#M, PREC, __FILE__, __LINE__)
686 static void ATTRIBUTE_UNUSED
687 make_int_n (const char *m
, int bitsize
,
688 const char *file
, unsigned int line
)
690 struct mode_data
*component
= find_mode (m
);
693 error ("%s:%d: no mode \"%s\"", file
, line
, m
);
696 if (component
->cl
!= MODE_INT
697 && component
->cl
!= MODE_PARTIAL_INT
)
699 error ("%s:%d: mode \"%s\" is not class INT or PARTIAL_INT", file
, line
, m
);
702 if (component
->int_n
!= 0)
704 error ("%s:%d: mode \"%s\" already has an intN", file
, line
, m
);
708 component
->int_n
= bitsize
;
711 /* Partial integer modes are specified by relation to a full integer
713 #define PARTIAL_INT_MODE(M,PREC,NAME) \
714 make_partial_integer_mode (#M, #NAME, PREC, __FILE__, __LINE__)
715 static void ATTRIBUTE_UNUSED
716 make_partial_integer_mode (const char *base
, const char *name
,
717 unsigned int precision
,
718 const char *file
, unsigned int line
)
721 struct mode_data
*component
= find_mode (base
);
724 error ("%s:%d: no mode \"%s\"", file
, line
, name
);
727 if (component
->cl
!= MODE_INT
)
729 error ("%s:%d: mode \"%s\" is not class INT", file
, line
, name
);
733 m
= new_mode (MODE_PARTIAL_INT
, name
, file
, line
);
734 m
->precision
= precision
;
735 m
->component
= component
;
738 /* A single vector mode can be specified by naming its component
739 mode and the number of components. */
740 #define VECTOR_MODE(C, M, N) \
741 make_vector_mode (MODE_##C, #M, N, __FILE__, __LINE__);
742 static void ATTRIBUTE_UNUSED
743 make_vector_mode (enum mode_class bclass
,
745 unsigned int ncomponents
,
746 const char *file
, unsigned int line
)
749 enum mode_class vclass
= vector_class (bclass
);
750 struct mode_data
*component
= find_mode (base
);
753 if (vclass
== MODE_RANDOM
)
757 error ("%s:%d: no mode \"%s\"", file
, line
, base
);
760 if (component
->cl
!= bclass
761 && (component
->cl
!= MODE_PARTIAL_INT
762 || bclass
!= MODE_INT
))
764 error ("%s:%d: mode \"%s\" is not class %s",
765 file
, line
, base
, mode_class_names
[bclass
] + 5);
769 if ((size_t)snprintf (namebuf
, sizeof namebuf
, "V%u%s",
770 ncomponents
, base
) >= sizeof namebuf
)
772 error ("%s:%d: mode name \"%s\" is too long",
777 v
= new_mode (vclass
, xstrdup (namebuf
), file
, line
);
778 v
->ncomponents
= ncomponents
;
779 v
->component
= component
;
783 #define _ADD_ADJUST(A, M, X, C1, C2) \
784 new_adjust (#M, &adj_##A, #A, #X, MODE_##C1, MODE_##C2, __FILE__, __LINE__)
786 #define ADJUST_NUNITS(M, X) _ADD_ADJUST (nunits, M, X, RANDOM, RANDOM)
787 #define ADJUST_BYTESIZE(M, X) _ADD_ADJUST (bytesize, M, X, RANDOM, RANDOM)
788 #define ADJUST_ALIGNMENT(M, X) _ADD_ADJUST (alignment, M, X, RANDOM, RANDOM)
789 #define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST (format, M, X, FLOAT, FLOAT)
790 #define ADJUST_IBIT(M, X) _ADD_ADJUST (ibit, M, X, ACCUM, UACCUM)
791 #define ADJUST_FBIT(M, X) _ADD_ADJUST (fbit, M, X, FRACT, UACCUM)
793 static int bits_per_unit
;
794 static int max_bitsize_mode_any_int
;
795 static int max_bitsize_mode_any_mode
;
800 #include "machmode.def"
802 /* So put the default value unless the target needs a non standard
805 bits_per_unit
= BITS_PER_UNIT
;
810 #ifdef MAX_BITSIZE_MODE_ANY_INT
811 max_bitsize_mode_any_int
= MAX_BITSIZE_MODE_ANY_INT
;
813 max_bitsize_mode_any_int
= 0;
816 #ifdef MAX_BITSIZE_MODE_ANY_MODE
817 max_bitsize_mode_any_mode
= MAX_BITSIZE_MODE_ANY_MODE
;
819 max_bitsize_mode_any_mode
= 0;
823 #ifndef NUM_POLY_INT_COEFFS
824 #define NUM_POLY_INT_COEFFS 1
829 /* Sort a list of modes into the order needed for the WIDER field:
830 major sort by precision, minor sort by component precision.
833 QI < HI < SI < DI < TI
834 V4QI < V2HI < V8QI < V4HI < V2SI.
836 If the precision is not set, sort by the bytesize. A mode with
837 precision set gets sorted before a mode without precision set, if
838 they have the same bytesize; this is the right thing because
839 the precision must always be smaller than the bytesize * BITS_PER_UNIT.
840 We don't have to do anything special to get this done -- an unset
841 precision shows up as (unsigned int)-1, i.e. UINT_MAX. */
843 cmp_modes (const void *a
, const void *b
)
845 const struct mode_data
*const m
= *(const struct mode_data
*const*)a
;
846 const struct mode_data
*const n
= *(const struct mode_data
*const*)b
;
848 if (m
->bytesize
> n
->bytesize
)
850 else if (m
->bytesize
< n
->bytesize
)
853 if (m
->precision
> n
->precision
)
855 else if (m
->precision
< n
->precision
)
858 if (!m
->component
&& !n
->component
)
860 if (m
->counter
< n
->counter
)
866 if (m
->component
->bytesize
> n
->component
->bytesize
)
868 else if (m
->component
->bytesize
< n
->component
->bytesize
)
871 if (m
->component
->precision
> n
->component
->precision
)
873 else if (m
->component
->precision
< n
->component
->precision
)
876 if (m
->counter
< n
->counter
)
883 calc_wider_mode (void)
887 struct mode_data
**sortbuf
;
888 unsigned int max_n_modes
= 0;
891 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
892 max_n_modes
= MAX (max_n_modes
, n_modes
[c
]);
894 /* Allocate max_n_modes + 1 entries to leave room for the extra null
895 pointer assigned after the qsort call below. */
896 sortbuf
= XALLOCAVEC (struct mode_data
*, max_n_modes
+ 1);
898 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
900 /* "wider" is not meaningful for MODE_RANDOM and MODE_CC.
901 However, we want these in textual order, and we have
902 precisely the reverse. */
903 if (c
== MODE_RANDOM
|| c
== MODE_CC
)
905 struct mode_data
*prev
, *next
;
907 for (prev
= 0, m
= modes
[c
]; m
; m
= next
)
909 m
->wider
= void_mode
;
911 /* this is nreverse */
923 for (i
= 0, m
= modes
[c
]; m
; i
++, m
= m
->next
)
926 (qsort
) (sortbuf
, i
, sizeof (struct mode_data
*), cmp_modes
);
929 for (j
= 0; j
< i
; j
++)
931 sortbuf
[j
]->next
= sortbuf
[j
+ 1];
932 if (c
== MODE_PARTIAL_INT
)
933 sortbuf
[j
]->wider
= sortbuf
[j
]->component
;
935 sortbuf
[j
]->wider
= sortbuf
[j
]->next
;
938 modes
[c
] = sortbuf
[0];
943 /* Text to add to the constant part of a poly_int_pod initializer in
944 order to fill out te whole structure. */
945 #if NUM_POLY_INT_COEFFS == 1
946 #define ZERO_COEFFS ""
947 #elif NUM_POLY_INT_COEFFS == 2
948 #define ZERO_COEFFS ", 0"
950 #error "Unknown value of NUM_POLY_INT_COEFFS"
953 /* Output routines. */
955 #define tagged_printf(FMT, ARG, TAG) do { \
956 int count_ = printf (" " FMT ",", ARG); \
957 printf ("%*s/* %s */\n", 27 - count_, "", TAG); \
960 #define print_decl(TYPE, NAME, ASIZE) \
961 puts ("\nconst " TYPE " " NAME "[" ASIZE "] =\n{");
963 #define print_maybe_const_decl(TYPE, NAME, ASIZE, NEEDS_ADJ) \
964 printf ("\n" TYPE " " NAME "[" ASIZE "] = \n{\n", \
965 NEEDS_ADJ ? "" : "const ")
967 #define print_closer() puts ("};")
969 /* Compute the max bitsize of some of the classes of integers. It may
970 be that there are needs for the other integer classes, and this
971 code is easy to extend. */
975 unsigned int max
, mmax
;
981 printf ("#define BITS_PER_UNIT (%d)\n", bits_per_unit
);
983 if (max_bitsize_mode_any_int
== 0)
985 for (max
= 1, i
= modes
[MODE_INT
]; i
; i
= i
->next
)
986 if (max
< i
->bytesize
)
989 for (max
= 1, i
= modes
[MODE_PARTIAL_INT
]; i
; i
= i
->next
)
990 if (max
< i
->bytesize
)
994 printf ("#define MAX_BITSIZE_MODE_ANY_INT (%d*BITS_PER_UNIT)\n", mmax
);
997 printf ("#define MAX_BITSIZE_MODE_ANY_INT %d\n", max_bitsize_mode_any_int
);
999 if (max_bitsize_mode_any_mode
== 0)
1002 for (j
= 0; j
< MAX_MODE_CLASS
; j
++)
1003 for (i
= modes
[j
]; i
; i
= i
->next
)
1004 if (mmax
< i
->bytesize
)
1006 printf ("#define MAX_BITSIZE_MODE_ANY_MODE (%d*BITS_PER_UNIT)\n", mmax
);
1009 printf ("#define MAX_BITSIZE_MODE_ANY_MODE %d\n",
1010 max_bitsize_mode_any_mode
);
1013 /* Emit mode_size_inline routine into insn-modes.h header. */
1015 emit_mode_size_inline (void)
1018 struct mode_adjust
*a
;
1019 struct mode_data
*m
;
1021 /* Size adjustments must be propagated to all containing modes. */
1022 for (a
= adj_bytesize
; a
; a
= a
->next
)
1024 a
->mode
->need_bytesize_adj
= true;
1025 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1026 m
->need_bytesize_adj
= true;
1029 /* Changing the number of units by a factor of X also changes the size
1030 by a factor of X. */
1031 for (mode_adjust
*a
= adj_nunits
; a
; a
= a
->next
)
1032 a
->mode
->need_bytesize_adj
= true;
1035 #ifdef __cplusplus\n\
1036 inline __attribute__((__always_inline__))\n\
1038 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1041 mode_size_inline (machine_mode mode)\n\
1043 extern %spoly_uint16_pod mode_size[NUM_MACHINE_MODES];\n\
1044 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1046 {\n", adj_nunits
|| adj_bytesize
? "" : "const ");
1048 for_all_modes (c
, m
)
1049 if (!m
->need_bytesize_adj
)
1050 printf (" case E_%smode: return %u;\n", m
->name
, m
->bytesize
);
1053 default: return mode_size[mode];\n\
1058 /* Emit mode_nunits_inline routine into insn-modes.h header. */
1060 emit_mode_nunits_inline (void)
1063 struct mode_data
*m
;
1065 for (mode_adjust
*a
= adj_nunits
; a
; a
= a
->next
)
1066 a
->mode
->need_nunits_adj
= true;
1069 #ifdef __cplusplus\n\
1070 inline __attribute__((__always_inline__))\n\
1072 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1075 mode_nunits_inline (machine_mode mode)\n\
1077 extern %spoly_uint16_pod mode_nunits[NUM_MACHINE_MODES];\n\
1079 {\n", adj_nunits
? "" : "const ");
1081 for_all_modes (c
, m
)
1082 if (!m
->need_nunits_adj
)
1083 printf (" case E_%smode: return %u;\n", m
->name
, m
->ncomponents
);
1086 default: return mode_nunits[mode];\n\
1091 /* Emit mode_inner_inline routine into insn-modes.h header. */
1093 emit_mode_inner_inline (void)
1096 struct mode_data
*m
;
1099 #ifdef __cplusplus\n\
1100 inline __attribute__((__always_inline__))\n\
1102 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1105 mode_inner_inline (machine_mode mode)\n\
1107 extern const unsigned char mode_inner[NUM_MACHINE_MODES];\n\
1108 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1112 for_all_modes (c
, m
)
1113 printf (" case E_%smode: return E_%smode;\n", m
->name
,
1114 c
!= MODE_PARTIAL_INT
&& m
->component
1115 ? m
->component
->name
: m
->name
);
1118 default: return mode_inner[mode];\n\
1123 /* Emit mode_unit_size_inline routine into insn-modes.h header. */
1125 emit_mode_unit_size_inline (void)
1128 struct mode_data
*m
;
1131 #ifdef __cplusplus\n\
1132 inline __attribute__((__always_inline__))\n\
1134 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1137 mode_unit_size_inline (machine_mode mode)\n\
1139 extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES];\
1141 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1145 for_all_modes (c
, m
)
1147 const char *name
= m
->name
;
1148 struct mode_data
*m2
= m
;
1149 if (c
!= MODE_PARTIAL_INT
&& m2
->component
)
1151 if (!m2
->need_bytesize_adj
)
1152 printf (" case E_%smode: return %u;\n", name
, m2
->bytesize
);
1156 default: return mode_unit_size[mode];\n\
1161 /* Emit mode_unit_precision_inline routine into insn-modes.h header. */
1163 emit_mode_unit_precision_inline (void)
1166 struct mode_data
*m
;
1169 #ifdef __cplusplus\n\
1170 inline __attribute__((__always_inline__))\n\
1172 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1175 mode_unit_precision_inline (machine_mode mode)\n\
1177 extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES];\n\
1178 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1182 for_all_modes (c
, m
)
1184 struct mode_data
*m2
1185 = (c
!= MODE_PARTIAL_INT
&& m
->component
) ? m
->component
: m
;
1186 if (m2
->precision
!= (unsigned int)-1)
1187 printf (" case E_%smode: return %u;\n", m
->name
, m2
->precision
);
1189 printf (" case E_%smode: return %u*BITS_PER_UNIT;\n",
1190 m
->name
, m2
->bytesize
);
1194 default: return mode_unit_precision[mode];\n\
1199 /* Return the best machine mode class for MODE, or null if machine_mode
1203 get_mode_class (struct mode_data
*mode
)
1208 case MODE_PARTIAL_INT
:
1209 return "scalar_int_mode";
1215 case MODE_POINTER_BOUNDS
:
1216 return "scalar_mode";
1219 case MODE_DECIMAL_FLOAT
:
1220 return "scalar_float_mode";
1222 case MODE_COMPLEX_INT
:
1223 case MODE_COMPLEX_FLOAT
:
1224 return "complex_mode";
1232 emit_insn_modes_h (void)
1235 struct mode_data
*m
, *first
, *last
;
1236 int n_int_n_ents
= 0;
1238 printf ("/* Generated automatically from machmode.def%s%s\n",
1239 HAVE_EXTRA_MODES
? " and " : "",
1245 #ifndef GCC_INSN_MODES_H\n\
1246 #define GCC_INSN_MODES_H\n\
1248 enum machine_mode\n{");
1250 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1251 for (m
= modes
[c
]; m
; m
= m
->next
)
1253 int count_
= printf (" E_%smode,", m
->name
);
1254 printf ("%*s/* %s:%d */\n", 27 - count_
, "",
1255 trim_filename (m
->file
), m
->line
);
1256 printf ("#define HAVE_%smode\n", m
->name
);
1257 printf ("#ifdef USE_ENUM_MODES\n");
1258 printf ("#define %smode E_%smode\n", m
->name
, m
->name
);
1260 if (const char *mode_class
= get_mode_class (m
))
1261 printf ("#define %smode (%s ((%s::from_int) E_%smode))\n",
1262 m
->name
, mode_class
, mode_class
, m
->name
);
1264 printf ("#define %smode ((void) 0, E_%smode)\n",
1266 printf ("#endif\n");
1269 puts (" MAX_MACHINE_MODE,\n");
1271 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1275 for (m
= first
; m
; last
= m
, m
= m
->next
)
1278 /* Don't use BImode for MIN_MODE_INT, since otherwise the middle
1279 end will try to use it for bitfields in structures and the
1280 like, which we do not want. Only the target md file should
1281 generate BImode widgets. */
1282 if (first
&& first
->precision
== 1 && c
== MODE_INT
)
1283 first
= first
->next
;
1286 printf (" MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n",
1287 mode_class_names
[c
], first
->name
,
1288 mode_class_names
[c
], last
->name
);
1290 printf (" MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n",
1291 mode_class_names
[c
], void_mode
->name
,
1292 mode_class_names
[c
], void_mode
->name
);
1296 NUM_MACHINE_MODES = MAX_MACHINE_MODE\n\
1299 /* I can't think of a better idea, can you? */
1300 printf ("#define CONST_MODE_NUNITS%s\n", adj_nunits
? "" : " const");
1301 printf ("#define CONST_MODE_PRECISION%s\n", adj_nunits
? "" : " const");
1302 printf ("#define CONST_MODE_SIZE%s\n",
1303 adj_bytesize
|| adj_nunits
? "" : " const");
1304 printf ("#define CONST_MODE_UNIT_SIZE%s\n", adj_bytesize
? "" : " const");
1305 printf ("#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment
? "" : " const");
1306 #if 0 /* disabled for backward compatibility, temporary */
1307 printf ("#define CONST_REAL_FORMAT_FOR_MODE%s\n", adj_format
? "" :" const");
1309 printf ("#define CONST_MODE_IBIT%s\n", adj_ibit
? "" : " const");
1310 printf ("#define CONST_MODE_FBIT%s\n", adj_fbit
? "" : " const");
1313 for_all_modes (c
, m
)
1317 printf ("#define NUM_INT_N_ENTS %d\n", n_int_n_ents
);
1319 printf ("#define NUM_POLY_INT_COEFFS %d\n", NUM_POLY_INT_COEFFS
);
1323 #endif /* insn-modes.h */");
1327 emit_insn_modes_inline_h (void)
1329 printf ("/* Generated automatically from machmode.def%s%s\n",
1330 HAVE_EXTRA_MODES
? " and " : "",
1336 #ifndef GCC_INSN_MODES_INLINE_H\n\
1337 #define GCC_INSN_MODES_INLINE_H");
1339 puts ("\n#if !defined (USED_FOR_TARGET) && GCC_VERSION >= 4001\n");
1340 emit_mode_size_inline ();
1341 emit_mode_nunits_inline ();
1342 emit_mode_inner_inline ();
1343 emit_mode_unit_size_inline ();
1344 emit_mode_unit_precision_inline ();
1345 puts ("#endif /* GCC_VERSION >= 4001 */");
1349 #endif /* insn-modes-inline.h */");
1353 emit_insn_modes_c_header (void)
1355 printf ("/* Generated automatically from machmode.def%s%s\n",
1356 HAVE_EXTRA_MODES
? " and " : "",
1362 #include \"config.h\"\n\
1363 #include \"system.h\"\n\
1364 #include \"coretypes.h\"\n\
1365 #include \"tm.h\"\n\
1366 #include \"real.h\"");
1370 emit_min_insn_modes_c_header (void)
1372 printf ("/* Generated automatically from machmode.def%s%s\n",
1373 HAVE_EXTRA_MODES
? " and " : "",
1379 #include \"bconfig.h\"\n\
1380 #include \"system.h\"\n\
1381 #include \"coretypes.h\"");
1385 emit_mode_name (void)
1388 struct mode_data
*m
;
1390 print_decl ("char *const", "mode_name", "NUM_MACHINE_MODES");
1392 for_all_modes (c
, m
)
1393 printf (" \"%s\",\n", m
->name
);
1399 emit_mode_class (void)
1402 struct mode_data
*m
;
1404 print_decl ("unsigned char", "mode_class", "NUM_MACHINE_MODES");
1406 for_all_modes (c
, m
)
1407 tagged_printf ("%s", mode_class_names
[m
->cl
], m
->name
);
1413 emit_mode_precision (void)
1416 struct mode_data
*m
;
1418 print_maybe_const_decl ("%spoly_uint16_pod", "mode_precision",
1419 "NUM_MACHINE_MODES", adj_nunits
);
1421 for_all_modes (c
, m
)
1422 if (m
->precision
!= (unsigned int)-1)
1423 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->precision
, m
->name
);
1425 tagged_printf ("{ %u * BITS_PER_UNIT" ZERO_COEFFS
" }",
1426 m
->bytesize
, m
->name
);
1432 emit_mode_size (void)
1435 struct mode_data
*m
;
1437 print_maybe_const_decl ("%spoly_uint16_pod", "mode_size",
1438 "NUM_MACHINE_MODES", adj_nunits
|| adj_bytesize
);
1440 for_all_modes (c
, m
)
1441 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->bytesize
, m
->name
);
1447 emit_mode_nunits (void)
1450 struct mode_data
*m
;
1452 print_maybe_const_decl ("%spoly_uint16_pod", "mode_nunits",
1453 "NUM_MACHINE_MODES", adj_nunits
);
1455 for_all_modes (c
, m
)
1456 tagged_printf ("{ %u" ZERO_COEFFS
" }", m
->ncomponents
, m
->name
);
1462 emit_mode_wider (void)
1465 struct mode_data
*m
;
1467 print_decl ("unsigned char", "mode_wider", "NUM_MACHINE_MODES");
1469 for_all_modes (c
, m
)
1470 tagged_printf ("E_%smode",
1471 m
->wider
? m
->wider
->name
: void_mode
->name
,
1475 print_decl ("unsigned char", "mode_2xwider", "NUM_MACHINE_MODES");
1477 for_all_modes (c
, m
)
1479 struct mode_data
* m2
;
1482 m2
&& m2
!= void_mode
;
1485 if (m2
->bytesize
< 2 * m
->bytesize
)
1487 if (m
->precision
!= (unsigned int) -1)
1489 if (m2
->precision
!= 2 * m
->precision
)
1494 if (m2
->precision
!= (unsigned int) -1)
1498 /* For vectors we want twice the number of components,
1499 with the same element type. */
1500 if (m
->cl
== MODE_VECTOR_BOOL
1501 || m
->cl
== MODE_VECTOR_INT
1502 || m
->cl
== MODE_VECTOR_FLOAT
1503 || m
->cl
== MODE_VECTOR_FRACT
1504 || m
->cl
== MODE_VECTOR_UFRACT
1505 || m
->cl
== MODE_VECTOR_ACCUM
1506 || m
->cl
== MODE_VECTOR_UACCUM
)
1508 if (m2
->ncomponents
!= 2 * m
->ncomponents
)
1510 if (m
->component
!= m2
->component
)
1516 if (m2
== void_mode
)
1518 tagged_printf ("E_%smode",
1519 m2
? m2
->name
: void_mode
->name
,
1527 emit_mode_complex (void)
1530 struct mode_data
*m
;
1532 print_decl ("unsigned char", "mode_complex", "NUM_MACHINE_MODES");
1534 for_all_modes (c
, m
)
1535 tagged_printf ("E_%smode",
1536 m
->complex ? m
->complex->name
: void_mode
->name
,
1543 emit_mode_mask (void)
1546 struct mode_data
*m
;
1548 print_decl ("unsigned HOST_WIDE_INT", "mode_mask_array",
1549 "NUM_MACHINE_MODES");
1551 #define MODE_MASK(m) \\\n\
1552 ((m) >= HOST_BITS_PER_WIDE_INT) \\\n\
1553 ? HOST_WIDE_INT_M1U \\\n\
1554 : (HOST_WIDE_INT_1U << (m)) - 1\n");
1556 for_all_modes (c
, m
)
1557 if (m
->precision
!= (unsigned int)-1)
1558 tagged_printf ("MODE_MASK (%u)", m
->precision
, m
->name
);
1560 tagged_printf ("MODE_MASK (%u*BITS_PER_UNIT)", m
->bytesize
, m
->name
);
1562 puts ("#undef MODE_MASK");
1567 emit_mode_inner (void)
1570 struct mode_data
*m
;
1572 print_decl ("unsigned char", "mode_inner", "NUM_MACHINE_MODES");
1574 for_all_modes (c
, m
)
1575 tagged_printf ("E_%smode",
1576 c
!= MODE_PARTIAL_INT
&& m
->component
1577 ? m
->component
->name
: m
->name
,
1583 /* Emit mode_unit_size array into insn-modes.c file. */
1585 emit_mode_unit_size (void)
1588 struct mode_data
*m
;
1590 print_maybe_const_decl ("%sunsigned char", "mode_unit_size",
1591 "NUM_MACHINE_MODES", adj_bytesize
);
1593 for_all_modes (c
, m
)
1594 tagged_printf ("%u",
1595 c
!= MODE_PARTIAL_INT
&& m
->component
1596 ? m
->component
->bytesize
: m
->bytesize
, m
->name
);
1601 /* Emit mode_unit_precision array into insn-modes.c file. */
1603 emit_mode_unit_precision (void)
1606 struct mode_data
*m
;
1608 print_decl ("unsigned short", "mode_unit_precision", "NUM_MACHINE_MODES");
1610 for_all_modes (c
, m
)
1612 struct mode_data
*m2
= (c
!= MODE_PARTIAL_INT
&& m
->component
) ?
1614 if (m2
->precision
!= (unsigned int)-1)
1615 tagged_printf ("%u", m2
->precision
, m
->name
);
1617 tagged_printf ("%u*BITS_PER_UNIT", m2
->bytesize
, m
->name
);
1625 emit_mode_base_align (void)
1628 struct mode_data
*m
;
1630 print_maybe_const_decl ("%sunsigned short",
1631 "mode_base_align", "NUM_MACHINE_MODES",
1634 for_all_modes (c
, m
)
1635 tagged_printf ("%u", m
->alignment
, m
->name
);
1641 emit_class_narrowest_mode (void)
1645 print_decl ("unsigned char", "class_narrowest_mode", "MAX_MODE_CLASS");
1647 for (c
= 0; c
< MAX_MODE_CLASS
; c
++)
1648 /* Bleah, all this to get the comment right for MIN_MODE_INT. */
1649 tagged_printf ("MIN_%s", mode_class_names
[c
],
1651 ? ((c
!= MODE_INT
|| modes
[c
]->precision
!= 1)
1654 ? modes
[c
]->next
->name
1662 emit_real_format_for_mode (void)
1664 struct mode_data
*m
;
1666 /* The entities pointed to by this table are constant, whether
1667 or not the table itself is constant.
1669 For backward compatibility this table is always writable
1670 (several targets modify it in TARGET_OPTION_OVERRIDE). FIXME:
1671 convert all said targets to use ADJUST_FORMAT instead. */
1673 print_maybe_const_decl ("const struct real_format *%s",
1674 "real_format_for_mode",
1675 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1",
1678 print_decl ("struct real_format *\n", "real_format_for_mode",
1679 "MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1 "
1680 "+ MAX_MODE_DECIMAL_FLOAT - MIN_MODE_DECIMAL_FLOAT + 1");
1683 /* The beginning of the table is entries for float modes. */
1684 for (m
= modes
[MODE_FLOAT
]; m
; m
= m
->next
)
1685 if (!strcmp (m
->format
, "0"))
1686 tagged_printf ("%s", m
->format
, m
->name
);
1688 tagged_printf ("&%s", m
->format
, m
->name
);
1690 /* The end of the table is entries for decimal float modes. */
1691 for (m
= modes
[MODE_DECIMAL_FLOAT
]; m
; m
= m
->next
)
1692 if (!strcmp (m
->format
, "0"))
1693 tagged_printf ("%s", m
->format
, m
->name
);
1695 tagged_printf ("&%s", m
->format
, m
->name
);
1701 emit_mode_adjustments (void)
1703 struct mode_adjust
*a
;
1704 struct mode_data
*m
;
1708 \ninit_adjust_machine_modes (void)\
1710 \n poly_uint16 ps ATTRIBUTE_UNUSED;\n\
1711 size_t s ATTRIBUTE_UNUSED;");
1713 for (a
= adj_nunits
; a
; a
= a
->next
)
1718 " /* %s:%d */\n ps = %s;\n",
1719 a
->file
, a
->line
, a
->adjustment
);
1720 printf (" int old_factor = vector_element_size"
1721 " (mode_precision[E_%smode], mode_nunits[E_%smode]);\n",
1723 printf (" mode_precision[E_%smode] = ps * old_factor;\n", m
->name
);
1724 printf (" mode_size[E_%smode] = exact_div (mode_precision[E_%smode],"
1725 " BITS_PER_UNIT);\n", m
->name
, m
->name
);
1726 printf (" mode_nunits[E_%smode] = ps;\n", m
->name
);
1730 /* Size adjustments must be propagated to all containing modes.
1731 A size adjustment forces us to recalculate the alignment too. */
1732 for (a
= adj_bytesize
; a
; a
= a
->next
)
1734 printf ("\n /* %s:%d */\n", a
->file
, a
->line
);
1735 switch (a
->mode
->cl
)
1737 case MODE_VECTOR_BOOL
:
1738 case MODE_VECTOR_INT
:
1739 case MODE_VECTOR_FLOAT
:
1740 case MODE_VECTOR_FRACT
:
1741 case MODE_VECTOR_UFRACT
:
1742 case MODE_VECTOR_ACCUM
:
1743 case MODE_VECTOR_UACCUM
:
1744 printf (" ps = %s;\n", a
->adjustment
);
1745 printf (" s = mode_unit_size[E_%smode];\n", a
->mode
->name
);
1749 printf (" ps = s = %s;\n", a
->adjustment
);
1750 printf (" mode_unit_size[E_%smode] = s;\n", a
->mode
->name
);
1753 printf (" mode_size[E_%smode] = ps;\n", a
->mode
->name
);
1754 printf (" mode_base_align[E_%smode] = known_alignment (ps);\n",
1757 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1761 case MODE_COMPLEX_INT
:
1762 case MODE_COMPLEX_FLOAT
:
1763 printf (" mode_size[E_%smode] = 2*s;\n", m
->name
);
1764 printf (" mode_unit_size[E_%smode] = s;\n", m
->name
);
1765 printf (" mode_base_align[E_%smode] = s & (~s + 1);\n",
1769 case MODE_VECTOR_BOOL
:
1770 /* Changes to BImode should not affect vector booleans. */
1773 case MODE_VECTOR_INT
:
1774 case MODE_VECTOR_FLOAT
:
1775 case MODE_VECTOR_FRACT
:
1776 case MODE_VECTOR_UFRACT
:
1777 case MODE_VECTOR_ACCUM
:
1778 case MODE_VECTOR_UACCUM
:
1779 printf (" mode_size[E_%smode] = %d * ps;\n",
1780 m
->name
, m
->ncomponents
);
1781 printf (" mode_unit_size[E_%smode] = s;\n", m
->name
);
1782 printf (" mode_base_align[E_%smode]"
1783 " = known_alignment (%d * ps);\n",
1784 m
->name
, m
->ncomponents
);
1789 "mode %s is neither vector nor complex but contains %s",
1790 m
->name
, a
->mode
->name
);
1796 /* Alignment adjustments propagate too.
1797 ??? This may not be the right thing for vector modes. */
1798 for (a
= adj_alignment
; a
; a
= a
->next
)
1800 printf ("\n /* %s:%d */\n s = %s;\n",
1801 a
->file
, a
->line
, a
->adjustment
);
1802 printf (" mode_base_align[E_%smode] = s;\n", a
->mode
->name
);
1804 for (m
= a
->mode
->contained
; m
; m
= m
->next_cont
)
1808 case MODE_COMPLEX_INT
:
1809 case MODE_COMPLEX_FLOAT
:
1810 printf (" mode_base_align[E_%smode] = s;\n", m
->name
);
1813 case MODE_VECTOR_BOOL
:
1814 /* Changes to BImode should not affect vector booleans. */
1817 case MODE_VECTOR_INT
:
1818 case MODE_VECTOR_FLOAT
:
1819 case MODE_VECTOR_FRACT
:
1820 case MODE_VECTOR_UFRACT
:
1821 case MODE_VECTOR_ACCUM
:
1822 case MODE_VECTOR_UACCUM
:
1823 printf (" mode_base_align[E_%smode] = %d*s;\n",
1824 m
->name
, m
->ncomponents
);
1829 "mode %s is neither vector nor complex but contains %s",
1830 m
->name
, a
->mode
->name
);
1836 /* Ibit adjustments don't have to propagate. */
1837 for (a
= adj_ibit
; a
; a
= a
->next
)
1839 printf ("\n /* %s:%d */\n s = %s;\n",
1840 a
->file
, a
->line
, a
->adjustment
);
1841 printf (" mode_ibit[E_%smode] = s;\n", a
->mode
->name
);
1844 /* Fbit adjustments don't have to propagate. */
1845 for (a
= adj_fbit
; a
; a
= a
->next
)
1847 printf ("\n /* %s:%d */\n s = %s;\n",
1848 a
->file
, a
->line
, a
->adjustment
);
1849 printf (" mode_fbit[E_%smode] = s;\n", a
->mode
->name
);
1852 /* Real mode formats don't have to propagate anywhere. */
1853 for (a
= adj_format
; a
; a
= a
->next
)
1854 printf ("\n /* %s:%d */\n REAL_MODE_FORMAT (E_%smode) = %s;\n",
1855 a
->file
, a
->line
, a
->mode
->name
, a
->adjustment
);
1860 /* Emit ibit for all modes. */
1863 emit_mode_ibit (void)
1866 struct mode_data
*m
;
1868 print_maybe_const_decl ("%sunsigned char",
1869 "mode_ibit", "NUM_MACHINE_MODES",
1872 for_all_modes (c
, m
)
1873 tagged_printf ("%u", m
->ibit
, m
->name
);
1878 /* Emit fbit for all modes. */
1881 emit_mode_fbit (void)
1884 struct mode_data
*m
;
1886 print_maybe_const_decl ("%sunsigned char",
1887 "mode_fbit", "NUM_MACHINE_MODES",
1890 for_all_modes (c
, m
)
1891 tagged_printf ("%u", m
->fbit
, m
->name
);
1896 /* Emit __intN for all modes. */
1899 emit_mode_int_n (void)
1902 struct mode_data
*m
;
1903 struct mode_data
**mode_sort
;
1907 print_decl ("int_n_data_t", "int_n_data", "");
1910 for_all_modes (c
, m
)
1913 mode_sort
= XALLOCAVEC (struct mode_data
*, n_modes
);
1916 for_all_modes (c
, m
)
1918 mode_sort
[n_modes
++] = m
;
1920 /* Yes, this is a bubblesort, but there are at most four (and
1921 usually only 1-2) entries to sort. */
1922 for (i
= 0; i
<n_modes
- 1; i
++)
1923 for (j
= i
+ 1; j
< n_modes
; j
++)
1924 if (mode_sort
[i
]->int_n
> mode_sort
[j
]->int_n
)
1925 std::swap (mode_sort
[i
], mode_sort
[j
]);
1927 for (i
= 0; i
< n_modes
; i
++)
1931 tagged_printf ("%u", m
->int_n
, m
->name
);
1932 printf ("{ E_%smode },", m
->name
);
1941 emit_insn_modes_c (void)
1943 emit_insn_modes_c_header ();
1946 emit_mode_precision ();
1948 emit_mode_nunits ();
1950 emit_mode_complex ();
1953 emit_mode_unit_size ();
1954 emit_mode_unit_precision ();
1955 emit_mode_base_align ();
1956 emit_class_narrowest_mode ();
1957 emit_real_format_for_mode ();
1958 emit_mode_adjustments ();
1965 emit_min_insn_modes_c (void)
1967 emit_min_insn_modes_c_header ();
1970 emit_mode_nunits ();
1973 emit_class_narrowest_mode ();
1976 /* Master control. */
1978 main (int argc
, char **argv
)
1980 bool gen_header
= false, gen_inlines
= false, gen_min
= false;
1985 else if (argc
== 2 && !strcmp (argv
[1], "-h"))
1987 else if (argc
== 2 && !strcmp (argv
[1], "-i"))
1989 else if (argc
== 2 && !strcmp (argv
[1], "-m"))
1993 error ("usage: %s [-h|-i|-m] > file", progname
);
1994 return FATAL_EXIT_CODE
;
1997 modes_by_name
= htab_create_alloc (64, hash_mode
, eq_mode
, 0, xcalloc
, free
);
2000 complete_all_modes ();
2003 return FATAL_EXIT_CODE
;
2008 emit_insn_modes_h ();
2009 else if (gen_inlines
)
2010 emit_insn_modes_inline_h ();
2012 emit_min_insn_modes_c ();
2014 emit_insn_modes_c ();
2016 if (fflush (stdout
) || fclose (stdout
))
2017 return FATAL_EXIT_CODE
;
2018 return SUCCESS_EXIT_CODE
;