2 ## --------------------------------------------------------------------------
4 ## Copyright 1996-2013 The NASM Authors - All Rights Reserved
5 ## See the file AUTHORS included with the NASM distribution for
6 ## the specific copyright holders.
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted provided that the following
10 ## conditions are met:
12 ## * Redistributions of source code must retain the above copyright
13 ## notice, this list of conditions and the following disclaimer.
14 ## * Redistributions in binary form must reproduce the above
15 ## copyright notice, this list of conditions and the following
16 ## disclaimer in the documentation and/or other materials provided
17 ## with the distribution.
19 ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
20 ## CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
21 ## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 ## DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 ## NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 ## LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 ## OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 ## EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ## --------------------------------------------------------------------------
38 # Parse insns.dat and produce generated source code files
40 require 'insns-iflags.pl';
42 # Opcode prefixes which need their own opcode tables
43 # LONGER PREFIXES FIRST!
44 @disasm_prefixes = qw(0F24 0F25 0F38 0F3A 0F7A 0FA6 0FA7 0F);
46 # This should match MAX_OPERANDS from nasm.h
49 # Add VEX/XOP prefixes
50 @vex_class = ( 'vex', 'xop', 'evex' );
51 $vex_classes = scalar(@vex_class);
54 for ($c = 0; $c < $vex_classes; $c++) {
55 $vexmap{$vex_class[$c]} = $c;
56 for ($m = 0; $m < 32; $m++) {
57 for ($p = 0; $p < 4; $p++) {
58 push(@vexlist, sprintf("%s%02X%01X", $vex_class[$c], $m, $p));
62 @disasm_prefixes = (@vexlist, @disasm_prefixes);
64 @bytecode_count = (0) x
256;
66 print STDERR
"Reading insns.dat...\n";
70 foreach $arg ( @ARGV ) {
71 if ( $arg =~ /^\-/ ) {
72 if ( $arg =~ /^\-([abdin]|f[hc])$/ ) {
75 die "$0: Unknown option: ${arg}\n";
82 $fname = "insns.dat" unless $fname = $args[0];
83 open (F
, $fname) || die "unable to open $fname";
93 next if ( /^\s*(\;.*|)$/ ); # comments or blank lines
95 unless (/^\s*(\S+)\s+(\S+)\s+(\S+|\[.*\])\s+(\S+)\s*$/) {
96 warn "line $line does not contain four fields\n";
99 @fields = ($1, $2, $3, $4);
100 @field_list = ([@fields, 0]);
102 if ($fields[1] =~ /\*/) {
103 # This instruction has relaxed form(s)
104 if ($fields[2] !~ /^\[/) {
105 warn "line $line has an * operand but uses raw bytecodes\n";
110 @ops = split(/,/, $fields[1]);
111 for ($oi = 0; $oi < scalar @ops; $oi++) {
112 if ($ops[$oi] =~ /\*$/) {
114 warn "line $line has a first operand with a *\n";
121 for ($oi = 1; $oi < (1 << scalar @ops); $oi++) {
122 if (($oi & ~$opmask) == 0) {
125 for ($oj = 0; $oj < scalar(@ops); $oj++) {
127 push(@xops, $ops[$oj]);
131 push(@field_list, [$fields[0], join(',', @xops),
132 $fields[2], $fields[3], $oi]);
137 foreach $fptr (@field_list) {
139 ($formatted, $nd) = format_insn
(@fields);
142 $aname = "aa_$fields[0]";
143 push @
$aname, $formatted;
145 if ( $fields[0] =~ /cc$/ ) {
146 # Conditional instruction
147 $k_opcodes_cc{$fields[0]}++;
149 # Unconditional instruction
150 $k_opcodes{$fields[0]}++;
152 if ($formatted && !$nd) {
153 push @big, $formatted;
154 my @sseq = startseq
($fields[2], $fields[4]);
156 if (!defined($dinstables{$i})) {
157 $dinstables{$i} = [];
159 push(@
{$dinstables{$i}}, $#big);
168 # Generate the bytecode array. At this point, @bytecode_list contains
169 # the full set of bytecodes.
172 # Sort by descending length
173 @bytecode_list = sort { scalar(@
$b) <=> scalar(@
$a) } @bytecode_list;
174 @bytecode_array = ();
177 foreach $bl (@bytecode_list) {
178 my $h = hexstr
(@
$bl);
179 next if (defined($bytecode_pos{$h}));
181 push(@bytecode_array, $bl);
183 $bytecode_pos{$h} = $bytecode_next;
188 undef @bytecode_list;
190 @opcodes = sort keys(%k_opcodes);
191 @opcodes_cc = sort keys(%k_opcodes_cc);
193 if ( !defined($output) || $output eq 'b') {
194 print STDERR
"Writing insnsb.c...\n";
198 print B
"/* This file auto-generated from insns.dat by insns.pl" .
199 " - don't edit it */\n\n";
201 print B
"#include \"nasm.h\"\n";
202 print B
"#include \"insns.h\"\n\n";
204 print B
"const uint8_t nasm_bytecodes[$bytecode_next] = {\n";
207 foreach $bl (@bytecode_array) {
208 printf B
" /* %5d */ ", $p;
219 print B
" * Bytecode frequencies (including reuse):\n";
221 for ($i = 0; $i < 32; $i++) {
223 for ($j = 0; $j < 256; $j += 32) {
224 print B
" |" if ($j);
225 printf B
" %3o:%4d", $i+$j, $bytecode_count[$i+$j];
234 if ( !defined($output) || $output eq 'a' ) {
235 print STDERR
"Writing insnsa.c...\n";
239 print A
"/* This file auto-generated from insns.dat by insns.pl" .
240 " - don't edit it */\n\n";
242 print A
"#include \"nasm.h\"\n";
243 print A
"#include \"insns.h\"\n\n";
245 foreach $i (@opcodes, @opcodes_cc) {
246 print A
"static const struct itemplate instrux_${i}[] = {\n";
248 foreach $j (@
$aname) {
249 print A
" ", codesubst
($j), "\n";
251 print A
" ITEMPLATE_END\n};\n\n";
253 print A
"const struct itemplate * const nasm_instructions[] = {\n";
254 foreach $i (@opcodes, @opcodes_cc) {
255 print A
" instrux_${i},\n";
262 if ( !defined($output) || $output eq 'd' ) {
263 print STDERR
"Writing insnsd.c...\n";
267 print D
"/* This file auto-generated from insns.dat by insns.pl" .
268 " - don't edit it */\n\n";
270 print D
"#include \"nasm.h\"\n";
271 print D
"#include \"insns.h\"\n\n";
273 print D
"static const struct itemplate instrux[] = {\n";
276 printf D
" /* %4d */ %s\n", $n++, codesubst
($j);
280 foreach $h (sort(keys(%dinstables))) {
281 next if ($h eq ''); # Skip pseudo-instructions
282 print D
"\nstatic const struct itemplate * const itable_${h}[] = {\n";
283 foreach $j (@
{$dinstables{$h}}) {
284 print D
" instrux + $j,\n";
290 foreach $h (@disasm_prefixes, '') {
291 for ($c = 0; $c < 256; $c++) {
292 $nn = sprintf("%s%02X", $h, $c);
293 if ($is_prefix{$nn} || defined($dinstables{$nn})) {
294 # At least one entry in this prefix table
295 push(@prefix_list, $h);
302 foreach $h (@prefix_list) {
304 print D
"static " unless ($h eq '');
305 print D
"const struct disasm_index ";
306 print D
($h eq '') ?
'itable' : "itable_$h";
307 print D
"[256] = {\n";
308 for ($c = 0; $c < 256; $c++) {
309 $nn = sprintf("%s%02X", $h, $c);
310 if ($is_prefix{$nn}) {
311 die "$fname: ambiguous decoding of $nn\n"
312 if (defined($dinstables{$nn}));
313 printf D
" /* 0x%02x */ { itable_%s, -1 },\n", $c, $nn;
314 } elsif (defined($dinstables{$nn})) {
315 printf D
" /* 0x%02x */ { itable_%s, %u },\n", $c,
316 $nn, scalar(@
{$dinstables{$nn}});
318 printf D
" /* 0x%02x */ { NULL, 0 },\n", $c;
324 printf D
"\nconst struct disasm_index * const itable_vex[NASM_VEX_CLASSES][32][4] =\n";
326 for ($c = 0; $c < $vex_classes; $c++) {
328 for ($m = 0; $m < 32; $m++) {
330 for ($p = 0; $p < 4; $p++) {
331 $vp = sprintf("%s%02X%01X", $vex_class[$c], $m, $p);
333 ($is_prefix{$vp} ?
sprintf("itable_%s,", $vp) : 'NULL,');
344 if ( !defined($output) || $output eq 'i' ) {
345 print STDERR
"Writing insnsi.h...\n";
349 print I
"/* This file is auto-generated from insns.dat by insns.pl" .
350 " - don't edit it */\n\n";
351 print I
"/* This file in included by nasm.h */\n\n";
353 print I
"/* Instruction names */\n\n";
354 print I
"#ifndef NASM_INSNSI_H\n";
355 print I
"#define NASM_INSNSI_H 1\n\n";
356 print I
"enum opcode {\n";
358 foreach $i (@opcodes, @opcodes_cc) {
359 print I
"\tI_${i},\n";
361 $len++ if ( $i =~ /cc$/ ); # Condition codes can be 3 characters long
362 $maxlen = $len if ( $len > $maxlen );
364 print I
"\tI_none = -1\n";
366 print I
"#define MAX_INSLEN ", $maxlen, "\n";
367 print I
"#define NASM_VEX_CLASSES ", $vex_classes, "\n";
368 print I
"#define NO_DECORATOR\t{", join(',',(0) x
$MAX_OPERANDS), "}\n";
369 print I
"#define FIRST_COND_OPCODE I_", $opcodes_cc[0], "\n\n";
370 print I
"#endif /* NASM_INSNSI_H */\n";
375 if ( !defined($output) || $output eq 'n' ) {
376 print STDERR
"Writing insnsn.c...\n";
380 print N
"/* This file is auto-generated from insns.dat by insns.pl" .
381 " - don't edit it */\n\n";
382 print N
"#include \"tables.h\"\n\n";
384 print N
"const char * const nasm_insn_names[] = {";
386 foreach $i (@opcodes, @opcodes_cc) {
387 print N
"," if ( !$first );
390 $ilower =~ s/cc$//; # Remove conditional cc suffix
391 $ilower =~ tr/A-Z/a-z/; # Change to lower case (Perl 4 compatible)
392 print N
"\n\t\"${ilower}\"";
398 if ( !defined($output) || $output eq 'fh') {
402 if ( !defined($output) || $output eq 'fc') {
406 printf STDERR
"Done: %d instructions\n", $insns;
408 # Count primary bytecodes, for statistics
409 sub count_bytecodes
(@
) {
411 foreach my $bc (@_) {
416 $bytecode_count[$bc]++;
417 if ($bc >= 01 && $bc <= 04) {
419 } elsif (($bc & ~03) == 010) {
421 } elsif (($bc & ~013) == 0144) {
423 } elsif ($bc == 0172 || $bc == 0173) {
425 } elsif (($bc & ~3) == 0260 || $bc == 0270) { # VEX
427 } elsif (($bc & ~3) == 0240 || $bc == 0250) { # EVEX
429 } elsif ($bc == 0330) {
435 sub format_insn
($$$$$) {
436 my ($opcode, $operands, $codes, $flags, $relax) = @_;
437 my $num, $nd = 0, $rawflags, $flagsindex;
439 my $op, @ops, $opp, @opx, @oppx, @decos, @opevex;
441 return (undef, undef) if $operands eq "ignore";
443 # format the operands
444 $operands =~ s/\*//g;
445 $operands =~ s/:/|colon,/g;
448 if ($operands ne 'void') {
449 foreach $op (split(/,/, $operands)) {
452 foreach $opp (split(/\|/, $op)) {
454 if ($opp =~ s/^(b(32|64)|mask|z|er|sae)$//) {
458 if ($opp =~ s/(?<!\d)(8|16|32|64|80|128|256|512)$//) {
459 push(@oppx, "bits$1");
461 $opp =~ s/^mem$/memory/;
462 $opp =~ s/^memory_offs$/mem_offs/;
463 $opp =~ s/^imm$/immediate/;
464 $opp =~ s/^([a-z]+)rm$/rm_$1/;
465 $opp =~ s/^rm$/rm_gpr/;
466 $opp =~ s/^reg$/reg_gpr/;
467 # only for evex insns, high-16 regs are allowed
468 if ($codes !~ /(^|\s)evex\./) {
469 $opp =~ s/^(rm_[xyz]mm)$/$1_l16/;
470 $opp =~ s/^([xyz]mm)reg$/$1_l16/;
472 push(@opx, $opp, @oppx) if $opp;
474 $op = join('|', @opx);
476 push(@decos, (@opevex ?
join('|', @opevex) : '0'));
481 while (scalar(@ops) < $MAX_OPERANDS) {
485 $operands = join(',', @ops);
486 $operands =~ tr/a-z/A-Z/;
488 $decorators = "{" . join(',', @decos) . "}";
489 if ($decorators =~ /^{(0,)+0}$/) {
490 $decorators = "NO_DECORATOR";
492 $decorators =~ tr/a-z/A-Z/;
495 $nd = 1 if $flags =~ /(^|\,)ND($|\,)/;
496 $flags =~ s/(^|\,)ND($|\,)/\1/g;
497 $flags =~ s/(^|\,)X64($|\,)/\1LONG,X86_64\2/g;
498 $flags .= ",EVEX" if ($codes =~ /evex\./);
500 $flagsindex = insns_flag_index
(split(',',$flags));
502 die "Error in flags $rawflags" if not defined($flagsindex);
504 @bytecode = (decodify
($codes, $relax), 0);
505 push(@bytecode_list, [@bytecode]);
506 $codes = hexstr
(@bytecode);
507 count_bytecodes
(@bytecode);
509 ("{I_$opcode, $num, {$operands}, $decorators, \@\@CODES-$codes\@\@, $flagsindex},", $nd);
513 # Look for @@CODES-xxx@@ sequences and replace them with the appropriate
514 # offset into nasm_bytecodes
520 while ($s =~ /\@\@CODES-([0-9A-F]+)\@\@/) {
521 my $pos = $bytecode_pos{$1};
522 if (!defined($pos)) {
523 die "$fname: no position assigned to byte code $1\n";
525 $s = $` . "nasm_bytecodes+${pos}" . "$'";
531 my ($prefix, @list) = @_;
536 push(@l, sprintf("%s%02X", $prefix, $x));
543 # Turn a code string into a sequence of bytes
546 # Although these are C-syntax strings, by convention they should have
547 # only octal escapes (for directives) and hexadecimal escapes
548 # (for verbatim bytes)
549 my($codestr, $relax) = @_;
551 if ($codestr =~ /^\s*\[([^\]]*)\]\s*$/) {
552 return byte_code_compile($1, $relax);
558 unless ($codestr eq 'ignore') {
560 if ($c =~ /^\\x([0-9a-f]+)(.*)$/i) {
561 push(@codes, hex $1);
564 } elsif ($c =~ /^\\([0-7]{1,3})(.*)$/) {
565 push(@codes, oct $1);
569 die "$fname: unknown code format in \"$codestr\"\n";
577 # Turn a numeric list into a hex string
583 $s .= sprintf("%02X", $c);
588 # Here we determine the range of possible starting bytes for a given
589 # instruction. We need only consider the codes:
590 # \[1234] mean literal bytes, of course
591 # \1[0123] mean byte plus register value
592 # \330 means byte plus condition code
593 # \0 or \340 mean give up and return empty set
594 # \34[4567] mean PUSH/POP of segment registers: special case
595 # \17[234] skip is4 control byte
596 # \26x \270 skip VEX control bytes
597 # \24x \250 skip EVEX control bytes
599 my ($codestr, $relax) = @_;
606 @codes = decodify($codestr, $relax);
608 while ($c0 = shift(@codes)) {
610 if ($c0 >= 01 && $c0 <= 04) {
614 if ($c0 >= 01 && $c0 <= 04) {
616 $fbs .= sprintf("%02X", shift(@codes));
624 foreach $pfx (@disasm_prefixes) {
625 if (substr($fbs, 0, length($pfx)) eq $pfx) {
627 $fbs = substr($fbs, length($pfx));
633 return ($prefix.substr($fbs,0,2));
636 unshift(@codes, $c0);
637 } elsif ($c0 >= 010 && $c0 <= 013) {
638 return addprefix($prefix, $c1..($c1+7));
639 } elsif (($c0 & ~013) == 0144) {
640 return addprefix($prefix, $c1, $c1|2);
641 } elsif ($c0 == 0330) {
642 return addprefix($prefix, $c1..($c1+15));
643 } elsif ($c0 == 0 || $c0 == 0340) {
645 } elsif (($c0 & ~3) == 0260 || $c0 == 0270 ||
646 ($c0 & ~3) == 0240 || $c0 == 0250) {
649 $wlp = shift(@codes);
652 $prefix .= sprintf('%s%02X%01X', $vex_class[$c], $m, $wlp & 3);
654 my $tuple = shift(@codes);
656 } elsif ($c0 >= 0172 && $c0 <= 173) {
657 shift(@codes); # Skip is4 control byte
659 # We really need to be able to distinguish "forbidden"
660 # and "ignorable" codes here
666 # EVEX tuple types offset is 0300. e.g. 0301 is for full vector(fv).
689 if (defined $tuple_codes{$tuplestr}) {
690 return 0300 + $tuple_codes{$tuplestr};
692 die "Undefined tuple type : $tuplestr\n";
697 # This function takes a series of byte codes in a format which is more
698 # typical of the Intel documentation, and encode it.
700 # The format looks like:
702 # [operands: opcodes]
704 # The operands word lists the order of the operands:
706 # r = register field in the modr/m
710 # s = register field of is4/imz2 field
711 # - = implicit (unencoded) operand
712 # x = indeX register of mib. 014..017 bytecodes are used.
714 # For an operand that should be filled into more than one field,
715 # enter it as e.g. "r+v".
717 sub byte_code_compile($$) {
718 my($str, $relax) = @_;
730 'ib,u' => 024, # Unsigned imm8
732 'ib,s' => 0274, # imm8 sign-extended to opsize or bits
733 'iwd' => 034, # imm16 or imm32, depending on opsize
735 'id,s' => 0254, # imm32 sign-extended to 64 bits
736 'iwdq' => 044, # imm16/32/64, depending on addrsize
740 'rel' => 064, # 16 or 32 bit relative operand
745 'o16' => 0320, # 16-bit operand size
746 'o32' => 0321, # 32-bit operand size
747 'odf' => 0322, # Operand size is default
748 'o64' => 0324, # 64-bit operand size requiring REX.W
749 'o64nw' => 0323, # Implied 64-bit operand size (no REX.W)
752 'adf' => 0312, # Address size is default
756 'f2i' => 0332, # F2 prefix, but 66 for operand size is OK
757 'f3i' => 0333, # F3 prefix, but 66 for operand size is OK
766 'nohi' => 0325, # Use spl/bpl/sil/dil even without REX
767 'nof3' => 0326, # No REP 0xF3 prefix permitted
768 'norep' => 0331, # No REP prefix permitted
769 'wait' => 0341, # Needs a wait prefix
771 'jcc8' => 0370, # Match only if Jcc possible with single byte
772 'jmp8' => 0371, # Match only if JMP possible with single byte
773 'jlen' => 0373, # Length of jump
778 # This instruction takes XMM VSIB
783 # This instruction takes YMM VSIB
788 # This instruction takes ZMM VSIB
794 unless ($str =~ /^(([^\s:]*)\:*([^\s:]*)\:|)\s*(.*\S)\s*$/) {
795 die "$fname: $line: cannot parse: [$str]\n";
798 $tuple = "\L$3"; # Tuple type for AVX512
802 for ($i = 0; $i < length($opr); $i++) {
803 my $c = substr($opr,$i,1);
814 $tup = tupletype($tuple);
818 foreach $op (split(/\s*(?:\s|(?=[\/\\]))/, $opc)) {
819 my $pc = $plain_codes{$op};
824 } elsif ($prefix_ok && $op =~ /^(66|f2|f3|np)$/) {
825 # 66/F2/F3 prefix used as an opcode extension, or np = no prefix
828 } elsif ($op eq 'f2') {
830 } elsif ($op eq 'f3') {
835 } elsif ($op =~ /^[0-9a-f]{2}$/) {
836 if (defined($litix) && $litix+$codes[$litix]+1 == scalar @codes &&
837 $codes[$litix] < 4) {
839 push(@codes, hex $op);
841 $litix = scalar(@codes);
842 push(@codes, 01, hex $op);
845 } elsif ($op eq '/r') {
846 if (!defined($oppos{'r'}) || !defined($oppos{'m'})) {
847 die "$fname: $line: $op requires r and m operands\n";
849 $opex = (($oppos{'m'} & 4) ? 06 : 0) |
850 (($oppos{'r'} & 4) ? 05 : 0);
851 push(@codes, $opex) if ($opex);
852 # if mib is composed with two separate operands - ICC style
853 push(@codes, 014 + ($oppos{'x'} & 3)) if (defined($oppos{'x'}));
854 push(@codes, 0100 + (($oppos{'m'} & 3) << 3) + ($oppos{'r'} & 3));
856 } elsif ($op =~ m:^/([0-7])$:) {
857 if (!defined($oppos{'m'})) {
858 die "$fname: $line: $op requires m operand\n";
860 push(@codes, 06) if ($oppos{'m'} & 4);
861 push(@codes, 0200 + (($oppos{'m'} & 3) << 3) + $1);
863 } elsif ($op =~ /^(vex|xop)(|\..*)$/) {
865 my ($m,$w,$l,$p) = (undef,2,undef,0);
867 my @subops = split(/\./, $op);
868 shift @subops; # Drop prefix
869 foreach $oq (@subops) {
870 if ($oq eq '128' || $oq eq 'l0' || $oq eq 'lz') {
872 } elsif ($oq eq '256' || $oq eq 'l1') {
874 } elsif ($oq eq 'lig') {
876 } elsif ($oq eq 'w0') {
878 } elsif ($oq eq 'w1') {
880 } elsif ($oq eq 'wig') {
882 } elsif ($oq eq 'ww') {
884 } elsif ($oq eq 'p0') {
886 } elsif ($oq eq '66' || $oq eq 'p1') {
888 } elsif ($oq eq 'f3' || $oq eq 'p2') {
890 } elsif ($oq eq 'f2' || $oq eq 'p3') {
892 } elsif ($oq eq '0f') {
894 } elsif ($oq eq '0f38') {
896 } elsif ($oq eq '0f3a') {
898 } elsif ($oq =~ /^m([0-9]+)$/) {
900 } elsif ($oq eq 'nds' || $oq eq 'ndd' || $oq eq 'dds') {
901 if (!defined($oppos{'v'})) {
902 die "$fname: $line: vex.$oq without 'v' operand\n";
906 die "$fname: $line: undefined VEX subcode: $oq\n";
909 if (!defined($m) || !defined($w) || !defined($l) || !defined($p)) {
910 die "$fname: $line: missing fields in VEX specification\n";
912 if (defined($oppos{'v'}) && !$has_nds) {
913 die "$fname: $line: 'v' operand without vex.nds or vex.ndd\n";
915 push(@codes, defined($oppos{'v'}) ? 0260+($oppos{'v'} & 3) : 0270,
916 ($c << 6)+$m, ($w << 4)+($l << 2)+$p);
918 } elsif ($op =~ /^(evex)(|\..*)$/) {
920 my ($m,$w,$l,$p) = (undef,2,undef,0);
922 my @subops = split(/\./, $op);
923 shift @subops; # Drop prefix
924 foreach $oq (@subops) {
925 if ($oq eq '128' || $oq eq 'l0' || $oq eq 'lz' || $oq eq 'lig') {
927 } elsif ($oq eq '256' || $oq eq 'l1') {
929 } elsif ($oq eq '512' || $oq eq 'l2') {
931 } elsif ($oq eq 'w0') {
933 } elsif ($oq eq 'w1') {
935 } elsif ($oq eq 'wig') {
937 } elsif ($oq eq 'ww') {
939 } elsif ($oq eq 'p0') {
941 } elsif ($oq eq '66' || $oq eq 'p1') {
943 } elsif ($oq eq 'f3' || $oq eq 'p2') {
945 } elsif ($oq eq 'f2' || $oq eq 'p3') {
947 } elsif ($oq eq '0f') {
949 } elsif ($oq eq '0f38') {
951 } elsif ($oq eq '0f3a') {
953 } elsif ($oq =~ /^m([0-9]+)$/) {
955 } elsif ($oq eq 'nds' || $oq eq 'ndd' || $oq eq 'dds') {
956 if (!defined($oppos{'v'})) {
957 die "$fname: $line: evex.$oq without 'v' operand\n";
961 die "$fname: $line: undefined EVEX subcode: $oq\n";
964 if (!defined($m) || !defined($w) || !defined($l) || !defined($p)) {
965 die "$fname: $line: missing fields in EVEX specification\n";
967 if (defined($oppos{'v'}) && !$has_nds) {
968 die "$fname: $line: 'v' operand without evex.nds or evex.ndd\n";
970 push(@codes, defined($oppos{'v'}) ? 0240+($oppos{'v'} & 3) : 0250,
971 ($c << 6)+$m, ($w << 4)+($l << 2)+$p, $tup);
973 } elsif (defined $imm_codes{$op}) {
975 if ($last_imm lt 'i') {
976 die "$fname: $line: seg without an immediate operand\n";
980 if ($last_imm gt 'j') {
981 die "$fname: $line: too many immediate operands\n";
984 if (!defined($oppos{$last_imm})) {
985 die "$fname: $line: $op without '$last_imm' operand\n";
987 push(@codes, 05) if ($oppos{$last_imm} & 4);
988 push(@codes, $imm_codes{$op} + ($oppos{$last_imm} & 3));
990 } elsif ($op eq '/is4') {
991 if (!defined($oppos{'s'})) {
992 die "$fname: $line: $op without 's' operand\n";
994 if (defined($oppos{'i'})) {
995 push(@codes, 0172, ($oppos{'s'} << 3)+$oppos{'i'});
997 push(@codes, 05) if ($oppos{'s'} & 4);
998 push(@codes, 0174+($oppos{'s'} & 3));
1001 } elsif ($op =~ /^\/is4\=([0-9]+)$/) {
1003 if (!defined($oppos{'s'})) {
1004 die "$fname: $line: $op without 's' operand\n";
1006 if ($imm < 0 || $imm > 15) {
1007 die "$fname: $line: invalid imm4 value for $op: $imm\n";
1009 push(@codes, 0173, ($oppos{'s'} << 4) + $imm);
1011 } elsif ($op =~ /^([0-9a-f]{2})\+c$/) {
1012 push(@codes, 0330, hex $1);
1014 } elsif ($op =~ /^([0-9a-f]{2})\+r$/) {
1015 if (!defined($oppos{'r'})) {
1016 die "$fname: $line: $op without 'r' operand\n";
1018 push(@codes, 05) if ($oppos{'r'} & 4);
1019 push(@codes, 010 + ($oppos{'r'} & 3), hex $1);
1021 } elsif ($op =~ /^\\([0-7]+|x[0-9a-f]{2})$/) {
1022 # Escape to enter literal bytecodes
1023 push(@codes, oct $1);
1025 die "$fname: $line: unknown operation: $op\n";