Re:One Byte to rule them all
by tlb on Saturday August 01, 2020 @02:22PM
(#24022702)
Indeed, a small integer tag seems much more vulnerable than a C++ virtual table pointer.
On modern hardware, how much is the penalty for using magic numbers instead of small indices? (A magic number meaning a constant like 0x85adb9ad instead of 2). The compiler can't optimize switch(it->type) using a jump table, but I suspect that branch prediction and speculation makes this optimization barely relevant.
Re:One Byte to rule them all
by kevincox on Saturday August 01, 2020 @03:59PM
(#24023409)
A jump table isn't likely used for very small unions anyways. The biggest downside that I see is that comparing with zero is slightly cheaper if that is a common value.
On modern hardware, how much is the penalty for using magic numbers instead of small indices? (A magic number meaning a constant like 0x85adb9ad instead of 2). The compiler can't optimize switch(it->type) using a jump table, but I suspect that branch prediction and speculation makes this optimization barely relevant.