[PATCH v2] x86: Add {imm8}/{imm16}/{imm32} pseudo prefixes

H.J. Lu hjl.tools@gmail.com
Mon Mar 24 18:41:58 GMT 2025


On Mon, Mar 24, 2025 at 9:27 AM Jan Beulich <jbeulich@suse.com> wrote:
>
> On 24.03.2025 17:24, H.J. Lu wrote:
> > Instruction templates with only sign-extended 8-bit immediate operand
> > also have a second template with full-operand-size immediate operand
> > under a different opcode.  Add {imm8}, {imm16} and {imm32} pseudo
> > prefixes as a hint to control immediate size.  Don't match the first
> > template if {imm16} or {imm32} are used.
> >
> > gas/
> >
> >       PR gas/32811
> >       * config/tc-i386.c (pseudo_prefixes): Add avoid_imm8s.
> >       (operand_size_match): Return false for templates with only sign-
> >       extended 8-bit immediate operand if {imm16} or {imm32} are used.
> >       (parse_insn): Handle Prefix_Imm8, Prefix_Imm16 and Prefix_Imm32.
> >       * doc/c-i386.texi: Document {imm8}, {imm16} and {imm32}.
> >       * testsuite/gas/i386/pseudos.s: Add tests for {imm8}, {imm16}
> >       and {imm32}.
> >       * testsuite/gas/i386/x86-64-pseudos.s: Likewise.
> >       * testsuite/gas/i386/pseudos.d: Updated.
> >       * testsuite/gas/i386/x86-64-pseudos.d: Likewise.
> >
> > opcodes/
> >
> >       PR gas/32811
> >       * opcodes/i386-opc.h (Prefix_Imm8): New.
> >       (Prefix_Imm16): Likewise.
> >       (Prefix_Imm32): Likewise.
> >       * i386-opc.tbl: Add {imm8}, {imm16} and {imm32} pseudo prefixes.
> >       * i386-mnem.h: Regenerated.
> >       * i386-tbl.h: Likewise.
> >
> > Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
>
> What's the difference to v1? Importantly {imm16} and {imm32} are still there,

full-operand-size and avoid_imm8s.

> when imo they should be suitably folded.
>

{imm16} and {imm32} are the same internally.  But for users,

{imm16} add $0,%bx
 {imm8} add $0,%bx

are quite clearer than other alternatives.

-- 
H.J.


More information about the Binutils mailing list