zeroshade commented on code in PR #13768:
URL: https://github.com/apache/arrow/pull/13768#discussion_r936849193
##########
go/arrow/bitutil/bitmaps.go:
##########
@@ -422,3 +423,81 @@ func CopyBitmap(src []byte, srcOffset, length int, dst
[]byte, dstOffset int) {
dst[nbytes-1] &= ^trailMask
dst[nbytes-1] |= lastData & trailMask
}
+
+type bitOp struct {
+ opWord func(uint64, uint64) uint64
+ opByte func(byte, byte) byte
+}
+
+var (
+ bitAndOp = bitOp{
+ opWord: func(l, r uint64) uint64 { return l & r },
+ opByte: func(l, r byte) byte { return l & r },
+ }
+ bitOrOp = bitOp{
+ opWord: func(l, r uint64) uint64 { return l | r },
+ opByte: func(l, r byte) byte { return l | r },
+ }
+)
+
+func alignedBitmapOp(op bitOp, left, right []byte, lOffset, rOffset int64, out
[]byte, outOffset int64, length int64) {
+ debug.Assert(lOffset%8 == rOffset%8, "aligned bitmap op called with
unaligned offsets")
+ debug.Assert(lOffset%8 == outOffset%8, "aligned bitmap op called with
unaligned output offset")
+
+ nbytes := BytesForBits(length + lOffset%8)
+ left = left[lOffset/8:]
+ right = right[rOffset/8:]
+ out = out[outOffset/8:]
+ for i := int64(0); i < nbytes; i++ {
+ out[i] = op.opByte(left[i], right[i])
+ }
+}
+
+func unalignedBitmapOp(op bitOp, left, right []byte, lOffset, rOffset int64,
out []byte, outOffset int64, length int64) {
+ leftRdr := NewBitmapWordReader(left, int(lOffset), int(length))
+ rightRdr := NewBitmapWordReader(right, int(rOffset), int(length))
+ writer := NewBitmapWordWriter(out, int(outOffset), int(length))
+
+ for nwords := leftRdr.Words(); nwords > 0; nwords-- {
+ writer.PutNextWord(op.opWord(leftRdr.NextWord(),
rightRdr.NextWord()))
Review Comment:
Before:
```
goos: linux
goarch: amd64
pkg: github.com/apache/arrow/go/v10/arrow/bitutil
cpu: 12th Gen Intel(R) Core(TM) i7-12700H
BenchmarkBitmapAnd/nbytes=32768/aligned-20 25418 48190
ns/op 1359.95 MB/s 0 B/op 0 allocs/op
BenchmarkBitmapAnd/nbytes=32768/unaligned-20 29241
40694 ns/op 1610.46 MB/s 192 B/op 3 allocs/op
BenchmarkBitmapAnd/nbytes=131072/aligned-20 6798
194915 ns/op 1344.91 MB/s 0 B/op 0 allocs/op
BenchmarkBitmapAnd/nbytes=131072/unaligned-20 7018
162163 ns/op 1616.55 MB/s 192 B/op 3 allocs/op
```
After:
```
goos: linux
goarch: amd64
pkg: github.com/apache/arrow/go/v10/arrow/bitutil
cpu: 12th Gen Intel(R) Core(TM) i7-12700H
BenchmarkBitmapAnd/nbytes=32768/aligned-20 126613 9308
ns/op 7040.73 MB/s 0 B/op 0 allocs/op
BenchmarkBitmapAnd/nbytes=32768/unaligned-20 28724
41392 ns/op 1583.30 MB/s 192 B/op 3 allocs/op
BenchmarkBitmapAnd/nbytes=131072/aligned-20 32292
37420 ns/op 7005.50 MB/s 0 B/op 0 allocs/op
BenchmarkBitmapAnd/nbytes=131072/unaligned-20 7068
166973 ns/op 1569.97 MB/s 192 B/op 3 allocs/op
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]