Extending SIMDRegister

Hi everyone,

I’ve started porting some of my code to the JUCE DSP framework and have realized that I need some operations in the SIMDRegister class that do not exist yet (things like bit shift operations etc.). For now I’m simply editing juce_SIMDRegister.h, as well as all the juce_xxx_SIMDNativeOps.h files.

However, that seems a bit awkward. Is there any better approach? Would subclassing SIMDRegister negatively impact performance?

I also have some specific questions regarding SIMDRegister:

  1. Certain intrinsics work only with immediate values (constants known at compile time). Is there a way to implement for example a shift right method for SIMDRegister that takes a constant argument? I tried all sorts of combinations of keywords but didn’t succeed so far to make the compiler understand that an argument must be a compile-time constant…

  2. Is there a way to implement a method in SIMDRegister that computes a value v based on the register’s current value, then changes the register’s value and returns v? When I try to implement this, it fails because I can’t return a reference to a local variable (v).

Thanks in advance for any help with this!


Ok, point 2 is resolved: it’s not necessary to return a reference to SIMDRegister, a new object does the job, too. In fact I simply based my method on the wrong template.

On point 1 I’m still stuck. And on the general question how to best add custom methods to SIMDRegister without modifying the original source code.

You could presumably add free functions to operate on them, but TBH if you’ve got some solid, cross-platform implementations for functions that are missing (and which do actually belong in there!) then we should probably add them!

Hi Jules,

Sure I don’t mind sharing the extensions I’m making. At the moment they’re not completely cross-platform yet (I don’t have an AVX2 capable machine to test with, so at the moment I’m focusing on SSE and NEON), and some of the methods I’ve implemented are really specific, like a kind of bit-wise FIFO in every element used to pack binary data (useful for cellular automaton implementations). Not sure if you want this kind of things in your code base. :wink:

Well, that leaves the issue with intrisics with immediate parameters. I guess I could make a huge switch statement for any suitable value of the parameter and the compiler will automatically eliminate the switch statement if the parameter is a constant. But that seems to be quite an ugly solution to me. Does anyone have a better suggestion?