clarify cr 16-bit
[libreriscv.git] / openpower / sv / 16_bit_compressed.mdwn
index b9ba2a901e27a8631c27edf8947268f061cb54df..5e3fc79e81d11b793b1673c0909d1b1ed3487515 100644 (file)
@@ -72,7 +72,7 @@ in 10-bit mode, and M and N in 16-bit mode.
 
 Once in 16-bit mode:
 
-* 0b01: stay in 16-bit mode
+* 0b01 (M=1, N=0): stay in 16-bit mode
 * 0b00: leave 16-bit mode permanently (return to standard OpenPOWER ISA)
 * 0b10: leave 16-bit mode for one cycle (return to standard OpenPOWER ISA)
 * 0b11: free to be used for something completely different.
@@ -81,41 +81,84 @@ The current "top" idea for 0b11 is to use it for a new encoding format
 of predominantly "immediates-based" 16-bit instructions (branch-conditional,
 addi, mulli etc.)
 
+* The Compressed Major Opcode is in bits 5-7.
+* Minor opcode in bit 8.
+* In some cases bit 9 is taken as an additional sub-opcode, followed
+  by bits 0-4 (for CR operations)
+* M+N mode-switching is not available for C-Major 0b001 or 0b111
+* 10 bit mode may be expanded by 16 bit mode, adding capabilities
+  that do not fit in the extreme limited space.
+
+### Immediate Opcodes
+
+only available in 16-bit mode, and only available when M=1 and N=1
+
+    | 0 | 1  | 2 3 4 | | 567.8 | 9ab  | c d e | f |
+    | 1 | o2 |  RT   | | 010.0 | RB|0 | offs  | 1 | addi.
+    | 1 | o2 |  RT   | | 010.1 | RB|0 | offs  | 1 | addis.
+    | 1 | o2         | | 011.0 | RB   | offs  | 1 | cmpdi
+    | 1 | o2         | | 011.1 | RB   | offs  | 1 | cmpwi
+    | 1 | o2         | | 100.0 | RT   | offs  | 1 | sti
+    | 1 | o2         | | 100.1 | RT   | offs  | 1 | fstwi
+    | 1 | o2         | | 101.0 | RA   | offs  | 1 | ldi
+    | 1 | o2         | | 101.1 | RA   | offs  | 1 | lwi
+    | 1 | o2         | | 110.0 | RA   | offs  | 1 | flwi
+    | 1 | o2         | | 110.1 | RA   | offs  | 1 | fldi
+
+* Note that bc is included (below)
+* immediate is constructed from offs (LSBs) and o2 (MSB)
+* for LD/ST, offset is aligned.  8-byte: o2||offs||0b000 4-byte: 0b00
+* SV Prefix over-rides help provide alternative bitwidths for LD/ST
+* RB|0 if RB is zero, addi. becomes "li" (this only works if RT takes
+  part of opcode).
+
 ### Branch
 
-10 bit mode may be expanded by 16 bit mode later, adding capabilities
-that do not fit in the extreme limited space.
+Note that illeg and nop are all zeros, including in the 16-bit mode.
+Given that C is allocated to OpenPOWER ISA Major opcodes EXT000 and
+EXT001 this ensures that in both 10-bit *and* 16-bit mode, a 16-bit
+run of all zeros is considered "illegal" whilst 0b0000.0000.1000.0000
+is "nop"
 
-    | 16-bit mode | | 10-bit mode              |
-    | 0 1 | 2 3 4 | | 567 | 8 9 a | b c d | e  | f |
-    |   offs2     | | 000 |    offs       | LK | M | b
-    | BO2 | BI3   | | 001 | 0  BI | 0  BO | LK | M | bclr
-    | BO2 | BI3   | | 001 | 0  BI | 1  BO | LK | M | bctar
+    | 16-bit mode | | 10-bit mode                 |
+    | 0 | 1 | 234 | | 567.8  | 9  ab | c   de | f |
+    | 0 | 0   000 | | 000.0  | 0  00 | 0   00 | 0 | illeg
+    | 0 | 0   000 | | 000.1  | 0  00 | 0   00 | 0 | nop
+    | N | offs2   | | 000.LK | offs!=0        | M | b, bl
+    | 1 | offs2   | | 000.LK | BI    | BO1 oo | 1 | bc, bcl
+    | N | BO3 BI3 | | 001.0  | LK BI | BO     | M | bclr, bclrl
 
 16 bit mode:
 
+* bc only available when N,M=0b11
 * offs2 extends offset in MSBs
 * BI3 extends BI in MSBs to allow selection of full CR
-* BO2 extends BO
+* BO3 extends BO
+* bc offset constructed from oo as LSBs and offs2 as MSBs
+* bc BI allows selection of all bits from CR0 or CR1
+* bc CR check is always active (as if BO0=1) therefore BO1 inverts
 
 10 bit mode:
 
+* illegal (all zeros) covers part of branch (offs=0,M=0,LK=0)
+* nop also covers part of branch (offs=0,M=0,LK=1)
+* bc **not available** in 10-bit mode
 * BO[0] enables CR check, BO[1] inverts check
 * BI refers to CR0 only (4 bits of)
 * no Branch Conditional with immediate
 * no Absolute Address
-* no CTR mode (and no bctr)
+* CTR mode allowed with BO[2] for b only.
 * offs is to 2 byte (signed) aligned
 * all branches to 2 byte aligned
 
 ### LD/ST
 
-    | 16-bit mode       | | 10-bit mode             |
-    | 0   | 1   | 2 3 4 | | 567 | 8 9 a | b c d | e | f |
-    | RB2 | RA2 |  RT   | | 001 | 1  RA | 1  RB | 0 | M | fld
-    | RA2 | RT2 |  RB   | | 001 | 1  RA | 1  RT | 1 | M | fst
-    |     |     |  RT   | | 111 |  RA   |  RB   | 0 | M | ld
-    |     |     |  RB   | | 111 |  RA   |  RT   | 1 | M | st
+    | 16-bit mode       | | 10-bit mode               |
+    | 0   | 1   | 2 3 4 | | 567.8 | 9 a b | c d e | f |
+    | RB2 | RA2 |  RT   | | 001.1 | 1  RA | 0  RB | M | fld
+    | RA2 | RT2 |  RB   | | 001.1 | 1  RA | 1  RT | M | fst
+    |     |     |  RT   | | 111.0 |  RA   |  RB   | M | ld
+    |     |     |  RB   | | 111.1 |  RA   |  RT   | M | st
 
 * elwidth overrides can set different widths
 
@@ -134,11 +177,13 @@ that do not fit in the extreme limited space.
 ### Arithmetic
 
     | 16-bit mode   | | 10-bit mode             |
-    | 0 | 1 | 2 3 4 | | 567 | 8 9 a | b c d | e | f |
-    | N |   |  RT   | | 010 | RB    | RA!=0 | 0 | M | add
-    | N |   |  RT   | | 011 | RB    | RA!=0 | 0 | M | sub.
-    | N |   |  RT   | | 010 | RB    | RA    | 1 | M | mul
-    | N |   |  RT   | | 011 | RB    | 0 0 0 | 0 | M | neg.
+    | 0 | 1 | 2 3 4 | | 567.8 | 9ab | c d e | f |
+    | N |   |  RT   | | 010.0 | RB  | RA!=0 | M | add
+    | N |   |  RT   | | 010.1 | RB  | RA    | M | mul
+    | N |   | RT!=0 | | 011.0 | RB  | RA!=0 | M | sub.
+    | N | 0 | 000   | | 011.0 | RB  | RA!=0 | M | cmpw
+    | N | 1 | 000   | | 011.0 | RB  | RA!=0 | M | cmpl
+    | N |   |  RT   | | 011.0 | RB  | 000   | M | neg.
 
 10 bit mode:
 
@@ -146,19 +191,33 @@ that do not fit in the extreme limited space.
 * for (RA|0) when RA=0 the input is a zero immediate,
   meaning that sub. becomes neg.
 * RT is implicitly RB: "add RT(=RB), RA, RB"
+* Opcode 0b010.0 RA=0 is not missing from the above:
+  it is a system-wide instruction, "cbank" (section below)
 
 ### Logical
 
     | 16-bit mode   | | 10-bit mode             |
-    | 0 | 1 | 2 3 4 | | 567 | 8 9 a | b c d | e | f |
-    | N |   |  RT   | | 100 | RB    | RA!=0 | 0 | M | and
-    | N |   |  RT   | | 100 | RB    | RA!=0 | 1 | M | nand
-    | N |   |  RT   | | 101 | RB    | RA!=0 | 0 | M | or
-    | N |   |  RT   | | 101 | RB    | RA!=0 | 1 | M | nor
-    | N |   |  RT   | | 100 | RB    | 0 0 0 | 0 | M | exts
-    | N |   |  RT   | | 100 | RB    | 0 0 0 | 1 | M | cntlz
-    | N |   |  RT   | | 101 | RB    | 0 0 0 | 0 | M | popcnt
-    | N |   |  RT   | | 101 | RB    | 0 0 0 | 1 | M | not
+    | 0 | 1 | 2 3 4 | | 567.8 | 9ab | c d e | f |
+    | N | 0 |  RT   | | 100.0 | RB  | RA!=0 | M | and
+    | N | 0 |  RT   | | 100.1 | RB  | RA!=0 | M | nand
+    | N | 0 |  RT   | | 101.0 | RB  | RA!=0 | M | or
+    | N | 0 |  RT   | | 101.1 | RB  | RA!=0 | M | nor
+    | N | 0 |  RT   | | 100.0 | RB  | 0 0 0 | M | extsw
+    | N | 0 |  RT   | | 100.1 | RB  | 0 0 0 | M | cntlz
+    | N | 0 |  RT   | | 101.0 | RB  | 0 0 0 | M | popcnt
+    | N | 0 |  RT   | | 101.1 | RB  | 0 0 0 | M | not
+
+16-bit mode only:
+
+    | 0 | 1 | 2 3 4 | | 567.8 | 9ab | c d e | f |
+    | N | 1 |  RT   | | 100.0 | RB  | RA!=0 | M |
+    | N | 1 |  RT   | | 100.1 | RB  | RA!=0 | M |
+    | N | 1 |  RT   | | 101.0 | RB  | RA!=0 | M | xor
+    | N | 1 |  RT   | | 101.1 | RB  | RA!=0 | M | eqv (xnor)
+    | N | 1 |  RT   | | 100.0 | RB  | 0 0 0 | M | extsb
+    | N | 1 |  RT   | | 100.1 | RB  | 0 0 0 | M | cnttz
+    | N | 1 |  RT   | | 101.0 | RB  | 0 0 0 | M |
+    | N | 1 |  RT   | | 101.1 | RB  | 0 0 0 | M | extsh
 
 10 bit mode:
 
@@ -169,15 +228,26 @@ that do not fit in the extreme limited space.
 
 ### Floating Point
 
+Note here that elwidth overrides (SV Prefix) can be used to select FP16/32/64
+
     | 16-bit mode   | | 10-bit mode             |
-    | 0 | 1 | 2 3 4 | | 567 | 8 9 a | b c d | e | f |
-    | N |   |  RT   | | 011 | RB    | RA!=0 | 1 | M | fsub.
-    | N |   |  RT   | | 110 | RB    | RA!=0 | 0 | M | fadd
-    | N | 0 |  RT   | | 110 | RB    | RA!=0 | 1 | M | fmul
-    | N | 1 |  RT   | | 110 | RB    | RA!=0 | 1 | M | fdiv
-    | N |   |  RT   | | 011 | RB    | 0 0 0 | 1 | M | fneg.
-    | N |   |  RT   | | 110 | RB    | 0 0 0 | 0 | M | fabs
-    | N |   |  RT   | | 110 | RB    | 0 0 0 | 1 | M | fmr.
+    | 0 | 1 | 2 3 4 | | 567.8 | 9ab | c d e | f |
+    | N |   |  RT   | | 011.1 | RB  | RA!=0 | M | fsub.
+    | N | 0 |  RT   | | 110.0 | RB  | RA!=0 | M | fadd
+    | N | 0 |  RT   | | 110.1 | RB  | RA!=0 | M | fmul
+    | N | 0 |  RT   | | 011.1 | RB  | 0 0 0 | M | fneg.
+    | N | 0 |  RT   | | 110.0 | RB  | 0 0 0 | M |
+    | N | 0 |  RT   | | 110.1 | RB  | 0 0 0 | M |
+
+16-bit mode only:
+
+    | 0 | 1 | 2 3 4 | | 567.8 | 9ab | c d e | f |
+    | N | 1 |  RT   | | 011.1 | RB  | RA!=0 | M |
+    | N | 1 |  RT   | | 110.0 | RB  | RA!=0 | M |
+    | N | 1 |  RT   | | 110.1 | RB  | RA!=0 | M | fdiv
+    | N | 1 |  RT   | | 011.1 | RB  | 0 0 0 | M | fabs.
+    | N | 1 |  RT   | | 110.0 | RB  | 0 0 0 | M | fmr.
+    | N | 1 |  RT   | | 110.1 | RB  | 0 0 0 | M |
 
 10 bit mode:
 
@@ -191,22 +261,22 @@ that do not fit in the extreme limited space.
 
 ### Condition Register
 
-    | 16-bit mode   | | 10-bit mode           |
-    | 0 1 2 3 | 4   | | 567 | 8 9 a | b c d e | f |
-    | 0 0 0 0 | BF2 | | 001 | 1  BF | 0  BFA  | M | mcrf
-    | 0 0 0 1 | BA2 | | 001 | 1  BA | 0  BB   | M | crnor
-    | 0 1 0 0 | BA2 | | 001 | 1  BA | 0  BB   | M | crandc
-    | 0 1 1 0 | BA2 | | 001 | 1  BA | 0  BB   | M | crxor
-    | 0 1 1 1 | BA2 | | 001 | 1  BA | 0  BB   | M | crnand
-    | 1 0 0 0 | BA2 | | 001 | 1  BA | 0  BB   | M | crand
-    | 1 0 0 1 | BA2 | | 001 | 1  BA | 0  BB   | M | creqv
-    | 1 1 0 1 | BA2 | | 001 | 1  BA | 0  BB   | M | crorc
-    | 1 1 1 0 | BA2 | | 001 | 1  BA | 0  BB   | M | cror
+    | 16-bit mode   | | 10-bit mode            |
+    | 0 1 2 3 | 4   | | 567.8 | 9 ab | cde | f |
+    | 0 0 0 0 | BF2 | | 001.1 | 0 BF | BFA | M | mcrf
+    | 0 0 0 1 | BA2 | | 001.1 | 0 BA | BB  | M | crnor
+    | 0 1 0 0 | BA2 | | 001.1 | 0 BA | BB  | M | crandc
+    | 0 1 1 0 | BA2 | | 001.1 | 0 BA | BB  | M | crxor
+    | 0 1 1 1 | BA2 | | 001.1 | 0 BA | BB  | M | crnand
+    | 1 0 0 0 | BA2 | | 001.1 | 0 BA | BB  | M | crand
+    | 1 0 0 1 | BA2 | | 001.1 | 0 BA | BB  | M | creqv
+    | 1 1 0 1 | BA2 | | 001.1 | 0 BA | BB  | M | crorc
+    | 1 1 1 0 | BA2 | | 001.1 | 0 BA | BB  | M | cror
 
 10 bit mode:
 
 * mcrf BF is only 2 bits which means the destination is only CR0-CR3
-* CR operations: **not available** in 10-bit mode
+* CR operations: **not available** in 10-bit mode (but mcrf is)
 
 16 bit mode:
 
@@ -220,33 +290,34 @@ SV (Vector Mode):
 
 ### System
 
-Selection of Compressed-encoding "Bank".  Different "banks" give different
-meanings to opcodes.  Example: CBank=0b001 is heavily optimised to A/Video
+cbank: Selection of Compressed-encoding "Bank".  Different "banks" give different
+meanings to opcodes.
+Example: CBank=0b001 is heavily optimised to A/Video
 Encode/Decode.
 
-    | 16-bit mode | | 10-bit mode             |
-    | 0 1 | 2 3 4 | | 567 | 8 9 a | b c d | e | f |
-    |       Bank2 | | 010 | CBank | 0 0 0 | 0 | M | cbank
+    | 16-bit mode | | 10-bit mode               |
+    | 0 | 1 2 3 4 | | 567.8 | 9 a b | c d e | f |
+    | N |   Bank2 | | 010.0 | CBank | 0 0 0 | M | cbank
 
 **not available** in 10-bit mode:
 
-    | 0 1 2 3 | 4  | | 567 | 8 9 a | b c d e  | f |
-    | 1 1 1 1 | 0  | | 001 | 1  00 | 0  RT    | M | mtlr
-    | 1 1 1 1 | 0  | | 001 | 1  01 | 0  RT    | M | mtctr
-    | 1 1 1 1 | 0  | | 001 | 1  10 | 0  RT    | M | mttar
-    | 1 1 1 1 | 0  | | 001 | 1  11 | 0  RT    | M | mtcr
-    | 1 1 1 1 | 1  | | 001 | 1  00 | 0  RA    | M | mflr
-    | 1 1 1 1 | 1  | | 001 | 1  01 | 0  RA    | M | mfctr
-    | 1 1 1 1 | 1  | | 001 | 1  10 | 0  RA    | M | mftar
-    | 1 1 1 1 | 1  | | 001 | 1  11 | 0  RA    | M | mfcr
+    | 0 1 2 3 | 4  | | 567.8 | 9 ab | c d e  | f |
+    | 1 1 1 1 | 0  | | 001.1 | 0 00 |  RT    | M | mtlr
+    | 1 1 1 1 | 0  | | 001.1 | 0 01 |  RT    | M | mtctr
+    | 1 1 1 1 | 0  | | 001.1 | 0 11 |  RT    | M | mtcr
+    | 1 1 1 1 | 1  | | 001.1 | 0 00 |  RA    | M | mflr
+    | 1 1 1 1 | 1  | | 001.1 | 0 01 |  RA    | M | mfctr
+    | 1 1 1 1 | 1  | | 001.1 | 0 11 |  RA    | M | mfcr
 
 ### Unallocated
 
-    | 0 1 2 3 | 4  | | 567 | 8 9 a | b c d e  | f |
-    | 0 0 1 0 |    | | 001 | 1     | 0        | M |
-    | 0 0 1 1 |    | | 001 | 1     | 0        | M |
-    | 0 1 0 1 |    | | 001 | 1     | 0        | M |
-    | 1 0 1 0 |    | | 001 | 1     | 0        | M |
-    | 1 0 1 1 |    | | 001 | 1     | 0        | M |
-    | 1 1 0 0 |    | | 001 | 1     | 0        | M |
+    | 0 1 2 3 | 4  | | 567.8 | 9 ab | c d e  | f |
+    | 0 0 1 0 |    | | 001.1 | 0    |        | M |
+    | 0 0 1 1 |    | | 001.1 | 0    |        | M |
+    | 0 1 0 1 |    | | 001.1 | 0    |        | M |
+    | 1 0 1 0 |    | | 001.1 | 0    |        | M |
+    | 1 0 1 1 |    | | 001.1 | 0    |        | M |
+    | 1 1 0 0 |    | | 001.1 | 0    |        | M |
+    | 1 1 1 1 | 0  | | 001.1 | 0 10 |        | M |
+    | 1 1 1 1 | 1  | | 001.1 | 0 10 |        | M |