| 193 | |
| 194 | template <typename Int> |
| 195 | void TestAll(UnpackFunc<Int> unpack) { |
| 196 | const int num_values_base = GetParam(); |
| 197 | |
| 198 | constexpr int kMaxBitWidth = std::is_same_v<Int, bool> ? 1 : 8 * sizeof(Int); |
| 199 | |
| 200 | // Given how many edge cases there are in unpacking integers, it is best to test all |
| 201 | // sizes |
| 202 | for (int bit_width = 0; bit_width <= kMaxBitWidth; ++bit_width) { |
| 203 | SCOPED_TRACE(::testing::Message() << "Testing bit_width=" << bit_width); |
| 204 | |
| 205 | // We test all bit offset within a byte / misalignments to change how the |
| 206 | // prolog. |
| 207 | for (int bit_offset = 0; bit_offset < 8; ++bit_offset) { |
| 208 | SCOPED_TRACE(::testing::Message() << "Testing bit_offset=" << bit_offset); |
| 209 | |
| 210 | const UnpackOptions opts{ |
| 211 | .batch_size = num_values_base, |
| 212 | .bit_width = bit_width, |
| 213 | .bit_offset = bit_offset, |
| 214 | .max_read_bytes = -1, // No over-reading in testing (strict ASAN) |
| 215 | }; |
| 216 | |
| 217 | // Known values |
| 218 | TestUnpackZeros(unpack, opts); |
| 219 | TestUnpackOnes(unpack, opts); |
| 220 | TestUnpackAlternating(unpack, opts); |
| 221 | |
| 222 | // Roundtrips |
| 223 | TestRoundtripAlignment(unpack, opts); |
| 224 | |
| 225 | if (testing::Test::HasFailure()) return; |
| 226 | } |
| 227 | |
| 228 | // Similarly, we test all epilog sizes. That is extra values that could make it |
| 229 | // fall outside of an SIMD register |
| 230 | for (int epilogue_size = 0; epilogue_size <= kMaxBitWidth; ++epilogue_size) { |
| 231 | SCOPED_TRACE(::testing::Message() << "Testing epilog_size=" << epilogue_size); |
| 232 | |
| 233 | const int num_values = num_values_base + epilogue_size; |
| 234 | |
| 235 | const UnpackOptions opts{ |
| 236 | .batch_size = num_values, |
| 237 | .bit_width = bit_width, |
| 238 | .bit_offset = 0, |
| 239 | .max_read_bytes = -1, // No over-reading in testing (strict ASAN) |
| 240 | }; |
| 241 | |
| 242 | // Known values |
| 243 | TestUnpackZeros(unpack, opts); |
| 244 | TestUnpackOnes(unpack, opts); |
| 245 | TestUnpackAlternating(unpack, opts); |
| 246 | |
| 247 | // Roundtrips |
| 248 | TestRoundtripAlignment(unpack, opts); |
| 249 | |
| 250 | if (testing::Test::HasFailure()) return; |
| 251 | } |
| 252 | } |