forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

newlib/psplibc memory alignment for VFPU

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
holger



Joined: 18 Aug 2005
Posts: 204

PostPosted: Mon Oct 03, 2005 1:23 am    Post subject: newlib/psplibc memory alignment for VFPU Reply with quote

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
View user's profile Send private message
weak



Joined: 13 Jan 2005
Posts: 114
Location: Vienna, Austria

PostPosted: Mon Oct 03, 2005 3:25 am    Post subject: Reply with quote

why not just use memalign?
Back to top
View user's profile Send private message
ector



Joined: 12 May 2005
Posts: 195

PostPosted: Mon Oct 03, 2005 3:50 am    Post subject: Reply with quote

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
View user's profile Send private message
holger



Joined: 18 Aug 2005
Posts: 204

PostPosted: Mon Oct 03, 2005 5:20 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
weak



Joined: 13 Jan 2005
Posts: 114
Location: Vienna, Austria

PostPosted: Mon Oct 03, 2005 5:59 am    Post subject: Reply with quote

sounds convincing :)
Back to top
View user's profile Send private message
JiniCho



Joined: 14 Sep 2005
Posts: 18

PostPosted: Wed Oct 05, 2005 11:12 am    Post subject: Reply with quote

/holger

what if I try to realloc memalign()'ed chunks? Does it return NULL?
Back to top
View user's profile Send private message
holger



Joined: 18 Aug 2005
Posts: 204

PostPosted: Wed Oct 05, 2005 6:08 pm    Post subject: Reply with quote

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
View user's profile Send private message
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Thu Oct 06, 2005 8:03 am    Post subject: Reply with quote

Someone should add rememalign() :)

Jim
_________________
http://www.dbfinteractive.com
Back to top
View user's profile Send private message Visit poster's website
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Wed Jan 04, 2006 5:42 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group