Skip to content

Commit a2eabbe

Browse files
author
H. Peter Anvin
committed
insns: drop special handling of conditional instructions
Instead of handling conditional instructions ad hoc, generate individual instruction patterns as normal. This simplifies the code and makes CMPccXADD support simpler (otherwise it would be necessary to hack in the handling of a condition code in the middle of an instruction.) Signed-off-by: H. Peter Anvin <[email protected]>
1 parent 5fd5426 commit a2eabbe

File tree

10 files changed

+176
-188
lines changed

10 files changed

+176
-188
lines changed

Makefile.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,17 +304,17 @@ doc/warnings.src : doc/warnings.src.time
304304
@: Side effect
305305

306306
# Assembler token hash
307-
asm/tokhash.c: x86/insns.dat x86/regs.dat asm/tokens.dat asm/tokhash.pl \
307+
asm/tokhash.c: x86/insns.dat x86/insnsn.c asm/tokens.dat asm/tokhash.pl \
308308
perllib/phash.ph
309309
$(RUNPERL) $(srcdir)/asm/tokhash.pl c \
310-
$(srcdir)/x86/insns.dat $(srcdir)/x86/regs.dat \
310+
x86/insnsn.c $(srcdir)/x86/regs.dat \
311311
$(srcdir)/asm/tokens.dat > asm/tokhash.c
312312

313313
# Assembler token metadata
314-
asm/tokens.h: x86/insns.dat x86/regs.dat asm/tokens.dat asm/tokhash.pl \
314+
asm/tokens.h: x86/insns.dat x86/insnsn.c asm/tokens.dat asm/tokhash.pl \
315315
perllib/phash.ph
316316
$(RUNPERL) $(srcdir)/asm/tokhash.pl h \
317-
$(srcdir)/x86/insns.dat $(srcdir)/x86/regs.dat \
317+
x86/insnsn.c $(srcdir)/x86/regs.dat \
318318
$(srcdir)/asm/tokens.dat > asm/tokens.h
319319

320320
# Preprocessor token hash

Mkfiles/msvc.mak

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ x86\regs.h: x86\regs.dat x86\regs.pl
234234
WARNFILES = asm\warnings.c include\warnings.h doc\warnings.src
235235

236236
warnings:
237-
$(RM_F) $(WARNFILES)
237+
$(RM_F) $(WARNFILES) $(WARNFILES:=.time)
238238
$(MAKE) asm\warnings.time
239239

240240
asm\warnings.time: $(ALLOBJ_NW:.$(O)=.c)
@@ -263,17 +263,17 @@ doc\warnings.src : doc\warnings.src.time
263263
@: Side effect
264264

265265
# Assembler token hash
266-
asm\tokhash.c: x86\insns.dat x86\regs.dat asm\tokens.dat asm\tokhash.pl \
266+
asm\tokhash.c: x86\insns.dat x86\insnsn.c asm\tokens.dat asm\tokhash.pl \
267267
perllib\phash.ph
268268
$(RUNPERL) $(srcdir)\asm\tokhash.pl c \
269-
$(srcdir)\x86\insns.dat $(srcdir)\x86\regs.dat \
269+
x86\insnsn.c $(srcdir)\x86\regs.dat \
270270
$(srcdir)\asm\tokens.dat > asm\tokhash.c
271271

272272
# Assembler token metadata
273-
asm\tokens.h: x86\insns.dat x86\regs.dat asm\tokens.dat asm\tokhash.pl \
273+
asm\tokens.h: x86\insns.dat x86\insnsn.c asm\tokens.dat asm\tokhash.pl \
274274
perllib\phash.ph
275275
$(RUNPERL) $(srcdir)\asm\tokhash.pl h \
276-
$(srcdir)\x86\insns.dat $(srcdir)\x86\regs.dat \
276+
x86\insnsn.c $(srcdir)\x86\regs.dat \
277277
$(srcdir)\asm\tokens.dat > asm\tokens.h
278278

279279
# Preprocessor token hash

Mkfiles/openwcom.mak

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ x86\regs.h: x86\regs.dat x86\regs.pl
247247
WARNFILES = asm\warnings.c include\warnings.h doc\warnings.src
248248

249249
warnings:
250-
$(RM_F) $(WARNFILES)
250+
$(RM_F) $(WARNFILES) $(WARNFILES:=.time)
251251
$(MAKE) asm\warnings.time
252252

253253
asm\warnings.time: $(ALLOBJ_NW:.$(O)=.c)
@@ -276,17 +276,17 @@ doc\warnings.src : doc\warnings.src.time
276276
@: Side effect
277277

278278
# Assembler token hash
279-
asm\tokhash.c: x86\insns.dat x86\regs.dat asm\tokens.dat asm\tokhash.pl &
279+
asm\tokhash.c: x86\insns.dat x86\insnsn.c asm\tokens.dat asm\tokhash.pl &
280280
perllib\phash.ph
281281
$(RUNPERL) $(srcdir)\asm\tokhash.pl c &
282-
$(srcdir)\x86\insns.dat $(srcdir)\x86\regs.dat &
282+
x86\insnsn.c $(srcdir)\x86\regs.dat &
283283
$(srcdir)\asm\tokens.dat > asm\tokhash.c
284284

285285
# Assembler token metadata
286-
asm\tokens.h: x86\insns.dat x86\regs.dat asm\tokens.dat asm\tokhash.pl &
286+
asm\tokens.h: x86\insns.dat x86\insnsn.c asm\tokens.dat asm\tokhash.pl &
287287
perllib\phash.ph
288288
$(RUNPERL) $(srcdir)\asm\tokhash.pl h &
289-
$(srcdir)\x86\insns.dat $(srcdir)\x86\regs.dat &
289+
x86\insnsn.c $(srcdir)\x86\regs.dat &
290290
$(srcdir)\asm\tokens.dat > asm\tokens.h
291291

292292
# Preprocessor token hash

asm/assemble.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,6 @@
146146
* \325 nohi instruction which always uses spl/bpl/sil/dil
147147
* \326 nof3 instruction not valid with 0xF3 REP prefix. Hint for
148148
disassembler only; for SSE instructions.
149-
* \330 a literal byte follows in the code stream, to be added
150-
* to the condition code value of the instruction.
151149
* \331 norep instruction not valid with REP prefix. Hint for
152150
* disassembler only; for SSE instructions.
153151
* \332 f2i REP prefix (0xF2 byte) used as opcode extension.
@@ -1472,10 +1470,6 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits,
14721470
case 0326:
14731471
break;
14741472

1475-
case 0330:
1476-
codes++, length++;
1477-
break;
1478-
14791473
case 0331:
14801474
break;
14811475

@@ -2188,10 +2182,6 @@ static void gencode(struct out_data *data, insn *ins)
21882182
case 0326:
21892183
break;
21902184

2191-
case 0330:
2192-
out_rawbyte(data, *codes++ ^ get_cond_opcode(ins->condition));
2193-
break;
2194-
21952185
case 0331:
21962186
break;
21972187

asm/parser.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,6 @@ insn *parse_line(char *buffer, insn *result)
748748
}
749749

750750
result->opcode = tokval.t_integer;
751-
result->condition = tokval.t_inttwo;
752751

753752
/*
754753
* INCBIN cannot be satisfied with incorrectly

asm/tokhash.pl

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
require 'phash.ph';
4242

43-
my($output, $insns_dat, $regs_dat, $tokens_dat) = @ARGV;
43+
my($output, $insnsn_c, $regs_dat, $tokens_dat) = @ARGV;
4444

4545
%tokens = ();
4646
@tokendata = ();
@@ -53,33 +53,18 @@
5353
'nle', 'no', 'np', 'ns', 'nz', 'o', 'p', 'pe', 'po', 's', 'z');
5454

5555
#
56-
# Read insns.dat
56+
# Read insnsn.c
5757
#
58-
open(ID, '<', $insns_dat) or die "$0: cannot open $insns_dat: $!\n";
58+
open(ID, '<', $insnsn_c) or die "$0: cannot open $insnsn_c: $!\n";
5959
while (defined($line = <ID>)) {
60-
if ($line =~ /^([\?\@A-Z0-9_]+)(|cc)\s/) {
61-
$insn = $1.$2;
62-
($token = $1) =~ tr/A-Z/a-z/;
63-
64-
if ($2 eq '') {
65-
# Single instruction token
66-
if (!defined($tokens{$token})) {
67-
$tokens{$token} = scalar @tokendata;
68-
push(@tokendata, "\"${token}\", ".length($token).
69-
", TOKEN_INSN, C_none, 0, I_${insn}");
70-
}
71-
} else {
72-
# Conditional instruction
73-
foreach $cc (@conditions) {
74-
my $etok = $token.$cc;
75-
if (!defined($tokens{$etok})) {
76-
$tokens{$etok} = scalar @tokendata;
77-
push(@tokendata, "\"${etok}\", ".length($etok).
78-
", TOKEN_INSN, C_\U$cc\E, 0, I_${insn}");
79-
}
80-
}
81-
}
82-
}
60+
next unless ($line =~ /^\s*\"([\?\@a-z0-9_]+)\"/);
61+
62+
my $token = $1;
63+
next if (defined($tokens{$token})); # This should never happen
64+
65+
$tokens{$token} = scalar @tokendata;
66+
push(@tokendata, "\"${token}\", ".length($token).
67+
", TOKEN_INSN, 0, 0, I_\U${token}");
8368
}
8469
close(ID);
8570

disasm/disasm.c

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* ----------------------------------------------------------------------- *
22
*
3-
* Copyright 1996-2012 The NASM Authors - All Rights Reserved
3+
* Copyright 1996-2022 The NASM Authors - All Rights Reserved
44
* See the file AUTHORS included with the NASM distribution for
55
* the specific copyright holders.
66
*
@@ -506,7 +506,6 @@ static int matches(const struct itemplate *t, uint8_t *data,
506506
ins->oprs[i].segment = ins->oprs[i].disp_size =
507507
(segsize == 64 ? SEG_64BIT : segsize == 32 ? SEG_32BIT : 0);
508508
}
509-
ins->condition = -1;
510509
ins->evex_tuple = 0;
511510
ins->rex = prefix->rex;
512511
memset(ins->prefixes, 0, sizeof ins->prefixes);
@@ -957,16 +956,6 @@ static int matches(const struct itemplate *t, uint8_t *data,
957956
ins->rex |= REX_NH;
958957
break;
959958

960-
case 0330:
961-
{
962-
int t = *r++, d = *data++;
963-
if (d < t || d > t + 15)
964-
return 0;
965-
else
966-
ins->condition = d - t;
967-
break;
968-
}
969-
970959
case 0326:
971960
if (prefix->rep == 0xF3)
972961
return 0;
@@ -1126,12 +1115,6 @@ static int matches(const struct itemplate *t, uint8_t *data,
11261115
return data - origdata;
11271116
}
11281117

1129-
/* Condition names for disassembly, sorted by x86 code */
1130-
static const char * const condition_name[16] = {
1131-
"o", "no", "c", "nc", "z", "nz", "na", "a",
1132-
"s", "ns", "pe", "po", "l", "nl", "ng", "g"
1133-
};
1134-
11351118
int32_t disasm(uint8_t *data, int32_t data_size, char *output, int outbufsize, int segsize,
11361119
int64_t offset, int autosync, iflag_t *prefer)
11371120
{
@@ -1424,12 +1407,8 @@ int32_t disasm(uint8_t *data, int32_t data_size, char *output, int outbufsize, i
14241407
}
14251408

14261409
i = (*p)->opcode;
1427-
if (i >= FIRST_COND_OPCODE)
1428-
slen += snprintf(output + slen, outbufsize - slen, "%s%s",
1429-
nasm_insn_names[i], condition_name[ins.condition]);
1430-
else
1431-
slen += snprintf(output + slen, outbufsize - slen, "%s",
1432-
nasm_insn_names[i]);
1410+
slen += snprintf(output + slen, outbufsize - slen, "%s",
1411+
nasm_insn_names[i]);
14331412

14341413
colon = false;
14351414
is_evex = !!(ins.rex & REX_EV);

include/nasm.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -523,13 +523,6 @@ static inline bool is_register(int reg)
523523
return reg >= EXPR_REG_START && reg < REG_ENUM_LIMIT;
524524
}
525525

526-
enum ccode { /* condition code names */
527-
C_A, C_AE, C_B, C_BE, C_C, C_E, C_G, C_GE, C_L, C_LE, C_NA, C_NAE,
528-
C_NB, C_NBE, C_NC, C_NE, C_NG, C_NGE, C_NL, C_NLE, C_NO, C_NP,
529-
C_NS, C_NZ, C_O, C_P, C_PE, C_PO, C_S, C_Z,
530-
C_none = -1
531-
};
532-
533526
/*
534527
* token flags
535528
*/
@@ -540,17 +533,6 @@ enum ccode { /* condition code names */
540533
#define TFLAG_WARN (1 << 3) /* warning only, treat as ID */
541534
#define TFLAG_DUP (1 << 4) /* valid ID but also has context-specific use */
542535

543-
static inline uint8_t get_cond_opcode(enum ccode c)
544-
{
545-
static const uint8_t ccode_opcodes[] = {
546-
0x7, 0x3, 0x2, 0x6, 0x2, 0x4, 0xf, 0xd, 0xc, 0xe, 0x6, 0x2,
547-
0x3, 0x7, 0x3, 0x5, 0xe, 0xc, 0xd, 0xf, 0x1, 0xb, 0x9, 0x5,
548-
0x0, 0xa, 0xa, 0xb, 0x8, 0x4
549-
};
550-
551-
return ccode_opcodes[(int)c];
552-
}
553-
554536
/*
555537
* REX flags
556538
*/
@@ -766,7 +748,6 @@ typedef struct insn { /* an instruction itself */
766748
char *label; /* the label defined, or NULL */
767749
int prefixes[MAXPREFIX]; /* instruction prefixes, if any */
768750
enum opcode opcode; /* the opcode - not just the string */
769-
enum ccode condition; /* the condition code, if Jcc/SETcc */
770751
int operands; /* how many operands? 0-3 (more if db et al) */
771752
int addr_size; /* address size */
772753
operand oprs[MAX_OPERANDS]; /* the operands, defined as above */

x86/iflags.ph

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ if_("AMXTILE", "AMX tile configuration instructions");
9898
if_("AMXBF16", "AMX bfloat16 multiplication");
9999
if_("AMXINT8", "AMX 8-bit integer multiplication");
100100
if_("FRED", "Flexible Return and Exception Delivery (FRED)");
101+
if_("RAOINT", "Remote atomic operations (RAO-INT)");
102+
if_("UINTR", "User interrupts");
101103

102-
# Put these last [hpa: why?]
104+
# Put these last to minimize their relevance
103105
if_("OBSOLETE", "Instruction removed from architecture");
104106
if_("NEVER", "Instruction never implemented");
105107
if_("NOP", "Instruction is always a (nonintentional) NOP");

0 commit comments

Comments
 (0)