1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 (* ********************************************************************** *)
16 (* Progetto FreeScale *)
19 (* Cosimo Oliboni, oliboni@cs.unibo.it *)
21 (* Questo materiale fa parte della tesi: *)
22 (* "Formalizzazione Interattiva dei Microcontroller a 8bit FreeScale" *)
24 (* data ultima modifica 15/11/2007 *)
25 (* ********************************************************************** *)
27 include "freescale/word16_lemmas.ma".
28 include "freescale/word32.ma".
34 nlemma word32_destruct_1 :
36 mk_word32 x1 y1 = mk_word32 x2 y2 → x1 = x2.
37 #x1; #x2; #y1; #y2; #H;
38 nchange with (match mk_word32 x2 y2 with [ mk_word32 a _ ⇒ x1 = a ]);
44 nlemma word32_destruct_2 :
46 mk_word32 x1 y1 = mk_word32 x2 y2 → y1 = y2.
47 #x1; #x2; #y1; #y2; #H;
48 nchange with (match mk_word32 x2 y2 with [ mk_word32 _ b ⇒ y1 = b ]);
54 nlemma symmetric_eqw32 : symmetricT word32 bool eq_w32.
59 nchange with (((eq_w16 w3 w1)⊗(eq_w16 w4 w2)) = ((eq_w16 w1 w3)⊗(eq_w16 w2 w4)));
60 nrewrite > (symmetric_eqw16 w1 w3);
61 nrewrite > (symmetric_eqw16 w2 w4);
65 nlemma symmetric_andw32 : symmetricT word32 word32 and_w32.
70 nchange with ((mk_word32 (and_w16 w3 w1) (and_w16 w4 w2)) = (mk_word32 (and_w16 w1 w3) (and_w16 w2 w4)));
71 nrewrite > (symmetric_andw16 w1 w3);
72 nrewrite > (symmetric_andw16 w2 w4);
76 nlemma associative_andw32 : ∀dw1,dw2,dw3.(and_w32 (and_w32 dw1 dw2) dw3) = (and_w32 dw1 (and_w32 dw2 dw3)).
84 nchange with (mk_word32 (and_w16 (and_w16 w1 w3) w5) (and_w16 (and_w16 w2 w4) w6) =
85 mk_word32 (and_w16 w1 (and_w16 w3 w5)) (and_w16 w2 (and_w16 w4 w6)));
86 nrewrite < (associative_andw16 w1 w3 w5);
87 nrewrite < (associative_andw16 w2 w4 w6);
91 nlemma symmetric_orw32 : symmetricT word32 word32 or_w32.
96 nchange with ((mk_word32 (or_w16 w3 w1) (or_w16 w4 w2)) = (mk_word32 (or_w16 w1 w3) (or_w16 w2 w4)));
97 nrewrite > (symmetric_orw16 w1 w3);
98 nrewrite > (symmetric_orw16 w2 w4);
102 nlemma associative_orw32 : ∀dw1,dw2,dw3.(or_w32 (or_w32 dw1 dw2) dw3) = (or_w32 dw1 (or_w32 dw2 dw3)).
110 nchange with (mk_word32 (or_w16 (or_w16 w1 w3) w5) (or_w16 (or_w16 w2 w4) w6) =
111 mk_word32 (or_w16 w1 (or_w16 w3 w5)) (or_w16 w2 (or_w16 w4 w6)));
112 nrewrite < (associative_orw16 w1 w3 w5);
113 nrewrite < (associative_orw16 w2 w4 w6);
117 nlemma symmetric_xorw32 : symmetricT word32 word32 xor_w32.
122 nchange with ((mk_word32 (xor_w16 w3 w1) (xor_w16 w4 w2)) = (mk_word32 (xor_w16 w1 w3) (xor_w16 w2 w4)));
123 nrewrite > (symmetric_xorw16 w1 w3);
124 nrewrite > (symmetric_xorw16 w2 w4);
128 nlemma associative_xorw32 : ∀dw1,dw2,dw3.(xor_w32 (xor_w32 dw1 dw2) dw3) = (xor_w32 dw1 (xor_w32 dw2 dw3)).
136 nchange with (mk_word32 (xor_w16 (xor_w16 w1 w3) w5) (xor_w16 (xor_w16 w2 w4) w6) =
137 mk_word32 (xor_w16 w1 (xor_w16 w3 w5)) (xor_w16 w2 (xor_w16 w4 w6)));
138 nrewrite < (associative_xorw16 w1 w3 w5);
139 nrewrite < (associative_xorw16 w2 w4 w6);
143 nlemma symmetric_plusw32_dc_dc : ∀dw1,dw2,c.plus_w32_dc_dc dw1 dw2 c = plus_w32_dc_dc dw2 dw1 c.
150 match plus_w16_dc_dc w2 w4 c with
151 [ pair l c ⇒ match plus_w16_dc_dc w1 w3 c with
152 [ pair h c' ⇒ pair ?? 〈h.l〉 c' ]] =
153 match plus_w16_dc_dc w4 w2 c with
154 [ pair l c ⇒ match plus_w16_dc_dc w3 w1 c with
155 [ pair h c' ⇒ pair ?? 〈h.l〉 c' ]]);
156 nrewrite > (symmetric_plusw16_dc_dc w4 w2 c);
157 ncases (plus_w16_dc_dc w2 w4 c);
160 match plus_w16_dc_dc w1 w3 c1 with
161 [ pair h c' ⇒ pair ?? 〈h.w5〉 c' ] =
162 match plus_w16_dc_dc w3 w1 c1 with
163 [ pair h c' ⇒ pair ?? 〈h.w5〉 c' ]);
164 nrewrite > (symmetric_plusw16_dc_dc w1 w3 c1);
168 nlemma symmetric_plusw32_dc_d : ∀dw1,dw2,c.plus_w32_dc_d dw1 dw2 c = plus_w32_dc_d dw2 dw1 c.
175 match plus_w16_dc_dc w2 w4 c with
176 [ pair l c ⇒ 〈plus_w16_dc_d w1 w3 c.l〉 ] =
177 match plus_w16_dc_dc w4 w2 c with
178 [ pair l c ⇒ 〈plus_w16_dc_d w3 w1 c.l〉 ]);
179 nrewrite > (symmetric_plusw16_dc_dc w4 w2 c);
180 ncases (plus_w16_dc_dc w2 w4 c);
182 nchange with (〈plus_w16_dc_d w1 w3 c1.w5〉 = 〈plus_w16_dc_d w3 w1 c1.w5〉);
183 nrewrite > (symmetric_plusw16_dc_d w1 w3 c1);
187 nlemma symmetric_plusw32_dc_c : ∀dw1,dw2,c.plus_w32_dc_c dw1 dw2 c = plus_w32_dc_c dw2 dw1 c.
194 plus_w16_dc_c w1 w3 (plus_w16_dc_c w2 w4 c) =
195 plus_w16_dc_c w3 w1 (plus_w16_dc_c w4 w2 c));
196 nrewrite > (symmetric_plusw16_dc_c w4 w2 c);
197 nrewrite > (symmetric_plusw16_dc_c w3 w1 (plus_w16_dc_c w2 w4 c));
201 nlemma symmetric_plusw32_d_dc : ∀dw1,dw2.plus_w32_d_dc dw1 dw2 = plus_w32_d_dc dw2 dw1.
208 match plus_w16_d_dc w2 w4 with
209 [ pair l c ⇒ match plus_w16_dc_dc w1 w3 c with
210 [ pair h c' ⇒ pair ?? 〈h.l〉 c' ]] =
211 match plus_w16_d_dc w4 w2 with
212 [ pair l c ⇒ match plus_w16_dc_dc w3 w1 c with
213 [ pair h c' ⇒ pair ?? 〈h.l〉 c' ]]);
214 nrewrite > (symmetric_plusw16_d_dc w4 w2);
215 ncases (plus_w16_d_dc w2 w4);
218 match plus_w16_dc_dc w1 w3 c with
219 [ pair h c' ⇒ pair ?? 〈h.w5〉 c' ] =
220 match plus_w16_dc_dc w3 w1 c with
221 [ pair h c' ⇒ pair ?? 〈h.w5〉 c' ]);
222 nrewrite > (symmetric_plusw16_dc_dc w1 w3 c);
226 nlemma symmetric_plusw32_d_d : ∀dw1,dw2.plus_w32_d_d dw1 dw2 = plus_w32_d_d dw2 dw1.
233 match plus_w16_d_dc w2 w4 with
234 [ pair l c ⇒ 〈plus_w16_dc_d w1 w3 c.l〉 ] =
235 match plus_w16_d_dc w4 w2 with
236 [ pair l c ⇒ 〈plus_w16_dc_d w3 w1 c.l〉 ]);
237 nrewrite > (symmetric_plusw16_d_dc w4 w2);
238 ncases (plus_w16_d_dc w2 w4);
240 nchange with (〈plus_w16_dc_d w1 w3 c.w5〉 = 〈plus_w16_dc_d w3 w1 c.w5〉);
241 nrewrite > (symmetric_plusw16_dc_d w1 w3 c);
245 nlemma symmetric_plusw32_d_c : ∀dw1,dw2.plus_w32_d_c dw1 dw2 = plus_w32_d_c dw2 dw1.
252 plus_w16_dc_c w1 w3 (plus_w16_d_c w2 w4) =
253 plus_w16_dc_c w3 w1 (plus_w16_d_c w4 w2));
254 nrewrite > (symmetric_plusw16_d_c w4 w2);
255 nrewrite > (symmetric_plusw16_dc_c w3 w1 (plus_w16_d_c w2 w4));
259 nlemma symmetric_mulw16 : symmetricT word16 word32 mul_w16.
265 nchange with (match mul_b8 b2 b4 with
266 [ mk_word16 t1_h t1_l ⇒ match mul_b8 b1 b4 with
267 [ mk_word16 t2_h t2_l ⇒ match mul_b8 b3 b2 with
268 [ mk_word16 t3_h t3_l ⇒ match mul_b8 b1 b3 with
269 [ mk_word16 t4_h t4_l ⇒ plus_w32_d_d (plus_w32_d_d (plus_w32_d_d 〈〈〈x0,x0〉:t3_h〉.〈t3_l:〈x0,x0〉〉〉 〈〈〈x0,x0〉:t2_h〉.〈t2_l:〈x0,x0〉〉〉) 〈〈t4_h:t4_l〉.〈〈x0,x0〉:〈x0,x0〉〉〉)〈〈〈x0,x0〉:〈x0,x0〉〉.〈t1_h:t1_l〉〉
270 ]]]] = match mul_b8 b4 b2 with
271 [ mk_word16 t1_h t1_l ⇒ match mul_b8 b3 b2 with
272 [ mk_word16 t2_h t2_l ⇒ match mul_b8 b1 b4 with
273 [ mk_word16 t3_h t3_l ⇒ match mul_b8 b3 b1 with
274 [ mk_word16 t4_h t4_l ⇒ plus_w32_d_d (plus_w32_d_d (plus_w32_d_d 〈〈〈x0,x0〉:t3_h〉.〈t3_l:〈x0,x0〉〉〉 〈〈〈x0,x0〉:t2_h〉.〈t2_l:〈x0,x0〉〉〉) 〈〈t4_h:t4_l〉.〈〈x0,x0〉:〈x0,x0〉〉〉)〈〈〈x0,x0〉:〈x0,x0〉〉.〈t1_h:t1_l〉〉
276 nrewrite < (symmetric_mulb8 b2 b4);
277 ncases (mul_b8 b2 b4);
279 nchange with (match mul_b8 b1 b4 with
280 [ mk_word16 t2_h t2_l ⇒ match mul_b8 b3 b2 with
281 [ mk_word16 t3_h t3_l ⇒ match mul_b8 b1 b3 with
282 [ mk_word16 t4_h t4_l ⇒ plus_w32_d_d (plus_w32_d_d (plus_w32_d_d 〈〈〈x0,x0〉:t3_h〉.〈t3_l:〈x0,x0〉〉〉 〈〈〈x0,x0〉:t2_h〉.〈t2_l:〈x0,x0〉〉〉) 〈〈t4_h:t4_l〉.〈〈x0,x0〉:〈x0,x0〉〉〉)〈〈〈x0,x0〉:〈x0,x0〉〉.〈b5:b6〉〉
283 ]]] = match mul_b8 b3 b2 with
284 [ mk_word16 t2_h t2_l ⇒ match mul_b8 b1 b4 with
285 [ mk_word16 t3_h t3_l ⇒ match mul_b8 b3 b1 with
286 [ mk_word16 t4_h t4_l ⇒ plus_w32_d_d (plus_w32_d_d (plus_w32_d_d 〈〈〈x0,x0〉:t3_h〉.〈t3_l:〈x0,x0〉〉〉 〈〈〈x0,x0〉:t2_h〉.〈t2_l:〈x0,x0〉〉〉) 〈〈t4_h:t4_l〉.〈〈x0,x0〉:〈x0,x0〉〉〉)〈〈〈x0,x0〉:〈x0,x0〉〉.〈b5:b6〉〉
288 ncases (mul_b8 b3 b2);
290 ncases (mul_b8 b1 b4);
292 nchange with (match mul_b8 b1 b3 with
293 [ mk_word16 t4_h t4_l ⇒ plus_w32_d_d (plus_w32_d_d (plus_w32_d_d 〈〈〈x0,x0〉:b7〉.〈b8:〈x0,x0〉〉〉 〈〈〈x0,x0〉:b9〉.〈b10:〈x0,x0〉〉〉) 〈〈t4_h:t4_l〉.〈〈x0,x0〉:〈x0,x0〉〉〉)〈〈〈x0,x0〉:〈x0,x0〉〉.〈b5:b6〉〉
294 ] = match mul_b8 b3 b1 with
295 [ mk_word16 t4_h t4_l ⇒ plus_w32_d_d (plus_w32_d_d (plus_w32_d_d 〈〈〈x0,x0〉:b9〉.〈b10:〈x0,x0〉〉〉 〈〈〈x0,x0〉:b7〉.〈b8:〈x0,x0〉〉〉) 〈〈t4_h:t4_l〉.〈〈x0,x0〉:〈x0,x0〉〉〉)〈〈〈x0,x0〉:〈x0,x0〉〉.〈b5:b6〉〉
297 nrewrite < (symmetric_mulb8 b1 b3);
298 ncases (mul_b8 b1 b3);
300 nchange with ((plus_w32_d_d (plus_w32_d_d (plus_w32_d_d 〈〈〈x0,x0〉:b7〉.〈b8:〈x0,x0〉〉〉 〈〈〈x0,x0〉:b9〉.〈b10:〈x0,x0〉〉〉) 〈〈b11:b12〉.〈〈x0,x0〉:〈x0,x0〉〉〉)〈〈〈x0,x0〉:〈x0,x0〉〉.〈b5:b6〉〉) =
301 (plus_w32_d_d (plus_w32_d_d (plus_w32_d_d 〈〈〈x0,x0〉:b9〉.〈b10:〈x0,x0〉〉〉 〈〈〈x0,x0〉:b7〉.〈b8:〈x0,x0〉〉〉) 〈〈b11:b12〉.〈〈x0,x0〉:〈x0,x0〉〉〉)〈〈〈x0,x0〉:〈x0,x0〉〉.〈b5:b6〉〉));
302 nrewrite > (symmetric_plusw32_d_d 〈〈〈x0,x0〉:b7〉.〈b8:〈x0,x0〉〉〉 〈〈〈x0,x0〉:b9〉.〈b10:〈x0,x0〉〉〉);
306 nlemma eqw32_to_eq : ∀dw1,dw2:word32.(eq_w32 dw1 dw2 = true) → (dw1 = dw2).
311 nchange in ⊢ (% → ?) with (((eq_w16 w3 w1)⊗(eq_w16 w4 w2)) = true);
313 nrewrite < (eqw16_to_eq ?? (andb_true_true_l ?? H));
314 nrewrite < (eqw16_to_eq ?? (andb_true_true_r ?? H));
318 nlemma eq_to_eqw32 : ∀dw1,dw2.dw1 = dw2 → eq_w32 dw1 dw2 = true.
324 nrewrite < (word32_destruct_1 ???? H);
325 nrewrite < (word32_destruct_2 ???? H);
326 nchange with (((eq_w16 w3 w3)⊗(eq_w16 w4 w4)) = true);
327 nrewrite > (eq_to_eqw16 w3 w3 (refl_eq ??));
328 nrewrite > (eq_to_eqw16 w4 w4 (refl_eq ??));