Given the following C code,
double a = 4.00;
double b = 123.456789;
double c = 15.123;
double res = a*b + c;
return res;
compiling with riscv64-linux-gcc -g -o2
generates the following
double res = a*b + c;
102e8: fe843707 fld fa4,-24(s0)
102ec: fe043787 fld fa5,-32(s0)
102f0: 12f777d3 fmul.d fa5,fa4,fa5
102f4: fd843707 fld fa4,-40(s0)
102f8: 02f777d3 fadd.d fa5,fa4,fa5
102fc: fcf43827 fsd fa5,-48(s0)
Meaning that the compiler did not recognize that this is a fused multiplication/addition operation (FMADD
).
So, I have two questions:
Is there a means to force the compiler to generate
FMADD.D
instead of the separateMUL.D
andADD.D
instructions?What mad the compiler choose to implement it this way?
(from what I know, FMA
is generally more efficient that separate MUL
and ADD
, and also, 1 instruction is generally more efficient than 2 from a power and speed point of view, so I'm a little bit confused about the choices being made by GCC)