• Avi Kivity's avatar
    KVM: x86 emulator: framework for streamlining arithmetic opcodes · e28bbd44
    Avi Kivity authored
    We emulate arithmetic opcodes by executing a "similar" (same operation,
    different operands) on the cpu.  This ensures accurate emulation, esp. wrt.
    eflags.  However, the prologue and epilogue around the opcode is fairly long,
    consisting of a switch (for the operand size) and code to load and save the
    operands.  This is repeated for every opcode.
    This patch introduces an alternative way to emulate arithmetic opcodes.
    Instead of the above, we have four (three on i386) functions consisting
    of just the opcode and a ret; one for each operand size.  For example:
       .align 8
    	not %al
       .align 8
    	not %ax
       .align 8
    	not %eax
       .align 8
    	not %rax
    The prologue and epilogue are shared across all opcodes.  Note the functions
    use a special calling convention; notably eflags is an input/output parameter
    and is not clobbered.  Rather than dispatching the four functions through a
    jump table, the functions are declared as a constant size (8) so their address
    can be calculated.
    Acked-by: default avatarGleb Natapov <gleb@redhat.com>
    Signed-off-by: default avatarAvi Kivity <avi.kivity@gmail.com>
    Signed-off-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>