maths icon indicating copy to clipboard operation
maths copied to clipboard

Alignment 16 for Vec3f for better simd instructions?

Open RicoP opened this issue 3 years ago • 4 comments

I was wondering could a explicit alignment attribute for Vec3f improve code generation for SIMD instructions?

#ifdef _WIN32
__declspec(align(16))
#else
__attribute__ ((aligned (16)))
#endif
typedef Vec<3, float>          Vec3f;

RicoP avatar Dec 01 '21 13:12 RicoP

yeah if you have a use case for it and the codegen is better, seems like something other people might like as well.

I am using vec3f in other code bases which might be packed in structs so possibly something like AlignedVec3 type? or we could enable on a macro? just so it's not going to break existing code.

do you have any example code showing the improvement in codegen for the aligned types?

polymonster avatar Dec 01 '21 15:12 polymonster

I yet have to do some digging and struct packing in my engine before can say if this is going to make a real difference.

RicoP avatar Dec 01 '21 16:12 RicoP

but it seems like you can't align a typedef :/

RicoP avatar Dec 01 '21 16:12 RicoP

would be good to get some test cases where it shows improvement and then its worth digging into what would be a nice way to add this support. Easiest way is just to enable the alignment on a macro so you can choose to use aligned or not

polymonster avatar Dec 01 '21 16:12 polymonster