I try to build an application which uses pthreads and __m128 SSE type. According to GCC manual, default stack alignment is 16 bytes. In order to use __m128, the requirement is t
Another solution would be, to use a padding function, which first aligns the stack and then calls f
. So instead of calling f
directly, you call pad
, which pads the stack first and then calls foo
with an aligned stack.
The code would look like this:
#include
#include
#define ALIGNMENT 16
void *f(void *x) {
__m128 y;
// other stuff
}
void * pad(void *val) {
unsigned int x; // to get the current address from the stack
unsigned char pad[ALIGNMENT - ((unsigned int) &x) % ALIGNMENT];
return f(val);
}
int main(void){
pthread_t p;
pthread_create(&p, NULL, pad, NULL);
}