AVX2 with JUCE



I’ve been developing a plugin and I’ve been trying to use AVX2 for optimisation. When I try to build it in xcode it gives me the following error message:

Always_inline function ‘_mm256_load_ps’ requires target feature ‘sse4.2’, but would be inlined into function ‘processBlock’ that is compiled without support for ‘sse4.2’

I am currently including <immintrin.h> and have configured “Enable Additional Vector Extensions” to AVX2, but neither of these resolve the issue.

Could someone tell whether it is possible to use AVX instructions within JUCE and if so how?
Is it something that has to be changed or added in the Projucer configuration-specific build settings?


Yes, it’s certainly possible. From the error message I suspect that you’ve not enabled AVX2 extensions for all the targets in your solution. Try setting the “Enable Additional Vector Extensions” option for the “Shared Code” target as well as “VST”, “VST3”, …


Bear in mind this will compile the whole target for AVX, so only newer computers can use the plugin.

Apple clang made a breaking change by turning this into an error. Previously, you could mix any instruction set with any global setting, such that you could have a optimized code paths for specific instructions sets. Unfortunately, this can no longer be done, unless you compile separate binaries for each code path. Probably also why JUCE won’t have AVX nor AVX2 nor AVX512 support for FloatVectorOperations, etc…

You can make the error go away using the target() __attribute__, but your code will be dead slow, as clang creates sse/avx transitions each instruction.


Thank you for the advices, I managed to solve the issue!