zeroshade commented on a change in pull request #9671:
URL: https://github.com/apache/arrow/pull/9671#discussion_r595185112



##########
File path: go/parquet/internal/bmi/bmi_init.go
##########
@@ -0,0 +1,66 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package bmi
+
+import (
+       "golang.org/x/sys/cpu"
+)
+
+type funcs struct {
+       extractBits func(uint64, uint64) uint64
+       popcount64  func(uint64) uint64
+       popcount32  func(uint32) uint32
+       gtbitmap    func([]int16, int16) uint64
+}
+
+var funclist funcs
+
+func init() {
+       if cpu.X86.HasPOPCNT {
+               funclist.popcount64 = popCount64BMI2

Review comment:
       So i just deleted my original comment as I just did a bit of 
benchmarking and managed to surprise myself. 
   
   Even though the `bits.OnesCount32` looks like it isn't quite as efficient as 
using a single `popcnt32` processor instruction for BMI2, it turns out under 
benchmarking that `bits.OnesCount` is actually slightly more efficient than 
using popcnt32BMI2, possibly because of the function indirection i'm doing but 
i'm not sure. But ultimately it looks like `bits.OnesCount32` ends up being 
around 0.6105 ns/op while the BMI2 ends up being ~3.8 ns/op when running on a 
value that is half 1's. (ie: 0b10101010101010........) on my laptop.
   
   So i'm glad you called me on this and made me actually revisit this 
assumption. I'll go through and remove the popcnt functions and just call 
`bits.OnesCount32` / `bits.OnesCount64` in those places.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to