Using mask with aligned_store not working
bmmogensen opened this issue · 6 comments
Hello NumScale,
I've noticed a problem when using masks together with aligned_store. It does not appear to actually store the values if the stored argument is a masked pointer. The expected behaviour is that it will store the values (and check if the data is actually aligned in debug mode).
A small example is given below:
#include <array>
#include <iostream>
#include <boost/simd.hpp>
#include <boost/simd/mask.hpp>
#include <boost/simd/function/aligned_store.hpp>
#include <boost/simd/function/store.hpp>
namespace bs = boost::simd;
int main()
{
alignas(32) std::array<double,4> datasrc = {{1.0,2.0,3.0,4.0}};
using value_type = bs::pack<double, 4>;
using mask_type = bs::as_logical_t<value_type>;
alignas(32) std::array<bs::logical<double>, 4> masksrc = { { true,false,false,true } };
std::cout << "original array: "; std::for_each(datasrc.begin(), datasrc.end(), [](auto val) {std::cout << val << ", "; });std::cout << std::endl;
std::cout << "applied mask : "; std::for_each(masksrc.begin(), masksrc.end(), [](auto val) {std::cout << val << ", "; });std::cout << std::endl;
bs::aligned_store(bs::Zero<value_type>(), bs::mask(datasrc.data(), mask_type(masksrc.data())));//store 0 with mask
std::cout << "aligned_store : " ; std::for_each(datasrc.begin(), datasrc.end(), [](auto val) {std::cout << val << ", "; }); std::cout << std::endl;
bs::store(bs::Zero<value_type>(), bs::mask(datasrc.data(), mask_type(masksrc.data())));//store 0 with mask
std::cout << "store : " ; std::for_each(datasrc.begin(), datasrc.end(), [](auto val) {std::cout << val << ", "; }); std::cout << std::endl;
return 0;
}
Output:
original array: 1, 2, 3, 4,
applied mask: true, false, false, true,
aligned_store: 1, 2, 3, 4,
store : 0, 2, 3, 0,
Whereas the boost::simd::store function appears to have the relevant implementation in the file:
\include\boost\simd\arch\common\simd\function\store\mask.hpp
The template specialization for a masked store operation does not appear to exist for boost::simd::aligned_store. However, rather than throwing an error, the code compiles, but does not perform the expected store operation.
Best regards,
Bjorn
Not sure aligned_store is supposed to mask. Does store works ?
Well, the store function does work as seen in the above example, and even if aligned_store should not work, then the example should still not compile. The masked store stores a 0 in location 0 and 3.
Reg. the use of for_each: Good point, but I just wanted to keep clear of calling other functions than store/aligned_store.
I think I know what's going on. Looking at the Intel intrinsics, I think both should be available. We'll add those soon.
Sounds great. Thanks for the quick response :)
Care to check if branch issue_481-aligned_store_with_mask fix it for you ?
Yes, that fixed it. Thanks.