Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio parameter alignment restrictions and Windows x64 ABI

With Visual C++ on WIN32 there's a long-standing problem with functions with 4 or more SSE parameters, e.g.

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

generates an error:

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

To compound the problem, Visual C++ still needlessly imposes the ABI restriction even if the function is __inline.

I'm wondering if this is still a problem on 64 bit Windows ? Does the ABI restriction still apply on x64 ?

(I don't have access to a 64 bit Windows system otherwise I'd try it myself, and an extensive Google search hasn't turned up anything definitive.)

like image 696
Paul R Avatar asked Apr 28 '13 16:04

Paul R


1 Answers

You can pass as many 128 bit SSE intrinsic parameters as you like under x64. The x64 ABI was designed with these types in mind.

From the 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.

like image 142
David Heffernan Avatar answered Nov 18 '22 07:11

David Heffernan