Guidelines on how to use the cache on Falcon?
Moderators: Mug UK, moondog/.tSCc., lp, [ProToS], Moderator Team
Guidelines on how to use the cache on Falcon?
I wonder if there are any good guidelines for using the data and instruction cache. I have a 3d application that I wrote in C and assembler but whatever I do with the cache settings is always worse than leave them alone.
I guess the default setting on the Falcon is instruction cache ON and data cache OFF? Atleast that's how it seems to work on my machine since if I enable the data cache my application goes slower than with it off (or leave it at whatever Falcon use as default).
I guess the default setting on the Falcon is instruction cache ON and data cache OFF? Atleast that's how it seems to work on my machine since if I enable the data cache my application goes slower than with it off (or leave it at whatever Falcon use as default).
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe
-
- Hardware Guru
- Posts: 3667
- Joined: Sat Sep 10, 2005 11:11 am
- Location: Kosice, Slovakia
- Contact:
Re: Guidelines on how to use the cache on Falcon?
A few years ago Daniel wrote a nice summary about the caches: https://nb.atari.org/main.php?page=prog ... _falcon030.
Also I wrote something about that topic many moons ago: https://mikro.naprvyraz.sk/docs/mikro/030_stram.html.
In short, yes, for tasks like clearing the frame buffer (screen) the data cache is your foe because every written long is written in the cache as well as in memory (write-through). The easiest workaround is to disable the data cache before clearing and then enable it again but Doug had developed a smarter way around: reprogram the PMMU so the frame buffer is marked as 'cache inhibit' by the PMMU.
Data cache enabled is useful for your use case, too: calculating a lot of middle-results (like matrices, 3D math etc) makes accessing stack/variables in memory faster.
Also, when playing with caches, don't forget to flush them first before disabling else you may get very strange and subtle errors. Oh and the burst mode doesn't work on plain Falcon, only with accelerators like CT2/DFB and similar.
Also I wrote something about that topic many moons ago: https://mikro.naprvyraz.sk/docs/mikro/030_stram.html.
In short, yes, for tasks like clearing the frame buffer (screen) the data cache is your foe because every written long is written in the cache as well as in memory (write-through). The easiest workaround is to disable the data cache before clearing and then enable it again but Doug had developed a smarter way around: reprogram the PMMU so the frame buffer is marked as 'cache inhibit' by the PMMU.
Data cache enabled is useful for your use case, too: calculating a lot of middle-results (like matrices, 3D math etc) makes accessing stack/variables in memory faster.
Also, when playing with caches, don't forget to flush them first before disabling else you may get very strange and subtle errors. Oh and the burst mode doesn't work on plain Falcon, only with accelerators like CT2/DFB and similar.
Re: Guidelines on how to use the cache on Falcon?
I have read those two articles. They are the only I have found for the Falcon so far.
I don't clear the frame buffer. I draw over it with new textures each frame, but that is maybe the same for the cache, so better disable it when drawing anything.
Is it better to clear the cache when disable it instead of when enable it?
I don't clear the frame buffer. I draw over it with new textures each frame, but that is maybe the same for the cache, so better disable it when drawing anything.
Is it better to clear the cache when disable it instead of when enable it?
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe
- Eero Tamminen
- Fuji Shaped Bastard
- Posts: 3438
- Joined: Sun Jul 31, 2011 1:11 pm
Re: Guidelines on how to use the cache on Falcon?
Yes, if your drawing is just writing a lot and not really reading any of that data back.
Note that Hatari profiler can tell you both about i-cache misses, and d-cache hits.
-
- Hardware Guru
- Posts: 3667
- Joined: Sat Sep 10, 2005 11:11 am
- Location: Kosice, Slovakia
- Contact:
Re: Guidelines on how to use the cache on Falcon?
Ah, sorry, I should have been more specific. You are correct, on the 030 you have to clear it only when enabling (because if there's some garbage, you enable it and read it immediately, it may contain invalid data).
Writing never leads to incorrect data because it is always written into memory, too. However this is not true for 040+, there you can write something, have it only in the cache and if you disable it, it will never make it to memory. So you have to flush the cache before disabling.
Re: Guidelines on how to use the cache on Falcon?
If I understand correctly the cache reads data in long words, but is it possible to align program code to start at a long addess?
ST / STFM / STE / Mega STE / Falcon / TT030 / Portfolio / 2600 / 7800 / Jaguar / 600xl / 130xe
Re: Guidelines on how to use the cache on Falcon?
if I remember correctly the TOS aligns the code to the word address boundary, but if needed you can realign it to the long-word address on your own.
Lynx I / Mega ST 1 / 7800 / Portfolio / Lynx II / Jaguar / TT030 / Mega STe / 800 XL / 1040 STe / Falcon030 / 65 XE / 520 STm / SM124 / SC1435
DDD HDD / AT Speed C16 / TF536 / SDrive / PAK68/3 / Lynx Multi Card / LDW Super 2000 / XCA12 / SkunkBoard / CosmosEx / SatanDisk / UltraSatan / USB Floppy Drive Emulator / Eiffel / SIO2PC / Crazy Dots / PAM Net
Hatari / Steem SSE / Aranym / Saint
http://260ste.atari.org
DDD HDD / AT Speed C16 / TF536 / SDrive / PAK68/3 / Lynx Multi Card / LDW Super 2000 / XCA12 / SkunkBoard / CosmosEx / SatanDisk / UltraSatan / USB Floppy Drive Emulator / Eiffel / SIO2PC / Crazy Dots / PAM Net
Hatari / Steem SSE / Aranym / Saint
http://260ste.atari.org
-
- Fuji Shaped Bastard
- Posts: 2685
- Joined: Sun Aug 03, 2014 5:54 pm
Re: Guidelines on how to use the cache on Falcon?
No, that cannot be guaranteed. TOS aligns Malloc() calls from STRAM only on an even address, but not necessarily on a long address. Since Pexec() uses Malloc, that also applies to program code. For TTRAM, that is different though. EmuTOS behaves the same.
-
- Fuji Shaped Bastard
- Posts: 2685
- Joined: Sun Aug 03, 2014 5:54 pm