2022.07.02

Specialize in Gem5

Problem to solve

decoder/one_byte_opcodes.isa => build/X86/arch/x86/generated/decode-method.cc.inc
MOV(Bv, Iv)                  => x86_macroop::MOV_R_I(...)

decoder/one_byte_opcodes.isa:

'X86ISA::OneByteOpcode': decode OPCODE_OP_TOP5 {
  format Inst {
    0x17: MOV(Bv,Iv);
}}

format Inst is defined in src/arch/x86/isa/formats/multi.isa:

def format Inst(*opTypeSet) {{
    blocks = specializeInst(Name, list(opTypeSet), EmulEnv())
    (header_output, decoder_output,
     decode_block, exec_output) = blocks.makeList()
}};

specializeInst is defined in src/arch/x86/isa/specialize.isa:

def specializeInst(Name, opTypes, env):
  ...

Here Name = "MOV", opTypes = ("Bv", "Iv").

r prefixed opType is reg, others are tag. Tag specialization are listed as below.

Note: '_P' means RIP relative addressing

tagmeaningsizesuffix
Breg encoded in opcode_R
Mmemory encoded in modrm(rm)_M/_P
Cctl reg encoded in modrm(reg)_C
Ddbg reg encoded in modrm(reg)_D
Sseg selector encoded in modrm(reg)_S
Greg encoded in modrm(reg)_R
Preg encoded in modrm(reg)-_MMX
Treg encoded in modrm(reg)_R
Vreg encoded in modrm(reg)-_XMM
Ereg or mem encoded in modrm(rm)_R/_M/_P
Qreg or mem encoded in modrm(rm)-_MMX/_M/_P
Wreg or mem encoded in modrm(rm)-_XMM/_M/_P
Iimmediate-_I
Jimmediate-_I
Oimmediate: mem offset_MI
PRreg encoded in modrm(rm)-_MMX
Rreg encoded in modrm(rm)_R
VRreg encoded in modrm(rm)-_XMM
Xstring inst mem (index&seg internally)_M
Ystring inst mem (index&seg internally)_M

Available data size is defined in src/arch/x86/isa/macroop.isa: getAllocator

bwdqvzdp
1248OPSIZE(OPSIZE==8)?4:OPSIZE(rex_w?8:4)

string specialization

See gem5/src/arch/x86/isa/formats/string.isa

_E for repe, _N for repne, e.g. STOS_E_M