Re: [PATCH RFC v1 12/20] KVM: x86: Support REX2-extended register index in the decoder

Chang S. Bae
2025-11-13T23:26:13Z

On 11/11/2025 8:53 AM, Paolo Bonzini wrote:
>
> Replying here for both patches 10 and 12, because I think you can merge
> them in one,

Done

> I'd prefer to avoid bitfields.
>
> You only need a single enum:
>
> enum {
>     REX_B = 1,
>     REX_X = 2,
>     REX_R = 4,
>     REX_W = 8,
>     REX_M = 0x80,
> };
>
> for REX_W/REX_M you access them directly, while for RXB you go through a
> function:
>
> static inline rex_get_rxb(u8 rex, u8 fld)
> {
>     BUILD_BUG_ON(!__builtin_constant_p(fld));
>     BUILD_BUG_ON(fld != REX_B && fld != REX_X && fld != REX_R);
>
>     rex >>= ffs(fld) - 1;    // bits 0+4
>     return (rex & 1) + (rex & 0x10 ? 8 : 0);
> }
>
>>       } else {
>>           reg = (ctxt->b & 7) |
>> -              (ctxt->rex.bits.b3 * BIT(3));
>> +              (ctxt->rex.bits.b3 * BIT(3)) |
>> +              (ctxt->rex.bits.b4 * BIT(4));
>
> +              rex_get_rxb(ctxt->rex, REX_B);
>
> and likewise everywhere else.

Neat! This looks much better. Thanks for the suggestion.