github-actions[bot] commented on code in PR #65738: URL: https://github.com/apache/doris/pull/65738#discussion_r3614579619
########## be/test/util/bit_packing_test.cpp: ########## @@ -0,0 +1,126 @@ +// 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. + +#include <algorithm> +#include <cstdint> +#include <limits> +#include <vector> + +#include "util/bit_stream_utils.inline.h" +#include "util/faststring.h" + +namespace doris { +namespace { + +#if defined(__x86_64__) && (defined(__GNUC__) || defined(__clang__)) +static_assert(PdepUnpack::should_use<uint16_t, 15>()); +static_assert(PdepUnpack::should_use<uint32_t, 15>()); +static_assert(!PdepUnpack::should_use<uint16_t, 16>()); +static_assert(!PdepUnpack::should_use<uint32_t, 16>()); +static_assert(!PdepUnpack::should_use<uint32_t, 32>()); +#endif + +template <typename T> +std::vector<T> make_values(int bit_width, int num_values) { + const uint64_t mask = bit_width == std::numeric_limits<T>::digits + ? std::numeric_limits<T>::max() + : (1ULL << bit_width) - 1; + std::vector<T> values(num_values); + for (int i = 0; i < num_values; ++i) { + values[i] = static_cast<T>((0x9E3779B9ULL * i + 0x7F4A7C15ULL) & mask); + } + return values; +} + +template <typename T> +void pack_values(const std::vector<T>& values, int bit_width, faststring* packed) { + BitWriter writer(packed); + for (T value : values) { + writer.PutValue(value, bit_width); + } + writer.Flush(); +} + +template <typename T> +void test_all_bit_widths(int num_values) { + for (int bit_width = 1; bit_width <= std::numeric_limits<T>::digits; ++bit_width) { + std::vector<T> expected = make_values<T>(bit_width, num_values); + faststring packed; + pack_values(expected, bit_width, &packed); + std::vector<T> actual(num_values); + + auto [end, values_read] = + BitPacking::UnpackValues(bit_width, reinterpret_cast<const uint8_t*>(packed.data()), + packed.size(), num_values, actual.data()); + + EXPECT_EQ(values_read, num_values) << "bit_width=" << bit_width; + EXPECT_EQ(end, reinterpret_cast<const uint8_t*>(packed.data()) + packed.size()) + << "bit_width=" << bit_width; + EXPECT_EQ(actual, expected) << "bit_width=" << bit_width; + } +} + +template <typename T> +void test_truncated_input() { + constexpr int num_values = 65; Review Comment: **[P2] Exercise the PDEP path in the truncated-input test** `test_truncated_input()` requests only 65 values, so after the new four-batch threshold it can produce at most two full batches. This test therefore always takes the old scalar path, even on BMI2+AVX2 hardware, and the shortened-`in_bytes` contract is never checked through the new decoder. For example, requesting 160 values and removing one byte leaves 152-159 readable values at production widths 1-15: four PDEP batches plus a 24-31-value scalar remainder, which checks readable-versus-requested batch accounting and the input-limited handoff. Please also physically shorten/guard the input and verify the output suffix if this test is meant to observe overreads or overwrites. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
