Language error for combining skip conditions?

Algorithm development and general DSP issues

Moderator: frank

Post Reply
knutolai
Posts: 86
Joined: Wed Nov 23, 2016 9:43 am
Location: Bergen, Norway

Language error for combining skip conditions?

Post by knutolai »

I'm having an issue with combining skip conditions. Setting the condition "NEG|GEZ" should result in a skip regardless of the value loaded into ACC. Similarly setting the condition "RUN" should yield the same result for every program cycle after the initial. I have a white noise generator that requires such an unconditional skip. These solutions should be interchangeable but the "NEG|GEZ" variant seems to not always produce the skip!

According to the manual (I'm ignoring the typo where "N" is used in case og "NEG"):
Maybe the most efficient way to define the condition mask is using it's symbolic representation. In order to
simplify the SKP syntax, SPINAsm has a predefined set of symbols which correspond to the name of the
individual condition flags. (RUN,ZRC,ZRO,GEZ,NEG). Although most of the condition flags are mutually
exclusive, SPINAsm allows you to specify more than one condition flag to become evaluated simply by
separating multiple predefined symbols by the "|" character. Accordingly "skp ZRC|N, 6" would skip the
following six instructions in case of a zero crossing to a negative value.
My codes. Note that the noise gen codes. Note that the noise gen initialization process is placed after the noise gen to effectively "annul" the initial noise gen code cycle.

Code: Select all

ldax	LFSR		; Read LFSR reg 
AND	0x000001	; Get LSB of noise reg 
skp	ZRO, shiftzero	; if not zero : additionaly toggle mask bits
clr			; clr acc (non-zero acc)
rdax	LFSR, 0.5		; Get LFSR, shift right 1 place
AND	0x7FFFFF		; Clear MSB
XOR	0xD80000	; Toggle MASK bits 
skp	RUN, nwrite	; uncond. skp to storage
shiftzero:		; if Zero :
rdax	LFSR, 0.5		; Get LFSR, shift right 1 place
AND	0x7FFFFF		; Clear MSB
nwrite:			; storage flag
wrax	LFSR, 0		; store, clr

skp	RUN, start	; Noise gen init
sof	0, 0.95		; 0.95
wrax	LFSR, 0		; ignite noise gen
start:

ldax	LFSR
mulx	POT0
wrax	DACL, 0

Code: Select all

ldax	LFSR		; Read LFSR reg 
AND	0x000001	; Get LSB of noise reg 
skp	ZRO, shiftzero	; if not zero : additionaly toggle mask bits
clr			; clr acc (non-zero acc)
rdax	LFSR, 0.5		; Get LFSR, shift right 1 place
AND	0x7FFFFF		; Clear MSB
XOR	0xD80000	; Toggle MASK bits 
skp	GEZ|NEG, nwrite	; uncond. skp to storage
shiftzero:		; if Zero :
rdax	LFSR, 0.5		; Get LFSR, shift right 1 place
AND	0x7FFFFF		; Clear MSB
nwrite:			; storage flag
wrax	LFSR, 0		; store, clr

skp	RUN, start	; Noise gen init
sof	0, 0.95		; 0.95
wrax	LFSR, 0		; ignite noise gen
start:

ldax	LFSR
mulx	POT0
wrax	DACL, 0
What's going on here? Is this a language error or is there a problem with my ASCII input or something? :?:
frank
Posts: 1281
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Re: Language error for combining skip conditions?

Post by frank »

While we OR the mask values to create the mask, the "skp" function is basically an AND of the bits, i.e. the "ZRC|NEG" means the value tested must have done a zero crossing (sign change) AND be negative. So your mask of "GEZ|NEG" means the tested value must be both negative AND positive which are mutually exclusive.

Your line "skp GEZ|NEG, nwrite" should work as a simple "skp NEG, nwrite" since in the 2 lines above it you clear then set the sign bit so the result will always be negative.
Frank Thomson
Experimental Noize
knutolai
Posts: 86
Joined: Wed Nov 23, 2016 9:43 am
Location: Bergen, Norway

Re: Language error for combining skip conditions?

Post by knutolai »

Thank you! I wish that was stated in the reference manual. So creating an unconditional skip requires 2 instructions (given RUN is out of the question):

Code: Select all

skp gez, label
skp neg, label

label:
frank
Posts: 1281
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Re: Language error for combining skip conditions?

Post by frank »

We do mention it in the reference for the SKP instruction, it states:

Only if all condition flags that correspond to a logic "1" within CMASK are asserted are the following N instructions skipped.

This is page 36 of the manual and I believe this is the only place it is mentioned so it can be missed.

But most code will never need an unconditional SKP as the value is usually being converted or limited in some way so it will always be negative (as in your codes case) or positive so the programmer knows they can just use a NEG or GEZ flag. If an unconditional is required I usually try to arrange the code so the code right after it is the code I would have skipped to so it just flows into it and the unconditional is no longer needed. Or if that is not possible then I usually clear the acc and do a "skp gez" so I enter the next block of code with a cleard acc which I usually need in any case.
Frank Thomson
Experimental Noize
Post Reply