Home » Developing U++ » U++ Developers corner » SSE2(/AVX) and alignment issues
Re: SSE2(/AVX) and alignment issues [message #30939 is a reply to message #30916] |
Fri, 28 January 2011 21:53 |
Novo
Messages: 1358 Registered: December 2006
|
Ultimate Contributor |
|
|
mirek wrote on Fri, 28 January 2011 04:55 | However, one big problem is that you would not be able to use 'new' to allocate SSE2 objects.
Of course, there is not much use for 'new' in U++ anyway, but still...
|
What is SSE2 object?
You can allocate sizeof(object) + alignment - 1 of memory and use placement new/delete to call constructor/destructor.
// A must be power of two.
template <unsigned A>
void* AlignMem(void* addr)
{
unsigned a = A - 1;
return (void*)((unsigned)addr + a) & ~a;
}
void* ptr = UPP::MemoryAlloc(sizeof(object) + alignment - 1)
object* o = new(AlignMem<alignment>(ptr)) object(aarg1, arg2, e.t.c.);
...
o->~object();
UPP::MemoryFree(ptr);
You need an extra pointer to allocated memory.
As far as I understand these SSE2 commands are going to be used with complicated data structures like matrices, vectors, strings, e.t.c. So, this pointer and allocation/destruction logic can be hidden inside of overloaded new/delete.
I personally would prefer to have an allocator, which allocates memory aligned by 16/32/64 bytes. AVX seems to be supported by Intel only at this time. So, you do not want to use AVX for quite long time. By the time we will need 64-byte aligned memory it might cost 1$ for a Gbyte.
mirek wrote on Fri, 28 January 2011 04:55 |
(Actually, life would be much easier in C++ if there would not be any 'new' and 'delete'
Mirek
|
Garbage collector in C++ is a real pain in the neck also. Your object can be garbage collected when you are still in a constructor.
I personally would prefer new/delete.
Regards,
Novo
|
|
|
|
|
SSE2(/AVX) and alignment issues
By: mirek on Fri, 28 January 2011 10:55
|
|
|
Re: SSE2(/AVX) and alignment issues
By: tojocky on Fri, 28 January 2011 13:48
|
|
|
Re: SSE2(/AVX) and alignment issues
|
|
|
Re: SSE2(/AVX) and alignment issues
By: Didier on Fri, 28 January 2011 18:43
|
|
|
Re: SSE2(/AVX) and alignment issues
By: mirek on Sat, 29 January 2011 00:05
|
|
|
Re: SSE2(/AVX) and alignment issues
By: mirek on Fri, 28 January 2011 23:59
|
|
|
Re: SSE2(/AVX) and alignment issues
By: Novo on Fri, 28 January 2011 21:53
|
|
|
Re: SSE2(/AVX) and alignment issues
By: mirek on Sat, 29 January 2011 00:03
|
|
|
Re: SSE2(/AVX) and alignment issues
By: Novo on Sat, 29 January 2011 02:07
|
|
|
Re: SSE2(/AVX) and alignment issues
By: tojocky on Sat, 29 January 2011 09:23
|
|
|
Re: SSE2(/AVX) and alignment issues
By: mirek on Sat, 29 January 2011 20:29
|
|
|
Re: SSE2(/AVX) and alignment issues
By: tojocky on Sun, 30 January 2011 11:34
|
|
|
Re: SSE2(/AVX) and alignment issues
By: mirek on Sun, 30 January 2011 11:51
|
|
|
Re: SSE2(/AVX) and alignment issues
By: tojocky on Sun, 30 January 2011 16:52
|
|
|
Re: SSE2(/AVX) and alignment issues
By: mirek on Sun, 30 January 2011 18:24
|
|
|
Re: SSE2(/AVX) and alignment issues
By: Novo on Sun, 30 January 2011 19:35
|
|
|
Re: SSE2(/AVX) and alignment issues
By: mirek on Sun, 30 January 2011 20:08
|
|
|
Re: SSE2(/AVX) and alignment issues
By: Novo on Sun, 30 January 2011 20:50
|
|
|
Re: SSE2(/AVX) and alignment issues
|
|
|
Re: SSE2(/AVX) and alignment issues
By: tojocky on Sun, 30 January 2011 22:03
|
Goto Forum:
Current Time: Sat May 11 18:50:45 CEST 2024
Total time taken to generate the page: 0.04285 seconds
|