Skip to contentSkip to conversation

x86-disas: port x86-mini disassembler to QEMU

PATCH Superseded Michael Clark 1 participant 8 messages Jan 24, 2025 – Jan 26, 2025 Arm/Amlogic Meson SoC support

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover x86-disas: port x86-mini disassembler to QEMU

a port of an embeddable x86 disassembler to QEMU.

- https://github.com/michaeljclark/qemu/tree/x86-mini
- https://github.com/michaeljclark/x86/tree/x86-mini

# x86-mini disassembler

the x86-mini library is a lightweight x86 encoder, decoder, and disassembler that uses extensions to the Intel instruction set metadata format to encode modern VEX/EVEX instructions and legacy instructions using a parameterized LEX (legacy extension) format.

- metadata-driven disassembler with Intel format output.
- written in C11 for compatibility with projects written in C.
- low-level instruction encoder and decoder uses <= 32-bytes.
- python tablegen program to generate C tables from CSV metadata.
- metadata table tool to inspect operand encode and decode tables.
- carefully checked machine-readable instruction set metadata.
- support for REX/VEX/EVEX and preliminary support for REX2.

the x86-mini x86 encoder and decoder library has been written from scratch to be modern and as simple as possible while also covering recent additions to the Intel and AMD 64-bit instruction sets such as the EVEX encodings for recent AVX-512 extensions and soon REX2/ EVEX encodings for Intel APX, as it is written with that in mind.

## interest to the QEMU community

- x86-mini is fast. raw decode performance is ~100-200MiB/sec.
- x86-mini is small. 5 files, ~5 KLOC or ~13 KLOC including tables.
- x86-mini is complete and includes the latest AVX-512 extensions.
- x86-mini is easy to extend and uses extended Intel format metadata.
- x86-mini is documented with detailed info on the metadata format.
- x86-mini has CLI tools for searching x86 instruction set metadata.

it would be nice to have an x86 disassembler building out-of-the-box as I find QEMU's built-in tracing extremely useful and given x86 is a popular target, a small embedded disassembler might be practical.

## techinical notes

- the decoder is table-based and uses a metadata interpreter.
- the decode table is ~66KiB with a ~150KiB acceleration trie.
- there are currently 3658 opcode entries active on x86-64 which expands to 4775 table entries due to parameterization.

after cherry-picking the commits, one can test host and target disassembly support. e.g. for an x86-64 target on an x86-64 host:

$ echo aaa | qemu-x86_64 -d in_asm,out_asm /usr/bin/openssl sha256

## caveats and limitations

- supports 32-bit and 64-bit disassembly, and theoretically 16-bit.
- designed to support 16-bit. base index formats are not done yet.
- x86-64 is exhaustively fuzz-tested against the LLVM disassembler.
- but x86-mini is new and hasn't been battle-tested in production.

## summary and conclusion

the metadata is based on x86-csv but has had numerous inaccuracies fixed plus conversion of legacy instructions to the new LEX format. in effect the metadata has been fuzz-tested against LLVM for x86-64 and ISA coverage is in the order of ~99.9%. the main branch of the linked repo has a procedural fuzzer for metadata-based instruction synthesis that could be useful for generating test cases for QEMU.

## changes in this version

- simplification to memory operand formatting logic.
- fixed VSIB pointer formatting for consistency with LLVM.
- 64-bit disasembly exhaustively fuzz tested against LLVM.
- includes x86 metadata and x86-tablegen.py python script.
- includes x86 metadata opcode and operand documentation.
- addressed non-whitespace related checkpatch.pl warnings.

Michael Clark (4):
x86-disas: add x86-mini instruction set metadata
x86-disas: add x86-mini metadata documentation
x86-disas: add x86-mini metadata tablegen script
x86-disas: add x86-mini disassembler implementation

 disas/disas-host.c                        |    5 +
 disas/meson.build                         |   97 +
 disas/x86-core.c                          | 2689 +++++++++++++++++++++
 disas/x86-data/x86_adx.csv                |    5 +
 disas/x86-data/x86_aes.csv                |   13 +
 disas/x86-data/x86_aeskle.csv             |    3 +
 disas/x86-data/x86_aesklewide.csv         |    3 +
 disas/x86-data/x86_avx.csv                |  375 +++
 disas/x86-data/x86_avx2.csv               |  171 ++
 disas/x86-data/x86_avx5124fmaps.csv       |    5 +
 disas/x86-data/x86_avx5124vnniw.csv       |    3 +
 disas/x86-data/x86_avx512b.csv            |    3 +
 disas/x86-data/x86_avx512bf16.csv         |   10 +
 disas/x86-data/x86_avx512bitalg.csv       |   10 +
 disas/x86-data/x86_avx512bw.csv           |  291 +++
 disas/x86-data/x86_avx512cd.csv           |   19 +
 disas/x86-data/x86_avx512d.csv            |    2 +
 disas/x86-data/x86_avx512dq.csv           |  143 ++
 disas/x86-data/x86_avx512er.csv           |   11 +
 disas/x86-data/x86_avx512f.csv            |  901 +++++++
 disas/x86-data/x86_avx512fp16.csv         |  237 ++
 disas/x86-data/x86_avx512ifma.csv         |    7 +
 disas/x86-data/x86_avx512pf.csv           |   17 +
 disas/x86-data/x86_avx512vbmi.csv         |   13 +
 disas/x86-data/x86_avx512vbmi2.csv        |   61 +
 disas/x86-data/x86_avx512vl.csv           |    2 +
 disas/x86-data/x86_avx512vnni.csv         |   13 +
 disas/x86-data/x86_avx512vp2intersect.csv |    7 +
 disas/x86-data/x86_avx512vpopcntdq.csv    |    7 +
 disas/x86-data/x86_avxneconvert.csv       |   15 +
 disas/x86-data/x86_avxvnni.csv            |    9 +
 disas/x86-data/x86_avxvnniint8.csv        |   13 +
 disas/x86-data/x86_base.csv               |  549 +++++
 disas/x86-data/x86_bmi1.csv               |   13 +
 disas/x86-data/x86_bmi2.csv               |   17 +
 disas/x86-data/x86_cet.csv                |   15 +
 disas/x86-data/x86_cldemote.csv           |    2 +
 disas/x86-data/x86_clwb.csv               |    2 +
 disas/x86-data/x86_enqcmd.csv             |    3 +
 disas/x86-data/x86_f16c.csv               |    5 +
 disas/x86-data/x86_fma.csv                |   97 +
 disas/x86-data/x86_fsgsbase.csv           |    9 +
 disas/x86-data/x86_gfni.csv               |   19 +
 disas/x86-data/x86_hreset.csv             |    2 +
 disas/x86-data/x86_invpcid.csv            |    2 +
 disas/x86-data/x86_lzcnt.csv              |    3 +
 disas/x86-data/x86_mmx.csv                |   60 +
 disas/x86-data/x86_movdir64b.csv          |    2 +
 disas/x86-data/x86_movdiri.csv            |    3 +
 disas/x86-data/x86_mpx.csv                |    9 +
 disas/x86-data/x86_msrlist.csv            |    4 +
 disas/x86-data/x86_ospke.csv              |    3 +
 disas/x86-data/x86_pclmulqdq.csv          |    3 +
 disas/x86-data/x86_pconfig.csv            |    2 +
 disas/x86-data/x86_prefetchw.csv          |    7 +
 disas/x86-data/x86_raoint.csv             |    9 +
 disas/x86-data/x86_rdpid.csv              |    2 +
 disas/x86-data/x86_rdrand.csv             |    2 +
 disas/x86-data/x86_rdseed.csv             |    2 +
 disas/x86-data/x86_rtm.csv                |    5 +
 disas/x86-data/x86_serialize.csv          |    2 +
 disas/x86-data/x86_sha.csv                |    8 +
 disas/x86-data/x86_smap.csv               |    3 +
 disas/x86-data/x86_sse.csv                |   58 +
 disas/x86-data/x86_sse2.csv               |  148 ++
 disas/x86-data/x86_sse3.csv               |   11 +
 disas/x86-data/x86_sse4_1.csv             |   48 +
 disas/x86-data/x86_sse4_2.csv             |    7 +
 disas/x86-data/x86_sse4_3.csv             |    2 +
 disas/x86-data/x86_ssse3.csv              |   33 +
 disas/x86-data/x86_uintr.csv              |    6 +
 disas/x86-data/x86_vaes.csv               |   17 +
 disas/x86-data/x86_vmx.csv                |   14 +
 disas/x86-data/x86_waitpkg.csv            |    4 +
 disas/x86-data/x86_wbnoinvd.csv           |    2 +
 disas/x86-data/x86_x87.csv                |  145 ++
 disas/x86-data/x86_xsaveopt.csv           |    3 +
 disas/x86-disas.c                         |   94 +
 disas/x86.h                               | 1969 +++++++++++++++
 docs/x86-metadata.txt                     |  301 +++
 include/disas/dis-asm.h                   |    1 +
 scripts/x86-tablegen.py                   |  693 ++++++
 target/i386/cpu.c                         |    7 +
 83 files changed, 9587 insertions(+)
 create mode 100644 disas/x86-core.c
 create mode 100644 disas/x86-data/x86_adx.csv
 create mode 100644 disas/x86-data/x86_aes.csv
 create mode 100644 disas/x86-data/x86_aeskle.csv
 create mode 100644 disas/x86-data/x86_aesklewide.csv
 create mode 100644 disas/x86-data/x86_avx.csv
 create mode 100644 disas/x86-data/x86_avx2.csv
 create mode 100644 disas/x86-data/x86_avx5124fmaps.csv
 create mode 100644 disas/x86-data/x86_avx5124vnniw.csv
 create mode 100644 disas/x86-data/x86_avx512b.csv
 create mode 100644 disas/x86-data/x86_avx512bf16.csv
 create mode 100644 disas/x86-data/x86_avx512bitalg.csv
 create mode 100644 disas/x86-data/x86_avx512bw.csv
 create mode 100644 disas/x86-data/x86_avx512cd.csv
 create mode 100644 disas/x86-data/x86_avx512d.csv
 create mode 100644 disas/x86-data/x86_avx512dq.csv
 create mode 100644 disas/x86-data/x86_avx512er.csv
 create mode 100644 disas/x86-data/x86_avx512f.csv
 create mode 100644 disas/x86-data/x86_avx512fp16.csv
 create mode 100644 disas/x86-data/x86_avx512ifma.csv
 create mode 100644 disas/x86-data/x86_avx512pf.csv
 create mode 100644 disas/x86-data/x86_avx512vbmi.csv
 create mode 100644 disas/x86-data/x86_avx512vbmi2.csv
 create mode 100644 disas/x86-data/x86_avx512vl.csv
 create mode 100644 disas/x86-data/x86_avx512vnni.csv
 create mode 100644 disas/x86-data/x86_avx512vp2intersect.csv
 create mode 100644 disas/x86-data/x86_avx512vpopcntdq.csv
 create mode 100644 disas/x86-data/x86_avxneconvert.csv
 create mode 100644 disas/x86-data/x86_avxvnni.csv
 create mode 100644 disas/x86-data/x86_avxvnniint8.csv
 create mode 100644 disas/x86-data/x86_base.csv
 create mode 100644 disas/x86-data/x86_bmi1.csv
 create mode 100644 disas/x86-data/x86_bmi2.csv
 create mode 100644 disas/x86-data/x86_cet.csv
 create mode 100644 disas/x86-data/x86_cldemote.csv
 create mode 100644 disas/x86-data/x86_clwb.csv
 create mode 100644 disas/x86-data/x86_enqcmd.csv
 create mode 100644 disas/x86-data/x86_f16c.csv
 create mode 100644 disas/x86-data/x86_fma.csv
 create mode 100644 disas/x86-data/x86_fsgsbase.csv
 create mode 100644 disas/x86-data/x86_gfni.csv
 create mode 100644 disas/x86-data/x86_hreset.csv
 create mode 100644 disas/x86-data/x86_invpcid.csv
 create mode 100644 disas/x86-data/x86_lzcnt.csv
 create mode 100644 disas/x86-data/x86_mmx.csv
 create mode 100644 disas/x86-data/x86_movdir64b.csv
 create mode 100644 disas/x86-data/x86_movdiri.csv
 create mode 100644 disas/x86-data/x86_mpx.csv
 create mode 100644 disas/x86-data/x86_msrlist.csv
 create mode 100644 disas/x86-data/x86_ospke.csv
 create mode 100644 disas/x86-data/x86_pclmulqdq.csv
 create mode 100644 disas/x86-data/x86_pconfig.csv
 create mode 100644 disas/x86-data/x86_prefetchw.csv
 create mode 100644 disas/x86-data/x86_raoint.csv
 create mode 100644 disas/x86-data/x86_rdpid.csv
 create mode 100644 disas/x86-data/x86_rdrand.csv
 create mode 100644 disas/x86-data/x86_rdseed.csv
 create mode 100644 disas/x86-data/x86_rtm.csv
 create mode 100644 disas/x86-data/x86_serialize.csv
 create mode 100644 disas/x86-data/x86_sha.csv
 create mode 100644 disas/x86-data/x86_smap.csv
 create mode 100644 disas/x86-data/x86_sse.csv
 create mode 100644 disas/x86-data/x86_sse2.csv
 create mode 100644 disas/x86-data/x86_sse3.csv
 create mode 100644 disas/x86-data/x86_sse4_1.csv
 create mode 100644 disas/x86-data/x86_sse4_2.csv
 create mode 100644 disas/x86-data/x86_sse4_3.csv
 create mode 100644 disas/x86-data/x86_ssse3.csv
 create mode 100644 disas/x86-data/x86_uintr.csv
 create mode 100644 disas/x86-data/x86_vaes.csv
 create mode 100644 disas/x86-data/x86_vmx.csv
 create mode 100644 disas/x86-data/x86_waitpkg.csv
 create mode 100644 disas/x86-data/x86_wbnoinvd.csv
 create mode 100644 disas/x86-data/x86_x87.csv
 create mode 100644 disas/x86-data/x86_xsaveopt.csv
 create mode 100644 disas/x86-disas.c
 create mode 100644 disas/x86.h
 create mode 100644 docs/x86-metadata.txt
 create mode 100755 scripts/x86-tablegen.py
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/4 x86-disas: add x86-mini instruction set metadata

this metadata is based on x86-csv with numerous inaccuracies fixed plus conversion of legacy instructions to a new LEX format. this metadata has been fuzz-tested against the LLVM disassembler for x86-64 with 64-bit ISA coverage in the order of ~99.9%.

---
 disas/x86-data/x86_adx.csv                |   5 +
 disas/x86-data/x86_aes.csv                |  13 +
 disas/x86-data/x86_aeskle.csv             |   3 +
 disas/x86-data/x86_aesklewide.csv         |   3 +
 disas/x86-data/x86_avx.csv                | 375 +++++++++
 disas/x86-data/x86_avx2.csv               | 171 ++++
 disas/x86-data/x86_avx5124fmaps.csv       |   5 +
 disas/x86-data/x86_avx5124vnniw.csv       |   3 +
 disas/x86-data/x86_avx512b.csv            |   3 +
 disas/x86-data/x86_avx512bf16.csv         |  10 +
 disas/x86-data/x86_avx512bitalg.csv       |  10 +
 disas/x86-data/x86_avx512bw.csv           | 291 +++++++
 disas/x86-data/x86_avx512cd.csv           |  19 +
 disas/x86-data/x86_avx512d.csv            |   2 +
 disas/x86-data/x86_avx512dq.csv           | 143 ++++
 disas/x86-data/x86_avx512er.csv           |  11 +
 disas/x86-data/x86_avx512f.csv            | 901 ++++++++++++++++++++++
 disas/x86-data/x86_avx512fp16.csv         | 237 ++++++
 disas/x86-data/x86_avx512ifma.csv         |   7 +
 disas/x86-data/x86_avx512pf.csv           |  17 +
 disas/x86-data/x86_avx512vbmi.csv         |  13 +
 disas/x86-data/x86_avx512vbmi2.csv        |  61 ++
 disas/x86-data/x86_avx512vl.csv           |   2 +
 disas/x86-data/x86_avx512vnni.csv         |  13 +
 disas/x86-data/x86_avx512vp2intersect.csv |   7 +
 disas/x86-data/x86_avx512vpopcntdq.csv    |   7 +
 disas/x86-data/x86_avxneconvert.csv       |  15 +
 disas/x86-data/x86_avxvnni.csv            |   9 +
 disas/x86-data/x86_avxvnniint8.csv        |  13 +
 disas/x86-data/x86_base.csv               | 549 +++++++++++++
 disas/x86-data/x86_bmi1.csv               |  13 +
 disas/x86-data/x86_bmi2.csv               |  17 +
 disas/x86-data/x86_cet.csv                |  15 +
 disas/x86-data/x86_cldemote.csv           |   2 +
 disas/x86-data/x86_clwb.csv               |   2 +
 disas/x86-data/x86_enqcmd.csv             |   3 +
 disas/x86-data/x86_f16c.csv               |   5 +
 disas/x86-data/x86_fma.csv                |  97 +++
 disas/x86-data/x86_fsgsbase.csv           |   9 +
 disas/x86-data/x86_gfni.csv               |  19 +
 disas/x86-data/x86_hreset.csv             |   2 +
 disas/x86-data/x86_invpcid.csv            |   2 +
 disas/x86-data/x86_lzcnt.csv              |   3 +
 disas/x86-data/x86_mmx.csv                |  60 ++
 disas/x86-data/x86_movdir64b.csv          |   2 +
 disas/x86-data/x86_movdiri.csv            |   3 +
 disas/x86-data/x86_mpx.csv                |   9 +
 disas/x86-data/x86_msrlist.csv            |   4 +
 disas/x86-data/x86_ospke.csv              |   3 +
 disas/x86-data/x86_pclmulqdq.csv          |   3 +
 disas/x86-data/x86_pconfig.csv            |   2 +
 disas/x86-data/x86_prefetchw.csv          |   7 +
 disas/x86-data/x86_raoint.csv             |   9 +
 disas/x86-data/x86_rdpid.csv              |   2 +
 disas/x86-data/x86_rdrand.csv             |   2 +
 disas/x86-data/x86_rdseed.csv             |   2 +
 disas/x86-data/x86_rtm.csv                |   5 +
 disas/x86-data/x86_serialize.csv          |   2 +
 disas/x86-data/x86_sha.csv                |   8 +
 disas/x86-data/x86_smap.csv               |   3 +
 disas/x86-data/x86_sse.csv                |  58 ++
 disas/x86-data/x86_sse2.csv               | 148 ++++
 disas/x86-data/x86_sse3.csv               |  11 +
 disas/x86-data/x86_sse4_1.csv             |  48 ++
 disas/x86-data/x86_sse4_2.csv             |   7 +
 disas/x86-data/x86_sse4_3.csv             |   2 +
 disas/x86-data/x86_ssse3.csv              |  33 +
 disas/x86-data/x86_uintr.csv              |   6 +
 disas/x86-data/x86_vaes.csv               |  17 +
 disas/x86-data/x86_vmx.csv                |  14 +
 disas/x86-data/x86_waitpkg.csv            |   4 +
 disas/x86-data/x86_wbnoinvd.csv           |   2 +
 disas/x86-data/x86_x87.csv                | 145 ++++
 disas/x86-data/x86_xsaveopt.csv           |   3 +
 74 files changed, 3731 insertions(+)
 create mode 100644 disas/x86-data/x86_adx.csv
 create mode 100644 disas/x86-data/x86_aes.csv
 create mode 100644 disas/x86-data/x86_aeskle.csv
 create mode 100644 disas/x86-data/x86_aesklewide.csv
 create mode 100644 disas/x86-data/x86_avx.csv
 create mode 100644 disas/x86-data/x86_avx2.csv
 create mode 100644 disas/x86-data/x86_avx5124fmaps.csv
 create mode 100644 disas/x86-data/x86_avx5124vnniw.csv
 create mode 100644 disas/x86-data/x86_avx512b.csv
 create mode 100644 disas/x86-data/x86_avx512bf16.csv
 create mode 100644 disas/x86-data/x86_avx512bitalg.csv
 create mode 100644 disas/x86-data/x86_avx512bw.csv
 create mode 100644 disas/x86-data/x86_avx512cd.csv
 create mode 100644 disas/x86-data/x86_avx512d.csv
 create mode 100644 disas/x86-data/x86_avx512dq.csv
 create mode 100644 disas/x86-data/x86_avx512er.csv
 create mode 100644 disas/x86-data/x86_avx512f.csv
 create mode 100644 disas/x86-data/x86_avx512fp16.csv
 create mode 100644 disas/x86-data/x86_avx512ifma.csv
 create mode 100644 disas/x86-data/x86_avx512pf.csv
 create mode 100644 disas/x86-data/x86_avx512vbmi.csv
 create mode 100644 disas/x86-data/x86_avx512vbmi2.csv
 create mode 100644 disas/x86-data/x86_avx512vl.csv
 create mode 100644 disas/x86-data/x86_avx512vnni.csv
 create mode 100644 disas/x86-data/x86_avx512vp2intersect.csv
 create mode 100644 disas/x86-data/x86_avx512vpopcntdq.csv
 create mode 100644 disas/x86-data/x86_avxneconvert.csv
 create mode 100644 disas/x86-data/x86_avxvnni.csv
 create mode 100644 disas/x86-data/x86_avxvnniint8.csv
 create mode 100644 disas/x86-data/x86_base.csv
 create mode 100644 disas/x86-data/x86_bmi1.csv
 create mode 100644 disas/x86-data/x86_bmi2.csv
 create mode 100644 disas/x86-data/x86_cet.csv
 create mode 100644 disas/x86-data/x86_cldemote.csv
 create mode 100644 disas/x86-data/x86_clwb.csv
 create mode 100644 disas/x86-data/x86_enqcmd.csv
 create mode 100644 disas/x86-data/x86_f16c.csv
 create mode 100644 disas/x86-data/x86_fma.csv
 create mode 100644 disas/x86-data/x86_fsgsbase.csv
 create mode 100644 disas/x86-data/x86_gfni.csv
 create mode 100644 disas/x86-data/x86_hreset.csv
 create mode 100644 disas/x86-data/x86_invpcid.csv
 create mode 100644 disas/x86-data/x86_lzcnt.csv
 create mode 100644 disas/x86-data/x86_mmx.csv
 create mode 100644 disas/x86-data/x86_movdir64b.csv
 create mode 100644 disas/x86-data/x86_movdiri.csv
 create mode 100644 disas/x86-data/x86_mpx.csv
 create mode 100644 disas/x86-data/x86_msrlist.csv
 create mode 100644 disas/x86-data/x86_ospke.csv
 create mode 100644 disas/x86-data/x86_pclmulqdq.csv
 create mode 100644 disas/x86-data/x86_pconfig.csv
 create mode 100644 disas/x86-data/x86_prefetchw.csv
 create mode 100644 disas/x86-data/x86_raoint.csv
 create mode 100644 disas/x86-data/x86_rdpid.csv
 create mode 100644 disas/x86-data/x86_rdrand.csv
 create mode 100644 disas/x86-data/x86_rdseed.csv
 create mode 100644 disas/x86-data/x86_rtm.csv
 create mode 100644 disas/x86-data/x86_serialize.csv
 create mode 100644 disas/x86-data/x86_sha.csv
 create mode 100644 disas/x86-data/x86_smap.csv
 create mode 100644 disas/x86-data/x86_sse.csv
 create mode 100644 disas/x86-data/x86_sse2.csv
 create mode 100644 disas/x86-data/x86_sse3.csv
 create mode 100644 disas/x86-data/x86_sse4_1.csv
 create mode 100644 disas/x86-data/x86_sse4_2.csv
 create mode 100644 disas/x86-data/x86_sse4_3.csv
 create mode 100644 disas/x86-data/x86_ssse3.csv
 create mode 100644 disas/x86-data/x86_uintr.csv
 create mode 100644 disas/x86-data/x86_vaes.csv
 create mode 100644 disas/x86-data/x86_vmx.csv
 create mode 100644 disas/x86-data/x86_waitpkg.csv
 create mode 100644 disas/x86-data/x86_wbnoinvd.csv
 create mode 100644 disas/x86-data/x86_x87.csv
 create mode 100644 disas/x86-data/x86_xsaveopt.csv
disas/x86-data/x86_adx.csv new file +5 -0
new file mode 100644
index 000000000000..c09d68445804
@@ -0,0 +1,5 @@
+"Instruction","Opcode","Valid 64-bit","Valid 32-bit","Valid 16-bit","Feature Flags","Operand 1","Operand 2","Operand 3","Operand 4","Tuple Type","Description"
+"ADCX rw, rw/mw","LEX.66.0F38.W0 F6 /r","Valid","Valid","Invalid","ADX","ModRM:reg (r, w)","ModRM:r/m (r)","","","","Unsigned addition of r with CF, r/m to r, writes CF."
+"ADCX rw, rw/mw","LEX.66.0F38.W1 F6 /r","Valid","Invalid","Invalid","ADX","ModRM:reg (r, w)","ModRM:r/m (r)","","","","Unsigned addition of r with CF, r/m to r, writes CF."
+"ADOX rw, rw/mw","LEX.F3.0F38.W0 F6 /r","Valid","Valid","Invalid","ADX","ModRM:reg (r, w)","ModRM:r/m (r)","","","","Unsigned addition of r with OF, r/m to r, writes OF."
+"ADOX rw, rw/mw","LEX.F3.0F38.W1 F6 /r","Valid","Invalid","Invalid","ADX","ModRM:reg (r, w)","ModRM:r/m (r)","","","","Unsigned addition of r with OF, r/m to r, writes OF."
disas/x86-data/x86_aes.csv new file +13 -0
new file mode 100644
index 000000000000..b61b8f6e87f2
@@ -0,0 +1,13 @@
+"Instruction","Opcode","Valid 64-bit","Valid 32-bit","Valid 16-bit","Feature Flags","Operand 1","Operand 2","Operand 3","Operand 4","Tuple Type","Description"
+"AESDEC xmm1, xmm2/m128","LEX.66.0F38.W0 DE /r","Valid","Valid","Invalid","AES","ModRM:reg (r, w)","ModRM:r/m (r)","","","","Perform one round of an AES decryption flow, using the Equivalent Inverse Cipher, operating on a 128-bit data (state) from xmm1 with a 128-bit round key from xmm2/m128."
+"AESDECLAST xmm1, xmm2/m128","LEX.66.0F38.W0 DF /r","Valid","Valid","Invalid","AES","ModRM:reg (r, w)","ModRM:r/m (r)","","","","Perform the last round of an AES decryption flow, using the Equivalent Inverse Cipher, operating on a 128-bit data (state) from xmm1 with a 128-bit round key from xmm2/m128."
+"AESENC xmm1, xmm2/m128","LEX.66.0F38.W0 DC /r","Valid","Valid","Invalid","AES","ModRM:reg (r, w)","ModRM:r/m (r)","","","","Perform one round of an AES encryption flow, operating on a 128-bit data (state) from xmm1 with a 128-bit round key from xmm2/m128."
+"AESENCLAST xmm1, xmm2/m128","LEX.66.0F38.W0 DD /r","Valid","Valid","Invalid","AES","ModRM:reg (r, w)","ModRM:r/m (r)","","","","Perform the last round of an AES encryption flow, operating on a 128-bit data (state) from xmm1 with a 128-bit round key from xmm2/m128."
+"AESIMC xmm1, xmm2/m128","LEX.66.0F38.W0 DB /r","Valid","Valid","Invalid","AES","ModRM:reg (w)","ModRM:r/m (r)","","","","Perform the InvMixColumn transformation on a 128-bit round key from xmm2/m128 and store the result in xmm1."
+"AESKEYGENASSIST xmm1, xmm2/m128, ib","LEX.66.0F3A.W0 DF /r ib","Valid","Valid","Invalid","AES","ModRM:reg (w)","ModRM:r/m (r)","ib","","","Assist in AES round key generation using an 8 bits Round Constant (RCON) specified in the immediate byte, operating on 128 bits of data specified in xmm2/m128 and stores the result in xmm1."
+"VAESDEC xmm1, xmm2, xmm3/m128","VEX.128.66.0F38.WIG DE /r","Valid","Valid","Invalid","AES AVX","ModRM:reg (w)","VEX.vvvv (r)","ModRM:r/m (r)","","","Perform one round of an AES decryption flow, using the Equivalent Inverse Cipher, operating on a 128-bit data (state) from xmm2 with a 128-bit round key from xmm3/m128; store the result in xmm1."
+"VAESDECLAST xmm1, xmm2, xmm3/m128","VEX.128.66.0F38.WIG DF /r","Valid","Valid","Invalid","AES AVX","ModRM:reg (w)","VEX.vvvv (r)","ModRM:r/m (r)","","","Perform the last round of an AES decryption flow, using the Equivalent Inverse Cipher, operating on a 128-bit data (state) from xmm2 with a 128-bit round key from xmm3/m128; store the result in xmm1."
+"VAESENC xmm1, xmm2, xmm3/m128","VEX.128.66.0F38.WIG DC /r","Valid","Valid","Invalid","AES AVX","ModRM:reg (w)","VEX.vvvv (r)","ModRM:r/m (r)","","","Perform one round of an AES encryption flow, operating on a 128-bit data (state) from xmm2 with a 128-bit round key from the xmm3/m128; store the result in xmm1."
+"VAESENCLAST xmm1, xmm2, xmm3/m128","VEX.128.66.0F38.WIG DD /r","Valid","Valid","Invalid","AES AVX","ModRM:reg (w)","VEX.vvvv (r)","ModRM:r/m (r)","","","Perform the last round of an AES encryption flow, operating on a 128-bit data (state) from xmm2 with a 128 bit round key from xmm3/m128; store the result in xmm1."
+"VAESIMC xmm1, xmm2/m128","VEX.128.66.0F38.WIG DB /r","Valid","Valid","Invalid","AES AVX","ModRM:reg (w)","ModRM:r/m (r)","","","","Perform the InvMixColumn transformation on a 128-bit round key from xmm2/m128 and store the result in xmm1."
+"VAESKEYGENASSIST xmm1, xmm2/m128, ib","VEX.128.66.0F3A.WIG DF /r ib","Valid","Valid","Invalid","AES AVX","ModRM:reg (w)","ModRM:r/m (r)","ib","","","Assist in AES round key generation using 8 bits Round Constant (RCON) specified in the immediate byte, operating on 128 bits of data specified in xmm2/m128 and stores the result in xmm1."
disas/x86-data/x86_aeskle.csv new file +3 -0
new file mode 100644
index 000000000000..b933d236bccd
@@ -0,0 +1,3 @@
+"Instruction","Opcode","Valid 64-bit","Valid 32-bit","Valid 16-bit","Feature Flags","Operand 1","Operand 2","Operand 3","Operand 4","Tuple Type","Description"
+"AESDEC128KL xmm, m","LEX.F3.0F38.W0 DD /r","Valid","Valid","Invalid","AESKLE","ModRM:reg (r, w)","ModRM:r/m (r)","","","","Decrypt xmm using 128-bit AES key indicated by handle at m384 and store result in xmm."
+"AESDEC256KL xmm, m","LEX.F3.0F38.W0 DF /r","Valid","Valid","Invalid","AESKLE","ModRM:reg (r, w)","ModRM:r/m (r)","","","","Decrypt xmm using 256-bit AES key indicated by handle at m512 and store result in xmm."
disas/x86-data/x86_aesklewide.csv new file +3 -0
new file mode 100644
index 000000000000..a4a27867fbcf
@@ -0,0 +1,3 @@
+"Instruction","Opcode","Valid 64-bit","Valid 32-bit","Valid 16-bit","Feature Flags","Operand 1","Operand 2","Operand 3","Operand 4","Tuple Type","Description"
+"AESDECWIDE128KL m","LEX.F3.0F38.W0 D8 /1","Valid","Valid","Invalid","AESKLEWIDE","ModRM:r/m (r)","Implicit XMM0-7 (r, w)","","","","Decrypt XMM0-7 using 128-bit AES key indicated by handle at m384 and store each resultant block back to its corresponding register."
+"AESDECWIDE256KL m","LEX.F3.0F38.W0 D8 /3","Valid","Valid","Invalid","AESKLEWIDE","ModRM:r/m (r)","Implicit XMM0-7 (r, w)","","","","Decrypt XMM0-7 using 256-bit AES key indicated by handle at m512 and store each resultant block back to its corresponding register."
disas/x86-data/x86_avx.csv new file +375 -0

375 lines not on this page · raw message

disas/x86-data/x86_avx2.csv new file +171 -0

171 lines not on this page · raw message

disas/x86-data/x86_avx5124fmaps.csv new file +5 -0
new file mode 100644
index 000000000000..2eda2075c1f9
@@ -0,0 +1,5 @@
+"Instruction","Opcode","Valid 64-bit","Valid 32-bit","Valid 16-bit","Feature Flags","Operand 1","Operand 2","Operand 3","Operand 4","Tuple Type","Description"
+"V4FMADDPS zmm{k}{z},zmm{rs4},m128","EVEX.512.f2.0F38.W0 9a /r","Valid","Valid","Invalid","AVX5124FMAPS","ModRM:reg (r, w)","EVEX.vvvv (r)","ModRM:r/m (r)","","Tuple1_4X","Multiply packed single-precision floating-point values from source register block indicated by zmm2 by values from m128 and accumulate the result in zmm1."
+"V4FMADDSS xmm{k}{z},xmm{rs4},m128","EVEX.LIG.f2.0F38.W0 9b /r","Valid","Valid","Invalid","AVX5124FMAPS","ModRM:reg (r, w)","EVEX.vvvv (r)","ModRM:r/m (r)","","Tuple1_4X","Multiply scalar single-precision floating-point values from source register block indicated by xmm2 by values from m128 and accumulate the result in xmm1."
+"V4FNMADDPS zmm{k}{z},zmm{rs4},m128","EVEX.512.f2.0F38.W0 aa /r","Valid","Valid","Invalid","AVX5124FMAPS","ModRM:reg (r, w)","EVEX.vvvv (r)","ModRM:r/m (r)","","Tuple1_4X","Multiply and negate packed single-precision floating-point values from source register block indicated by zmm2 by values from m128 and accumulate the result in zmm1."
+"V4FNMADDSS xmm{k}{z},xmm{rs4},m128","EVEX.LIG.f2.0F38.W0 ab /r","Valid","Valid","Invalid","AVX5124FMAPS","ModRM:reg (r, w)","EVEX.vvvv (r)","ModRM:r/m (r)","","Tuple1_4X","Multiply and negate scalar single-precision floating-point values from source register block indicated by xmm2 by values from m128 and accumulate the result in xmm1."
disas/x86-data/x86_avx5124vnniw.csv new file +3 -0
new file mode 100644
index 000000000000..f215738e1091
@@ -0,0 +1,3 @@
+"Instruction","Opcode","Valid 64-bit","Valid 32-bit","Valid 16-bit","Feature Flags","Operand 1","Operand 2","Operand 3","Operand 4","Tuple Type","Description"
+"VP4DPWSSD zmm{k}{z},zmm{rs4},m128","EVEX.512.f2.0F38.W0 52 /r","Valid","Valid","Invalid","AVX5124VNNIW","ModRM:reg (r, w)","EVEX.vvvv (r)","ModRM:r/m (r)","","Tuple1_4X","Multiply signed words from source register block indicated by zmm2 by signed words from m128 and accumulate resulting signed dwords in zmm1."
+"VP4DPWSSDS zmm{k}{z},zmm{rs4},m128","EVEX.512.f2.0F38.W0 53 /r","Valid","Valid","Invalid","AVX5124VNNIW","ModRM:reg (r, w)","EVEX.vvvv (r)","ModRM:r/m (r)","","Tuple1_4X","Multiply signed words from source register block indicated by zmm2 by signed words from m128 and accumulate the resulting dword results with signed saturation in zmm1."
disas/x86-data/x86_avx512b.csv new file +3 -0
new file mode 100644
index 000000000000..7e95f90fe46f
@@ -0,0 +1,3 @@
+"Instruction","Opcode","Valid 64-bit","Valid 32-bit","Valid 16-bit","Feature Flags","Operand 1","Operand 2","Operand 3","Operand 4","Tuple Type","Description"
+"VPEXTRW r32/m16, xmm2, ib","EVEX.128.66.0F3A.WIG 15 /r ib","Valid","Valid","Invalid","AVX512B","ModRM:r/m (w)","ModRM:reg (r)","ib","","Tuple1 Scalar","Extract a word integer value from xmm2 at the source word offset specified by ib into reg or m16. The upper bits of r are zeroed."
+"VPEXTRW r32, xmm1, ib","EVEX.128.66.0F.WIG C5 /r ib","Valid","Valid","Invalid","AVX512B","ModRM:reg (w)","ModRM:r/m (r)","ib","","","Extract the word specified by ib from xmm1 and move it to reg, bits 15:0. Zero-extend the result. The upper bits of r are zeroed."
disas/x86-data/x86_avx512bf16.csv new file +10 -0
new file mode 100644
index 000000000000..91ad8dfb7703
@@ -0,0 +1,10 @@
+"Instruction","Opcode","Valid 64-bit","Valid 32-bit","Valid 16-bit","Feature Flags","Operand 1","Operand 2","Operand 3","Operand 4","Tuple Type","Description"
+"VCVTNE2PS2BF16 xmm{k}{z},xmm,xmm/m128/m32bcst","EVEX.128.f2.0F38.W0 72 /r","Valid","Valid","Invalid","AVX512VL AVX512BF16","ModRM:reg (w)","EVEX.vvvv (r)","ModRM:r/m (r)","","Full","Convert packed single data from xmm2 and xmm3/m128/m32bcst to packed BF16 data in xmm1 with writemask k1."
+"VCVTNE2PS2BF16 ymm{k}{z},ymm,ymm/m256/m32bcst","EVEX.256.f2.0F38.W0 72 /r","Valid","Valid","Invalid","AVX512VL AVX512BF16","ModRM:reg (w)","EVEX.vvvv (r)","ModRM:r/m (r)","","Full","Convert packed single data from ymm2 and ymm3/m256/m32bcst to packed BF16 data in ymm1 with writemask k1."
+"VCVTNE2PS2BF16 zmm{k}{z},zmm,zmm/m512/m32bcst","EVEX.512.f2.0F38.W0 72 /r","Valid","Valid","Invalid","AVX512BF16","ModRM:reg (w)","EVEX.vvvv (r)","ModRM:r/m (r)","","Full","Convert packed single data from zmm2 and zmm3/m512/m32bcst to packed BF16 data in zmm1 with writemask k1."
+"VCVTNEPS2BF16 xmm{k}{z},xmm/m128/m32bcst","EVEX.128.f3.0F38.W0 72 /r","Valid","Valid","Invalid","AVX512VL AVX512BF16","ModRM:reg (w)","ModRM:r/m (r)","","","Full","Convert packed single data from xmm2/m128 to packed BF16 data in xmm1 with writemask k1."
+"VCVTNEPS2BF16 xmm{k}{z},ymm/m256/m32bcst","EVEX.256.f3.0F38.W0 72 /r","Valid","Valid","Invalid","AVX512VL AVX512BF16","ModRM:reg (w)","ModRM:r/m (r)","","","Full","Convert packed single data from ymm2/m256 to packed BF16 data in xmm1 with writemask k1."
+"VCVTNEPS2BF16 ymm{k}{z},zmm/m512/m32bcst","EVEX.512.f3.0F38.W0 72 /r","Valid","Valid","Invalid","AVX512BF16","ModRM:reg (w)","ModRM:r/m (r)","","","Full","Convert packed single data from zmm2/m512 to packed BF16 data in ymm1 with writemask k1."
+"VDPBF16PS xmm{k}{z},xmm,xmm/m128/m32bcst","EVEX.128.f3.0F38.W0 52 /r","Valid","Valid","Invalid","AVX512VL AVX512BF16","ModRM:reg (w)","EVEX.vvvv (r)","ModRM:r/m (r)","","Full","Multiply BF16 pairs from xmm2 and xmm3/m128, and accumulate the resulting packed single precision results in xmm1 with writemask k1."
+"VDPBF16PS ymm{k}{z},ymm,ymm/m256/m32bcst","EVEX.256.f3.0F38.W0 52 /r","Valid","Valid","Invalid","AVX512VL AVX512BF16","ModRM:reg (w)","EVEX.vvvv (r)","ModRM:r/m (r)","","Full","Multiply BF16 pairs from ymm2 and ymm3/m256, and accumulate the resulting packed single precision results in ymm1 with writemask k1."
+"VDPBF16PS zmm{k}{z},zmm,zmm/m512/m32bcst","EVEX.512.f3.0F38.W0 52 /r","Valid","Valid","Invalid","AVX512BF16","ModRM:reg (w)","EVEX.vvvv (r)","ModRM:r/m (r)","","Full","Multiply BF16 pairs from zmm2 and zmm3/m512, and accumulate the resulting packed single precision results in zmm1 with writemask k1."
disas/x86-data/x86_avx512bitalg.csv new file +10 -0
new file mode 100644
index 000000000000..cf92160caacb
@@ -0,0 +1,10 @@
+"Instruction","Opcode","Valid 64-bit","Valid 32-bit","Valid 16-bit","Feature Flags","Operand 1","Operand 2","Operand 3","Operand 4","Tuple Type","Description"
+"VPOPCNTB xmm{k}{z},xmm/m128","EVEX.128.66.0F38.W0 54 /r","Valid","Valid","Invalid","AVX512VL AVX512BITALG","ModRM:reg (w)","ModRM:r/m (r)","","","Full Mem","Counts the number of bits set to one in xmm2/m128 and puts the result in xmm1 with writemask k1."
+"VPOPCNTB ymm{k}{z},ymm/m256","EVEX.256.66.0F38.W0 54 /r","Valid","Valid","Invalid","AVX512VL AVX512BITALG","ModRM:reg (w)","ModRM:r/m (r)","","","Full Mem","Counts the number of bits set to one in ymm2/m256 and puts the result in ymm1 with writemask k1."
+"VPOPCNTB zmm{k}{z},zmm/m512","EVEX.512.66.0F38.W0 54 /r","Valid","Valid","Invalid","AVX512BITALG","ModRM:reg (w)","ModRM:r/m (r)","","","Full Mem","Counts the number of bits set to one in zmm2/m512 and puts the result in zmm1 with writemask k1."
+"VPOPCNTW xmm{k}{z},xmm/m128","EVEX.128.66.0F38.W1 54 /r","Valid","Valid","Invalid","AVX512VL AVX512BITALG","ModRM:reg (w)","ModRM:r/m (r)","","","Full Mem","Counts the number of bits set to one in xmm2/m128 and puts the result in xmm1 with writemask k1."
+"VPOPCNTW ymm{k}{z},ymm/m256","EVEX.256.66.0F38.W1 54 /r","Valid","Valid","Invalid","AVX512VL AVX512BITALG","ModRM:reg (w)","ModRM:r/m (r)","","","Full Mem","Counts the number of bits set to one in ymm2/m256 and puts the result in ymm1 with writemask k1."
+"VPOPCNTW zmm{k}{z},zmm/m512","EVEX.512.66.0F38.W1 54 /r","Valid","Valid","Invalid","AVX512BITALG","ModRM:reg (w)","ModRM:r/m (r)","","","Full Mem","Counts the number of bits set to one in zmm2/m512 and puts the result in zmm1 with writemask k1."
+"VPSHUFBITQMB k{k},xmm,xmm/m128","EVEX.128.66.0F38.W0 8f /r","Valid","Valid","Invalid","AVX512VL AVX512BITALG","ModRM:reg (w)","EVEX.vvvv (r)","ModRM:r/m (r)","","Full Mem","Extract values in xmm2 using control bits of xmm3/m128 with writemask k2 and leave the result in mask register k1."
+"VPSHUFBITQMB k{k},ymm,ymm/m256","EVEX.256.66.0F38.W0 8f /r","Valid","Valid","Invalid","AVX512VL AVX512BITALG","ModRM:reg (w)","EVEX.vvvv (r)","ModRM:r/m (r)","","Full Mem","Extract values in ymm2 using control bits of ymm3/m256 with writemask k2 and leave the result in mask register k1."
+"VPSHUFBITQMB k{k},zmm,zmm/m512","EVEX.512.66.0F38.W0 8f /r","Valid","Valid","Invalid","AVX512BITALG","ModRM:reg (w)","EVEX.vvvv (r)","ModRM:r/m (r)","","Full Mem","Extract values in zmm2 using control bits of zmm3/m512 with writemask k2 and leave the result in mask register k1."
disas/x86-data/x86_avx512bw.csv new file +291 -0

291 lines not on this page · raw message

disas/x86-data/x86_avx512cd.csv new file +19 -0
new file mode 100644
index 000000000000..f1d6d7dedb69
@@ -0,0 +1,19 @@
+"Instruction","Opcode","Valid 64-bit","Valid 32-bit","Valid 16-bit","Feature Flags","Operand 1","Operand 2","Operand 3","Operand 4","Tuple Type","Description"
+"VPBROADCASTMB2Q xmm1, k1","EVEX.128.F3.0F38.W1 2A /r","Valid","Valid","Invalid","AVX512VL AVX512CD","ModRM:reg (w)","ModRM:r/m (r)","","","","Broadcast low byte value in k1 to two locations in xmm1."
+"VPBROADCASTMB2Q ymm1, k1","EVEX.256.F3.0F38.W1 2A /r","Valid","Valid","Invalid","AVX512VL AVX512CD","ModRM:reg (w)","ModRM:r/m (r)","","","","Broadcast low byte value in k1 to four locations in ymm1."
+"VPBROADCASTMB2Q zmm1, k1","EVEX.512.F3.0F38.W1 2A /r","Valid","Valid","Invalid","AVX512CD","ModRM:reg (w)","ModRM:r/m (r)","","","","Broadcast low byte value in k1 to eight locations in zmm1."
+"VPBROADCASTMW2D xmm1, k1","EVEX.128.F3.0F38.W0 3A /r","Valid","Valid","Invalid","AVX512VL AVX512CD","ModRM:reg (w)","ModRM:r/m (r)","","","","Broadcast low word value in k1 to four locations in xmm1."
+"VPBROADCASTMW2D ymm1, k1","EVEX.256.F3.0F38.W0 3A /r","Valid","Valid","Invalid","AVX512VL AVX512CD","ModRM:reg (w)","ModRM:r/m (r)","","","","Broadcast low word value in k1 to eight locations in ymm1."
+"VPBROADCASTMW2D zmm1, k1","EVEX.512.F3.0F38.W0 3A /r","Valid","Valid","Invalid","AVX512CD","ModRM:reg (w)","ModRM:r/m (r)","","","","Broadcast low word value in k1 to sixteen locations in zmm1."
+"VPCONFLICTD xmm1 {k1}{z}, xmm2/m128/m32bcst","EVEX.128.66.0F38.W0 C4 /r","Valid","Valid","Invalid","AVX512VL AVX512CD","ModRM:reg (w)","ModRM:r/m (r)","","","Full Vector","Detect duplicate double-word values in xmm2/m128/m32bcst using writemask k1."
+"VPCONFLICTD ymm1 {k1}{z}, ymm2/m256/m32bcst","EVEX.256.66.0F38.W0 C4 /r","Valid","Valid","Invalid","AVX512VL AVX512CD","ModRM:reg (w)","ModRM:r/m (r)","","","Full Vector","Detect duplicate double-word values in ymm2/m256/m32bcst using writemask k1."
+"VPCONFLICTD zmm1 {k1}{z}, zmm2/m512/m32bcst","EVEX.512.66.0F38.W0 C4 /r","Valid","Valid","Invalid","AVX512CD","ModRM:reg (w)","ModRM:r/m (r)","","","Full Vector","Detect duplicate double-word values in zmm2/m512/m32bcst using writemask k1."
+"VPCONFLICTQ xmm1 {k1}{z}, xmm2/m128/m64bcst","EVEX.128.66.0F38.W1 C4 /r","Valid","Valid","Invalid","AVX512VL AVX512CD","ModRM:reg (w)","ModRM:r/m (r)","","","Full Vector","Detect duplicate quad-word values in xmm2/m128/m64bcst using writemask k1."
+"VPCONFLICTQ ymm1 {k1}{z}, ymm2/m256/m64bcst","EVEX.256.66.0F38.W1 C4 /r","Valid","Valid","Invalid","AVX512VL AVX512CD","ModRM:reg (w)","ModRM:r/m (r)","","","Full Vector","Detect duplicate quad-word values in ymm2/m256/m64bcst using writemask k1."
+"VPCONFLICTQ zmm1 {k1}{z}, zmm2/m512/m64bcst","EVEX.512.66.0F38.W1 C4 /r","Valid","Valid","Invalid","AVX512CD","ModRM:reg (w)","ModRM:r/m (r)","","","Full Vector","Detect duplicate quad-word values in zmm2/m512/m64bcst using writemask k1."
+"VPLZCNTD xmm1 {k1}{z}, xmm2/m128/m32bcst","EVEX.128.66.0F38.W0 44 /r","Valid","Valid","Invalid","AVX512VL AVX512CD","ModRM:reg (w)","ModRM:r/m (r)","","","Full Vector","Count the number of leading zero bits in each dword element of xmm2/m128/m32bcst using writemask k1."
+"VPLZCNTD ymm1 {k1}{z}, ymm2/m256/m32bcst","EVEX.256.66.0F38.W0 44 /r","Valid","Valid","Invalid","AVX512VL AVX512CD","ModRM:reg (w)","ModRM:r/m (r)","","","Full Vector","Count the number of leading zero bits in each dword element of ymm2/m256/m32bcst using writemask k1."
+"VPLZCNTD zmm1 {k1}{z}, zmm2/m512/m32bcst","EVEX.512.66.0F38.W0 44 /r","Valid","Valid","Invalid","AVX512CD","ModRM:reg (w)","ModRM:r/m (r)","","","Full Vector","Count the number of leading zero bits in each dword element of zmm2/m512/m32bcst using writemask k1."
+"VPLZCNTQ xmm1 {k1}{z}, xmm2/m128/m64bcst","EVEX.128.66.0F38.W1 44 /r","Valid","Valid","Invalid","AVX512VL AVX512CD","ModRM:reg (w)","ModRM:r/m (r)","","","Full Vector","Count the number of leading zero bits in each qword element of xmm2/m128/m64bcst using writemask k1."
+"VPLZCNTQ ymm1 {k1}{z}, ymm2/m256/m64bcst","EVEX.256.66.0F38.W1 44 /r","Valid","Valid","Invalid","AVX512VL AVX512CD","ModRM:reg (w)","ModRM:r/m (r)","","","Full Vector","Count the number of leading zero bits in each qword element of ymm2/m256/m64bcst using writemask k1."
+"VPLZCNTQ zmm1 {k1}{z}, zmm2/m512/m64bcst","EVEX.512.66.0F38.W1 44 /r","Valid","Valid","Invalid","AVX512CD","ModRM:reg (w)","ModRM:r/m (r)","","","Full Vector","Count the number of leading zero bits in each qword element of zmm2/m512/m64bcst using writemask k1."
disas/x86-data/x86_avx512d.csv new file +2 -0
new file mode 100644
index 000000000000..9af7418a542a
@@ -0,0 +1,2 @@
+"Instruction","Opcode","Valid 64-bit","Valid 32-bit","Valid 16-bit","Feature Flags","Operand 1","Operand 2","Operand 3","Operand 4","Tuple Type","Description"
+"VREDUCESD xmm1 {k1}{z}, xmm2, xmm3/m64{sae}, ib","EVEX.LIG.66.0F3A.W1 57 /r ib","Valid","Valid","Invalid","AVX512D","ModRM:reg (w)","EVEX.vvvv (r)","ModRM:r/m (r)","ib","Tuple1 Scalar","Perform a reduction transformation on a scalar double-precision floating point value in xmm3/m64 by subtracting a number of fraction bits specified by the ib field. Also, upper double precision floating-point value (bits[127:64]) from xmm2 are copied to xmm1[127:64]. Stores the result in xmm1 register."
disas/x86-data/x86_avx512dq.csv new file +143 -0

143 lines not on this page · raw message

disas/x86-data/x86_avx512er.csv new file +11 -0
new file mode 100644
index 000000000000..22441ea5c38b
@@ -0,0 +1,11 @@
+"Instruction","Opcode","Valid 64-bit","Valid 32-bit","Valid 16-bit","Feature Flags","Operand 1","Operand 2","Operand 3","Operand 4","Tuple Type","Description"
+"VEXP2PD zmm1 {k1}{z}, zmm2/m512/m64bcst {sae}","EVEX.512.66.0F38.W1 C8 /r","Valid","Valid","Invalid","AVX512ER","ModRM:reg (r, w)","ModRM:r/m (r)","","","Full Vector","Computes approximations to the exponential 2^x (with less than 2^-23 of maximum relative error) of the packed double-precision floating-point values from zmm2/m512/m64bcst and stores the floating-point result in zmm1with writemask k1."
+"VEXP2PS zmm1 {k1}{z}, zmm2/m512/m32bcst {sae}","EVEX.512.66.0F38.W0 C8 /r","Valid","Valid","Invalid","AVX512ER","ModRM:reg (r, w)","ModRM:r/m (r)","","","Full Vector","Computes approximations to the exponential 2^x (with less than 2^-23 of maximum relative error) of the packed single-precision floating-point values from zmm2/m512/m32bcst and stores the floating-point result in zmm1with writemask k1."
+"VRCP28PD zmm1 {k1}{z}, zmm2/m512/m64bcst {sae}","EVEX.512.66.0F38.W1 CA /r","Valid","Valid","Invalid","AVX512ER","ModRM:reg (w)","ModRM:r/m (r)","","","Full Vector","Computes the approximate reciprocals ( < 2^-28 relative error) of the packed double-precision floating-point values in zmm2/m512/m64bcst and stores the results in zmm1. Under writemask."
+"VRCP28PS zmm1 {k1}{z}, zmm2/m512/m32bcst {sae}","EVEX.512.66.0F38.W0 CA /r","Valid","Valid","Invalid","AVX512ER","ModRM:reg (w)","ModRM:r/m (r)","","","Full Vector","Computes the approximate reciprocals ( < 2^-28 relative error) of the packed single-precision floating-point values in zmm2/m512/m32bcst and stores the results in zmm1. Under writemask."
+"VRCP28SD xmm1 {k1}{z}, xmm2, xmm3/m64 {sae}","EVEX.LIG.66.0F38.W1 CB /r","Valid","Valid","Invalid","AVX512ER","ModRM:reg (w)","EVEX.vvvv (r)","ModRM:r/m (r)","","Tuple1 Scalar","Computes the approximate reciprocal ( < 2^-28 relative error) of the scalar double-precision floating-point value in xmm3/m64 and stores the results in xmm1. Under writemask. Also, upper double-precision floating-point value (bits[127:64]) from xmm2 is copied to xmm1[127:64]."
+"VRCP28SS xmm1 {k1}{z}, xmm2, xmm3/m32 {sae}","EVEX.LIG.66.0F38.W0 CB /r","Valid","Valid","Invalid","AVX512ER","ModRM:reg (w)","EVEX.vvvv (r)","ModRM:r/m (r)","","Tuple1 Scalar","Computes the approximate reciprocal ( < 2^-28 relative error) of the scalar single-precision floating-point value in xmm3/m32 and stores the results in xmm1. Under writemask. Also, upper 3 single-precision floating-point values (bits[127:32]) from xmm2 is copied to xmm1[127:32]."
+"VRSQRT28PD zmm1 {k1}{z}, zmm2/m512/m64bcst {sae}","EVEX.512.66.0F38.W1 CC /r","Valid","Valid","Invalid","AVX512ER","ModRM:reg (w)","ModRM:r/m (r)","","","Full Vector","Computes approximations to the Reciprocal square root (<2^-28 relative error) of the packed double-precision floating-point values from zmm2/m512/m64bcst and stores result in zmm1with writemask k1."
+"VRSQRT28PS zmm1 {k1}{z}, zmm2/m512/m32bcst {sae}","EVEX.512.66.0F38.W0 CC /r","Valid","Valid","Invalid","AVX512ER","ModRM:reg (w)","ModRM:r/m (r)","","","Full Vector","Computes approximations to the Reciprocal square root (<2^-28 relative error) of the packed single-precision floating-point values from zmm2/m512/m32bcst and stores result in zmm1with writemask k1."
+"VRSQRT28SD xmm1 {k1}{z}, xmm2, xmm3/m64 {sae}","EVEX.LIG.66.0F38.W1 CD /r","Valid","Valid","Invalid","AVX512ER","ModRM:reg (w)","EVEX.vvvv (r)","ModRM:r/m (r)","","Tuple1 Scalar","Computes approximate reciprocal square root (<2^-28 relative error) of the scalar double-precision floating-point value from xmm3/m64 and stores result in xmm1with writemask k1. Also, upper double-precision floating-point value (bits[127:64]) from xmm2 is copied to xmm1[127:64]."
+"VRSQRT28SS xmm1 {k1}{z}, xmm2, xmm3/m32 {sae}","EVEX.LIG.66.0F38.W0 CD /r","Valid","Valid","Invalid","AVX512ER","ModRM:reg (w)","EVEX.vvvv (r)","ModRM:r/m (r)","","Tuple1 Scalar","Computes approximate reciprocal square root (<2^-28 relative error) of the scalar single-precision floating-point value from xmm3/m32 and stores result in xmm1with writemask k1. Also, upper 3 single-precision floating-point value (bits[127:32]) from xmm2 is copied to xmm1[127:32]."
disas/x86-data/x86_avx512f.csv new file +901 -0

892 lines not on this page · raw message

disas/x86-data/x86_avx512fp16.csv new file +237 -0

237 lines not on this page · raw message

disas/x86-data/x86_avx512ifma.csv new file +7 -0
new file mode 100644
index 000000000000..5bda254f33f7

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_avx512pf.csv new file +17 -0
new file mode 100644
index 000000000000..d7773d564b1a

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_avx512vbmi.csv new file +13 -0
new file mode 100644
index 000000000000..b24820134cf7

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_avx512vbmi2.csv new file +61 -0

61 lines not on this page · raw message

disas/x86-data/x86_avx512vl.csv new file +2 -0
new file mode 100644
index 000000000000..d8111406786a

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_avx512vnni.csv new file +13 -0
new file mode 100644
index 000000000000..2167968eabac

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_avx512vp2intersect.csv new file +7 -0
new file mode 100644
index 000000000000..8e40ae87acee

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_avx512vpopcntdq.csv new file +7 -0
new file mode 100644
index 000000000000..8d5a6a92f06e

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_avxneconvert.csv new file +15 -0
new file mode 100644
index 000000000000..03b1826b960a

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_avxvnni.csv new file +9 -0
new file mode 100644
index 000000000000..a675d1ee54f7

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_avxvnniint8.csv new file +13 -0
new file mode 100644
index 000000000000..f0428f43cb94

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_base.csv new file +549 -0

549 lines not on this page · raw message

disas/x86-data/x86_bmi1.csv new file +13 -0
new file mode 100644
index 000000000000..d7b2d292089a

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_bmi2.csv new file +17 -0
new file mode 100644
index 000000000000..70f5ac7065a7

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_cet.csv new file +15 -0
new file mode 100644
index 000000000000..4365a253d1af

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_cldemote.csv new file +2 -0
new file mode 100644
index 000000000000..4752596a0570

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_clwb.csv new file +2 -0
new file mode 100644
index 000000000000..f8028a9e24c3

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_enqcmd.csv new file +3 -0
new file mode 100644
index 000000000000..8f7b59e830cb

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_f16c.csv new file +5 -0
new file mode 100644
index 000000000000..a20460332c24

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_fma.csv new file +97 -0

97 lines not on this page · raw message

disas/x86-data/x86_fsgsbase.csv new file +9 -0
new file mode 100644
index 000000000000..e1e56d96677d

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_gfni.csv new file +19 -0
new file mode 100644
index 000000000000..5516183c0461

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_hreset.csv new file +2 -0
new file mode 100644
index 000000000000..5ee644846790

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_invpcid.csv new file +2 -0
new file mode 100644
index 000000000000..b09612909a21

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_lzcnt.csv new file +3 -0
new file mode 100644
index 000000000000..b9b2af7ed7c4

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_mmx.csv new file +60 -0

60 lines not on this page · raw message

disas/x86-data/x86_movdir64b.csv new file +2 -0
new file mode 100644
index 000000000000..c177b1d6f98d

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_movdiri.csv new file +3 -0
new file mode 100644
index 000000000000..f6f6c4f7fc44

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_mpx.csv new file +9 -0
new file mode 100644
index 000000000000..ebe7c6cebf10

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_msrlist.csv new file +4 -0
new file mode 100644
index 000000000000..0c94ba6470a8

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_ospke.csv new file +3 -0
new file mode 100644
index 000000000000..99247830b63e

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_pclmulqdq.csv new file +3 -0
new file mode 100644
index 000000000000..723d959fe9d4

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_pconfig.csv new file +2 -0
new file mode 100644
index 000000000000..edc2fa9b7c0e

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_prefetchw.csv new file +7 -0
new file mode 100644
index 000000000000..b4c6f4338b06

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_raoint.csv new file +9 -0
new file mode 100644
index 000000000000..7a6dea2fe716

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_rdpid.csv new file +2 -0
new file mode 100644
index 000000000000..ecf7a2e7b052

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_rdrand.csv new file +2 -0
new file mode 100644
index 000000000000..d2ed1147d47b

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_rdseed.csv new file +2 -0
new file mode 100644
index 000000000000..d884a9d4d620

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_rtm.csv new file +5 -0
new file mode 100644
index 000000000000..a358aadba6ef

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_serialize.csv new file +2 -0
new file mode 100644
index 000000000000..5e5d1c2544a8

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_sha.csv new file +8 -0
new file mode 100644
index 000000000000..de9f5331ce76

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_smap.csv new file +3 -0
new file mode 100644
index 000000000000..e4e9b06a420e

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_sse.csv new file +58 -0

58 lines not on this page · raw message

disas/x86-data/x86_sse2.csv new file +148 -0

148 lines not on this page · raw message

disas/x86-data/x86_sse3.csv new file +11 -0
new file mode 100644
index 000000000000..93bdb4ec0323

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_sse4_1.csv new file +48 -0

48 lines not on this page · raw message

disas/x86-data/x86_sse4_2.csv new file +7 -0
new file mode 100644
index 000000000000..660d5d8c612a

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_sse4_3.csv new file +2 -0
new file mode 100644
index 000000000000..f57757ff8f94

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_ssse3.csv new file +33 -0
new file mode 100644
index 000000000000..379014eb5d1a

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_uintr.csv new file +6 -0
new file mode 100644
index 000000000000..7de80b61637f

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_vaes.csv new file +17 -0
new file mode 100644
index 000000000000..e7dc7f512c31

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_vmx.csv new file +14 -0
new file mode 100644
index 000000000000..94f83d134f28

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_waitpkg.csv new file +4 -0
new file mode 100644
index 000000000000..a695148fa0e7

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_wbnoinvd.csv new file +2 -0
new file mode 100644
index 000000000000..06882ddd0910

Lines of this file are not shown. View the raw message.

disas/x86-data/x86_x87.csv new file +145 -0

145 lines not on this page · raw message

disas/x86-data/x86_xsaveopt.csv new file +3 -0
new file mode 100644
index 000000000000..d64ba7f92f90

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.43.0

Part of the diff is not shown here. View the raw message.

#2 lore raw

Re: [PATCH v1 1/4] x86-disas: add x86-mini instruction set metadata

Quoted 4 lines · Michael Clark

this metadata is based on x86-csv with numerous inaccuracies fixed plus conversion of legacy instructions to a new LEX format. this metadata has been fuzz-tested against the LLVM disassembler for x86-64 with 64-bit ISA coverage in the order of ~99.9%.

adding someone from AMD into this thread.

I should say disassembly for ~99.9% of the Intel ISA in 64-bit mode. as I did not get to transcribing the AMD extensions yet. I did make a somewhat complete list of instructions that includes AMD extensions:

https://github.com/michaeljclark/x86/blob/trunk/doc/x86_desc.md

that table can be used to get a list of missing AMD instructions. in fact, I have a patch to x86-tablegen.py that does that. note SSE instructions paired with VEX extension start with lower case v so they will sort properly. and that file is grouped by extension instead of listed in alphabetical order of all possible orders.

the version of x86-tablegen in the repo in the first message in this thread has additional features. it can read instruction descriptions to print fancy documentation in Markdown-like format. this is truncated for the email because it needs a 132 column line printer, as opposed to a 72 column line printer like emails.

./scripts/x86_tablegen.py --print-fancy-insn

[AND] # r/m AND sign-extend ib.

| opcode                               | encoding                      |
|:-------------------------------------|:------------------------------|
| AND r8/m8,r8                         | lex.wb 20 /r lock             |
| AND rw/mw,rw                         | lex.wx 21 /r lock             |
| AND r8,r8/m8                         | lex.wb 22 /r                  |
| AND rw,rw/mw                         | lex.wx 23 /r                  |
| AND al,ib                            | lex.wn 24 ib                  |
| AND aw,iw                            | lex.wx 25 iw                  |
| AND r8/m8,ib                         | lex.wb 80 /4 ib lock          |
| AND rw/mw,iw                         | lex.wx 81 /4 iw lock          |
| AND rw/mw,ib                         | lex.wx 83 /4 ib lock          |
|:-------------------------------------|:------------------------------|

i'd appreciate if someone from AMD could contribute data for the AMD extensions, or donate hardware. ;D the interest in AVX-512 was because I have an old Intel 7980XE PC and TCG doesn't/didn't support AVX-512 so I thought I would write another one. I note there is tcg_out_evex_opc but I have not seen that code. the original code in x86-mini is external and is by-file MIT-licensed. so I would appreciate if folks that want to help with this could patch the original repo instead of making code that I can't use. like you are doing for Berkeley SoftFloat.

thanks,
Michael.

#3 lore raw

PATCH 2/4 x86-disas: add x86-mini metadata documentation

In reply to Michael Clark

add detailed information on the instruction opcode encoding format for LEX/VEX/EVEX prefix, map and opcode encoding, the operand encoding format, the field order encoding format and notes on instruction synthesis for parameterized opcodes.

---
 docs/x86-metadata.txt | 301 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 301 insertions(+)
 create mode 100644 docs/x86-metadata.txt
docs/x86-metadata.txt new file +301 -0
new file mode 100644
index 000000000000..1e4756069d9d
@@ -0,0 +1,301 @@
+x86 Instruction Set Metadata
+============================
+
+Legacy x86 instructions have been parameterized in the instruction set
+metadata using a new LEX prefix for instruction encoding with abstract width
+suffix codes that synthesize multiple instruction widths using combinations
+of operand size prefixes and `REX.W` bits. This new LEX format makes legacy
+instruction encodings consistent with VEX and EVEX encodings as well as
+eliminating some redundancy in the metadata.
+
+There are a small number of special cases for legacy instructions which need
+mode-dependent overrides for cases such as, a different opcode is used for
+different modes, or the instruction has a quirk where the operand size does
+not follow the default rules for instruction word and address sizes:
+
+- `.wx` is used to specify 64-bit instructions that default to 32-bit
+  operands in 64-bit mode.
+- `.ww` is used to specify 64-bit instructions that default to 64-bit
+  operands in 64-bit mode.
+- `.o16` is used to specify an instruction override specific to 16-bit mode.
+- `.o32` is used to specify an instruction override specific to 32-bit mode.
+- `.o64` is used to specify an instruction override specific to 64-bit mode.
+
+CSV File Format
+===============
+
+The instruction set metadata in the `data` directory has the following fields
+which map to instruction encoding tables in the Intel Architecture Software
+Developer's Manual:
+
+- _Instruction_: opcode and operands from Opcode/Instruction column.
+- _Opcode_: instruction encoding from Opcode/Instruction column.
+- _Valid 64-bit_: 64-bit valid field from 64/32 bit Mode Support column.
+- _Valid 32-bit_: 32-bit valid field from 64/32 bit Mode Support column.
+- _Valid 16-bit_: 16-bit valid field from Compat/Legacy Mode column.
+- _Feature Flags_: extension name from CPUID Feature Flag column.
+- _Operand 1_: Operand 1 column from Instruction Operand Encoding table.
+- _Operand 2_: Operand 2 column from Instruction Operand Encoding table.
+- _Operand 3_: Operand 3 column from Instruction Operand Encoding table.
+- _Operand 4_: Operand 4 column from Instruction Operand Encoding table.
+- _Tuple Type_: Tuple Type column from Instruction Operand Encoding table.
+
+The instruction set metadata in the `data` directory is derived from
+[x86-csv](https://github.com/GregoryComer/x86-csv), although it has had
+extensive modifications to fix transcription errors, to revise legacy
+instruction encodings to conform to the new LEX format, as well as add
+missing details such as missing operands or recently added AVX-512
+instruction encodings and various other instruction set extensions.
+
+Table Generation
+================
+
+The appendices outline the printable form of the mnemonics used in the
+generated tables to describe operands, instruction encodings and field order.
+The mnemonics are referenced in the instruction set metadata files which are
+translated to enums and arrays by `scripts/x86-tablegen.py` which then map to
+the enum type and set definitions in `disas/x86.h`:
+
+- _enum x86_opr_ - operand encoding enum type and set attributes.
+- _enum x86_enc_ - instruction encoding enum type and set attributes.
+- _enum x86_ord_ - operand to instruction encoding field map set attributes.
+
+The enum values are combined together with _logical or_ combinations to
+form the primary metadata tables used by the encoder and decoder library:
+
+- _struct x86_opc_data_ - table type for instruction opcode encodings.
+- _struct x86_opr_data_ - table type for unique sets of instruction operands.
+- _struct x86_ord_data_ - table type for unique sets of instruction field orders.
+
+***Note***: There are some differences between the mnemonics used in the
+CSV metadata and the C enums. Exceptions are described in `operand_map` and
+`opcode_map` within `scripts/x86_tablegen.py`. The primary differences are
+in the names used in the operand columns to indicate operand field order,
+otherwise a type prefix is added, dots and brackets are omitted, and forward
+slashes are translated to underscores.
+
+Appendices
+==========
+
+This section describes the mnemonics used in the primary data structures:
+
+- _Appendix A - Operand Encoding_ - describes instruction operands.
+- _Appendix B - Operand Order_ - describes instruction field ordering.
+- _Appendix C - Instruction Encoding Prefixes_ - describes encoding prefixes.
+- _Appendix D - Instruction Encoding Suffixes_ - describes encoding suffixes.
+- _Appendix E - Instruction Synthesis Notes_ - notes on prefix synthesis.
+
+Appendix A - Operand Encoding
+=============================
+
+This table outlines the operand mnemonics used in instruction operands
+_(enum x86_opr)_.
+
+| operand            | description                                           |
+|:-------------------|:------------------------------------------------------|
+| `r`                | integer register                                      |
+| `v`                | vector register                                       |
+| `k`                | mask register                                         |
+| `seg`              | segment register                                      |
+| `creg`             | control register                                      |
+| `dreg`             | debug register                                        |
+| `bnd`              | bound register                                        |
+| `mem`              | memory reference                                      |
+| `rw`               | integer register word-sized (16/32/64 bit)            |
+| `ra`               | integer register addr-sized (16/32/64 bit)            |
+| `mw`               | memory reference word-sized (16/32/64 bit)            |
+| `mm`               | vector register 64-bit                                |
+| `xmm`              | vector register 128-bit                               |
+| `ymm`              | vector register 256-bit                               |
+| `zmm`              | vector register 512-bit                               |
+| `r8`               | register 8-bit                                        |
+| `r16`              | register 16-bit                                       |
+| `r32`              | register 32-bit                                       |
+| `r64`              | register 64-bit                                       |
+| `m8`               | memory reference 8-bit byte                           |
+| `m16`              | memory reference 16-bit word                          |
+| `m32`              | memory reference 32-bit dword                         |
+| `m64`              | memory reference 64-bit qword                         |
+| `m128`             | memory reference 128-bit oword/xmmword                |
+| `m256`             | memory reference 256-bit ymmword                      |
+| `m512`             | memory reference 512-bit zmmword                      |
+| `m80`              | memory reference 80-bit tword/tbyte                   |
+| `m384`             | memory reference 384-bit key locker handle            |
+| `mib`              | memory reference bound                                |
+| `m16bcst`          | memory reference 16-bit word broadcast                |
+| `m32bcst`          | memory reference 32-bit word broadcast                |
+| `m64bcst`          | memory reference 64-bit word broadcast                |
+| `vm32`             | vector memory 32-bit                                  |
+| `vm64`             | vector memory 64-bit                                  |
+| `{er}`             | operand suffix - embedded rounding control            |
+| `{k}`              | operand suffix - apply mask register                  |
+| `{sae}`            | operand suffix - suppress all execptions              |
+| `{z}`              | operand suffix - zero instead of merge                |
+| `{rs2}`            | operand suffix - register stride 2                    |
+| `{rs4}`            | operand suffix - register stride 4                    |
+| `r/m8`             | register unsized memory 8-bit                         |
+| `r/m16`            | register unsized memory 16-bit                        |
+| `r/m32`            | register unsized memory 32-bit                        |
+| `r/m64`            | register unsized memory 64-bit                        |
+| `k/m8`             | mask register memory 8-bit                            |
+| `k/m16`            | mask register memory 16-bit                           |
+| `k/m32`            | mask register memory 32-bit                           |
+| `k/m64`            | mask register memory 64-bit                           |
+| `bnd/m64`          | bound register memory 64-bit                          |
+| `bnd/m128`         | bound register memory 128-bit                         |
+| `rw/mw`            | register or memory 16/32/64-bit (word size)           |
+| `r8/m8`            | 8-bit register 8-bit memory                           |
+| `r?/m?`            | N-bit register N-bit memory                           |
+| `mm/m?`            | 64-bit vector N-bit memory                            |
+| `xmm/m?`           | 128-bit vector N-bit memory                           |
+| `ymm/m?`           | 256-bit vector N-bit memory                           |
+| `zmm/m?`           | 512-bit vector N-bit memory                           |
+| `xmm/m?/m?bcst`    | 128-bit vector N-bit memory N-bit broadcast           |
+| `ymm/m?/m?bcst`    | 256-bit vector N-bit memory N-bit broadcast           |
+| `zmm/m?/m?bcst`    | 512-bit vector N-bit memory N-bit broadcast           |
+| `vm32x`            | 32-bit vector memory in xmm                           |
+| `vm32y`            | 32-bit vector memory in ymm                           |
+| `vm32z`            | 32-bit vector memory in zmm                           |
+| `vm64x`            | 64-bit vector memory in xmm                           |
+| `vm64y`            | 64-bit vector memory in ymm                           |
+| `vm64z`            | 64-bit vector memory in zmm                           |
+| `st0`              | implicit register st0                                 |
+| `st1`              | implicit register st1                                 |
+| `es`               | implicit segment es                                   |
+| `cs`               | implicit segment cs                                   |
+| `ss`               | implicit segment ss                                   |
+| `ds`               | implicit segment ds                                   |
+| `fs`               | implicit segment fs                                   |
+| `gs`               | implicit segment gs                                   |
+| `aw`               | implicit register (ax/eax/rax)                        |
+| `cw`               | implicit register (cx/ecx/rcx)                        |
+| `dw`               | implicit register (dx/edx/rdx)                        |
+| `bw`               | implicit register (bx/ebx/rbx)                        |
+| `pa`               | implicit indirect register (ax/eax/rax)               |
+| `pc`               | implicit indirect register (cx/ecx/rcx)               |
+| `pd`               | implicit indirect register (dx/edx/rdx)               |
+| `pb`               | implicit indirect register (bx/ebx/rbx)               |
+| `psi`              | implicit indirect register (si/esi/rsi)               |
+| `pdi`              | implicit indirect register (di/edi/rdi)               |
+| `xmm0`             | implicit register xmm0                                |
+| `xmm0_7`           | implicit registers xmm0-xmm7                          |
+| `1`                | constant 1                                            |
+| `ib`               | 8-bit immediate                                       |
+| `iw`               | 16-bit or 32-bit immediate (mode + operand size)      |
+| `id`               | 32-bit immediate                                      |
+| `iq`               | 64-bit immediate                                      |
+| `rel8`             | 8-bit displacement                                    |
+| `relw`             | 6-bit or 32-bit displacement (mode + operand size)    |
+| `moffs`            | indirect memory offset                                |
+| `far16/16`         | 16-bit seg 16-bit far displacement                    |
+| `far16/32`         | 16-bit seg 32-bit far displacement                    |
+| `memfar16/16`      | indirect 16-bit seg 16-bit far displacement           |
+| `memfar16/32`      | indirect 16-bit seg 32-bit far displacement           |
+| `memfar16/64`      | indirect 16-bit seg 64-bit far displacement           |
+
+Appendix B - Operand Order
+==========================
+
+This table outlines the mnemonics used to map operand field order
+_(enum x86_ord)_.
+
+| mnemonic | description                                                     |
+|:---------|:----------------------------------------------------------------|
+| `imm`    | ib, iw, i16, i32, i64                                           |
+| `reg`    | modrm.reg                                                       |
+| `mrm`    | modrm.r/m                                                       |
+| `sib`    | modrm.r/m sib                                                   |
+| `is4`    | register from ib                                                |
+| `ime`    | i8, i16 (special case for CALLF/JMPF/ENTER)                     |
+| `vec`    | VEX.vvvv                                                        |
+| `opr`    | opcode +r                                                       |
+| `one`    | constant 1                                                      |
+| `rax`    | constant al/ax/eax/rax                                          |
+| `rcx`    | constant cl/cx/ecx/rcx                                          |
+| `rdx`    | constant dl/dx/edx/rdx                                          |
+| `rbx`    | constant bl/bx/ebx/rbx                                          |
+| `rsp`    | constant sp/esp/rsp                                             |
+| `rbp`    | constant bp/ebp/rbp                                             |
+| `rsi`    | constant si/esi/rsi                                             |
+| `rdi`    | constant di/edi/rdi                                             |
+| `st0`    | constant st(0)                                                  |
+| `stx`    | constant st(i)                                                  |
+| `seg`    | constant segment                                                |
+| `xmm0`   | constant xmm0                                                   |
+| `xmm0_7` | constant xmm0-xmm7                                              |
+| `mxcsr`  | constant mxcsr                                                  |
+| `rflags` | constant rflags                                                 |
+
+Appendix C - Instruction Encoding Prefixes
+==========================================
+
+This table outlines the mnemonic prefixes used in instruction encodings
+_(enum x86_enc)_.
+
+| mnemonic | description                                                     |
+|:---------|:----------------------------------------------------------------|
+| `lex`    | legacy instruction                                              |
+| `vex`    | VEX encoded instruction                                         |
+| `evex`   | EVEX encoded instruction                                        |
+| `.lz`    | VEX encoding L=0 and L=1 is unassigned                          |
+| `.l0`    | VEX encoding L=0                                                |
+| `.l1`    | VEX encoding L=1                                                |
+| `.lig`   | VEX/EVEX encoding ignores length L=any                          |
+| `.128`   | VEX/EVEX encoding uses 128-bit vector L=0                       |
+| `.256`   | VEX/EVEX encoding uses 256-bit vector L=1                       |
+| `.512`   | EVEX encoding uses 512-bit vector L=2                           |
+| `.66`    | prefix byte 66 is used for opcode mapping                       |
+| `.f2`    | prefix byte f2 is used for opcode mapping                       |
+| `.f3`    | prefix byte f3 is used for opcode mapping                       |
+| `.9b`    | prefix byte 9b is used for opcode mapping (x87 only)            |
+| `.0f`    | map 0f is used in opcode                                        |
+| `.0f38`  | map 0f38 is used in opcode                                      |
+| `.0f3a`  | map 0f3a is used in opcode                                      |
+| `.wn`    | no register extension, fixed operand size                       |
+| `.wb`    | register extension, fixed operand size                          |
+| `.wx`    | REX and/or operand size extension, optional 66 or REX.W0/W1     |
+| `.ww`    | REX and/or operand size extension, optional 66 and REX.WIG      |
+| `.w0`    | LEX/VEX/EVEX optional REX W0 with operand size used in opcode   |
+| `.w1`    | LEX/VEX/EVEX mandatory REX W1 with operand size used in opcode  |
+| `.wig`   | VEX/EVEX encoding width ignored                                 |
+
+Appendix D - Instruction Encoding Suffixes
+==========================================
+
+This table outlines the mnemonic suffixes used in instruction encodings
+_(enum x86_enc)_.
+
+| mnemonic | description                                                     |
+|:---------|:----------------------------------------------------------------|
+| `/r`     | ModRM byte                                                      |
+| `/0../9` | ModRM byte with 'r' field used for functions 0 to 7             |
+| `XX+r`   | opcode byte with 3-bit register added to the opcode             |
+| `XX`     | opcode byte                                                     |
+| `ib`     | 8-bit immediate                                                 |
+| `iw`     | 16-bit or 32-bit immediate (real mode XOR operand size)         |
+| `i16`    | 16-bit immediate                                                |
+| `i32`    | 32-bit immediate                                                |
+| `i64`    | 64-bit immediate                                                |
+| `o16`    | encoding uses prefix 66 in 32-bit and 64-bit modes              |
+| `o32`    | encoding uses prefix 66 in 16-bit mode                          |
+| `o64`    | encoding is used exclusively in 64-bit mode with REX.W=1        |
+| `a16`    | encoding uses prefix 67 in 32-bit and 64-bit modes              |
+| `a32`    | encoding uses prefix 67 in 16-bit mode                          |
+| `a64`    | encoding is used exclusively in 64-bit mode                     |
+| `lock`   | memory operand encodings can be used with the LOCK prefix       |
+
+Appendix E - Instruction Synthesis Notes
+========================================
+
+The `.wx` and `.ww` mnemonics are used to synthesize prefix combinations:
+
+- `.wx` labels opcodes with _default 32-bit operand size in 64-bit mode_
+  to synthesize 16/32/64-bit versions using REX and operand size prefix,
+  or in 16/32-bit modes synthesizes 16/32-bit versions using only the
+  operand size prefix. REX is used for register extension on opcodes
+  with `rw` or `rw/mw` operands or fixed register operands like `aw`.
+- `.ww` labels opcodes with _default 64-bit operand size in 64-bit mode_
+  to synthesize 16/64-bit versions using only the operand size prefix,
+  or in 16/32-bit modes. synthesizes 16/32-bit versions using only the
+  operand size prefix. REX is used for register extension on opcodes
+  with `rw` or `rw/mw` operands or fixed register operands like `aw`.
Signature · 1 line
2.43.0
#4 lore raw

PATCH 3/4 x86-disas: add x86-mini metadata tablegen script

In reply to Michael Clark

the x86-mini metadata tablegen python script reads instruction set metadata CSV files and translates them into tables used by the disassembler. it generates the following tables:

- x86_opc_table that encodes prefix, map, and opcode
- x86_opr_table that encodes instruction operands
- x86_ord_table that encodes operand field order
- x86 register enum and string table
- x86 opcode enum and string table

---
 scripts/x86-tablegen.py | 693 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 693 insertions(+)
 create mode 100755 scripts/x86-tablegen.py
scripts/x86-tablegen.py new file +693 -0
new file mode 100755
index 000000000000..6d6a0916fb36
@@ -0,0 +1,693 @@
+#!/usr/bin/env python3
+#
+# Copyright (c) 2024-2025 Michael Clark
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+# OTHER DEALINGS IN THE SOFTWARE.
+
+import re
+import sys
+import csv
+import glob
+import string
+import argparse
+
+gpr_bh = ["ah", "ch", "dh", "bh"]
+gpr_b = ["al", "cl", "dl", "bl", "spl", "bpl", "sil", "dil"]
+gpr_w = ["ax", "cx", "dx", "bx", "sp", "bp", "si", "di"]
+gpr_d = ["eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi"]
+gpr_q = ["rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi"]
+seg_r = ["es", "cs", "ss", "ds", "fs", "gs", "seg6", "seg7"]
+sys_r = ["rip", "rflags","fpcsr", "mxcsr"]
+sys_n = ["none"]
+
+cc_all = [ 'EQ', 'NEQ', 'GT', 'NLE', 'GE', 'NLT', 'LT', 'NGE', 'LE', 'NGT',
+                        'A',  'NBE', 'AE', 'NB',  'B',  'NAE', 'BE', 'NA' ]
+cc_signed = [ 'EQ', 'GE', 'GT', 'LE', 'LT', 'NEQ', 'NGT', 'NLE', 'NLT' ]
+cc_unsigned = [ 'EQ', 'AE', 'A',  'BE', 'B',  'NEQ', 'NA',  'NBE', 'NB' ]
+
+def gen_range(fmt,f,s,e):
+    t = []
+    for i in range(s,e):
+        t += [[i, fmt % i, f]]
+    return t
+
+def gen_list(l,f,start):
+    t = []
+    for i, s in enumerate(l):
+        t += [[i + start, s, f]]
+    return t
+
+def gen_sep():
+    return [[0, "", ""]]
+
+def reg_table():
+    t = []
+    t += gen_list(gpr_bh, "reg_bl", 4)
+    t += gen_sep()
+    t += gen_list(gpr_b, "reg_b", 0)
+    t += gen_range("r%db", "reg_b", 8, 32)
+    t += gen_sep()
+    t += gen_list(gpr_w, "reg_w", 0)
+    t += gen_range("r%dw", "reg_w", 8, 32)
+    t += gen_sep()
+    t += gen_list(gpr_d, "reg_d", 0)
+    t += gen_range("r%dd", "reg_d", 8, 32)
+    t += gen_sep()
+    t += gen_list(gpr_q, "reg_q", 0)
+    t += gen_range("r%d", "reg_q", 8, 32)
+    t += gen_sep()
+    t += gen_range("mm%d", "reg_mmx", 0, 8)
+    t += gen_sep()
+    t += gen_range("xmm%d", "reg_xmm", 0, 32)
+    t += gen_sep()
+    t += gen_range("ymm%d", "reg_ymm", 0, 32)
+    t += gen_sep()
+    t += gen_range("zmm%d", "reg_zmm", 0, 32)
+    t += gen_sep()
+    t += gen_range("k%d", "reg_kmask", 0, 8)
+    t += gen_sep()
+    t += gen_range("st(%d)", "reg_fpu", 0, 8)
+    t += gen_sep()
+    t += gen_range("bnd%d", "reg_bnd", 0, 8)
+    t += gen_sep()
+    t += gen_range("dr%d", "reg_dreg", 0, 16)
+    t += gen_sep()
+    t += gen_range("cr%d", "reg_creg", 0, 16)
+    t += gen_sep()
+    t += gen_list(seg_r, "reg_sreg", 0)
+    t += gen_sep()
+    t += gen_list(sys_r, "reg_sys", 0)
+    t += gen_sep()
+    t += gen_list(sys_n, "reg_sys", 31)
+    return t
+
+operand_map = {
+    '1'                                                     : 'one/r',
+    'RAX (r)'                                               : 'rax/r',
+    'RAX (r, w)'                                            : 'rax/rw',
+    'RAX (w)'                                               : 'rax/w',
+    'RCX (r)'                                               : 'rcx/r',
+    'RCX (r, w)'                                            : 'rcx/rw',
+    'RCX (w)'                                               : 'rcx/w',
+    'RDX (r)'                                               : 'rdx/r',
+    'RDX (r, w)'                                            : 'rdx/rw',
+    'RDX (w)'                                               : 'rdx/w',
+    'RBX (r)'                                               : 'rbx/r',
+    'RBX (r, w)'                                            : 'rbx/rw',
+    'RBX (w)'                                               : 'rbx/w',
+    'RSI (r)'                                               : 'rsi/r',
+    'RSI (r, w)'                                            : 'rsi/rw',
+    'RSI (w)'                                               : 'rsi/w',
+    'RDI (r)'                                               : 'rdi/r',
+    'RDI (r, w)'                                            : 'rdi/rw',
+    'RDI (w)'                                               : 'rdi/w',
+    'ST0 (r)'                                               : 'st0/r',
+    'ST0 (r, w)'                                            : 'st0/rw',
+    'ST0 (w)'                                               : 'st0/w',
+    'STX (r)'                                               : 'stx/r',
+    'STX (r, w)'                                            : 'stx/rw',
+    'STX (w)'                                               : 'stx/w',
+    'SEG (r)'                                               : 'seg/r',
+    'SEG (r, w)'                                            : 'seg/rw',
+    'SEG (w)'                                               : 'seg/w',
+    'RSP (r, w, i)'                                         : 'rsp/rwi',
+    'RBP (r, w, i)'                                         : 'rbp/rwi',
+    'MXCSR (r, i)'                                          : 'mxcsr/ri',
+    'MXCSR (w, i)'                                          : 'mxcsr/wi',
+    'RFLAGS (r, i)'                                         : 'rflags/ri',
+    'RFLAGS (w, i)'                                         : 'rflags/wi',
+    'ModRM:reg (r)'                                         : 'reg/r',
+    'ModRM:reg (r, w)'                                      : 'reg/rw',
+    'ModRM:reg (w)'                                         : 'reg/w',
+    'ModRM:r/m (r)'                                         : 'mrm/r',
+    'ModRM:r/m (r, w)'                                      : 'mrm/rw',
+    'ModRM:r/m (w)'                                         : 'mrm/w',
+    'ModRM:r/m (r, ModRM:[7:6] must be 11b)'                : 'mrm/r',
+    'ModRM:r/m (r, ModRM:[7:6] must not be 11b)'            : 'mrm/r',
+    'ModRM:r/m (w, ModRM:[7:6] must not be 11b)'            : 'mrm/w',
+    'ModRM:r/m (r, w, ModRM:[7:6] must not be 11b)'         : 'mrm/rw',
+    'BaseReg (r): VSIB:base, VectorReg (r): VSIB:index'     : 'sib/r',
+    'SIB.base (r): Address of pointer SIB.index (r)'        : 'sib/r',
+    'EVEX.vvvv (r)'                                         : 'vec/r',
+    'EVEX.vvvv (w)'                                         : 'vec/w',
+    'VEX.vvvv (r)'                                          : 'vec/r',
+    'VEX.vvvv (r, w)'                                       : 'vec/rw',
+    'VEX.vvvv (w)'                                          : 'vec/w',
+    'ib'                                                    : 'imm',
+    'iw'                                                    : 'imm',
+    'iwd'                                                   : 'imm',
+    'i16'                                                   : 'imm',
+    'i32'                                                   : 'imm',
+    'i64'                                                   : 'imm',
+    'imm'                                                   : 'imm',
+    'ime'                                                   : 'ime',
+    'ib[3:0]'                                               : 'imm',
+    'ib[7:4]'                                               : 'is4/r',
+    'Implicit XMM0 (r)'                                     : 'xmm0/r',
+    'Implicit XMM0-7 (r, w)'                                : 'xmm0_7/rw',
+    'opcode +r (r)'                                         : 'opr/r',
+    'opcode +r (r, w)'                                      : 'opr/rw',
+    'opcode +r (w)'                                         : 'opr/w',
+    'NA'                                                    : None,
+    ''                                                      : None
+}
+
+opcode_map = {
+    '<xmm0>'  : 'reg_xmm0',
+    '<xmm0-7>': 'reg_xmm0_7',
+    '1'       : '1',
+    'm'       : 'mem',
+    'al'      : 'reg_al',
+    'cl'      : 'reg_cl',
+    'ah'      : 'reg_ah',
+    'aw'      : 'reg_aw',
+    'cw'      : 'reg_cw',
+    'dw'      : 'reg_dw',
+    'bw'      : 'reg_bw',
+    'ax'      : 'reg_ax',
+    'cx'      : 'reg_cx',
+    'dx'      : 'reg_dx',
+    'bx'      : 'reg_bx',
+    'eax'     : 'reg_eax',
+    'ecx'     : 'reg_ecx',
+    'edx'     : 'reg_edx',
+    'ebx'     : 'reg_ebx',
+    'rax'     : 'reg_rax',
+    'rcx'     : 'reg_rcx',
+    'rdx'     : 'reg_rdx',
+    'rbx'     : 'reg_rbx',
+    'si'      : 'reg_si',
+    'di'      : 'reg_di',
+    'pa'      : 'reg_pa',
+    'pc'      : 'reg_pc',
+    'pd'      : 'reg_pd',
+    'pb'      : 'reg_pb',
+    'psi'     : 'reg_psi',
+    'pdi'     : 'reg_pdi',
+    'cs'      : 'seg_cs',
+    'ds'      : 'seg_ds',
+    'ss'      : 'seg_ss',
+    'es'      : 'seg_es',
+    'fs'      : 'seg_fs',
+    'gs'      : 'seg_gs',
+    'sreg'    : 'seg',
+    'dr0-dr7' : 'dreg',
+    'cr0-cr15': 'creg',
+    'cr8'     : 'creg8',
+    'st(0)'   : 'reg_st0',
+    'st(1)'   : 'reg_st1',
+    'st(i)'   : 'st'
+}
+
+def x86_mode(row):
+    l = list()
+    if row['Valid 64-bit'] == 'Valid':
+        l.append('64')
+    if row['Valid 32-bit'] == 'Valid':
+        l.append('32')
+    if row['Valid 16-bit'] == 'Valid':
+        l.append('16')
+    return "/".join(l)
+
+def x86_operand(opcode,row):
+    l = list()
+    opcode = opcode.split(' ')[0]
+    operand1 = operand_map[row['Operand 1']]
+    operand2 = operand_map[row['Operand 2']]
+    operand3 = operand_map[row['Operand 3']]
+    operand4 = operand_map[row['Operand 4']]
+    if operand1:
+        l += [operand1]
+    if operand2:
+        l += [operand2]
+    if operand3:
+        l += [operand3]
+    if operand4:
+        l += [operand4]
+    return ",".join(l)
+
+def cleanup_oprs(args):
+    args = list(map(lambda x : x.lstrip().rstrip(), args.split(",")))
+    args = list(map(lambda x : x.replace('&',':'), args))
+    args = list(map(lambda x : x.replace('{k1}','{k}'), args))
+    args = list(map(lambda x : x.lower(), args))
+    args = list(map(lambda x : opcode_map[x] if x in opcode_map else x, args))
+    for reg in ('r32', 'r64'):
+        for suffix in ('a', 'b'):
+            args = list(map(lambda x : x.replace(reg + suffix, reg), args))
+    args = list(map(lambda x : 'rw' if x == 'r' else x, args))
+    args = list(map(lambda x : 'rw/mw' if x == 'r/m' else x, args))
+    for reg in ('k', 'bnd', 'mm', 'xmm', 'ymm', 'zmm'):
+        for i in range(0,5):
+            args = list(map(lambda x : x.replace(reg + str(i), reg) \
+                if x.find(reg) == 0 else x, args))
+    args = list(map(lambda x : x.replace(' ', ''), args))
+    return args
+
+def split_opcode(opcode):
+    space_idx = opcode.find(' ')
+    if space_idx == -1:
+        return (opcode,list())
+    else:
+        return (opcode[:space_idx], cleanup_oprs(opcode[space_idx:]))
+
+def cleanup_opcode(opcode):
+    op, args = split_opcode(opcode)
+    if len(args) > 0:
+        return "%s %s " % (op, ",".join(args))
+    else:
+        return op
+
+def cleanup_encoding(enc):
+    enc = enc.lower()
+    enc = enc.replace('/is4', 'ib')
+    enc = enc.replace('0f 38', '0f38')
+    enc = enc.replace('0f 3a', '0f3a')
+    enc = enc.replace('  ', ' ')
+    return enc
+
+def translate_modes(modes):
+    modelist = []
+    if modes == '':
+        return '0'
+    for m in modes.split('/'):
+        modelist += ['x86_modes_%s' % m]
+    return "|".join(modelist)
+
+# add 9b, del rex rex.w
+def translate_encoding(enc):
+    prefixes = [ 'hex', 'lex', 'vex', 'evex' ]
+    r_suffixes = [ 'rep', 'lock', 'norexb' ]
+    s_suffixes = [ 'o16', 'o32', 'o64', 'a16', 'a32', 'a64' ]
+    pbytes = [ '66', '9b', 'f2', 'f3' ]
+    maps = { '0f', '0f38', '0f3a', 'map4', 'map5', 'map6' }
+    widths = { 'w0', 'w1', 'wig', 'wb', 'wn', 'ws', 'wx', 'ww' }
+    lengths = { 'lig', 'lz', 'l0', 'l1', '128', '256', '512' }
+    flags = { 'nds', 'ndd', 'dds' }
+    imm = { 'ib', 'iw', 'iwd', 'i16', 'i32', 'i64' }
+    mods = { '/r', '/0', '/1', '/2', '/3', '/4', '/5', '/6', '/7' }
+    pl = []
+    opc = ['0x00','0x00']
+    opm = ['0x00','0x00']
+    oplen = 0
+    has_imm, has_pfx, has_pbyte, has_map = False, False, False, False
+    comps = enc.split(" ")
+    for el in comps:
+        is_hex = all(c in string.hexdigits for c in el[0:2])
+        p = None
+        for sel in prefixes:
+            if el.find(sel) == 0 and ( p == None or len(sel) > len(p) ):
+                p = sel
+        if p:
+            pl += ['x86_enc_t_%s' % p.replace('.', '_')]
+            el = el[len(p):]
+            vp, vm, vw, vl, vf = None, None, None, None, None
+            for sel in el.split('.'):
+                if sel == '':
+                    pass
+                elif sel in pbytes:
+                    vp = 'x86_enc_p_%s' % sel
+                elif sel in maps:
+                    vm = 'x86_enc_m_%s' % sel
+                elif sel in widths:
+                    vw = 'x86_enc_w_%s' % sel
+                elif sel in lengths:
+                    vl = 'x86_enc_l_%s' % sel
+                elif sel in flags:
+                    vf = 'x86_enc_f_%s' % sel
+                else:
+                    raise Exception("unknown element '%s' for encoding"
+                        " '%s" % (sel, enc))
+            if vp:
+                pl += [vp]
+            if vm:
+                pl += [vm]
+            if vw:
+                pl += [vw]
+            if vl:
+                pl += [vl]
+            if vf:
+                pl += [vf]
+            if p == 'vex' or p == 'evex' or p == 'lex':
+                has_pfx = True
+        elif el in maps and len(comps) > 1 and not (has_map or has_pfx):
+            pl += ['x86_enc_m_%s' % el]
+            has_map = True
+        elif el in r_suffixes:
+            pl += ['x86_enc_r_%s' % el]
+        elif el in s_suffixes:
+            pl += ['x86_enc_s_%s' % el]
+        elif el in imm:
+            if has_imm:
+                # additional immediate used by CALLF/JMPF/ENTER
+                if el in { 'ib', 'i16' }:
+                    pl += ['x86_enc_j_%s' % el]
+                else:
+                    raise Exception("illegal immediate '%s' for encoding"
+                        " '%s" % (el, enc))
+            else:
+                pl += ['x86_enc_i_%s' % el]
+                has_imm = True
+        elif el in mods:
+            if oplen == 2:
+                raise Exception("opcode '%s' limit exceeded for encoding"
+                    " '%s" % (el, enc))
+            pl += ['x86_enc_f_modrm_r' if el == '/r' else 'x86_enc_f_modrm_n']
+            if el != '/r':
+                opc[oplen] = '0x{:02x}'.format(int(el[1]) << 3)
+                opm[oplen] = '0x38'
+            oplen += 1
+        elif len(el) == 2 and is_hex:
+            if oplen == 2:
+                raise Exception("opcode '%s' limit exceeded for encoding"
+                    " '%s" % (el, enc))
+            if oplen == 1:
+                pl += ['x86_enc_f_opcode']
+            opc[oplen] = '0x%s' % el[0:2]
+            opm[oplen] = '0xff'
+            oplen += 1
+        elif len(el) == 4 and is_hex and el[2:4] == '+r':
+            if oplen == 2:
+                raise Exception("opcode '%s' limit exceeded for encoding "
+                    "'%s" % (el, enc))
+            pl += ['x86_enc_%s_opcode_r' % ('o' if oplen == 0 else 'f')]
+            opc[oplen] = '0x%s' % el[0:2]
+            opm[oplen] = '0xf8'
+            oplen += 1
+        else:
+            raise Exception("unknown element '%s' for encoding "
+                "'%s" % (el, enc))
+    return "|".join(pl), opc, opm
+
+def translate_operands(operands):
+    oprlist = []
+    typpat = re.compile('([if])(\\d+)x(\\d+)')
+    for i,arg0 in enumerate(operands):
+        flags = arg0.split('{')
+        argcomps = []
+        for j,arg1 in enumerate(flags):
+            cp = arg1.find('}')
+            if cp == -1:
+                arg1 = arg1.replace(':','_')
+                argp = []
+                for arg2 in arg1.split('/'):
+                    m = typpat.match(arg2)
+                    if m:
+                        argcomps += ['x86_opr_' + arg2]
+                    else:
+                        argp += [arg2]
+                argcomps += ['x86_opr_' + '_'.join(argp)]
+            else:
+                arg1 = arg1.replace('}','')
+                argcomps += ['x86_opr_flag_' + arg1]
+        oprlist += ["|".join(argcomps)]
+    return oprlist
+
+def translate_order(order):
+    ol = []
+    if order:
+        for o in order.split(','):
+            o = o.replace(':','_')
+            ol.append("|".join(map(lambda x: 'x86_ord_' + x, o.split('/'))))
+    return ol
+
+def print_insn(x86_insn):
+    for row in x86_insn:
+        opcode, enc, modes, ext, order, tt, desc = row
+        opcode = opcode.replace('reg_','')
+        print("| %-53s | %-31s | %-23s | %-8s |" % \
+            (opcode, enc, order, modes))
+
+def opcode_list(x86_insn):
+    ops = set()
+    for row in x86_insn:
+        opcode, enc, modes, ext, order, tt, desc = row
+        op, opr = split_opcode(opcode)
+        ops.add(op)
+    return ['NIL'] + sorted(ops)
+
+def operand_list(x86_insn):
+    oprset = set()
+    for idx, row in enumerate(x86_insn):
+        opcode, enc, modes, ext, order, tt, desc = row
+        op, opr = split_opcode(opcode)
+        oprset.add(tuple(translate_operands(opr)))
+    return sorted(oprset)
+
+def order_list(x86_insn):
+    ordset = set()
+    for idx, row in enumerate(x86_insn):
+        opcode, enc, modes, ext, order, tt, desc = row
+        ordset.add(tuple(translate_order(order)))
+    return sorted(ordset)
+
+opcode_enums_template = """/* generated source */
+enum x86_reg\n{%s};
+enum x86_op\n{%s};"""
+
+opcode_table_template = """/* generated source */
+const size_t x86_opc_table_size = %d;
+const size_t x86_opr_table_size = %d;
+const size_t x86_ord_table_size = %d;
+const size_t x86_op_names_size = %d;
+const x86_opc_data x86_opc_table[] =\n{
+  { x86_op_NIL, 0, 0, 0, 0, { { 0, 0 } }, { { 0, 0 } } },%s};
+const x86_opr_data x86_opr_table[] =\n{%s};
+const x86_ord_data x86_ord_table[] =\n{%s};
+const char* x86_op_names[] =\n{%s};
+const char* x86_reg_names[512] =\n{%s};"""
+
+def print_opcode_enums(x86_reg, x86_insn):
+    regstr, opstr = '\n', '\n'
+    for i,s,f in x86_reg:
+        n = s.replace('(','').replace(')','')
+        regstr += '\n' if len(s) == 0 else \
+            '  %-10s = %s,\n' % ('x86_%s' % n, 'x86_%s | %d' % (f, i))
+    for op in opcode_list(x86_insn):
+        opstr += '    x86_op_%s,\n' % op
+    print(opcode_enums_template % (regstr, opstr))
+
+def print_opcode_tables(x86_reg, x86_insn):
+    oplist = opcode_list(x86_insn)
+    oprlist = operand_list(x86_insn)
+    ordlist = order_list(x86_insn)
+    oprmap = {v: i for i, v in enumerate(oprlist)}
+    ordmap = {v: i for i, v in enumerate(ordlist)}
+    opcstr, oprstr, ordstr, opsstr, regstr = '\n', '\n', '\n', '\n', '\n'
+    for idx, row in enumerate(x86_insn):
+        opcode, enc, modes, ext, order, tt, desc = row
+        op, opr = split_opcode(opcode)
+        oprl = translate_operands(opr)
+        ordl = translate_order(order)
+        oprc = oprmap[tuple(oprl)]
+        ordc = ordmap[tuple(ordl)]
+        modes = translate_modes(modes)
+        enc, opc, opm = translate_encoding(enc)
+        opcstr += '  { %s, %s, %d, %d, %s, { %s }, { %s } },\n' % \
+            ('x86_op_%s' % op, modes, oprc, ordc, enc,
+                '{ %s, %s }' % (opc[0], opc[1]),
+                '{ %s, %s }' % (opm[0], opm[1]))
+    for x in oprlist:
+        oprstr += '  { { %s } },\n' % (", ".join(['0'] if not x else x))
+    for x in ordlist:
+        ordstr += '  { { %s } },\n' % (", ".join(['0'] if not x else x))
+    for op in oplist:
+        opsstr += '    "' + op.lower() + '",\n'
+    for i,s,f in x86_reg:
+        n = s.replace('(','').replace(')','')
+        regstr += '\n' if len(s) == 0 else \
+                  '    %-12s = \"%s\",\n' % ('[x86_%s]' % n, s)
+    print(opcode_table_template % (
+        len(x86_insn) + 1, len(oprlist), len(ordlist), len(oplist),
+        opcstr, oprstr, ordstr, opsstr, regstr)
+    )
+
+def read_data(files):
+    data = []
+    if not isinstance(files, list):
+        files = glob.glob(files)
+    for csvpath in files:
+        file = open(csvpath, encoding='utf-8-sig', newline='')
+        reader = csv.DictReader(file, delimiter=',', quotechar='"')
+        for row in reader:
+            data += [row]
+    data.sort(key=lambda x: (
+            x['Instruction'].split(' ')[0],
+            x['Opcode'].split(' ')[1],
+            x['Instruction']))
+    insn = []
+    for row in data:
+        opcode = cleanup_opcode(row['Instruction'])
+        enc = cleanup_encoding(row['Opcode'])
+        modes = x86_mode(row)
+        ext = row['Feature Flags']
+        order = x86_operand(opcode,row)
+        tt = row['Tuple Type']
+        desc = row['Description']
+        insn += [[opcode, enc, modes, ext, order, tt, desc]]
+    return insn
+
+def parse_table(rows):
+    rows = [row.strip() for row in rows]
+    data = []
+    obj = []
+    h1 = None
+    begun = False
+    for row in rows:
+        if row.startswith("#"):
+            space = row.index(' ')
+            hashes = row[:space]
+            heading = row[space+1:]
+            depth = hashes.count('#')
+            if not h1:
+                h1 = heading
+            obj.append(TableSection(heading, depth))
+        elif row.startswith("|"):
+            cells = row.split('|')
+            cells = [cell.strip() for cell in cells if cell.strip()]
+            if cells[0].startswith("-") or cells[0].startswith(":"):
+                begun = True
+                obj.append(TableHeader())
+            elif begun:
+                data.append(cells)
+                obj.append(TableData(cells))
+        else:
+            begun = False
+            obj.append(TableText(row))
+    return { 'title': h1, 'data': data, 'obj': obj }
+
+def read_file(file_path):
+    try:
+        with open(file_path, 'r') as file:
+            lines = file.readlines()
+            lines = [line.strip() for line in lines]
+        return lines
+    except FileNotFoundError:
+        print(f"File not found: {file_path}")
+        return []
+
+def make_map(x86_insn):
+    insn_map = dict()
+    for row in x86_insn:
+        opcode, enc, modes, ext, order, tt, desc = row
+        op, opr = split_opcode(opcode)
+        if op not in insn_map:
+            insn_map[op] = list()
+        insn_map[op].append(row)
+    return insn_map
+
+#
+# description table types
+#
+class TableText():
+    def __init__(self,text):
+        self.text = text
+class TableSection():
+    def __init__(self,heading,depth):
+        self.heading = heading
+        self.depth = depth
+class TableHeader():
+    def __init__(self):
+        return
+class TableData():
+    def __init__(self,cells):
+        self.cells = cells
+
+#
+# print descriptions with instructions
+#
+def table_text_insn(self,x86_desc):
+    return ""
+def table_section_insn(self,x86_desc):
+    return "%s %s\n\n" % ("#" * self.depth, self.heading)
+def table_header_insn(self,x86_desc):
+    return ""
+def table_data_insn(self,x86_desc):
+    insn_map = x86_desc['insn']
+    insn, desc = self.cells
+    text = ""
+    insn_list = []
+    o = insn.find("cc")
+    if insn.startswith("v"):
+        insn_list.append(insn[1:])
+        insn_list.append(insn.upper())
+    elif o >= 0:
+        for cc in cc_all:
+            new_insn = '%s%s%s' % (insn[0:o], cc, insn[o+2:])
+            insn_list.append(new_insn)
+    else:
+        insn_list.append(insn)
+    if len(insn_list) > 0:
+        text += "\n"
+        text += "| %-51s | %-29s | %-23s | %-8s |\n" % \
+            ("opcode", "encoding", "order", "modes")
+        text += "|:%-51s-|:%-29s-|:%-23s-|:%-8s-|\n" % \
+            ("-"*51, "-"*29, "-"*23, "-"*8)
+        for insn_name in insn_list:
+            if insn_name in insn_map:
+                for row in insn_map[insn_name]:
+                    opcode, enc, modes, ext, order, tt, desc = row
+                    opcode = opcode.replace('reg_','')
+                    text += "| %-51s | %-29s | %-23s | %-8s |\n" % \
+                        (opcode, enc, order, modes)
+        text += "|:%-51s-|:%-29s-|:%-23s-|:%-8s-|\n" % \
+            ("-"*51, "-"*29, "-"*23, "-"*8)
+    text += "\n\n"
+    return "%s %s\n%s" % ("[%s]" % insn, "# %s" % desc, text)
+
+table_insn = {
+    TableText: table_text_insn, TableSection: table_section_insn,
+    TableHeader: table_header_insn, TableData: table_data_insn,
+}
+
+def print_fancy_insn(x86_desc):
+    for obj in x86_desc['tab']['obj']:
+        print(table_insn[type(obj)](obj, x86_desc), end="")
+
+parser = argparse.ArgumentParser(description='x86 table generator')
+parser.add_argument('files',
+                    default='data/*.csv', nargs='*',
+                    help='x86 csv metadata')
+parser.add_argument('--print-insn',
+                    default=False, action='store_true',
+                    help='print instructions')
+parser.add_argument('--print-fancy-insn',
+                    default=False, action='store_true',
+                    help='print fancy instructions')
+parser.add_argument('--print-opcode-enums',
+                    default=False, action='store_true',
+                    help='print register enum')
+parser.add_argument('--print-opcode-tables',
+                    default=False, action='store_true',
+                    help='print register strings')
+parser.add_argument('--output-file', type=argparse.FileType('w'),
+                    help="filename to write output to")
+args = parser.parse_args()
+
+x86_reg = reg_table()
+x86_insn = read_data(args.files)
+
+if args.output_file:
+    sys.stdout = args.output_file
+if args.print_insn:
+    print_insn(x86_insn)
+if args.print_opcode_enums:
+    print_opcode_enums(x86_reg, x86_insn)
+if args.print_opcode_tables:
+    print_opcode_tables(x86_reg, x86_insn)
Signature · 1 line
2.43.0
#5 lore raw

PATCH 4/4 x86-disas: add x86-mini disassembler implementation

In reply to Michael Clark

the x86-mini library is a lightweight x86 encoder, decoder, and disassembler that uses extensions to the Intel instruction set metadata to encode modern VEX/EVEX instructions and legacy instructions with a parameterized LEX (legacy extension) format.

this patch adds the x86-tablegen.py script, the disassembler, a print_insn_x86 implementation plus host and target cpu stubs.

---
 disas/disas-host.c      |    5 +
 disas/meson.build       |   97 ++
 disas/x86-core.c        | 2689 +++++++++++++++++++++++++++++++++++++++
 disas/x86-disas.c       |   94 ++
 disas/x86.h             | 1969 ++++++++++++++++++++++++++++
 include/disas/dis-asm.h |    1 +
 target/i386/cpu.c       |    7 +
 7 files changed, 4862 insertions(+)
 create mode 100644 disas/x86-core.c
 create mode 100644 disas/x86-disas.c
 create mode 100644 disas/x86.h
disas/disas-host.c +5 -0
index 8146fafe804c..e05dec5c76f6 100644
@@ -7,6 +7,7 @@
 #include "disas/disas.h"
 #include "disas/capstone.h"
 #include "disas-internal.h"
+#include "x86.h"
 
 
 /*
@@ -50,12 +51,16 @@ static void initialize_debug_host(CPUDebug *s)
     s->info.cap_mode = CS_MODE_32;
     s->info.cap_insn_unit = 1;
     s->info.cap_insn_split = 8;
+    s->info.private_data = x86_ctx_create(x86_modes_32);
+    s->info.print_insn = print_insn_x86;
 #elif defined(__x86_64__)
     s->info.mach = bfd_mach_x86_64;
     s->info.cap_arch = CS_ARCH_X86;
     s->info.cap_mode = CS_MODE_64;
     s->info.cap_insn_unit = 1;
     s->info.cap_insn_split = 8;
+    s->info.private_data = x86_ctx_create(x86_modes_64);
+    s->info.print_insn = print_insn_x86;
 #elif defined(_ARCH_PPC)
     s->info.cap_arch = CS_ARCH_PPC;
 # ifdef _ARCH_PPC64
disas/meson.build +97 -0

103 lines not on this page · raw message

disas/x86-core.c new file +2689 -0

2,689 lines not on this page · raw message

disas/x86-disas.c new file +94 -0

94 lines not on this page · raw message

disas/x86.h new file +1969 -0

91 lines not on this page · raw message

include/disas/dis-asm.h +1 -0
index 3b50ecfb5409..fd8aa326948f 100644

Lines of this file are not shown. View the raw message.

target/i386/cpu.c +7 -0
index 1b9c11022c48..9b23e2193630 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.43.0

Part of the diff is not shown here. View the raw message.

#6 lore raw

Re: [PATCH v1 4/4] x86-disas: add x86-mini disassembler implementation

to save time on reviews. I had a look over the patch in light of QEMU conventions I neglected due to it being portable code.

this is what I have found so far:

- use g_malloc/g_malloc0/g_free instead of malloc/calloc/free.
- remove duplicate unused definition of ctz/clz/popcnt.
- remove some magic constants and replace with math.
- remove some unnecessary casts.

the only thing that forks the code is the allocator conversion as most of the code is quite functional/combinatorial. I could get away with layering a patch on top of the upstream code.

I noticed QEMU doesn't use alloca much. I prefer it for small temporary function scope allocations because it is super cheap.

I was thinking. it would be nice to pipe the bytes to another thread. that way the disassembler won't trash the cache and it might run a little faster. because otherwise it will dominate L1 cache and compete with the translator for cache. one could use something like this pipe, with the addition of a sleeping mutex. I am using it in a kernel with spinlocks but it would not be too hard to add a sleeping mutex on qfull. it would be faster than sockets because it's just a couple of atomic compare swap and memcpy in the case that the queue is not full. one could copy a whole translation block at a time. that limits the cache footprint to stuff already in cache.

- https://github.com/michaeljclark/cpipe/

I will spin a v2 in a few weeks time. with this sort of thing:

disas/x86-core.c +7 -5
index d2704bf839f4..8a08f9bff4b3 100644
@@ -27,6 +27,7 @@
 
 #include "disas/x86.h"
 #include "disas/x86-tables.inc"
+#include "qemu/osdep.h"
 
 #define array_size(arr) (sizeof(arr) / sizeof(arr[0]))
 
@@ -787,7 +788,7 @@ static int x86_opc_data_compare_alpha(const void *p1, const void *p2)
 
 static x86_table_idx x86_opc_table_index(size_t n)
 {
-    x86_table_idx tab = { n, malloc(sizeof(size_t) * n) };
+    x86_table_idx tab = { n, g_malloc(sizeof(size_t) * n) };
     for (size_t i = 0; i < tab.count; i++) tab.idx[i] = i;
     return tab;
 }
@@ -819,7 +820,7 @@ x86_table_idx x86_opc_table_filter(x86_table_idx tab, uint modes)
         const x86_opc_data *d = x86_opc_table + tab.idx[i];
         if (d->mode & modes) count++;
     }
-    x86_table_idx newtab = { count, malloc(sizeof(size_t) * count) };
+    x86_table_idx newtab = { count, g_malloc(sizeof(size_t) * count) };
     count = 0;
     for (size_t i = 0; i < tab.count; i++) {
         const x86_opc_data *d = x86_opc_table + tab.idx[i];
@@ -1079,24 +1080,25 @@ static void x86_build_accel_table(x86_acc_idx *idx, x86_acc_entry *acc)
 
 static x86_acc_idx *x86_table_build(uint modes)
 {
-    x86_acc_idx *idx = calloc(1, sizeof(x86_acc_idx));
+    x86_acc_idx *idx = g_malloc0(sizeof(x86_acc_idx));
     x86_table_idx tab = x86_opc_table_sorted(x86_opc_table_filter(
         x86_opc_table_identity(), modes), x86_sort_numeric);
-    ullong *modfun = (ullong *)calloc(2048, sizeof(ullong));
-    ullong *modmod = (ullong *)calloc(2048, sizeof(ullong));
+    size_t bmap_size = /*t,p,m*/ 512 * /*opcode*/ 256 >> /*bits*/ 3;
+    ullong *modfun = g_malloc0(bmap_size);
+    ullong *modmod = g_malloc0(bmap_size);
     x86_build_prefix_clashes(idx, tab, modfun, modmod);
     x86_build_prefix_table(idx, tab, NULL, &idx->map_count, modfun, 

modmod);
- idx->map = calloc(idx->map_count, sizeof(x86_opc_data));

+    idx->map = g_malloc0(idx->map_count * sizeof(x86_opc_data));
     x86_build_prefix_table(idx, tab, idx->map, NULL, modfun, modmod);
     qsort(idx->map, idx->map_count, sizeof(x86_opc_data),
         x86_opc_data_compare_build);
-    idx->page_offsets = calloc(512, sizeof(uchar));
+    idx->page_offsets = g_malloc0(/*t,p,m*/ 512);
     idx->acc_count = x86_build_accel_offsets(idx);
-    idx->acc = calloc(sizeof(x86_acc_entry), idx->acc_count);
+    idx->acc = g_malloc0(idx->acc_count * sizeof(x86_acc_entry));
     x86_build_accel_table(idx, idx->acc);
-    free(tab.idx);
-    free(modfun);
-    free(modmod);
+    g_free(tab.idx);
+    g_free(modfun);
+    g_free(modmod);
     return idx;

}

@@ -2674,7 +2676,7 @@ err:

x86_ctx *x86_ctx_create(uint mode)
{
- x86_ctx *ctx = malloc(sizeof(x86_ctx));

+    x86_ctx *ctx = g_malloc(sizeof(x86_ctx));
     ctx->mode = mode;
     ctx->idx = x86_table_build(mode);
     return ctx;

@@ -2682,8 +2684,8 @@ x86_ctx *x86_ctx_create(uint mode)

void x86_ctx_destroy(x86_ctx *ctx)
{

-    free(ctx->idx->page_offsets);
-    free(ctx->idx->map);
-    free(ctx->idx->acc);
-    free(ctx);
+    g_free(ctx->idx->page_offsets);
+    g_free(ctx->idx->map);
+    g_free(ctx->idx->acc);
+    g_free(ctx);

}

disas/x86.h +0 -96

102 lines not on this page · raw message

#7 lore raw

Re: [PATCH v1 4/4] x86-disas: add x86-mini disassembler implementation

In reply to Michael Clark
Quoted 30 lines · Michael Clark
disas/x86-core.c new file +30 -0
+static x86_opc_prefix x86_table_make_prefix(const x86_opc_data *d,
+    const x86_opr_data *o, const x86_ord_data *p)
+{
+    x86_opc_prefix tp;
+    memset(&tp, 0, sizeof(tp));
+
+    /* extract prefix and synthesize width prefixes */
+    switch (x86_enc_type(d->enc)) {
+    case x86_enc_t_lex:
+    case x86_enc_t_vex:
+    case x86_enc_t_evex:
+        switch (d->enc & x86_enc_w_mask) {
+        case x86_enc_w_wig:
+        case x86_enc_w_wn:
+        case x86_enc_w_wb:
+        case x86_enc_w_w0: break;
+        case x86_enc_w_w1: tp.pfx = x86_enc_p_rexw; break;
+        case x86_enc_w_wx: tp.pfx_w = x86_enc_p_rexw; /* fallthrough */
+        case x86_enc_w_ww: tp.pfx_o = x86_enc_p_66; break;
+        }
+        break;
+     }
+
+    /* find register or memory operand mapping to modrm.rm field
+     * so that we can add mod=0b11 or mod!=0b11 to modrm mask */
+    tp.modfun = x86_enc_func(d->enc) == x86_enc_f_modrm_n;
+    for (size_t i = 0; i < array_size(o->opr) && o->opr[i]; i++) {
+        uint isreg = x86_opr_type_val(o->opr[i]) >= x86_opr_reg;
+        uint ismem = x86_opr_has_mem(o->opr[i]);
+        uint ismrm = x86_ord_type_val(p->ord[i]) == x86_ord_mrm;

disas/x86-core.c line 910

Quoted 10 lines
disas/x86-core.c new file +10 -0
+        if (ismrm) {
+            if (isreg && !ismem) {
+                tp.modreg = 1; /* mod == 0b11 */
+                break;
+            } else if (!isreg && ismem) {
+                tp.modmem = 1; /* mod != 0b11 */
+                break;
+            }
+        }
+    }

I am already relatively strictly following QEMU conventions for single-line and multi-line comments. I don't remember seeing a checkpatch.pl report for the above multi-line comment. I wonder if the constraint is restricted to top-level comments? I left this as-is due to symmetry with the other comments in this block as they are single-line and it looks better. this is very pedantic.

so am curious about a determination on the commenting convention.

I have a disagreement about unbraced 'if' in switch because IMHO the QEMU rules make combinatorial logic sparse and hard to read. I also typically put the first brace of functions on their own line so there is space between function signature and first line. those are the two main rules I break. my coding-style has lots of switch statements because I rely on switch constant analysis and jump table conversion because it tends to translate to fast code. also I linearize them explicitly because not all compilers detect a constant stride for index canonicalization in switch constants. that is where the bulk of the checkpatch.pl warnings show up.

disas/x86-core.c line 920

Quoted 9 lines
disas/x86-core.c new file +9 -0
+    /* explict second opcode byte has mod == 0b11 */
+    if (d->opm[1] == 0xff && (d->opc[1] & 0xc0) == 0xc0 &&
+        !tp.modreg && !tp.modmem)
+    {
+        tp.modreg = 1;
+    }
+
+    return tp;
+}

fyi I have made a x86-mini-v2 branch with the changes I mentioned in an email yesterday but it is still in flux:

https://github.com/michaeljclark/qemu/commits/x86-mini-v2

I still don't expect this code to be merged any-time-soon. maybe in the future if QEMU gains the ability to run TCG full-system under hypervisor with accelerated page tables. I'm also considering digging out the most recent QEMU or tcc TCG that is fully MIT-licensed as a starting point for IR.

the patch set may eventually become compelling if there is a complete TCG supporting all AVX-512 vector ops. maybe this is already there but I am not reading the GPL code in QEMU. I am unsure about that code because a lot of code is by-file licensed. it is questionable when the provenance originates inside QEMU as opposed to MIT-licensed or dual-licensed code (like FreeType) that is clearly of external origin. as a modern embedded TCG would be quite useful in Rui's chibicc or the MIT-licensed version of tcc:

- https://github.com/rui314/chibicc
- https://github.com/absop/Tinycc/blob/master/RELICENSING

and I am confessing about a snippet of code. this may look familiar. there is one enum and two functions that were derived from TCG X86 but they are unused. so I should add Fabrice's original TCG MIT-license header or remove them.

I am pretty sure I checked the provenance for the version of TCG that I used but I need to add an explicit reference or delete these definitions. they can't really be written a different way because they are more like reference data and invariant logic based on X86 ISA constraints:

+/*
+ * test conditions
+ */
+
+enum
+{

+    /* non-signed */
+    x86_never  = (0 | 0 | 0 | 0),
+    x86_always = (0 | 0 | 0 | 1),
+    x86_eq     = (8 | 0 | 0 | 0),
+    x86_ne     = (8 | 0 | 0 | 1),
+    /* signed */
+    x86_lt     = (0 | 0 | 2 | 0),
+    x86_ge     = (0 | 0 | 2 | 1),
+    x86_le     = (8 | 0 | 2 | 0),
+    x86_gt     = (8 | 0 | 2 | 1),
+    /* unsigned */
+    x86_ltu    = (0 | 4 | 0 | 0),
+    x86_geu    = (0 | 4 | 0 | 1),
+    x86_leu    = (8 | 4 | 0 | 0),
+    x86_gtu    = (8 | 4 | 0 | 1),

+};

+/*
+ * invert condition
+ */
+
+static inline uint x86_invert_cond(uint c) {
+ return c ^ 1;
+}
+
+/*
+ * swap condition operands
+ */
+
+static inline uint x86_swap_cond(uint c) {
+ return c & 6 ? c ^ 9 : c;
+}