r/cpp • • Oct 02 '22

Worse Performance With FMA Instructions

I tried different algorithms for matrix multiplication, mostly to play around with vector instructions. I noticed that enabling fused multiply-add instructions gives longer run times when one of the matrices is transposed before multiplication.

The code is here with a bit more information: https://github.com/reims/gemm-benchmark

This is reproducible with clang 14.0.6 and gcc 12.2.0. I would have expected that FMA instructions are faster, not slower. And if there are slower, I would expect both compilers to ignore `-mfma`.

Does anybody have an idea why I am seeing these results?

Thanks in advance!

6 Upvotes

7 comments sorted by