I am multiplying constant vector<bool> on different vector<double> many times. I wonder how fast is that, wouldn’t it be faster to convert it first to vector<double>, so that sse can be used?
void applyMask(std::vector<double>& frame, const std::vector<bool>& mask)
{
std::transform(frame.begin(), frame.end(), mask.begin(), frame.begin(), [](const double& x, const bool& m)->double{ return x*m;});
}
It seems like you’re trying to zero parts of a
vector<double>using a mask ofvector<bool>.As it stands right now, it’s not vectorizable. Furthermore, the
vector<bool>template specialization is going to hinder the compiler’s ability to do any sort of auto-vectorization.So you basically have two options:
The easy way is to indeed convert the
vector<bool>to avector<double>of corresponding zeros and ones. Then the problem reduces to simply vector-to-vector multiplication of the same datatype, which is completely vectorizable. (even auto-vectorizable)The harder way (which might be faster), is to play some hacks with the
_mm_and_pdor_mm_blendv_pd()intrinsics/instructions. But that requires a lot more work since you have to manually vectorize the code.I suggest you just go with the easy way. No need to dive into manual vectorization unless you really need to.