comments on popcount
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 29 May 2020 21:33:46 +0000 (22:33 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 29 May 2020 21:33:46 +0000 (22:33 +0100)
src/soc/fu/logical/popcount.py

index 6f47300b41ada8c87701890cacc16d81dd4d923d..d655b551f7ed463b3354bf6c93f3028915a157e7 100644 (file)
@@ -27,7 +27,7 @@ class Popcount(Elaboratable):
         pc = [a]
         # QTY32 2-bit (to take 2x 1-bit sums) etc.
         work = [(32, 2), (16, 3), (8, 4), (4, 5), (2, 6), (1, 7)]
-        for l, bw in work:
+        for l, bw in work: # l=number of add-reductions, bw=bitwidth
             pc.append(array_of(l, bw))
         pc8 = pc[3]     # array of 8 8-bit counts (popcntb)
         pc32 = pc[5]    # array of 2 32-bit counts (popcntw)
@@ -39,17 +39,17 @@ class Popcount(Elaboratable):
                 src, dst = pc[idx], pc[idx+1]
                 comb += dst[i].eq(Cat(src[stt], Const(0, 1)) +
                                   Cat(src[end], Const(0, 1)))
-        # decode operation length
+        # decode operation length (1-hot)
         with m.If(data_len == 1):
-            # popcntb - pack 8x 4-bit answers into output
+            # popcntb - pack 8x 4-bit answers into 8x 8-bit output fields
             for i in range(8):
                 comb += o[i*8:(i+1)*8].eq(pc8[i])
         with m.Elif(data_len == 4):
-            # popcntw - pack 2x 5-bit answers into output
+            # popcntw - pack 2x 5-bit answers into 2x 32-bit output fields
             for i in range(2):
                 comb += o[i*32:(i+1)*32].eq(pc32[i])
         with m.Else():
-            # popcntd - put 1x 6-bit answer into output
+            # popcntd - put 1x 6-bit answer into 64-bit output
             comb += o.eq(popcnt[0])
 
         return m