title: Can branch prediction crash my program?
body: <p>Going trough chapter 3 of this book called <a href="https://rads.stackoverflow.com/amzn/click/com/0136108040" rel="noreferrer" rel="nofollow noreferrer">Computer Systems Architecture: A programmer's perspective</a>, it is stated that an implementation like</p>
  
  <pre><code>testl %eax, %eax
  cmovne (%eax), %edx
  </code></pre>
  
  <p>is invalid because if the prediction fails, then we'll have NULL dereferencing. It is also stated that we should use branching code.</p>
  
  <p>Still, wouldn't using conditional jumps lead to the same result? For example:</p>
  
  <pre><code>.L1:
  jmp *%eax
  
  testl %eax, %eax
  jne .L1
  </code></pre>
  
  <p>Is it possible to trick gcc to output something like that for an x86-32? Suppose I have an array of pointers to functions of which some are valid and some aren't and I call each one that's not NULL.</p>