zlib using bios functions

Post Reply
Mysoft
Posts: 19
Joined: Thu Jun 09, 2011 11:56 am

zlib using bios functions

Post by Mysoft » Sat Jul 14, 2012 4:57 pm

as you guys know, among the bios functions there's support to decompress lz777 / huffman / rle
which is exactly what zlib uses (altough i'm not sure if they are modified versions of those)

but so my question is... anyone know if it's possible to use those to make the INFLATE/UNCOMPRESS functions from zlib? anyone atempted something like that?

also i saw the huffman part is streamed so it will probabily have poor performance and not suitable
since i wanted to check if it out could outperform zlib itself...

otherwise i think i should try to make a fully optimized pure ARM ASM version of such functions from zlib, to achieve maximum performance....
since i'm doing a AVI player (for ZMBV codec) the codec used in dosbox. and altough i had sucess playing an .avi 320x200x8 with full 70.083 fps with ADPCM (DS hardware) 22khz mono, for some videos that are more demanding, because they not compress great as simple platform games... the ZLIB alone is responsible for like 70% of cpu usage, even on 1/3rd fps videos (23.361 fps). and so even my frame caching scheme isnt enough to play such videos... so i think aside the fact that i can recode zlib to use compression level 1, to speed up zlib decompression, i think i can make it be at least 30-50% faster if using pure asm, because ZLIB is being compiled from a generic code (altough it does have a DS makefile)

(in fact i'm surprised that GCC can compile such things for DS, even knowing the horrendous alignment problems, that one can have on DS, (that affects pretty much all my freebasic compiled programs))

so anyway, maybe this isnt the best sections for this, but since the BIOS functions are on libnds, i tought it would worth a shot :)

Dwedit
Posts: 40
Joined: Sun Jan 06, 2008 4:06 am

Re: zlib using bios functions

Post by Dwedit » Sat Jul 14, 2012 7:20 pm

Just because there's a bios function doesn't mean it will be any faster.
Compiling code in ARM mode instead of THUMB mode will make it run faster. Then profile it to see what the "hot" loops are, and rewrite those in ASM if they need it. Placing code in ITCM makes it faster, but loops end up getting cached anyway.

I made a hacked-up version of VisualBoyAdvance that can do code profiling. Compile some kind of test program for the GBA, and you can profile it there.

Mysoft
Posts: 19
Joined: Thu Jun 09, 2011 11:56 am

Re: zlib using bios functions

Post by Mysoft » Sun Jul 15, 2012 3:34 am

Just because there's a bios function doesn't mean it will be any faster.
yeah but, since the BIOS function is written by nintendo, i would expect they to put effort, into optimizting it for that, instead of just lazyily compile code, like it is the case with the the ZLIB... altough based on the fiasko that is the "FastCopy" functions from the bios... nothing can be expected.... but those doesnt matter anymore, since i made my own FastCopy / FastSet functions to work with unaligned buffers, and to be waaaaaaaay faster than memcpy/memset (like up to 2x fast in optimal aligned case, and up to 10x faster in unaligned byte case).
Compiling code in ARM mode instead of THUMB mode will make it run faster.
ok, yeah, i compiled with ARM instead of thumb, also did -O3, got like 5-10% of speed up, ITCM isnt a good option yet, because the lib itself is 100kb
Then profile it to see what the "hot" loops are, and rewrite those in ASM if they need it. Placing code in ITCM makes it faster, but loops end up getting cached anyway.
altough i don't need a profile to know which parts requires more attention, but i will be doing gradual tests anyway :)

and so yeah, but i will not modify the C code, i will port it to freebasic, and then convert it fully to asm, or at least the functions i need to start with. Inflate* , and uncompress since uncompress does use inflate anyway...

altough that might seem a waste, it will be useful for anything using that, and so it's a "work once" / "use all" approach, that SHOULD be standard for systems like that :)

i think with my experience doing LZ777 and Huffman to port Titus The Fox, to a Trs-Color (0.896mhz CPU), will help a bunch here... to make the lib very fast, and small in size...
I made a hacked-up version of VisualBoyAdvance that can do code profiling. Compile some kind of test program for the GBA, and you can profile it there.
good to know, altough i will need to do some more headers translation, to code in freebasic in GBA as aswell, but it's definately something i will try :)

mtheall
Posts: 210
Joined: Thu Feb 03, 2011 10:47 pm

Re: zlib using bios functions

Post by mtheall » Tue Jul 17, 2012 4:07 pm

I wrote some asm code a few months ago for these guys. It's on github. It compares my C code (with -O3 in arm mode) vs my asm code (in arm mode) vs the BIOS code.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests