3 ms·
Yeah, it's a little opaque. I'll try to rephrase. You have some code, with an if and else. if (cond) X else Y. After that comes code Z. When you compile this, t
by tedunangst 10y ago
Yeah, it's a little opaque. I'll try to rephrase. You have some code, with an if and else. if (cond) X else Y. After that comes code Z. When you compile this, the compiler emits instructions to check the condition, and if it's zero, jump to the else. Otherwise it proceeds to run X. At the end of X, you need to add another jump over Y to Z. Otherwise you'd execute Y too.
Having lots of little jumps in your code can slow things down (well, maybe, depending on CPU, etc., but stipulate that jumps are bad). So at the end of X, you have to have a jump over the length of Y. However, if Y is very short, like 1 or 4 bytes, you don't actually need to use a jump instruction. Instead, pretend the Y instruction is a constant, and load it into a register (and ignore it). The result is the CPU runs X, loads some ignored data into a register, then runs Z. No jumps.