Skip to content

Commit bbe1c77

Browse files
committed
Add fp.fma operator
1 parent d7dbf7e commit bbe1c77

File tree

9 files changed

+32
-0
lines changed

9 files changed

+32
-0
lines changed

src/smtml/bitwuzla_mappings.default.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@ module Fresh_bitwuzla (B : Bitwuzla_cxx.S) : M = struct
386386

387387
let max t1 t2 = mk_term2 Kind.Fp_max t1 t2
388388

389+
let fma ~rm a b c = mk_term Kind.Fp_fma [| rm; a; b; c |]
390+
389391
let rem t1 t2 = mk_term2 Kind.Fp_rem t1 t2
390392

391393
let eq t1 t2 = mk_term2 Kind.Fp_equal t1 t2

src/smtml/cvc5_mappings.default.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ module Fresh_cvc5 () = struct
373373

374374
let max t1 t2 = Term.mk_term tm Kind.Floatingpoint_max [| t1; t2 |]
375375

376+
let fma ~rm a b c = Term.mk_term Kind.Floatingpoint_fma [| rm; a; b; c |]
377+
376378
let rem t1 t2 = Term.mk_term tm Kind.Floatingpoint_rem [| t1; t2 |]
377379

378380
let eq t1 t2 = Term.mk_term tm Kind.Floatingpoint_eq [| t1; t2 |]

src/smtml/dolmenexpr_to_expr.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ module DolmenIntf = struct
325325

326326
let div ~rm t1 t2 = DTerm.Float.div rm t1 t2
327327

328+
let fma ~rm a b c = DTerm.Float.fma rm a b c
329+
328330
let le = DTerm.Float.leq
329331

330332
let ge = DTerm.Float.geq

src/smtml/dolmenexpr_to_expr.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ module DolmenIntf : sig
302302

303303
val rem : term -> term -> term
304304

305+
val fma : rm:term -> term -> term -> term -> term
306+
305307
val eq : term -> term -> term
306308

307309
val lt : term -> term -> term

src/smtml/mappings.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,12 @@ module Make (M_with_make : M_with_make) : S_with_fresh = struct
699699
let ctx, b = encode_expr ctx b in
700700
let rm = get_rounding_mode rm in
701701
(ctx, M.Float.div ~rm a b)
702+
| App ({ name = Simple "fp.fma"; _ }, [ rm; a; b; c ]) ->
703+
let ctx, a = encode_expr ctx a in
704+
let ctx, b = encode_expr ctx b in
705+
let ctx, c = encode_expr ctx c in
706+
let rm = get_rounding_mode rm in
707+
(ctx, M.Float.fma ~rm a b c)
702708
| App ({ name = Simple "fp.sqrt"; _ }, [ rm; a ]) ->
703709
let ctx, a = encode_expr ctx a in
704710
let rm = get_rounding_mode rm in

src/smtml/mappings.nop.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ module Nop = struct
299299

300300
let rem _ = assert false
301301

302+
let fma ~rm:_ = assert false
303+
302304
let eq _ = assert false
303305

304306
let lt _ = assert false

src/smtml/mappings_intf.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ module type M = sig
527527
[t2]. *)
528528
val max : term -> term -> term
529529

530+
(** [fma ~rm a b c] *)
531+
val fma : rm:term -> term -> term -> term -> term
532+
530533
(** [rem t1 t2] constructs the remainder of the floating-point terms [t1]
531534
and [t2]. *)
532535
val rem : term -> term -> term

src/smtml/rewrite.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ let rewrite_ty unknown_ty tys =
2828
debug " rewrite_ty: %a %a@." (fun k -> k Ty.pp ty1 Ty.pp ty2);
2929
assert (Ty.equal ty1 ty2);
3030
ty1
31+
| Ty_none, ty1 :: ty2 :: [ ty3 ] ->
32+
debug " rewrite_ty: %a %a %a@." (fun k -> k Ty.pp ty1 Ty.pp ty2 Ty.pp ty3);
33+
assert (Ty.equal ty1 ty2);
34+
assert (Ty.equal ty2 ty3);
35+
ty1
3136
| Ty_none, _ -> assert false
3237
| ty, _ -> ty
3338

@@ -54,6 +59,12 @@ let rec rewrite_expr (type_map, expr_map) hte =
5459
let b = rewrite_expr (type_map, expr_map) b in
5560
let ty = rewrite_ty Ty_none [ Expr.ty a; Expr.ty b ] in
5661
Expr.app { sym with ty } [ rm; a; b ]
62+
| App (({ name = Simple "fp.fma"; _ } as sym), [ rm; a; b; c ]) ->
63+
let a = rewrite_expr (type_map, expr_map) a in
64+
let b = rewrite_expr (type_map, expr_map) b in
65+
let c = rewrite_expr (type_map, expr_map) c in
66+
let ty = rewrite_ty Ty_none [ Expr.ty a; Expr.ty b; Expr.ty c ] in
67+
Expr.app { sym with ty } [ rm; a; b; c ]
5768
| App
5869
( ({ name = Simple ("fp.sqrt" | "fp.roundToIntegral"); _ } as sym)
5970
, [ rm; a ] ) ->

src/smtml/z3_mappings.default.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ module M = struct
363363

364364
let max e1 e2 = Z3.FloatingPoint.mk_max ctx e1 e2
365365

366+
let fma ~rm a b c = Z3.FloatingPoint.mk_fma ctx rm a b c
367+
366368
let rem e1 e2 = Z3.FloatingPoint.mk_rem ctx e1 e2
367369

368370
let eq e1 e2 = Z3.FloatingPoint.mk_eq ctx e1 e2

0 commit comments

Comments
 (0)