Skip to content
  • sheaf's avatar
    Add fused multiply-add instructions · 87eebf98
    sheaf authored and Marge Bot's avatar Marge Bot committed
    This patch adds eight new primops that fuse a multiplication and an
    addition or subtraction:
    
      - `{fmadd,fmsub,fnmadd,fnmsub}{Float,Double}#`
    
    fmadd x y z is x * y + z, computed with a single rounding step.
    
    This patch implements code generation for these primops in the following
    backends:
    
      - X86, AArch64 and PowerPC NCG,
      - LLVM
      - C
    
    WASM uses the C implementation. The primops are unsupported in the
    JavaScript backend.
    
    The following constant folding rules are also provided:
    
      - compute a * b + c when a, b, c are all literals,
      - x * y + 0 ==> x * y,
      - ±1 * y + z ==> z ± y and x * ±1 + z ==> z ± x.
    
    NB: the constant folding rules incorrectly handle signed zero.
    This is a known limitation with GHC's floating-point constant folding
    rules (#21227), which we hope to resolve in the future.
    87eebf98