summaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorLaurent Thévenoux <laurent.thevenoux@gmail.com>2018-10-26 10:45:36 +0200
committerAlain Frisch <alain@frisch.fr>2018-10-26 10:45:36 +0200
commitdb99969bc8f1c4f244526dea556bb4d2550c2a02 (patch)
tree4be9206f873c44a6b133518ff18cfe4799e1c146 /stdlib
parent6eea292727c2b47ed17fc5fa1ed09725eaed7948 (diff)
downloadocaml-db99969bc8f1c4f244526dea556bb4d2550c2a02.tar.gz
Support FMA operation (#1354)
Adds a fused multiply-add operation to the Float module. The following changes are made: - configure: check math.h for the C99 fma() operation. - fma declarations in float.ml[i] (stdlib/). - C fma() call or emulation in runtime/floats.c. - dedicated tests in testsuite/tests/fma.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/float.ml2
-rw-r--r--stdlib/float.mli9
2 files changed, 11 insertions, 0 deletions
diff --git a/stdlib/float.ml b/stdlib/float.ml
index f51275faf3..e5a4d52718 100644
--- a/stdlib/float.ml
+++ b/stdlib/float.ml
@@ -21,6 +21,8 @@ external mul : float -> float -> float = "%mulfloat"
external div : float -> float -> float = "%divfloat"
external rem : float -> float -> float = "caml_fmod_float" "fmod"
[@@unboxed] [@@noalloc]
+external fma : float -> float -> float -> float = "caml_fma_float" "caml_fma"
+ [@@unboxed] [@@noalloc]
external abs : float -> float = "%absfloat"
let zero = 0.
diff --git a/stdlib/float.mli b/stdlib/float.mli
index b8a9094335..38386e0256 100644
--- a/stdlib/float.mli
+++ b/stdlib/float.mli
@@ -57,6 +57,15 @@ external mul : float -> float -> float = "%mulfloat"
external div : float -> float -> float = "%divfloat"
(** Floating-point division. *)
+external fma : float -> float -> float -> float =
+ "caml_fma_float" "caml_fma" [@@unboxed] [@@noalloc]
+(** [fma x y z] returns [x * y + z], with a best effort for computing
+ this expression with a single rounding, using either hardware
+ instructions (providing full IEEE compliance) or a software
+ emulation. Note: since software emulation of the fma is costly,
+ make sure that you are using hardware fma support if performance
+ matters. @since 4.08.0 *)
+
external rem : float -> float -> float = "caml_fmod_float" "fmod"
[@@unboxed] [@@noalloc]
(** [rem a b] returns the remainder of [a] with respect to [b]. The returned