library colibrilib.known_bits — module ExportThe total versions: they raise TooBig exactly when the size condition of the version with a precondition is false. The other functions of KnownBits are already total.
module Export925use int.Int926use colibrilib.zarith.Zbit927use colibrilib.safe_bits.BitsSpec928use colibrilib.safe_bits.SafeBits929use KnownBits930use Range931use colibrilib.spec.Sound932use option.Option933Valid (90ms) (colibri2)934let top () : t935ensures { result = KnownBits.top }936= KnownBits.top937Valid (101ms) (colibri2)938let is_top (a:t) : bool939ensures { result <-> forall x. mem x a }940= KnownBits.is_top a941Valid (87ms) (colibri2)942let cst (a:int) : t943ensures { exact mem (fun x -> x = a) result }944= KnownBits.cst a945Valid (100ms) (colibri2)946let cst_mask (a mask:int) : t947ensures { exact mem (fun x -> forall i. 0 <= i -> Zbit.bittest mask i ->948(Zbit.bittest x i <-> Zbit.bittest a i)) result }949= KnownBits.cst_mask a mask950Valid (100ms) (colibri2)951let inter (a b:t) : option t952ensures { exact_opt mem (fun x -> mem x a /\ mem x b) result }953= KnownBits.inter a b954Valid (85ms) (colibri2)955let union (a b:t) : t956ensures { join mem a b result }957= KnownBits.union a b958Valid (109ms) (colibri2)959let mk (known0 known1:int) : option t960ensures { match result with961| None -> not (Zbit.subset known1 known0)962| Some r -> r.l = known0 /\ r.u = known1963end }964= KnownBits.mk known0 known1965Valid (96ms) (colibri2)966let lognot (a:t) : t967ensures { forall x. mem (Zbit.lnot x) result <-> mem x a }968ensures { sound1 mem Zbit.lnot a result }969ensures { complete1 mem Zbit.lnot a result }970= KnownBits.lognot a971Valid (97ms) (colibri2)972let logand (a b:t) : t973ensures { sound2 mem Zbit.land a b result }974ensures { complete2 mem Zbit.land a b result }975= KnownBits.logand a b976Valid (91ms) (colibri2)977let logor (a b:t) : t978ensures { sound2 mem Zbit.lor a b result }979ensures { complete2 mem Zbit.lor a b result }980= KnownBits.logor a b981Valid (112ms) (colibri2)982let logxor (a b:t) : t983ensures { sound2 mem Zbit.lxor a b result }984ensures { complete2 mem Zbit.lxor a b result }985= KnownBits.logxor a b986Valid (113ms) (colibri2)987let testbit (a:t) (i:int) : kind988ensures { forall x. mem x a -> (result = One -> Zbit.bittest x i) /\989(result = Zero -> not (Zbit.bittest x i)) }990ensures { result = Unknown ->9910 <= i /\ mem a.l a /\ mem a.u a /\ Zbit.bittest a.l i /\ not (Zbit.bittest a.u i) }992= KnownBits.testbit a i993Valid (96ms) (colibri2)994let of_range (a b:int) : t995ensures { includes mem (fun x -> a <= x <= b) result }996= Range.of_range a b997Valid (113ms) (colibri2)998let bounds (k:t) : option (int, int)999ensures { match result with1000| None -> 0 <= k.u /\ k.l < 01001| Some (lo, hi) -> forall x. mem x k -> lo <= x <= hi1002end }1003= Range.bounds k1004Valid (107ms) (colibri2)1005let next (k:int) (b:bool) (x:int) : int1006ensures { forall z. x <= z -> (Zbit.bittest z k <-> b) -> result <= z }1007= Range.next k b x1008Valid (97ms) (colibri2)1009let prev (k:int) (b:bool) (x:int) : int1010ensures { forall z. z <= x -> (Zbit.bittest z k <-> b) -> z <= result }1011= Range.prev k b x1012Valid (32ms) (colibri2)1013let shift_right (off:int) (a:t) : t1014ensures { sound1 mem (fun x -> Zbit.asr x off) a result }1015ensures { complete1 mem (fun x -> Zbit.asr x off) a result }1016raises { TooBig -> not (SafeBits.shift_ok off a.l /\ SafeBits.shift_ok off a.u) }1017= if SafeBits.shift_ok off a.l && SafeBits.shift_ok off a.u1018then KnownBits.shift_right off a else raise TooBig1019Valid (34ms) (colibri2)1020let extract (off len:int) (a:t) : t1021ensures { sound1 mem (fun x -> BitsSpec.extract off len x) a result }1022ensures { complete1 mem (fun x -> BitsSpec.extract off len x) a result }1023raises { TooBig -> not (SafeBits.extract_ok off len a.l /\ SafeBits.extract_ok off len a.u) }1024= if SafeBits.extract_ok off len a.l && SafeBits.extract_ok off len a.u1025then KnownBits.extract off len a else raise TooBig1026Valid (174ms) (colibri2)1027let signed_extract (off len:int) (a:t) : t1028ensures { sound1 mem (fun x -> BitsSpec.signed_extract off len x) a result }1029raises { TooBig -> not (SafeBits.signed_extract_ok off len) }1030= if SafeBits.signed_extract_ok off len then KnownBits.signed_extract off len a else raise TooBig1031Valid (152ms) (colibri2 3) (cvc5) (split_vc) (depth 1)1032let update (off len:int) (src dst:t) : t1033ensures { sound2 mem (fun xs xd -> BitsSpec.update off len xs xd) src dst result }1034ensures { complete2 mem (fun xs xd -> BitsSpec.update off len xs xd) src dst result }1035raises { TooBig -> not (SafeBits.update_ok off len) }1036= if SafeBits.update_ok off len then KnownBits.update off len src dst else raise TooBig1037end1038