Update mac_5x9x8 Revised authored by gling's avatar gling
We have defined a KxMxN MAC unit as a device which takes K signed M-bit numbers ($a_0, a_1, ..., a_{K-1}$) and K signed N-bit numbers ($b_0, b_1, ..., b_{K-1}$), and computes $$a_0 \ast b_0 + a_1 \ast b_1 + ... + a_{K-1} \ast b_{K-1}$$ We have defined a KxMxN MAC unit as a device which takes K signed M-bit numbers ($a_0, a_1, ..., a_{K-1}$) and K signed N-bit numbers ($b_0, b_1, ..., b_{K-1}$), and computes $$a_0 \ast b_0 + a_1 \ast b_1 + ... + a_{K-1} \ast b_{K-1}$$
For making an KxMxN MAC unit, the number of output bits will be For making an KxMxN MAC unit, the number of output bits will be
$$\lceil\log_2(K * 2^M * 2^N)\rceil = \lceil\log_2 K\rceil + M + N$$ $$B = \lceil\log_2(K * 2^M * 2^N)\rceil = \lceil\log_2 K\rceil + M + N$$
For our specialized case of a 5x9x8 MAC unit, $\lceil\log_2 5\rceil + 9 + 8 = 20$ bits. For our specialized case of a 5x9x8 MAC unit, $\lceil\log_2 5\rceil + 9 + 8 = 20$ bits.
...@@ -24,7 +24,33 @@ p3[4:0] = a[4:0] * b[3] ...@@ -24,7 +24,33 @@ p3[4:0] = a[4:0] * b[3]
P[8] P[7] P[6] P[5] P[4] P[3] P[2] P[1] P[0] P[8] P[7] P[6] P[5] P[4] P[3] P[2] P[1] P[0]
``` ```
Now, to sum K products together, these products must be sign-extended to B bits, then summed.
Simply adding 1's to the constant addition correctly sign-extends the result to as many bits as needed.
In this case, if this multiply was a part of a 5x4x5 MAC unit, $\lceil\log_2(5)\rceil= 3$ ones will need to be prepended to the constant term.
Since there are no more sign extensions required, we can rewrite the entire 5x4x5 MAC unit as a single large array addition:
```
p00[4:0] = a0[4:0] * b0[0]
p01[4:0] = a0[4:0] * b0[1]
p02[4:0] = a0[4:0] * b0[2]
p03[4:0] = a0[4:0] * b0[3]
p00[4:0] = a0[4:0] * b0[0]
p01[4:0] = a0[4:0] * b0[1]
p02[4:0] = a0[4:0] * b0[2]
p03[4:0] = a0[4:0] * b0[3]
~p0[4] p0[3] p0[2] p0[1] p0[0]
~p0[4] p0[3] p0[2] p0[1] p0[0]
~p0[4] p0[3] p0[2] p0[1] p0[0]
p0[4] ~p0[3] ~p0[2] ~p0[1] ~p0[0]
+ 1 0 0 0 0 1 0 0 0
-------------------------------------------------------------------------------
P[8] P[7] P[6] P[5] P[4] P[3] P[2] P[1] P[0]
```
... ...
......