Shop OBEX P1 Docs P2 Docs Learn Events
Tucking ASSY instructions into instructions that take 7..22 clocks — Parallax Forums

Tucking ASSY instructions into instructions that take 7..22 clocks

parskoparsko Posts: 501
edited 2006-11-20 20:55 in Propeller 1
Below is a quote from another post submitted by Chip in response to my question (found about 2/3 of the way down in the post).

There have been discussions about how to tuck extra instructions into long (listed as 7-22 clocks) instructions. For example, in PASSY, the "rdlong" command takes 7-22 clocks. We can tuck other 4-clock instructions into the same command, with "no hit" on the number of clocks it takes to execute the overall code.

My question:

How can one guarantee that these "extra" instructions will get executed?

AKA, I can **kinda** imagine how this works if the "rdlong" takes 22 clocks, but what about the 7 clock scenario?

Would someone care to explain this in a bit more depth?

Thanks,

-Parsko

======================================================================================
build                   rdword  tile,tile_ptr           'get next word from the tile array
                        add     tile_ptr,#2             '(need 6, not 7 inst's between rdword and
                                                        'rdlong to keep hub pace, else big penalty!!)
                        movs    col,tile                'get color bits from tile word          
                        andn    col,#$1C0

Comments

  • nutsonnutson Posts: 242
    edited 2006-11-20 13:33
    A single "rdlong" instruction takes a variable time 7-22 cycles because it has to wait on a timeslot for hubaccess, which occurs every 16 cycles. Once the instruction has been executed, there are 16-7=9 cycles left before the next time slot. This is enough time to execute 2 normal 4 cycle instructions in between. The best timing of a sequence of "rdlong" instructions would be:
    1st rdlong 7-22
    xor 4
    add 4
    2nd rdlong 8 (or 2 normal instructions)
    shl 4
    andn 4
    3th rdlong 8 etc

    Nico



    Nico Hattink

    Nico Hattink
  • parskoparsko Posts: 501
    edited 2006-11-20 14:09
    Nico,

    What happens if the "rdlong" occurs at clock 16, then needs 7 more clocks to execute. Doesn't this mean the two instructions get skipped?

    I understand your answer, and knew about the 16-7=9, but still confused how it gets tucked in there... they always get executed???

    -Luke
  • CJCJ Posts: 470
    edited 2006-11-20 14:24
    nothing gets skipped, you just put a couple of instructions in between two "consecutive" hub operations, you are just making use of time that would otherwise just be spent waiting at the next hub op. hub access comes around once every 16 cycles whether or not you make full use of the time between accesses

    
    rdlong    'syncs to hub then takes 7
    add        'takes 4
    xor        'takes 4
    rdlong    'takes 1 cycle to sync to the hub instead of 9, then takes 7
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Who says you have to have knowledge to use it?

    I've killed a fly with my bare mind.

    Post Edited (CJ) : 11/20/2006 2:29:14 PM GMT
  • parskoparsko Posts: 501
    edited 2006-11-20 14:32
    Ah, two consecutive hub access. That makes sense to me.

    So, it can only be done if one has two consecutive hub accesses?

    -Luke
  • CJCJ Posts: 470
    edited 2006-11-20 15:51
    yes

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Who says you have to have knowledge to use it?

    I've killed a fly with my bare mind.
  • nutsonnutson Posts: 242
    edited 2006-11-20 16:47
    Look at it this way. The execution time of a hub access-instructions consists of a fixed 6 cycles execution time, and a variable 1-16 cycles wait till the next hub access window. No escape. However, if you are going to execute a series of hub-access instructions, only the first one will need to have this uncertain wait-time, the next one will only need to wait the minimum 1 cycle if you having exactly 2, 6, 10 .. etc normal instructions executed in between hub-access instructions, because you are now in sync with the hub access mechanism..

    rdlong 6 + (1 to 16) wait
    add 4
    add 4
    rdlong 6 + 2 wait "this one has minimum hub wait time

    compared to

    rdlong 6 + (1 to 16) wait
    add 4
    add 4
    add 4
    rdlong 6 + 14 wait 'this one has to wait an additional 12 cycles for hub access

    Nico
  • cgraceycgracey Posts: 14,206
    edited 2006-11-20 17:42
    Once a hub instruction executes, you can execute 4n+2 instructions before another hub instruction lands right in front of its window of opportinuty. In other words, if you need more than 2 regular instructions between a pair of hub instructions, you might as well try to fit 6, or 10, or 14, etc.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.
  • AndreLAndreL Posts: 1,004
    edited 2006-11-20 20:55
    Both the HYDRA book and the propeller manual show this graphically and explain it in a clear manner. In the HYDRA book, you can find it on page 192, section 13.6, on the HUB stuff. Also, my "HEL" single COG tile/sprite engine makes extensive use of this interleaving and is documented thoroughly as well. This is in chapter 16 and 24 of the HYDRA book.

    Andre'
Sign In or Register to comment.