How to use SSE(2,3) in C++/QT programs
I am working on a project with a lot of vector math and I'd like to find a way to speed it up. I've been reading about SSE, but I've found no explanation on how to actually use it in code (was looking for some kind of hello-world example, complete with compilation instructions).
Does the gcc compiler automatically make use of SSE, if you add the -sse(2,3) option on the command line? Or are their specific functions/libraries you need to call?
Re: How to use SSE(2,3) in C++/QT programs
GCC has inbuilt support, refer the like GCC documentation, example of how to use it also described
http://gcc.gnu.org/onlinedocs/gcc-4....tor-Extensions
example you can try compiling
Code:
#include "stdio.h"
typedef float v4 __attribute__ ((vector_size(sizeof(float)*4)));
union f4v
{
v4 v;
float f[4];
} ;
void print_f4v(union f4v* v)
{
printf("%f,%f,%f,%f\n", v->f[0], v->f[1], v->f[2], v->f[3]);
}
int main()
{
union f4v a, b, c;
a.v = (v4){1.1, 2.2, 3.3, 4.4};
b.v = (v4){5.5., 6.6, 7.7, 8.8};
c.v = a.v + b.v;
print_f4v(&a);
print_f4v(&b);
print_f4v(&c);
}