jianxind commented on a change in pull request #7029:
URL: https://github.com/apache/arrow/pull/7029#discussion_r414505645



##########
File path: cpp/src/arrow/util/spaced.h
##########
@@ -0,0 +1,266 @@
+// 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.
+
+#pragma once
+
+#include "arrow/util/bit_util.h"
+
+#ifdef ARROW_HAVE_AVX512
+#include <immintrin.h>
+#endif  // ARROW_HAVE_AVX512
+
+namespace arrow {
+namespace util {
+namespace internal {
+
+template <typename T>
+int PutSpacedScalar(const T* values, int num_values, const uint8_t* valid_bits,
+                    int64_t valid_bits_offset, T* output) {
+  int num_valid_values = 0;
+  arrow::internal::BitmapReader valid_bits_reader(valid_bits, 
valid_bits_offset,
+                                                  num_values);
+  for (int32_t i = 0; i < num_values; i++) {
+    if (valid_bits_reader.IsSet()) {
+      output[num_valid_values++] = values[i];
+    }
+    valid_bits_reader.Next();
+  }
+  return num_valid_values;
+}
+
+template <typename T>
+int DecodeSpacedScalar(T* buffer, int num_values, int null_count,
+                       const uint8_t* valid_bits, int64_t valid_bits_offset) {
+  const int values_read = num_values - null_count;
+
+  // Depending on the number of nulls, some of the value slots in buffer may
+  // be uninitialized, and this will cause valgrind warnings / potentially UB
+  memset(static_cast<void*>(buffer + values_read), 0,
+         (num_values - values_read) * sizeof(T));
+
+  // Add spacing for null entries. As we have filled the buffer from the front,
+  // we need to add the spacing from the back.
+  int values_to_move = values_read - 1;
+  // We stop early on one of two conditions:
+  // 1. There are no more null values that need spacing.  Note we infer this
+  //     backwards, when 'i' is equal to 'values_to_move' it indicates
+  //    all nulls have been consumed.
+  // 2. There are no more non-null values that need to move which indicates
+  //    all remaining slots are null, so their exact value doesn't matter.
+  for (int i = num_values - 1; (i > values_to_move) && (values_to_move >= 0); 
i--) {
+    if (BitUtil::GetBit(valid_bits, valid_bits_offset + i)) {
+      buffer[i] = buffer[values_to_move];
+      values_to_move--;
+    }
+  }
+  return num_values;
+}
+
+#if defined(ARROW_HAVE_AVX512)
+template <typename T>
+int PutSpacedAvx512Compress(const T* values, int num_values, const uint8_t* 
valid_bits,
+                            int64_t valid_bits_offset, T* output) {
+  assert(sizeof(T) == 4 || sizeof(T) == 8);  // Only support epi32 and epi64

Review comment:
       Can't. The instantiation PutSpaced of other types still get to this 
place though it will never be reached.
   
   /mnt/github/arrow/cpp/src/arrow/util/spaced.h: In instantiation of 'int 
arrow::util::internal::PutSpacedAvx512Compress(const T*, int, const uint8_t*, 
int64_t, T*) [with T = parquet::Int96; uint8_t = unsigned char; int64_t = long 
int]':
   /mnt/github/arrow/cpp/src/arrow/util/spaced.h:224:38:   required from 'int 
arrow::util::internal::PutSpacedAvx512(const T*, int, const uint8_t*, int64_t, 
T*) [with T = parquet::Int96; uint8_t = unsigned char; int64_t = long int]'
   /mnt/github/arrow/cpp/src/arrow/util/spaced.h:246:28:   required from 'int 
arrow::util::internal::PutSpaced(const T*, int, const uint8_t*, int64_t, T*) 
[with T = parquet::Int96; uint8_t = unsigned char; int64_t = long int]'
   /mnt/github/arrow/cpp/src/parquet/encoding.cc:107:63:   required from 'void 
parquet::PlainEncoder<DType>::PutSpaced(const T*, int, const uint8_t*, int64_t) 
[with DType = parquet::PhysicalType<(parquet::Type::type)3>; 
parquet::PlainEncoder<DType>::T = parquet::Int96; uint8_t = unsigned char; 
int64_t = long int]'
   




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