Skip to content

Commit 073e17d

Browse files
committed
Add is{Normal|Subnormal|Negative|Positive|Infinite} operators
1 parent 94bb919 commit 073e17d

File tree

11 files changed

+127
-17
lines changed

11 files changed

+127
-17
lines changed

src/smtml/bitwuzla_mappings.default.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,20 @@ module Fresh_bitwuzla (B : Bitwuzla_cxx.S) : M = struct
370370

371371
let sqrt ~rm t = mk_term2 Kind.Fp_sqrt rm t
372372

373+
let is_normal t = mk_term1 Kind.Fp_is_normal t
374+
375+
let is_subnormal t = mk_term1 Kind.Fp_is_subnormal t
376+
377+
let is_negative t = mk_term1 Kind.Fp_is_neg t
378+
379+
let is_positive t = mk_term1 Kind.Fp_is_pos t
380+
381+
let is_infinite t = mk_term1 Kind.Fp_is_inf t
382+
373383
let is_nan t = mk_term1 Kind.Fp_is_nan t
374384

385+
let is_zero t = mk_term1 Kind.Fp_is_zero t
386+
375387
let round_to_integral ~rm t = mk_term2 Kind.Fp_rti rm t
376388

377389
let add ~rm lhs rhs = mk_term3 Kind.Fp_add rm lhs rhs

src/smtml/cvc5_mappings.default.ml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,20 @@ module Fresh_cvc5 () = struct
356356

357357
let sqrt ~rm t = Term.mk_term tm Kind.Floatingpoint_sqrt [| rm; t |]
358358

359+
let is_normal t = Term.mk_term tm Kind.Floatingpoint_is_normal [| t |]
360+
361+
let is_subnormal t = Term.mk_term tm Kind.Floatingpoint_is_subnormal [| t |]
362+
363+
let is_negative t = Term.mk_term tm Kind.Floatingpoint_is_neg [| t |]
364+
365+
let is_positive t = Term.mk_term tm Kind.Floatingpoint_is_pos [| t |]
366+
367+
let is_infinite t = Term.mk_term tm Kind.Floatingpoint_is_inf [| t |]
368+
359369
let is_nan t = Term.mk_term tm Kind.Floatingpoint_is_nan [| t |]
360370

371+
let is_zero t = Term.mk_term tm Kind.Floatingpoint_is_zero [| t |]
372+
361373
let round_to_integral ~rm t =
362374
Term.mk_term tm Kind.Floatingpoint_rti [| rm; t |]
363375

@@ -373,7 +385,7 @@ module Fresh_cvc5 () = struct
373385

374386
let max t1 t2 = Term.mk_term tm Kind.Floatingpoint_max [| t1; t2 |]
375387

376-
let fma ~rm a b c = Term.mk_term Kind.Floatingpoint_fma [| rm; a; b; c |]
388+
let fma ~rm a b c = Term.mk_term tm Kind.Floatingpoint_fma [| rm; a; b; c |]
377389

378390
let rem t1 t2 = Term.mk_term tm Kind.Floatingpoint_rem [| t1; t2 |]
379391

src/smtml/dolmenexpr_to_expr.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,20 @@ module DolmenIntf = struct
313313

314314
let sqrt ~rm t = DTerm.Float.sqrt rm t
315315

316+
let is_normal = DTerm.Float.isNormal
317+
318+
let is_subnormal = DTerm.Float.isSubnormal
319+
320+
let is_negative = DTerm.Float.isNegative
321+
322+
let is_positive = DTerm.Float.isPositive
323+
324+
let is_infinite = DTerm.Float.isInfinite
325+
316326
let is_nan = DTerm.Float.isNaN
317327

328+
let is_zero = DTerm.Float.isZero
329+
318330
let round_to_integral ~rm t = DTerm.Float.roundToIntegral rm t
319331

320332
let add ~rm t1 t2 = DTerm.Float.add rm t1 t2

src/smtml/dolmenexpr_to_expr.mli

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,18 @@ module DolmenIntf : sig
284284

285285
val sqrt : rm:term -> term -> term
286286

287+
val is_normal : term -> term
288+
289+
val is_subnormal : term -> term
290+
291+
val is_negative : term -> term
292+
293+
val is_positive : term -> term
294+
295+
val is_infinite : term -> term
296+
297+
val is_zero : term -> term
298+
287299
val is_nan : term -> term
288300

289301
val round_to_integral : rm:term -> term -> term

src/smtml/mappings.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,13 @@ module Make (M_with_make : M_with_make) : S_with_fresh = struct
482482
| Unop.Neg -> Float.neg e
483483
| Abs -> Float.abs e
484484
| Sqrt -> Float.sqrt ~rm:Float.Rounding_mode.rne e
485+
| Is_normal -> Float.is_normal e
486+
| Is_subnormal -> Float.is_subnormal e
487+
| Is_negative -> Float.is_negative e
488+
| Is_positive -> Float.is_positive e
489+
| Is_infinite -> Float.is_infinite e
485490
| Is_nan -> Float.is_nan e
491+
| Is_zero -> Float.is_zero e
486492
| Ceil -> Float.round_to_integral ~rm:Float.Rounding_mode.rtp e
487493
| Floor -> Float.round_to_integral ~rm:Float.Rounding_mode.rtn e
488494
| Trunc -> Float.round_to_integral ~rm:Float.Rounding_mode.rtz e

src/smtml/mappings.nop.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,20 @@ module Nop = struct
281281

282282
let sqrt ~rm:_ = assert false
283283

284+
let is_normal _ = assert false
285+
286+
let is_subnormal _ = assert false
287+
288+
let is_negative _ = assert false
289+
290+
let is_positive _ = assert false
291+
292+
let is_infinite _ = assert false
293+
284294
let is_nan _ = assert false
285295

296+
let is_zero _ = assert false
297+
286298
let round_to_integral ~rm:_ = assert false
287299

288300
let add ~rm:_ = assert false

src/smtml/mappings_intf.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,18 @@ module type M = sig
496496
using the rounding mode [rm]. *)
497497
val sqrt : rm:term -> term -> term
498498

499+
val is_normal : term -> term
500+
501+
val is_subnormal : term -> term
502+
503+
val is_negative : term -> term
504+
505+
val is_positive : term -> term
506+
507+
val is_infinite : term -> term
508+
509+
val is_zero : term -> term
510+
499511
(** [is_nan t] checks if the floating-point term [t] is NaN. *)
500512
val is_nan : term -> term
501513

src/smtml/smtlib.ml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,6 @@ module Term = struct
124124
Fmt.failwith "%acould not parse colon: %a %a" pp_loc loc Expr.pp symbol
125125
Expr.pp term
126126

127-
let combine_to_int64 sign_bit exponent_bit mantissa_bit =
128-
let sign = Int64.of_string sign_bit in
129-
let exponent = Int64.of_string exponent_bit in
130-
let mantissa = Int64.of_string mantissa_bit in
131-
let sign_shifted = Int64.shift_left sign 63 in
132-
let exponent_shifted = Int64.shift_left exponent 52 in
133-
Int64.logor sign_shifted (Int64.logor exponent_shifted mantissa)
134-
135-
let combine_to_int32 sign exponent mantissa =
136-
let sign_shifted = Int32.shift_left sign 31 in
137-
let exponent_shifted = Int32.shift_left exponent 23 in
138-
Int32.logor sign_shifted (Int32.logor exponent_shifted mantissa)
139-
140127
let make_fp_binop symbol (op : Ty.Binop.t) rm a b =
141128
match Expr.view rm with
142129
| Symbol { name = Simple "roundNearestTiesToEven"; _ } ->
@@ -227,6 +214,13 @@ module Term = struct
227214
if fp_sz = 32 then Expr.value (Num (F32 (Bitvector.to_int32 fp)))
228215
else if fp_sz = 64 then Expr.value (Num (F64 (Bitvector.to_int64 fp)))
229216
else Fmt.failwith "%afp size not supported" pp_loc loc
217+
| "fp.isNormal", [ a ] -> Expr.raw_unop Ty_none Is_normal a
218+
| "fp.isSubnormal", [ a ] -> Expr.raw_unop Ty_none Is_subnormal a
219+
| "fp.isNegative", [ a ] -> Expr.raw_unop Ty_none Is_negative a
220+
| "fp.isPositive", [ a ] -> Expr.raw_unop Ty_none Is_positive a
221+
| "fp.isInfinite", [ a ] -> Expr.raw_unop Ty_none Is_infinite a
222+
| "fp.isNaN", [ a ] -> Expr.raw_unop Ty_none Is_nan a
223+
| "fp.isZero", [ a ] -> Expr.raw_unop Ty_none Is_zero a
230224
| "fp.abs", [ a ] -> Expr.raw_unop Ty_none Abs a
231225
| "fp.neg", [ a ] -> Expr.raw_unop Ty_none Neg a
232226
| "fp.add", [ rm; a; b ] -> make_fp_binop symbol Add rm a b

src/smtml/ty.ml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,13 @@ module Unop = struct
9898
(* Float *)
9999
| Abs
100100
| Sqrt
101+
| Is_normal
102+
| Is_subnormal
103+
| Is_negative
104+
| Is_positive
105+
| Is_infinite
101106
| Is_nan
107+
| Is_zero
102108
| Ceil
103109
| Floor
104110
| Trunc
@@ -125,7 +131,13 @@ module Unop = struct
125131
| Ctz, Ctz
126132
| Abs, Abs
127133
| Sqrt, Sqrt
134+
| Is_normal, Is_normal
135+
| Is_subnormal, Is_subnormal
136+
| Is_negative, Is_negative
137+
| Is_positive, Is_positive
138+
| Is_infinite, Is_infinite
128139
| Is_nan, Is_nan
140+
| Is_zero, Is_zero
129141
| Ceil, Ceil
130142
| Floor, Floor
131143
| Trunc, Trunc
@@ -141,9 +153,11 @@ module Unop = struct
141153
| Regexp_opt, Regexp_opt
142154
| Regexp_comp, Regexp_comp ->
143155
true
144-
| ( ( Neg | Not | Clz | Popcnt | Ctz | Abs | Sqrt | Is_nan | Ceil | Floor
145-
| Trunc | Nearest | Head | Tail | Reverse | Length | Trim | Regexp_star
146-
| Regexp_loop _ | Regexp_plus | Regexp_opt | Regexp_comp )
156+
| ( ( Neg | Not | Clz | Popcnt | Ctz | Abs | Sqrt | Is_normal | Is_subnormal
157+
| Is_negative | Is_positive | Is_infinite | Is_nan | Is_zero | Ceil
158+
| Floor | Trunc | Nearest | Head | Tail | Reverse | Length | Trim
159+
| Regexp_star | Regexp_loop _ | Regexp_plus | Regexp_opt | Regexp_comp
160+
)
147161
, _ ) ->
148162
false
149163

@@ -155,7 +169,13 @@ module Unop = struct
155169
| Popcnt -> Fmt.string fmt "popcnt"
156170
| Abs -> Fmt.string fmt "abs"
157171
| Sqrt -> Fmt.string fmt "sqrt"
172+
| Is_normal -> Fmt.string fmt "isNormal"
173+
| Is_subnormal -> Fmt.string fmt "isSubnormal"
174+
| Is_negative -> Fmt.string fmt "isNegative"
175+
| Is_positive -> Fmt.string fmt "isPositive"
176+
| Is_infinite -> Fmt.string fmt "isInfinite"
158177
| Is_nan -> Fmt.string fmt "is_nan"
178+
| Is_zero -> Fmt.string fmt "isZero"
159179
| Ceil -> Fmt.string fmt "ceil"
160180
| Floor -> Fmt.string fmt "floor"
161181
| Trunc -> Fmt.string fmt "trunc"

src/smtml/ty.mli

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,13 @@ module Unop : sig
7070
(* Float operations *)
7171
| Abs (** Absolute value. *)
7272
| Sqrt (** Square root. *)
73+
| Is_normal
74+
| Is_subnormal
75+
| Is_negative
76+
| Is_positive
77+
| Is_infinite
7378
| Is_nan (** Check if NaN. *)
79+
| Is_zero
7480
| Ceil (** Ceiling. *)
7581
| Floor (** Floor. *)
7682
| Trunc (** Truncate. *)

0 commit comments

Comments
 (0)