Archived

This topic is now archived and is closed to further replies.

Dwiel

16byte Alligned Data

Recommended Posts

I have recently been working on SSE2 insructions and have found that if I can get my data 16byte alligned, I can call much much faster mov commands. Right now I use the following hack to get my 16byte alligned data: void *AllignData(void *data) { return (void *)(((int)data + 15) &~ 0x0F); } void main { const int sizeofdata = 512; double *lotsofdata; double *tempptr; tempptr = new double[sizeofdata + 2]; // " + 2" because in the worst case scenario, we will find the first 16bytes alligned data 15 bytes into our buffer. lotsofdata = AllignData(tempptr); // do lots of CPU intensive SSE2 stuff here delete [] tempptr; lotsofdata = 0; // do not delete lotsofdata, just set it to 0, the memory it points to is no longer valid } I was just wondering if there was a better way to accomplish this, as it is not a a very clean method for accomplishing what I want. A solution in gcc and/or visual C++ would be great. I have tried many things to fix this to no avail... Thanx! Dwiel

Share this post


Link to post
Share on other sites
You would most likely have to overload new/delete operators, because I don''t think setting byte alignment to 16 would do anything for you in that case.

Share this post


Link to post
Share on other sites
Yech... don''t align data this way. There are #pragmas and/or compiler-specific keywords to help you out; check your compiler docs.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites