| View previous topic :: View next topic |
| Author |
Message |
holger
Joined: 18 Aug 2005 Posts: 204
|
Posted: Mon Oct 03, 2005 1:23 am Post subject: newlib/psplibc memory alignment for VFPU |
|
|
Hi,
VFPU load/store instructions seem to support only 16-byte-aligned accesses (similiar to Altivec and SSE). The psplibc already uses this alignment as default for malloc()/realloc() and friends, can we also make this the default for the newlib (here this is right now only done when built for PPC/Altivec)? Then unaligned buffers passed from application to libraries (as textures, matrix pointers, vertex buffers, etc) are less likely, also will realloc work on aligned buffers.
what do you think?
newlib would require to define MALLOC_ALIGNMENT=16 in newlib/libc/include/sys/config.h, the required patch would be trivial.
Last edited by holger on Mon Oct 03, 2005 6:37 am; edited 1 time in total |
|
| Back to top |
|
 |
weak
Joined: 13 Jan 2005 Posts: 114 Location: Vienna, Austria
|
Posted: Mon Oct 03, 2005 3:25 am Post subject: |
|
|
| why not just use memalign? |
|
| Back to top |
|
 |
ector
Joined: 12 May 2005 Posts: 195
|
Posted: Mon Oct 03, 2005 3:50 am Post subject: |
|
|
I agree with Holger, a sacrifice of an average of 4 bytes per memory allocation is definitely worth it for the convenience. _________________ http://www.dtek.chalmers.se/~tronic/PSPTexTool.zip Free texture converter for PSP with source. More to come. |
|
| Back to top |
|
 |
holger
Joined: 18 Aug 2005 Posts: 204
|
Posted: Mon Oct 03, 2005 5:20 am Post subject: |
|
|
- you can't realloc memalign()'ed chunks
- user programs allocate their textures, LUTs, vertex buffers etc usually without knowing the required alignment, so the buffers can neither get directly passed to the DMA engine nor the GE, the graphics library has to touch every vertex or texel, even if it is already in optimal format and the GE could theoretically directly access it (if it would be properly aligned).
- memalign is tagged as obsolete since unix98. |
|
| Back to top |
|
 |
weak
Joined: 13 Jan 2005 Posts: 114 Location: Vienna, Austria
|
Posted: Mon Oct 03, 2005 5:59 am Post subject: |
|
|
| sounds convincing :) |
|
| Back to top |
|
 |
JiniCho
Joined: 14 Sep 2005 Posts: 18
|
Posted: Wed Oct 05, 2005 11:12 am Post subject: |
|
|
/holger
what if I try to realloc memalign()'ed chunks? Does it return NULL? |
|
| Back to top |
|
 |
holger
Joined: 18 Aug 2005 Posts: 204
|
Posted: Wed Oct 05, 2005 6:08 pm Post subject: |
|
|
| it's undefined by the spec. Everything can happen, also there is no guarantee that the new, reallocated buffer still meets some alignment requirements. (if it becomes reallocated at all - usually memalign is implemented on top of malloc and relies on the fact that free in most implementations does not needs to point on the start address of a memory chunk). |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Wed Jan 04, 2006 5:42 am Post subject: |
|
|
| Since this has been suggested for a long time with no objections, I just made the change. malloc() should now be 16-byte aligned. |
|
| Back to top |
|
 |
|