I have two classes which do the same thing, but one uses SSE4.2 and the other not. I am already detecting if the code runs on a CPU supporting SSE4.2 and using the correspondending class, but I am struggling compiling the SSE4.2 class.
I want the compiler using SSE4.2 optimation only for this class and not for the rest of the code, so I can't use -msse4.2
.
I read of #pragma GCC target("sse4.2")
, but I still get an compile error in the included SSE4.2-Header:
nmmintrin.h:31:3: error: #error "SSE4.2 instruction set not enabled"
How can I compile this class with SSE4.2 optimation enabled and the rest of my code disabled?
I am using GCC 4.8 & Android NDK 10d.
My class looks like this:
#include "MyClassWithSSE42.h"
#pragma GCC target("sse4.2")
#include <nmmintrin.h>
uint32_t MyClassWithSSE42::CRC32byte(const uint32_t *p, const uint32_t startValue)
{
uint32_t c = _mm_crc32_u32(startValue, p[0]);
c = _mm_crc32_u32(c, p[1]);
c = _mm_crc32_u32(c, p[2]);
c = _mm_crc32_u32(c, p[3]);
c = _mm_crc32_u32(c, p[4]);
c = _mm_crc32_u32(c, p[5]);
c = _mm_crc32_u32(c, p[6]);
return _mm_crc32_u32(c, p[7]);
}