Shop OBEX P1 Docs P2 Docs Learn Events
Fastest way of encoding values for RFVAR/RFVARS — Parallax Forums

Fastest way of encoding values for RFVAR/RFVARS

Inspired by the nibble reversing thread and some conversation I had with @moony , what is the fastest way to encode a value for fast-yet-compact FIFO retrieval?

Conditions:

  • HUBEXEC, so expensive branches and no FIFO (although if you want to try optimizing for COGEXEC, who's to tell you no?)
  • input value in inp
  • put encoded value in out (bonus points if unused high bytes are zero,but it really doesn't matter)
  • put encoding length in length
  • alternatively, write to hub ram with PTRB

My attempt (untested):

encode_any_signed
              abs   tmp,inp
              encod tmp,tmp
              sca   tmp,##9363 ' divide by 7
              mov   tmp,tmp
              mul   tmp,#7
              add   tmp,#7
              zerox inp,tmp
encode_any
              mov length,#1              
              getbyte out,inp,#0
              shr inp,#7 wz
              bitnz out,#7
        if_z  ret
              mov length,#2
              setbyte out,inp,#1
              shr inp,#7 wz
              bitnz out,#7+8
        if_z  ret          
              mov length,#3
              setbyte out,inp,#2
              shr inp,#7 wz
              bitnz out,#7+16
        if_z  ret          
              mov length,#4
              setbyte out,inp,#3
              shr inp,#7 wz
              bitnz out,#7+24
        if_z  ret
              '' error handling here

Not sure if that actually works. Also, surely, there's a better way.

Sign In or Register to comment.