LinearSmoothedValue feature request - alignment issue


#1

Hello,

I’m using the LinearSmoothedValue class with classes representing SIMD registers. In Xcode this is fine but on MSVC the constructor and setValue() methods have arguments passed by value, which can’t be aligned (apparently) and references or pointers need to be used.

Could these use the PARAMETER_TYPE macro like this:

    LinearSmoothedValue (PARAMETER_TYPE (FloatType) initialValue) noexcept
        : currentValue (initialValue), target (initialValue), step (0), countdown (0), stepsToTarget (0)
    {
    }
    /** Set a new target value. */
    void setValue (PARAMETER_TYPE (FloatType) newValue) noexcept
    {
        if (target != newValue)
        {
            target = newValue;
            countdown = stepsToTarget;

            if (countdown <= 0)
                currentValue = target;
            else
                step = (target - currentValue) / (FloatType) countdown;
        }
    }

#2

Is your FloatType parameter a SIMD class that you wrote? If yes, have you tried adding the alignment declspec to your SIMD class definition:

__declspec(align(32)) struct MySIMDType
{
     .
     .
     .
};

#3

Hi Fabian,

Yes, I have some cross-platform macros that ensure the alignment like that and I’m using constructors that align the memory allocation of new for the class (e.g., _mm_malloc (numBytes, 32) etc…

When allocating on the heap and storing as members of other classes the alignment works.

The issue is only with passing arguments to functions in MSVC:

The solution seems to be to have to pass by pointer or reference. My suggested change might uglier than the original but will result in identical code for the float and double types. But for classes it will pass by reference. I’ve tried this and MSVC works (I was previously getting seg faults where the alignment was sometimes landing on 8 rather than 16 bytes).