__declspec(align(X)) struct SomeStruct
{
float a,b,c,d;
};
void AlignmentCheck()
{
struct SomeStruct abc;
assert( ( 0 == (((size_t)(&abc))&15) ) ); // this always fails
}
__declspec(align(X)) struct SomeStruct
{
float a,b,c,d;
};
void AlignmentCheck()
{
struct SomeStruct abc;
assert( ( 0 == (((size_t)(&abc))&15) ) ); // this always fails
}
[source lang='C']typedef __declspec(align(16)) struct SomeStruct SomeStruct;
[source lang='C']typedef __declspec(align(16)) struct SomeStruct SomeStruct_A;
Quote:
A few things -
This is compiler specific. There is nothing in the language about forcing an alignment. The libraries are required to place things in a proper alignment for the type, but it is an implementation detail.
Your cast is a bug: (((size_t)(&abc))&15)
The result of the & operator is a pointer of the same type as abc. A size_t object is not the same as a pointer.
For the stack, Microsoft's compiler defaults to 4-byte alignment on the x86 platform, unless you tell it otherwise.
If you are going to be using variables for SSE, you should be using the intrinsic types. For example the types __m128i __m128d, __m64 are all properly aligned for use in MMX/SSE/SSE2 instructions.
Quote:Original post by obhiAt first I was surprised that this even compiles, but I can see why.
typedef __declspec(align(16)) struct SomeStruct SomeStruct;
Quote:Original post by obhi
failed
typedef __declspec(align(16)) struct SomeStruct SomeStruct;
succeeded
typedef __declspec(align(16)) struct SomeStruct SomeStruct_A;
And this works i.e. when I declare a variable for SomeStruct_A it is declared aligned. What is wrong with my first declaration (typedef)?
Quote:Original post by obhiSSE was introduced in the Pentium III, nearly 11 years ago.
And I cant really use __m128 because my whole point in using these structures to allow a fallback mechanism in case SSE is not supported by an architecture.
Quote:Original post by frobQuote:Original post by obhiSSE was introduced in the Pentium III, nearly 11 years ago.
And I cant really use __m128 because my whole point in using these structures to allow a fallback mechanism in case SSE is not supported by an architecture.
The fastest Pentium II processors were 450 MHz. Are you honestly going to build your game with support for that kind of processor?
Quote:Original post by LessBreadI don't have anything from the C spec, but the GCC doumentation explicitly states that:
C compilers don't handle aliases as well as C++ compilers. Maybe there's something in the spec about it. A typical approach is to prepend or append characters to the struct name not the alias.
You cannot specify alignment for a typedef name because such a name is just an alias, not a distinct type.
Quote:Other compilers using special includes or #pragma directives for alignment.The modern GCC syntax would be __attribute__ ((aligned (1))), and or __attribute__((packed)). See the relevant docs for details.
#pragma pack(push,1)
typedef struct tagSomeStruct {
// struct members
} SomeStruct, *PSomeStruct;
#pragma pack(pop);
Check yer docs