I think you will probably need to use a union for this, for example:
union U { __m256 v; float a[8]; };
and the value operator will be:
float operator[](int idx) const { U u = { v }; return ua[idx]; }
The link operator is more complex, and the only way I can do this is to use the punning function, so with the usual caveats:
float& operator[](int idx) { return ((float *)&v)[idx]; }
I'm not even sure if this -fno-strict-aliasing and you might need -fno-strict-aliasing .
To avoid this nastiness, I suppose you could consider changing the member variable from __m256 v; to U u; .
I just hope that you are not doing this kind of thing inside any critical cycles.
source share