Shop OBEX P1 Docs P2 Docs Learn Events
Instruction Operation P2 v10a — Parallax Forums

Instruction Operation P2 v10a

Here is a place to record how instructions work and if they have been tested, etc
(just to keep it in one place without other discussions being interleaved)

Chips' P2 Documentation v10a
https://drive.google.com/open?id=1WVk_NHejFVTZzYv33SL1xPU5lHQXCiVwYS7DXK3Um2Y

Google P2 Instructions (some out of date)
https://docs.google.com/document/d/1O27nO2tMjBTvUNblFFRtEp5DHvcvsSGXcPvH9FaJ9u8/pub

Here is the Instruction Summary...
Propeller P16X64A Instructions v10a-1c 17Jun2016
----------------------------------------------------------------------------------------------------------------------------------------
Cond Opcode  CZ I Dest       Source     Instr00 01      10      11        Operand(s)                                         Flags      
----------------------------------------------------------------------------------------------------------------------------------------
CCCC 00000ff CZ I DDDDDDDDD  SSSSSSSSS  ROR     ROL     SHR     SHL       D,S/#                                              CZ CZ CZ CZ
CCCC 00001ff CZ I DDDDDDDDD  SSSSSSSSS  RCR     RCL     SAR     SAL       D,S/#                                              CZ CZ CZ CZ
CCCC 00010ff CZ I DDDDDDDDD  SSSSSSSSS  ADD     ADDX    ADDS    ADDSX     D,S/#                                              CZ CZ CZ CZ
CCCC 00011ff CZ I DDDDDDDDD  SSSSSSSSS  SUB     SUBX    SUBS    SUBSX     D,S/#                                              CZ CZ CZ CZ
CCCC 00100ff CZ I DDDDDDDDD  SSSSSSSSS  CMP     CMPX    CMPS    CMPSX     D,S/#                                              CZ CZ CZ CZ
CCCC 00101ff CZ I DDDDDDDDD  SSSSSSSSS  CMPR    CMPM    SUBR    CMPSUB    D,S/#                                              CZ CZ CZ CZ
CCCC 00110ff CZ I DDDDDDDDD  SSSSSSSSS  MIN     MAX     MINS    MAXS      D,S/#                                              CZ CZ CZ CZ
CCCC 00111ff CZ I DDDDDDDDD  SSSSSSSSS  SUMC    SUMNC   SUMZ    SUMNZ     D,S/#                                              CZ CZ CZ CZ
CCCC 01000ff CZ I DDDDDDDDD  SSSSSSSSS  ISOB    NOTB    CLRB    SETB      D,S/#                                              CZ CZ CZ CZ
CCCC 01001ff CZ I DDDDDDDDD  SSSSSSSSS  SETBC   SETBNC  SETBZ   SETBNZ    D,S/#                                              CZ CZ CZ CZ
CCCC 01010ff CZ I DDDDDDDDD  SSSSSSSSS  ANDN    AND     OR      XOR       D,S/#                                              CZ CZ CZ CZ
CCCC 01011ff CZ I DDDDDDDDD  SSSSSSSSS  MUXC    MUXNC   MUXZ    MUXNZ     D,S/#                                              CZ CZ CZ CZ
CCCC 01100ff CZ I DDDDDDDDD  SSSSSSSSS  MOV     NOT     ABS     NEG       D,S/#                                              CZ CZ CZ CZ
CCCC 01101ff CZ I DDDDDDDDD  SSSSSSSSS  NEGC    NEGNC   NEGZ    NEGNZ     D,S/#                                              CZ CZ CZ CZ
CCCC 0111000 ff I DDDDDDDDD  SSSSSSSSS  ALTI    ALTR    ALTD    ALTS      D,S/#                                              -- -- -- --
CCCC 0111001 CZ I DDDDDDDDD  SSSSSSSSS  DECOD                             D,S/#                                              CZ         
CCCC 011101f CZ I DDDDDDDDD  SSSSSSSSS  TOPONE  BOTONE                    D,S/#                                              CZ CZ      
CCCC 011110f CZ I DDDDDDDDD  SSSSSSSSS  INCMOD  DECMOD                    D,S/#                                              CZ CZ      
CCCC 011111f fZ I DDDDDDDDD  SSSSSSSSS  MUL     MULS    SCLU    SCL       D,S/#                                              -Z -Z -Z -Z
----------------------------------------------------------------------------------------------------------------------------------------
CCCC 1000ffn nn I DDDDDDDDD  SSSSSSSSS  SETNIB  GETNIB  ROLNIB  *******   D,S/#,#n                                           -- -- -- --
CCCC 100011f nn I DDDDDDDDD  SSSSSSSSS  SETBYTE GETBYTE                   D,S/#,#n                                           -- --      
CCCC 1001000 nn I DDDDDDDDD  SSSSSSSSS  ROLBYTE                           D,S/#,#n                                           --         
CCCC 1001001 fn I DDDDDDDDD  SSSSSSSSS  SETWORD GETWORD                   D,S/#,#n                                           -- --      
CCCC 1001010 0n I DDDDDDDDD  SSSSSSSSS  ROLWORD                           D,S/#,#n                                           --         
CCCC 1001010 1f I DDDDDDDDD  SSSSSSSSS  SETBYTS MOVBYTS                   D,S/#                                              -- --      
CCCC 1001011 ff I DDDDDDDDD  SSSSSSSSS  SPLITB  MERGEB  SPLITW  MERGEW    D,S/#                                              -- -- -- --
CCCC 1001100 ff I DDDDDDDDD  SSSSSSSSS  SEUSSF  SEUSSR  RGBSQZ  RGBEXP    D,S/#                                              -- -- -- --
CCCC 1001101 ff I DDDDDDDDD  SSSSSSSSS  REV     SETI    SETD    SETS      D,S/#                                              -- -- -- --
CCCC 1001110 ff I DDDDDDDDD  SSSSSSSSS  DJZ     DJNZ    DJS     DJNS      D,S/#rel9                                          -- -- -- --
CCCC 1001111 ff I DDDDDDDDD  SSSSSSSSS  TJZ     TJNZ    TJS     TJNS      D,S/#rel9                                          -- -- -- --
CCCC 10100ff CZ I DDDDDDDDD  SSSSSSSSS  TESTN   TEST    ANYB    TESTB     D,S/#                                              CZ CZ CZ CZ
CCCC 1010100 ff I DDDDDDDDD  SSSSSSSSS  ADDCT1  ADDCT2  ADDCT3  WMLONG    D,S/#;D,S/#;D,S/#;D,S/#/PTRx                       -- -- -- --
CCCC 1010101 CZ I DDDDDDDDD  SSSSSSSSS  CALLD                             D,S/#rel9                                          CZ         
CCCC 101011f CZ I DDDDDDDDD  SSSSSSSSS  RDPIN   RDLUT                     D,S/#                                              CZ CZ      
CCCC 10110ff CZ I DDDDDDDDD  SSSSSSSSS  RDBYTE  RDWORD  RDLONG  *******   D,S/#/PTRx                                         CZ CZ CZ CZ
CCCC 1011011 ff I DDDDDDDDD  SSSSSSSSS  ADDPIX  MULPIX  BLNPIX  MIXPIX    D,S/#                                              -- -- -- --
CCCC 101110f fL I DDDDDDDDD  SSSSSSSSS  <empty> <empty> JP      JNP       D/#,S/#;D/#,S/#;D/#,S/#rel9;D/#,S/#rel9            -- -- -- --
CCCC 101111f fL I DDDDDDDDD  SSSSSSSSS  SETPAE  SETPAN  SETPBE  SETPBN    D/#,S/#                                            -- -- -- --
CCCC 110000f fL I DDDDDDDDD  SSSSSSSSS  WRPIN   WXPIN   WYPIN   WRLUT     D/#,S/#                                            -- -- -- --
CCCC 110001f fL I DDDDDDDDD  SSSSSSSSS  WRBYTE  WRWORD  WRLONG  RDFAST    D/#,S/#/PTRx;D/#,S/#/PTRx;D/#,S/#/PTRx;D/#,S/#     -- -- -- --
CCCC 1100100 fL I DDDDDDDDD  SSSSSSSSS  WRFAST  FBLOCK                    D/#,S/#                                            -- --      
CCCC 1100101 fL I DDDDDDDDD  SSSSSSSSS  XINIT   XZERO                     D/#,S/#                                            -- --      
CCCC 1100110 fL I DDDDDDDDD  SSSSSSSSS  XCONT   REP                       D/#,S/#                                            -- --      
CCCC 1100111 CL I DDDDDDDDD  SSSSSSSSS  COGINIT                           D/#,S/#                                            C-         
CCCC 110100f fL I DDDDDDDDD  SSSSSSSSS  QMUL    QDIV    QFRAC   QSQRT     D/#,S/#                                            -- -- -- --
CCCC 1101010 fL I DDDDDDDDD  SSSSSSSSS  QROTATE QVECTOR                   D/#,S/#                                            -- --      
----------------------------------------------------------------------------------------------------------------------------------------
CCCC 1101011 CZ L DDDDDDDDD  0000000ff  CLKSET  COGID   <empty> COGSTOP   D/#                                                CZ CZ CZ --
CCCC 1101011 CZ 0 DDDDDDDDD  0000001ff  LOCKNEW LOCKRET LOCKCLR LOCKSET   D;D/#;D/#;D/#                                      CZ -- C- C-
CCCC 1101011 CZ L DDDDDDDDD  0000010ff  <empty> <empty> <empty> <empty>   D/#                                                CZ CZ CZ CZ
CCCC 1101011 CZ L DDDDDDDDD  0000011ff  <empty> <empty> QLOG    QEXP      D/#                                                CZ CZ -- --
CCCC 1101011 CZ 0 DDDDDDDDD  0000100ff  RFBYTE  RFWORD  RFLONG  WFBYTE    D;D;D;D/#                                          CZ CZ CZ --
CCCC 1101011 00 L DDDDDDDDD  0000101ff  WFWORD  WFLONG  SETQ    SETQ2     D/#                                                -- -- -- --
CCCC 1101011 CZ 0 DDDDDDDDD  0000110ff  GETQX   GETQY   GETCT   GETRND    D                                                  CZ CZ -- CZ
CCCC 1101011 00 L DDDDDDDDD  0000111ff  SETDACS SETXFRQ GETXCOS GETXSIN   D/#;D/#;D;D                                        -- -- -- --
CCCC 1101011 00 L DDDDDDDDD  0001000ff  SETEDG  SETRDL  SETWRL  SETHLK    D/#                                                -- -- -- --
----------------------------------------------------------------------------------------------------------------------------------------
CCCC 1101011 C0 0 0000000ff  000100100  POLLINT POLLCT1 POLLCT2 POLLCT3                                                      C- C- C- C-
CCCC 1101011 C0 0 0000001ff  000100100  POLLEDG POLLPAT POLLRDL POLLWRL                                                      C- C- C- C-
CCCC 1101011 C0 0 0000010ff  000100100  POLLXMT POLLXFI POLLXRO POLLXRL                                                      C- C- C- C-
CCCC 1101011 C0 0 0000011ff  000100100  POLLFBW POLLHLK POLLATN POLLQMT                                                      C- C- C- C-
CCCC 1101011 C0 0 0000100ff  000100100  WAITINT WAITCT1 WAITCT2 WAITCT3                                                      C- C- C- C-
CCCC 1101011 C0 0 0000101ff  000100100  WAITEDG WAITPAT WAITRDL WAITWRL                                                      C- C- C- C-
CCCC 1101011 C0 0 0000110ff  000100100  WAITXMT WAITXFI WAITXRO WAITXRL                                                      C- C- C- C-
CCCC 1101011 C0 0 0000111ff  000100100  WAITFBW WAITHLK WAITATN <empty>                                                      C- C- C- CZ
CCCC 1101011 00 0 0001000ff  000100100  ALLOWI  STALLI  <empty> <empty>                                                      -- -- CZ CZ
CCCC 1101011 CZ 0 0001001ff  000100100  <empty> <empty> <empty> <empty>                                                      CZ CZ CZ CZ
----------------------------------------------------------------------------------------------------------------------------------------
CCCC 1101011 00 L DDDDDDDDD  0001001ff  ******* SETINT1 SETINT2 SETINT3   -;D/#;D/#;D/#                                      -- -- -- --
CCCC 1101011 00 L DDDDDDDDD  0001010ff  WAITX   SETCZ   PUSH    POP       D/#;D/#;D/#;D                                      -- CZ -- CZ
CCCC 1101011 CZ 0 DDDDDDDDD  0001011ff  JMP     CALL    CALLA   CALLB     D                                                  CZ CZ CZ CZ
CCCC 1101011 00 L DDDDDDDDD  0001100ff  JMPREL  RET     RETA    RETB      D/#;-;-;-                                          -- CZ CZ CZ
CCCC 1101011 00 0 DDDDDDDDD  0001101ff  GETPTR  GETINT  SETBRK  SETLUT    D;D;D/#;D/#                                        -- -- -- --
CCCC 1101011 00 L DDDDDDDDD  0001110ff  SETCY   SETCI   SETCQ   SETCFRQ   D/#                                                -- -- -- --
CCCC 1101011 00 L DDDDDDDDD  0001111ff  SETCMOD SETPIX  SETPIV  COGATN    D/#                                                -- -- -- --
----------------------------------------------------------------------------------------------------------------------------------------
CCCC 11011ff Rn n nnnnnnnnn  nnnnnnnnn  JMP     CALL    CALLA   CALLB     #abs/#rel                                          -- -- -- --
CCCC 1110fww Rn n nnnnnnnnn  nnnnnnnnn  CALLD   LOC                       reg,#abs/#rel                                      -- --      
CCCC 1111fnn nn n nnnnnnnnn  nnnnnnnnn  AUGS    AUGD                      #23bits                                            -- --      
----------------------------------------------------------------------------------------------------------------------------------------
  COG REGISTERS                                  
-------------------------------------------------
  _IJMP3 = $1F0   '' COG Interrupt Jump   3      
  _IRET3 = $1F1   '' COG Interrupt Return 3      
  _IJMP2 = $1F2   '' COG Interrupt Jump   2      
  _IRET2 = $1F3   '' COG Interrupt Return 2      
  _IJMP1 = $1F4   '' COG Interrupt Jump   1      
  _IRET1 = $1F5   '' COG Interrupt Return 1      
  _ADDRA = $1F6   '' COG ADDR A                  
  _ADDRB = $1F7   '' COG ADDR B                  
  _PTRA  = $1F8   '' COG PTR  A                  
  _PTRB  = $1F9   '' COG PTR  B                  
  _DIRA  = $1FA   '' COG DIR  A                  
  _DIRB  = $1FB   '' COG DIR  B                  
  _OUTA  = $1FC   '' COG OUT  A                  
  _OUTB  = $1FD   '' COG OUT  B                  
  _INA   = $1FE   '' COG IN   A / Debug JMP      
  _INB   = $1FF   '' COG IN   B / Debug RET      
-------------------------------------------------

Comments

  • Cluso99Cluso99 Posts: 18,069
    SETCZ D/# {WC,WZ}

    CCCC 1101011 CZ L DDDDDDDDD 000101001 SETCZ D/# {WC,WZ}

    Sets the C & Z flags according to D[1:0] and WC, WZ
    If WC is specified then C=D[1] (0=C cleared, 1=C set)
    If WZ is specified then Z=D[0] (0=Z cleared, 1=Z set) (yes, 1 sets Zero flag)
    If neither WC nor WZ is specified, then C & Z flags are not set/changed
    If both WC and WZ are specified, then both C & Z flags are set/changed

    I have verified the above with v10a.

    Note to Chip
    Might it be possible/easy to have SETCZ when neither WC nor WZ is specified, that D[1:0] is set/written with the contents of C & Z flags (ie the reverse of SETCZ D WC,WZ) ? It could be called SAVECZ.
  • Cluso99 wrote: »
    Might it be possible/easy to have SETCZ when neither WC nor WZ is specified, that D[1:0] is set/written with the contents of C & Z flags (ie the reverse of SETCZ D WC,WZ) ? It could be called SAVECZ.

    FYI This can be achieved by using 2 SETBx instructions.
    	setbc	x,#1
    	setbz	x,#0
    


  • +1 for SAVECZ

    Enjoy!

    Mike
  • Thinking about flags saving some more we had PUSHZC/POPZC instructions in P2-Hot
    Here's some of my notes on these instructions to refresh our memory on them.
    The PUSHZC/POPZC instructions rotate ZC states thru the
     source address as follows.
    
    PUSHZC rotates left x 2 thru source address.
    Z/C flags are only updated if WZ/WC effects are nominated.
    
    +-----------> Z flag  ----+
    |                         |
    |  +------->  C flag  ------+
    |  |                      | |
    WZ WC                     | |
                              | | 
    ^  ^                      | |
    |  |                      V V
    
    31 30.................... 1 0
       <-----------------------
           rotated left x2
    
    
    POPZC rotates right x 2 thru source address
    Z/C flags are only updated if WZ/WC effects are nominated.
    
    +------------ Z flag  <---+
    |                         |
    |  +--------  C flag  <-----+
    |  |                      | |
    |  |                     WZ WC
    |  |                      ^ ^ 
    |  |                      | |
    V  V                      | |
    
    31 30.................... 1 0 
       ----------------------->
          rotated right x2
    
    These enabled saving and restoring zc flags.
    A 16 level flag stack basically. :)



  • Cluso99Cluso99 Posts: 18,069
    ozpropdev wrote: »
    Thinking about flags saving some more we had PUSHZC/POPZC instructions in P2-Hot
    Here's some of my notes on these instructions to refresh our memory on them.
    The PUSHZC/POPZC instructions rotate ZC states thru the
     source address as follows.
    
    PUSHZC rotates left x 2 thru source address.
    Z/C flags are only updated if WZ/WC effects are nominated.
    
    +-----------> Z flag  ----+
    |                         |
    |  +------->  C flag  ------+
    |  |                      | |
    WZ WC                     | |
                              | | 
    ^  ^                      | |
    |  |                      V V
    
    31 30.................... 1 0
       <-----------------------
           rotated left x2
    
    
    POPZC rotates right x 2 thru source address
    Z/C flags are only updated if WZ/WC effects are nominated.
    
    +------------ Z flag  <---+
    |                         |
    |  +--------  C flag  <-----+
    |  |                      | |
    |  |                     WZ WC
    |  |                      ^ ^ 
    |  |                      | |
    V  V                      | |
    
    31 30.................... 1 0 
       ----------------------->
          rotated right x2
    
    These enabled saving and restoring zc flags.
    A 16 level flag stack basically. :)


    I don't think we need anything that complex. Just a simple save which is the reverse of setcz. It saves an instruction only when both are being saved. Otherwise we have other instructions which can perform this such as if_z setb x,#n and those from your prior post.
  • jmgjmg Posts: 15,173
    edited 2016-10-14 05:43
    Is the info in #1 up to date with most recent changes ?
    It seems to have only partial opcode construction details

    eg with fasmg, https://flatassembler.net/download.php

    and using a Chip docs example, I find/guess this is the required form of WAITX
    - looks ok for the 32b case ?
    ;  1098 7654321 09 8 765432109
    ;  CCCC 1101011 00 L DDDDDDDDD  0001010ff  WAITX  
    
    macro WAITX? ParS*&  ; fasmg 
        F2_ZC_S ParS  
        pV = ParS	; force numeric eval
        if pV <= 0x1ff
            dd gZCS + (1101011_00_0b shl 18) + (pV and 0x1ff) shl 9 + 000101000b
        else    
            dd (pV shr 9) + 0xff800000  ; upper bits to 1's ?
            dd gZCS + (1101011_00_1b shl 18) + (pV and 0x1ff) shl 9 + 000101000b
        end if
    end macro 
    
    tests as
    
    ;00000008: 25 26 80 FF 28 80 66 FD WAITX 20_000_000/4     OK 
    
    
  • Latest FPGA version is V12.

    Your bytes are all correct.
    Your macro will also have to deal with non immediate variants too.
        WAITX myreg
    
  • jmgjmg Posts: 15,173
    ozpropdev wrote: »
    Latest FPGA version is V12.

    Your bytes are all correct.
    Your macro will also have to deal with non immediate variants too.
        WAITX myreg
    
    Do you have an encoding for that ?
    I can see only a L bit in WAITX, which I assumed was Long immediate, or does that mean L=0 is RegAdr, and all immediates are 32b prefixed ? ( L == #32)

    In that case, the macro gives this
    macro WAITX? ParS*&  ;
        F2_ZC_S ParS  
        pV = ParS	; force numeric eval
        match #data, ParS  
    		dd (pV shr 9) + 0xff800000  ; upper bits to 1's ?
            dd gZCS + (1101011_00_1b shl 18) + (pV and 0x1ff) shl 9 + 000101000b
        else    
            dd gZCS + (1101011_00_0b shl 18) + (pV and 0x1ff) shl 9 + 000101000b
        end match    
    end macro 
    
    
    00000000: FB F7 23 F6             NOT DIRB
    00000004:                         lp:
    00000004: FD FB 23 F6             NOT _OUTB
    00000008: 25 26 80 FF 28 80 66 FD WAITX #20_000_000/4
    00000010: F0 FF 9F FD             jmp lp
    00000014:                         R5 EQU 5
    00000014: 00 00 80 FF 28 FC 67 FD WAITX #510
    0000001C: 28 0A 60 FD             WAITX R5
    
    
    

  • jmg

    L = 0 Register
    L = 1 Immediate

    If immediate >$1ff then prefixed with AUGS instruction
    	waitx	$123
    
    would generate bytes 28 46 62 FD
    
    
  • jmgjmg Posts: 15,173
    ok, this macro is the result :
    ;  1098 7654321 09 8 765432109
    ;  CCCC 1101011 00 L DDDDDDDDD  0001010ff  WAITX   L = 0 Register  L = 1 Immediate
    
    macro WAITX? ParS*&  ;
        F2_ZC_S ParS  
        pV = ParS   ; force numeric eval
        match #data, ParS  
            if pV > 0x1ff  
              dd (pV shr 9) + 0xff800000  ; upper bits to 1's , for AUGS 
              dd gZCS + (1101011_00_1b shl 18) + (pV and 0x1ff) shl 9 + 000101000b
            else
              dd gZCS + (1101011_00_1b shl 18) + (pV and 0x1ff) shl 9 + 000101000b
            end if      
        else    
            dd gZCS + (1101011_00_0b shl 18) + (pV and 0x1ff) shl 9 + 000101000b
        end match    
    end macro 
    
    ;00000000: FB F7 23 F6             NOT DIRB               OK
    ;00000004:                         lp:
    ;00000004: FD FB 23 F6             NOT OUTB               OK
    ;00000008: 25 26 80 FF 28 80 66 FD WAITX 20_000_000/4     OK 
    ;00000010: F0 FF 9F FD             jmp lp   - need F0 FF 9F FD fix with +4
    
    ;00000014: 28 FC 67 FD             WAITX #510
    ;00000018: 28 0A 60 FD             WAITX R5
    ;0000001C: 28 46 66 FD             WAITX #$123
    ;00000020: 28 46 62 FD             WAITX $123 $123 would generate bytes 28 46 62 FD   OK
    
    
Sign In or Register to comment.