(no commit message)
[libreriscv.git] / simple_v_extension / appendix.mdwn
index 24ae6ca71d826d609c7666ae56e0e11170a0dd84..d4a69b3529a925f146827c1de1449e46abd8cb65 100644 (file)
@@ -1,3 +1,5 @@
+[[!tag standards]]
+
 # Simple-V (Parallelism Extension Proposal) Appendix
 
 * Copyright (C) 2017, 2018, 2019 Luke Kenneth Casson Leighton
@@ -194,38 +196,52 @@ comprehensive in its effect on instructions.
 Branch operations are augmented slightly to be a little more like FP
 Compares (FEQ, FNE etc.), by permitting the cumulation (and storage)
 of multiple comparisons into a register (taken indirectly from the predicate
-table).  As such, "ffirst" - fail-on-first - condition mode can be enabled.
+table) and enhancing them to branch "consensually" depending on *multiple*
+tests.  "ffirst" - fail-on-first - condition mode can also be enabled,
+to terminate the comparisons early.
 See ffirst mode in the Predication Table section.
 
-There are two registers for the comparison operation, therefore there is
-the opportunity to associate two predicate registers.  The first is a
-"normal" predicate register, which acts just as it does on any other
-single-predicated operation: masks out elements where a bit is zero,
-applies an inversion to the predicate mask, and enables zeroing / non-zeroing
-mode.
-
-The second is utilised to indicate where the results of each comparison
-are to be stored, as a bitmask.  Additionally, the behaviour of the branch
-- when it occurs - may also be modified depending on whether the predicate
-"invert" and "zeroing" bits are set.
-
-* If "invert" is zero, and "zeroing" is zero, the branch will occur if and only
-  all tests pass
-* If "invert" is set and "zeroing" is zero, the branch will occur if all
-  tests *fail* (opposite of inv=0,zero=0)
-* If "invert" is zero, and "zeroing" is set, the branch will occur if
-  even *one* test passes
-* If "invert" is set and "zeroing" is set, the branch will occur if
-  even *one* test fails.
-
-This inversion capability covers AND, OR, NAND and NOR branching based
-on multiple element comparisons.  Note that unlike normal computer
-programming early-termination of chains of AND or OR conditional tests,
-the chain does *not* terminate early except if fail-on-first is set,
-and even then ffirst ends on the first data-dependent zero.  When ffirst
-mode is not set, *all* conditional element tests must be performed (and
-the result optionally stored in the result mask), with a "post-analysis"
-phase carried out which checks whether to branch.
+There are two registers for the comparison operation, therefore there
+is the opportunity to associate two predicate registers (note: not in
+the same way as twin-predication).  The first is a "normal" predicate
+register, which acts just as it does on any other single-predicated
+operation: masks out elements where a bit is zero, applies an inversion
+to the predicate mask, and enables zeroing / non-zeroing mode.
+
+The second (not to be confused with a twin-predication 2nd register)
+is utilised to indicate where the results of each comparison are to
+be stored, as a bitmask.  Additionally, the behaviour of the branch -
+when it occurs - may also be modified depending on whether the 2nd predicate's
+"invert" and "zeroing" bits are set.  These four combinations result
+in "consensual branches", cbranch.ifnone (NOR), cbranch.ifany (OR),
+cbranch.ifall (AND), cbranch.ifnotall (NAND).
+
+| invert | zeroing | description                 | operation | cbranch |
+| ------ | ------- | --------------------------- | --------- | ------- |
+| 0      | 0       | branch if all pass          | AND       | ifall   |
+| 1      | 0       | branch if one fails         | NAND      | ifnall  |
+| 0      | 1       | branch if one passes        | OR        | ifany   |
+| 1      | 1       | branch if all fail          | NOR       | ifnone  |
+
+This inversion capability covers AND, OR, NAND and NOR branching
+based on multiple element comparisons. Without the full set of four,
+it is necessary to have two-sequence branch operations: one conditional, one
+unconditional.
+
+Note that unlike normal computer programming, early-termination of chains
+of AND or OR conditional tests, the chain does *not* terminate early
+except if fail-on-first is set, and even then ffirst ends on the first
+data-dependent zero.  When ffirst mode is not set, *all* conditional
+element tests must be performed (and the result optionally stored in
+the result mask), with a "post-analysis" phase carried out which checks
+whether to branch.
+
+Note also that whilst it may seem excessive to have all four (because
+conditional comparisons may be inverted by swapping src1 and src2),
+data-dependent fail-on-first is *not* invertible and *only* terminates
+on first zero-condition encountered.  Additionally it may be inconvenient
+to have to swap the predicate registers associated with src1 and src2,
+because this involves a new VBLOCK Context.
 
 ### Standard Branch <a name="standard_branch"></a>
 
@@ -321,16 +337,20 @@ complex), this becomes:
 
     if pred_inversion:
         if pred_zeroing:
-            if result != 0:
+            # NOR
+            if result == 0:
                 goto branch
         else:
-            if result == 0:
+            # NAND
+            if (result & ps) != result:
                 goto branch
     else:
         if pred_zeroing:
-            if (result & ps) != result:
+            # OR
+            if result != 0:
                 goto branch
         else:
+            # AND
             if (result & ps) == result:
                 goto branch