(no commit message)
[libreriscv.git] / openpower / sv / twin_butterfly.mdwn
index 72a2552ec65541ebe96849f015e83884fb7f4019..a2a7b8d7f3e964fd63b350cb78a82c8e6dc77c52 100644 (file)
@@ -8,9 +8,14 @@
 * [[openpower/isa/svfparith]]
 * [[openpower/isa/svfixedarith]]
 * [[openpower/sv/rfc/ls016]]
-
 <!-- show -->
 
+Although best used with SVP64 REMAP these instructions may be used in a Scalar-only
+context to save considerably on DCT, DFT and FFT processing.  Whilst some hardware
+implementations may not necessarily implement them efficiently (slower Micro-coding)
+savings still come from the reduction in temporary registers as well as instruction
+count.
+
 # Rationale for Twin Butterfly Integer DCT Instruction(s)
 
 The number of general-purpose uses for DCT is huge. The number of
@@ -33,7 +38,7 @@ For the single-coefficient butterfly instruction, and:
 
 For the double-coefficient butterfly instruction.
 
-`fdct_round_shift` is defined as `ROUND_POWER_OF_TWO(x, 14)`
+In a 32-bit context `fdct_round_shift` is defined as `ROUND_POWER_OF_TWO(x, 14)`
 
 ```
     #define ROUND_POWER_OF_TWO(value, n) \
@@ -42,7 +47,7 @@ For the double-coefficient butterfly instruction.
 
 These instructions are at the core of **ALL** FDCT calculations in many
 major video codecs, including -but not limited to- VP8/VP9, AV1, etc.
-Arm includes special instructions to optimize these operations, although
+ARM includes special instructions to optimize these operations, although
 they are limited in precision: `vqrdmulhq_s16`/`vqrdmulhq_s32`.
 
 The suggestion is to have a single instruction to calculate both values
@@ -90,7 +95,6 @@ A-Form
 ```
     |0     |6     |11      |16     |21      |26    |31 |
     | PO   |  RT  |   RA   |   RB  |   SH   |   XO |Rc |
-
 ```
 
 * maddsubrs  RT,RA,SH,RB
@@ -101,19 +105,27 @@ Pseudo-code:
     n <- SH
     sum <- (RT) + (RA)
     diff <- (RT) - (RA)
-    prod1 <- MULS(RB, sum)[XLEN:(XLEN*2)-1] + 1
-    prod2 <- MULS(RB, diff)[XLEN:(XLEN*2)-1] + 1
-    res1 <- ROTL64(prod1, XLEN-n)
-    res2 <- ROTL64(prod2, XLEN-n)
-    m <- MASK(n, (XLEN-1))
-    signbit1 <- res1[0]
-    signbit2 <- res2[0]
-    smask1 <- ([signbit1]*XLEN) & ¬m
-    smask2 <- ([signbit2]*XLEN) & ¬m
-    s64_1 <- [0]*(XLEN-1) || signbit1
-    s64_2 <- [0]*(XLEN-1) || signbit2
-    RT <- (res1 & m | smask1) + s64_1
-    RS <- (res2 & m | smask2) + s64_2
+    prod1 <- MULS(RB, sum)
+    prod1_lo <- prod1[XLEN:(XLEN*2)-1]
+    prod2 <- MULS(RB, diff)
+    prod2_lo <- prod2[XLEN:(XLEN*2)-1]
+    if n = 0 then
+        RT <- prod1_lo
+        RS <- prod2_lo
+    else
+        round <- [0]*XLEN
+        round[XLEN -n] <- 1
+        prod1_lo <- prod1_lo + round
+        prod2_lo <- prod2_lo + round
+        m <- MASK(n, (XLEN-1))
+        res1 <- ROTL64(prod1_lo, XLEN-n) & m
+        res2 <- ROTL64(prod2_lo, XLEN-n) & m
+        signbit1 <- prod1_lo[0]
+        signbit2 <- prod2_lo[0]
+        smask1 <- ([signbit1]*XLEN) & ¬m
+        smask2 <- ([signbit2]*XLEN) & ¬m
+        RT <- (res1 | smask1)
+        RS <- (res2 | smask2)
 ```
 
 Note that if Rc=1 an Illegal Instruction is raised.  Rc=1 is `RESERVED`
@@ -133,12 +145,12 @@ Special Registers Altered:
 
 \newpage{}
 
-# Twin Butterfly Floating-Point DCT Instruction(s)
-
-## Floating-Point Twin Multiply-Add DCT [Single]
+# Twin Butterfly Floating-Point DCT and FFT Instruction(s)
 
 **Add the following to Book I Section 4.6.6.3**
 
+## Floating-Point Twin Multiply-Add DCT [Single]
+
 X-Form
 
 ```
@@ -171,13 +183,14 @@ operand in register FRB and the result stored in FRS.
 Using the exact same operand input register values from FRT and FRB
 that were used to create FRS, the Floating-Point operand in register
 FRB is subtracted from the floating-point operand in register FRT and
-the result then multiplied by FRA to create an intermediate result that
-is stored in FRT.
+the result then rounded before being multiplied by FRA to create an
+intermediate result that is stored in FRT.
 
 The add into FRS is treated exactly as `fadds`.  The creation of the
-result FRT is **not** the same as that of `fmsubs`.
-The creation of FRS and FRT are treated as parallel independent operations
-which occur at the same time.
+result FRT is **not** the same as that of `fmsubs`, but is instead as if
+`fsubs` were performed first followed by `fmuls`.  The creation of FRS
+and FRT are treated as parallel independent operations which occur at
+the same time.
 
 Note that if Rc=1 an Illegal Instruction is raised.  Rc=1 is `RESERVED`
 
@@ -196,8 +209,6 @@ Special Registers Altered:
 
 ## Floating-Point Multiply-Add FFT [Single]
 
-**Add the following to Book I Section 4.6.6.3**
-
 X-Form
 
 ```
@@ -230,7 +241,7 @@ stored in FRS.
 
 Using the exact same values of FRT, FRT and FRB as used to create
 FRS, the floating-point operand in register FRT is multiplied by the
-floating-point operand in register FRA. The floating-point operand
+floating-point operand in register FRA. The floating-point operand
 in register FRB is subtracted from this intermediate result, and the
 intermediate stored in FRT.
 
@@ -250,7 +261,6 @@ For SVP64 if `FRT` is a Vector, `FRS` begins immediately after the
 Vector `FRT` where the length of `FRT` is set by `SVSTATE.MAXVL`
 (Max Vector Length).
 
-
 Special Registers Altered:
 
 ```
@@ -258,9 +268,8 @@ Special Registers Altered:
     FX OX UX XX
     VXSNAN VXISI VXIMZ
 ```
-## Floating-Point Twin Multiply-Add DCT
 
-**Add the following to Book I Section 4.6.6.3**
+## Floating-Point Twin Multiply-Add DCT
 
 X-Form
 
@@ -294,13 +303,14 @@ operand in register FRB and the result stored in FRS.
 Using the exact same operand input register values from FRT and FRB
 that were used to create FRS, the Floating-Point operand in register
 FRB is subtracted from the floating-point operand in register FRT and
-the result then multiplied by FRA to create an intermediate result that
-is stored in FRT.
+the result then rounded before being multiplied by FRA to create an
+intermediate result that is stored in FRT.
 
 The add into FRS is treated exactly as `fadd`.  The creation of the
-result FRT is **not** the same as that of `fmsub`.
-The creation of FRS and FRT are treated as parallel independent operations
-which occur at the same time.
+result FRT is **not** the same as that of `fmsub`, but is instead as if
+`fsub` were performed first followed by `fmuls.  The creation of FRS
+and FRT are treated as parallel independent operations which occur at
+the same time.
 
 Note that if Rc=1 an Illegal Instruction is raised.  Rc=1 is `RESERVED`
 
@@ -319,8 +329,6 @@ Special Registers Altered:
 
 ## Floating-Point Twin Multiply-Add FFT
 
-**Add the following to Book I Section 4.6.6.3**
-
 X-Form
 
 ```
@@ -380,12 +388,16 @@ Special Registers Altered:
 ```
 
 
-## [DRAFT] Floating-Point Add FFT/DCT [Single]
+## Floating-Point Add FFT/DCT [Single]
 
 A-Form
 
+```
+    |0     |6     |11      |16     |21      |26    |31 |
+    | PO   | FRT  |  FRA   |  FRB  |     /  |   XO |Rc |
+```
+
 * ffadds FRT,FRA,FRB (Rc=0)
-* ffadds. FRT,FRA,FRB (Rc=1)
 
 Pseudo-code:
 
@@ -400,15 +412,18 @@ Special Registers Altered:
     FPRF FR FI
     FX OX UX XX
     VXSNAN VXISI
-    CR1          (if Rc=1)
 ```
 
-## [DRAFT] Floating-Point Add FFT/DCT [Double]
+## Floating-Point Add FFT/DCT [Double]
 
 A-Form
 
+```
+    |0     |6     |11      |16     |21      |26    |31 |
+    | PO   | FRT  |  FRA   |  FRB  |     /  |   XO |Rc |
+```
+
 * ffadd FRT,FRA,FRB (Rc=0)
-* ffadd. FRT,FRA,FRB (Rc=1)
 
 Pseudo-code:
 
@@ -423,15 +438,18 @@ Special Registers Altered:
     FPRF FR FI
     FX OX UX XX
     VXSNAN VXISI
-    CR1          (if Rc=1)
 ```
 
-## [DRAFT] Floating-Point Subtract FFT/DCT [Single]
+## Floating-Point Subtract FFT/DCT [Single]
 
 A-Form
 
+```
+    |0     |6     |11      |16     |21      |26    |31 |
+    | PO   | FRT  |  FRA   |  FRB  |     /  |   XO |Rc |
+```
+
 * ffsubs FRT,FRA,FRB (Rc=0)
-* ffsubs. FRT,FRA,FRB (Rc=1)
 
 Pseudo-code:
 
@@ -446,15 +464,18 @@ Special Registers Altered:
     FPRF FR FI
     FX OX UX XX
     VXSNAN VXISI
-    CR1          (if Rc=1)
 ```
 
-## [DRAFT] Floating-Point Subtract FFT/DCT [Double]
+## Floating-Point Subtract FFT/DCT [Double]
 
 A-Form
 
+```
+    |0     |6     |11      |16     |21      |26    |31 |
+    | PO   | FRT  |  FRA   |  FRB  |     /  |   XO |Rc |
+```
+
 * ffsub FRT,FRA,FRB (Rc=0)
-* ffsub. FRT,FRA,FRB (Rc=1)
 
 Pseudo-code:
 
@@ -469,5 +490,4 @@ Special Registers Altered:
     FPRF FR FI
     FX OX UX XX
     VXSNAN VXISI
-    CR1          (if Rc=1)
 ```