-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- created build.hpp for TPUBuild - epu8id and similar are now Epu8.id() - improved doc
- Loading branch information
Showing
11 changed files
with
182 additions
and
152 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
//****************************************************************************// | ||
// Copyright (C) 2018 Florent Hivert <[email protected]>, // | ||
// Copyright (C) 2018-2023 Florent Hivert <[email protected]>, // | ||
// // | ||
// Distributed under the terms of the GNU General Public License (GPL) // | ||
// // | ||
|
@@ -32,7 +32,7 @@ namespace { | |
struct RoundsMask { | ||
constexpr RoundsMask() : arr() { | ||
for (unsigned i = 0; i < sorting_rounds.size(); ++i) | ||
arr[i] = sorting_rounds[i] < epu8id; | ||
arr[i] = sorting_rounds[i] < Epu8.id(); | ||
} | ||
epu8 arr[sorting_rounds.size()]; | ||
}; | ||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
//****************************************************************************// | ||
// Copyright (C) 2016 Florent Hivert <[email protected]>, // | ||
// Copyright (C) 2016-2023 Florent Hivert <[email protected]>, // | ||
// // | ||
// Distributed under the terms of the GNU General Public License (GPL) // | ||
// // | ||
|
@@ -35,7 +35,7 @@ std::vector<epu8> rand_epu8(size_t sz) { | |
inline epu8 rand_perm() { | ||
static std::random_device rd; | ||
static std::mt19937 g(rd()); | ||
epu8 res = HPCombi::epu8id; | ||
epu8 res = HPCombi::Epu8.id(); | ||
auto &ar = HPCombi::as_array(res); | ||
std::shuffle(ar.begin(), ar.end(), g); | ||
return res; | ||
|
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,91 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Copyright (C) 2023 Florent Hivert <[email protected]>, // | ||
// // | ||
// Distributed under the terms of the GNU General Public License (GPL) // | ||
// // | ||
// This code is distributed in the hope that it will be useful, // | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of // | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // | ||
// General Public License for more details. // | ||
// // | ||
// The full text of the GPL is available at: // | ||
// // | ||
// http://www.gnu.org/licenses/ // | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#ifndef HPCOMBI_BUILDER_HPP_INCLUDED | ||
#define HPCOMBI_BUILDER_HPP_INCLUDED | ||
|
||
/** Factory object for various SIMD constants in particular constexpr | ||
*/ | ||
template <class TPU> struct TPUBuild { | ||
// Type for Packed Unsigned integer (TPU) | ||
using type_elem = typename std::remove_reference_t<decltype((TPU{})[0])>; | ||
static constexpr size_t size_elem = sizeof(type_elem); | ||
static constexpr size_t size = sizeof(TPU) / size_elem; | ||
|
||
using array = std::array<type_elem, size>; | ||
|
||
template <class Fun, decltype(size)... Is> | ||
static constexpr TPU make_helper(Fun f, std::index_sequence<Is...>) { | ||
static_assert(std::is_invocable_v<Fun, type_elem>); | ||
return TPU{f(Is)...}; | ||
} | ||
|
||
inline constexpr TPU operator()(std::initializer_list<type_elem> il, | ||
type_elem def) const { | ||
HPCOMBI_ASSERT(il.size() <= size); | ||
array res; | ||
std::copy(il.begin(), il.end(), res.begin()); | ||
std::fill(res.begin() + il.size(), res.end(), def); | ||
return reinterpret_cast<const TPU &>(res); | ||
} | ||
|
||
template <class Fun> inline constexpr TPU operator()(Fun f) const { | ||
static_assert(std::is_invocable_v<Fun, type_elem>); | ||
return make_helper(f, std::make_index_sequence<size>{}); | ||
} | ||
|
||
inline constexpr TPU operator()(type_elem c) const { | ||
return make_helper([c](auto) { return c; }, | ||
std::make_index_sequence<size>{}); | ||
} | ||
// explicit overloading for int constants | ||
inline constexpr TPU operator()(int c) const { | ||
return operator()(type_elem(c)); | ||
} | ||
inline constexpr TPU operator()(size_t c) const { | ||
return operator()(type_elem(c)); | ||
} | ||
|
||
/** Return the identity element of type \c TPU | ||
*/ | ||
constexpr TPU id() const { return operator()([](type_elem i) { return i; }); } | ||
/** Return reversed element of type \c TPU | ||
*/ | ||
constexpr TPU rev() const { | ||
return (*this)([](type_elem i) { return size - 1 - i; }); | ||
} | ||
constexpr TPU left_cycle() const { | ||
return (*this)([](type_elem i) { return (i + size - 1) % size; }); | ||
} | ||
constexpr TPU right_cycle() const { | ||
return (*this)([](type_elem i) { return (i + 1) % size; }); | ||
} | ||
constexpr TPU left_dup() const { | ||
return (*this)([](type_elem i) { return i == 15 ? 15 : i + 1; }); | ||
} | ||
constexpr TPU right_dup() const { | ||
return (*this)([](type_elem i) { return i == 0 ? 0 : i - 1; }); | ||
} | ||
constexpr TPU popcount() const { | ||
return (*this)([](type_elem i) { | ||
return (((i & 0x01) != 0 ? 1 : 0) + ((i & 0x02) != 0 ? 1 : 0) + | ||
((i & 0x04) != 0 ? 1 : 0) + ((i & 0x08) != 0 ? 1 : 0) + | ||
((i & 0x10) != 0 ? 1 : 0) + ((i & 0x20) != 0 ? 1 : 0) + | ||
((i & 0x40) != 0 ? 1 : 0) + ((i & 0x80) != 0 ? 1 : 0)); | ||
}); | ||
} | ||
}; | ||
|
||
#endif // HPCOMBI_BUILDER_HPP_INCLUDED |
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.