Shop OBEX P1 Docs P2 Docs Learn Events
Bug in SETQ for fast Block move — Parallax Forums

Bug in SETQ for fast Block move

Christof Eb.Christof Eb. Posts: 1,195
edited 2023-11-15 11:20 in PASM2/Spin2 (P2)

Hi,
After spending xx (!) hours first because of the "poor" documentation and then because of very strange results I have now been able to strip down the issue:

**SETQ in combination with WRLONG gives wrong results for upper cog registers starting from $1F9=PTRB. **
This should be made clear in the documentation!
I also have doubts, if SETQ works with RDLONG for PTRB?

In Taqoz PTRA is used as instruction pointer and PTRB is used as parameter stack pointer pointing into LUT.
The routine storeSetq uses setq and setq2 for fast block moves, while storeConv uses conventional loops. Both are executed from HUB ram.

The test first uses 2 times storeConv to store to different buffers and compare them. Then first storeSetq and then storeConv and compare again.

TAQOZ# test ---
2* conventional:

$0000_0000 $0006_C000 $0006_D010 \ OK buffer address
$0000_0011 $0000_0228 $0000_0000 \ OK register R1
$0000_0023 $0006_C000 $0006_D010 \ OK TOS
LUT: $0000_0242 $0000_B94E $0000_B954 \ OK return address

setq and conventional:

$0000_0000 $0006_C000 $0006_D010 \ OK buffer address
$0000_0010 $0000_0400 $0000_0010  \ OK register R0
$0000_0012 $0000_0000 $0000_01EE \ OK register R2 
$0000_0023 $0006_C000 $0006_D010 \ OK TOS 
$0000_01F8 $0000_B86A $0000_B89A \ OK??? calling wordcode address
$0000_01F9 $0000_0000 $0000_0001 \ NOK Forth stack pointer should be same
$0000_01FA $AF9C_F31B $0000_0000 \ NOK DIRA 
$0000_01FE $0000_01F8 $FFFF_FFF0 \ NOK INA
$0000_01FF $7952_BE52 $7FFF_FFFF \ NOK INB
LUT: $0000_0242 $0000_B978 $0000_B97E \ OK return address
TAQOZ#  ---  ok

Code:

!polls \ clear multitasking


pub *Tests*     PRINT" P2 Test" ;

org@ := oriorg
$6C000 := userdata
userdata org


\ scr $36e5 ! \ use video memory $33600 for buffer, normally $60000
7 cogstop \ vga

1028 longs aBuffer
aBuffer 1028 4* erase
1028 longs bBuffer
bBuffer 1028 4* erase
$5_0000 := diffBuffer \ on boundary for dump
\ 1028 longs diffBuffer
diffBuffer 1028 4* erase

0 := cog0
\ TAQOZ
%red %pen

code storeSetq ( buffer )
   push cog0

   mov cog0,a 
   setq #511 ' write all cog RAM
   wrlong 0,cog0

   mov cog0,a
   add cog0,##2048
   setq2 #511 ' 512-1 write all LUT from 0 3,645ns @200MHz #####
   wrlong 0,cog0

   pop cog0
   ret
end

code storeConv ( buffer )
   push cog0

   mov cog0,a
   mov r0,#0 ' store all cog ########################
   mov r2,##512 '  
   FOR: ' store cog
      altd r0,#0
      wrlong 0,cog0
      add r0,#1      
      add cog0,#4
   NEXT: r2

   mov cog0,a
   add cog0,##2048

   mov r2,##512 '  
   FOR: ' store cog
      rdlut r1,r0
      wrlong r1,cog0
      add r0,#1      
      add cog0,#4
   NEXT: r2

   pop cog0
   ret
end

%white %pen

: dumpDiff
   crlf
   1028 for
      aBuffer i 4* + @ dup >a
      bBuffer i 4* + @ dup >b -
      if 
         crlf i .l ."  "  a> .l ."  " b> .l
      then
   next
;

: test
   \ crlf ." Buffers just cleared: "
   \ dumpDiff

   crlf ." 2* conventional: "   
   aBuffer storeConv drop 
   bBuffer storeConv drop
   dumpDiff

   crlf ." setq and conventional: "
   aBuffer storeSetq drop
   bBuffer storeConv drop
   dumpDiff   
;

test
Sign In or Register to comment.