Re: [eigen] Re: platform detection for aligned malloc

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


2009/1/8 Gael Guennebaud <gael.guennebaud@xxxxxxxxx>:
> well, here is my proposal:
>
> 1 -  since _mm_malloc is only available when vectorization is enabled
> we can forget about it.
>
> 2 - for all platforms which make problem let's eventually implement
> our own "_mm_malloc" using the common trick to allocate 16bytes more
> and store the original pointer in front of the aligned pointer. This
> is exactly how GCC's _mm_malloc is implemented: use posix_memalign if
> available, otherwise do the trick. Sounds reasonable, no ?
>
> This tricks holds for cygwin and all other systems for which we are
> still unsure.

I've been thinking the same actually. For a long time I was wary of
doing that because I wrongly believed that that would force us to keep
track of 2 ptrs instead of just 1 (the aligned ptr to use, and the
original ptr to free)
Actually there is a trick allowing to avoid doing that. I've seen
implementations of it but they're not LGPL-licensable so we can't use
them; but the idea is that the aligned ptr that you return is
guaranteed to be at an offset of at least sizeof(void*) bytes into the
actually allocated buffer, so that you may safely store another
pointer just before it; that latter storage space is where you store
the original ptr you'll have to free.

So yes, +1 from me.

Cheers,
Benoit

---


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/