From d072c5998bd5b9431323ec25974d8bdf6664387a Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Sat, 29 Aug 2015 19:07:41 -0700 Subject: [PATCH 1/2] Add min and max operators. --- ml-proto/src/arithmetic.ml | 2 ++ ml-proto/src/ast.ml | 2 +- ml-proto/src/lexer.mll | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ml-proto/src/arithmetic.ml b/ml-proto/src/arithmetic.ml index cc3397ab05..e3a1ff7c66 100644 --- a/ml-proto/src/arithmetic.ml +++ b/ml-proto/src/arithmetic.ml @@ -196,6 +196,8 @@ struct | Mul -> ( *.) | Div -> (/.) | CopySign -> copysign + | Min -> fun _ _ -> 0.0 (* TODO *) + | Max -> fun _ _ -> 0.0 (* TODO *) in fun v1 v2 -> Float.to_value (f (Float.of_value 1 v1) (Float.of_value 2 v2)) diff --git a/ml-proto/src/ast.ml b/ml-proto/src/ast.ml index 668f42d33a..18fc33dc14 100644 --- a/ml-proto/src/ast.ml +++ b/ml-proto/src/ast.ml @@ -44,7 +44,7 @@ end module FloatOp () = struct type unop = Neg | Abs | Ceil | Floor | Trunc | Nearest | Sqrt - type binop = Add | Sub | Mul | Div | CopySign + type binop = Add | Sub | Mul | Div | CopySign | Min | Max type relop = Eq | Neq | Lt | Le | Gt | Ge type cvt = ToInt32S | ToInt32U | ToInt64S | ToInt64U | ToIntCast | ToFloat32 | ToFloat64 diff --git a/ml-proto/src/lexer.mll b/ml-proto/src/lexer.mll index 313fa8726f..a62765e2ff 100644 --- a/ml-proto/src/lexer.mll +++ b/ml-proto/src/lexer.mll @@ -193,6 +193,8 @@ rule token = parse | "mul."(fxx as t) { BINARY (floatop t F32.Mul F64.Mul) } | "div."(fxx as t) { BINARY (floatop t F32.Div F64.Div) } | "copysign."(fxx as t) { BINARY (floatop t F32.CopySign F64.CopySign) } + | "min."(fxx as t) { BINARY (floatop t F32.Min F64.Min) } + | "max."(fxx as t) { BINARY (floatop t F32.Max F64.Max) } | "eq."(ixx as t) { COMPARE (intop t I32.Eq I64.Eq) } | "neq."(ixx as t) { COMPARE (intop t I32.Neq I64.Neq) } From 745505879e3c471226ac10ab46239a43c7a93868 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 2 Sep 2015 19:38:19 -0700 Subject: [PATCH 2/2] Add temporary approximative implementations of min and max. --- ml-proto/src/arithmetic.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ml-proto/src/arithmetic.ml b/ml-proto/src/arithmetic.ml index e3a1ff7c66..517b945c30 100644 --- a/ml-proto/src/arithmetic.ml +++ b/ml-proto/src/arithmetic.ml @@ -196,8 +196,8 @@ struct | Mul -> ( *.) | Div -> (/.) | CopySign -> copysign - | Min -> fun _ _ -> 0.0 (* TODO *) - | Max -> fun _ _ -> 0.0 (* TODO *) + | Min -> min + | Max -> max in fun v1 v2 -> Float.to_value (f (Float.of_value 1 v1) (Float.of_value 2 v2))