PDA

View Full Version : MMX Programming



vhptt
19th November 2013, 02:54
I've try this code:

#include <QtCore/QCoreApplication>
#include <xmmintrin.h>
#include <emmintrin.h>


int main(int argc, char *argv[])
{
QCoreApplication x(argc, argv);

quint32 a[256];
quint32 b[256];
quint32 c[256];

for (int i = 0; i < 256; i += 4)
{
__m128i vectorA = _mm_loadu_si128((__m128i*)&a[i]);
__m128i vectorB = _mm_loadu_si128((__m128i*)&b[i]);
__m128i vectorC = _mm_add_epi32(vectorA, vectorB);
_mm_storeu_si128((__m128i*)&c[i], vectorC);
}


return x.exec();
}

And got this:
/usr/lib/gcc/i586-suse-linux/4.6/include/xmmintrin.h:32: error: #error "SSE instruction set not enabled"
/usr/lib/gcc/i586-suse-linux/4.6/include/emmintrin.h:32: error: #error "SSE2 instruction set not enabled"
error: ‘__m128i’ was not declared in this scope.

How can I fix it ?

ChrisW67
19th November 2013, 03:36
Enable SSE and SSE2 by whatever method the headers require, probably by doing whatever causes defining of __SSE__ and __SSE2__. At a guess you want the "-msse -msse2" options passed to your GCC compiler.

This has nothing to do with Qt directly although you can get qmake to put the options in a Makefile for you:


QMAKE_CXXFLAGS += -msse -msse2

vhptt
19th November 2013, 04:58
Thanks for your supporting, I've added the option in .pro and build OK.
But, QtCreator did not hightlight _m128i type and I cannot press F2 to navigate to declaration :(

ChrisW67
19th November 2013, 05:10
Certainly does here.