Commit feef57e6 authored by Peter Steinbach's avatar Peter Steinbach

added accumulate function that can scan for multiple features at once

and store them into an integer
parent d6db78aa
......@@ -58,6 +58,40 @@ namespace compass {
}
namespace detail {
static std::uint32_t accumulate(std::uint32_t value){
return value;
}
template < typename T, typename... features_t >
static std::uint32_t accumulate(std::uint32_t value,
T head,
features_t... tail)
{
std::uint32_t local = compass::runtime::has(head);
value = (value <<= 1) | local;
return accumulate(value,tail...);
}
};
template <typename... feature_t>
static std::uint32_t accumulate(feature_t... features) {
static const int pack_size = sizeof...(features);
static_assert(pack_size <= 32, "[compass::runtime::accumulate] unable to handle more than 32 features" );
std::uint32_t value = compass::runtime::detail::accumulate( 0u, features...);
return value;
}
namespace size {
struct cacheline{
......
......@@ -3,6 +3,7 @@
#include "compass.hpp"
#include <bitset>
#include <vector>
#include <iostream>
#include <string>
......@@ -115,6 +116,20 @@ TEST_CASE_METHOD( host_reference, "machine_specific" ){
}
SECTION( "has_multiple_features" ){
auto value = compass::runtime::accumulate(compass::feature::avx(),compass::feature::sse4(),compass::feature::sse3());
const bool expected = (expected_has_avx || expected_has_sse4 || expected_has_sse3 );
REQUIRE(bool(value) == expected );
std::bitset<3> mask((unsigned long)value);
REQUIRE(mask[0] == expected_has_avx);
REQUIRE(mask[1] == expected_has_sse4);
REQUIRE(mask[2] == expected_has_sse3);
}
SECTION( "has_avx2_right" ){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment