Skip to content

Commit

Permalink
simd_detail => simd::detail
Browse files Browse the repository at this point in the history
Summary: rename simd_detail => simd::detail

Reviewed By: Gownta

Differential Revision: D63318623

fbshipit-source-id: c5126134cbc5ec3e7631410d8b01b99e768d8343
  • Loading branch information
DenisYaroshevskiy authored and facebook-github-bot committed Sep 25, 2024
1 parent 00ed8ed commit fb77fc1
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 49 deletions.
4 changes: 2 additions & 2 deletions folly/algorithm/simd/detail/SimdAnyOf.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <folly/algorithm/simd/detail/UnrollUtils.h>

namespace folly {
namespace simd_detail {
namespace simd::detail {

/**
* AnyOfDelegate
Expand Down Expand Up @@ -79,5 +79,5 @@ FOLLY_ALWAYS_INLINE bool simdAnyOf(T* f, T* l, P p) {
return delegate.res;
}

} // namespace simd_detail
} // namespace simd::detail
} // namespace folly
39 changes: 18 additions & 21 deletions folly/algorithm/simd/detail/SimdCharPlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#endif

namespace folly {
namespace simd_detail {
namespace simd::detail {

/**
* SimdCharPlatform
Expand Down Expand Up @@ -97,7 +97,7 @@ struct SimdCharPlatformCommon : Platform {
}

FOLLY_NODISCARD FOLLY_ALWAYS_INLINE static mmask_t clear(
mmask_t mmask, simd_detail::ignore_extrema ignore) {
mmask_t mmask, ignore_extrema ignore) {
mmask_t clearFirst =
~setLowerNBits<mmask_t>(ignore.first * kMmaskBitsPerElement);
mmask_t clearLast = setLowerNBits<mmask_t>(
Expand All @@ -106,20 +106,20 @@ struct SimdCharPlatformCommon : Platform {
}

FOLLY_NODISCARD FOLLY_ALWAYS_INLINE static mmask_t clear(
mmask_t mmask, simd_detail::ignore_none) {
mmask_t mmask, ignore_none) {
return mmask;
}

// These are aligned loads but there is no point in generating
// aligned load instructions, so we call loadu.
FOLLY_ALWAYS_INLINE
static auto loada(const char* ptr, simd_detail::ignore_none) {
return Platform::loadu(ptr, simd_detail::ignore_none{});
static auto loada(const char* ptr, ignore_none) {
return Platform::loadu(ptr, ignore_none{});
}

FOLLY_ALWAYS_INLINE
static auto loada(const char* ptr, simd_detail::ignore_extrema) {
return Platform::unsafeLoadu(ptr, simd_detail::ignore_none{});
static auto loada(const char* ptr, ignore_extrema) {
return Platform::unsafeLoadu(ptr, ignore_none{});
}

FOLLY_ALWAYS_INLINE
Expand All @@ -130,8 +130,7 @@ struct SimdCharPlatformCommon : Platform {
using Platform::any;

FOLLY_ALWAYS_INLINE
static bool any(
typename Platform::logical_t log, simd_detail::ignore_extrema ignore) {
static bool any(typename Platform::logical_t log, ignore_extrema ignore) {
auto mmask = movemask(log);
mmask = clear(mmask, ignore);
return mmask;
Expand All @@ -157,13 +156,13 @@ struct SimdCharSse2PlatformSpecific {
// Even for aligned loads intel people don't recommend using
// aligned load instruction
FOLLY_ALWAYS_INLINE
static reg_t loadu(const char* p, simd_detail::ignore_none) {
static reg_t loadu(const char* p, ignore_none) {
return _mm_loadu_si128(reinterpret_cast<const reg_t*>(p));
}

FOLLY_DISABLE_SANITIZERS
FOLLY_ALWAYS_INLINE
static reg_t unsafeLoadu(const char* p, simd_detail::ignore_none) {
static reg_t unsafeLoadu(const char* p, ignore_none) {
return _mm_loadu_si128(reinterpret_cast<const reg_t*>(p));
}

Expand All @@ -186,7 +185,7 @@ struct SimdCharSse2PlatformSpecific {
}

FOLLY_ALWAYS_INLINE
static bool any(logical_t log, simd_detail::ignore_none) {
static bool any(logical_t log, ignore_none) {
return folly::movemask<std::uint8_t>(log).first;
}
};
Expand All @@ -206,13 +205,13 @@ struct SimdCharAvx2PlatformSpecific {

// We can actually use aligned loads but our Intel people don't recommend
FOLLY_ALWAYS_INLINE
static reg_t loadu(const char* p, simd_detail::ignore_none) {
static reg_t loadu(const char* p, ignore_none) {
return _mm256_loadu_si256(reinterpret_cast<const reg_t*>(p));
}

FOLLY_DISABLE_SANITIZERS
FOLLY_ALWAYS_INLINE
static reg_t unsafeLoadu(const char* p, simd_detail::ignore_none) {
static reg_t unsafeLoadu(const char* p, ignore_none) {
return _mm256_loadu_si256(reinterpret_cast<const reg_t*>(p));
}

Expand All @@ -234,7 +233,7 @@ struct SimdCharAvx2PlatformSpecific {
}

FOLLY_ALWAYS_INLINE
static bool any(logical_t log, simd_detail::ignore_none) {
static bool any(logical_t log, ignore_none) {
return folly::movemask<std::uint8_t>(log).first;
}
};
Expand All @@ -257,13 +256,13 @@ struct SimdCharAarch64PlatformSpecific {
static constexpr int kCardinal = 16;

FOLLY_ALWAYS_INLINE
static reg_t loadu(const char* p, simd_detail::ignore_none) {
static reg_t loadu(const char* p, ignore_none) {
return vld1q_u8(reinterpret_cast<const std::uint8_t*>(p));
}

FOLLY_DISABLE_SANITIZERS
FOLLY_ALWAYS_INLINE
static reg_t unsafeLoadu(const char* p, simd_detail::ignore_none) {
static reg_t unsafeLoadu(const char* p, ignore_none) {
return vld1q_u8(reinterpret_cast<const std::uint8_t*>(p));
}

Expand All @@ -283,9 +282,7 @@ struct SimdCharAarch64PlatformSpecific {
}

FOLLY_ALWAYS_INLINE
static bool any(logical_t log, simd_detail::ignore_none) {
return vmaxvq_u8(log);
}
static bool any(logical_t log, ignore_none) { return vmaxvq_u8(log); }
};

#define FOLLY_DETAIL_HAS_SIMD_CHAR_PLATFORM 1
Expand All @@ -305,5 +302,5 @@ using SimdCharPlatform = void;

#endif

} // namespace simd_detail
} // namespace simd::detail
} // namespace folly
11 changes: 5 additions & 6 deletions folly/algorithm/simd/detail/SimdForEach.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <type_traits>

namespace folly {
namespace simd_detail {
namespace simd::detail {

// Based on
// https://github.com/jfalcou/eve/blob/5264e20c51aeca17675e67abf236ce1ead781c52/include/eve/module/algo/algo/for_each_iteration.hpp#L148
Expand Down Expand Up @@ -165,9 +165,8 @@ struct SimdForEachMainLoop {
bool shouldBreak = false;

// single steps
if (detail::UnrollUtils::unrollUntil<unrolling>(
SmallStepsLambda<T, Delegate>{
shouldBreak, cardinal, f, l, delegate})) {
if (UnrollUtils::unrollUntil<unrolling>(SmallStepsLambda<T, Delegate>{
shouldBreak, cardinal, f, l, delegate})) {
return shouldBreak;
}

Expand All @@ -176,7 +175,7 @@ struct SimdForEachMainLoop {
--bigStepsCount) {
std::array<T*, unrolling> arr;
// Since there is no callback, we can rely on the inlining
detail::UnrollUtils::unrollUntil<unrolling>([&](auto idx) {
UnrollUtils::unrollUntil<unrolling>([&](auto idx) {
arr[idx()] = f;
f += cardinal;
return false;
Expand Down Expand Up @@ -224,5 +223,5 @@ FOLLY_ALWAYS_INLINE void simdForEachAligning(
delegate.step(af, ignore, index_constant<0>{});
}

} // namespace simd_detail
} // namespace simd::detail
} // namespace folly
4 changes: 2 additions & 2 deletions folly/algorithm/simd/detail/UnrollUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <array>
#include <type_traits>

namespace folly::detail {
namespace folly::simd::detail {

/**
* UnrollUtils
Expand Down Expand Up @@ -123,4 +123,4 @@ struct UnrollUtils {
}
};

} // namespace folly::detail
} // namespace folly::simd::detail
6 changes: 3 additions & 3 deletions folly/algorithm/simd/detail/test/SimdAnyOfTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
#if FOLLY_DETAIL_HAS_SIMD_CHAR_PLATFORM

namespace folly {
namespace simd_detail {
namespace simd::detail {

template <typename Platform, int unrolling>
void anySpacesTestForPlatformUnrolling(folly::StringPiece s, bool expected) {
bool actual = folly::simd_detail::simdAnyOf<Platform, unrolling>(
bool actual = simdAnyOf<Platform, unrolling>(
s.data(), s.data() + s.size(), [](typename Platform::reg_t x) {
return Platform::equal(x, ' ');
});
Expand Down Expand Up @@ -111,7 +111,7 @@ TEST(SimdAnyOfSimple, BigChunk) {
}
}

} // namespace simd_detail
} // namespace simd::detail
} // namespace folly

#endif // FOLLY_DETAIL_HAS_SIMD_CHAR_PLATFORM
4 changes: 2 additions & 2 deletions folly/algorithm/simd/detail/test/SimdForEachTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <array>

namespace folly {
namespace simd_detail {
namespace simd::detail {

constexpr int kCardinal = 4;

Expand Down Expand Up @@ -270,5 +270,5 @@ TEST(SimdForEachAligningTest, UnrollIndexes) {
run<4>(0, 37, -1));
}

} // namespace simd_detail
} // namespace simd::detail
} // namespace folly
4 changes: 2 additions & 2 deletions folly/algorithm/simd/detail/test/UnrollUtilsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include <array>

namespace folly::detail {
namespace folly::simd::detail {

TEST(UnrollUtilsTest, ArrayMap) {
constexpr std::array<int, 3> in = {1, 2, 3};
Expand Down Expand Up @@ -115,4 +115,4 @@ TEST(UnrollUtilsTest, UnrollUntil) {
"");
}

} // namespace folly::detail
} // namespace folly::simd::detail
2 changes: 1 addition & 1 deletion folly/detail/SimpleSimdStringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace detail {

bool simdHasSpaceOrCntrlSymbols(folly::StringPiece s) {
return SimpleSimdStringUtilsImpl<
simd_detail::SimdCharPlatform>::hasSpaceOrCntrlSymbols(s);
simd::detail::SimdCharPlatform>::hasSpaceOrCntrlSymbols(s);
}

} // namespace detail
Expand Down
2 changes: 1 addition & 1 deletion folly/detail/SimpleSimdStringUtilsImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct SimpleSimdStringUtilsImpl {

FOLLY_ALWAYS_INLINE
static bool hasSpaceOrCntrlSymbols(folly::StringPiece s) {
return simd_detail::simdAnyOf<Platform, /*unrolling*/ 4>(
return simd::detail::simdAnyOf<Platform, /*unrolling*/ 4>(
s.data(), s.data() + s.size(), HasSpaceOrCntrlSymbolsLambda{});
}
};
Expand Down
8 changes: 4 additions & 4 deletions folly/detail/SplitStringSimd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@ template <typename Container>
void SimdSplitByCharImpl<Container>::keepEmpty(
char sep, folly::StringPiece what, Container& res) {
PlatformSimdSplitByChar<
simd_detail::SimdCharPlatform,
simd::detail::SimdCharPlatform,
/*ignoreEmpty*/ false>{}(sep, what, res);
}

template <typename Container>
void SimdSplitByCharImpl<Container>::dropEmpty(
char sep, folly::StringPiece what, Container& res) {
PlatformSimdSplitByChar<
simd_detail::SimdCharPlatform,
simd::detail::SimdCharPlatform,
/*ignoreEmpty*/ true>{}(sep, what, res);
}

template <typename Container>
void SimdSplitByCharImplToStrings<Container>::keepEmpty(
char sep, folly::StringPiece what, Container& res) {
PlatformSimdSplitByChar<
simd_detail::SimdCharPlatform,
simd::detail::SimdCharPlatform,
/*ignoreEmpty*/ false>{}(sep, what, res);
}

template <typename Container>
void SimdSplitByCharImplToStrings<Container>::dropEmpty(
char sep, folly::StringPiece what, Container& res) {
PlatformSimdSplitByChar<
simd_detail::SimdCharPlatform,
simd::detail::SimdCharPlatform,
/*ignoreEmpty*/ true>{}(sep, what, res);
}

Expand Down
2 changes: 1 addition & 1 deletion folly/detail/SplitStringSimdImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ struct PlatformSimdSplitByChar {
char sep, folly::StringPiece what, Container& res) const {
const char* prev = what.data();
ForEachDelegate<Container> delegate{*this, sep, prev, res};
simd_detail::simdForEachAligning</*unrolling*/ 1>(
simd::detail::simdForEachAligning</*unrolling*/ 1>(
Platform::kCardinal, what.data(), what.data() + what.size(), delegate);
emplaceBack(res, prev, what.data() + what.size());
}
Expand Down
2 changes: 1 addition & 1 deletion folly/detail/test/SimpleSimdStringUtilsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bool hasSpaceOrCntrlSymbolsForPlatform(folly::StringPiece s) {
void testHasSpaceOrCntrlSymbols(folly::StringPiece s, bool r) {
ASSERT_EQ(r, simdHasSpaceOrCntrlSymbols(s)) << s;

using namespace simd_detail;
using namespace simd::detail;
ASSERT_EQ(r, hasSpaceOrCntrlSymbolsForPlatform<void>(s)) << s;

#if FOLLY_X64
Expand Down
6 changes: 3 additions & 3 deletions folly/detail/test/SplitStringSimdTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,18 @@ void runTestStringSplitOneType(folly::StringPiece s) {

#if FOLLY_X64
actuals.emplace_back();
PlatformSimdSplitByChar<simd_detail::SimdCharSse2Platform, ignoreEmpty>{}(
PlatformSimdSplitByChar<simd::detail::SimdCharSse2Platform, ignoreEmpty>{}(
',', s, actuals.back());
#if defined(__AVX2__)
actuals.emplace_back();
PlatformSimdSplitByChar<simd_detail::SimdCharAvx2Platform, ignoreEmpty>{}(
PlatformSimdSplitByChar<simd::detail::SimdCharAvx2Platform, ignoreEmpty>{}(
',', s, actuals.back());
#endif
#endif

#if FOLLY_AARCH64
actuals.emplace_back();
PlatformSimdSplitByChar<simd_detail::SimdCharAarch64Platform, ignoreEmpty>{}(
PlatformSimdSplitByChar<simd::detail::SimdCharAarch64Platform, ignoreEmpty>{}(
',', s, actuals.back());
#endif

Expand Down

0 comments on commit fb77fc1

Please sign in to comment.