[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Computed goto optimization of vanilla Lua
- From: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 4 Feb 2016 09:45:51 -0200
> computed gotos are a feature of modern compilers . They can be used
> as a faster replacement for switch-based VM . Many programming
> languages have VMs implemented in computed gotos (at least, Ruby and
> The computed goto version is faster because of two reasons :
> * The switch does a bit more per iteration because of bounds checking.
> * The effects of hardware branch prediction.
> I have applied this optimization to VM of Lua 5.3.2, file src/lvm.c
> . It was very easy, because VM uses macros vmdispatch, vmcase and
> vmbreak. I have redefined these macros and created a dispatch table.
Thanks for the results.
These macros are there exactly for this reason. However, my ealier
tests (a few years ago, when we introduced the macros) did not show
any perceptible improvement. In particular, the GCC compiler insisted
in applying a space optimization that merged the common code at the
end of different branches in a conditional (most of 'vmbreak', in our
case), therefore throwing away any possibility of optimized branch
predictions. (All opcodes ended up using the same indirect jump in the
final code.) I will try it again.