Skip to content

v5: Speedup x86 decoding with the help of LUT tables#2907

Merged
Rot127 merged 3 commits into
capstone-engine:v5from
trufae:x86lut
May 6, 2026
Merged

v5: Speedup x86 decoding with the help of LUT tables#2907
Rot127 merged 3 commits into
capstone-engine:v5from
trufae:x86lut

Conversation

@trufae
Copy link
Copy Markdown
Contributor

@trufae trufae commented Apr 30, 2026

lu: Disassembled 37602620 instructions (35221820 valid, 2380800 bad), 6015.21 ms
v5: Disassembled 37602620 instructions (35221820 valid, 2380800 bad), 7291.75 ms

That's around 20% faster

Your checklist for this pull request

  • I've documented or updated the documentation of every API function and struct this PR changes.
  • I've added tests that prove my fix is effective or that my feature works (if possible)

Detailed description

arm64 disassembler uses lut tables to speedup decoding, x86 was the slow one here, so i just make it happen there
...

Test plan

$ cat /tmp/b.sh
#!/bin/sh
C=$1
[ -z "$C" ] && C=2
rm -rf build
export CFLAGS=-O3
cmake -B build
make -C build CFLAGS=-O2 -j
make -C suite/benchmark clean
make -C suite/benchmark
suite/benchmark/test_file_benchmark $C 0 5651232 /usr/bin/vim
0$

...

Closing issues

...

lu: Disassembled 37602620 instructions (35221820 valid, 2380800 bad), 6015.21 ms
v5: Disassembled 37602620 instructions (35221820 valid, 2380800 bad), 7291.75 ms
@github-actions github-actions Bot added X86 Arch CS-core-files auto-sync labels Apr 30, 2026
@trufae trufae changed the title Speedup x86 decoding with the help of LUT tables v5: Speedup x86 decoding with the help of LUT tables Apr 30, 2026
Copy link
Copy Markdown
Collaborator

@Rot127 Rot127 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I am not the biggest fan of allocating it instead of a static table, but we can change this once we find the time to update x86.

Comment thread arch/X86/X86Mapping.c Outdated

// Build insn_reg lookup table (low 16 bits = Intel, high 16 bits = ATT).
h->x86_insn_reg_lut = (uint32_t *)cs_mem_calloc(id_max + 1, sizeof(uint32_t));
if (h->x86_insn_reg_lut) {
Copy link
Copy Markdown
Collaborator

@Rot127 Rot127 May 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invert and return early please. Also CS_ASSERT_RET

Comment thread arch/X86/X86Mapping.c Outdated
Comment thread arch/X86/X86Mapping.c Outdated
Comment thread arch/X86/X86Mapping.c Outdated
@Rot127 Rot127 merged commit 30d610c into capstone-engine:v5 May 6, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CS-core-files auto-sync X86 Arch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants