gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > NDS cache

#156385 - ProblemBaby - Fri May 09, 2008 6:33 am

Hey

I'am wondering how to know if code and data is efficient cached or not?
is it possible to manually control it? in my project i've written the time consuming parts in ASM (but most are still in C) but am still unsure if the cache is used in the most efficient way...

There are especially some code and data that I would like to make sure stays in cache during the whole process, is it possible to force it to do that?

if someone could explain how I should think when I want to optimize with the cache in mind it would be awesome!

thanks

#156388 - Dwedit - Fri May 09, 2008 9:14 am

If you want to control where stuff goes, forget about the cache. Use fast DTCM and ITCM memory instead. TCM has the same speed as cache, but it is not 'automatic' like a cache is.
Cache is tiny, 8k code, 4k data. ITCM (32k) and DTCM (16k) are much bigger.
Most of the time you can ignore that a cache even exists. But the existence of the cache really matters when you need to use DMA, since you need to flush the write cache before the RAM will read correct data.
Only if your code exceeds the cache, will you notice when the cache isn't being helpful.
Keeping data aligned to 32 byte boundaries may help improve cache performance.
There are also non-cached mirrors of RAM, which are mostly useless.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#156400 - silent_code - Fri May 09, 2008 1:11 pm

as they originally said when the cache was introduced: "think of it as a black box. code as usually, it will 'just work'."

Dwedit's tip should be of much more interest to you.

#156405 - tepples - Fri May 09, 2008 1:21 pm

Dwedit wrote:
Keeping data aligned to 32 byte boundaries may help improve cache performance.

Would it be worth it to hack newlib malloc() to always return cache-aligned pointers?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#156406 - elhobbs - Fri May 09, 2008 1:27 pm

there is an existing thread on malloc and alignment.
http://forum.gbadev.org/viewtopic.php?t=14744
It already does return cache aligned addresses.

#156408 - pepsiman - Fri May 09, 2008 1:40 pm

elhobbs wrote:
there is an existing thread on malloc and alignment.
http://forum.gbadev.org/viewtopic.php?t=14744
It already does return cache aligned addresses.

That thread says malloc returns word aligned (32 bit, 4 byte) addresses, not cache aligned (32 byte) addresses.

#156414 - silent_code - Fri May 09, 2008 2:56 pm

EDIT: this has been a stupid crap post, sorry!

ps @ pepsiman: you might want to change your post from reading "32 bit, 4 byte" to just "4 byte". along with "32 bytes" later (<lol> "32 bytes later", get it?), it confused me, thus the crap post happened, that hopefully nobody read! ;^)
somehow, i guess i won't be the last one to be confused by that.

#156420 - Noda - Fri May 09, 2008 3:29 pm

tepples wrote:
Dwedit wrote:
Keeping data aligned to 32 byte boundaries may help improve cache performance.

Would it be worth it to hack newlib malloc() to always return cache-aligned pointers?


just use memalign if you want 32-bytes aligned pointers ;)

#156675 - pepsiman - Mon May 12, 2008 4:03 pm

silent_code wrote:
somehow, i guess i won't be the last one to be confused by that.

I was trying to clear up the 32 bits vs 32 bytes confusion.
Guess I failed.