Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a lot of answers mentioning SSE already… but since nobody has mentioned how to use it, I'll throw another in…</p> <p>Your code has most everything a vectorizer needs to work, except two constraints: aliasing and alignment.</p> <ul> <li><p>Aliasing is the problem of two names referring two the same object. For example, <code>my_point.dist2( my_point )</code> would operate on two copies of <code>my_point</code>. This messes with the vectorizer.</p> <p>C99 defines the keyword <code>restrict</code> for pointers to specify that the referenced object is referenced uniquely: there will be no other <code>restrict</code> pointer to that object in the current scope. Most decent C++ compilers implement C99 as well, and import this feature somehow.</p> <ul> <li>GCC calls it <code>__restrict__</code>. It may be applied to references or <code>this</code>.</li> <li>MSVC calls it <code>__restrict</code>. I'd be surprised if support were any different from GCC.</li> </ul> <p>(It is not in C++0x, though.)</p> <pre><code>#ifdef __GCC__ #define restrict __restrict__ #elif defined _MSC_VER #define restrict __restrict #endif   Base dist2(const Point&amp; restrict p) const restrict </code></pre></li> <li><p>Most SIMD units require alignment to the size of the vector. C++ and C99 leave alignment implementation-defined, but C++0x wins this race by introducing <code>[[align(16)]]</code>. As that's still a bit in the future, you probably want your compiler's semi-portable support, a la <code>restrict</code>:</p> <pre><code>#ifdef __GCC__ #define align16 __attribute__((aligned (16))) #elif defined _MSC_VER #define align16 __declspec(align (16)) #endif   struct Point { double align16 xyz[ 3 ]; // separate x,y,z might work; dunno … }; </code></pre></li> </ul> <p>This isn't guaranteed to produce results; both GCC and MSVC implement helpful feedback to tell you what wasn't vectorized and why. Google your vectorizer to learn more.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload