[3] | 1 | (* *********************************************************************) |
---|
| 2 | (* *) |
---|
| 3 | (* The Compcert verified compiler *) |
---|
| 4 | (* *) |
---|
| 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) |
---|
| 6 | (* *) |
---|
| 7 | (* Copyright Institut National de Recherche en Informatique et en *) |
---|
| 8 | (* Automatique. All rights reserved. This file is distributed *) |
---|
| 9 | (* under the terms of the GNU General Public License as published by *) |
---|
| 10 | (* the Free Software Foundation, either version 2 of the License, or *) |
---|
| 11 | (* (at your option) any later version. This file is also distributed *) |
---|
| 12 | (* under the terms of the INRIA Non-Commercial License Agreement. *) |
---|
| 13 | (* *) |
---|
| 14 | (* *********************************************************************) |
---|
| 15 | |
---|
| 16 | (* * This module defines the type of values that is used in the dynamic |
---|
| 17 | semantics of all our intermediate languages. *) |
---|
| 18 | |
---|
| 19 | include "Coqlib.ma". |
---|
| 20 | include "AST.ma". |
---|
| 21 | include "Integers.ma". |
---|
| 22 | include "Floats.ma". |
---|
| 23 | |
---|
| 24 | include "Plogic/connectives.ma". |
---|
| 25 | |
---|
| 26 | ndefinition block ≝ Z. |
---|
| 27 | (*ndefinition eq_block ≝ zeq.*) |
---|
| 28 | |
---|
| 29 | (* * A value is either: |
---|
| 30 | - a machine integer; |
---|
| 31 | - a floating-point number; |
---|
| 32 | - a pointer: a pair of a memory address and an integer offset with respect |
---|
| 33 | to this address; |
---|
| 34 | - the [Vundef] value denoting an arbitrary bit pattern, such as the |
---|
| 35 | value of an uninitialized variable. |
---|
| 36 | *) |
---|
| 37 | |
---|
[124] | 38 | (* TODO: should comparison and subtraction of pointers of different sorts |
---|
| 39 | be supported? *) |
---|
| 40 | |
---|
[3] | 41 | ninductive val: Type[0] ≝ |
---|
| 42 | | Vundef: val |
---|
| 43 | | Vint: int -> val |
---|
| 44 | | Vfloat: float -> val |
---|
[125] | 45 | | Vptr: memory_space → block -> int -> val. |
---|
[3] | 46 | |
---|
| 47 | ndefinition Vzero: val ≝ Vint zero. |
---|
| 48 | ndefinition Vone: val ≝ Vint one. |
---|
| 49 | ndefinition Vmone: val ≝ Vint mone. |
---|
| 50 | |
---|
| 51 | ndefinition Vtrue: val ≝ Vint one. |
---|
| 52 | ndefinition Vfalse: val ≝ Vint zero. |
---|
| 53 | |
---|
| 54 | (* |
---|
| 55 | (** The module [Val] defines a number of arithmetic and logical operations |
---|
| 56 | over type [val]. Most of these operations are straightforward extensions |
---|
| 57 | of the corresponding integer or floating-point operations. *) |
---|
| 58 | |
---|
| 59 | Module Val. |
---|
| 60 | *) |
---|
| 61 | ndefinition of_bool : bool → val ≝ λb. if b then Vtrue else Vfalse. |
---|
| 62 | |
---|
| 63 | ndefinition has_type ≝ λv: val. λt: typ. |
---|
| 64 | match v with |
---|
| 65 | [ Vundef ⇒ True |
---|
| 66 | | Vint _ ⇒ match t with [ Tint ⇒ True | _ ⇒ False ] |
---|
| 67 | | Vfloat _ ⇒ match t with [ Tfloat ⇒ True | _ ⇒ False ] |
---|
[124] | 68 | | Vptr _ _ _ ⇒ match t with [ Tint ⇒ True | _ ⇒ False ] |
---|
[3] | 69 | | _ ⇒ False |
---|
| 70 | ]. |
---|
| 71 | |
---|
| 72 | nlet rec has_type_list (vl: list val) (tl: list typ) on vl : Prop ≝ |
---|
| 73 | match vl with |
---|
| 74 | [ nil ⇒ match tl with [ nil ⇒ True | _ ⇒ False ] |
---|
| 75 | | cons v1 vs ⇒ match tl with [ nil ⇒ False | cons t1 ts ⇒ |
---|
| 76 | has_type v1 t1 ∧ has_type_list vs ts ] |
---|
| 77 | ]. |
---|
| 78 | |
---|
| 79 | (* * Truth values. Pointers and non-zero integers are treated as [True]. |
---|
| 80 | The integer 0 (also used to represent the null pointer) is [False]. |
---|
| 81 | [Vundef] and floats are neither true nor false. *) |
---|
| 82 | |
---|
| 83 | ndefinition is_true : val → Prop ≝ λv. |
---|
| 84 | match v with |
---|
| 85 | [ Vint n ⇒ n ≠ zero |
---|
[124] | 86 | | Vptr _ b ofs ⇒ True |
---|
[3] | 87 | | _ ⇒ False |
---|
| 88 | ]. |
---|
| 89 | |
---|
| 90 | ndefinition is_false : val → Prop ≝ λv. |
---|
| 91 | match v with |
---|
| 92 | [ Vint n ⇒ n = zero |
---|
| 93 | | _ ⇒ False |
---|
| 94 | ]. |
---|
| 95 | |
---|
| 96 | ninductive bool_of_val: val → bool → Prop ≝ |
---|
| 97 | | bool_of_val_int_true: |
---|
| 98 | ∀n. n ≠ zero → bool_of_val (Vint n) true |
---|
| 99 | | bool_of_val_int_false: |
---|
| 100 | bool_of_val (Vint zero) false |
---|
| 101 | | bool_of_val_ptr: |
---|
[124] | 102 | ∀pty,b,ofs. bool_of_val (Vptr pty b ofs) true. |
---|
[3] | 103 | |
---|
| 104 | ndefinition neg : val → val ≝ λv. |
---|
| 105 | match v with |
---|
| 106 | [ Vint n ⇒ Vint (neg n) |
---|
| 107 | | _ ⇒ Vundef |
---|
| 108 | ]. |
---|
| 109 | |
---|
| 110 | ndefinition negf : val → val ≝ λv. |
---|
| 111 | match v with |
---|
| 112 | [ Vfloat f ⇒ Vfloat (Fneg f) |
---|
| 113 | | _ => Vundef |
---|
| 114 | ]. |
---|
| 115 | |
---|
| 116 | ndefinition absf : val → val ≝ λv. |
---|
| 117 | match v with |
---|
| 118 | [ Vfloat f ⇒ Vfloat (Fabs f) |
---|
| 119 | | _ ⇒ Vundef |
---|
| 120 | ]. |
---|
| 121 | |
---|
| 122 | ndefinition intoffloat : val → val ≝ λv. |
---|
| 123 | match v with |
---|
| 124 | [ Vfloat f ⇒ Vint (intoffloat f) |
---|
| 125 | | _ ⇒ Vundef |
---|
| 126 | ]. |
---|
| 127 | |
---|
| 128 | ndefinition intuoffloat : val → val ≝ λv. |
---|
| 129 | match v with |
---|
| 130 | [ Vfloat f ⇒ Vint (intuoffloat f) |
---|
| 131 | | _ ⇒ Vundef |
---|
| 132 | ]. |
---|
| 133 | |
---|
| 134 | ndefinition floatofint : val → val ≝ λv. |
---|
| 135 | match v with |
---|
| 136 | [ Vint n ⇒ Vfloat (floatofint n) |
---|
| 137 | | _ ⇒ Vundef |
---|
| 138 | ]. |
---|
| 139 | |
---|
| 140 | ndefinition floatofintu : val → val ≝ λv. |
---|
| 141 | match v with |
---|
| 142 | [ Vint n ⇒ Vfloat (floatofintu n) |
---|
| 143 | | _ ⇒ Vundef |
---|
| 144 | ]. |
---|
| 145 | |
---|
| 146 | ndefinition notint : val → val ≝ λv. |
---|
| 147 | match v with |
---|
| 148 | [ Vint n ⇒ Vint (xor n mone) |
---|
| 149 | | _ ⇒ Vundef |
---|
| 150 | ]. |
---|
| 151 | |
---|
| 152 | (* FIXME: switch to alias, or rename, or … *) |
---|
| 153 | ndefinition int_eq : int → int → bool ≝ eq. |
---|
| 154 | ndefinition notbool : val → val ≝ λv. |
---|
| 155 | match v with |
---|
| 156 | [ Vint n ⇒ of_bool (int_eq n zero) |
---|
[124] | 157 | | Vptr _ b ofs ⇒ Vfalse |
---|
[3] | 158 | | _ ⇒ Vundef |
---|
| 159 | ]. |
---|
| 160 | |
---|
| 161 | ndefinition zero_ext ≝ λnbits: Z. λv: val. |
---|
| 162 | match v with |
---|
| 163 | [ Vint n ⇒ Vint (zero_ext nbits n) |
---|
| 164 | | _ ⇒ Vundef |
---|
| 165 | ]. |
---|
| 166 | |
---|
| 167 | ndefinition sign_ext ≝ λnbits:Z. λv:val. |
---|
| 168 | match v with |
---|
| 169 | [ Vint i ⇒ Vint (sign_ext nbits i) |
---|
| 170 | | _ ⇒ Vundef |
---|
| 171 | ]. |
---|
| 172 | |
---|
| 173 | ndefinition singleoffloat : val → val ≝ λv. |
---|
| 174 | match v with |
---|
| 175 | [ Vfloat f ⇒ Vfloat (singleoffloat f) |
---|
| 176 | | _ ⇒ Vundef |
---|
| 177 | ]. |
---|
| 178 | |
---|
| 179 | ndefinition add ≝ λv1,v2: val. |
---|
| 180 | match v1 with |
---|
| 181 | [ Vint n1 ⇒ match v2 with |
---|
| 182 | [ Vint n2 ⇒ Vint (add n1 n2) |
---|
[124] | 183 | | Vptr pty b2 ofs2 ⇒ Vptr pty b2 (add ofs2 n1) |
---|
[3] | 184 | | _ ⇒ Vundef ] |
---|
[124] | 185 | | Vptr pty b1 ofs1 ⇒ match v2 with |
---|
| 186 | [ Vint n2 ⇒ Vptr pty b1 (add ofs1 n2) |
---|
[3] | 187 | | _ ⇒ Vundef ] |
---|
| 188 | | _ ⇒ Vundef ]. |
---|
| 189 | |
---|
| 190 | ndefinition sub ≝ λv1,v2: val. |
---|
| 191 | match v1 with |
---|
| 192 | [ Vint n1 ⇒ match v2 with |
---|
| 193 | [ Vint n2 ⇒ Vint (sub n1 n2) |
---|
| 194 | | _ ⇒ Vundef ] |
---|
[124] | 195 | | Vptr pty1 b1 ofs1 ⇒ match v2 with |
---|
| 196 | [ Vint n2 ⇒ Vptr pty1 b1 (sub ofs1 n2) |
---|
| 197 | | Vptr pty2 b2 ofs2 ⇒ |
---|
[3] | 198 | if eqZb b1 b2 then Vint (sub ofs1 ofs2) else Vundef |
---|
| 199 | | _ ⇒ Vundef ] |
---|
| 200 | | _ ⇒ Vundef ]. |
---|
| 201 | |
---|
| 202 | ndefinition mul ≝ λv1, v2: val. |
---|
| 203 | match v1 with |
---|
| 204 | [ Vint n1 ⇒ match v2 with |
---|
| 205 | [ Vint n2 ⇒ Vint (mul n1 n2) |
---|
| 206 | | _ ⇒ Vundef ] |
---|
| 207 | | _ ⇒ Vundef ]. |
---|
| 208 | (* |
---|
| 209 | ndefinition divs ≝ λv1, v2: val. |
---|
| 210 | match v1 with |
---|
| 211 | [ Vint n1 ⇒ match v2 with |
---|
| 212 | [ Vint n2 ⇒ Vint (divs n1 n2) |
---|
| 213 | | _ ⇒ Vundef ] |
---|
| 214 | | _ ⇒ Vundef ]. |
---|
| 215 | |
---|
| 216 | Definition mods (v1 v2: val): val := |
---|
| 217 | match v1, v2 with |
---|
| 218 | | Vint n1, Vint n2 => |
---|
| 219 | if Int.eq n2 Int.zero then Vundef else Vint(Int.mods n1 n2) |
---|
| 220 | | _, _ => Vundef |
---|
| 221 | end. |
---|
| 222 | |
---|
| 223 | Definition divu (v1 v2: val): val := |
---|
| 224 | match v1, v2 with |
---|
| 225 | | Vint n1, Vint n2 => |
---|
| 226 | if Int.eq n2 Int.zero then Vundef else Vint(Int.divu n1 n2) |
---|
| 227 | | _, _ => Vundef |
---|
| 228 | end. |
---|
| 229 | |
---|
| 230 | Definition modu (v1 v2: val): val := |
---|
| 231 | match v1, v2 with |
---|
| 232 | | Vint n1, Vint n2 => |
---|
| 233 | if Int.eq n2 Int.zero then Vundef else Vint(Int.modu n1 n2) |
---|
| 234 | | _, _ => Vundef |
---|
| 235 | end. |
---|
| 236 | *) |
---|
| 237 | ndefinition v_and ≝ λv1, v2: val. |
---|
| 238 | match v1 with |
---|
| 239 | [ Vint n1 ⇒ match v2 with |
---|
| 240 | [ Vint n2 ⇒ Vint (i_and n1 n2) |
---|
| 241 | | _ ⇒ Vundef ] |
---|
| 242 | | _ ⇒ Vundef ]. |
---|
| 243 | |
---|
| 244 | ndefinition or ≝ λv1, v2: val. |
---|
| 245 | match v1 with |
---|
| 246 | [ Vint n1 ⇒ match v2 with |
---|
| 247 | [ Vint n2 ⇒ Vint (or n1 n2) |
---|
| 248 | | _ ⇒ Vundef ] |
---|
| 249 | | _ ⇒ Vundef ]. |
---|
| 250 | |
---|
| 251 | ndefinition xor ≝ λv1, v2: val. |
---|
| 252 | match v1 with |
---|
| 253 | [ Vint n1 ⇒ match v2 with |
---|
| 254 | [ Vint n2 ⇒ Vint (xor n1 n2) |
---|
| 255 | | _ ⇒ Vundef ] |
---|
| 256 | | _ ⇒ Vundef ]. |
---|
| 257 | (* |
---|
| 258 | Definition shl (v1 v2: val): val := |
---|
| 259 | match v1, v2 with |
---|
| 260 | | Vint n1, Vint n2 => |
---|
| 261 | if Int.ltu n2 Int.iwordsize |
---|
| 262 | then Vint(Int.shl n1 n2) |
---|
| 263 | else Vundef |
---|
| 264 | | _, _ => Vundef |
---|
| 265 | end. |
---|
| 266 | |
---|
| 267 | Definition shr (v1 v2: val): val := |
---|
| 268 | match v1, v2 with |
---|
| 269 | | Vint n1, Vint n2 => |
---|
| 270 | if Int.ltu n2 Int.iwordsize |
---|
| 271 | then Vint(Int.shr n1 n2) |
---|
| 272 | else Vundef |
---|
| 273 | | _, _ => Vundef |
---|
| 274 | end. |
---|
| 275 | |
---|
| 276 | Definition shr_carry (v1 v2: val): val := |
---|
| 277 | match v1, v2 with |
---|
| 278 | | Vint n1, Vint n2 => |
---|
| 279 | if Int.ltu n2 Int.iwordsize |
---|
| 280 | then Vint(Int.shr_carry n1 n2) |
---|
| 281 | else Vundef |
---|
| 282 | | _, _ => Vundef |
---|
| 283 | end. |
---|
| 284 | |
---|
| 285 | Definition shrx (v1 v2: val): val := |
---|
| 286 | match v1, v2 with |
---|
| 287 | | Vint n1, Vint n2 => |
---|
| 288 | if Int.ltu n2 Int.iwordsize |
---|
| 289 | then Vint(Int.shrx n1 n2) |
---|
| 290 | else Vundef |
---|
| 291 | | _, _ => Vundef |
---|
| 292 | end. |
---|
| 293 | |
---|
| 294 | Definition shru (v1 v2: val): val := |
---|
| 295 | match v1, v2 with |
---|
| 296 | | Vint n1, Vint n2 => |
---|
| 297 | if Int.ltu n2 Int.iwordsize |
---|
| 298 | then Vint(Int.shru n1 n2) |
---|
| 299 | else Vundef |
---|
| 300 | | _, _ => Vundef |
---|
| 301 | end. |
---|
| 302 | |
---|
| 303 | Definition rolm (v: val) (amount mask: int): val := |
---|
| 304 | match v with |
---|
| 305 | | Vint n => Vint(Int.rolm n amount mask) |
---|
| 306 | | _ => Vundef |
---|
| 307 | end. |
---|
| 308 | |
---|
| 309 | Definition ror (v1 v2: val): val := |
---|
| 310 | match v1, v2 with |
---|
| 311 | | Vint n1, Vint n2 => |
---|
| 312 | if Int.ltu n2 Int.iwordsize |
---|
| 313 | then Vint(Int.ror n1 n2) |
---|
| 314 | else Vundef |
---|
| 315 | | _, _ => Vundef |
---|
| 316 | end. |
---|
| 317 | *) |
---|
| 318 | ndefinition addf ≝ λv1,v2: val. |
---|
| 319 | match v1 with |
---|
| 320 | [ Vfloat f1 ⇒ match v2 with |
---|
| 321 | [ Vfloat f2 ⇒ Vfloat (Fadd f1 f2) |
---|
| 322 | | _ ⇒ Vundef ] |
---|
| 323 | | _ ⇒ Vundef ]. |
---|
| 324 | |
---|
| 325 | ndefinition subf ≝ λv1,v2: val. |
---|
| 326 | match v1 with |
---|
| 327 | [ Vfloat f1 ⇒ match v2 with |
---|
| 328 | [ Vfloat f2 ⇒ Vfloat (Fsub f1 f2) |
---|
| 329 | | _ ⇒ Vundef ] |
---|
| 330 | | _ ⇒ Vundef ]. |
---|
| 331 | |
---|
| 332 | ndefinition mulf ≝ λv1,v2: val. |
---|
| 333 | match v1 with |
---|
| 334 | [ Vfloat f1 ⇒ match v2 with |
---|
| 335 | [ Vfloat f2 ⇒ Vfloat (Fmul f1 f2) |
---|
| 336 | | _ ⇒ Vundef ] |
---|
| 337 | | _ ⇒ Vundef ]. |
---|
| 338 | |
---|
| 339 | ndefinition divf ≝ λv1,v2: val. |
---|
| 340 | match v1 with |
---|
| 341 | [ Vfloat f1 ⇒ match v2 with |
---|
| 342 | [ Vfloat f2 ⇒ Vfloat (Fdiv f1 f2) |
---|
| 343 | | _ ⇒ Vundef ] |
---|
| 344 | | _ ⇒ Vundef ]. |
---|
| 345 | |
---|
| 346 | ndefinition cmp_mismatch : comparison → val ≝ λc. |
---|
| 347 | match c with |
---|
| 348 | [ Ceq ⇒ Vfalse |
---|
| 349 | | Cne ⇒ Vtrue |
---|
| 350 | | _ ⇒ Vundef |
---|
| 351 | ]. |
---|
| 352 | |
---|
| 353 | ndefinition cmp ≝ λc: comparison. λv1,v2: val. |
---|
| 354 | match v1 with |
---|
| 355 | [ Vint n1 ⇒ match v2 with |
---|
| 356 | [ Vint n2 ⇒ of_bool (cmp c n1 n2) |
---|
[124] | 357 | | Vptr pty2 b2 ofs2 ⇒ |
---|
[3] | 358 | if eq n1 zero then cmp_mismatch c else Vundef |
---|
| 359 | | _ ⇒ Vundef ] |
---|
[124] | 360 | | Vptr pty1 b1 ofs1 ⇒ match v2 with |
---|
| 361 | [ Vptr pty2 b2 ofs2 ⇒ |
---|
[3] | 362 | if eqZb b1 b2 |
---|
| 363 | then of_bool (cmp c ofs1 ofs2) |
---|
| 364 | else cmp_mismatch c |
---|
| 365 | | Vint n2 ⇒ |
---|
| 366 | if eq n2 zero then cmp_mismatch c else Vundef |
---|
| 367 | | _ ⇒ Vundef ] |
---|
| 368 | | _ ⇒ Vundef ]. |
---|
| 369 | |
---|
| 370 | ndefinition cmpu ≝ λc: comparison. λv1,v2: val. |
---|
| 371 | match v1 with |
---|
| 372 | [ Vint n1 ⇒ match v2 with |
---|
| 373 | [ Vint n2 ⇒ of_bool (cmpu c n1 n2) |
---|
[124] | 374 | | Vptr pty2 b2 ofs2 ⇒ |
---|
[3] | 375 | if eq n1 zero then cmp_mismatch c else Vundef |
---|
| 376 | | _ ⇒ Vundef ] |
---|
[124] | 377 | | Vptr pty1 b1 ofs1 ⇒ match v2 with |
---|
| 378 | [ Vptr pty2 b2 ofs2 ⇒ |
---|
[3] | 379 | if eqZb b1 b2 |
---|
| 380 | then of_bool (cmpu c ofs1 ofs2) |
---|
| 381 | else cmp_mismatch c |
---|
| 382 | | Vint n2 ⇒ |
---|
| 383 | if eq n2 zero then cmp_mismatch c else Vundef |
---|
| 384 | | _ ⇒ Vundef ] |
---|
| 385 | | _ ⇒ Vundef ]. |
---|
| 386 | |
---|
| 387 | ndefinition cmpf ≝ λc: comparison. λv1,v2: val. |
---|
| 388 | match v1 with |
---|
| 389 | [ Vfloat f1 ⇒ match v2 with |
---|
| 390 | [ Vfloat f2 ⇒ of_bool (Fcmp c f1 f2) |
---|
| 391 | | _ ⇒ Vundef ] |
---|
| 392 | | _ ⇒ Vundef ]. |
---|
| 393 | |
---|
| 394 | (* * [load_result] is used in the memory model (library [Mem]) |
---|
| 395 | to post-process the results of a memory read. For instance, |
---|
| 396 | consider storing the integer value [0xFFF] on 1 byte at a |
---|
| 397 | given address, and reading it back. If it is read back with |
---|
| 398 | chunk [Mint8unsigned], zero-extension must be performed, resulting |
---|
| 399 | in [0xFF]. If it is read back as a [Mint8signed], sign-extension |
---|
| 400 | is performed and [0xFFFFFFFF] is returned. Type mismatches |
---|
| 401 | (e.g. reading back a float as a [Mint32]) read back as [Vundef]. *) |
---|
| 402 | |
---|
| 403 | nlet rec load_result (chunk: memory_chunk) (v: val) ≝ |
---|
| 404 | match v with |
---|
| 405 | [ Vint n ⇒ |
---|
| 406 | match chunk with |
---|
| 407 | [ Mint8signed ⇒ Vint (sign_ext 8 n) |
---|
| 408 | | Mint8unsigned ⇒ Vint (zero_ext 8 n) |
---|
| 409 | | Mint16signed ⇒ Vint (sign_ext 16 n) |
---|
| 410 | | Mint16unsigned ⇒ Vint (zero_ext 16 n) |
---|
| 411 | | Mint32 ⇒ Vint n |
---|
| 412 | | _ ⇒ Vundef |
---|
| 413 | ] |
---|
[124] | 414 | | Vptr pty b ofs ⇒ |
---|
[153] | 415 | match pty with |
---|
| 416 | [ Any ⇒ match chunk with [ Mint24 ⇒ Vptr pty b ofs | _ ⇒ Vundef ] |
---|
| 417 | | Data ⇒ match chunk with [ Mint8unsigned ⇒ Vptr pty b ofs | _ ⇒ Vundef ] |
---|
| 418 | | IData ⇒ match chunk with [ Mint8unsigned ⇒ Vptr pty b ofs | _ ⇒ Vundef ] |
---|
[156] | 419 | | PData ⇒ match chunk with [ Mint8unsigned ⇒ Vptr pty b ofs | _ ⇒ Vundef ] |
---|
[153] | 420 | | XData ⇒ match chunk with [ Mint16unsigned ⇒ Vptr pty b ofs | _ ⇒ Vundef ] |
---|
| 421 | | Code ⇒ match chunk with [ Mint16unsigned ⇒ Vptr pty b ofs | _ ⇒ Vundef ] |
---|
[3] | 422 | ] |
---|
| 423 | | Vfloat f ⇒ |
---|
| 424 | match chunk with |
---|
| 425 | [ Mfloat32 ⇒ Vfloat(singleoffloat f) |
---|
| 426 | | Mfloat64 ⇒ Vfloat f |
---|
| 427 | | _ ⇒ Vundef |
---|
| 428 | ] |
---|
| 429 | | _ ⇒ Vundef |
---|
| 430 | ]. |
---|
| 431 | |
---|
| 432 | (* |
---|
| 433 | (** Theorems on arithmetic operations. *) |
---|
| 434 | |
---|
| 435 | Theorem cast8unsigned_and: |
---|
| 436 | forall x, zero_ext 8 x = and x (Vint(Int.repr 255)). |
---|
| 437 | Proof. |
---|
| 438 | destruct x; simpl; auto. decEq. |
---|
| 439 | change 255 with (two_p 8 - 1). apply Int.zero_ext_and. vm_compute; auto. |
---|
| 440 | Qed. |
---|
| 441 | |
---|
| 442 | Theorem cast16unsigned_and: |
---|
| 443 | forall x, zero_ext 16 x = and x (Vint(Int.repr 65535)). |
---|
| 444 | Proof. |
---|
| 445 | destruct x; simpl; auto. decEq. |
---|
| 446 | change 65535 with (two_p 16 - 1). apply Int.zero_ext_and. vm_compute; auto. |
---|
| 447 | Qed. |
---|
| 448 | |
---|
| 449 | Theorem istrue_not_isfalse: |
---|
| 450 | forall v, is_false v -> is_true (notbool v). |
---|
| 451 | Proof. |
---|
| 452 | destruct v; simpl; try contradiction. |
---|
| 453 | intros. subst i. simpl. discriminate. |
---|
| 454 | Qed. |
---|
| 455 | |
---|
| 456 | Theorem isfalse_not_istrue: |
---|
| 457 | forall v, is_true v -> is_false (notbool v). |
---|
| 458 | Proof. |
---|
| 459 | destruct v; simpl; try contradiction. |
---|
| 460 | intros. generalize (Int.eq_spec i Int.zero). |
---|
| 461 | case (Int.eq i Int.zero); intro. |
---|
| 462 | contradiction. simpl. auto. |
---|
| 463 | auto. |
---|
| 464 | Qed. |
---|
| 465 | |
---|
| 466 | Theorem bool_of_true_val: |
---|
| 467 | forall v, is_true v -> bool_of_val v true. |
---|
| 468 | Proof. |
---|
| 469 | intro. destruct v; simpl; intros; try contradiction. |
---|
| 470 | constructor; auto. constructor. |
---|
| 471 | Qed. |
---|
| 472 | |
---|
| 473 | Theorem bool_of_true_val2: |
---|
| 474 | forall v, bool_of_val v true -> is_true v. |
---|
| 475 | Proof. |
---|
| 476 | intros. inversion H; simpl; auto. |
---|
| 477 | Qed. |
---|
| 478 | |
---|
| 479 | Theorem bool_of_true_val_inv: |
---|
| 480 | forall v b, is_true v -> bool_of_val v b -> b = true. |
---|
| 481 | Proof. |
---|
| 482 | intros. inversion H0; subst v b; simpl in H; auto. |
---|
| 483 | Qed. |
---|
| 484 | |
---|
| 485 | Theorem bool_of_false_val: |
---|
| 486 | forall v, is_false v -> bool_of_val v false. |
---|
| 487 | Proof. |
---|
| 488 | intro. destruct v; simpl; intros; try contradiction. |
---|
| 489 | subst i; constructor. |
---|
| 490 | Qed. |
---|
| 491 | |
---|
| 492 | Theorem bool_of_false_val2: |
---|
| 493 | forall v, bool_of_val v false -> is_false v. |
---|
| 494 | Proof. |
---|
| 495 | intros. inversion H; simpl; auto. |
---|
| 496 | Qed. |
---|
| 497 | |
---|
| 498 | Theorem bool_of_false_val_inv: |
---|
| 499 | forall v b, is_false v -> bool_of_val v b -> b = false. |
---|
| 500 | Proof. |
---|
| 501 | intros. inversion H0; subst v b; simpl in H. |
---|
| 502 | congruence. auto. contradiction. |
---|
| 503 | Qed. |
---|
| 504 | |
---|
| 505 | Theorem notbool_negb_1: |
---|
| 506 | forall b, of_bool (negb b) = notbool (of_bool b). |
---|
| 507 | Proof. |
---|
| 508 | destruct b; reflexivity. |
---|
| 509 | Qed. |
---|
| 510 | |
---|
| 511 | Theorem notbool_negb_2: |
---|
| 512 | forall b, of_bool b = notbool (of_bool (negb b)). |
---|
| 513 | Proof. |
---|
| 514 | destruct b; reflexivity. |
---|
| 515 | Qed. |
---|
| 516 | |
---|
| 517 | Theorem notbool_idem2: |
---|
| 518 | forall b, notbool(notbool(of_bool b)) = of_bool b. |
---|
| 519 | Proof. |
---|
| 520 | destruct b; reflexivity. |
---|
| 521 | Qed. |
---|
| 522 | |
---|
| 523 | Theorem notbool_idem3: |
---|
| 524 | forall x, notbool(notbool(notbool x)) = notbool x. |
---|
| 525 | Proof. |
---|
| 526 | destruct x; simpl; auto. |
---|
| 527 | case (Int.eq i Int.zero); reflexivity. |
---|
| 528 | Qed. |
---|
| 529 | |
---|
| 530 | Theorem add_commut: forall x y, add x y = add y x. |
---|
| 531 | Proof. |
---|
| 532 | destruct x; destruct y; simpl; auto. |
---|
| 533 | decEq. apply Int.add_commut. |
---|
| 534 | Qed. |
---|
| 535 | |
---|
| 536 | Theorem add_assoc: forall x y z, add (add x y) z = add x (add y z). |
---|
| 537 | Proof. |
---|
| 538 | destruct x; destruct y; destruct z; simpl; auto. |
---|
| 539 | rewrite Int.add_assoc; auto. |
---|
| 540 | rewrite Int.add_assoc; auto. |
---|
| 541 | decEq. decEq. apply Int.add_commut. |
---|
| 542 | decEq. rewrite Int.add_commut. rewrite <- Int.add_assoc. |
---|
| 543 | decEq. apply Int.add_commut. |
---|
| 544 | decEq. rewrite Int.add_assoc. auto. |
---|
| 545 | Qed. |
---|
| 546 | |
---|
| 547 | Theorem add_permut: forall x y z, add x (add y z) = add y (add x z). |
---|
| 548 | Proof. |
---|
| 549 | intros. rewrite (add_commut y z). rewrite <- add_assoc. apply add_commut. |
---|
| 550 | Qed. |
---|
| 551 | |
---|
| 552 | Theorem add_permut_4: |
---|
| 553 | forall x y z t, add (add x y) (add z t) = add (add x z) (add y t). |
---|
| 554 | Proof. |
---|
| 555 | intros. rewrite add_permut. rewrite add_assoc. |
---|
| 556 | rewrite add_permut. symmetry. apply add_assoc. |
---|
| 557 | Qed. |
---|
| 558 | |
---|
| 559 | Theorem neg_zero: neg Vzero = Vzero. |
---|
| 560 | Proof. |
---|
| 561 | reflexivity. |
---|
| 562 | Qed. |
---|
| 563 | |
---|
| 564 | Theorem neg_add_distr: forall x y, neg(add x y) = add (neg x) (neg y). |
---|
| 565 | Proof. |
---|
| 566 | destruct x; destruct y; simpl; auto. decEq. apply Int.neg_add_distr. |
---|
| 567 | Qed. |
---|
| 568 | |
---|
| 569 | Theorem sub_zero_r: forall x, sub Vzero x = neg x. |
---|
| 570 | Proof. |
---|
| 571 | destruct x; simpl; auto. |
---|
| 572 | Qed. |
---|
| 573 | |
---|
| 574 | Theorem sub_add_opp: forall x y, sub x (Vint y) = add x (Vint (Int.neg y)). |
---|
| 575 | Proof. |
---|
| 576 | destruct x; intro y; simpl; auto; rewrite Int.sub_add_opp; auto. |
---|
| 577 | Qed. |
---|
| 578 | |
---|
| 579 | Theorem sub_opp_add: forall x y, sub x (Vint (Int.neg y)) = add x (Vint y). |
---|
| 580 | Proof. |
---|
| 581 | intros. unfold sub, add. |
---|
| 582 | destruct x; auto; rewrite Int.sub_add_opp; rewrite Int.neg_involutive; auto. |
---|
| 583 | Qed. |
---|
| 584 | |
---|
| 585 | Theorem sub_add_l: |
---|
| 586 | forall v1 v2 i, sub (add v1 (Vint i)) v2 = add (sub v1 v2) (Vint i). |
---|
| 587 | Proof. |
---|
| 588 | destruct v1; destruct v2; intros; simpl; auto. |
---|
| 589 | rewrite Int.sub_add_l. auto. |
---|
| 590 | rewrite Int.sub_add_l. auto. |
---|
| 591 | case (zeq b b0); intro. rewrite Int.sub_add_l. auto. reflexivity. |
---|
| 592 | Qed. |
---|
| 593 | |
---|
| 594 | Theorem sub_add_r: |
---|
| 595 | forall v1 v2 i, sub v1 (add v2 (Vint i)) = add (sub v1 v2) (Vint (Int.neg i)). |
---|
| 596 | Proof. |
---|
| 597 | destruct v1; destruct v2; intros; simpl; auto. |
---|
| 598 | rewrite Int.sub_add_r. auto. |
---|
| 599 | repeat rewrite Int.sub_add_opp. decEq. |
---|
| 600 | repeat rewrite Int.add_assoc. decEq. apply Int.add_commut. |
---|
| 601 | decEq. repeat rewrite Int.sub_add_opp. |
---|
| 602 | rewrite Int.add_assoc. decEq. apply Int.neg_add_distr. |
---|
| 603 | case (zeq b b0); intro. simpl. decEq. |
---|
| 604 | repeat rewrite Int.sub_add_opp. rewrite Int.add_assoc. decEq. |
---|
| 605 | apply Int.neg_add_distr. |
---|
| 606 | reflexivity. |
---|
| 607 | Qed. |
---|
| 608 | |
---|
| 609 | Theorem mul_commut: forall x y, mul x y = mul y x. |
---|
| 610 | Proof. |
---|
| 611 | destruct x; destruct y; simpl; auto. decEq. apply Int.mul_commut. |
---|
| 612 | Qed. |
---|
| 613 | |
---|
| 614 | Theorem mul_assoc: forall x y z, mul (mul x y) z = mul x (mul y z). |
---|
| 615 | Proof. |
---|
| 616 | destruct x; destruct y; destruct z; simpl; auto. |
---|
| 617 | decEq. apply Int.mul_assoc. |
---|
| 618 | Qed. |
---|
| 619 | |
---|
| 620 | Theorem mul_add_distr_l: |
---|
| 621 | forall x y z, mul (add x y) z = add (mul x z) (mul y z). |
---|
| 622 | Proof. |
---|
| 623 | destruct x; destruct y; destruct z; simpl; auto. |
---|
| 624 | decEq. apply Int.mul_add_distr_l. |
---|
| 625 | Qed. |
---|
| 626 | |
---|
| 627 | |
---|
| 628 | Theorem mul_add_distr_r: |
---|
| 629 | forall x y z, mul x (add y z) = add (mul x y) (mul x z). |
---|
| 630 | Proof. |
---|
| 631 | destruct x; destruct y; destruct z; simpl; auto. |
---|
| 632 | decEq. apply Int.mul_add_distr_r. |
---|
| 633 | Qed. |
---|
| 634 | |
---|
| 635 | Theorem mul_pow2: |
---|
| 636 | forall x n logn, |
---|
| 637 | Int.is_power2 n = Some logn -> |
---|
| 638 | mul x (Vint n) = shl x (Vint logn). |
---|
| 639 | Proof. |
---|
| 640 | intros; destruct x; simpl; auto. |
---|
| 641 | change 32 with (Z_of_nat Int.wordsize). |
---|
| 642 | rewrite (Int.is_power2_range _ _ H). decEq. apply Int.mul_pow2. auto. |
---|
| 643 | Qed. |
---|
| 644 | |
---|
| 645 | Theorem mods_divs: |
---|
| 646 | forall x y, mods x y = sub x (mul (divs x y) y). |
---|
| 647 | Proof. |
---|
| 648 | destruct x; destruct y; simpl; auto. |
---|
| 649 | case (Int.eq i0 Int.zero); simpl. auto. decEq. apply Int.mods_divs. |
---|
| 650 | Qed. |
---|
| 651 | |
---|
| 652 | Theorem modu_divu: |
---|
| 653 | forall x y, modu x y = sub x (mul (divu x y) y). |
---|
| 654 | Proof. |
---|
| 655 | destruct x; destruct y; simpl; auto. |
---|
| 656 | generalize (Int.eq_spec i0 Int.zero); |
---|
| 657 | case (Int.eq i0 Int.zero); simpl. auto. |
---|
| 658 | intro. decEq. apply Int.modu_divu. auto. |
---|
| 659 | Qed. |
---|
| 660 | |
---|
| 661 | Theorem divs_pow2: |
---|
| 662 | forall x n logn, |
---|
| 663 | Int.is_power2 n = Some logn -> |
---|
| 664 | divs x (Vint n) = shrx x (Vint logn). |
---|
| 665 | Proof. |
---|
| 666 | intros; destruct x; simpl; auto. |
---|
| 667 | change 32 with (Z_of_nat Int.wordsize). |
---|
| 668 | rewrite (Int.is_power2_range _ _ H). |
---|
| 669 | generalize (Int.eq_spec n Int.zero); |
---|
| 670 | case (Int.eq n Int.zero); intro. |
---|
| 671 | subst n. compute in H. discriminate. |
---|
| 672 | decEq. apply Int.divs_pow2. auto. |
---|
| 673 | Qed. |
---|
| 674 | |
---|
| 675 | Theorem divu_pow2: |
---|
| 676 | forall x n logn, |
---|
| 677 | Int.is_power2 n = Some logn -> |
---|
| 678 | divu x (Vint n) = shru x (Vint logn). |
---|
| 679 | Proof. |
---|
| 680 | intros; destruct x; simpl; auto. |
---|
| 681 | change 32 with (Z_of_nat Int.wordsize). |
---|
| 682 | rewrite (Int.is_power2_range _ _ H). |
---|
| 683 | generalize (Int.eq_spec n Int.zero); |
---|
| 684 | case (Int.eq n Int.zero); intro. |
---|
| 685 | subst n. compute in H. discriminate. |
---|
| 686 | decEq. apply Int.divu_pow2. auto. |
---|
| 687 | Qed. |
---|
| 688 | |
---|
| 689 | Theorem modu_pow2: |
---|
| 690 | forall x n logn, |
---|
| 691 | Int.is_power2 n = Some logn -> |
---|
| 692 | modu x (Vint n) = and x (Vint (Int.sub n Int.one)). |
---|
| 693 | Proof. |
---|
| 694 | intros; destruct x; simpl; auto. |
---|
| 695 | generalize (Int.eq_spec n Int.zero); |
---|
| 696 | case (Int.eq n Int.zero); intro. |
---|
| 697 | subst n. compute in H. discriminate. |
---|
| 698 | decEq. eapply Int.modu_and; eauto. |
---|
| 699 | Qed. |
---|
| 700 | |
---|
| 701 | Theorem and_commut: forall x y, and x y = and y x. |
---|
| 702 | Proof. |
---|
| 703 | destruct x; destruct y; simpl; auto. decEq. apply Int.and_commut. |
---|
| 704 | Qed. |
---|
| 705 | |
---|
| 706 | Theorem and_assoc: forall x y z, and (and x y) z = and x (and y z). |
---|
| 707 | Proof. |
---|
| 708 | destruct x; destruct y; destruct z; simpl; auto. |
---|
| 709 | decEq. apply Int.and_assoc. |
---|
| 710 | Qed. |
---|
| 711 | |
---|
| 712 | Theorem or_commut: forall x y, or x y = or y x. |
---|
| 713 | Proof. |
---|
| 714 | destruct x; destruct y; simpl; auto. decEq. apply Int.or_commut. |
---|
| 715 | Qed. |
---|
| 716 | |
---|
| 717 | Theorem or_assoc: forall x y z, or (or x y) z = or x (or y z). |
---|
| 718 | Proof. |
---|
| 719 | destruct x; destruct y; destruct z; simpl; auto. |
---|
| 720 | decEq. apply Int.or_assoc. |
---|
| 721 | Qed. |
---|
| 722 | |
---|
| 723 | Theorem xor_commut: forall x y, xor x y = xor y x. |
---|
| 724 | Proof. |
---|
| 725 | destruct x; destruct y; simpl; auto. decEq. apply Int.xor_commut. |
---|
| 726 | Qed. |
---|
| 727 | |
---|
| 728 | Theorem xor_assoc: forall x y z, xor (xor x y) z = xor x (xor y z). |
---|
| 729 | Proof. |
---|
| 730 | destruct x; destruct y; destruct z; simpl; auto. |
---|
| 731 | decEq. apply Int.xor_assoc. |
---|
| 732 | Qed. |
---|
| 733 | |
---|
| 734 | Theorem shl_mul: forall x y, Val.mul x (Val.shl Vone y) = Val.shl x y. |
---|
| 735 | Proof. |
---|
| 736 | destruct x; destruct y; simpl; auto. |
---|
| 737 | case (Int.ltu i0 Int.iwordsize); auto. |
---|
| 738 | decEq. symmetry. apply Int.shl_mul. |
---|
| 739 | Qed. |
---|
| 740 | |
---|
| 741 | Theorem shl_rolm: |
---|
| 742 | forall x n, |
---|
| 743 | Int.ltu n Int.iwordsize = true -> |
---|
| 744 | shl x (Vint n) = rolm x n (Int.shl Int.mone n). |
---|
| 745 | Proof. |
---|
| 746 | intros; destruct x; simpl; auto. |
---|
| 747 | rewrite H. decEq. apply Int.shl_rolm. exact H. |
---|
| 748 | Qed. |
---|
| 749 | |
---|
| 750 | Theorem shru_rolm: |
---|
| 751 | forall x n, |
---|
| 752 | Int.ltu n Int.iwordsize = true -> |
---|
| 753 | shru x (Vint n) = rolm x (Int.sub Int.iwordsize n) (Int.shru Int.mone n). |
---|
| 754 | Proof. |
---|
| 755 | intros; destruct x; simpl; auto. |
---|
| 756 | rewrite H. decEq. apply Int.shru_rolm. exact H. |
---|
| 757 | Qed. |
---|
| 758 | |
---|
| 759 | Theorem shrx_carry: |
---|
| 760 | forall x y, |
---|
| 761 | add (shr x y) (shr_carry x y) = shrx x y. |
---|
| 762 | Proof. |
---|
| 763 | destruct x; destruct y; simpl; auto. |
---|
| 764 | case (Int.ltu i0 Int.iwordsize); auto. |
---|
| 765 | simpl. decEq. apply Int.shrx_carry. |
---|
| 766 | Qed. |
---|
| 767 | |
---|
| 768 | Theorem or_rolm: |
---|
| 769 | forall x n m1 m2, |
---|
| 770 | or (rolm x n m1) (rolm x n m2) = rolm x n (Int.or m1 m2). |
---|
| 771 | Proof. |
---|
| 772 | intros; destruct x; simpl; auto. |
---|
| 773 | decEq. apply Int.or_rolm. |
---|
| 774 | Qed. |
---|
| 775 | |
---|
| 776 | Theorem rolm_rolm: |
---|
| 777 | forall x n1 m1 n2 m2, |
---|
| 778 | rolm (rolm x n1 m1) n2 m2 = |
---|
| 779 | rolm x (Int.modu (Int.add n1 n2) Int.iwordsize) |
---|
| 780 | (Int.and (Int.rol m1 n2) m2). |
---|
| 781 | Proof. |
---|
| 782 | intros; destruct x; simpl; auto. |
---|
| 783 | decEq. |
---|
| 784 | apply Int.rolm_rolm. apply int_wordsize_divides_modulus. |
---|
| 785 | Qed. |
---|
| 786 | |
---|
| 787 | Theorem rolm_zero: |
---|
| 788 | forall x m, |
---|
| 789 | rolm x Int.zero m = and x (Vint m). |
---|
| 790 | Proof. |
---|
| 791 | intros; destruct x; simpl; auto. decEq. apply Int.rolm_zero. |
---|
| 792 | Qed. |
---|
| 793 | |
---|
| 794 | Theorem addf_commut: forall x y, addf x y = addf y x. |
---|
| 795 | Proof. |
---|
| 796 | destruct x; destruct y; simpl; auto. decEq. apply Float.addf_commut. |
---|
| 797 | Qed. |
---|
| 798 | |
---|
| 799 | Lemma negate_cmp_mismatch: |
---|
| 800 | forall c, |
---|
| 801 | cmp_mismatch (negate_comparison c) = notbool(cmp_mismatch c). |
---|
| 802 | Proof. |
---|
| 803 | destruct c; reflexivity. |
---|
| 804 | Qed. |
---|
| 805 | |
---|
| 806 | Theorem negate_cmp: |
---|
| 807 | forall c x y, |
---|
| 808 | cmp (negate_comparison c) x y = notbool (cmp c x y). |
---|
| 809 | Proof. |
---|
| 810 | destruct x; destruct y; simpl; auto. |
---|
| 811 | rewrite Int.negate_cmp. apply notbool_negb_1. |
---|
| 812 | case (Int.eq i Int.zero). apply negate_cmp_mismatch. reflexivity. |
---|
| 813 | case (Int.eq i0 Int.zero). apply negate_cmp_mismatch. reflexivity. |
---|
| 814 | case (zeq b b0); intro. |
---|
| 815 | rewrite Int.negate_cmp. apply notbool_negb_1. |
---|
| 816 | apply negate_cmp_mismatch. |
---|
| 817 | Qed. |
---|
| 818 | |
---|
| 819 | Theorem negate_cmpu: |
---|
| 820 | forall c x y, |
---|
| 821 | cmpu (negate_comparison c) x y = notbool (cmpu c x y). |
---|
| 822 | Proof. |
---|
| 823 | destruct x; destruct y; simpl; auto. |
---|
| 824 | rewrite Int.negate_cmpu. apply notbool_negb_1. |
---|
| 825 | case (Int.eq i Int.zero). apply negate_cmp_mismatch. reflexivity. |
---|
| 826 | case (Int.eq i0 Int.zero). apply negate_cmp_mismatch. reflexivity. |
---|
| 827 | case (zeq b b0); intro. |
---|
| 828 | rewrite Int.negate_cmpu. apply notbool_negb_1. |
---|
| 829 | apply negate_cmp_mismatch. |
---|
| 830 | Qed. |
---|
| 831 | |
---|
| 832 | Lemma swap_cmp_mismatch: |
---|
| 833 | forall c, cmp_mismatch (swap_comparison c) = cmp_mismatch c. |
---|
| 834 | Proof. |
---|
| 835 | destruct c; reflexivity. |
---|
| 836 | Qed. |
---|
| 837 | |
---|
| 838 | Theorem swap_cmp: |
---|
| 839 | forall c x y, |
---|
| 840 | cmp (swap_comparison c) x y = cmp c y x. |
---|
| 841 | Proof. |
---|
| 842 | destruct x; destruct y; simpl; auto. |
---|
| 843 | rewrite Int.swap_cmp. auto. |
---|
| 844 | case (Int.eq i Int.zero). apply swap_cmp_mismatch. auto. |
---|
| 845 | case (Int.eq i0 Int.zero). apply swap_cmp_mismatch. auto. |
---|
| 846 | case (zeq b b0); intro. |
---|
| 847 | subst b0. rewrite zeq_true. rewrite Int.swap_cmp. auto. |
---|
| 848 | rewrite zeq_false. apply swap_cmp_mismatch. auto. |
---|
| 849 | Qed. |
---|
| 850 | |
---|
| 851 | Theorem swap_cmpu: |
---|
| 852 | forall c x y, |
---|
| 853 | cmpu (swap_comparison c) x y = cmpu c y x. |
---|
| 854 | Proof. |
---|
| 855 | destruct x; destruct y; simpl; auto. |
---|
| 856 | rewrite Int.swap_cmpu. auto. |
---|
| 857 | case (Int.eq i Int.zero). apply swap_cmp_mismatch. auto. |
---|
| 858 | case (Int.eq i0 Int.zero). apply swap_cmp_mismatch. auto. |
---|
| 859 | case (zeq b b0); intro. |
---|
| 860 | subst b0. rewrite zeq_true. rewrite Int.swap_cmpu. auto. |
---|
| 861 | rewrite zeq_false. apply swap_cmp_mismatch. auto. |
---|
| 862 | Qed. |
---|
| 863 | |
---|
| 864 | Theorem negate_cmpf_eq: |
---|
| 865 | forall v1 v2, notbool (cmpf Cne v1 v2) = cmpf Ceq v1 v2. |
---|
| 866 | Proof. |
---|
| 867 | destruct v1; destruct v2; simpl; auto. |
---|
| 868 | rewrite Float.cmp_ne_eq. rewrite notbool_negb_1. |
---|
| 869 | apply notbool_idem2. |
---|
| 870 | Qed. |
---|
| 871 | |
---|
| 872 | Theorem negate_cmpf_ne: |
---|
| 873 | forall v1 v2, notbool (cmpf Ceq v1 v2) = cmpf Cne v1 v2. |
---|
| 874 | Proof. |
---|
| 875 | destruct v1; destruct v2; simpl; auto. |
---|
| 876 | rewrite Float.cmp_ne_eq. rewrite notbool_negb_1. auto. |
---|
| 877 | Qed. |
---|
| 878 | |
---|
| 879 | Lemma or_of_bool: |
---|
| 880 | forall b1 b2, or (of_bool b1) (of_bool b2) = of_bool (b1 || b2). |
---|
| 881 | Proof. |
---|
| 882 | destruct b1; destruct b2; reflexivity. |
---|
| 883 | Qed. |
---|
| 884 | |
---|
| 885 | Theorem cmpf_le: |
---|
| 886 | forall v1 v2, cmpf Cle v1 v2 = or (cmpf Clt v1 v2) (cmpf Ceq v1 v2). |
---|
| 887 | Proof. |
---|
| 888 | destruct v1; destruct v2; simpl; auto. |
---|
| 889 | rewrite or_of_bool. decEq. apply Float.cmp_le_lt_eq. |
---|
| 890 | Qed. |
---|
| 891 | |
---|
| 892 | Theorem cmpf_ge: |
---|
| 893 | forall v1 v2, cmpf Cge v1 v2 = or (cmpf Cgt v1 v2) (cmpf Ceq v1 v2). |
---|
| 894 | Proof. |
---|
| 895 | destruct v1; destruct v2; simpl; auto. |
---|
| 896 | rewrite or_of_bool. decEq. apply Float.cmp_ge_gt_eq. |
---|
| 897 | Qed. |
---|
| 898 | |
---|
| 899 | Definition is_bool (v: val) := |
---|
| 900 | v = Vundef \/ v = Vtrue \/ v = Vfalse. |
---|
| 901 | |
---|
| 902 | Lemma of_bool_is_bool: |
---|
| 903 | forall b, is_bool (of_bool b). |
---|
| 904 | Proof. |
---|
| 905 | destruct b; unfold is_bool; simpl; tauto. |
---|
| 906 | Qed. |
---|
| 907 | |
---|
| 908 | Lemma undef_is_bool: is_bool Vundef. |
---|
| 909 | Proof. |
---|
| 910 | unfold is_bool; tauto. |
---|
| 911 | Qed. |
---|
| 912 | |
---|
| 913 | Lemma cmp_mismatch_is_bool: |
---|
| 914 | forall c, is_bool (cmp_mismatch c). |
---|
| 915 | Proof. |
---|
| 916 | destruct c; simpl; unfold is_bool; tauto. |
---|
| 917 | Qed. |
---|
| 918 | |
---|
| 919 | Lemma cmp_is_bool: |
---|
| 920 | forall c v1 v2, is_bool (cmp c v1 v2). |
---|
| 921 | Proof. |
---|
| 922 | destruct v1; destruct v2; simpl; try apply undef_is_bool. |
---|
| 923 | apply of_bool_is_bool. |
---|
| 924 | case (Int.eq i Int.zero). apply cmp_mismatch_is_bool. apply undef_is_bool. |
---|
| 925 | case (Int.eq i0 Int.zero). apply cmp_mismatch_is_bool. apply undef_is_bool. |
---|
| 926 | case (zeq b b0); intro. apply of_bool_is_bool. apply cmp_mismatch_is_bool. |
---|
| 927 | Qed. |
---|
| 928 | |
---|
| 929 | Lemma cmpu_is_bool: |
---|
| 930 | forall c v1 v2, is_bool (cmpu c v1 v2). |
---|
| 931 | Proof. |
---|
| 932 | destruct v1; destruct v2; simpl; try apply undef_is_bool. |
---|
| 933 | apply of_bool_is_bool. |
---|
| 934 | case (Int.eq i Int.zero). apply cmp_mismatch_is_bool. apply undef_is_bool. |
---|
| 935 | case (Int.eq i0 Int.zero). apply cmp_mismatch_is_bool. apply undef_is_bool. |
---|
| 936 | case (zeq b b0); intro. apply of_bool_is_bool. apply cmp_mismatch_is_bool. |
---|
| 937 | Qed. |
---|
| 938 | |
---|
| 939 | Lemma cmpf_is_bool: |
---|
| 940 | forall c v1 v2, is_bool (cmpf c v1 v2). |
---|
| 941 | Proof. |
---|
| 942 | destruct v1; destruct v2; simpl; |
---|
| 943 | apply undef_is_bool || apply of_bool_is_bool. |
---|
| 944 | Qed. |
---|
| 945 | |
---|
| 946 | Lemma notbool_is_bool: |
---|
| 947 | forall v, is_bool (notbool v). |
---|
| 948 | Proof. |
---|
| 949 | destruct v; simpl. |
---|
| 950 | apply undef_is_bool. apply of_bool_is_bool. |
---|
| 951 | apply undef_is_bool. unfold is_bool; tauto. |
---|
| 952 | Qed. |
---|
| 953 | |
---|
| 954 | Lemma notbool_xor: |
---|
| 955 | forall v, is_bool v -> v = xor (notbool v) Vone. |
---|
| 956 | Proof. |
---|
| 957 | intros. elim H; intro. |
---|
| 958 | subst v. reflexivity. |
---|
| 959 | elim H0; intro; subst v; reflexivity. |
---|
| 960 | Qed. |
---|
| 961 | |
---|
| 962 | Lemma rolm_lt_zero: |
---|
| 963 | forall v, rolm v Int.one Int.one = cmp Clt v (Vint Int.zero). |
---|
| 964 | Proof. |
---|
| 965 | intros. destruct v; simpl; auto. |
---|
| 966 | transitivity (Vint (Int.shru i (Int.repr (Z_of_nat Int.wordsize - 1)))). |
---|
| 967 | decEq. symmetry. rewrite Int.shru_rolm. auto. auto. |
---|
| 968 | rewrite Int.shru_lt_zero. destruct (Int.lt i Int.zero); auto. |
---|
| 969 | Qed. |
---|
| 970 | |
---|
| 971 | Lemma rolm_ge_zero: |
---|
| 972 | forall v, |
---|
| 973 | xor (rolm v Int.one Int.one) (Vint Int.one) = cmp Cge v (Vint Int.zero). |
---|
| 974 | Proof. |
---|
| 975 | intros. rewrite rolm_lt_zero. destruct v; simpl; auto. |
---|
| 976 | destruct (Int.lt i Int.zero); auto. |
---|
| 977 | Qed. |
---|
| 978 | *) |
---|
| 979 | (* * The ``is less defined'' relation between values. |
---|
| 980 | A value is less defined than itself, and [Vundef] is |
---|
| 981 | less defined than any value. *) |
---|
| 982 | |
---|
| 983 | ninductive Val_lessdef: val → val → Prop ≝ |
---|
| 984 | | lessdef_refl: ∀v. Val_lessdef v v |
---|
| 985 | | lessdef_undef: ∀v. Val_lessdef Vundef v. |
---|
| 986 | |
---|
| 987 | ninductive lessdef_list: list val → list val → Prop ≝ |
---|
| 988 | | lessdef_list_nil: |
---|
| 989 | lessdef_list (nil ?) (nil ?) |
---|
| 990 | | lessdef_list_cons: |
---|
| 991 | ∀v1,v2,vl1,vl2. |
---|
| 992 | Val_lessdef v1 v2 → lessdef_list vl1 vl2 → |
---|
| 993 | lessdef_list (v1 :: vl1) (v2 :: vl2). |
---|
| 994 | |
---|
| 995 | (*Hint Resolve lessdef_refl lessdef_undef lessdef_list_nil lessdef_list_cons.*) |
---|
| 996 | |
---|
| 997 | nlemma lessdef_list_inv: |
---|
| 998 | ∀vl1,vl2. lessdef_list vl1 vl2 → vl1 = vl2 ∨ in_list ? Vundef vl1. |
---|
| 999 | #vl1; nelim vl1; |
---|
| 1000 | ##[ #vl2; #H; ninversion H; /2/; #h1;#h2;#t1;#t2;#H1;#H2;#H3;#Hbad; ndestruct |
---|
| 1001 | ##| #h;#t;#IH;#vl2;#H; |
---|
| 1002 | ninversion H; |
---|
| 1003 | ##[ #H'; ndestruct |
---|
| 1004 | ##| #h1;#h2;#t1;#t2;#H1;#H2;#H3;#e1;#e2; ndestruct; |
---|
| 1005 | nelim H1; |
---|
| 1006 | ##[ nelim (IH t2 H2); |
---|
| 1007 | ##[ #e; ndestruct; /2/; |
---|
| 1008 | ##| /3/ ##] |
---|
| 1009 | ##| /3/ ##] |
---|
| 1010 | ##] |
---|
| 1011 | ##] nqed. |
---|
| 1012 | |
---|
| 1013 | nlemma load_result_lessdef: |
---|
| 1014 | ∀chunk,v1,v2. |
---|
| 1015 | Val_lessdef v1 v2 → Val_lessdef (load_result chunk v1) (load_result chunk v2). |
---|
[14] | 1016 | #chunk;#v1;#v2;#H; ninversion H; //; #v e1 e2; ncases chunk; nwhd in ⊢ (?%?); //; |
---|
[3] | 1017 | nqed. |
---|
| 1018 | |
---|
| 1019 | (* |
---|
| 1020 | Lemma zero_ext_lessdef: |
---|
| 1021 | forall n v1 v2, lessdef v1 v2 -> lessdef (zero_ext n v1) (zero_ext n v2). |
---|
| 1022 | Proof. |
---|
| 1023 | intros; inv H; simpl; auto. |
---|
| 1024 | Qed. |
---|
| 1025 | *) |
---|
| 1026 | nlemma sign_ext_lessdef: |
---|
| 1027 | ∀n,v1,v2. Val_lessdef v1 v2 → Val_lessdef (sign_ext n v1) (sign_ext n v2). |
---|
| 1028 | #n;#v1;#v2;#H;ninversion H;//;#v;#e1;#e2;nrewrite < e1 in H; nrewrite > e2; //; |
---|
| 1029 | nqed. |
---|
| 1030 | (* |
---|
| 1031 | Lemma singleoffloat_lessdef: |
---|
| 1032 | forall v1 v2, lessdef v1 v2 -> lessdef (singleoffloat v1) (singleoffloat v2). |
---|
| 1033 | Proof. |
---|
| 1034 | intros; inv H; simpl; auto. |
---|
| 1035 | Qed. |
---|
| 1036 | |
---|
| 1037 | End Val. |
---|
| 1038 | *) |
---|