问题
I'm trying to compile and run my code migrated from Unix to windows. My code is pure C++ and not using Qt classes. it is fine in Unix.
I'm also using Qt creator as an IDE and qmake.exe
with -spec win32-g++
for compiling. As I have sse
instructions within my code, I have to include emmintrin.h
header.
I added:
QMAKE_FLAGS_RELEASE += -O3 -msse4.1 -mssse3 -msse3 -msse2 -msse
QMAKE_CXXFLAGS_RELEASE += -O3 -msse4.1 -mssse3 -msse3 -msse2 -msse
In the .pro
file. I have been able to compile my code without errors. but after running it gives run-time error while going through some functions containing __m128
or like that.
When I open emmintrin.h
, I see:
#ifndef __SSE2__
# error "SSE2 instruction set not enabled"
#else
and It is undefined after #else
.
I don't know how to enable SSE
in my computer.
Platform: Windows Vista
System type: 64-bit
Processor: intel(R) Core(TM) i5-2430M CPU @ 2.40Hz
Does anyone know the solution?
Thanks in advance.
回答1:
It sounds like your data is not 16 byte aligned, which is a requirement for SSE loads such as mm_load_ps
. You can either:
- use
_mm_loadu_ps
as a temporary workaround. On newer CPUs the performance hit for misaligned loads such as this is fairly small (on older CPUs it's much more significant), but it should still be avoided if possible
or
- fix your memory alignment. On Windows/Visual Studio you can use the
declspec(align(16))
attribute for static allocations or_aligned_malloc
for dynamic allocations. For gcc and most other civilised platforms/compilers use__attribute__ ((align(16)))
for the former andposix_memalign
for the latter.
来源:https://stackoverflow.com/questions/18653452/successful-compilation-of-sse-instruction-with-qmake-but-sse2-is-not-recognized