The old code uses bitshifts and bitwise-and all over the place for decoding ModR/M fields. Avoid doing that by introducing proper decoding operands.
Signed-off-by: Jan Bobek <jan.bo...@gmail.com> --- target/i386/translate.c | 62 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/target/i386/translate.c b/target/i386/translate.c index a0a9f64ff3..b3b316d389 100644 --- a/target/i386/translate.c +++ b/target/i386/translate.c @@ -4791,6 +4791,68 @@ INSNOP_FINALIZE(modrm) { } +/* + * modrm_mod + * + * Operand whose value is the MOD field of the ModR/M byte. + */ +typedef int insnop_arg_t(modrm_mod); +typedef struct {} insnop_ctxt_t(modrm_mod); + +INSNOP_INIT(modrm_mod) +{ + return true; +} +INSNOP_PREPARE(modrm_mod) +{ + return (modrm >> 6) & 3; +} +INSNOP_FINALIZE(modrm_mod) +{ +} + +/* + * modrm_reg + * + * Operand whose value is the REG field of the ModR/M byte, extended + * with the REX.R bit if REX prefix is present. + */ +typedef int insnop_arg_t(modrm_reg); +typedef struct {} insnop_ctxt_t(modrm_reg); + +INSNOP_INIT(modrm_reg) +{ + return true; +} +INSNOP_PREPARE(modrm_reg) +{ + return ((modrm >> 3) & 7) | REX_R(s); +} +INSNOP_FINALIZE(modrm_reg) +{ +} + +/* + * modrm_rm + * + * Operand whose value is the RM field of the ModR/M byte, extended + * with the REX.B bit if REX prefix is present. + */ +typedef int insnop_arg_t(modrm_rm); +typedef struct {} insnop_ctxt_t(modrm_rm); + +INSNOP_INIT(modrm_rm) +{ + return true; +} +INSNOP_PREPARE(modrm_rm) +{ + return (modrm & 7) | REX_B(s); +} +INSNOP_FINALIZE(modrm_rm) +{ +} + static void gen_sse_ng(CPUX86State *env, DisasContext *s, int b) { enum { -- 2.20.1