SIMDRegister: how to set a mask manually. [solved]

Sofar I have used masks created automatically via
auto myMask = x.greaterThan(x, y); // x and y are simdregisters.
Now I want to set a mask myself and I dont know how to declare them, could find no example.
Something like:
juce::dsp::SIMDRegister<??????> sign_mask(0x80000000);

Here is the answer, for other people searching for it. not tested yet, just correct me when I’m wrong here…


// A few defines for easy reading
#define vektor juce::dsp::SIMDRegister<float>
#define vektorMask juce::dsp::SIMDRegister<float>::vMaskType

// test
vektor valueOne(-1);
vektorMask absolute_mask(0x7FFFFFFF);
vektor absoluteValue =  valueOne & absolute_mask;

Just for the record, you should avoid macros in C++ code if possible, since C++ offers you a lot options to do the same in a safer way without the preprocessor. Benefits are type safety, namespaces no risk to shadow other symbols and better readable compiler errors in case something goes wrong. So you should better go for

// A few type aliases for easy reading
using vektor = juce::dsp::SIMDRegister<float>;
using vektorMask = juce::dsp::SIMDRegister<float>::vMaskType;

// test
vektor valueOne(-1);
vektorMask absolute_mask(0x7FFFFFFF);
auto absoluteValue =  valueOne & absolute_mask;
1 Like

yes i know, I noticed people using USING nowadays. it is just a habit of mine from my microcontroller days… I’ll adapt :wink:

1 Like