AVX FMA: Instruction table for the AVX FMA instructions
[nasm.git] / regs.pl
blob9c0d96e2a075011732df1b140f5dd444b3004002
1 #!/usr/bin/perl
3 # Read regs.dat and output regs.h and regs.c (included in names.c)
6 $nline = 0;
8 sub toint($) {
9 my($v) = @_;
11 return ($v =~ /^0/) ? oct $v : $v+0;
14 sub process_line($) {
15 my($line) = @_;
16 my @v;
18 if ( $line !~ /^\s*(\S+)\s*(\S+)\s*(\S+)\s*([0-9]+)$/i ) {
19 die "regs.dat:$nline: invalid input\n";
21 $reg = $1;
22 $aclass = $2;
23 $dclasses = $3;
24 $x86regno = toint($4);
26 if ($reg =~ /^(.*[^0-9])([0-9]+)\-([0-9]+)(|[^0-9].*)$/) {
27 $nregs = $3-$2+1;
28 $reg = $1.$2.$4;
29 $reg_nr = $2;
30 $reg_prefix = $1;
31 $reg_suffix = $4;
32 } else {
33 $nregs = 1;
34 undef $reg_prefix, $reg_suffix;
37 while ($nregs--) {
38 $regs{$reg} = $aclass;
39 $regvals{$reg} = $x86regno;
41 foreach $dclass (split(/,/, $dclasses)) {
42 if ( !defined($disclass{$dclass}) ) {
43 $disclass{$dclass} = [];
46 $disclass{$dclass}->[$x86regno] = $reg;
49 # Compute the next register, if any
50 if (defined($reg_prefix)) {
51 $x86regno++;
52 $reg_nr++;
53 $reg = sprintf("%s%u%s", $reg_prefix, $reg_nr, $reg_suffix);
54 } else {
55 # Not a dashed sequence
56 die if ($nregs);
61 ($fmt, $file) = @ARGV;
63 %regs = ();
64 %regvals = ();
65 %disclass = ();
66 open(REGS, "< ${file}") or die "$0: Cannot open $file\n";
67 while ( defined($line = <REGS>) ) {
68 $nline++;
70 chomp $line;
71 $line =~ s/\s*(\#.*|)$//;
73 next if ( $line eq '' );
75 process_line($line);
77 close(REGS);
79 if ( $fmt eq 'h' ) {
80 # Output regs.h
81 print "/* automatically generated from $file - do not edit */\n\n";
82 $expr_regs = 1;
83 printf "#define EXPR_REG_START %d\n", $expr_regs;
84 print "enum reg_enum {\n";
85 $attach = ' = EXPR_REG_START'; # EXPR_REG_START == 1
86 foreach $reg ( sort(keys(%regs)) ) {
87 print " R_\U${reg}\E${attach},\n";
88 $attach = '';
89 $expr_regs++;
91 print " REG_ENUM_LIMIT,\n";
92 # Unfortunately the code uses both 0 and -1 as "no register" in
93 # different places...
94 print " R_zero = 0,\n";
95 print " R_none = -1";
96 print "};\n\n";
97 printf "#define EXPR_REG_END %d\n", $expr_regs-1;
98 foreach $reg ( sort(keys(%regs)) ) {
99 printf "#define %-15s %2d\n", "REG_NUM_\U${reg}", $regvals{$reg};
101 print "\n";
102 } elsif ( $fmt eq 'c' ) {
103 # Output regs.c
104 print "/* automatically generated from $file - do not edit */\n\n";
105 print "#include \"tables.h\"\n\n";
106 print "const char * const nasm_reg_names[] = "; $ch = '{';
107 # This one has no dummy entry for 0
108 foreach $reg ( sort(keys(%regs)) ) {
109 print "$ch\n \"${reg}\"";
110 $ch = ',';
112 print "\n};\n";
113 } elsif ( $fmt eq 'fc' ) {
114 # Output regflags.c
115 print "/* automatically generated from $file - do not edit */\n\n";
116 print "#include \"tables.h\"\n";
117 print "#include \"nasm.h\"\n\n";
118 print "const int32_t nasm_reg_flags[] = {\n";
119 print " 0"; # Dummy entry for 0
120 foreach $reg ( sort(keys(%regs)) ) {
121 print ",\n ", $regs{$reg}; # Print the class of the register
123 print "\n};\n";
124 } elsif ( $fmt eq 'vc' ) {
125 # Output regvals.c
126 print "/* automatically generated from $file - do not edit */\n\n";
127 print "#include \"tables.h\"\n\n";
128 print "const int nasm_regvals[] = {\n";
129 print " -1"; # Dummy entry for 0
130 foreach $reg ( sort(keys(%regs)) ) {
131 printf ",\n %2d", $regvals{$reg}; # Print the regval of the register
133 print "\n};\n";
134 } elsif ( $fmt eq 'dc' ) {
135 # Output regdis.c
136 print "/* automatically generated from $file - do not edit */\n\n";
137 print "#include \"regs.h\"\n\n";
138 foreach $class ( sort(keys(%disclass)) ) {
139 printf "const enum reg_enum nasm_rd_%-8s[%2d] = {",
140 $class, scalar @{$disclass{$class}};
141 @foo = @{$disclass{$class}};
142 @bar = ();
143 for ( $i = 0 ; $i < scalar(@foo) ; $i++ ) {
144 if (defined($foo[$i])) {
145 push(@bar, "R_\U$foo[$i]\E");
146 } else {
147 die "$0: No register name for class $class, value $i\n";
150 print join(',', @bar), "};\n";
152 } elsif ( $fmt eq 'dh' ) {
153 # Output regdis.h
154 print "/* automatically generated from $file - do not edit */\n";
155 foreach $class ( sort(keys(%disclass)) ) {
156 printf "const enum reg_enum nasm_rd_%-8s[%2d];\n",
157 $class, scalar @{$disclass{$class}};
159 } else {
160 die "$0: Unknown output format\n";