Shop OBEX P1 Docs P2 Docs Learn Events
Code Optimization — Parallax Forums

Code Optimization

KyeKye Posts: 2,200
edited 2009-01-19 21:35 in Propeller 1
Hello, all I've been busting my head on how to do something in asm much more simply, but I just can't seem to get it done.

Here's the code..

                        muxnz   keyBuffer,          #1                  ' Backup Z flag.
                                                
                        cmp     keyArrayCounter,    #2 wz               ' Wait a little while to synchronize.      
if_nz                   cmp     keyArrayCounter,    #6 wz               '
if_nz                   cmp     keyArrayCounter,    #10 wz              '    
if_nz                   cmp     keyArrayCounter,    #14 wz              '
if_nz                   cmp     keyArrayCounter,    #18 wz              '
if_nz                   cmp     keyArrayCounter,    #22 wz              '
if_z                    waitcnt keyTimeBuffer,      clockWait           '
                                                                            
                        test    keyBuffer,          #1 wz               ' Restore Z flag.  

Basically, I need to use waitcnt for a state machine at specific times·in my code. The piece above is run inside a loop that loops 26 times. Every four loops I need to execute the waitcnt which is what this code does.

Now, I want to make it more optimized by using the c flag only so I don't need to backup the z flag since I'm using it within the loop. The problem is however, that there's a sweet spot. The code above executes that sweet spot. To say, waitcnt must only be executed on the 22, 18, 14, 10, 6, 2 parts in the loop. Note that the loop counts down from 26 so the execution of the coditional for 2 is last and 26 is first.

I can't seem to figure out how to do this with the c flag...

Any ideas?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,

Comments

  • lonesocklonesock Posts: 917
    edited 2009-01-19 19:30
    Untested, off the top of my head:

    mov tmp, keyArrayCounter
    sub tmp, #2
    and tmp, #3
    tjnz tmp, #skip_pause
    waitcnt keyTimeBuffer, clockWait
    skip_pause
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lonesock
    Piranha are people too.
  • KyeKye Posts: 2,200
    edited 2009-01-19 19:43
    Wow, I think that will work, thanks!

    Any other ideas anyone?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • lonesocklonesock Posts: 917
    edited 2009-01-19 19:50
    YW, and maybe this will work:

       mov tmp, keyArrayCounter
       rev tmp, #30
       djnz tmp, #:skip_pause
       waitcnt keyTimeBuffer, clockWait
    :skip_pause
    
    



    Reversing the lower 2 bits of tmp will zero out all upper 30 bits, and will leave a 1 in tmp if the original value would have been a 2. Then the DJNZ jump to :skip_pause if the value of tmp was not 1.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lonesock
    Piranha are people too.
  • mparkmpark Posts: 1,305
    edited 2009-01-19 21:03
    Wow Lonesock! Nice one!
  • lonesocklonesock Posts: 917
    edited 2009-01-19 21:35
    Thanks.

    * bows *


    [noparse][[/noparse]8^)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lonesock
    Piranha are people too.
Sign In or Register to comment.