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.

Coding > Is the stack fast?

#34514 - ProblemBaby - Thu Jan 20, 2005 8:01 pm

Is the stack faster then iwram and how big is it?
if I want to load something from iwram would be a better idea to put it on the stack and then load it from there?

then how is it done? in ARM asm

thanks in adv.

#34517 - poslundc - Thu Jan 20, 2005 8:50 pm

The stack is in IWRAM.

There is a pointer to the bottom of it (it is a descending stack) in r13, otherwise known as the stack pointer (sp).

Dan.

#34520 - NoMis - Thu Jan 20, 2005 9:32 pm

As poslundc mentioned the stack is in IWRAM. Every object created on compile time goes to the stack. Dynamicaly created objects go to the heap wich is in EWRAM as far as I know.

NoMis

#34585 - ProblemBaby - Fri Jan 21, 2005 11:49 pm

thanks for the information!
one more question.
how about ewram is it faster to load something from ewram then ROM?

#34588 - poslundc - Sat Jan 22, 2005 12:38 am

That's a... complicated question.

To put it simply, on modern carts using the settings that published games use, it's faster to load a contiguous block of data from ROM than it is from EWRAM.

For random memory access (such as loading a single integer), EWRAM outperforms ROM, and also consumes less battery power.

Dan.

#34590 - DekuTree64 - Sat Jan 22, 2005 1:01 am

poslundc wrote:
For random memory access (such as loading a single integer), EWRAM outperforms ROM, and also consumes less battery power.


Hmm, I thought the usual ROM waitstates were 3 first/1 sequential, and EWRAM is 3/2?
True EWRAM saves on battery life, but I don't think you'll ever get a speed increase from caching read-only data there.
That is, unless you leave the ROM waitstates on the default setting. If I remember right, it's set to 4/2 on startup, so you have to manually set 3/1 in REG_WSCNT.

VRAM, on the other hand, is faster than ROM. I ran some tests a while back but now I can't find the post with the results.
Bottom line is if you use VRAM for non-graphical things (code, tables, etc), the video hardware does take priority if you try to access something at the same time, but it's still the next fastest after IWRAM.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#34591 - Miked0801 - Sat Jan 22, 2005 1:20 am

Actually I believe EWRAM is 2/2 not 3/2 so random access is same as sequential. And all normal startups switch the ROM over to 3/1 access. Heck, you can set it it 2/1 but no carts will work reliably with it :)

#34597 - DekuTree64 - Sat Jan 22, 2005 2:06 am

Indeed it would appear you're right. And all this time I thought it was dirt slow.
So, EWRAM should be faster for loading single 8/16-bit values, and equal for 32-bit, since according to some other speed tests I did once, a load instruction will always hit the non-sequential access time, and only get sequential on the second 16 bits when loading 32 bits from a 16-bit bus.

DMA and block transfers (ldmia/stmia) should be faster from ROM though.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku