Wikipedia Affiliate Button

середу, 21 жовтня 2009 р.

SSE vector operations in GCC

Thanks to GCC vector types one can do SSE vector operations without having to write any assembly. The below code snippet:
#include <stdio.h>

typedef int v4si __attribute__ ((mode(V4SI)));

int main(int argc, char** argv) {


     v4si a[10], b[10], c[10];

        for(int i = 0; i < 10; i++) {
     c[i] = a[i] + b[i];
}

}

translates into the following assembly:
 movdqa  (%eax), %xmm1
 ...   
 movdqa  (%eax), %xmm0
 paddd   %xmm1, %xmm0

Немає коментарів: