diff options
author | Jan Beulich <jbeulich@suse.com> | 2024-03-28 11:47:59 +0100 |
---|---|---|
committer | Jan Beulich <jbeulich@suse.com> | 2024-03-28 11:47:59 +0100 |
commit | cd9ca24dd21821f203279d48d8ae1b67cc4aa5fe (patch) | |
tree | 39fb221ed632c46917c68f0e0a37e3dacc0ceb4d | |
parent | 4ef6173d2dfeafd33deedf7ce0d384cfbcf1170d (diff) | |
download | fsf-binutils-gdb-cd9ca24dd21821f203279d48d8ae1b67cc4aa5fe.zip fsf-binutils-gdb-cd9ca24dd21821f203279d48d8ae1b67cc4aa5fe.tar.gz fsf-binutils-gdb-cd9ca24dd21821f203279d48d8ae1b67cc4aa5fe.tar.bz2 |
x86: templatize INC/DEC
With the multitude of new APX templates, it finally becomes desirable to
further remove redundancy by also templatizing basic arithmetic insns.
Start with the simplest case, accompanied by a necessary adjustment to
i386-gen (such that template uses can also be at the start of a line).
While there also drop a bogus (meaningless / unreachable) "break" as
well as a unused variable (which I'm surprised compilers didn't warn
about).
-rw-r--r-- | opcodes/i386-gen.c | 24 | ||||
-rw-r--r-- | opcodes/i386-opc.tbl | 16 | ||||
-rw-r--r-- | opcodes/i386-tbl.h | 108 |
3 files changed, 80 insertions, 68 deletions
diff --git a/opcodes/i386-gen.c b/opcodes/i386-gen.c index 2133121..3f63d15 100644 --- a/opcodes/i386-gen.c +++ b/opcodes/i386-gen.c @@ -1538,10 +1538,10 @@ opcode_hash_eq (const void *p, const void *q) return strcmp (name, entry->name) == 0; } -static void +static bool parse_template (char *buf, int lineno) { - char sep, *end, *name; + char sep, *end, *ptr; struct template *tmpl; struct template_instance *last_inst = NULL; @@ -1568,8 +1568,16 @@ parse_template (char *buf, int lineno) prev->next = tmpl->next; else templates = tmpl->next; - return; + return true; } + + /* Check whether this actually is a reference to an existing template: + If there's '>' ahead of ':', it can't be a new template definition + (and template undefs have are dealt with above). */ + ptr = strchr (buf, '>'); + if (ptr != NULL && ptr < end) + return false; + *end++ = '\0'; remove_trailing_whitespaces (buf); @@ -1644,6 +1652,8 @@ parse_template (char *buf, int lineno) tmpl->next = templates; templates = tmpl; + + return true; } static unsigned int @@ -1900,10 +1910,12 @@ process_i386_opcodes (FILE *table) /* Ignore comments. */ case '\0': continue; - break; + case '<': - parse_template (p, lineno); - continue; + if (parse_template (p, lineno)) + continue; + break; + default: if (!marker) continue; diff --git a/opcodes/i386-opc.tbl b/opcodes/i386-opc.tbl index 1c770e2..eed55f9 100644 --- a/opcodes/i386-opc.tbl +++ b/opcodes/i386-opc.tbl @@ -316,10 +316,6 @@ add, 0x4, 0, W|No_sSuf, { Imm8|Imm16|Imm32|Imm32S, Acc|Byte|Word|Dword|Qword } add, 0x80/0, APX_F, W|Modrm|CheckOperandSize|No_sSuf|DstVVVV|EVexMap4|NF, { Imm8|Imm16|Imm32|Imm32S, Reg8|Reg16|Reg32|Reg64|Unspecified|BaseIndex, Reg8|Reg16|Reg32|Reg64} add, 0x80/0, 0, W|Modrm|No_sSuf|HLEPrefixLock, { Imm8|Imm16|Imm32|Imm32S, Reg8|Reg16|Reg32|Reg64|Unspecified|BaseIndex } -inc, 0x40, No64, No_bSuf|No_sSuf|No_qSuf, { Reg16|Reg32 } -inc, 0xfe/0, APX_F, W|Modrm|No_sSuf|CheckOperandSize|DstVVVV|EVexMap4|NF, {Reg8|Reg16|Reg32|Reg64|Unspecified|BaseIndex, Reg8|Reg16|Reg32|Reg64} -inc, 0xfe/0, 0, W|Modrm|No_sSuf|HLEPrefixLock, { Reg8|Reg16|Reg32|Reg64|Unspecified|BaseIndex } - sub, 0x28, APX_F, D|W|CheckOperandSize|Modrm|No_sSuf|DstVVVV|EVexMap4|NF|Optimize, { Reg8|Reg16|Reg32|Reg64, Reg8|Reg16|Reg32|Reg64|Unspecified|BaseIndex, Reg8|Reg16|Reg32|Reg64, } sub, 0x28, 0, D|W|CheckOperandSize|Modrm|No_sSuf|HLEPrefixLock|Optimize, { Reg8|Reg16|Reg32|Reg64, Reg8|Reg16|Reg32|Reg64|Unspecified|BaseIndex } sub, 0x83/5, APX_F, Modrm|No_bSuf|No_sSuf|DstVVVV|EVexMap4|NF, { Imm8S, Reg16|Reg32|Reg64|Unspecified|BaseIndex, Reg16|Reg32|Reg64 } @@ -328,10 +324,6 @@ sub, 0x2c, 0, W|No_sSuf, { Imm8|Imm16|Imm32|Imm32S, Acc|Byte|Word|Dword|Qword } sub, 0x80/5, APX_F, W|Modrm|CheckOperandSize|No_sSuf|DstVVVV|EVexMap4|NF, { Imm8|Imm16|Imm32|Imm32S, Reg8|Reg16|Reg32|Reg64|Unspecified|BaseIndex, Reg8|Reg16|Reg32|Reg64 } sub, 0x80/5, 0, W|Modrm|No_sSuf|HLEPrefixLock, { Imm8|Imm16|Imm32|Imm32S, Reg8|Reg16|Reg32|Reg64|Unspecified|BaseIndex } -dec, 0x48, No64, No_bSuf|No_sSuf|No_qSuf, { Reg16|Reg32 } -dec, 0xfe/1, APX_F, W|Modrm|CheckOperandSize|No_sSuf|DstVVVV|EVexMap4|NF, { Reg8|Reg16|Reg32|Reg64|Unspecified|BaseIndex, Reg8|Reg16|Reg32|Reg64 } -dec, 0xfe/1, 0, W|Modrm|No_sSuf|HLEPrefixLock, { Reg8|Reg16|Reg32|Reg64|Unspecified|BaseIndex } - sbb, 0x18, APX_F, D|W|CheckOperandSize|Modrm|No_sSuf|DstVVVV|EVexMap4, { Reg8|Reg16|Reg32|Reg64, Reg8|Reg16|Reg32|Reg64|Unspecified|BaseIndex, Reg8|Reg16|Reg32|Reg64 } sbb, 0x18, 0, D|W|CheckOperandSize|Modrm|No_sSuf|HLEPrefixLock, { Reg8|Reg16|Reg32|Reg64, Reg8|Reg16|Reg32|Reg64|Unspecified|BaseIndex } sbb, 0x83/3, APX_F, Modrm|CheckOperandSize|No_bSuf|No_sSuf|DstVVVV|EVexMap4, { Imm8S, Reg16|Reg32|Reg64|Unspecified|BaseIndex, Reg16|Reg32|Reg64 } @@ -385,6 +377,14 @@ adc, 0x14, 0, W|No_sSuf, { Imm8|Imm16|Imm32|Imm32S, Acc|Byte|Word|Dword|Qword } adc, 0x80/2, APX_F, W|Modrm|CheckOperandSize|No_sSuf|DstVVVV|EVexMap4, { Imm8|Imm16|Imm32|Imm32S, Reg8|Reg16|Reg32|Reg64|Unspecified|BaseIndex, Reg8|Reg16|Reg32|Reg64 } adc, 0x80/2, 0, W|Modrm|No_sSuf|HLEPrefixLock, { Imm8|Imm16|Imm32|Imm32S, Reg8|Reg16|Reg32|Reg64|Unspecified|BaseIndex } +<incdec:opc, inc:0, dec:1> + +<incdec>, 0x40 | (<incdec:opc> << 3), No64, No_bSuf|No_sSuf|No_qSuf, { Reg16|Reg32 } +<incdec>, 0xfe/<incdec:opc>, APX_F, W|Modrm|No_sSuf|CheckOperandSize|DstVVVV|EVexMap4|NF, {Reg8|Reg16|Reg32|Reg64|Unspecified|BaseIndex, Reg8|Reg16|Reg32|Reg64} +<incdec>, 0xfe/<incdec:opc>, 0, W|Modrm|No_sSuf|HLEPrefixLock, { Reg8|Reg16|Reg32|Reg64|Unspecified|BaseIndex } + +<incdec> + neg, 0xf6/3, APX_F, W|Modrm|CheckOperandSize|No_sSuf|DstVVVV|EVexMap4|NF, { Reg8|Reg16|Reg32|Reg64|Unspecified|BaseIndex, Reg8|Reg16|Reg32|Reg64 } neg, 0xf6/3, 0, W|Modrm|No_sSuf|HLEPrefixLock, { Reg8|Reg16|Reg32|Reg64|Unspecified|BaseIndex } diff --git a/opcodes/i386-tbl.h b/opcodes/i386-tbl.h index f17d94e..1b10f13 100644 --- a/opcodes/i386-tbl.h +++ b/opcodes/i386-tbl.h @@ -868,32 +868,6 @@ static const insn_template i386_optab[] = 0, 0, 0, 0, 0, 0 } }, { { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0 } } } }, - { MN_inc, 0x40, 1, SPACE_BASE, None, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1,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, { MN_sub, 0x28, 3, SPACE_EVEXMAP4, None, { 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, @@ -970,32 +944,6 @@ static const insn_template i386_optab[] = 0, 0, 0, 0, 0, 0 } }, { { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0 } } } }, - { MN_dec, 0x48, 1, SPACE_BASE, None, - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0 }, - { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 } }, - { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, - { { { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 0 } } } }, - { MN_dec, 0xfe, 2, SPACE_EVEXMAP4, 1, - { 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 0 }, - { { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0 } }, - { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, - { { { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, - 0, 0, 0, 0, 1, 0 } }, - { { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, - 0, 0, 0, 0, 0, 0 } } } }, - { MN_dec, 0xfe, 1, SPACE_BASE, 1, - { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 5, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, - { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, - { { { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, - 0, 0, 0, 0, 1, 0 } } } }, { MN_sbb, 0x18, 3, SPACE_EVEXMAP4, None, { 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -1464,6 +1412,58 @@ static const insn_template i386_optab[] = 0, 0, 0, 0, 0, 0 } }, { { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0 } } } }, + { MN_inc, 0x40 | (0 <<3), 1, SPACE_BASE, None, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, + 0 }, + { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 } }, + { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, + { { { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0 } } } }, + { MN_inc, 0xfe, 2, SPACE_EVEXMAP4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0, 0, 0, 0, 1, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0 } } } }, + { MN_dec, 0xfe, 2, SPACE_EVEXMAP4, 1, + { 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0 }, + { { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0 } }, + { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, + { { { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, + 0, 0, 0, 0, 1, 0 } }, + { { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, + 0, 0, 0, 0, 0, 0 } } } }, + { MN_dec, 0xfe, 1, SPACE_BASE, 1, + { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 5, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, + { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, + { { { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, + 0, 0, 0, 0, 1, 0 } } } }, { MN_neg, 0xf6, 2, SPACE_EVEXMAP4, 3, { 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, @@ -41378,8 +41378,8 @@ static const i386_op_off_t i386_op_sets[] = 48, 49, 50, 52, 56, 60, 61, 62, 63, 65, 67, 69, 70, 71, 72, 73, 74, 76, 78, 80, 82, 83, 84, 85, - 92, 95, 102, 105, 113, 117, 120, 127, - 134, 141, 142, 149, 151, 153, 154, 155, + 92, 99, 107, 111, 114, 121, 128, 135, + 136, 143, 146, 149, 151, 153, 154, 155, 156, 157, 159, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 181, 183, 185, 192, 199, 210, 221, |