Commit ff94de3
committed
Vectorize the bitmap-container word operations, fusing the cardinality pass
The bitmap-container boolean operations wrote their result with a plain Go
loop over 1024 words and then made a second pass to count it. Add six word
helpers -- orSlice, andSlice, xorSlice, andNotSlice, and the orCardSlice and
andCardSlice variants that also return the population count via VPOPCNTQ --
and use them to replace eight hand-written loops in bitmapcontainer.go.
orBitmap, iorBitmap and iandBitmap now make a single fused pass. andBitmap,
xorBitmap, ixorBitmap, andNotBitmap and iandNotBitmapSurely need the
cardinality before choosing a bitmap or array result, so they keep the
count-first shape and only their write loop is vectorized. lazyIORBitmap and
lazyORBitmap lose their manual four-way unroll.
dst may alias either source: sources are loaded before the destination is
stored within an iteration, which is what the in-place operations rely on.
One 8 KB container on a Xeon Gold 6548N:
write only 599 ns -> 52 ns (11.5x)
write + cardinality 631 ns -> 115 ns (5.5x)
Two bitmaps of 64 dense bitmap containers:
Or 152985 ns -> 90806 ns (1.68x)
AndNot 153366 ns -> 105304 ns (1.46x)
And 152147 ns -> 105404 ns (1.44x)
Xor 151482 ns -> 105158 ns (1.44x)
The end-to-end gap is allocation: each operation allocates 64 fresh 8 KB
containers.
Claude-Session: https://claude.ai/code/session_0123ePBefqPjrCvhxdwWFakj1 parent 92bd7e5 commit ff94de3
8 files changed
Lines changed: 721 additions & 49 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
562 | 562 | | |
563 | 563 | | |
564 | 564 | | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
| 565 | + | |
569 | 566 | | |
570 | 567 | | |
571 | 568 | | |
| |||
601 | 598 | | |
602 | 599 | | |
603 | 600 | | |
604 | | - | |
605 | | - | |
606 | | - | |
607 | | - | |
608 | | - | |
| 601 | + | |
609 | 602 | | |
610 | 603 | | |
611 | 604 | | |
| |||
654 | 647 | | |
655 | 648 | | |
656 | 649 | | |
657 | | - | |
658 | | - | |
659 | | - | |
660 | | - | |
661 | | - | |
662 | | - | |
663 | | - | |
664 | | - | |
665 | | - | |
666 | | - | |
| 650 | + | |
667 | 651 | | |
668 | 652 | | |
669 | 653 | | |
| |||
674 | 658 | | |
675 | 659 | | |
676 | 660 | | |
677 | | - | |
678 | | - | |
679 | | - | |
680 | | - | |
681 | | - | |
682 | | - | |
683 | | - | |
684 | | - | |
685 | | - | |
686 | | - | |
687 | | - | |
| 661 | + | |
688 | 662 | | |
689 | 663 | | |
690 | 664 | | |
| |||
744 | 718 | | |
745 | 719 | | |
746 | 720 | | |
747 | | - | |
748 | | - | |
749 | | - | |
| 721 | + | |
750 | 722 | | |
751 | 723 | | |
752 | 724 | | |
| |||
868 | 840 | | |
869 | 841 | | |
870 | 842 | | |
871 | | - | |
872 | | - | |
873 | | - | |
| 843 | + | |
874 | 844 | | |
875 | 845 | | |
876 | 846 | | |
| |||
901 | 871 | | |
902 | 872 | | |
903 | 873 | | |
904 | | - | |
905 | | - | |
906 | | - | |
907 | | - | |
| 874 | + | |
908 | 875 | | |
909 | 876 | | |
910 | 877 | | |
| |||
938 | 905 | | |
939 | 906 | | |
940 | 907 | | |
941 | | - | |
942 | | - | |
943 | | - | |
| 908 | + | |
944 | 909 | | |
945 | 910 | | |
946 | 911 | | |
| |||
1064 | 1029 | | |
1065 | 1030 | | |
1066 | 1031 | | |
1067 | | - | |
1068 | | - | |
1069 | | - | |
| 1032 | + | |
1070 | 1033 | | |
1071 | 1034 | | |
1072 | 1035 | | |
| |||
1077 | 1040 | | |
1078 | 1041 | | |
1079 | 1042 | | |
1080 | | - | |
1081 | | - | |
1082 | | - | |
| 1043 | + | |
1083 | 1044 | | |
1084 | 1045 | | |
1085 | 1046 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
0 commit comments