Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If someone is interested this is the dirty code I come with to test a new idea that I came with while reading about the library that Paul posted.</p> <p>Thanks Paul!</p> <pre><code>// This is just a conceptual test // I haven't profile the code and I haven't verified if the result is correct #include &lt;xmmintrin.h&gt; // This class is doing all the math template &lt;bool SIMD&gt; class cStreamF32 { private: void* m_data; void* m_dataEnd; __m128* m_current128; float* m_current32; public: cStreamF32(int size) { if (SIMD) m_data = _mm_malloc(sizeof(float) * size, 16); else m_data = new float[size]; } ~cStreamF32() { if (SIMD) _mm_free(m_data); else delete[] (float*)m_data; } inline void Begin() { if (SIMD) m_current128 = (__m128*)m_data; else m_current32 = (float*)m_data; } inline bool Next() { if (SIMD) { m_current128++; return m_current128 &lt; m_dataEnd; } else { m_current32++; return m_current32 &lt; m_dataEnd; } } inline void operator=(const __m128 x) { *m_current128 = x; } inline void operator=(const float x) { *m_current32 = x; } inline __m128 operator+(const cStreamF32&lt;true&gt;&amp; x) { return _mm_add_ss(*m_current128, *x.m_current128); } inline float operator+(const cStreamF32&lt;false&gt;&amp; x) { return *m_current32 + *x.m_current32; } inline __m128 operator+(const __m128 x) { return _mm_add_ss(*m_current128, x); } inline float operator+(const float x) { return *m_current32 + x; } inline __m128 operator*(const cStreamF32&lt;true&gt;&amp; x) { return _mm_mul_ss(*m_current128, *x.m_current128); } inline float operator*(const cStreamF32&lt;false&gt;&amp; x) { return *m_current32 * *x.m_current32; } inline __m128 operator*(const __m128 x) { return _mm_mul_ss(*m_current128, x); } inline float operator*(const float x) { return *m_current32 * x; } }; // Executes both functors template&lt;class T1, class T2&gt; void Execute(T1&amp; functor1, T2&amp; functor2) { functor1.Begin(); do { functor1.Exec(); } while (functor1.Next()); functor2.Begin(); do { functor2.Exec(); } while (functor2.Next()); } // This is the implementation of the problem template &lt;bool SIMD&gt; class cTestFunctor { private: cStreamF32&lt;SIMD&gt; a; cStreamF32&lt;SIMD&gt; b; cStreamF32&lt;SIMD&gt; c; public: cTestFunctor() : a(1024), b(1024), c(1024) { } inline void Exec() { c = a + b * a; } inline void Begin() { a.Begin(); b.Begin(); c.Begin(); } inline bool Next() { a.Next(); b.Next(); return c.Next(); } }; int main (int argc, char * const argv[]) { cTestFunctor&lt;true&gt; functor1; cTestFunctor&lt;false&gt; functor2; Execute(functor1, functor2); return 0; } </code></pre>
    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