3 ms·
Great interview, more please. Is there a way to submit question? I'd like to know 1) what affects branch predictors? From my understanding return statements do
by levodelellis 2y ago
Great interview, more please.
Is there a way to submit question? I'd like to know 1) what affects branch predictors? From my understanding return statements do and cmov does not 2) Why isn't there a conditional exception? to replace if (!cond) { __builtin_trap(); }
- wtallis 2y agoConditional instructions that don't branch or otherwise interrupt the program flow don't necessarily have to cause any pipeline stalls or bubbles. The CPU can decode a cmov and then carry on decoding subsequent instructions (and pass the cmov on to subsequent pipeline stages) well before it's known whether the condition is true. For a branching instruction, the CPU doesn't know during the early phases what the next instruction after the branch will be, so it has to predict and speculate. > Why isn't there a conditional exception? to replace if (!cond) { __builtin_trap(); } There's not really any way to make that into something that doesn't branch; the best you can hope for is only one instruction that may branch but hopefully gets predicted accurately. But in the event of an exception, there really does need to be something that can cause the instruction pointer to do something other than advance to the next byte after the current instruction.