You are not logged in.
Lost Password?


Register To Post



 Bottom   Previous Topic   Next Topic

#1
Performance Tip: Enable Cache for intense loops
Posted on: 2008/6/2 8:26
PVB Elite
Joined 2003/7/25
USA
1507 Posts
PVBCC 1stCoderContributor#3 PosterHOTY09 EntryLong Time User (15 Years) App CoderPVBCC 2010 EntryPVBCC 2013 Entry
Hey,

Here's a quick and easy performance tip: Manually enabling cache before an intense loop and disabling it after creates a VERY noticable performance increase (if used correctly, and where it's actually needed, of course). In the loop where I create the affine table in Mario Kart, the game was running a little slow on real hardware, so I decided I needed to either use more LUTs to get rid of divisions, rewrite in ASM, or see what happens when I explicitly enable cache. Just enabling cache made the game run MUCH faster (probably ~2x as fast). Of course I knew that was the bottleneck, so it makes sense to enable cache there, but I didn't expect that much performance difference.

Anyway, just wanted to give a heads up... I was never sure if gccvb handled cache, or if it always left it disabled... I kinda figured it left it disabled, and I believe that's correct.

DogP
Top

#2
Re: Performance Tip: Enable Cache for intense loops
Posted on: 2008/6/2 10:57
Administrator
Joined 2000/1/8
Germany
2515 Posts
Highscore Top10Highscore Top ScoreCoder#1 PosterHOTY09 1stLong Time User (15 Years) App Coder90+ Game Ratings
thanks for the great tip!
got a code snippet to enable the cache for us lazy ones? ;)
Top

#3
Re: Performance Tip: Enable Cache for intense loops
Posted on: 2008/6/2 20:49
VUE(xpert)
Joined 2003/9/3
Sweden
442 Posts
PVBCC EntryHighscore Top10 3rdCoderContributorHOTY09 2ndLong Time User (15 Years) DonatorApp CoderPVBCC 2010 1st20+ Game RatingsPVBCC 2013 2nd
This sounds interesting... you mean the VB has some cache memory that we've never used before? Maybe this could relight the spark in my yeti projects :D
Top

#4
Re: Performance Tip: Enable Cache for intense loops
Posted on: 2008/6/3 3:00
PVB Elite
Joined 2003/7/25
USA
1507 Posts
PVBCC 1stCoderContributor#3 PosterHOTY09 EntryLong Time User (15 Years) App CoderPVBCC 2010 EntryPVBCC 2013 Entry
Yeah, there's 1KB cache. ROM (with the default wait states) takes 3 cycles, RAM takes 2 cycles, and cache takes 1 cycle... so it's definitely faster. You could also change the ROM wait states to 1 to get ROM access down to 2 cycles... that would probably be fine since most of the flash ROMs are faster than 100ns (at least the ones that I'm using).

Anyway, for the code, you can either use the asm in the code, or I use a #define and do CACHE_ENABLE and CACHE_DISABLE:

Enable:

asm
("mov 2,r1
    ldsr r1,sr24"
    
/* No Output */
    
/* No Input */
    
"r1" /* Reg r1 Used */
    
);

#define CACHE_ENABLE    asm("mov 2,r1 n    ldsr r1,sr24": /* No Output */: /* No Input */: "r1" /* Reg r1 Used */)


Disable:

asm
("ldsr r0,sr24");

#define CACHE_DISABLE    asm("ldsr r0,sr24")


So, my code looks like:

CACHE_ENABLE
;
while (
something)
{
    
//do lots of stuff
}
CACHE_DISABLE;


BTW, I believe you need to have the tabs in there (you usually need them in asm), and there's a tab after the \n in the CACHE_ENABLE line (you can't do multi-lines w/ a '\' in the newest gccvb without making some changes). I think you can use \t instead of tabs if you'd prefer as well.

Edit: There's a '\' before the n in the CACHE_ENABLE line (if you quote it in the reply it's there correctly, but in the post it disappeared).

DogP
Top

#5
Re: Performance Tip: Enable Cache for intense loops
Posted on: 2008/6/9 19:54
Nintendoid!
Joined 2006/3/15
Ecuador
234 Posts
PVBCC 3rdCoderLong Time User (13 Years)
Wow.. I will check this in my engine as soon as I get at home tonight.

jorgeche
Top

 Top   Previous Topic   Next Topic


Register To Post