2013-04-28 70 views
9

使用WIN32上的Visual C++,有4個或更多SSE參數的函數存在長期存在的問題,例如,Visual Studio參數對齊限制和Windows x64 ABI

__m128i foo4(__m128i m0, __m128i m1, __m128i m2, __m128i m3) {} 

生成錯誤:

align.c(8) : error C2719: 'm3': formal parameter with __declspec(align('16')) won't be aligned 

使問題更加複雜時,Visual C++仍然不必要強加限制ABI即使功能是__inline

我想知道這是否仍然是64位Windows上的問題? ABI限制是否仍然適用於x64?

(我沒有訪問64位Windows系統,否則我想嘗試它自己,以及廣泛的谷歌搜索還沒有止跌回升什麼明確的。)

+1

根據[昂納霧的 「調用約定」 手冊(第7.2節)](http://www.agner.org/optimize/),Windows64傳遞所有__m128參數由指針,所以4個或更多的__m128參數應該不成問題。 (無法檢查,因爲我也無法訪問Windows系統)。 – 2013-04-28 17:39:08

回答

7

您可以通過儘可能多的128位在x64下你喜歡SSE內在參數。 x64 ABI的設計考慮了這些類型。

MSDN documentation

__m128 types, arrays and strings are never passed by immediate value but rather a pointer is passed to memory allocated by the caller. Structs/unions of size 8, 16, 32, or 64 bits and __m64 are passed as if they were integers of the same size. Structs/unions other than these sizes are passed as a pointer to memory allocated by the caller. For these aggregate types passed as a pointer (including __m128), the caller-allocated temporary memory will be 16-byte aligned.

+0

謝謝 - 這聽起來像是時候開始只針對Windows x64了 - 您是否碰巧知道構建和運行x64可執行文件所需的Windows和Visual Studio的最低版本? – 2013-04-28 18:15:10

+1

VS2008我想。有XP64,但幾乎沒有使用。 Vista 64可能是明智的最低水平。 – 2013-04-28 18:23:30

+0

謝謝 - 這是一個很大的幫助。 – 2013-04-28 19:40:05

相關問題