Re: [PATCH] KVM: x86: small optimization for is_mtrr_mask calculation

From: linmiaohe
Date: Thu Mar 05 2020 - 21:05:54 EST


Hi,
Paolo Bonzini <pbonzini@xxxxxxxxxx> wrote:
>On 05/03/20 03:48, linmiaohe wrote:
>> From: Miaohe Lin <linmiaohe@xxxxxxxxxx>
>>
>> We can get is_mtrr_mask by calculating (msr - 0x200) % 2 directly.
>> index = (msr - 0x200) / 2;
>> - is_mtrr_mask = msr - 0x200 - 2 * index;
>> + is_mtrr_mask = (msr - 0x200) % 2;
>> if (!is_mtrr_mask)
>> *pdata = vcpu->arch.mtrr_state.var_ranges[index].base;
>> else
>>
>
>If you're going to do that, might as well use ">> 1" for index instead of "/ 2", and "msr & 1" for is_mtrr_mask.
>

Many thanks for suggestion. What do you mean is like this ?

index = (msr - 0x200) >> 1;
is_mtrr_mask = msr & 1;

Thanks again.