PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

What is the cache page size?

What is the cache page size? The reason I ask is that someone said it was 32 bytes (i.e. when you read from 0x1234, 0x1220 to 0x123f are cached) so I decided to test this out.

I am blitting 32x32 tiles to a back buffer:
Code:

static void OneTile(unsigned int x,unsigned int y,unsigned int t)
{
unsigned char *ps=NULL,*pd=NULL;
unsigned char *WholeEnd=NULL;

ps=Gdata+(t<<11);
pd=DrawBuf+(x<<1)+(y<<9);

WholeEnd=ps+2048;
do
{
unsigned char *End=ps+64;
do
{
*(unsigned short *)pd=*(unsigned short *)ps;
pd+=2; ps+=2;
}
while (ps<End);
pd+=512-64;
}
while (ps<WholeEnd);
}


It takes about 0.10 ms to blit one tile (memory to memory).
But then I tried fliping the tile diagonally
pd+=2; ps+=64; etc...
i.e. reading from Tile+0 then Tile+64 etc - you get the idea. Should have taken a massive performance hit, but it took none: still 0.10 ms and I've tested this in full flow (tiles diagonally flipped fine) with no performance hit at all. It works...

So what's going on, how big is the page size? I wasn't expecting this?

(This will make a big difference to me, because I'll store the back buffer in the same orientation as the screen if I can rotate tiles without a performance hit. Even though it's hassle to handle all the different orientations...!)
It may be down to the granularity of your timer. You might need I higher resolution timer.

You could try copying longwords instead of shorts. This should 1/2 the amount of time spent in the loop. Good to see your source data is consecutive in memory, saving an add per line.

As for the cache, that'll probably depend on the CPU. 32 bytes sounds a bit weedy!

Steve.
>It may be down to the granularity of your timer. You might need I higher resolution timer.
I'm timing 100 and 1000 repetitions

>You could try copying longwords instead of shorts. This should 1/2 the amount of time spent in the loop. Good to see your source data is consecutive in memory, saving an add per line.

>As for the cache, that'll probably depend on the CPU. 32 bytes sounds a bit weedy!

What is it for the StrongARM in the iPAQs?
I mean the accuracy of your timer, not the number of your repeats. If the code took 1.98ms and the optimised version took 1.01ms, the timer might just output 1ms.
Dunno much about the cache of IPAQ, the MIPS used to have 4K cache (on PSX anyway...)
Appologies, just found this on the spec page:

"16 kilobyte instruction cache, 8 kilobyte write-back data cache"

Use google to search for:

ipaq hardware specification

All sorts of good stuff.
>I mean the accuracy of your timer, not the number of your repeats. If the code took 1.98ms and the optimised version took 1.01ms, the timer might just output 1ms.

Not really, because the timer isn't started and stopped after each repetition - it times the entire repetition set. Which means that if the timer has an accuracy of 1ms, the result is accurate to .01ms if you do 100 repetitions or 0.001ms if you do 1000 repetitions.

>"16 kilobyte instruction cache, 8 kilobyte write-back data cache"
>Use google to search for:
>ipaq hardware specification
>All sorts of good stuff.

Thanks! I guess that means about 19 cache misses per line copy. Thinking about it - that's going to kill it!! That also explains why 32x32x16 bit tiles are okay either way (they are only 2k)
Steve:

You're confusing the cache size with the cache-line size.

The cache on the StrongARM, I believe, has a 32-byte cache line length, so yes, when it reads from memory it'll read 32-bytes at a time, on a physically aligned 32-byte boundary (which should map directly into logical space, i.e. if logical is aligned the physical is). The cache size is, as you state, 16KB instruction, 8KB data.

However, on the StrongARM, I *think* that the read cache doesn't actually stall the data bus while it reads the data (sorry if I said it did before... I'm not sure now and I don't have the manual to hand), so if you're using the first word you get it after a couple of cycles, then the next appears two later, etc (and so you may be able to move things without stalls).

Try not to work/plot in unsigned shorts, if you can avoid it. I'll disassemble it later and have a look at it if I get 5 mins.

Cheers,

Refractor
The cache on the StrongARM, I believe, has a 32-byte cache line length, so yes, when it reads from memory it'll read 32-bytes at a time, on a physically aligned 32-byte boundary (which should map directly into logical space, i.e. if logical is aligned the physical is). The cache size is, as you state, 16KB instruction, 8KB data.


I don't understand... oh hang on, do you mean it can cache 256*block of 32 bytes of data at one time? (256*32=8K)
Spot on.

From the manual:

"The main data cache, an 8 Kbyte write-back Dcache, has 256 lines of 32 bytes (8words) in a 32-way set-associative organization."

(And the cache works in logical memory space, not physical, just for the record, though like I said earlier, for WinCE PPCs it shouldn't matter).

Cheers,

Ref.