summaryrefslogtreecommitdiff
path: root/testsuite/tests/asmcomp/prevent_fma.ml
blob: 6ce124fce0a96a140c9f05085e60bc280fb5f33b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(* TEST
  * native
*)

let ( *. ) x y = Sys.opaque_identity (x *. y)
(* Using opaque_identity should prevent use of FMA. *)

let f x = (x *. x -. x *. x)
    (* The expression above can be compiled in two ways:
       1. First evaluating x' = x *. x, then x' -. x'
       The result is obviously zero.
       2. First evaluating x' = x *. x, then x *. x -. x' as a single evaluation
       step, using fused-multiply-add (or rather sub here).
       FMA computes with increased precision because no rounding of the
       intermediate computation happens.
       In this case, the result is not always exactly 0.

       See issue #10323. *)


let () =
  assert (Int64.bits_of_float (f (sqrt 2.0)) = 0L)