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