Correct syntax to reserve the first n longs for a run-time fast lookup table
godzich
Posts: 74
in Propeller 1
Hi,
I want to run PASM in one cog so that I have 64 longs from address 0 reserved for a run-time generated table that I can access as fast as possible within the same COG's PASM program. The table must start att the COG address 0 to have the fastest access possible (no table base address addition before accessing the data). What is the proper syntax for this? To save the precious HUB memory I want to use the RES directive before my code since the table is generated at the beginning of the PASM program. Can this be done? Wich is the proper syntax?
Cheers,
Christian
I want to run PASM in one cog so that I have 64 longs from address 0 reserved for a run-time generated table that I can access as fast as possible within the same COG's PASM program. The table must start att the COG address 0 to have the fastest access possible (no table base address addition before accessing the data). What is the proper syntax for this? To save the precious HUB memory I want to use the RES directive before my code since the table is generated at the beginning of the PASM program. Can this be done? Wich is the proper syntax?
Cheers,
Christian
Comments
1. As Frank says, place 64 long zeros (NOPs) at the beginning and your code will fall thru the NOPs.
2. Place a JMP to the start of your code at Cog $000, the the remaining 63 longs of your table, followed by the first entry of your table (the one replaced by the JMP), then the start of your code. Label the first entry of you table TABLE0. Then at the start of you code (following the JMP, 63 table, first table entry), perform a MOV $0, TABLE0
Hope this helps.
-Phil
Here is a code snippet that shows the suggestion (not tested): So you can reduce the overhead from 64 to 6 longs.
Andy
Thanx for all replies. Phil and Ariba - you nailed it! I don't want to loose 64 HUB longs just for the sake of making room for an initially empty table in a COG.
Your idea moving the code after it has started - is genious. And then nex overwrite the code snipplet that moved everything with my runtime generated table. But what happens to compile time resolved absolute adresses and references? Will this really work - oh I see (thanks Phil for pointing it out), the org 64 directs the compilert to resolve all references properly so that when this relocated code executes from 64 upwards, all references are correct.
This technique also means (?!!) that I cannot fill the COG completely with code - I will lose 64 LONGs at the end of the COG codespace - and that is a no go - my algorightm needs about all 496 available longs... ? Is this assumption correct?
So - to return to the original question; Isn't there any trick using RES that would work??? How RES erally works is still a little dim. Such a waste to only be able to use it at the END of your code !!??
The calling COG that starts my PASM COG has an label "Start" ( cognew(@Start, 0) ) that indicates where the execution starts? Or is it just used as a reference for the compiler to keep it on the track? Execution always starts at 0?
As always, grateful for your comments and support with this very different but interesting processor. Still learning...
Cheers,
Christian
Christian
Ariba's concept will work for you. Following the bit of code moving the 496-64 longs up, calculate the table and put into cog overwriting the startup code. You will need to be careful not to overwrite your code executing. You might have to put a tiny bit of code at the end of your cog that will be used as data space once everything is ready.
If you don't have enough space, then ask as I can help you get a few extra longs using the shadow ram in the register space. It's tricky but can be done if there is no other way.
The Assembler builds a cog image in Hub-Ram. A cognew loads this image into a cog and starts execution at address 0. Cognew always loads 496 longs from the hubaddress you give in the second parameter. Normally you don't have code that spans the full 496 longs, so it additionally loads just what is in hub behind the cog image (mostly hub-data or Spincode).
RES allows to make the cog-image smaller if you have variables that don't need to be initalised. So RES increments the cog address for the Assembler, but does not reserve memory in Hub-Ram. This can only work at the end, not at begin. If you do it at begin of the image the whole image gets displaced references.
If you want to spare Hub-Ram, you can use the space of the cog-image for other things, like a fifo or sector-buffer, after you have startet the cog. The hub-image is then no longer needed, as long as you don't want to start the same code in another cog, or stop and start the cog again.
Andy
@ Andy and Phil: thank you a zillion - works like a charm
I learned at the same time a neat trick about how to optimize code and run efficient loops using "local" count variables in a clever way (ccntr)! Those variables (ccntr and IncDS) must naturally be defined and referenced "locally" and cannot be variables that are defined after the org 64
Thanks for saving me 58 longs in HUB! Very helpful. I assume this is the only way to reserve n longs in the beginning of a cog and preserving at the same time HUB ram. Obviously HUB ram can later be overwritten. I need to restart or launch several COGs running this same code so this is not in this case an option.
it is clear that the max size of all code, variables, constants can be max 496 LONGs.
@Cluso99 - it would also be interesting to learn more about the shadow ram
Cheers,
Christian
Kuroneko is the specialist for tricks using the counters FRQA/B and PHSA/B.
Does this mean cog execution always start at zero, and that the compiler will generate code starting from the label in coginit/cognew call, discarding any code before the label?
coginit/cogstart load the code from the address given into the COG and then always start at COG address 0
Enjoy!
Mike
This way, it's less "tricky" looking and still accomplishes the task in six longs.
-Phil
But in "relocating" the code, what happens when the S field contains an immediate constant (#), and does not want to be adjusted? I suspect a few more lines of code are required to take care of such issues.
Cheers,
Peter (pjv)
The org 64 will take care of any such issues. The code will assemble as if it were already relocated at the new address. None of the code that's being moved gets altered in any way.
-Phil
I did not read your code precisely enough.... I thought you were adjusting code assembled at org 0 , but on closer inspection of the line
sub :moveup,IncDS 'next 1 address lower
I now see it simply adjusts the addresses of the move pointers
Cheers,
Peter (pjv)