Shop OBEX P1 Docs P2 Docs Learn Events
Cog memory byte addressing in prop assembly code — Parallax Forums

Cog memory byte addressing in prop assembly code

ght_dakght_dak Posts: 15
edited 2007-08-15 16:37 in Propeller 1
Is there an easy (fast)·way to·write / read single bytes·in cog memory?· All the instructions are register (long) aligned (other than the hub memory access instructions)... so i'll need to do a bunch of shifting and bit operations...

I'm trying to build a small byte buffer in cog memory.

-glenn
·

Comments

  • deSilvadeSilva Posts: 2,967
    edited 2007-08-13 01:53
    Carry on shifting smile.gif
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-13 02:48
    I've written routines to do byte packing and unpacking and they're not hard using shifts and bit operations, but it's easier just to store a byte in a 32-bit word if the buffer is small enough.
  • big_markbig_mark Posts: 49
    edited 2007-08-13 09:49
    But if you wanted to then dump the data out to hub RAM at some point, it may be quicker to keep the data packed and use 'wrlong' and write 4 bytes at once.
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-08-13 11:45
    It does seem like a single byte case devolves down to just wrbyte. For instance,

    movs outbyte,byteVal
    wrbyte outbyte,hubdest

    could just as well be

    wrbyte byteVal,hubdest

    word lengths are more fun

    movs outword,lowbyte
    ror outword,8
    movs outword,highbyte
    rol outword,8
    wrword outword,hubdest

    Alas, the long can't do the same trick because a fourth movs would clobber a bit that you really wanted.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-13 13:30
    Since wrbyte and wrword don't use the upper part of the register, you could do:
    wrbyte byteVal,hubDest
    add hubDest,#1
    ror byteVal,#8
    

    You can repeat this 4 times, it catches every hub cycle, and it leaves the packed byte values unchanged (after 4).
    You can do the same for packed words like:
    wrword wordVal,hubDest
    add hubDest,#2
    ror wordVal,#16
    

    This requires that hubDest be a multiple of 2. For longs, you'd have:
    wrlong longVal,hubDest
    add hubDest,#4
    

    In this case, hubDest must be a multiple of 4.
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-08-13 15:16
    Mike, what's the optimum way to pack 4 bytes into a Cog long?
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-13 15:31
    smile.gif
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-13 15:53
    Optimum depends on what you want to do with the data. The most useful order is LSB first because that's the way they're stored in byte-addressable hub memory and you can use RDLONG and WRLONG to transfer blocks of 4 bytes back and forth.
  • ght_dakght_dak Posts: 15
    edited 2007-08-14 04:21
    I guess I was wondering how I could use fewer instructions to accomplish the byte write... it was getting to the point where I might as well just jam the byte into hub memory using WRBITE instead of doing the byte manipulation... fewer cycles overall and lots more capability once its on the hub side

    OTOH, here's a great deal of flexibility in how one writes prop assembly code... some of it quite wierd using indirect addressing schemes etc. Perhaps if I played around more with these capabilities, I'd come up with somethig very elegant and fast... then again, maybe not smile.gif
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-14 05:02
    Fred Hawkins said...
    Alas, the long can't do the same trick because a fourth movs would clobber a bit that you really wanted.
      movi x, byte0
      shr x, #8
      movi  x, byte1
      shr x, #8
      movi  x, byte2
      shr x, #8  ' NO, NO, NO! It should be 7 - obviously
      shr x, #1 WC
      movi  x, byte3
      rcl x, #1
      wrlong x, huba
    


    smile.gif

    Edit: But this was just an untested idea :-( Fred did in correct (see below)

    Post Edited (deSilva) : 8/15/2007 4:42:24 PM GMT
  • ght_dakght_dak Posts: 15
    edited 2007-08-14 05:37
    Yup, that'll do it. thx..
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-08-14 12:09
    deSilva said...
    Fred Hawkins said...
    Alas, the long can't do the same trick because a fourth movs would clobber a bit that you really wanted.
      movi x, byte0
      shr x, #8
      movi  x, byte1
      shr x, #8
      movi  x, byte2
      shr x, #8
      shr x, #1 WC
      movi  x, byte3
      rcl x, #1
      wrlong x, huba
    


    smile.gif
    hmmm, sez bug. Methinks last big shift is 7 bits, not 8:
    1024 x 768 - 23K
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-15 16:37
    Thank you! Copy 'n' paste and not tested smile.gifsmile.gif
Sign In or Register to comment.