diff options
author | Jan Beulich <jbeulich@suse.com> | 2020-06-25 09:25:52 +0200 |
---|---|---|
committer | Jan Beulich <jbeulich@suse.com> | 2020-06-25 09:25:52 +0200 |
commit | a5aeccd9d33b8cea1ca9145fdeb1be4978cadaeb (patch) | |
tree | ca0931b6ae2235fa6850a61a35a721da45d28ed0 /gas/config/tc-i386.c | |
parent | 40d231b4fbcb68d5906a949acd1d421123d74082 (diff) | |
download | gdb-a5aeccd9d33b8cea1ca9145fdeb1be4978cadaeb.zip gdb-a5aeccd9d33b8cea1ca9145fdeb1be4978cadaeb.tar.gz gdb-a5aeccd9d33b8cea1ca9145fdeb1be4978cadaeb.tar.bz2 |
x86-64: honor REX prefixes for SSE2AVX
Legacy encoded insns do so, and their automatic conversion to AVX ones
ought to produce functionally identical code. Therefore explicit REX
prefixes cannot simply be ignored. This is in particular relevant
because at least PCMPESTR{I,M}'s 64-bit forms couldn't be expressed in
older gas by other than using a REX64 prefix.
Diffstat (limited to 'gas/config/tc-i386.c')
-rw-r--r-- | gas/config/tc-i386.c | 65 |
1 files changed, 37 insertions, 28 deletions
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c index 5a652a9..c84192e 100644 --- a/gas/config/tc-i386.c +++ b/gas/config/tc-i386.c @@ -7408,6 +7408,15 @@ process_operands (void) unnecessary segment overrides. */ const seg_entry *default_seg = 0; + if (i.tm.opcode_modifier.sse2avx) + { + /* Legacy encoded insns allow explicit REX prefixes, so these prefixes + need converting. */ + i.rex |= i.prefix[REX_PREFIX] & (REX_W | REX_R | REX_X | REX_B); + i.prefix[REX_PREFIX] = 0; + i.rex_encoding = 0; + } + if (i.tm.opcode_modifier.sse2avx && i.tm.opcode_modifier.vexvvvv) { unsigned int dupl = i.operands; @@ -7645,6 +7654,25 @@ process_operands (void) return 1; } +static INLINE void set_rex_vrex (const reg_entry *r, unsigned int rex_bit, + bfd_boolean do_sse2avx) +{ + if (r->reg_flags & RegRex) + { + if (i.rex & rex_bit) + as_bad (_("same type of prefix used twice")); + i.rex |= rex_bit; + } + else if (do_sse2avx && (i.rex & rex_bit) && i.vex.register_specifier) + { + gas_assert (i.vex.register_specifier == r); + i.vex.register_specifier += 8; + } + + if (r->reg_flags & RegVRex) + i.vrex |= rex_bit; +} + static const seg_entry * build_modrm_byte (void) { @@ -7875,27 +7903,15 @@ build_modrm_byte (void) else i.has_regxmm = TRUE; } - if ((i.op[dest].regs->reg_flags & RegRex) != 0) - i.rex |= REX_R; - if ((i.op[dest].regs->reg_flags & RegVRex) != 0) - i.vrex |= REX_R; - if ((i.op[source].regs->reg_flags & RegRex) != 0) - i.rex |= REX_B; - if ((i.op[source].regs->reg_flags & RegVRex) != 0) - i.vrex |= REX_B; + set_rex_vrex (i.op[dest].regs, REX_R, i.tm.opcode_modifier.sse2avx); + set_rex_vrex (i.op[source].regs, REX_B, FALSE); } else { i.rm.reg = i.op[source].regs->reg_num; i.rm.regmem = i.op[dest].regs->reg_num; - if ((i.op[dest].regs->reg_flags & RegRex) != 0) - i.rex |= REX_B; - if ((i.op[dest].regs->reg_flags & RegVRex) != 0) - i.vrex |= REX_B; - if ((i.op[source].regs->reg_flags & RegRex) != 0) - i.rex |= REX_R; - if ((i.op[source].regs->reg_flags & RegVRex) != 0) - i.vrex |= REX_R; + set_rex_vrex (i.op[dest].regs, REX_B, i.tm.opcode_modifier.sse2avx); + set_rex_vrex (i.op[source].regs, REX_R, FALSE); } if (flag_code != CODE_64BIT && (i.rex & REX_R)) { @@ -7945,10 +7961,7 @@ build_modrm_byte (void) } } i.sib.index = i.index_reg->reg_num; - if ((i.index_reg->reg_flags & RegRex) != 0) - i.rex |= REX_X; - if ((i.index_reg->reg_flags & RegVRex) != 0) - i.vrex |= REX_X; + set_rex_vrex (i.index_reg, REX_X, FALSE); } default_seg = &ds; @@ -8314,18 +8327,14 @@ build_modrm_byte (void) if (i.tm.extension_opcode != None) { i.rm.regmem = i.op[op].regs->reg_num; - if ((i.op[op].regs->reg_flags & RegRex) != 0) - i.rex |= REX_B; - if ((i.op[op].regs->reg_flags & RegVRex) != 0) - i.vrex |= REX_B; + set_rex_vrex (i.op[op].regs, REX_B, + i.tm.opcode_modifier.sse2avx); } else { i.rm.reg = i.op[op].regs->reg_num; - if ((i.op[op].regs->reg_flags & RegRex) != 0) - i.rex |= REX_R; - if ((i.op[op].regs->reg_flags & RegVRex) != 0) - i.vrex |= REX_R; + set_rex_vrex (i.op[op].regs, REX_R, + i.tm.opcode_modifier.sse2avx); } } |