Using comparisons of the Vector Engine
Submitted by Christoph Keller
Assigned to Christoph Keller
Link to original bugzilla bug (#97)
Version: 3.3 (current stable)
Description
At least the most use vector extensions SSE and AVX do have comparison instructions. These currently cannot be used by the Eigen-User in a useful way.
To use them one has to consider:
--Different formats for booleans
In AVX only the highest bit counts when using select assembler instructions
In SSE one uses bitmasks
Without using extensions an int is true if it's nonzero
--Different Sizes for booleans
booleans have the size of the scalar
--Using the FPU/Interger Unit
xor/or/and operations withe these boolean can be done in the integer/floating point unit of the processor. Getting them from the integer unit to the fp unit takes up to 2 cycles. The programmer should have a way to control this.
In order to adress these issues the boolean type in Eigen needs to have a format description. The best way to do this may be templates.
template <Scalartype (int/float/double), Vectorengine>
EigenBool {...}
This adresses the first two issues. One can partially specialize these to get the size right.
This type can then be used with some useful operations like
EigenBool.select(a,b)
Basically the Scalartype of the EigenBool selects the Processor unit to use (FPU/Integer), so the typical user is not bothered by problem 3.
One should be able to store the EigenBools in memory.
And/Or/Xor should be usable
If only the highest bit count like in AVX, then one could convert float to EigenBool<float,AVX> without any cost and this should be possible.
These operations can all be Expression Templates.
I think if everything is done right, then the user has very fast comparisons in the usual clean-and-easy-to-use Eigen way.
So the question is: How to implement this exactly? One could add operators | & ^ to Matrixbase, but using a special type for this is much more elegant.