Common — library colibrilib.known_bits — module Export

The 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.

925
module Export
926
use int.Int
927
use colibrilib.zarith.Zbit
928
use colibrilib.safe_bits.BitsSpec
929
use colibrilib.safe_bits.SafeBits
930
use KnownBits
931
use Range
932
use colibrilib.spec.Sound
933
use option.Option
934
Valid (90ms) (colibri2)
935
let
top
() : t
936
ensures { result = KnownBits.top }
937
= KnownBits.top
938
Valid (101ms) (colibri2)
939
let
is_top
(a:t) : bool
940
ensures { result <-> forall x. mem x a }
941
= KnownBits.is_top a
942
Valid (87ms) (colibri2)
943
let
cst
(a:int) : t
944
ensures { exact mem (fun x -> x = a) result }
945
= KnownBits.cst a
946
Valid (100ms) (colibri2)
947
let
cst_mask
(a mask:int) : t
948
ensures { exact mem (fun x -> forall i. 0 <= i -> Zbit.bittest mask i ->
949
(Zbit.bittest x i <-> Zbit.bittest a i)) result }
950
= KnownBits.cst_mask a mask
951
Valid (100ms) (colibri2)
952
let
inter
(a b:t) : option t
953
ensures { exact_opt mem (fun x -> mem x a /\ mem x b) result }
954
= KnownBits.inter a b
955
Valid (85ms) (colibri2)
956
let
union
(a b:t) : t
957
ensures { join mem a b result }
958
= KnownBits.union a b
959
Valid (109ms) (colibri2)
960
let
mk
(known0 known1:int) : option t
961
ensures { match result with
962
| None -> not (Zbit.subset known1 known0)
963
| Some r -> r.l = known0 /\ r.u = known1
964
end }
965
= KnownBits.mk known0 known1
966
Valid (96ms) (colibri2)
967
let
lognot
(a:t) : t
968
ensures { forall x. mem (Zbit.lnot x) result <-> mem x a }
969
ensures { sound1 mem Zbit.lnot a result }
970
ensures { complete1 mem Zbit.lnot a result }
971
= KnownBits.lognot a
972
Valid (97ms) (colibri2)
973
let
logand
(a b:t) : t
974
ensures { sound2 mem Zbit.land a b result }
975
ensures { complete2 mem Zbit.land a b result }
976
= KnownBits.logand a b
977
Valid (91ms) (colibri2)
978
let
logor
(a b:t) : t
979
ensures { sound2 mem Zbit.lor a b result }
980
ensures { complete2 mem Zbit.lor a b result }
981
= KnownBits.logor a b
982
Valid (112ms) (colibri2)
983
let
logxor
(a b:t) : t
984
ensures { sound2 mem Zbit.lxor a b result }
985
ensures { complete2 mem Zbit.lxor a b result }
986
= KnownBits.logxor a b
987
Valid (113ms) (colibri2)
988
let
testbit
(a:t) (i:int) : kind
989
ensures { forall x. mem x a -> (result = One -> Zbit.bittest x i) /\
990
(result = Zero -> not (Zbit.bittest x i)) }
991
ensures { result = Unknown ->
992
0 <= i /\ mem a.l a /\ mem a.u a /\ Zbit.bittest a.l i /\ not (Zbit.bittest a.u i) }
993
= KnownBits.testbit a i
994
Valid (96ms) (colibri2)
995
let
of_range
(a b:int) : t
996
ensures { includes mem (fun x -> a <= x <= b) result }
997
= Range.of_range a b
998
Valid (113ms) (colibri2)
999
let
bounds
(k:t) : option (int, int)
1000
ensures { match result with
1001
| None -> 0 <= k.u /\ k.l < 0
1002
| Some (lo, hi) -> forall x. mem x k -> lo <= x <= hi
1003
end }
1004
= Range.bounds k
1005
Valid (107ms) (colibri2)
1006
let next (k:int) (b:bool) (x:int) : int
1007
ensures { forall z. x <= z -> (Zbit.bittest z k <-> b) -> result <= z }
1008
= Range.next k b x
1009
Valid (97ms) (colibri2)
1010
let prev (k:int) (b:bool) (x:int) : int
1011
ensures { forall z. z <= x -> (Zbit.bittest z k <-> b) -> z <= result }
1012
= Range.prev k b x
1013
Valid (32ms) (colibri2)
1014
let
shift_right
(off:int) (a:t) : t
1015
ensures { sound1 mem (fun x -> Zbit.asr x off) a result }
1016
ensures { complete1 mem (fun x -> Zbit.asr x off) a result }
1017
raises { TooBig -> not (SafeBits.shift_ok off a.l /\ SafeBits.shift_ok off a.u) }
1018
= if SafeBits.shift_ok off a.l && SafeBits.shift_ok off a.u
1019
then KnownBits.shift_right off a else raise TooBig
1020
Valid (34ms) (colibri2)
1021
let
extract
(off len:int) (a:t) : t
1022
ensures { sound1 mem (fun x -> BitsSpec.extract off len x) a result }
1023
ensures { complete1 mem (fun x -> BitsSpec.extract off len x) a result }
1024
raises { TooBig -> not (SafeBits.extract_ok off len a.l /\ SafeBits.extract_ok off len a.u) }
1025
= if SafeBits.extract_ok off len a.l && SafeBits.extract_ok off len a.u
1026
then KnownBits.extract off len a else raise TooBig
1027
Valid (174ms) (colibri2)
1028
let
signed_extract
(off len:int) (a:t) : t
1029
ensures { sound1 mem (fun x -> BitsSpec.signed_extract off len x) a result }
1030
raises { TooBig -> not (SafeBits.signed_extract_ok off len) }
1031
= if SafeBits.signed_extract_ok off len then KnownBits.signed_extract off len a else raise TooBig
1032
Valid (152ms) (colibri2 3) (cvc5) (split_vc) (depth 1)
1033
let
update
(off len:int) (src dst:t) : t
1034
ensures { sound2 mem (fun xs xd -> BitsSpec.update off len xs xd) src dst result }
1035
ensures { complete2 mem (fun xs xd -> BitsSpec.update off len xs xd) src dst result }
1036
raises { TooBig -> not (SafeBits.update_ok off len) }
1037
= if SafeBits.update_ok off len then KnownBits.update off len src dst else raise TooBig
1038
end