newlib/psplibc memory alignment for VFPU

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
holger
Posts: 204
Joined: Thu Aug 18, 2005 10:57 am

newlib/psplibc memory alignment for VFPU

Post by holger »

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.
weak
Posts: 114
Joined: Thu Jan 13, 2005 8:31 pm
Location: Vienna, Austria

Post by weak »

why not just use memalign?
ector
Posts: 195
Joined: Thu May 12, 2005 10:22 pm

Post by ector »

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.
holger
Posts: 204
Joined: Thu Aug 18, 2005 10:57 am

Post by holger »

weak wrote:why not just use memalign?
- 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.
weak
Posts: 114
Joined: Thu Jan 13, 2005 8:31 pm
Location: Vienna, Austria

Post by weak »

sounds convincing :)
JiniCho
Posts: 18
Joined: Wed Sep 14, 2005 11:03 am

Post by JiniCho »

/holger

what if I try to realloc memalign()'ed chunks? Does it return NULL?
holger
Posts: 204
Joined: Thu Aug 18, 2005 10:57 am

Post by holger »

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).
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

Someone should add rememalign() :)

Jim
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Since this has been suggested for a long time with no objections, I just made the change. malloc() should now be 16-byte aligned.
Post Reply