SVS Documentation
John Strawn
10 September 1987
Here are the operations to be done.
do x1,baz
move x:(r1),x0
tfr x0,b x:(r1)+n1,y0
tst b
jle foo
mac x0,y0,a
jmp bar
foo mac -x0,y0,a
bar nop
baz nop
Remember the restrictions on DO loops. If you omit the nop at
bar, and you jump to baz after the first mac, then you'll jump
past the end of the loop.
This can be rearranged as follows:
; pipeline setup
clr a
move x:(r1),x0
tfr x0,b x:(r1)+n1,y0
; inner loop
do x1,baz1
tst b
jle foo1
mac x0,y0,a x:(r1),x0
jmp bar1
foo1 mac -x0,y0,a x:(r1),x0
bar1 tfr x0,b x:(r1)+n1,y0
baz1 nop
Here is another possibility. Here, we always calculate the
negative of A[n], where A is the input vector. If A[n]<0, then we
transfer it into y0, overwriting the original A[n] there. The
multiply that's done will result in a negative product, which is
smoothly accumulated.
do x1,baz2
move x:(r1),b
neg b x:(r1),x0
tst b x:(r1)+n1,y0
jle foo2
move b1,y0
foo2 mac x0,y0,a
baz2 nop
This can be arranged as follows:
; pipeline setup
move x:(r1),b
; inner loop
do x1,baz2
neg b x:(r1),x0
tst b x:(r1)+n1,y0
jle foo2
move b1,y0
foo2 mac x0,y0,a x:(r1),b
baz2 nop
Here is a third solution:
do x1,baz3
move x:(r1),b
move x:(r1),y0
neg b x:(r1),x0
jclr #23,x:(r1)+n1,foo3
move b,y0
foo3 mac x0,y0,a
baz3 nop
This can be rearranged as follows:
move x:(r1),b
clr a
do x1,baz3
move x:(r1),y0
neg b x:(r1),x0
jclr #23,x:(r1)+n1,foo3
move b,y0
foo3 mac x0,y0,a x:(r1),b
baz3 nop
Tests with the simulator give the following results:
Method Positive no. Negative no.
1 9 6
2 6 7
3 6 7
I chose to implement the second method, since its pipeline setup
is cleaner. Both methods 2 and 3 take 5 instructions inside the
loop, so there's no difference there.