Pre-check for waitcnt?
mpark
Posts: 1,305
I have some cog code that occasionally runs long and causes waitcnt to stall for a minute 'cuz it's missed the boat.
I thought I'd try to skip the waitcnt if cnt has already passed the target value. This is what I have so far; what do you think of it?
The 10 is just a number I pulled out of my... head. Anyone know what the correct value is? I figure it shouldn't be too big, because I don't want to skip the waitcnt unnecessarily, but it has to be big enough to account for the extra instructions leading up to waitcnt.
What I'd really like to do is figure out why my %$# code runs long in the first place, but after chasing it for a day I'm ready to put in this stopgap and move on. Unfortunately I have lost all faith in my ability to reason about waitcnt and timing, so I'd appreciate less bleary eyes checking me on this little snippet.
I thought I'd try to skip the waitcnt if cnt has already passed the target value. This is what I have so far; what do you think of it?
mov temp, cntTarget sub temp, cnt cmps temp, #10 wc, wz if_b jmp #:skipWaitcnt waitcnt cntTarget, cntPeriod :skipWaitcnt
The 10 is just a number I pulled out of my... head. Anyone know what the correct value is? I figure it shouldn't be too big, because I don't want to skip the waitcnt unnecessarily, but it has to be big enough to account for the extra instructions leading up to waitcnt.
What I'd really like to do is figure out why my %$# code runs long in the first place, but after chasing it for a day I'm ready to put in this stopgap and move on. Unfortunately I have lost all faith in my ability to reason about waitcnt and timing, so I'd appreciate less bleary eyes checking me on this little snippet.
Comments
Good points about 20 and making waitcnt conditional (slaps forehead).
cmp will only return the desired carry when CNT hasn't yet passed Target but is very close. cmps also handles the case where CNT has already passed Target.
-Phil
Addendum:
One thing to note is that cmps will work only when your timed interval is less than $8000_0000 (about 27 seconds). To encompass the entire 53-second interval, you will need something like this:
At least I think that's correct. I still need to work through some examples.
Post Edited (Phil Pilgrim (PhiPi)) : 1/11/2009 8:50:55 PM GMT
Your addendum is giving me a headache. I may be misunderstanding your scenario, but I think there's a problem here.
After "sub temp, cnt wc", C means "cnt passed target up to 27 seconds ago" and NC means "cnt will hit target in 27 seconds or less". Of course, because of modular arithmetic, C also means "cnt will hit target between 27 and 54 seconds from now".
If I set target to 50 seconds from now and then do my work, and it only takes say 10 seconds, I'll hit the sub instruction with 40 seconds to go before cnt reaches target, so sub will set C (the second meaning, but there's no way to tell) and the waitcnt will be skipped, thus exiting prematurely.
Edit: Never mind, I was thinking subs, not sub. I gotta stop trying to think about this stuff.
Post Edited (mpark) : 1/12/2009 5:42:58 AM GMT
-Phil