我正在尝试制作一个使用 GCC 编译并使用 Qt 和 SSE 内在函数的程序。似乎当我的一个函数被 Qt 调用时,堆栈对齐不会被保留。这是一个简短的例子来说明我的意思:
#include <cstdio>
#include <emmintrin.h>
#include <QtGui/QApplication.h>
#include <QtGui/QWidget.h>
class Widget: public QWidget {
public:
void paintEvent(QPaintEvent *) {
__m128 a;
printf("a: 0x%08x\n", ((void *) &a));
}
};
int main(int argc, char** argv)
{
QApplication application(argc, argv);
Widget w;
w.paintEvent(NULL); // Called from here, my function behaves correctly
w.show();
w.update();
// Qt will call Widget::paintEvent and my __m128 will not be
// aligned on 16 bytes as it should
application.processEvents();
return 0;
}
这是输出:
a: 0x0023ff40 // OK, that's aligned on 16 bytes
a: 0x0023d14c // Not aligned!
配置:
- 英特尔酷睿2
- 操作系统,SP3
- GCC 4.4(Mingw 包含在 Qt SDK 2010.01 中)
我尝试使用与我在 Qt makefile 中看到的相同的选项来编译示例程序:
-O2 -Wall -frtti -fexceptions -mthreads
,链接选项:
-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -mthreads
现在我不知道在哪个方向搜索。任何提示将不胜感激。谢谢!
法比安