Re: [PATCH v3 01/20] KVM: VMX: Macrofy 64-bit GPR swapping in __vmx_vcpu_run()

Paolo Bonzini
2026-04-29T07:50:53Z

On Tue, Apr 28, 2026 at 10:12 PM Chang S. Bae <chang.seok.bae@intel.com> wrote:
> On 4/28/2026 2:03 AM, Paolo Bonzini wrote:
> > I would also consider using inst.h's name-to-index conversion:
> >
> > .macro LOAD_GPRS src:req, regs_ofs:req, regs:vararg
> > .irp reg, \regs
> > #ifdef CONFIG_X86_64
> > R64_NUM reg_num \reg
> > #else
> > R32_NUM reg_num \reg
> > #endif
> > .if \reg_num <> REG_NUM_INVALID
> > mov (\regs_ofs + \reg_num * WORD_SIZE)(%_ASM_DI), \reg
> > .else
> > .err invalid register \reg
> > .endif
> > .endr
> > .endm
> Yup! Also, looks like still needs the REG_TYPE macro:

I don't think so, you can (and should) assume that \reg has WORD_SIZE
size (i.e. disallow %eax if CONFIG_X86_64 is set). Only CLEAR_REGS
uses smaller registers but it does not need the reg_num.

Paolo

> .macro LOAD_REGS src:req, regs_ofs:req, regs:vararg
> .irp reg, \regs
> REG_TYPE reg_type \reg
> .if reg_type == REG_TYPE_R64
> R64_NUM reg_num \reg
> .else
> R32_NUM reg_num \reg
> .endif
> .if reg_num <> REG_NUM_INVALID
> mov (\regs_ofs + reg_num * WORD_SIZE)(\src), \reg
> .else
> .err invalid register \reg
> .endif
> .endr
> .endm
>
> Thanks,
> Chang
>