Hi guys,

I have some questions about the prefetch-instructions.
The Syntax is something like this: prefetch <Memory Adress>

1. How to access the prefetched value? Or does the processor has a table in which all cached memory-adresses reside.

2. How to unload a value from the cache. Is the existing memory-adress updated?

Or do I have a totally misunderstood these principles?
Thanks for your help

Compuholic
Posted on 2002-11-21 15:43:38 by Compuholic
Prefetch tells the processor we would like the cacheline containing this address to be in the cache.

1. The whole cacheline is prefetched. It is accessed with normal memory use.

2. This is automatic when address falls within cache.

I think you misunderstand. Cache is transparent to most code execution. You only recommend to the processor with prefetch what would be good to have in cache in the future. For example,

mov al,

...this instruction forces the whole cacheline at into the cache because that memory is needed right now for the instruction (assuming it is not in the cache). So the data travels: {main memory} --> {L2} --> {L1} --> {CPU}.

But if prefetch is used:

prefetch
...
...{give processor time to load cacheline}
...
mov al,

Then data travels: {L1} --> {CPU} and this is much quicker. If the value is already in the cache then the prefetch instruction is like NOP.
Posted on 2002-11-21 16:09:35 by bitRAKE
Hi Compuholic: PREFETCH is only an optimization hint for the CPU.. it doesn't change program flow at all.. besides, hopefully, only the execution speed, if used correctly and if the CPU doesn't decide to ignore the hint we give it. It's like Pentium 4's branch hints.. they are only attempts at optimization, the CPU is free to ignore them.
Posted on 2002-11-21 16:13:40 by Maverick
Thanks,

I think I've got it now :)
Posted on 2002-11-22 11:36:07 by Compuholic