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. *)
(** The ``is less defined'' relation between values. A value is less defined than itself, and [Vundef] is less defined than any value. *)
Inductive lessdef: val -> val -> Prop :=
| lessdef_refl: forall v, lessdef v v
| lessdef_undef: forall v, lessdef Vundef v.
Inductive lessdef_list: list val -> list val -> Prop :=
| lessdef_list_nil:
lessdef_list nil nil
| lessdef_list_cons:
forall v1 v2 vl1 vl2,
lessdef v1 v2 -> lessdef_list vl1 vl2 ->
lessdef_list (v1 :: vl1) (v2 :: vl2).
Hint Resolve lessdef_refl lessdef_undef lessdef_list_nil lessdef_list_cons.
(** Compatibility of operations with the [lessdef] relation. *)

Lemma offset_ptr_assoc:
forall v d1 d2, offset_ptr (offset_ptr v d1) d2 = offset_ptr v (Ptrofs.add d1 d2).