Skip to content

Commit

Permalink
Fixed kernel::store for booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanMabille authored and serge-sans-paille committed Feb 24, 2025
1 parent 339fade commit b3c882c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion include/xsimd/arch/generic/xsimd_generic_memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ namespace xsimd
}

// store
template <class T, class A>
template <class A, class T>
XSIMD_INLINE void store(batch_bool<T, A> const& self, bool* mem, requires_arch<generic>) noexcept
{
using batch_type = batch<T, A>;
Expand Down
39 changes: 29 additions & 10 deletions test/test_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "xsimd/xsimd.hpp"
#ifndef XSIMD_NO_SUPPORTED_ARCHITECTURE

#include <functional>
#include <numeric>
#include <random>

#include "test_utils.hpp"
Expand All @@ -20,6 +22,7 @@ template <class B>
struct xsimd_api_test
{
using batch_type = B;
using batch_bool_type = typename B::batch_bool_type;
using value_type = typename B::value_type;
static constexpr size_t size = B::size;
using array_type = std::array<value_type, size>;
Expand Down Expand Up @@ -81,17 +84,17 @@ struct xsimd_api_test

void test_store()
{
test_store_impl(i8_vec, "load int8_t");
test_store_impl(ui8_vec, "load uint8_t");
test_store_impl(i16_vec, "load int16_t");
test_store_impl(ui16_vec, "load uint16_t");
test_store_impl(i32_vec, "load int32_t");
test_store_impl(ui32_vec, "load uint32_t");
test_store_impl(i64_vec, "load int64_t");
test_store_impl(ui64_vec, "load uint64_t");
test_store_impl(f_vec, "load float");
test_store_impl(i8_vec, "store int8_t");
test_store_impl(ui8_vec, "store uint8_t");
test_store_impl(i16_vec, "store int16_t");
test_store_impl(ui16_vec, "store uint16_t");
test_store_impl(i32_vec, "store int32_t");
test_store_impl(ui32_vec, "store uint32_t");
test_store_impl(i64_vec, "store int64_t");
test_store_impl(ui64_vec, "store uint64_t");
test_store_impl(f_vec, "store float");
#if XSIMD_WITH_NEON64 || !XSIMD_WITH_NEON
test_store_impl(d_vec, "load double");
test_store_impl(d_vec, "store double");
#endif
}

Expand Down Expand Up @@ -133,13 +136,29 @@ struct xsimd_api_test
batch_type b = batch_type::load(v.data(), xsimd::aligned_mode());
V res(size);

bool* b_data = new bool[size];

xsimd::store_as(res.data(), b, xsimd::unaligned_mode());
INFO(name, " unaligned");
CHECK_VECTOR_EQ(res, v);

std::fill(b_data, b_data + size, false);
batch_bool_type bb = (b == b);
xsimd::store_as(b_data, bb, xsimd::unaligned_mode());
INFO(name, " batch_bool unaligned");
CHECK_UNARY(std::accumulate(b_data, b_data + size, true, std::logical_and<bool>()));

xsimd::store_as(res.data(), b, xsimd::aligned_mode());
INFO(name, " aligned");
CHECK_VECTOR_EQ(res, v);

std::fill(b_data, b_data + size, false);
bb = (b == b);
xsimd::store_as(b_data, bb, xsimd::aligned_mode());
INFO(name, " batch_bool aligned");
CHECK_UNARY(std::accumulate(b_data, b_data + size, true, std::logical_and<bool>()));

delete[] b_data;
}

template <class T>
Expand Down

0 comments on commit b3c882c

Please sign in to comment.