Skip to content

Commit

Permalink
tweaks to simd-contains tests
Browse files Browse the repository at this point in the history
Summary:
* Either everything is outside `namespace folly::simd` and the calls are qualified or everything is inside and the calls are unqualified.
* No death tests, including non-death tests. Death tests are slower to run, especially in loops.
* Evade use-of-detail-namespace linter.

Reviewed By: skrueger

Differential Revision: D64180212

fbshipit-source-id: 61742aaaa1a1c960958ac9cfc22e33d8cb935d56
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Oct 16, 2024
1 parent 285f95c commit 33c3f25
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions folly/algorithm/simd/test/ContainsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@
#include <list>
#include <vector>

namespace folly::simd {

static_assert( //
!std::is_invocable_v< //
contains_fn,
folly::simd::contains_fn,
std::vector<double>&,
double>);

static_assert( //
std::is_invocable_v< //
contains_fn,
folly::simd::contains_fn,
std::vector<int>&,
int>);

Expand Down Expand Up @@ -109,23 +107,28 @@ using TypesToTest = ::testing::Types<

TYPED_TEST_SUITE(ContainsTest, TypesToTest);

namespace folly::simd {
using detail::containsImplHandwritten;
using detail::containsImplStd;
using detail::hasHandwrittenContains;
} // namespace folly::simd

template <typename T>
void testSimdContainsVerify(folly::span<T> haystack, T needle, bool expected) {
bool actual1 = simd::contains(haystack, needle);
bool actual1 = folly::simd::contains(haystack, needle);
ASSERT_EQ(expected, actual1);

auto const_haystack = folly::static_span_cast<const T>(haystack);

if constexpr (
std::is_same_v<T, std::uint8_t> || std::is_same_v<T, std::uint16_t> ||
std::is_same_v<T, std::uint32_t> || std::is_same_v<T, std::uint64_t>) {
bool actual2 = simd::detail::containsImplStd(const_haystack, needle);
bool actual2 = folly::simd::containsImplStd(const_haystack, needle);
ASSERT_EQ(expected, actual2) << " haystack.size(): " << haystack.size();
}

if constexpr (simd::detail::hasHandwrittenContains<T>()) {
bool actual3 =
simd::detail::containsImplHandwritten(const_haystack, needle);
if constexpr (folly::simd::detail::hasHandwrittenContains<T>()) {
bool actual3 = folly::simd::containsImplHandwritten(const_haystack, needle);
ASSERT_EQ(expected, actual3) << " haystack.size(): " << haystack.size();
}
}
Expand All @@ -139,13 +142,11 @@ TYPED_TEST(ContainsTest, Basic) {
++offset) {
folly::span<T> haystack(buf.data() + offset, buf.data() + buf.size());
T needle{1};
ASSERT_NO_FATAL_FAILURE(
testSimdContainsVerify(haystack, needle, /*expected*/ false));
testSimdContainsVerify(haystack, needle, /*expected*/ false);

for (auto& x : haystack) {
x = needle;
ASSERT_NO_FATAL_FAILURE(
testSimdContainsVerify(haystack, needle, /*expected*/ true));
testSimdContainsVerify(haystack, needle, /*expected*/ true);
x = 0;
}
}
Expand All @@ -168,5 +169,3 @@ TEST_F(ContainsTestSpeicalCases, AsanShouldDetectInvalidRange) {
EXPECT_DEATH(
(folly::simd::contains(s, 0)), "AddressSanitizer: heap-buffer-overflow");
}

} // namespace folly::simd

0 comments on commit 33c3f25

Please sign in to comment.