Having a C++ simd library in Blender would be great.
I was also playing with this idea in the past and lately again after reading this. It triggered me to add SIMDe to compiler explorer to make some experiments easier.
I’m not sure what the right approach is. Lately, I was thinking that it would be good to build a C++ library on top of SIMDe, but I’m not sure. There seem to be two main approaches to implementing such a library:
- Provide C++ wrappers for specific cpu architectures. This is what is done in Cycles with the
seei
,avxf
, etc. types. - Provide C++ wrappers for generic vector types such as packed floats. This seems to be the approach of the experimental simd library linked to by Jeroen.
Having generic vector types is nice and might be the way to go for Blender. However, there will always be the need to use architecture specific intrinsics when really optimizing something… In most other cases, auto-vectorization might be good enough already.
I experimented with one approach to writing a C++ simd library last year. I had types like float_v<N>
and int32_v<N>
with specializations for different N
. I’m still not sure if that approach was good.
@brecht, I’m not familiar with Embree, can you give me a link to a file that shows how its simd abstraction works?
I think it is important that float3
in BLI_float3.hh
is really just struct float3 { float x, y, z; }
. It should not have special alignment requirements. Also sizeof(float3)
should remain 12. Without these requirements, it would be much harder to use this type when interacting with other Blender data. When I have an array of float3
, I expect that there are really only 3 floats, and not 4 per element. I wrote a bit more about this here.
That sounds good.