comparison gcc/genmodes.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 /* Generate the machine mode enumeration and associated tables. 1 /* Generate the machine mode enumeration and associated tables.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010 2 Copyright (C) 2003-2017 Free Software Foundation, Inc.
3 Free Software Foundation, Inc.
4 3
5 This file is part of GCC. 4 This file is part of GCC.
6 5
7 GCC is free software; you can redistribute it and/or modify it under 6 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free 7 the terms of the GNU General Public License as published by the Free
19 <http://www.gnu.org/licenses/>. */ 18 <http://www.gnu.org/licenses/>. */
20 19
21 #include "bconfig.h" 20 #include "bconfig.h"
22 #include "system.h" 21 #include "system.h"
23 #include "errors.h" 22 #include "errors.h"
24 #include "hashtab.h"
25 23
26 /* enum mode_class is normally defined by machmode.h but we can't 24 /* enum mode_class is normally defined by machmode.h but we can't
27 include that header here. */ 25 include that header here. */
28 #include "mode-classes.def" 26 #include "mode-classes.def"
29 27
61 unsigned int alignment; /* mode alignment */ 59 unsigned int alignment; /* mode alignment */
62 const char *format; /* floating point format - float modes only */ 60 const char *format; /* floating point format - float modes only */
63 61
64 struct mode_data *component; /* mode of components */ 62 struct mode_data *component; /* mode of components */
65 struct mode_data *wider; /* next wider mode */ 63 struct mode_data *wider; /* next wider mode */
66 struct mode_data *wider_2x; /* 2x wider mode */
67 64
68 struct mode_data *contained; /* Pointer to list of modes that have 65 struct mode_data *contained; /* Pointer to list of modes that have
69 this mode as a component. */ 66 this mode as a component. */
70 struct mode_data *next_cont; /* Next mode in that list. */ 67 struct mode_data *next_cont; /* Next mode in that list. */
71 68
69 struct mode_data *complex; /* complex type with mode as component. */
72 const char *file; /* file and line of definition, */ 70 const char *file; /* file and line of definition, */
73 unsigned int line; /* for error reporting */ 71 unsigned int line; /* for error reporting */
74 unsigned int counter; /* Rank ordering of modes */ 72 unsigned int counter; /* Rank ordering of modes */
75 unsigned int ibit; /* the number of integral bits */ 73 unsigned int ibit; /* the number of integral bits */
76 unsigned int fbit; /* the number of fractional bits */ 74 unsigned int fbit; /* the number of fractional bits */
75 bool need_bytesize_adj; /* true if this mode need dynamic size
76 adjustment */
77 unsigned int int_n; /* If nonzero, then __int<INT_N> will be defined */
77 }; 78 };
78 79
79 static struct mode_data *modes[MAX_MODE_CLASS]; 80 static struct mode_data *modes[MAX_MODE_CLASS];
80 static unsigned int n_modes[MAX_MODE_CLASS]; 81 static unsigned int n_modes[MAX_MODE_CLASS];
81 static struct mode_data *void_mode; 82 static struct mode_data *void_mode;
82 83
83 static const struct mode_data blank_mode = { 84 static const struct mode_data blank_mode = {
84 0, "<unknown>", MAX_MODE_CLASS, 85 0, "<unknown>", MAX_MODE_CLASS,
85 -1U, -1U, -1U, -1U, 86 -1U, -1U, -1U, -1U,
86 0, 0, 0, 0, 0, 0, 87 0, 0, 0, 0, 0, 0,
87 "<unknown>", 0, 0, 0, 0 88 "<unknown>", 0, 0, 0, 0, false, 0
88 }; 89 };
89 90
90 static htab_t modes_by_name; 91 static htab_t modes_by_name;
91 92
92 /* Data structure for recording target-specified runtime adjustments 93 /* Data structure for recording target-specified runtime adjustments
333 m->ncomponents = 1; 334 m->ncomponents = 1;
334 m->component = 0; 335 m->component = 0;
335 break; 336 break;
336 337
337 case MODE_INT: 338 case MODE_INT:
339 case MODE_POINTER_BOUNDS:
338 case MODE_FLOAT: 340 case MODE_FLOAT:
339 case MODE_DECIMAL_FLOAT: 341 case MODE_DECIMAL_FLOAT:
340 case MODE_FRACT: 342 case MODE_FRACT:
341 case MODE_UFRACT: 343 case MODE_UFRACT:
342 case MODE_ACCUM: 344 case MODE_ACCUM:
359 validate_mode (m, OPTIONAL, UNSET, SET, UNSET, UNSET); 361 validate_mode (m, OPTIONAL, UNSET, SET, UNSET, UNSET);
360 362
361 m->bytesize = m->component->bytesize; 363 m->bytesize = m->component->bytesize;
362 364
363 m->ncomponents = 1; 365 m->ncomponents = 1;
364 m->component = 0; /* ??? preserve this */
365 break; 366 break;
366 367
367 case MODE_COMPLEX_INT: 368 case MODE_COMPLEX_INT:
368 case MODE_COMPLEX_FLOAT: 369 case MODE_COMPLEX_FLOAT:
369 /* Complex modes should have a component indicated, but no more. */ 370 /* Complex modes should have a component indicated, but no more. */
419 for_all_modes (cl, m) 420 for_all_modes (cl, m)
420 complete_mode (m); 421 complete_mode (m);
421 } 422 }
422 423
423 /* For each mode in class CLASS, construct a corresponding complex mode. */ 424 /* For each mode in class CLASS, construct a corresponding complex mode. */
424 #define COMPLEX_MODES(C) make_complex_modes(MODE_##C, __FILE__, __LINE__) 425 #define COMPLEX_MODES(C) make_complex_modes (MODE_##C, __FILE__, __LINE__)
425 static void 426 static void
426 make_complex_modes (enum mode_class cl, 427 make_complex_modes (enum mode_class cl,
427 const char *file, unsigned int line) 428 const char *file, unsigned int line)
428 { 429 {
429 struct mode_data *m; 430 struct mode_data *m;
430 struct mode_data *c; 431 struct mode_data *c;
431 char buf[8];
432 enum mode_class cclass = complex_class (cl); 432 enum mode_class cclass = complex_class (cl);
433 433
434 if (cclass == MODE_RANDOM) 434 if (cclass == MODE_RANDOM)
435 return; 435 return;
436 436
437 for (m = modes[cl]; m; m = m->next) 437 for (m = modes[cl]; m; m = m->next)
438 { 438 {
439 char *p, *buf;
440 size_t m_len;
441
439 /* Skip BImode. FIXME: BImode probably shouldn't be MODE_INT. */ 442 /* Skip BImode. FIXME: BImode probably shouldn't be MODE_INT. */
440 if (m->precision == 1) 443 if (m->precision == 1)
441 continue; 444 continue;
442 445
443 if (strlen (m->name) >= sizeof buf) 446 m_len = strlen (m->name);
444 { 447 /* The leading "1 +" is in case we prepend a "C" below. */
445 error ("%s:%d:mode name \"%s\" is too long", 448 buf = (char *) xmalloc (1 + m_len + 1);
446 m->file, m->line, m->name);
447 continue;
448 }
449 449
450 /* Float complex modes are named SCmode, etc. 450 /* Float complex modes are named SCmode, etc.
451 Int complex modes are named CSImode, etc. 451 Int complex modes are named CSImode, etc.
452 This inconsistency should be eliminated. */ 452 This inconsistency should be eliminated. */
453 p = 0;
453 if (cl == MODE_FLOAT) 454 if (cl == MODE_FLOAT)
454 { 455 {
455 char *p, *q = 0; 456 memcpy (buf, m->name, m_len + 1);
456 strncpy (buf, m->name, sizeof buf);
457 p = strchr (buf, 'F'); 457 p = strchr (buf, 'F');
458 if (p == 0) 458 if (p == 0 && strchr (buf, 'D') == 0)
459 q = strchr (buf, 'D');
460 if (p == 0 && q == 0)
461 { 459 {
462 error ("%s:%d: float mode \"%s\" has no 'F' or 'D'", 460 error ("%s:%d: float mode \"%s\" has no 'F' or 'D'",
463 m->file, m->line, m->name); 461 m->file, m->line, m->name);
462 free (buf);
464 continue; 463 continue;
465 } 464 }
466
467 if (p != 0)
468 *p = 'C';
469 else
470 snprintf (buf, sizeof buf, "C%s", m->name);
471 } 465 }
466 if (p != 0)
467 *p = 'C';
472 else 468 else
473 snprintf (buf, sizeof buf, "C%s", m->name); 469 {
474 470 buf[0] = 'C';
475 c = new_mode (cclass, xstrdup (buf), file, line); 471 memcpy (buf + 1, m->name, m_len + 1);
472 }
473
474 c = new_mode (cclass, buf, file, line);
476 c->component = m; 475 c->component = m;
476 m->complex = c;
477 } 477 }
478 } 478 }
479 479
480 /* For all modes in class CL, construct vector modes of width 480 /* For all modes in class CL, construct vector modes of width
481 WIDTH, having as many components as necessary. */ 481 WIDTH, having as many components as necessary. */
482 #define VECTOR_MODES(C, W) make_vector_modes(MODE_##C, W, __FILE__, __LINE__) 482 #define VECTOR_MODES(C, W) make_vector_modes (MODE_##C, W, __FILE__, __LINE__)
483 static void ATTRIBUTE_UNUSED 483 static void ATTRIBUTE_UNUSED
484 make_vector_modes (enum mode_class cl, unsigned int width, 484 make_vector_modes (enum mode_class cl, unsigned int width,
485 const char *file, unsigned int line) 485 const char *file, unsigned int line)
486 { 486 {
487 struct mode_data *m; 487 struct mode_data *m;
488 struct mode_data *v; 488 struct mode_data *v;
489 char buf[8]; 489 /* Big enough for a 32-bit UINT_MAX plus the text. */
490 char buf[12];
490 unsigned int ncomponents; 491 unsigned int ncomponents;
491 enum mode_class vclass = vector_class (cl); 492 enum mode_class vclass = vector_class (cl);
492 493
493 if (vclass == MODE_RANDOM) 494 if (vclass == MODE_RANDOM)
494 return; 495 return;
525 } 526 }
526 } 527 }
527 528
528 /* Input. */ 529 /* Input. */
529 530
530 #define _SPECIAL_MODE(C, N) make_special_mode(MODE_##C, #N, __FILE__, __LINE__) 531 #define _SPECIAL_MODE(C, N) \
532 make_special_mode (MODE_##C, #N, __FILE__, __LINE__)
531 #define RANDOM_MODE(N) _SPECIAL_MODE (RANDOM, N) 533 #define RANDOM_MODE(N) _SPECIAL_MODE (RANDOM, N)
532 #define CC_MODE(N) _SPECIAL_MODE (CC, N) 534 #define CC_MODE(N) _SPECIAL_MODE (CC, N)
533 535
534 static void 536 static void
535 make_special_mode (enum mode_class cl, const char *name, 537 make_special_mode (enum mode_class cl, const char *name,
536 const char *file, unsigned int line) 538 const char *file, unsigned int line)
537 { 539 {
538 new_mode (cl, name, file, line); 540 new_mode (cl, name, file, line);
539 } 541 }
542
543 #define POINTER_BOUNDS_MODE(N, Y) \
544 make_pointer_bounds_mode (#N, Y, __FILE__, __LINE__)
545
546 static void ATTRIBUTE_UNUSED
547 make_pointer_bounds_mode (const char *name,
548 unsigned int bytesize,
549 const char *file, unsigned int line)
550 {
551 struct mode_data *m = new_mode (MODE_POINTER_BOUNDS, name, file, line);
552 m->bytesize = bytesize;
553 }
554
540 555
541 #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y) 556 #define INT_MODE(N, Y) FRACTIONAL_INT_MODE (N, -1U, Y)
542 #define FRACTIONAL_INT_MODE(N, B, Y) \ 557 #define FRACTIONAL_INT_MODE(N, B, Y) \
543 make_int_mode (#N, B, Y, __FILE__, __LINE__) 558 make_int_mode (#N, B, Y, __FILE__, __LINE__)
544 559
632 return; 647 return;
633 } 648 }
634 m->format = format; 649 m->format = format;
635 } 650 }
636 651
637 /* Partial integer modes are specified by relation to a full integer mode. 652 /* __intN support. */
638 For now, we do not attempt to narrow down their bit sizes. */ 653 #define INT_N(M,PREC) \
639 #define PARTIAL_INT_MODE(M) \ 654 make_int_n (#M, PREC, __FILE__, __LINE__)
640 make_partial_integer_mode (#M, "P" #M, -1U, __FILE__, __LINE__) 655 static void ATTRIBUTE_UNUSED
656 make_int_n (const char *m, int bitsize,
657 const char *file, unsigned int line)
658 {
659 struct mode_data *component = find_mode (m);
660 if (!component)
661 {
662 error ("%s:%d: no mode \"%s\"", file, line, m);
663 return;
664 }
665 if (component->cl != MODE_INT
666 && component->cl != MODE_PARTIAL_INT)
667 {
668 error ("%s:%d: mode \"%s\" is not class INT or PARTIAL_INT", file, line, m);
669 return;
670 }
671 if (component->int_n != 0)
672 {
673 error ("%s:%d: mode \"%s\" already has an intN", file, line, m);
674 return;
675 }
676
677 component->int_n = bitsize;
678 }
679
680 /* Partial integer modes are specified by relation to a full integer
681 mode. */
682 #define PARTIAL_INT_MODE(M,PREC,NAME) \
683 make_partial_integer_mode (#M, #NAME, PREC, __FILE__, __LINE__)
641 static void ATTRIBUTE_UNUSED 684 static void ATTRIBUTE_UNUSED
642 make_partial_integer_mode (const char *base, const char *name, 685 make_partial_integer_mode (const char *base, const char *name,
643 unsigned int precision, 686 unsigned int precision,
644 const char *file, unsigned int line) 687 const char *file, unsigned int line)
645 { 688 {
672 const char *file, unsigned int line) 715 const char *file, unsigned int line)
673 { 716 {
674 struct mode_data *v; 717 struct mode_data *v;
675 enum mode_class vclass = vector_class (bclass); 718 enum mode_class vclass = vector_class (bclass);
676 struct mode_data *component = find_mode (base); 719 struct mode_data *component = find_mode (base);
677 char namebuf[8]; 720 char namebuf[16];
678 721
679 if (vclass == MODE_RANDOM) 722 if (vclass == MODE_RANDOM)
680 return; 723 return;
681 if (component == 0) 724 if (component == 0)
682 { 725 {
707 750
708 /* Adjustability. */ 751 /* Adjustability. */
709 #define _ADD_ADJUST(A, M, X, C1, C2) \ 752 #define _ADD_ADJUST(A, M, X, C1, C2) \
710 new_adjust (#M, &adj_##A, #A, #X, MODE_##C1, MODE_##C2, __FILE__, __LINE__) 753 new_adjust (#M, &adj_##A, #A, #X, MODE_##C1, MODE_##C2, __FILE__, __LINE__)
711 754
712 #define ADJUST_BYTESIZE(M, X) _ADD_ADJUST(bytesize, M, X, RANDOM, RANDOM) 755 #define ADJUST_BYTESIZE(M, X) _ADD_ADJUST (bytesize, M, X, RANDOM, RANDOM)
713 #define ADJUST_ALIGNMENT(M, X) _ADD_ADJUST(alignment, M, X, RANDOM, RANDOM) 756 #define ADJUST_ALIGNMENT(M, X) _ADD_ADJUST (alignment, M, X, RANDOM, RANDOM)
714 #define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST(format, M, X, FLOAT, FLOAT) 757 #define ADJUST_FLOAT_FORMAT(M, X) _ADD_ADJUST (format, M, X, FLOAT, FLOAT)
715 #define ADJUST_IBIT(M, X) _ADD_ADJUST(ibit, M, X, ACCUM, UACCUM) 758 #define ADJUST_IBIT(M, X) _ADD_ADJUST (ibit, M, X, ACCUM, UACCUM)
716 #define ADJUST_FBIT(M, X) _ADD_ADJUST(fbit, M, X, FRACT, UACCUM) 759 #define ADJUST_FBIT(M, X) _ADD_ADJUST (fbit, M, X, FRACT, UACCUM)
760
761 static int bits_per_unit;
762 static int max_bitsize_mode_any_int;
717 763
718 static void 764 static void
719 create_modes (void) 765 create_modes (void)
720 { 766 {
721 #include "machmode.def" 767 #include "machmode.def"
768
769 /* So put the default value unless the target needs a non standard
770 value. */
771 #ifdef BITS_PER_UNIT
772 bits_per_unit = BITS_PER_UNIT;
773 #else
774 bits_per_unit = 8;
775 #endif
776
777 #ifdef MAX_BITSIZE_MODE_ANY_INT
778 max_bitsize_mode_any_int = MAX_BITSIZE_MODE_ANY_INT;
779 #else
780 max_bitsize_mode_any_int = 0;
781 #endif
722 } 782 }
723 783
724 /* Processing. */ 784 /* Processing. */
725 785
726 /* Sort a list of modes into the order needed for the WIDER field: 786 /* Sort a list of modes into the order needed for the WIDER field:
788 for (c = 0; c < MAX_MODE_CLASS; c++) 848 for (c = 0; c < MAX_MODE_CLASS; c++)
789 max_n_modes = MAX (max_n_modes, n_modes[c]); 849 max_n_modes = MAX (max_n_modes, n_modes[c]);
790 850
791 /* Allocate max_n_modes + 1 entries to leave room for the extra null 851 /* Allocate max_n_modes + 1 entries to leave room for the extra null
792 pointer assigned after the qsort call below. */ 852 pointer assigned after the qsort call below. */
793 sortbuf = (struct mode_data **) alloca ((max_n_modes + 1) * sizeof (struct mode_data *)); 853 sortbuf = XALLOCAVEC (struct mode_data *, max_n_modes + 1);
794 854
795 for (c = 0; c < MAX_MODE_CLASS; c++) 855 for (c = 0; c < MAX_MODE_CLASS; c++)
796 { 856 {
797 /* "wider" is not meaningful for MODE_RANDOM and MODE_CC. 857 /* "wider" is not meaningful for MODE_RANDOM and MODE_CC.
798 However, we want these in textual order, and we have 858 However, we want these in textual order, and we have
802 struct mode_data *prev, *next; 862 struct mode_data *prev, *next;
803 863
804 for (prev = 0, m = modes[c]; m; m = next) 864 for (prev = 0, m = modes[c]; m; m = next)
805 { 865 {
806 m->wider = void_mode; 866 m->wider = void_mode;
807 m->wider_2x = void_mode;
808 867
809 /* this is nreverse */ 868 /* this is nreverse */
810 next = m->next; 869 next = m->next;
811 m->next = prev; 870 m->next = prev;
812 prev = m; 871 prev = m;
819 continue; 878 continue;
820 879
821 for (i = 0, m = modes[c]; m; i++, m = m->next) 880 for (i = 0, m = modes[c]; m; i++, m = m->next)
822 sortbuf[i] = m; 881 sortbuf[i] = m;
823 882
824 qsort (sortbuf, i, sizeof (struct mode_data *), cmp_modes); 883 (qsort) (sortbuf, i, sizeof (struct mode_data *), cmp_modes);
825 884
826 sortbuf[i] = 0; 885 sortbuf[i] = 0;
827 for (j = 0; j < i; j++) 886 for (j = 0; j < i; j++)
828 sortbuf[j]->next = sortbuf[j]->wider = sortbuf[j + 1]; 887 {
829 888 sortbuf[j]->next = sortbuf[j + 1];
889 if (c == MODE_PARTIAL_INT)
890 sortbuf[j]->wider = sortbuf[j]->component;
891 else
892 sortbuf[j]->wider = sortbuf[j]->next;
893 }
830 894
831 modes[c] = sortbuf[0]; 895 modes[c] = sortbuf[0];
832 } 896 }
833 } 897 }
834 } 898 }
847 printf ("\n" TYPE " " NAME "[" ASIZE "] = \n{\n", \ 911 printf ("\n" TYPE " " NAME "[" ASIZE "] = \n{\n", \
848 adj_##CATEGORY ? "" : "const ") 912 adj_##CATEGORY ? "" : "const ")
849 913
850 #define print_closer() puts ("};") 914 #define print_closer() puts ("};")
851 915
916 /* Compute the max bitsize of some of the classes of integers. It may
917 be that there are needs for the other integer classes, and this
918 code is easy to extend. */
919 static void
920 emit_max_int (void)
921 {
922 unsigned int max, mmax;
923 struct mode_data *i;
924 int j;
925
926 puts ("");
927
928 printf ("#define BITS_PER_UNIT (%d)\n", bits_per_unit);
929
930 if (max_bitsize_mode_any_int == 0)
931 {
932 for (max = 1, i = modes[MODE_INT]; i; i = i->next)
933 if (max < i->bytesize)
934 max = i->bytesize;
935 mmax = max;
936 for (max = 1, i = modes[MODE_PARTIAL_INT]; i; i = i->next)
937 if (max < i->bytesize)
938 max = i->bytesize;
939 if (max > mmax)
940 mmax = max;
941 printf ("#define MAX_BITSIZE_MODE_ANY_INT (%d*BITS_PER_UNIT)\n", mmax);
942 }
943 else
944 printf ("#define MAX_BITSIZE_MODE_ANY_INT %d\n", max_bitsize_mode_any_int);
945
946 mmax = 0;
947 for (j = 0; j < MAX_MODE_CLASS; j++)
948 for (i = modes[j]; i; i = i->next)
949 if (mmax < i->bytesize)
950 mmax = i->bytesize;
951 printf ("#define MAX_BITSIZE_MODE_ANY_MODE (%d*BITS_PER_UNIT)\n", mmax);
952 }
953
954 /* Emit mode_size_inline routine into insn-modes.h header. */
955 static void
956 emit_mode_size_inline (void)
957 {
958 int c;
959 struct mode_adjust *a;
960 struct mode_data *m;
961
962 /* Size adjustments must be propagated to all containing modes. */
963 for (a = adj_bytesize; a; a = a->next)
964 {
965 a->mode->need_bytesize_adj = true;
966 for (m = a->mode->contained; m; m = m->next_cont)
967 m->need_bytesize_adj = true;
968 }
969
970 printf ("\
971 #ifdef __cplusplus\n\
972 inline __attribute__((__always_inline__))\n\
973 #else\n\
974 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
975 #endif\n\
976 unsigned short\n\
977 mode_size_inline (machine_mode mode)\n\
978 {\n\
979 extern %sunsigned short mode_size[NUM_MACHINE_MODES];\n\
980 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
981 switch (mode)\n\
982 {\n", adj_bytesize ? "" : "const ");
983
984 for_all_modes (c, m)
985 if (!m->need_bytesize_adj)
986 printf (" case E_%smode: return %u;\n", m->name, m->bytesize);
987
988 puts ("\
989 default: return mode_size[mode];\n\
990 }\n\
991 }\n");
992 }
993
994 /* Emit mode_nunits_inline routine into insn-modes.h header. */
995 static void
996 emit_mode_nunits_inline (void)
997 {
998 int c;
999 struct mode_data *m;
1000
1001 puts ("\
1002 #ifdef __cplusplus\n\
1003 inline __attribute__((__always_inline__))\n\
1004 #else\n\
1005 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1006 #endif\n\
1007 unsigned char\n\
1008 mode_nunits_inline (machine_mode mode)\n\
1009 {\n\
1010 extern const unsigned char mode_nunits[NUM_MACHINE_MODES];\n\
1011 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1012 switch (mode)\n\
1013 {");
1014
1015 for_all_modes (c, m)
1016 printf (" case E_%smode: return %u;\n", m->name, m->ncomponents);
1017
1018 puts ("\
1019 default: return mode_nunits[mode];\n\
1020 }\n\
1021 }\n");
1022 }
1023
1024 /* Emit mode_inner_inline routine into insn-modes.h header. */
1025 static void
1026 emit_mode_inner_inline (void)
1027 {
1028 int c;
1029 struct mode_data *m;
1030
1031 puts ("\
1032 #ifdef __cplusplus\n\
1033 inline __attribute__((__always_inline__))\n\
1034 #else\n\
1035 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1036 #endif\n\
1037 unsigned char\n\
1038 mode_inner_inline (machine_mode mode)\n\
1039 {\n\
1040 extern const unsigned char mode_inner[NUM_MACHINE_MODES];\n\
1041 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1042 switch (mode)\n\
1043 {");
1044
1045 for_all_modes (c, m)
1046 printf (" case E_%smode: return E_%smode;\n", m->name,
1047 c != MODE_PARTIAL_INT && m->component
1048 ? m->component->name : m->name);
1049
1050 puts ("\
1051 default: return mode_inner[mode];\n\
1052 }\n\
1053 }\n");
1054 }
1055
1056 /* Emit mode_unit_size_inline routine into insn-modes.h header. */
1057 static void
1058 emit_mode_unit_size_inline (void)
1059 {
1060 int c;
1061 struct mode_data *m;
1062
1063 puts ("\
1064 #ifdef __cplusplus\n\
1065 inline __attribute__((__always_inline__))\n\
1066 #else\n\
1067 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1068 #endif\n\
1069 unsigned char\n\
1070 mode_unit_size_inline (machine_mode mode)\n\
1071 {\n\
1072 extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES];\
1073 \n\
1074 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1075 switch (mode)\n\
1076 {");
1077
1078 for_all_modes (c, m)
1079 {
1080 const char *name = m->name;
1081 struct mode_data *m2 = m;
1082 if (c != MODE_PARTIAL_INT && m2->component)
1083 m2 = m2->component;
1084 if (!m2->need_bytesize_adj)
1085 printf (" case E_%smode: return %u;\n", name, m2->bytesize);
1086 }
1087
1088 puts ("\
1089 default: return mode_unit_size[mode];\n\
1090 }\n\
1091 }\n");
1092 }
1093
1094 /* Emit mode_unit_precision_inline routine into insn-modes.h header. */
1095 static void
1096 emit_mode_unit_precision_inline (void)
1097 {
1098 int c;
1099 struct mode_data *m;
1100
1101 puts ("\
1102 #ifdef __cplusplus\n\
1103 inline __attribute__((__always_inline__))\n\
1104 #else\n\
1105 extern __inline__ __attribute__((__always_inline__, __gnu_inline__))\n\
1106 #endif\n\
1107 unsigned short\n\
1108 mode_unit_precision_inline (machine_mode mode)\n\
1109 {\n\
1110 extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES];\n\
1111 gcc_assert (mode >= 0 && mode < NUM_MACHINE_MODES);\n\
1112 switch (mode)\n\
1113 {");
1114
1115 for_all_modes (c, m)
1116 {
1117 struct mode_data *m2
1118 = (c != MODE_PARTIAL_INT && m->component) ? m->component : m;
1119 if (m2->precision != (unsigned int)-1)
1120 printf (" case E_%smode: return %u;\n", m->name, m2->precision);
1121 else
1122 printf (" case E_%smode: return %u*BITS_PER_UNIT;\n",
1123 m->name, m2->bytesize);
1124 }
1125
1126 puts ("\
1127 default: return mode_unit_precision[mode];\n\
1128 }\n\
1129 }\n");
1130 }
1131
1132 /* Return the best machine mode class for MODE, or null if machine_mode
1133 should be used. */
1134
1135 static const char *
1136 get_mode_class (struct mode_data *mode)
1137 {
1138 switch (mode->cl)
1139 {
1140 case MODE_INT:
1141 case MODE_PARTIAL_INT:
1142 return "scalar_int_mode";
1143
1144 case MODE_FRACT:
1145 case MODE_UFRACT:
1146 case MODE_ACCUM:
1147 case MODE_UACCUM:
1148 case MODE_POINTER_BOUNDS:
1149 return "scalar_mode";
1150
1151 case MODE_FLOAT:
1152 case MODE_DECIMAL_FLOAT:
1153 return "scalar_float_mode";
1154
1155 case MODE_COMPLEX_INT:
1156 case MODE_COMPLEX_FLOAT:
1157 return "complex_mode";
1158
1159 default:
1160 return NULL;
1161 }
1162 }
1163
852 static void 1164 static void
853 emit_insn_modes_h (void) 1165 emit_insn_modes_h (void)
854 { 1166 {
855 int c; 1167 int c;
856 struct mode_data *m, *first, *last; 1168 struct mode_data *m, *first, *last;
1169 int n_int_n_ents = 0;
857 1170
858 printf ("/* Generated automatically from machmode.def%s%s\n", 1171 printf ("/* Generated automatically from machmode.def%s%s\n",
859 HAVE_EXTRA_MODES ? " and " : "", 1172 HAVE_EXTRA_MODES ? " and " : "",
860 EXTRA_MODES_FILE); 1173 EXTRA_MODES_FILE);
861 1174
868 enum machine_mode\n{"); 1181 enum machine_mode\n{");
869 1182
870 for (c = 0; c < MAX_MODE_CLASS; c++) 1183 for (c = 0; c < MAX_MODE_CLASS; c++)
871 for (m = modes[c]; m; m = m->next) 1184 for (m = modes[c]; m; m = m->next)
872 { 1185 {
873 int count_ = printf (" %smode,", m->name); 1186 int count_ = printf (" E_%smode,", m->name);
874 printf ("%*s/* %s:%d */\n", 27 - count_, "", 1187 printf ("%*s/* %s:%d */\n", 27 - count_, "",
875 trim_filename (m->file), m->line); 1188 trim_filename (m->file), m->line);
1189 printf ("#define HAVE_%smode\n", m->name);
1190 printf ("#ifdef USE_ENUM_MODES\n");
1191 printf ("#define %smode E_%smode\n", m->name, m->name);
1192 printf ("#else\n");
1193 if (const char *mode_class = get_mode_class (m))
1194 printf ("#define %smode (%s ((%s::from_int) E_%smode))\n",
1195 m->name, mode_class, mode_class, m->name);
1196 else
1197 printf ("#define %smode ((void) 0, E_%smode)\n",
1198 m->name, m->name);
1199 printf ("#endif\n");
876 } 1200 }
877 1201
878 puts (" MAX_MACHINE_MODE,\n"); 1202 puts (" MAX_MACHINE_MODE,\n");
879 1203
880 for (c = 0; c < MAX_MODE_CLASS; c++) 1204 for (c = 0; c < MAX_MODE_CLASS; c++)
886 1210
887 /* Don't use BImode for MIN_MODE_INT, since otherwise the middle 1211 /* Don't use BImode for MIN_MODE_INT, since otherwise the middle
888 end will try to use it for bitfields in structures and the 1212 end will try to use it for bitfields in structures and the
889 like, which we do not want. Only the target md file should 1213 like, which we do not want. Only the target md file should
890 generate BImode widgets. */ 1214 generate BImode widgets. */
891 if (first && first->precision == 1) 1215 if (first && first->precision == 1 && c == MODE_INT)
892 first = first->next; 1216 first = first->next;
893 1217
894 if (first && last) 1218 if (first && last)
895 printf (" MIN_%s = %smode,\n MAX_%s = %smode,\n\n", 1219 printf (" MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n",
896 mode_class_names[c], first->name, 1220 mode_class_names[c], first->name,
897 mode_class_names[c], last->name); 1221 mode_class_names[c], last->name);
898 else 1222 else
899 printf (" MIN_%s = %smode,\n MAX_%s = %smode,\n\n", 1223 printf (" MIN_%s = E_%smode,\n MAX_%s = E_%smode,\n\n",
900 mode_class_names[c], void_mode->name, 1224 mode_class_names[c], void_mode->name,
901 mode_class_names[c], void_mode->name); 1225 mode_class_names[c], void_mode->name);
902 } 1226 }
903 1227
904 puts ("\ 1228 puts ("\
905 NUM_MACHINE_MODES = MAX_MACHINE_MODE\n\ 1229 NUM_MACHINE_MODES = MAX_MACHINE_MODE\n\
906 };\n"); 1230 };\n");
907 1231
908 /* I can't think of a better idea, can you? */ 1232 /* I can't think of a better idea, can you? */
909 printf ("#define CONST_MODE_SIZE%s\n", adj_bytesize ? "" : " const"); 1233 printf ("#define CONST_MODE_SIZE%s\n", adj_bytesize ? "" : " const");
1234 printf ("#define CONST_MODE_UNIT_SIZE%s\n", adj_bytesize ? "" : " const");
910 printf ("#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment ? "" : " const"); 1235 printf ("#define CONST_MODE_BASE_ALIGN%s\n", adj_alignment ? "" : " const");
911 #if 0 /* disabled for backward compatibility, temporary */ 1236 #if 0 /* disabled for backward compatibility, temporary */
912 printf ("#define CONST_REAL_FORMAT_FOR_MODE%s\n", adj_format ? "" :" const"); 1237 printf ("#define CONST_REAL_FORMAT_FOR_MODE%s\n", adj_format ? "" :" const");
913 #endif 1238 #endif
914 printf ("#define CONST_MODE_IBIT%s\n", adj_ibit ? "" : " const"); 1239 printf ("#define CONST_MODE_IBIT%s\n", adj_ibit ? "" : " const");
915 printf ("#define CONST_MODE_FBIT%s\n", adj_fbit ? "" : " const"); 1240 printf ("#define CONST_MODE_FBIT%s\n", adj_fbit ? "" : " const");
1241 emit_max_int ();
1242
1243 for_all_modes (c, m)
1244 if (m->int_n)
1245 n_int_n_ents ++;
1246
1247 printf ("#define NUM_INT_N_ENTS %d\n", n_int_n_ents);
1248
916 puts ("\ 1249 puts ("\
917 \n\ 1250 \n\
918 #endif /* insn-modes.h */"); 1251 #endif /* insn-modes.h */");
1252 }
1253
1254 static void
1255 emit_insn_modes_inline_h (void)
1256 {
1257 printf ("/* Generated automatically from machmode.def%s%s\n",
1258 HAVE_EXTRA_MODES ? " and " : "",
1259 EXTRA_MODES_FILE);
1260
1261 puts ("\
1262 by genmodes. */\n\
1263 \n\
1264 #ifndef GCC_INSN_MODES_INLINE_H\n\
1265 #define GCC_INSN_MODES_INLINE_H");
1266
1267 puts ("\n#if !defined (USED_FOR_TARGET) && GCC_VERSION >= 4001\n");
1268 emit_mode_size_inline ();
1269 emit_mode_nunits_inline ();
1270 emit_mode_inner_inline ();
1271 emit_mode_unit_size_inline ();
1272 emit_mode_unit_precision_inline ();
1273 puts ("#endif /* GCC_VERSION >= 4001 */");
1274
1275 puts ("\
1276 \n\
1277 #endif /* insn-modes-inline.h */");
919 } 1278 }
920 1279
921 static void 1280 static void
922 emit_insn_modes_c_header (void) 1281 emit_insn_modes_c_header (void)
923 { 1282 {
930 \n\ 1289 \n\
931 #include \"config.h\"\n\ 1290 #include \"config.h\"\n\
932 #include \"system.h\"\n\ 1291 #include \"system.h\"\n\
933 #include \"coretypes.h\"\n\ 1292 #include \"coretypes.h\"\n\
934 #include \"tm.h\"\n\ 1293 #include \"tm.h\"\n\
935 #include \"machmode.h\"\n\
936 #include \"real.h\""); 1294 #include \"real.h\"");
937 } 1295 }
938 1296
939 static void 1297 static void
940 emit_min_insn_modes_c_header (void) 1298 emit_min_insn_modes_c_header (void)
946 puts ("\ 1304 puts ("\
947 by genmodes. */\n\ 1305 by genmodes. */\n\
948 \n\ 1306 \n\
949 #include \"bconfig.h\"\n\ 1307 #include \"bconfig.h\"\n\
950 #include \"system.h\"\n\ 1308 #include \"system.h\"\n\
951 #include \"machmode.h\""); 1309 #include \"coretypes.h\"");
952 } 1310 }
953 1311
954 static void 1312 static void
955 emit_mode_name (void) 1313 emit_mode_name (void)
956 { 1314 {
1000 emit_mode_size (void) 1358 emit_mode_size (void)
1001 { 1359 {
1002 int c; 1360 int c;
1003 struct mode_data *m; 1361 struct mode_data *m;
1004 1362
1005 print_maybe_const_decl ("%sunsigned char", "mode_size", 1363 print_maybe_const_decl ("%sunsigned short", "mode_size",
1006 "NUM_MACHINE_MODES", bytesize); 1364 "NUM_MACHINE_MODES", bytesize);
1007 1365
1008 for_all_modes (c, m) 1366 for_all_modes (c, m)
1009 tagged_printf ("%u", m->bytesize, m->name); 1367 tagged_printf ("%u", m->bytesize, m->name);
1010 1368
1032 struct mode_data *m; 1390 struct mode_data *m;
1033 1391
1034 print_decl ("unsigned char", "mode_wider", "NUM_MACHINE_MODES"); 1392 print_decl ("unsigned char", "mode_wider", "NUM_MACHINE_MODES");
1035 1393
1036 for_all_modes (c, m) 1394 for_all_modes (c, m)
1037 tagged_printf ("%smode", 1395 tagged_printf ("E_%smode",
1038 m->wider ? m->wider->name : void_mode->name, 1396 m->wider ? m->wider->name : void_mode->name,
1039 m->name); 1397 m->name);
1040 1398
1041 print_closer (); 1399 print_closer ();
1042 print_decl ("unsigned char", "mode_2xwider", "NUM_MACHINE_MODES"); 1400 print_decl ("unsigned char", "mode_2xwider", "NUM_MACHINE_MODES");
1060 { 1418 {
1061 if (m2->precision != (unsigned int) -1) 1419 if (m2->precision != (unsigned int) -1)
1062 continue; 1420 continue;
1063 } 1421 }
1064 1422
1423 /* For vectors we want twice the number of components,
1424 with the same element type. */
1425 if (m->cl == MODE_VECTOR_INT
1426 || m->cl == MODE_VECTOR_FLOAT
1427 || m->cl == MODE_VECTOR_FRACT
1428 || m->cl == MODE_VECTOR_UFRACT
1429 || m->cl == MODE_VECTOR_ACCUM
1430 || m->cl == MODE_VECTOR_UACCUM)
1431 {
1432 if (m2->ncomponents != 2 * m->ncomponents)
1433 continue;
1434 if (m->component != m2->component)
1435 continue;
1436 }
1437
1065 break; 1438 break;
1066 } 1439 }
1067 if (m2 == void_mode) 1440 if (m2 == void_mode)
1068 m2 = 0; 1441 m2 = 0;
1069 tagged_printf ("%smode", 1442 tagged_printf ("E_%smode",
1070 m2 ? m2->name : void_mode->name, 1443 m2 ? m2->name : void_mode->name,
1071 m->name); 1444 m->name);
1072 } 1445 }
1446
1447 print_closer ();
1448 }
1449
1450 static void
1451 emit_mode_complex (void)
1452 {
1453 int c;
1454 struct mode_data *m;
1455
1456 print_decl ("unsigned char", "mode_complex", "NUM_MACHINE_MODES");
1457
1458 for_all_modes (c, m)
1459 tagged_printf ("E_%smode",
1460 m->complex ? m->complex->name : void_mode->name,
1461 m->name);
1073 1462
1074 print_closer (); 1463 print_closer ();
1075 } 1464 }
1076 1465
1077 static void 1466 static void
1083 print_decl ("unsigned HOST_WIDE_INT", "mode_mask_array", 1472 print_decl ("unsigned HOST_WIDE_INT", "mode_mask_array",
1084 "NUM_MACHINE_MODES"); 1473 "NUM_MACHINE_MODES");
1085 puts ("\ 1474 puts ("\
1086 #define MODE_MASK(m) \\\n\ 1475 #define MODE_MASK(m) \\\n\
1087 ((m) >= HOST_BITS_PER_WIDE_INT) \\\n\ 1476 ((m) >= HOST_BITS_PER_WIDE_INT) \\\n\
1088 ? ~(unsigned HOST_WIDE_INT) 0 \\\n\ 1477 ? HOST_WIDE_INT_M1U \\\n\
1089 : ((unsigned HOST_WIDE_INT) 1 << (m)) - 1\n"); 1478 : (HOST_WIDE_INT_1U << (m)) - 1\n");
1090 1479
1091 for_all_modes (c, m) 1480 for_all_modes (c, m)
1092 if (m->precision != (unsigned int)-1) 1481 if (m->precision != (unsigned int)-1)
1093 tagged_printf ("MODE_MASK (%u)", m->precision, m->name); 1482 tagged_printf ("MODE_MASK (%u)", m->precision, m->name);
1094 else 1483 else
1105 struct mode_data *m; 1494 struct mode_data *m;
1106 1495
1107 print_decl ("unsigned char", "mode_inner", "NUM_MACHINE_MODES"); 1496 print_decl ("unsigned char", "mode_inner", "NUM_MACHINE_MODES");
1108 1497
1109 for_all_modes (c, m) 1498 for_all_modes (c, m)
1110 tagged_printf ("%smode", 1499 tagged_printf ("E_%smode",
1111 m->component ? m->component->name : void_mode->name, 1500 c != MODE_PARTIAL_INT && m->component
1501 ? m->component->name : m->name,
1112 m->name); 1502 m->name);
1113 1503
1114 print_closer (); 1504 print_closer ();
1115 } 1505 }
1116 1506
1507 /* Emit mode_unit_size array into insn-modes.c file. */
1508 static void
1509 emit_mode_unit_size (void)
1510 {
1511 int c;
1512 struct mode_data *m;
1513
1514 print_maybe_const_decl ("%sunsigned char", "mode_unit_size",
1515 "NUM_MACHINE_MODES", bytesize);
1516
1517 for_all_modes (c, m)
1518 tagged_printf ("%u",
1519 c != MODE_PARTIAL_INT && m->component
1520 ? m->component->bytesize : m->bytesize, m->name);
1521
1522 print_closer ();
1523 }
1524
1525 /* Emit mode_unit_precision array into insn-modes.c file. */
1526 static void
1527 emit_mode_unit_precision (void)
1528 {
1529 int c;
1530 struct mode_data *m;
1531
1532 print_decl ("unsigned short", "mode_unit_precision", "NUM_MACHINE_MODES");
1533
1534 for_all_modes (c, m)
1535 {
1536 struct mode_data *m2 = (c != MODE_PARTIAL_INT && m->component) ?
1537 m->component : m;
1538 if (m2->precision != (unsigned int)-1)
1539 tagged_printf ("%u", m2->precision, m->name);
1540 else
1541 tagged_printf ("%u*BITS_PER_UNIT", m2->bytesize, m->name);
1542 }
1543
1544 print_closer ();
1545 }
1546
1547
1117 static void 1548 static void
1118 emit_mode_base_align (void) 1549 emit_mode_base_align (void)
1119 { 1550 {
1120 int c; 1551 int c;
1121 struct mode_data *m; 1552 struct mode_data *m;
1122 1553
1123 print_maybe_const_decl ("%sunsigned char", 1554 print_maybe_const_decl ("%sunsigned short",
1124 "mode_base_align", "NUM_MACHINE_MODES", 1555 "mode_base_align", "NUM_MACHINE_MODES",
1125 alignment); 1556 alignment);
1126 1557
1127 for_all_modes (c, m) 1558 for_all_modes (c, m)
1128 tagged_printf ("%u", m->alignment, m->name); 1559 tagged_printf ("%u", m->alignment, m->name);
1139 1570
1140 for (c = 0; c < MAX_MODE_CLASS; c++) 1571 for (c = 0; c < MAX_MODE_CLASS; c++)
1141 /* Bleah, all this to get the comment right for MIN_MODE_INT. */ 1572 /* Bleah, all this to get the comment right for MIN_MODE_INT. */
1142 tagged_printf ("MIN_%s", mode_class_names[c], 1573 tagged_printf ("MIN_%s", mode_class_names[c],
1143 modes[c] 1574 modes[c]
1144 ? (modes[c]->precision != 1 1575 ? ((c != MODE_INT || modes[c]->precision != 1)
1145 ? modes[c]->name 1576 ? modes[c]->name
1146 : (modes[c]->next 1577 : (modes[c]->next
1147 ? modes[c]->next->name 1578 ? modes[c]->next->name
1148 : void_mode->name)) 1579 : void_mode->name))
1149 : void_mode->name); 1580 : void_mode->name);
1206 A size adjustment forces us to recalculate the alignment too. */ 1637 A size adjustment forces us to recalculate the alignment too. */
1207 for (a = adj_bytesize; a; a = a->next) 1638 for (a = adj_bytesize; a; a = a->next)
1208 { 1639 {
1209 printf ("\n /* %s:%d */\n s = %s;\n", 1640 printf ("\n /* %s:%d */\n s = %s;\n",
1210 a->file, a->line, a->adjustment); 1641 a->file, a->line, a->adjustment);
1211 printf (" mode_size[%smode] = s;\n", a->mode->name); 1642 printf (" mode_size[E_%smode] = s;\n", a->mode->name);
1212 printf (" mode_base_align[%smode] = s & (~s + 1);\n", 1643 printf (" mode_unit_size[E_%smode] = s;\n", a->mode->name);
1644 printf (" mode_base_align[E_%smode] = s & (~s + 1);\n",
1213 a->mode->name); 1645 a->mode->name);
1214 1646
1215 for (m = a->mode->contained; m; m = m->next_cont) 1647 for (m = a->mode->contained; m; m = m->next_cont)
1216 { 1648 {
1217 switch (m->cl) 1649 switch (m->cl)
1218 { 1650 {
1219 case MODE_COMPLEX_INT: 1651 case MODE_COMPLEX_INT:
1220 case MODE_COMPLEX_FLOAT: 1652 case MODE_COMPLEX_FLOAT:
1221 printf (" mode_size[%smode] = 2*s;\n", m->name); 1653 printf (" mode_size[E_%smode] = 2*s;\n", m->name);
1222 printf (" mode_base_align[%smode] = s & (~s + 1);\n", 1654 printf (" mode_unit_size[E_%smode] = s;\n", m->name);
1655 printf (" mode_base_align[E_%smode] = s & (~s + 1);\n",
1223 m->name); 1656 m->name);
1224 break; 1657 break;
1225 1658
1226 case MODE_VECTOR_INT: 1659 case MODE_VECTOR_INT:
1227 case MODE_VECTOR_FLOAT: 1660 case MODE_VECTOR_FLOAT:
1228 case MODE_VECTOR_FRACT: 1661 case MODE_VECTOR_FRACT:
1229 case MODE_VECTOR_UFRACT: 1662 case MODE_VECTOR_UFRACT:
1230 case MODE_VECTOR_ACCUM: 1663 case MODE_VECTOR_ACCUM:
1231 case MODE_VECTOR_UACCUM: 1664 case MODE_VECTOR_UACCUM:
1232 printf (" mode_size[%smode] = %d*s;\n", 1665 printf (" mode_size[E_%smode] = %d*s;\n",
1233 m->name, m->ncomponents); 1666 m->name, m->ncomponents);
1234 printf (" mode_base_align[%smode] = (%d*s) & (~(%d*s)+1);\n", 1667 printf (" mode_unit_size[E_%smode] = s;\n", m->name);
1668 printf (" mode_base_align[E_%smode] = (%d*s) & (~(%d*s)+1);\n",
1235 m->name, m->ncomponents, m->ncomponents); 1669 m->name, m->ncomponents, m->ncomponents);
1236 break; 1670 break;
1237 1671
1238 default: 1672 default:
1239 internal_error ( 1673 internal_error (
1248 ??? This may not be the right thing for vector modes. */ 1682 ??? This may not be the right thing for vector modes. */
1249 for (a = adj_alignment; a; a = a->next) 1683 for (a = adj_alignment; a; a = a->next)
1250 { 1684 {
1251 printf ("\n /* %s:%d */\n s = %s;\n", 1685 printf ("\n /* %s:%d */\n s = %s;\n",
1252 a->file, a->line, a->adjustment); 1686 a->file, a->line, a->adjustment);
1253 printf (" mode_base_align[%smode] = s;\n", a->mode->name); 1687 printf (" mode_base_align[E_%smode] = s;\n", a->mode->name);
1254 1688
1255 for (m = a->mode->contained; m; m = m->next_cont) 1689 for (m = a->mode->contained; m; m = m->next_cont)
1256 { 1690 {
1257 switch (m->cl) 1691 switch (m->cl)
1258 { 1692 {
1259 case MODE_COMPLEX_INT: 1693 case MODE_COMPLEX_INT:
1260 case MODE_COMPLEX_FLOAT: 1694 case MODE_COMPLEX_FLOAT:
1261 printf (" mode_base_align[%smode] = s;\n", m->name); 1695 printf (" mode_base_align[E_%smode] = s;\n", m->name);
1262 break; 1696 break;
1263 1697
1264 case MODE_VECTOR_INT: 1698 case MODE_VECTOR_INT:
1265 case MODE_VECTOR_FLOAT: 1699 case MODE_VECTOR_FLOAT:
1266 case MODE_VECTOR_FRACT: 1700 case MODE_VECTOR_FRACT:
1267 case MODE_VECTOR_UFRACT: 1701 case MODE_VECTOR_UFRACT:
1268 case MODE_VECTOR_ACCUM: 1702 case MODE_VECTOR_ACCUM:
1269 case MODE_VECTOR_UACCUM: 1703 case MODE_VECTOR_UACCUM:
1270 printf (" mode_base_align[%smode] = %d*s;\n", 1704 printf (" mode_base_align[E_%smode] = %d*s;\n",
1271 m->name, m->ncomponents); 1705 m->name, m->ncomponents);
1272 break; 1706 break;
1273 1707
1274 default: 1708 default:
1275 internal_error ( 1709 internal_error (
1283 /* Ibit adjustments don't have to propagate. */ 1717 /* Ibit adjustments don't have to propagate. */
1284 for (a = adj_ibit; a; a = a->next) 1718 for (a = adj_ibit; a; a = a->next)
1285 { 1719 {
1286 printf ("\n /* %s:%d */\n s = %s;\n", 1720 printf ("\n /* %s:%d */\n s = %s;\n",
1287 a->file, a->line, a->adjustment); 1721 a->file, a->line, a->adjustment);
1288 printf (" mode_ibit[%smode] = s;\n", a->mode->name); 1722 printf (" mode_ibit[E_%smode] = s;\n", a->mode->name);
1289 } 1723 }
1290 1724
1291 /* Fbit adjustments don't have to propagate. */ 1725 /* Fbit adjustments don't have to propagate. */
1292 for (a = adj_fbit; a; a = a->next) 1726 for (a = adj_fbit; a; a = a->next)
1293 { 1727 {
1294 printf ("\n /* %s:%d */\n s = %s;\n", 1728 printf ("\n /* %s:%d */\n s = %s;\n",
1295 a->file, a->line, a->adjustment); 1729 a->file, a->line, a->adjustment);
1296 printf (" mode_fbit[%smode] = s;\n", a->mode->name); 1730 printf (" mode_fbit[E_%smode] = s;\n", a->mode->name);
1297 } 1731 }
1298 1732
1299 /* Real mode formats don't have to propagate anywhere. */ 1733 /* Real mode formats don't have to propagate anywhere. */
1300 for (a = adj_format; a; a = a->next) 1734 for (a = adj_format; a; a = a->next)
1301 printf ("\n /* %s:%d */\n REAL_MODE_FORMAT (%smode) = %s;\n", 1735 printf ("\n /* %s:%d */\n REAL_MODE_FORMAT (E_%smode) = %s;\n",
1302 a->file, a->line, a->mode->name, a->adjustment); 1736 a->file, a->line, a->mode->name, a->adjustment);
1303 1737
1304 puts ("}"); 1738 puts ("}");
1305 } 1739 }
1306 1740
1334 "mode_fbit", "NUM_MACHINE_MODES", 1768 "mode_fbit", "NUM_MACHINE_MODES",
1335 fbit); 1769 fbit);
1336 1770
1337 for_all_modes (c, m) 1771 for_all_modes (c, m)
1338 tagged_printf ("%u", m->fbit, m->name); 1772 tagged_printf ("%u", m->fbit, m->name);
1773
1774 print_closer ();
1775 }
1776
1777 /* Emit __intN for all modes. */
1778
1779 static void
1780 emit_mode_int_n (void)
1781 {
1782 int c;
1783 struct mode_data *m;
1784 struct mode_data **mode_sort;
1785 int n_modes = 0;
1786 int i, j;
1787
1788 print_decl ("int_n_data_t", "int_n_data", "");
1789
1790 n_modes = 0;
1791 for_all_modes (c, m)
1792 if (m->int_n)
1793 n_modes ++;
1794 mode_sort = XALLOCAVEC (struct mode_data *, n_modes);
1795
1796 n_modes = 0;
1797 for_all_modes (c, m)
1798 if (m->int_n)
1799 mode_sort[n_modes++] = m;
1800
1801 /* Yes, this is a bubblesort, but there are at most four (and
1802 usually only 1-2) entries to sort. */
1803 for (i = 0; i<n_modes - 1; i++)
1804 for (j = i + 1; j < n_modes; j++)
1805 if (mode_sort[i]->int_n > mode_sort[j]->int_n)
1806 std::swap (mode_sort[i], mode_sort[j]);
1807
1808 for (i = 0; i < n_modes; i ++)
1809 {
1810 m = mode_sort[i];
1811 printf(" {\n");
1812 tagged_printf ("%u", m->int_n, m->name);
1813 printf ("{ E_%smode },", m->name);
1814 printf(" },\n");
1815 }
1339 1816
1340 print_closer (); 1817 print_closer ();
1341 } 1818 }
1342 1819
1343 1820
1349 emit_mode_class (); 1826 emit_mode_class ();
1350 emit_mode_precision (); 1827 emit_mode_precision ();
1351 emit_mode_size (); 1828 emit_mode_size ();
1352 emit_mode_nunits (); 1829 emit_mode_nunits ();
1353 emit_mode_wider (); 1830 emit_mode_wider ();
1831 emit_mode_complex ();
1354 emit_mode_mask (); 1832 emit_mode_mask ();
1355 emit_mode_inner (); 1833 emit_mode_inner ();
1834 emit_mode_unit_size ();
1835 emit_mode_unit_precision ();
1356 emit_mode_base_align (); 1836 emit_mode_base_align ();
1357 emit_class_narrowest_mode (); 1837 emit_class_narrowest_mode ();
1358 emit_real_format_for_mode (); 1838 emit_real_format_for_mode ();
1359 emit_mode_adjustments (); 1839 emit_mode_adjustments ();
1360 emit_mode_ibit (); 1840 emit_mode_ibit ();
1361 emit_mode_fbit (); 1841 emit_mode_fbit ();
1842 emit_mode_int_n ();
1362 } 1843 }
1363 1844
1364 static void 1845 static void
1365 emit_min_insn_modes_c (void) 1846 emit_min_insn_modes_c (void)
1366 { 1847 {
1367 emit_min_insn_modes_c_header (); 1848 emit_min_insn_modes_c_header ();
1368 emit_mode_name (); 1849 emit_mode_name ();
1369 emit_mode_class (); 1850 emit_mode_class ();
1851 emit_mode_nunits ();
1370 emit_mode_wider (); 1852 emit_mode_wider ();
1853 emit_mode_inner ();
1371 emit_class_narrowest_mode (); 1854 emit_class_narrowest_mode ();
1372 } 1855 }
1373 1856
1374 /* Master control. */ 1857 /* Master control. */
1375 int 1858 int
1376 main (int argc, char **argv) 1859 main (int argc, char **argv)
1377 { 1860 {
1378 bool gen_header = false, gen_min = false; 1861 bool gen_header = false, gen_inlines = false, gen_min = false;
1379 progname = argv[0]; 1862 progname = argv[0];
1380 1863
1381 if (argc == 1) 1864 if (argc == 1)
1382 ; 1865 ;
1383 else if (argc == 2 && !strcmp (argv[1], "-h")) 1866 else if (argc == 2 && !strcmp (argv[1], "-h"))
1384 gen_header = true; 1867 gen_header = true;
1868 else if (argc == 2 && !strcmp (argv[1], "-i"))
1869 gen_inlines = true;
1385 else if (argc == 2 && !strcmp (argv[1], "-m")) 1870 else if (argc == 2 && !strcmp (argv[1], "-m"))
1386 gen_min = true; 1871 gen_min = true;
1387 else 1872 else
1388 { 1873 {
1389 error ("usage: %s [-h|-m] > file", progname); 1874 error ("usage: %s [-h|-i|-m] > file", progname);
1390 return FATAL_EXIT_CODE; 1875 return FATAL_EXIT_CODE;
1391 } 1876 }
1392 1877
1393 modes_by_name = htab_create_alloc (64, hash_mode, eq_mode, 0, xcalloc, free); 1878 modes_by_name = htab_create_alloc (64, hash_mode, eq_mode, 0, xcalloc, free);
1394 1879
1400 1885
1401 calc_wider_mode (); 1886 calc_wider_mode ();
1402 1887
1403 if (gen_header) 1888 if (gen_header)
1404 emit_insn_modes_h (); 1889 emit_insn_modes_h ();
1890 else if (gen_inlines)
1891 emit_insn_modes_inline_h ();
1405 else if (gen_min) 1892 else if (gen_min)
1406 emit_min_insn_modes_c (); 1893 emit_min_insn_modes_c ();
1407 else 1894 else
1408 emit_insn_modes_c (); 1895 emit_insn_modes_c ();
1409 1896