Click here to Skip to main content
15,895,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how do i align the btr data before manupulations in sse2? see code snippet below

C++
//.h file
Class tom
{
Public:
virtual void add(void* btr);
.
.
.
}

// .cpp file

void tom::add(void* btr)
{
    int* b = (int *)btr;
}
Posted
Updated 6-Aug-10 1:10am
v2

1 solution

It doesn't matter if btr is not aligned, what is important is that the buffer pointed by it is aligned (i.e. the address inside btr should be aligned). After that use the statement:

C++
__declspec(aligned(16)) int *b = (int *)btr;
 
Share this answer
 
Comments
SMART LUBOBYA 6-Aug-10 7:34am    
sauro, thanks for your quick response. btr is an array of integers. just how do i do address alignment?
Sauro Viti 6-Aug-10 7:44am    
This way:

void DoSomethingWithSSE2(int *btr)
{
// btr is an address passed on the stack, the parameter address could not be aligned...
__declspec(align(16)) int *b = btr; // This way the address of b is aligned!
}

void main()
{
// The array should be aligned for use with SSE2
__declspec(align(16)) int array[4][4] = { ... };

DoSomethingWithSSE2(array);
}
SMART LUBOBYA 6-Aug-10 10:02am    
in my code where do i place this:
void DoSomethingWithSSE2(int *btr) { // btr is an address passed on the stack, the parameter address could not be aligned... __declspec(align(16)) int *b = btr; // This way the address of b is aligned! }
in .h file or .cpp file?
Sauro Viti 6-Aug-10 14:22pm    
As that function is not declared as inline, you should place it in a .cpp file: if you place it in a .h file and then you include the header from more than one .cpp file ou will get warnings/errors while linking
SMART LUBOBYA 8-Aug-10 5:31am    
tried this:
//.cpp file

void tom::add(void* btr)
{
void add(int *btr)
{ //error C2601: 'add' : local function definitions are illegal
__declspec(align(16)) int *b = btr;
}

__declspec(align(16))int* b =(int*)btr;
__m128i f0,f1,f2,f3;
f0 = _mm_loadu_si128((__m128i*)b);
f1 = _mm_loadu_si128((__m128i*)b+1);
f2 = _mm_loadu_si128((__m128i*)b+2);
f3 = _mm_loadu_si128((__m128i*)b+3);
}
i get error C2601: 'add' : local function definitions are illegal

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900