且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MinGW64无法使用32字节堆栈对齐方式(在Windows x64上需要AVX),易于使用或交换编译器?

更新时间:2023-11-14 09:33:40

您可以通过切换到Microsoft的64位C / C ++编译器来解决此问题。这个问题不是固有的64位Windows。尽管Kai Tietz在你关联的bug报告中说过,微软的x64 ABI确实允许一个编译器为堆栈上的变量提供大于16字节的对齐。

另外Cygwin's GCC 4.9.2的64位版本可以为堆栈上的变量提供32字节对齐方式。

I'm trying to work with AVX instructions and windows 64bit. I'm comfortable with g++ compiler so I've been using that, however, there is a big bug described reported here and very rough solutions were presented here.

Basically, m256 variable can't be aligned on the stack to work properly with avx instructions, it needs 32 byte alignment.

The solutions presented at the other stack question I linked are really terrible, especially if you have performance in mind. A python program that you would have to run every time you want to debug that replaces instructions with their sub-optimal unaligned instructions, or over-allocating and doing a bunch of costly hacky pointer math in code to get proper alignment. If you do the pointer math solution, I think there is still even a chance for a seg fault because you can't control the allocation or r-values / temporaries.

I'm looking for an easier and cheaper solution. I don't mind switching compilers, would prefer not to, but if it's the best solution I will. However, my very poor understanding of the bug is that it is intrinsic to windows 64 bit, so would switching compilers help or do other compilers also have the same issue?

You can solve this problem by switching to Microsoft's 64-bit C/C++ compiler. The problem is not intrinsic to 64-bit Windows. Despite what Kai Tietz said in the bug report you linked, Microsoft's x64 ABI does allow a compiler to give variables a greater than 16-byte alignment on the stack.

Also Cygwin's 64-bit version of GCC 4.9.2 can give variables 32-byte alignment on the stack.