pub enum Contract {
Off,
On,
Fast,
}Expand description
How far a multiply and an addition may be fused into one rounding, from -ffp-contract=.
A fused multiply add computes a * b + c with one rounding instead of two, which is both
faster and closer to the exact answer, and is therefore a different answer. C lets an
implementation do it within one expression and lets a program turn it off with the
FP_CONTRACT pragma, gcc does it across a whole function by default, and code that cares about
reproducing a result bit for bit turns it off everywhere.
This is the command line’s answer to that question, and it is carried into the IR as an attribute on each function so that the code generator still has it by the time it would matter. It is a separate question from the flag on one instruction: a licence granted to an expression the optimizer has since taken apart is a licence about operations that no longer sit together, and only the function level answer survives that.
Variants§
Off
-ffp-contract=off. Never, so every rounding the source asked for happens.
The default here, which is not gcc’s. gcc defaults to fast under its own dialects and to
off under a strict -std=, and the reason the default is this one anyway is that nothing
in this compiler fuses anything: the two settings are the same program today, and of the two
this is the one that does not write a licence nobody reads onto every function in the file.
The day the code generator learns to fuse, the default moves to gcc’s, and that is a change
to the code generator rather than to this flag.
On
-ffp-contract=on. Within one expression, which is what C allows an implementation to do
without being asked.
Fast
-ffp-contract=fast. Anywhere in the function, across statements and across whatever the
optimizer has rearranged, which is what gcc does under its own dialects.