SIMD, bestimmen wieviel Cycles eine Funktion braucht



  • Hi!

    Ich habe dieses SIMD-SSE Tutorial (http://www.cfxweb.net/modules.php?name=News&file=article&sid=1316) gelesen.
    Bei jeder Funktion wird dabei die Anzahl der Cycles angegeben.
    Ich frage mich nur wie sich das feststellen läßt. Gibts da
    ne Formel? Wie wirken sich dann Optimierungen wie Pairing oder so
    aus?

    Als spezielles Bsp. hab ich an den Code unten gedacht
    (Compiliert nur mit dem GCC)

    #define loadaps			__builtin_ia32_loadaps
    #define loadss			__builtin_ia32_loadss
    #define storeaps		__builtin_ia32_storeaps
    #define storess			__builtin_ia32_storess
    
    #define shufps			__builtin_ia32_shufps
    
    #define addps			__builtin_ia32_addps
    #define subps			__builtin_ia32_subps
    #define mulps			__builtin_ia32_mulps
    #define divps				__builtin_ia32_divps
    
    #define sqrtss			__builtin_ia32_sqrtss
    #define rsqrtss			__builtin_ia32_rsqrtss
    #define addss			__builtin_ia32_addss
    
    typedef int __attribute__ ((mode(V4SF))) sse_register;
    static sse_register _sa, _sb, _sc;
    
    void length_vector_sse(float* in, float* out)
    {
    	_sa  = loadaps(in);
    	_sa = mulps(_sa, _sa);
    	_sb = shufps(_sa, _sa, 0x55);
    	_sc = shufps(_sa, _sa, 0xAA);
    	_sa = addps(_sa, _sb);
    	_sa = addps(_sa, _sc);
    	_sa = sqrtss(_sa);
    	storess(out, _sa);
    }
    

    Edit: SIMG -> SIMD



  • Steht alles in Intels Doku (gibt's gratis).

    Ist allerdings eher mühsam - und natürlich sind diese Angaben unabhängig von Caching-Effekten. Empfehlenswert ist eher, es einfach zu messen, das ist schon wesentlich nützlicher.



  • mit rdtsc kannst du die Cycles messen

    #include <stdint.h>
    
    inline uint64_t rdtsc()
    {
      uint32_t high, low;
      __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high));
      return ((uint64_t)high << 32) | low;
    }
    
    int main() {
      uint64_t a=rdtsc();
      funktion();
      uint64_t cycles=rdtsc()-a;
      printf("funktion() brauchte %d cycles\n",cycles);
      return 0;
    }
    


  • Genau sowas habe ich gesucht 👍

    thx


Anmelden zum Antworten