131 Commits

Author SHA1 Message Date
Alexis Engelke
6abc971576 decode: Move instr-width to legacy path
Very few instructions set use instrwidth, so move this check as well to
the legacy path. The only affected common instructions are RET and
LEAVE.
2023-04-24 08:55:56 +02:00
Alexis Engelke
48f886e130 decode: Group all VSIB handling in single branch
Most instructions don't use VSIB encoding, so move all VSIB-related
handling to a single block behind a single branch.
2023-04-23 11:55:45 +02:00
Alexis Engelke
1290e9f094 decode: Group all EVEX-handling for ModRM operands
Most instructions aren't EVEX-encoded, so hide all uncommon paths behind
a single branch.
2023-04-23 11:29:34 +02:00
Alexis Engelke
bbc1b0b648 decode: Use macros for all desc accesses [NFC] 2023-04-23 08:57:08 +02:00
Alexis Engelke
247acd6221 decode: Unify VEX opcode escape extraction 2023-04-23 08:57:08 +02:00
Alexis Engelke
0a36604c81 decode: Change REP flag values
The new values allow for a more optimizable computation of the required
flags from the decoded prefix.
2023-04-23 08:57:08 +02:00
Alexis Engelke
538708cd21 decode: Change encoding of T16 index
This encoding change saves a shift for the "is register" part.
2023-04-23 08:57:08 +02:00
Alexis Engelke
c5f5fa1f75 decode: Simplify ModRM reg vs. mem distiction 2023-04-23 08:57:08 +02:00
Alexis Engelke
513cc709a4 decode: Handle GPH, NOP and 3DNow in legacy block 2023-04-23 08:57:08 +02:00
Alexis Engelke
dac2ff1987 decode: Encode trie node kind in 2 bits 2023-04-23 08:57:08 +02:00
Alexis Engelke
e1084be859 decode: Encode prefixes in trie
This allows to handle unescaped opcodes with a single table lookup.
2023-04-23 08:57:08 +02:00
Alexis Engelke
262370046c decode: Optimize handling of immediates 2023-04-23 08:57:08 +02:00
Alexis Engelke
957537651e decode: Optimize decoding of shift operands 2023-04-23 08:57:08 +02:00
Alexis Engelke
49f5b7b338 decode: Implement 16-bit ModRM decoding 2023-02-16 09:14:34 +01:00
Alexis Engelke
2c21073379 decode: Faster prefix decoder
This improves decoding performance by ~5%.
2023-01-21 12:30:00 +01:00
Alexis Engelke
b48495805e decode: Minor tweaks for performance 2023-01-15 13:47:11 +01:00
Alexis Engelke
955f139025 instrs: Add AVX512-FP16 instructions 2023-01-15 13:47:11 +01:00
Alexis Engelke
8550e2cac9 parseinstrs: Add support for BCST16
2-byte broadcasts cannot be inferred from the encoding and need to be
indicated in the descriptor.
2023-01-15 13:47:11 +01:00
Alexis Engelke
06832825ec fadec: Store broadcast size in segment
This is a preparation for AVX512-FP16, where the broadcast size is not
just 32/64 bit depending solely on EVEX.W, but can also be 16 bit (with
EVEX.W=0). The broadcast size therefore needs two bits, but the evex
field only had one free bit left. Store broadcast size with the segment
for now. (This is not a good fit and is likely to change at some point.)
2023-01-15 13:47:11 +01:00
Alexis Engelke
b1f7a5fe19 decode: Add UD for EVEX.z without EVEX.aaa
This was tested on hardware, where EVEX.z without EVEX.aaa reliably
causes #UD. The SDM is not too precise about this.
2023-01-15 13:47:11 +01:00
Alexis Engelke
e04aff73dc decode: Add AVX-512 support 2023-01-15 13:47:11 +01:00
Alexis Engelke
ec5a430b5c decode: Decode EVEX prefix 2023-01-15 13:40:51 +01:00
Alexis Engelke
377e362a0e decode: Handle imm_byte size differently
For byte-sized immediates, there are only two options for the operand
size: byte and the instruction's operand size. This knowledge allows to
remove the byte constraint from the set of fixed operand sizes.
2022-12-27 19:46:04 +01:00
Alexis Engelke
99a9802f50 decode: Store op size per operand type
This change doesn't really affect performance and is preparatory
work for AVX-512, where the memory operand size is required to compute
the compressed displacement.
2022-12-03 14:52:06 +01:00
Alexis Engelke
4abad24610 decode: Support half vector size
This is realized by two changes: first, GP and vector operand size are
completely separated using one extra bit. If the operand size of an
instruction is derived from VEX.L (or EVEX.L'L), then the "opsize" bits
indicate how to derive a smaller vector size (half/quarter/eighth).
2022-11-30 09:32:02 +01:00
Alexis Engelke
b817713ae8 decode: Store operand size logarithmic 2022-11-25 14:34:22 +01:00
Alexis Engelke
1c04ded9b7 decode: Merge zeroreg and vexreg
There is no instruction that uses an implicit register and an
VEX-encoded register at the same time. Thus, we can merge vexreg and
zeroreg in the instruction descriptor; the zeroreg value will be added
to the vex-operand (which is zero unless set by a VEX prefix).

This also frees 4 descriptor bits for use with AVX-512 (which will
probably need 1-2 additional unused bits, probably from the type).
2022-11-20 15:25:37 +01:00
Alexis Engelke
0c20aa4f19 decode: remove unnecessary shifts 2022-11-05 13:56:27 +01:00
Ole André Vadla Ravnås
a05d52fdd0 windows: Add support for building with MSVC 2022-11-01 19:22:43 +01:00
Alexis Engelke
2fd83903cf meson,parseinstrs: Make decode and encode optional 2022-02-20 17:15:21 +01:00
Ole André Vadla Ravnås
e98e96c28c decode: Remove inline hint on table_walk()
To avoid GCC warnings when building with `-Os`:

    warning: inlining failed in call to 'table_walk': call is
        unlikely and code size would grow [-Winline]

I don't know if this causes a performance regression when optimizing for
speed instead of size, but perhaps there's a different way we can help
the compiler make this decision in such cases.
2022-01-06 09:54:47 +01:00
Ole André Vadla Ravnås
5c35f0e40e decode: Fix LOAD_LE_8() on 32-bit systems
Where size_t is only 32 bits wide, and we end up losing the upper bits.

GCC catches this and emits a warning such as:

    warning: left shift count >= width of type [-Wshift-count-overflow]
2022-01-06 09:45:21 +01:00
Alexis Engelke
1bd5f7c572 decode: Set address size when decoding prefixes 2021-09-20 13:52:06 +02:00
Alexis Engelke
bf0425f057 decode: Expose immediate in RVMR encodings
The AMD64 instructions VPERMIL2PS and VPERMIL2PD (currently not
supported) encode a fifth immediate operand in the lower bits of the
re-purposed immediate. Expose this value in any case so that no
information gets lost during decoding.
2021-09-13 17:38:24 +02:00
Alexis Engelke
50f052488d decode: More precise register types 2021-04-02 17:20:23 +02:00
Alexis Engelke
f17d84cee6 format: Emit XACQUIRE/XRELEASE
As CMPXCHGD has a mandatory prefix table, it is absolutely necessary
that the presence of any tables does not modify any decoding state.
2021-01-23 14:35:08 +01:00
Alexis Engelke
fe68dbb743 decode: Fix LOCK handling for MOV CR/DR 2021-01-23 14:28:27 +01:00
Alexis Engelke
bd611902b0 parseinstrs: Add separate ModRM indicator to desc
Some instructions have no ModRM operand and no extended opcode but still
consume a ModRM byte.
2021-01-23 13:25:23 +01:00
Alexis Engelke
9d7b584121 decode: Verify 3DNow! opcode validity 2021-01-10 18:53:32 +01:00
Alexis Engelke
9245a97248 instrs: Add several AMD-only instructions
- 3DNow! instructions have a trailing immediate byte which indicates the
  opcode. Decoding this with the existing table structure requires more
  effort (in particular, a new lookup table after decoding ModRM would
  be required). Given that AMD even removed 3DNow! over 10 years ago, it
  appears unlikely that this will ever be fully supported. Adding the
  RMI-encoded pseudo-instruction "3DNOW" just to support that opcode.
- FEMMS is a legacy 3DNow! instruction.
- EXTRQ/INSERTQ are instructions with an "unusual" encoding and
  operation mode. This is another instance of 16-bit immediates.
- SVM (AMD's variant of VMX) and SNP instructions are AMD-only.
2021-01-10 15:18:44 +01:00
Alexis Engelke
dd4263b169 instrs: Support far jumps/calls encoded target 2021-01-10 12:31:07 +01:00
Alexis Engelke
af9188e267 parseinstrs: Respect mem-only/reg-only encodings 2021-01-10 12:02:58 +01:00
Alexis Engelke
d2bf961b77 instrs: Properly handle PUSH/POP of SEG registers 2021-01-03 20:08:34 +01:00
Alexis Engelke
90cce987f0 decode: Remove use of ARCH_* macros 2021-01-02 16:25:25 +01:00
Alexis Engelke
305eb9d568 decode: Inline ModRM decoding
This is a preparation for further changes to that routine.
2020-11-29 13:34:16 +01:00
Alexis Engelke
aa1a39bd9d instrs: Check SREG validity using modreg table 2020-11-29 11:56:08 +01:00
Alexis Engelke
13e7e27640 decode: Minor non-functional changes 2020-11-29 10:03:11 +01:00
Alexis Engelke
8976c7141a decode: Fix erroneous decoding of high-byte regs 2020-11-28 13:54:19 +01:00
Alexis Engelke
757acf18c3 decode: Minor performance improvements 2020-11-27 09:07:52 +01:00
Alexis Engelke
fd80706f54 decode: Store instruction descriptors separately 2020-11-22 22:27:43 +01:00