prepare assembler for warm-words, pospopcount
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 5 Dec 2023 14:36:42 +0000 (14:36 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 5 Dec 2023 14:36:46 +0000 (14:36 +0000)
openpower/sv/cookbook/pospopcnt.mdwn

index 2c9b6533bfd98dd0918f976b3d7f7c8fca97da2f..eb8c722bbe72faf75f69509a9796a0a861d348b5 100644 (file)
@@ -53,5 +53,43 @@ bit-position, of an array of input values.
 
 <img src="/openpower/sv/cookbook/2_popcount.svg " alt="pospopcnt" width="70%" />
 
+# Visual representation of the pospopcount algorithm
+
+# Walkthrough of the assembler
+
+```
+mtspr 9, 3"                # move r3 to CTR
+```
+
+```
+# VL = MIN(CTR,MAXVL=8), Rc=1 (CR0 set if CTR ends)
+setvl 3,0,8,0,1,1"         # set MVL=8, VL=MIN(MVL,CTR)
+```
+
+```
+# load VL bytes (update r4 addr) but compressed (dw=8)
+addi 6, 0, 0               # initialise all 64-bits of r6 to zero
+sv.lbzu/pi/dw=8 *6, 1(4)   # should be /lf here as well
+```
+
+```
+# gather performs the transpose (which gets us to positional..)
+gbbd 8,6
+```
+
+```
+# now those bits have been turned around, popcount and sum them
+setvl 0,0,8,0,1,1          # set MVL=VL=8
+sv.popcntd/sw=8 *24,*8     # do the (now transposed) popcount
+```
+
+```
+sv.add *16,*16,*24         # and accumulate in results
+```
+
+```
+# branch back if CTR still non-zero. works even though VL=8
+sv.bc/all 16, *0, -0x28   # reduce CTR by VL and stop if -ve
+```
 
 [[!tag svp64_cookbook ]]