forked from facebook/folly
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removing movemask from platform (facebook#2302)
Summary: Pull Request resolved: facebook#2302 stepping stone for simd::contains. We want to do less things in simd platform if possbile, so moving out non essential things. Differential Revision: D63388617
- Loading branch information
1 parent
70d9018
commit cd61173
Showing
13 changed files
with
171 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* Licensed 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 <folly/lang/Bits.h> | ||
|
||
#include <type_traits> | ||
|
||
namespace folly::simd::detail { | ||
|
||
/** | ||
* ignore(_none/_extrema) | ||
* | ||
* Tag types for handling the tails. | ||
* ignore_none indicates that the whole register is used. | ||
* ignore_extrema.first, .last show how many elements are out of the data. | ||
* | ||
* For example 3 elements, starting from the second for an 8 element register | ||
* will be ignore_extrema{.first = 1, .last = 4} | ||
*/ | ||
|
||
struct ignore_extrema { | ||
int first = 0; | ||
int last = 0; | ||
}; | ||
|
||
struct ignore_none {}; | ||
|
||
/* | ||
* NOTE: for ignore none we don't clear anything, even if some bits are not | ||
* doing anything. We expect mmask to only have zeroes in masked out elements. | ||
* | ||
* Maybe we need to revisit that at some point. | ||
*/ | ||
template <int Cardinal, typename Uint, typename BitsPerElement, typename Ignore> | ||
void mmaskClearIgnored(std::pair<Uint, BitsPerElement>& mmask, Ignore ignore) { | ||
if constexpr (std::is_same_v<Ignore, ignore_extrema>) { | ||
mmask.first = set_rzero(mmask.first, ignore.first * BitsPerElement{}); | ||
|
||
static constexpr int kTopBitsAlwaysIgnored = | ||
sizeof(Uint) * 8 - Cardinal * BitsPerElement{}; | ||
mmask.first = set_lzero( | ||
mmask.first, ignore.last * BitsPerElement{} + kTopBitsAlwaysIgnored); | ||
} | ||
} | ||
|
||
} // namespace folly::simd::detail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* Licensed 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 <folly/algorithm/simd/detail/Ignore.h> | ||
|
||
#include <cstdint> | ||
|
||
#include <folly/portability/GTest.h> | ||
|
||
namespace folly::simd::detail { | ||
|
||
struct IgnoreTest : ::testing::Test {}; | ||
|
||
TEST_F(IgnoreTest, MaskClearIgnored) { | ||
auto mmask = | ||
std::pair{std::uint8_t{0xff}, std::integral_constant<std::uint32_t, 2>{}}; | ||
|
||
// mostly relying on folly::clear_<>_n_bits working correctly | ||
// simd any of also covers a lot of cases. | ||
// this is just the bare minimal smoke test. | ||
|
||
mmaskClearIgnored<4>(mmask, ignore_none{}); | ||
EXPECT_EQ(0xff, mmask.first); | ||
|
||
mmaskClearIgnored<4>(mmask, ignore_extrema{1, 2}); | ||
EXPECT_EQ(0b0000'1100, mmask.first); | ||
|
||
mmaskClearIgnored<2>(mmask, ignore_extrema{0, 1}); | ||
EXPECT_EQ(0b0000'0000, mmask.first); | ||
} | ||
|
||
} // namespace folly::simd::detail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.