Add convertFloatToFixed to FloatVectorOperations to vectorized truncate a float buffer?


#1

Hi,
The FloatVectorOperations class is totally great. But can I request a convertFloatToFixed method in addition to convertFixedToFloat (probably based on _mm_cvttps_epi32)? This would be very helpful to get the fractional parts (trunc) of all floats in a buffer to e.g. implement vectorized linear interpolation. Or is there another way of doing this with the existing methods?
Thanks, Tobias


FloatVectorOperations Divide
#2

Hi there,

I found a solution that works for me. I subclased FloatVectorOperations and added a method that gives me that fractional part of the float vector values, e.g. similar to modf(). Here is the code:

	void JUCE_CALLTYPE FloatVectorOperations::getFraction(float* dest, const float* src, int num) noexcept
	{
#if JUCE_USE_VDSP_FRAMEWORK
		//??
#else
		JUCE_PERFORM_VEC_OP_SRC_DEST(dest[i] = src[i] - int(src[i]),
			Mode::sub(s, _mm_cvtepi32_ps(_mm_cvttps_epi32(_mm_loadu_ps(src)))),
			JUCE_LOAD_SRC, JUCE_INCREMENT_SRC_DEST)
#endif
	}

Don’t know if this is the best way of doing it but it works and seems to be fast. I have no idea about the VDSP implementation though. Any chances to add something like this to the standard?

Best regards,
Tobias