AntoinePrv commented on code in PR #47573:
URL: https://github.com/apache/arrow/pull/47573#discussion_r2428956737


##########
cpp/src/arrow/util/bpacking_dispatch_internal.h:
##########
@@ -0,0 +1,104 @@
+// 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 <cstring>
+#include <utility>
+
+#include "arrow/util/endian.h"
+#include "arrow/util/logging.h"
+#include "arrow/util/ubsan.h"
+
+namespace arrow::internal {
+
+/// Unpack a zero bit packed array.
+template <typename Uint>
+int unpack_null(const uint8_t* in, Uint* out, int batch_size) {
+  std::memset(out, 0, batch_size * sizeof(Uint));
+  return batch_size;
+}
+
+/// Unpack a packed array where packed and unpacked values have exactly the 
same number of
+/// bits.
+template <typename Uint>
+int unpack_full(const uint8_t* in, Uint* out, int batch_size) {
+  if constexpr (ARROW_LITTLE_ENDIAN == 1) {
+    std::memcpy(out, in, batch_size * sizeof(Uint));
+  } else {
+    using bit_util::FromLittleEndian;
+    using util::SafeLoadAs;
+
+    for (int k = 0; k < batch_size; k += 1) {
+      out[k] = FromLittleEndian(SafeLoadAs<Uint>(in + (k * sizeof(Uint))));
+    }
+  }
+  return batch_size;
+}
+
+/// Unpack a packed array, delegating to a Unpacker struct.
+///
+/// @tparam kPackedBitWidth The width in bits of the values in the packed 
array.
+/// @tparam Unpacker The struct providing information and an ``unpack`` method 
to unpack a
+///                  fixed amount of values (usually constrained by SIMD batch 
sizes and
+///                  byte alignment).
+/// @tparam UnpackedUInt The type in which we unpack the values.
+template <int kPackedBitWidth, template <typename, int> typename Unpacker,
+          typename UnpackedUInt>
+int unpack_width(const uint8_t* in, UnpackedUInt* out, int batch_size) {
+  using UnpackerForWidth = Unpacker<UnpackedUInt, kPackedBitWidth>;
+
+  constexpr auto kValuesUnpacked = UnpackerForWidth::kValuesUnpacked;

Review Comment:
   I think the currently implicit contract of these functions is unpack up to 
`batch_size` but possibly less.
   At least that's how they are called. Best would be to have the epilog in 
these functions so that they extract exactly `batch_size` values.



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

Reply via email to