Common — library colibrilib.bitwise_rules — module Export

The rules of the ground terms, without precondition: the meaning of the term is given by its interpretation (Term.view), the constant arguments by their values when they are known (else no equation yet: the wiring calls again when they are known)

923
module Export
924
use int.Int
925
use list.List
926
use option.Option
927
use colibrilib.env.Env
928
use colibrilib.bv_sem.Sem
929
use Term
930
use TermView
931
use Rules
932
use Intervals
933
use colibrilib.sbdd.SNode
934
use colibrilib.bddbitv.Export
935
use colibrilib.spec.Opt
936
use TermSize as TS

The size of a node, from its value, its domain and its types (Dom_genrelbitv.get_bv_size)

  Valid (60ms) (colibri2)
940
let
size
(d:env) (n:Node.t) : option int
941
ensures { when_some (has_size d n) result }
942
= TS.size d n

The term of a node, of its size if it is known (Dom_genrelbitv.monome_int)

  Valid (56ms) (colibri2)
946
let
monome
(d:env) (n:Node.t) : IBDD.t
947
ensures { is_term d n result }
948
= TS.monome d n

The known bits of the interval of n in its term

  Valid (258ms) (colibri2)
951
let partial
bits_of_interval
(d:env) (n:Node.t) : unit
952
raises { Contradiction -> not live d }
953
raises { Unsupported -> false }
954
raises { Overflow -> false }
955
= Intervals.bits_of_interval d n

The bit–level term of a ground term (except the value of a testbit)

  Valid (954ms) (colibri2 56) (split_vc) (depth 1)
958
let partial
term
(d:env) (g:ground) : unit
959
raises { Contradiction -> not live d }
960
= let r = node g in
961
match view g with
962
| Some (And, Cons a (Cons b Nil)) -> logand d r a b
963
| Some (Or, Cons a (Cons b Nil)) -> logor d r a b
964
| Some (Xor, Cons a (Cons b Nil)) -> logxor d r a b
965
| Some (Not, Cons a Nil) -> lognot d r a
966
| Some (Asr, Cons a (Cons o Nil)) ->
967
match int_value d o with
968
| Some off -> shift_right d r a off
969
| None -> ()
970
end
971
| Some (Extract, Cons a (Cons o (Cons l Nil))) ->
972
match int_value d o, int_value d l with
973
| Some off, Some len -> extract d r a off len
974
| _ -> ()
975
end
976
| Some (SignedExtract, Cons a (Cons o (Cons l Nil))) ->
977
match int_value d o, int_value d l with
978
| Some off, Some len -> signed_extract d r a off len
979
| _ -> ()
980
end
981
| Some (Update, Cons dst (Cons o (Cons l (Cons src Nil)))) ->
982
match int_value d o, int_value d l with
983
| Some off, Some len -> update d r dst src off len
984
| _ -> ()
985
end
986
| Some (Test, Cons a (Cons kn Nil)) ->
987
match int_value d kn with
988
| Some k -> testbit d r a k
989
| None -> ()
990
end
991
| Some (Sbv2int s, Cons a Nil) ->
992
sbv2int_spec s (pure { ienv d a }); signed_extract d r a 0 s
993
| Some ((BvAnd n | BvOr n | BvXor n) as op, Cons a (Cons b Nil)) ->
994
bv_binop d r a b n op
995
| Some ((BvNot _ | BvExtract _ _ _ | BvSignExtend _ _ | BvRotl _ _ | BvRotr _ _) as op,
996
Cons a Nil) -> bv_unop d r a op
997
| Some ((BvShl n | BvLshr n | BvAshr n) as op, Cons a (Cons o Nil)) ->
998
match int_value d o with
999
| Some off -> bv_shift d r a o n off op
1000
| None -> ()
1001
end
1002
| _ -> ()
1003
end

The value of a testbit node is known

  Valid (910ms) (colibri2)
1006
let partial
test_value
(d:env) (g:ground) : unit
1007
raises { Contradiction -> not live d }
1008
= let r = node g in
1009
match view g with
1010
| Some (Test, Cons a (Cons kn Nil)) ->
1011
match int_value d kn, bool_value d r with
1012
| Some k, Some v -> testbit_value d r a k v
1013
| _ -> ()
1014
end
1015
| _ -> ()
1016
end
1017
end