使用qmake成功编译SSE指令(但不能识别SSE2) [英] Successful compilation of SSE instruction with qmake (but SSE2 is not recognized)

查看:1570
本文介绍了使用qmake成功编译SSE指令(但不能识别SSE2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译和运行我的代码从Unix迁移到Windows。我的代码是纯C ++,而不是使用Qt类。



我也使用Qt creator作为IDE和 qmake.exe code> -spec win32-g ++ 用于编译。因为我在代码中有 sse 指令,我必须包括 emmintrin.h 头。



我添加了:



QMAKE_FLAGS_RELEASE + = -O3 -msse4.1 -mssse3 -msse3 -msse2 -msse



QMAKE_CXXFLAGS_RELEASE + = -O3 -msse4.1 -mssse3 -msse3 -msse2 - msse



.pro 文件中。 我已经能够无错编译代码。但是在运行之后,在通过一些包含 __ m128 的函数时会产生运行时错误。



打开 emmintrin.h ,我看到了:

  #ifndef __SSE2__ 
#错误SSE2指令集未启用
#else

#else



我不知道如何启用 SSE

系统类型:64位


$ b

处理器:intel(R)Core(TM)i5-2430M CPU @ 2.40Hz





提前感谢。

解决方案

不是16字节对齐,这是SSE加载的要求,例如 mm_load_ps 。您可以:




  • 使用 _mm_loadu_ps 作为临时解决方法。在较新的CPU上,对于未对齐的负载,这种性能损失是相当小的(在较旧的CPU上它是更重要的),但如果可能,仍然应该避免






  • 修复记忆体对齐方式。在Windows / Visual Studio中,您可以使用静态分配的 declspec(align(16))属性或动态分配的 _aligned_malloc 分配。对于gcc和大多数其他文明平台/编译器对于前者和使用 __ attribute__((align(16)))> posix_memalign


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.

解决方案

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 and posix_memalign for the latter.

这篇关于使用qmake成功编译SSE指令(但不能识别SSE2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆