PocketMatrix forums

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

Instruction/data cache performance

From: http://www.cewindows.net/faqs/pocketpcstaving.htm

"...The cache in the StrongARM CPU is 16k for code and 8k for data. The cache in the XScale CPU is 32k for code and 32k for data. So if the code and data that is being executed fits into the cache, the system is able to operate at the full clock speed of the CPU. If it does not fit then it will not execute at full speed. The actual performance of the system will vary dramatically between these 2 limits of 25 million instructions and 206 million instructions per second depending on whether or not the program and data fit into the cache..."

I'm always skeptical of claims such as this, which suggests that if my main body of code (and ideally data) can fit into the cache, then my program will run X magnitudes faster. Two or three times faster, quite possibly, but 8 times faster? Hmm.

Does anybody have real-world experience of the use of such techniques - if so do they really result in the dramatic performance gains suggested by the above quote?

(As a sidenote: yes I could go ahead and experiment in order to find out myself, but I'm ... lazy ... like that...) :wink:
Some of the "data" in that article is wrong or misleading, IMHO,.. but processors that are designed to run with a cache suffer very badly when the cache is turned off, especially processors with long pipelines.

which suggests that if my main body of code (and ideally data) can fit into the cache, then my program will run X magnitudes faster.


That's not really a good way of looking at it, due to the way that caches work.

Two or three times faster, quite possibly, but 8 times faster? Hmm.


It depends on whether you're talking average case, or worst case. If you imagine that something like a StrongARM, with a 5-stage pipeline that needs to be flushed on a branch, means that *every* branch you take you're loading from main memory. If the cache is on, and the instructions/data are in it, it's 1 cycle per load.. if you're loading from main memory instead, you're looking at some serious performance problems.

Generally, if a routine is using a lot of data access, then making it nicely cache coherant will gain you a lot of speed.

I just hacked together a quick test on one of my StrongARM platforms (which suffers from much worse data throughput than the PocketPCs). Provisos:

  • this isn't a "fair", or a "real" test

  • the loaded data fits a cache line, and we're loading it from a static address (meaning that the cache performance is very likely 100% cache hits on the data)

  • more iterations would give more accurate results, but I have 'flu right now and don't want to wait hours

  • it was run on a non-multi-tasking system

  • the machine I ran it on is not a PocketPC

  • this bypasses the issue of fitting stuff nicely into the cache - I bypass/ignore the "average" case, nonetheless it does show the affect using the cache well could have...


The code:
Code:

Test_Loop
STMFD R13!,{R0-R12,R14}
LDR R0,Iterations_Loop
Loop
MOV R1,R2
MOV R2,R3
MOV R3,R4
MOV R4,R5
MOV R5,R6
MOV R6,R7
MOV R7,R8
SUBS R0,R0,#1
BNE Loop
LDMFD R13!,{R0-R12,PC}

Test_Load
STMFD R13!,{R0-R12,R14}
ADR R12,Data
LDR R0,Iterations_Load
Loop2
LDMIA R12,{R1-R8}
SUBS R0,R0,#1
BNE Loop2
LDMFD R13!,{R0-R12,PC}


The results (times are in seconds):


Iterations:
Loop = 16777216
Load = 16777216
-----------------
Cache ON
Loop:0.85
Load:0.93
-----------------
Cache OFF
Loop:72.79
Load:83.56
-----------------
Cache DATA ONLY
Loop:57.01
Load:22.82
-----------------
Cache INSTRUCTION ONLY
Loop:0.88
Load:41.04
-----------------


Cheers,

Ref.
Ref, one of these days I'm going to come up with a technical question you can't answer :D

Thanks for the info.
:) Thanks, it was no problem.