Re: [fpc-devel] cmem not aligning memory
Marco van de Voort wrote: > In our previous episode, Jonas Maebe said: >>> Or do we have to allocate more bytes for blocks that are a multiple of 8? >> FPC's default memory manager even guarantees 16 byte alignment (for vectors). > > So a possible solution is to allocate 16-sizeof(ptruint) bytes more? > > for 32-bit that would mean: > > <12 bytes slack> > Note that fftw_getmem and fftw_freemem (packages/fftw/src/fftw_s.pas) already contain the code to allocate always aligned pointer. (They allocate 15 bytes more for 16-bytes aligmnment, and store the value of original unaligned pointer to pass it to free.) One could use these as a workaround, to get aligned pointers from any GetMem/FreeMem implementation. Michalis ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] cmem not aligning memory
On 03 Apr 2010, at 14:09, Micha Nelissen wrote: > Do C memory managers guarantee any alignment anyway? Not for SSE (16 bytes) > I'm sure, but 8 bytes I don't know. From Linux' malloc man page: For calloc() and malloc(), the value returned is a pointer to the allo- cated memory, which is suitably aligned for any kind of variable, or NULL if the request fails. Mac OS X: The allocated memory is aligned such that it can be used for any data type, including AltiVec- and SSE-related types. Jonas___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] cmem not aligning memory
In our previous episode, Jonas Maebe said: > > Or do we have to allocate more bytes for blocks that are a multiple of 8? > > FPC's default memory manager even guarantees 16 byte alignment (for vectors). So a possible solution is to allocate 16-sizeof(ptruint) bytes more? for 32-bit that would mean: <12 bytes slack> ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] cmem not aligning memory
C Western wrote: Inspecting the cmem unit indicates the issue is the extra bytes allocated for the count - is this really needed? Or do we have to allocate more bytes for blocks that are a multiple of 8? Do C memory managers guarantee any alignment anyway? Not for SSE (16 bytes) I'm sure, but 8 bytes I don't know. Micha ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] cmem not aligning memory
On 03 Apr 2010, at 13:00, C Western wrote: > I notice that the cmem unit does not align memory in the same way as the > default unit - removing the cmem unit makes a factor of two difference in the > speed of some double precision matrix code. (My system is i386). Inspecting > the cmem unit indicates the issue is the extra bytes allocated for the count > - is this really needed? It is to be able to implement the same checking as the Pascal version has (give a run time error in case someone calls freemem(p,size) with the wrong size). BSD variants have a malloc_size() function that could be used instead, but at least Solaris and Linux don't seem to have something similar. > Or do we have to allocate more bytes for blocks that are a multiple of 8? FPC's default memory manager even guarantees 16 byte alignment (for vectors). Jonas___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
[fpc-devel] cmem not aligning memory
I notice that the cmem unit does not align memory in the same way as the default unit - removing the cmem unit makes a factor of two difference in the speed of some double precision matrix code. (My system is i386). Inspecting the cmem unit indicates the issue is the extra bytes allocated for the count - is this really needed? Or do we have to allocate more bytes for blocks that are a multiple of 8? Colin ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel