Commit 56c5f74
committed
Optimize Capstone disassembly performance across the stack
Thread-safe per-handle O(1) lookup tables in Capstone X86:
- Move lookup tables from static globals to cs_struct fields
- Build tables in X86_global_init(), free in cs_close()
- Add find_insn_h() and X86_insn_reg_{intel,att}_h() per-handle variants
- Keep binary search fallback for decoder paths without handle access
- Replace vsnprintf number formatting with fast custom formatters in SStream
- Use memset for MCInst tied_op_idx initialization
ARM plugin (plugin_cs.c):
- Switch from allocating cs_disasm() to stack-based cs_disasm_iter()
- Replace r_str_newf mnemonic construction with direct malloc+memcpy
x86 plugin (plugin_cs.c):
- Replace r_str_newf + r_str_replace (2 allocs) with single malloc + in-place memmove
- Remove redundant per-instruction cs_option(CS_OPT_DETAIL) call
- Inline cs_len_prefix_opcode() for branch penalty elimination
Core disassembly (disasm.c):
- Compute decode_mask once based on display settings (asm.emu, asm.cmt.esil)
- Skip ESIL/OPEX generation when not needed for display
- Use R_ARCH_OP_MASK_BASIC for color-only decode paths
Analysis (fcn.c):
- Remove R_ARCH_OP_MASK_ESIL from default analysis loop for non-ARM archs
- ESIL generation only when architecture needs it for pattern matching
https://claude.ai/code/session_01KDR9eBZ4vEAftFBQ2vuhmr1 parent a1bae73 commit 56c5f74
5 files changed
Lines changed: 365 additions & 209 deletions
File tree
- libr
- anal
- arch/p
- arm
- x86
- core
- subprojects/packagefiles/capstone-v5/capstone-patches
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
853 | 853 | | |
854 | 854 | | |
855 | 855 | | |
856 | | - | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
857 | 859 | | |
858 | 860 | | |
859 | 861 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4692 | 4692 | | |
4693 | 4693 | | |
4694 | 4694 | | |
4695 | | - | |
4696 | 4695 | | |
4697 | 4696 | | |
4698 | 4697 | | |
4699 | 4698 | | |
4700 | 4699 | | |
4701 | 4700 | | |
4702 | | - | |
4703 | | - | |
| 4701 | + | |
| 4702 | + | |
| 4703 | + | |
| 4704 | + | |
| 4705 | + | |
| 4706 | + | |
| 4707 | + | |
| 4708 | + | |
| 4709 | + | |
| 4710 | + | |
| 4711 | + | |
4704 | 4712 | | |
4705 | 4713 | | |
4706 | | - | |
4707 | | - | |
4708 | | - | |
4709 | | - | |
4710 | | - | |
| 4714 | + | |
| 4715 | + | |
| 4716 | + | |
| 4717 | + | |
| 4718 | + | |
| 4719 | + | |
| 4720 | + | |
| 4721 | + | |
| 4722 | + | |
| 4723 | + | |
| 4724 | + | |
| 4725 | + | |
| 4726 | + | |
| 4727 | + | |
| 4728 | + | |
| 4729 | + | |
| 4730 | + | |
4711 | 4731 | | |
4712 | 4732 | | |
4713 | 4733 | | |
| |||
4734 | 4754 | | |
4735 | 4755 | | |
4736 | 4756 | | |
4737 | | - | |
4738 | 4757 | | |
4739 | | - | |
4740 | 4758 | | |
4741 | 4759 | | |
4742 | 4760 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4140 | 4140 | | |
4141 | 4141 | | |
4142 | 4142 | | |
4143 | | - | |
4144 | | - | |
4145 | | - | |
4146 | | - | |
4147 | | - | |
4148 | | - | |
| 4143 | + | |
| 4144 | + | |
4149 | 4145 | | |
4150 | 4146 | | |
4151 | 4147 | | |
| |||
4191 | 4187 | | |
4192 | 4188 | | |
4193 | 4189 | | |
4194 | | - | |
| 4190 | + | |
4195 | 4191 | | |
4196 | 4192 | | |
4197 | 4193 | | |
| |||
4222 | 4218 | | |
4223 | 4219 | | |
4224 | 4220 | | |
4225 | | - | |
4226 | | - | |
4227 | | - | |
4228 | | - | |
4229 | | - | |
| 4221 | + | |
| 4222 | + | |
| 4223 | + | |
| 4224 | + | |
| 4225 | + | |
| 4226 | + | |
| 4227 | + | |
| 4228 | + | |
| 4229 | + | |
| 4230 | + | |
| 4231 | + | |
| 4232 | + | |
| 4233 | + | |
| 4234 | + | |
| 4235 | + | |
| 4236 | + | |
4230 | 4237 | | |
4231 | | - | |
| 4238 | + | |
| 4239 | + | |
| 4240 | + | |
| 4241 | + | |
4232 | 4242 | | |
4233 | 4243 | | |
4234 | | - | |
4235 | | - | |
4236 | | - | |
4237 | | - | |
| 4244 | + | |
| 4245 | + | |
| 4246 | + | |
| 4247 | + | |
4238 | 4248 | | |
4239 | 4249 | | |
4240 | 4250 | | |
| 4251 | + | |
4241 | 4252 | | |
4242 | 4253 | | |
4243 | 4254 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
| 146 | + | |
146 | 147 | | |
147 | 148 | | |
148 | 149 | | |
| |||
976 | 977 | | |
977 | 978 | | |
978 | 979 | | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
979 | 985 | | |
980 | 986 | | |
981 | 987 | | |
| |||
6683 | 6689 | | |
6684 | 6690 | | |
6685 | 6691 | | |
6686 | | - | |
| 6692 | + | |
6687 | 6693 | | |
6688 | 6694 | | |
6689 | 6695 | | |
| |||
6798 | 6804 | | |
6799 | 6805 | | |
6800 | 6806 | | |
6801 | | - | |
| 6807 | + | |
6802 | 6808 | | |
6803 | 6809 | | |
6804 | 6810 | | |
| |||
6914 | 6920 | | |
6915 | 6921 | | |
6916 | 6922 | | |
6917 | | - | |
| 6923 | + | |
6918 | 6924 | | |
6919 | 6925 | | |
6920 | 6926 | | |
| |||
7369 | 7375 | | |
7370 | 7376 | | |
7371 | 7377 | | |
7372 | | - | |
| 7378 | + | |
7373 | 7379 | | |
7374 | 7380 | | |
7375 | 7381 | | |
| |||
7719 | 7725 | | |
7720 | 7726 | | |
7721 | 7727 | | |
7722 | | - | |
| 7728 | + | |
7723 | 7729 | | |
7724 | 7730 | | |
7725 | 7731 | | |
| |||
8008 | 8014 | | |
8009 | 8015 | | |
8010 | 8016 | | |
8011 | | - | |
| 8017 | + | |
8012 | 8018 | | |
8013 | 8019 | | |
8014 | 8020 | | |
| |||
0 commit comments