[WIP] Add twin-butterfly proposed insn
[libreriscv.git] / openpower / sv / twin_butterfly.mdwn
1 <https://bugs.libre-soc.org/show_bug.cgi?id=1074>
2
3 # [DRAFT] Twin Butterfly DCT Instruction(s)
4
5 The goal is to implement instructions that calculate the expression:
6
7 ```
8 fdct_round_shift((a +/- b) * c)
9 ```
10
11 For the single-coefficient butterfly instruction, and:
12
13 ```
14 fdct_round_shift(a * c1 +/- b * c2)
15 ```
16
17 For the double-coefficient butterfly instruction.
18
19 `fdct_round_shift` is defined as `ROUND_POWER_OF_TWO(x, 14)`
20
21 ```
22 #define ROUND_POWER_OF_TWO(value, n) (((value) + (1 << ((n)-1))) >> (n))
23 ```
24
25 The suggestion is to have a single instruction to calculate both values `((a + b) * c) >> N`, and `((a - b) * c) >> N`.
26 The instruction will run in accumulate mode, so in order to calculate the 2-coeff version one would just have to call the same instruction with different order a, b and a different constant c.
27
28 ```
29 # [DRAFT] Integer Butterfly Multiply Add/Sub FFT/DCT
30
31 BF-Form
32
33 * maddsubrs RT,RA,RB,RC,SH
34
35 Pseudo-code:
36
37 RT2 <- RT + 1
38 sum <- (RA) + (RB)
39 diff <- (RA) - (RB)
40 prod1 <- MUL(RC, sum)
41 prod2 <- MUL(RC, diff)
42 res1 <- ROTL64(prod1, SH)
43 res2 <- ROTL64(prod2, SH)
44 RT <- (RT) + res1
45 RT2 <- (RT2) + res2
46
47 Special Registers Altered:
48
49 None
50 ```
51
52 Where BF-Form is defined in fields.txt:
53
54 ```
55 # 1.6.39 BF-FORM
56 |0 | 6 |11 |16 |21 | 25 |30 |31 |
57 | PO | RT | RA | RB | RC | SH | XO | Rc |
58
59 ```
60
61 The resulting autogenerated code is:
62
63 ```
64 class butterfly:
65 @inject()
66 def op_maddsubrs(self, RA, RB, RC, RT):
67 RT2 = copy_assign_rhs(RT + 1)
68 sum = copy_assign_rhs(RA + RB)
69 diff = copy_assign_rhs(RA - RB)
70 prod1 = copy_assign_rhs(self.MUL(RC, sum))
71 prod2 = copy_assign_rhs(self.MUL(RC, diff))
72 res1 = copy_assign_rhs(self.ROTL64(prod1, SH))
73 res2 = copy_assign_rhs(self.ROTL64(prod2, SH))
74 RT = copy_assign_rhs(RT + res1)
75 RT2 = copy_assign_rhs(RT2 + res2)
76 return (RT,)
77 ```
78
79 The instruction has been added to `minor_59.csv`:
80 ```
81 1111011111,ALU,OP_MADDSUBRS,RA,RB,RC,RT,NONE,CR1,0,0,ZERO,0,NONE,0,0,0,0,1,0,RC_ONLY,0,0,maddsubrs,A,,1,unofficial until submitted and approved/renumbered by the opf isa wg
82 ```
83