title: __builtin_prefetch, How much does it read?
body: <p>I'm trying to optimize some C++ (<a href="https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods" rel="noreferrer">RK4</a>) by using </p>
  
  <pre><code>__builtin_prefetch
  </code></pre>
  
  <p>I can't figure out how to prefetch a whole structure.</p>
  
  <p>I don't understand how much of the <code>const void *addr</code> is read. I want to have the next values of <code>from</code> and <code>to</code> loaded.</p>
  
  <pre><code>for (int i = from; i &lt; to; i++)
  {
      double kv = myLinks[i].kv;
      particle* from = con[i].Pfrom;
      particle* to = con[i].Pto;
      //Prefetch values at con[i++].Pfrom &amp; con[i].Pto;
      double pos = to-&gt;px- from-&gt;px;
      double delta = from-&gt;r + to-&gt;r - pos;
      double k1 = axcel(kv, delta, from-&gt;mass) * dt; //axcel is an inlined function
      double k2 = axcel(kv, delta + 0.5 * k1, from-&gt;mass) * dt;
      double k3 = axcel(kv, delta + 0.5 * k2, from-&gt;mass) * dt;
      double k4 = axcel(kv, delta + k3, from-&gt;mass) * dt;
      #define likely(x)       __builtin_expect((x),1)
      if (likely(!from-&gt;bc))
      {
              from-&gt;x += (( k1 + 2 * k2 + 2 * k3 + k4) / 6);
      }
  }
  </code></pre>
  
  <p>Link: <a href="http://www.ibm.com/developerworks/linux/library/l-gcc-hacks/" rel="noreferrer">http://www.ibm.com/developerworks/linux/library/l-gcc-hacks/</a></p>