Module Val.
Definition eq (x y: val): {x=y} + {x<>y}.
Definition has_type_dec (v: val) (t: typ) : { has_type v t } + { ~ has_type v t }.
(** Select between two values based on the result of a comparison. *)
Definition select (cmp: option bool) (v1 v2: val) (ty: typ) :=
match cmp with
| Some b => normalize (if b then v1 else v2) ty
| None => Vundef
end.
(** [load_result] reflects the effect of storing a value with a given memory chunk, then reading it back with the same chunk.  Depending on the chunk and the type of the value, some normalization occurs. For instance, consider storing the integer value [0xFFF] on 1 byte at a given address, and reading it back.  If it is read back with chunk [Mint8unsigned], zero-extension must be performed, resulting in [0xFF].  If it is read back as a [Mint8signed], sign-extension is performed and [0xFFFFFFFF] is returned. *)
Definition load_result (chunk: memory_chunk) (v: val) :=
match chunk, v with
| Mint8signed, Vint n => Vint (Int.sign_ext 8 n)
| Mint8unsigned, Vint n => Vint (Int.zero_ext 8 n)
| Mint16signed, Vint n => Vint (Int.sign_ext 16 n)
| Mint16unsigned, Vint n => Vint (Int.zero_ext 16 n)
| Mint32, Vint n => Vint n
| Mint32, Vptr b ofs => if Archi.ptr64 then Vundef else Vptr b ofs
| Mint64, Vlong n => Vlong n
| Mint64, Vptr b ofs => if Archi.ptr64 then Vptr b ofs else Vundef
| Mfloat32, Vsingle f => Vsingle f
| Mfloat64, Vfloat f => Vfloat f
| Many32, (Vint _ | Vsingle _) => v
| Many32, Vptr _ _ => if Archi.ptr64 then Vundef else v
| Many64, _ => v
| _, _ => Vundef
end.
(** Theorems on arithmetic operations. *)

Theorem sub_add_l:
forall v1 v2 i, sub (add v1 (Vint i)) v2 = add (sub v1 v2) (Vint i).