-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathstack_allocProofScript.sml
6350 lines (6195 loc) · 277 KB
/
stack_allocProofScript.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(*
Correctness proof for stack_alloc
*)
open preamble stack_allocTheory
stackLangTheory stackSemTheory stackPropsTheory
word_gcFunctionsTheory
local open blastLib wordSemTheory in end
val _ = temp_delsimps ["NORMEQ_CONV"]
val _ = temp_delsimps ["lift_disj_eq", "lift_imp_disj", "fromAList_def"]
val _ = new_theory"stack_allocProof";
val _ = (max_print_depth := 18);
val word_shift_def = backend_commonTheory.word_shift_def
val theWord_def = wordSemTheory.theWord_def;
val isWord_def = wordSemTheory.isWord_def;
val is_fwd_ptr_def = wordSemTheory.is_fwd_ptr_def;
val _ = set_grammar_ancestry["stack_alloc", "stackLang", "stackSem", "stackProps",
"word_gcFunctions" (* for memcpy *)
];
Overload good_dimindex[local] = ``misc$good_dimindex``
val _ = temp_bring_to_front_overload"compile"{Thy="stack_alloc",Name="compile"};
val drule = old_drule
(* TODO: move and join with stack_remove *)
Theorem lsl_lsr:
w2n ((n:'a word)) * 2 ** a < dimword (:'a) ⇒ n << a >>> a = n
Proof
Cases_on`n` \\ simp[]
\\ qmatch_assum_rename_tac`n < dimword _`
\\ srw_tac[][]
\\ REWRITE_TAC[GSYM wordsTheory.w2n_11]
\\ REWRITE_TAC[wordsTheory.w2n_lsr]
\\ simp[]
\\ simp[word_lsl_n2w]
\\ srw_tac[][]
>- (
simp[ZERO_DIV]
\\ Cases_on`n`
\\ full_simp_tac(srw_ss())[dimword_def]
\\ full_simp_tac(srw_ss())[bitTheory.LT_TWOEXP]
\\ full_simp_tac(srw_ss())[bitTheory.LOG2_def]
\\ qmatch_asmsub_rename_tac`SUC n * 2 ** a`
\\ qspecl_then[`a`,`2`,`SUC n`]mp_tac logrootTheory.LOG_EXP
\\ simp[] )
\\ simp[MULT_DIV]
QED
Theorem bytes_in_word_word_shift:
good_dimindex(:'a) ∧ w2n (bytes_in_word:'a word) * w2n n < dimword(:'a) ⇒
(bytes_in_word:'a word * n) >>> word_shift (:'a) = n
Proof
EVAL_TAC \\ srw_tac[][] \\ pop_assum mp_tac
\\ blastLib.BBLAST_TAC \\ simp[]
\\ blastLib.BBLAST_TAC \\ srw_tac[][]
\\ match_mp_tac lsl_lsr
\\ simp[]
\\ Cases_on`n`\\full_simp_tac(srw_ss())[word_lsl_n2w]
\\ full_simp_tac(srw_ss())[dimword_def]
QED
(* ---- *)
Triviality get_var_imm_case:
get_var_imm ri s =
case ri of
| Reg n => get_var n s
| Imm w => SOME (Word w)
Proof
Cases_on `ri` \\ full_simp_tac(srw_ss())[get_var_imm_def]
QED
Triviality prog_comp_lemma:
prog_comp = \(n,p). (n,FST (comp n (next_lab p 2) p))
Proof
full_simp_tac(srw_ss())[FUN_EQ_THM,FORALL_PROD,prog_comp_def]
QED
Theorem FST_prog_comp[simp]:
FST (prog_comp pp) = FST pp
Proof
Cases_on`pp` \\ EVAL_TAC
QED
Theorem lookup_IMP_lookup_compile[local]:
lookup dest s.code = SOME x /\
dest ≠ gc_stub_location ==>
?m1 n1. lookup dest (fromAList (compile c (toAList s.code))) =
SOME (FST (comp m1 n1 x))
Proof
full_simp_tac(srw_ss())[lookup_fromAList,compile_def] \\ srw_tac[][ALOOKUP_APPEND]
\\ `ALOOKUP (stubs c) dest = NONE` by
(full_simp_tac(srw_ss())[stubs_def] \\ srw_tac[][] \\ full_simp_tac(srw_ss())[] \\ decide_tac) \\ full_simp_tac(srw_ss())[]
\\ full_simp_tac(srw_ss())[prog_comp_lemma] \\ full_simp_tac(srw_ss())[ALOOKUP_MAP_2,ALOOKUP_toAList]
\\ metis_tac []
QED
Triviality map_bitmap_APPEND:
!x q stack p0 p1.
filter_bitmap x stack = SOME (p0,p1) /\
LENGTH q = LENGTH p0 ==>
map_bitmap x (q ++ q') stack =
case map_bitmap x q stack of
| NONE => NONE
| SOME (hd,ts,ws) => SOME (hd,ts++q',ws)
Proof
Induct \\ full_simp_tac(srw_ss())[map_bitmap_def]
\\ reverse (Cases \\ Cases_on `stack`)
\\ full_simp_tac(srw_ss())[map_bitmap_def,filter_bitmap_def]
THEN1 (srw_tac[][] \\ rpt (CASE_TAC \\ full_simp_tac(srw_ss())[]))
\\ CASE_TAC \\ full_simp_tac(srw_ss())[]
\\ CASE_TAC \\ full_simp_tac(srw_ss())[]
\\ Cases \\ full_simp_tac(srw_ss())[map_bitmap_def]
\\ every_case_tac \\ full_simp_tac(srw_ss())[]
QED
Theorem filter_bitmap_map_bitmap:
!x t q xs xs1 z ys ys1.
filter_bitmap x t = SOME (xs,xs1) /\
LENGTH q = LENGTH xs /\
map_bitmap x q t = SOME (ys,z,ys1) ==>
z = [] /\ ys1 = xs1
Proof
Induct
THEN1 ( fs[filter_bitmap_def,map_bitmap_def] )
\\ Cases_on `t` \\ Cases_on `q` \\ Cases
\\ rewrite_tac [filter_bitmap_def] \\ simp_tac std_ss [map_bitmap_def]
THEN1
(Cases_on `xs` \\ simp_tac std_ss [map_bitmap_def,LENGTH,ADD1]
\\ CASE_TAC \\ rename1 `_ = SOME y` \\ PairCases_on `y`
\\ simp_tac (srw_ss()) [map_bitmap_def,LENGTH,ADD1]
\\ ntac 2 strip_tac \\ first_x_assum drule
\\ disch_then (qspec_then `[]` mp_tac) \\ full_simp_tac(srw_ss())[])
THEN1
(CASE_TAC \\ rename1 `_ = SOME y` \\ PairCases_on `y`
\\ simp_tac (srw_ss()) [map_bitmap_def,LENGTH,ADD1]
\\ CASE_TAC \\ rename1 `_ = SOME y` \\ PairCases_on `y`
\\ simp_tac (srw_ss()) [map_bitmap_def,LENGTH,ADD1]
\\ metis_tac [])
\\ CASE_TAC \\ rename1 `_ = SOME y` \\ PairCases_on `y`
\\ simp_tac (srw_ss()) []
\\ rpt gen_tac \\ strip_tac
\\ first_x_assum match_mp_tac
\\ qexists_tac `t'` \\ full_simp_tac(srw_ss())[]
\\ qexists_tac `h'::t` \\ full_simp_tac(srw_ss())[]
QED
Definition get_bits_def:
get_bits w = GENLIST (\i. w ' i) (bit_length w − 1)
End
Theorem bit_length_thm:
!w. ((w >>> bit_length w) = 0w) /\ !n. n < bit_length w ==> (w >>> n) <> 0w
Proof
HO_MATCH_MP_TAC bit_length_ind \\ srw_tac[][]
\\ once_rewrite_tac [bit_length_def]
\\ srw_tac[][] \\ full_simp_tac(srw_ss())[AC ADD_COMM ADD_ASSOC]
\\ Cases_on `w = 0w` \\ full_simp_tac(srw_ss())[EVAL ``bit_length 0w``]
\\ Cases_on `n` \\ full_simp_tac(srw_ss())[]
\\ ntac 2 (pop_assum mp_tac)
\\ once_rewrite_tac [bit_length_def]
\\ full_simp_tac(srw_ss())[ADD1] \\ srw_tac[][]
QED
Triviality word_lsr_dimindex:
(w:'a word) >>> dimindex (:'a) = 0w
Proof
full_simp_tac(srw_ss())[]
QED
Theorem bit_length_LESS_EQ_dimindex:
bit_length (w:'a word) <= dimindex (:'a)
Proof
CCONTR_TAC \\ full_simp_tac(srw_ss())[GSYM NOT_LESS]
\\ imp_res_tac bit_length_thm
\\ full_simp_tac(srw_ss())[word_lsr_dimindex]
QED
Theorem shift_to_zero_word_msb:
(w:'a word) >>> n = 0w /\ word_msb w ==> dimindex (:'a) <= n
Proof
srw_tac [wordsLib.WORD_BIT_EQ_ss] []
\\ CCONTR_TAC
\\ qpat_x_assum `!xx.bb` mp_tac
\\ fs [GSYM NOT_LESS]
\\ qexists_tac `dimindex (:α) - 1 - n`
\\ simp []
QED
Triviality word_msb_IMP_bit_length:
!h. word_msb (h:'a word) ==> (bit_length h = dimindex (:'a))
Proof
srw_tac[][] \\ imp_res_tac shift_to_zero_word_msb \\ CCONTR_TAC
\\ imp_res_tac (DECIDE ``n<>m ==> n < m \/ m < n:num``)
\\ qspec_then `h` mp_tac bit_length_thm
\\ strip_tac \\ res_tac \\ full_simp_tac(srw_ss())[word_lsr_dimindex]
\\ decide_tac
QED
Triviality get_bits_intro:
word_msb (h:'a word) ==>
GENLIST (\i. h ' i) (dimindex (:'a) - 1) = get_bits h
Proof
full_simp_tac(srw_ss())[get_bits_def,word_msb_IMP_bit_length]
QED
Triviality filter_bitmap_APPEND:
!xs stack ys.
filter_bitmap (xs ++ ys) stack =
case filter_bitmap xs stack of
| NONE => NONE
| SOME (zs,rs) =>
case filter_bitmap ys rs of
| NONE => NONE
| SOME (zs2,rs) => SOME (zs ++ zs2,rs)
Proof
Induct \\ Cases_on `stack` \\ full_simp_tac(srw_ss())[filter_bitmap_def]
THEN1 (srw_tac[][] \\ every_case_tac \\ full_simp_tac(srw_ss())[])
THEN1 (srw_tac[][] \\ every_case_tac \\ full_simp_tac(srw_ss())[])
\\ Cases \\ full_simp_tac(srw_ss())[filter_bitmap_def] \\ srw_tac[][]
\\ rpt (CASE_TAC \\ full_simp_tac(srw_ss())[])
QED
Theorem bit_length_minus_1:
w <> 0w ==> bit_length w − 1 = bit_length (w >>> 1)
Proof
simp [Once bit_length_def]
QED
Theorem bit_length_eq_1:
bit_length w = 1 <=> w = 1w
Proof
Cases_on `w = 1w` \\ full_simp_tac(srw_ss())[] THEN1 (EVAL_TAC \\ full_simp_tac(srw_ss())[])
\\ once_rewrite_tac [bit_length_def] \\ srw_tac[][]
\\ once_rewrite_tac [bit_length_def] \\ srw_tac[][]
\\ pop_assum mp_tac
\\ simp_tac std_ss [GSYM w2n_11,w2n_lsr]
\\ Cases_on `w` \\ full_simp_tac(srw_ss())[]
\\ Cases_on `n` \\ full_simp_tac(srw_ss())[]
\\ Cases_on `n'` \\ full_simp_tac(srw_ss())[]
\\ full_simp_tac(srw_ss())[DIV_EQ_X] \\ decide_tac
QED
Theorem word_and_one_eq_0_iff:
!w. ((w && 1w) = 0w) <=> ~(w ' 0)
Proof
srw_tac [wordsLib.WORD_BIT_EQ_ss] [wordsTheory.word_index]
QED
Triviality split_num_forall_to_10:
($! P) <=> P 0 /\ P 1 /\ P 2 /\ P 3 /\ P 4 /\ P 5 /\
P 6 /\ P 7 /\ P 8 /\ P 9 /\ !x. 9 < x ==> P (x:num)
Proof
full_simp_tac(srw_ss())[GSYM (RAND_CONV ETA_CONV ``!x. P x``)]
\\ eq_tac \\ srw_tac[][]
\\ Cases_on `x` \\ full_simp_tac(srw_ss())[]
\\ ntac 5 (Cases_on `n` \\ full_simp_tac(srw_ss())[] \\ Cases_on `n'` \\ full_simp_tac(srw_ss())[])
\\ full_simp_tac(srw_ss())[ADD1,GSYM ADD_ASSOC]
\\ pop_assum match_mp_tac \\ decide_tac
QED
val nine_less = DECIDE
``9 < n ==> n <> 0 /\ n <> 1 /\ n <> 2 /\ n <> 3 /\ n <> 4 /\
n <> 5 /\ n <> 6 /\ n <> 7 /\ n <> 8 /\ n <> 9n``
Theorem word_shift_not_0:
word_shift (:'a) <> 0
Proof
srw_tac[][word_shift_def] \\ full_simp_tac(srw_ss())[]
QED
Theorem select_lower_lemma:
(n -- 0) w = ((w:'a word) << (dimindex(:'a)-n-1)) >>> (dimindex(:'a)-n-1)
Proof
srw_tac [wordsLib.WORD_BIT_EQ_ss, boolSimps.CONJ_ss] [wordsTheory.word_index]
\\ Cases_on `i + (dimindex (:α) - n - 1) < dimindex (:α)`
\\ fs []
QED
Theorem select_eq_select_0:
k <= n ==> (n -- k) w = (n - k -- 0) (w >>> k)
Proof
srw_tac [wordsLib.WORD_BIT_EQ_ss] [] \\ eq_tac \\ rw []
QED
Triviality is_fwd_ptr_iff:
!w. is_fwd_ptr w <=> ?v. w = Word v /\ (v && 3w) = 0w
Proof
Cases \\ full_simp_tac(srw_ss())[wordSemTheory.is_fwd_ptr_def]
QED
Triviality isWord_thm:
!w. isWord w = ?v. w = Word v
Proof
Cases \\ full_simp_tac(srw_ss())[wordSemTheory.isWord_def]
QED
Triviality lower_2w_eq:
!w:'a word. good_dimindex (:'a) ==> (w <+ 2w <=> w = 0w \/ w = 1w)
Proof
Cases \\ fs [good_dimindex_def,WORD_LO,dimword_def]
\\ rw [] \\ rw []
QED
Triviality EL_LENGTH_ADD_LEMMA:
EL (LENGTH init + LENGTH old) (init ++ old ++ [x] ++ st1) = x
Proof
mp_tac (EL_LENGTH_APPEND |> Q.SPECL [`[x] ++ st1`,`init++old`])
\\ fs []
QED
Triviality LUPDATE_LENGTH_ADD_LEMMA:
LUPDATE w (LENGTH init + LENGTH old) (init ++ old ++ [x] ++ st1) =
init ++ old ++ [w] ++ st1
Proof
mp_tac (LUPDATE_LENGTH |> Q.SPECL [`init++old`]) \\ fs []
QED
Theorem word_msb_IFF_lsr_EQ_0:
word_msb h <=> (h >>> (dimindex (:'a) - 1) <> 0w:'a word)
Proof
srw_tac [wordsLib.WORD_BIT_EQ_ss] []
QED
Theorem map_bitmap_IMP_LENGTH:
!x wl stack xs ys.
map_bitmap x wl stack = SOME (xs,ys) ==>
LENGTH xs = LENGTH x
Proof
recInduct map_bitmap_ind \\ fs [map_bitmap_def]
\\ rw [] \\ res_tac \\ fs []
\\ every_case_tac \\ fs [] \\ rw [] \\ fs []
QED
Theorem filter_bitmap_IMP_LENGTH:
!x stack q r.
filter_bitmap x stack = SOME (q,r) ==>
LENGTH stack = LENGTH x + LENGTH r
Proof
recInduct filter_bitmap_ind \\ fs [filter_bitmap_def]
\\ rw [] \\ res_tac \\ fs []
\\ every_case_tac \\ fs []
QED
Triviality EL_LENGTH_ADD_LEMMA:
!n xs y ys. LENGTH xs = n ==> EL n (xs ++ y::ys) = y
Proof
fs [EL_LENGTH_APPEND]
QED
Theorem bytes_in_word_word_shift_n2w:
good_dimindex (:α) ∧ (dimindex(:'a) DIV 8) * n < dimword (:α) ⇒
(bytes_in_word * n2w n) ⋙ word_shift (:α) = (n2w n):'a word
Proof
strip_tac \\ match_mp_tac bytes_in_word_word_shift
\\ fs [bytes_in_word_def]
\\ `(dimindex (:α) DIV 8) < dimword (:α) /\ n < dimword (:α)` by
(rfs [good_dimindex_def,dimword_def] \\ rfs [])
\\ fs []
QED
val tac = simp [list_Seq_def,evaluate_def,inst_def,word_exp_def,get_var_def,
wordLangTheory.word_op_def,mem_load_def,assign_def,set_var_def,
FLOOKUP_UPDATE,mem_store_def,dec_clock_def,get_var_imm_def,
asmTheory.word_cmp_def,
labSemTheory.word_cmp_def,GREATER_EQ,GSYM NOT_LESS,FUPDATE_LIST,
wordLangTheory.word_sh_def,word_shift_not_0,FLOOKUP_UPDATE]
val tac1 = simp [Once list_Seq_def, evaluate_def,inst_def,word_exp_def,get_var_def,
wordLangTheory.word_op_def,mem_load_def,assign_def,set_var_def,
FLOOKUP_UPDATE,mem_store_def,dec_clock_def,get_var_imm_def,
asmTheory.word_cmp_def,set_store_def,
labSemTheory.word_cmp_def,GREATER_EQ,GSYM NOT_LESS,FUPDATE_LIST,
wordLangTheory.word_sh_def,word_shift_not_0,FLOOKUP_UPDATE]
fun abbrev_under_exists tm tac =
(fn state => (`?^(tm). ^(hd (fst (hd (fst (tac state)))))` by
(fs [markerTheory.Abbrev_def] \\ NO_TAC)) state)
Triviality memcpy_code_thm:
!n a b m dm b1 m1 (s:('a,'c,'b)stackSem$state).
memcpy ((n2w n):'a word) a b m dm = (b1:'a word,m1,T) /\
n < dimword (:'a) /\
s.memory = m /\ s.mdomain = dm /\
get_var 0 s = SOME (Word (n2w n)) /\
1 IN FDOM s.regs /\
get_var 2 s = SOME (Word a) /\
get_var 3 s = SOME (Word b) ==>
?r1.
evaluate (memcpy_code,s with clock := s.clock + n) =
(NONE,s with <| memory := m1;
regs := s.regs |++ [(0,Word 0w);
(1,r1);
(2,Word (a + n2w n * bytes_in_word));
(3,Word b1)] |>)
Proof
Induct THEN1
(simp [Once memcpy_def]
\\ srw_tac[][]
\\ full_simp_tac(srw_ss())[memcpy_code_def,
evaluate_def,get_var_def,get_var_imm_def]
\\ full_simp_tac(srw_ss())[EVAL ``word_cmp NotEqual 0w 0w``]
\\ full_simp_tac(srw_ss())[state_component_equality]
\\ full_simp_tac(srw_ss())[FUPDATE_LIST,GSYM fmap_EQ,FLOOKUP_DEF,EXTENSION,
FUN_EQ_THM,FAPPLY_FUPDATE_THM]
\\ once_rewrite_tac [split_num_forall_to_10] \\ full_simp_tac(srw_ss())[nine_less])
\\ simp [Once memcpy_def]
\\ rpt gen_tac \\ strip_tac \\ full_simp_tac(srw_ss())[]
\\ full_simp_tac(srw_ss())[ADD1,GSYM word_add_n2w]
\\ pairarg_tac \\ full_simp_tac(srw_ss())[] \\ rpt var_eq_tac \\ full_simp_tac(srw_ss())[]
\\ simp [memcpy_code_def,evaluate_def,get_var_def,get_var_imm_def]
\\ full_simp_tac(srw_ss())[labSemTheory.word_cmp_def,asmTheory.word_cmp_def,word_add_n2w,get_var_def]
\\ tac
\\ qpat_abbrev_tac `s3 = s with <| regs := _ ; memory := _; clock := _ |>`
\\ `memcpy ((n2w n):'a word) (a + bytes_in_word) (b + bytes_in_word)
(s3 with clock := s3.clock - n).memory
(s3 with clock := s3.clock - n).mdomain = (b1,m1,T)` by
(unabbrev_all_tac \\ full_simp_tac(srw_ss())[])
\\ first_x_assum drule \\ full_simp_tac(srw_ss())[]
\\ impl_tac THEN1
(unabbrev_all_tac \\ full_simp_tac(srw_ss())[FLOOKUP_UPDATE,GSYM word_add_n2w] \\ decide_tac)
\\ strip_tac
\\ `s3 with clock := s3.clock - n + n = s3` by
(unabbrev_all_tac \\ full_simp_tac(srw_ss())[state_component_equality] \\ decide_tac)
\\ full_simp_tac(srw_ss())[memcpy_code_def,list_Seq_def,STOP_def]
\\ unabbrev_all_tac
\\ full_simp_tac(srw_ss())[state_component_equality]
\\ full_simp_tac(srw_ss())[FUPDATE_LIST,GSYM fmap_EQ,FLOOKUP_DEF,EXTENSION,
FUN_EQ_THM,FAPPLY_FUPDATE_THM]
\\ once_rewrite_tac [split_num_forall_to_10] \\ full_simp_tac(srw_ss())[nine_less]
\\ full_simp_tac(srw_ss())[GSYM word_add_n2w,WORD_LEFT_ADD_DISTRIB]
QED
Theorem memcpy_code_thm:
!w a b m dm b1 m1 (s:('a,'c,'b)stackSem$state).
memcpy (w:'a word) a b m dm = (b1:'a word,m1,T) /\
s.memory = m /\ s.mdomain = dm /\
get_var 0 s = SOME (Word w) /\
1 IN FDOM s.regs /\
get_var 2 s = SOME (Word a) /\
get_var 3 s = SOME (Word b) ==>
?r1.
evaluate (memcpy_code,s with clock := s.clock + w2n w) =
(NONE,s with <| memory := m1;
regs := s.regs |++ [(0,Word 0w);
(1,r1);
(2,Word (a + w * bytes_in_word));
(3,Word b1)] |>)
Proof
Cases \\ full_simp_tac(srw_ss())[]
\\ pop_assum mp_tac \\ qspec_tac (`n`,`n`)
\\ full_simp_tac(srw_ss())[PULL_FORALL] \\ rpt strip_tac
\\ match_mp_tac (memcpy_code_thm |> SIMP_RULE (srw_ss()) [])
\\ metis_tac []
QED
(* gc_kind = Simple *)
val word_gc_fun_lemma =
word_gc_fun_def
|> SPEC_ALL
|> DISCH ``conf.gc_kind = Simple``
|> SIMP_RULE std_ss [TypeBase.case_def_of ``:gc_kind`` ]
|> SIMP_RULE std_ss [word_full_gc_def]
|> SIMP_RULE std_ss [Once LET_THM]
|> SIMP_RULE std_ss [Once LET_THM]
|> SIMP_RULE std_ss [Once LET_THM]
|> SIMP_RULE std_ss [Once LET_THM]
|> SIMP_RULE std_ss [Once LET_THM,word_gc_move_roots_def]
Triviality word_gc_fun_thm:
conf.gc_kind = Simple ==>
word_gc_fun conf (roots,m,dm,s) =
let (w1,i1:'a word,pa1,m1,c1) =
word_gc_move conf
(s ' Globals,0w,theWord (s ' OtherHeap),
theWord (s ' CurrHeap),m,dm) in
let (ws2,i2,pa2,m2,c2) =
word_gc_move_roots conf
(roots,i1,pa1,theWord (s ' CurrHeap),m1,dm) in
let (i1,pa1,m1,c2) =
word_gc_move_loop (dimword (:'a)) conf
(theWord (s ' OtherHeap),i2,pa2,
theWord (s ' CurrHeap),m2,dm,c1 /\ c2) in
let s1 =
s |++
[(CurrHeap,Word (theWord (s ' OtherHeap)));
(OtherHeap,Word (theWord (s ' CurrHeap)));
(NextFree,Word pa1);
(TriggerGC,
Word
(theWord (s ' OtherHeap) +
theWord (s ' HeapLength)));
(EndOfHeap,
Word
(theWord (s ' OtherHeap) +
theWord (s ' HeapLength)));
(Globals,w1);
(GlobReal,glob_real conf (theWord (s ' OtherHeap)) w1)]
in
if word_gc_fun_assum conf s /\ c2 then SOME (ws2,m1,s1) else NONE
Proof
full_simp_tac(srw_ss())[word_gc_fun_lemma,LET_THM]
\\ rpt (pairarg_tac \\ full_simp_tac(srw_ss())[]
\\ rpt var_eq_tac \\ full_simp_tac(srw_ss())[])
\\ IF_CASES_TAC \\ full_simp_tac(srw_ss())[]
QED
val gc_lemma = gc_def
|> SPEC_ALL
|> DISCH ``s.gc_fun = word_gc_fun conf``
|> SIMP_RULE std_ss [] |> UNDISCH
|> DISCH ``conf.gc_kind = Simple``
|> SIMP_RULE std_ss [word_gc_fun_thm] |> DISCH_ALL
Definition word_gc_move_roots_bitmaps_def:
word_gc_move_roots_bitmaps conf (stack,bitmaps,i1,pa1,curr,m,dm) =
case enc_stack bitmaps stack of
| NONE => (ARB,ARB,ARB,ARB,F)
| SOME wl_list =>
let (wl,i2,pa2,m2,c2) =
word_gc_move_roots conf (wl_list,i1,pa1,curr,m,dm) in
case dec_stack bitmaps wl stack of
| NONE => (ARB,ARB,ARB,ARB,F)
| SOME stack => (stack,i2,pa2,m2,c2)
End
Theorem word_gc_move_loop_F:
!k conf pb i pa old m dm i1 pa1 m1 c1.
word_gc_move_loop k conf (pb,i,pa,old,m,dm,F) = (i1,pa1,m1,c1) ==> ~c1
Proof
Induct \\ once_rewrite_tac [word_gc_move_loop_def] \\ fs [] \\ rw []
\\ pairarg_tac \\ fs []
\\ IF_CASES_TAC \\ fs []
\\ pairarg_tac \\ fs []
QED
Theorem word_gc_move_loop_ok:
word_gc_move_loop k conf (pb,i,pa,old,m,dm,c) = (i1,pa1,m1,c1) ==> c1 ==> c
Proof
Cases_on `c` \\ fs [] \\ rw [] \\ imp_res_tac word_gc_move_loop_F \\ fs []
QED
Triviality gc_thm:
s.gc_fun = word_gc_fun conf /\ conf.gc_kind = Simple ==>
gc (s:('a,'c,'b)stackSem$state) =
if LENGTH s.stack < s.stack_space then NONE else
let unused = TAKE s.stack_space s.stack in
let stack = DROP s.stack_space s.stack in
let (w1,i1,pa1,m1,c1) =
word_gc_move conf
(s.store ' Globals,0w,
theWord (s.store ' OtherHeap),
theWord (s.store ' CurrHeap),s.memory,s.mdomain) in
let (stack,i2,pa2,m2,c2) =
word_gc_move_roots_bitmaps conf
(stack,s.bitmaps,i1,pa1,
theWord (s.store ' CurrHeap),m1,s.mdomain) in
let (i1,pa1,m1,c2) =
word_gc_move_loop (dimword(:'a)) conf
(theWord (s.store ' OtherHeap),i2,pa2,
theWord (s.store ' CurrHeap),m2,s.mdomain,
c1 ∧ c2) in
let s1 =
s.store |++
[(CurrHeap,Word (theWord (s.store ' OtherHeap)));
(OtherHeap,Word (theWord (s.store ' CurrHeap)));
(NextFree,Word pa1);
(TriggerGC,
Word
(theWord (s.store ' OtherHeap) +
theWord (s.store ' HeapLength)));
(EndOfHeap,
Word
(theWord (s.store ' OtherHeap) +
theWord (s.store ' HeapLength)));
(Globals,w1);
(GlobReal,glob_real conf (theWord (s.store ' OtherHeap)) w1)] in
if word_gc_fun_assum conf s.store /\ c2 then SOME (s with
<|stack := unused ++ stack; store := s1;
regs := FEMPTY; memory := m1|>) else NONE
Proof
strip_tac \\ drule gc_lemma
\\ disch_then (fn th => full_simp_tac(srw_ss())[th])
\\ IF_CASES_TAC \\ full_simp_tac(srw_ss())[]
\\ full_simp_tac(srw_ss())[LET_THM,word_gc_move_roots_bitmaps_def]
\\ CASE_TAC \\ full_simp_tac(srw_ss())[]
THEN1
(rpt (pairarg_tac \\ full_simp_tac(srw_ss())[]
\\ rpt var_eq_tac \\ full_simp_tac(srw_ss())[])
\\ imp_res_tac word_gc_move_loop_F \\ fs [])
\\ rpt (pairarg_tac \\ full_simp_tac(srw_ss())[]
\\ rpt var_eq_tac \\ full_simp_tac(srw_ss())[])
\\ Cases_on `dec_stack s.bitmaps ws2 (DROP s.stack_space s.stack)`
THEN1
(full_simp_tac(srw_ss())[] \\ rpt var_eq_tac \\ full_simp_tac(srw_ss())[]
\\ imp_res_tac word_gc_move_loop_F \\ full_simp_tac(srw_ss())[]
\\ IF_CASES_TAC \\ full_simp_tac(srw_ss())[])
\\ full_simp_tac(srw_ss())[] \\ rpt var_eq_tac \\ full_simp_tac(srw_ss())[]
\\ IF_CASES_TAC \\ full_simp_tac(srw_ss())[]
QED
Definition word_gc_move_bitmaps_def:
word_gc_move_bitmaps conf (w,stack,bitmaps,i1,pa1,curr,m,dm) =
case full_read_bitmap bitmaps w of
| NONE => NONE
| SOME bs =>
case filter_bitmap bs stack of
| NONE => NONE
| SOME (ts,ws) =>
let (wl,i2,pa2,m2,c2) =
word_gc_move_roots conf (ts,i1,pa1,curr,m,dm) in
case map_bitmap bs wl stack of
| NONE => NONE
| SOME (hd,ts1,ws') =>
SOME (hd,ws,i2,pa2,m2,c2)
End
Triviality word_gc_move_roots_APPEND:
!xs ys i1 pa1 m.
word_gc_move_roots conf (xs++ys,i1,pa1,curr,m,dm) =
let (ws1,i1,pa1,m1,c1) = word_gc_move_roots conf (xs,i1,pa1,curr,m,dm) in
let (ws2,i2,pa2,m2,c2) = word_gc_move_roots conf (ys,i1,pa1,curr,m1,dm) in
(ws1++ws2,i2,pa2,m2,c1 /\ c2)
Proof
Induct \\ full_simp_tac(srw_ss())[word_gc_move_roots_def,LET_THM]
\\ srw_tac[][] \\ pairarg_tac \\ full_simp_tac(srw_ss())[]
\\ pairarg_tac \\ fs[]
\\ pairarg_tac \\ fs[]
\\ pairarg_tac \\ fs[]
\\ pairarg_tac \\ fs[]
\\ rveq \\ fs[]
\\ EQ_TAC \\ fs[] \\ rw[]
QED
Theorem word_gc_move_roots_IMP_LENGTH:
!xs r0 r1 curr r2 dm ys i2 pa2 m2 c conf.
word_gc_move_roots conf (xs,r0,r1,curr,r2,dm) = (ys,i2,pa2,m2,c) ==>
LENGTH ys = LENGTH xs
Proof
Induct \\ full_simp_tac(srw_ss())[word_gc_move_roots_def,LET_THM] \\ srw_tac[][]
\\ rpt (pairarg_tac \\ full_simp_tac(srw_ss())[])
\\ rpt var_eq_tac \\ full_simp_tac(srw_ss())[] \\ res_tac
QED
Triviality word_gc_move_roots_bitmaps:
!stack i1 pa1 m stack2 i2 pa2 m2.
(word_gc_move_roots_bitmaps conf (stack,bitmaps,i1,pa1,curr,m,dm) =
(stack2,i2,pa2,m2,T)) ==>
word_gc_move_roots_bitmaps conf (stack,bitmaps,i1,pa1,curr,m,dm) =
case stack of
| [] => (ARB,ARB,ARB,ARB,F)
| (w::ws) =>
if w = Word 0w then (stack,i1,pa1,m,ws = []) else
case word_gc_move_bitmaps conf (w,ws,bitmaps,i1,pa1,curr,m,dm) of
| NONE => (ARB,ARB,ARB,ARB,F)
| SOME (new,stack,i2,pa2,m2,c2) =>
let (stack,i,pa,m,c3) =
word_gc_move_roots_bitmaps conf (stack,bitmaps,i2,pa2,curr,m2,dm) in
(w::new++stack,i,pa,m,c2 /\ c3)
Proof
Cases THEN1 (full_simp_tac(srw_ss())[word_gc_move_roots_bitmaps_def,
enc_stack_def])
\\ rpt strip_tac \\ pop_assum mp_tac \\ full_simp_tac(srw_ss())[]
\\ IF_CASES_TAC \\ full_simp_tac(srw_ss())[]
THEN1 (full_simp_tac(srw_ss())[word_gc_move_roots_bitmaps_def,enc_stack_def]
\\ IF_CASES_TAC \\ full_simp_tac(srw_ss())[word_gc_move_roots_def,LET_THM,dec_stack_def])
\\ full_simp_tac(srw_ss())[word_gc_move_roots_bitmaps_def,word_gc_move_bitmaps_def,enc_stack_def]
\\ Cases_on `full_read_bitmap bitmaps h` \\ full_simp_tac(srw_ss())[]
\\ Cases_on `filter_bitmap x t` \\ full_simp_tac(srw_ss())[]
\\ rename1 `_ = SOME filter_res` \\ PairCases_on `filter_res` \\ full_simp_tac(srw_ss())[]
\\ Cases_on `enc_stack bitmaps filter_res1` \\ full_simp_tac(srw_ss())[]
\\ rename1 `_ = SOME enc_rest` \\ full_simp_tac(srw_ss())[word_gc_move_roots_APPEND]
\\ simp [Once LET_DEF]
\\ Cases_on `word_gc_move_roots conf (filter_res0,i1,pa1,curr,m,dm)` \\ full_simp_tac(srw_ss())[]
\\ PairCases_on `r` \\ full_simp_tac(srw_ss())[dec_stack_def]
\\ Cases_on `word_gc_move_roots conf (enc_rest,r0,r1,curr,r2,dm)` \\ full_simp_tac(srw_ss())[]
\\ PairCases_on `r` \\ full_simp_tac(srw_ss())[]
\\ CASE_TAC \\ full_simp_tac(srw_ss())[] \\ rename1 `_ = SOME map_rest` \\ full_simp_tac(srw_ss())[]
\\ PairCases_on `map_rest` \\ full_simp_tac(srw_ss())[]
\\ imp_res_tac word_gc_move_roots_IMP_LENGTH \\ full_simp_tac(srw_ss())[]
\\ drule (GEN_ALL map_bitmap_APPEND) \\ full_simp_tac(srw_ss())[]
\\ disch_then (mp_tac o SPEC_ALL) \\ full_simp_tac(srw_ss())[]
\\ full_simp_tac(srw_ss())[] \\ pop_assum kall_tac
\\ CASE_TAC \\ full_simp_tac(srw_ss())[]
\\ rename1 `_ = SOME z` \\ full_simp_tac(srw_ss())[] \\ PairCases_on `z` \\ full_simp_tac(srw_ss())[]
\\ strip_tac \\ rpt var_eq_tac \\ full_simp_tac(srw_ss())[]
\\ CASE_TAC \\ full_simp_tac(srw_ss())[]
\\ strip_tac \\ rpt var_eq_tac \\ full_simp_tac(srw_ss())[]
\\ imp_res_tac word_gc_move_roots_IMP_LENGTH \\ full_simp_tac(srw_ss())[]
\\ drule filter_bitmap_map_bitmap
\\ disch_then drule \\ full_simp_tac(srw_ss())[]
\\ strip_tac \\ rpt var_eq_tac \\ full_simp_tac(srw_ss())[]
QED
Definition word_gc_move_bitmap_def:
word_gc_move_bitmap conf (w,stack,i1,pa1,curr,m,dm) =
let bs = get_bits w in
case filter_bitmap bs stack of
| NONE => NONE
| SOME (ts,ws) =>
let (wl,i2,pa2,m2,c2) = word_gc_move_roots conf (ts,i1,pa1,curr,m,dm) in
case map_bitmap bs wl stack of
| NONE => NONE
| SOME (hd,v2) => SOME (hd,ws,i2,pa2,m2,c2)
End
val map_bitmap_APPEND_APPEND = Q.prove(
`!vs1 stack x0 x1 ws2 vs2 ws1.
filter_bitmap vs1 stack = SOME (x0,x1) /\
LENGTH x0 = LENGTH ws1 ==>
map_bitmap (vs1 ++ vs2) (ws1 ++ ws2) stack =
case map_bitmap vs1 ws1 stack of
| NONE => NONE
| SOME (ts1,ts2,ts3) =>
case map_bitmap vs2 ws2 ts3 of
| NONE => NONE
| SOME (us1,us2,us3) => SOME (ts1++us1,ts2++us2,us3)`,
Induct \\ full_simp_tac(srw_ss())[map_bitmap_def] THEN1
(Cases \\ full_simp_tac(srw_ss())[filter_bitmap_def]
\\ once_rewrite_tac [EQ_SYM_EQ] \\ full_simp_tac(srw_ss())[LENGTH_NIL]
\\ srw_tac[][] \\ every_case_tac \\ full_simp_tac(srw_ss())[])
\\ Cases_on `stack` \\ full_simp_tac(srw_ss())[filter_bitmap_def]
\\ reverse Cases \\ full_simp_tac(srw_ss())[filter_bitmap_def,map_bitmap_def]
THEN1 (srw_tac[][] \\ every_case_tac \\ full_simp_tac(srw_ss())[])
\\ CASE_TAC \\ full_simp_tac(srw_ss())[]
\\ CASE_TAC \\ full_simp_tac(srw_ss())[]
\\ Cases_on `ws1` \\ full_simp_tac(srw_ss())[LENGTH,map_bitmap_def]
\\ srw_tac[][] \\ every_case_tac \\ full_simp_tac(srw_ss())[])
|> SIMP_RULE std_ss [];
val word_gc_move_bitmaps_Loc =
``word_gc_move_bitmaps conf (Loc l1 l2,stack,bitmaps,i1,pa1,curr,m,dm)``
|> SIMP_CONV std_ss [word_gc_move_bitmaps_def,full_read_bitmap_def];
Triviality word_gc_move_bitmaps_unroll:
word_gc_move_bitmaps conf (Word w,stack,bitmaps,i1,pa1,curr,m,dm) = SOME x /\
LENGTH bitmaps < dimword (:'a) - 1 /\ good_dimindex (:'a) ==>
word_gc_move_bitmaps conf (Word w,stack,bitmaps,i1,pa1,curr,m,dm) =
case DROP (w2n (w - 1w:'a word)) bitmaps of
| [] => NONE
| (y::ys) =>
case word_gc_move_bitmap conf (y,stack,i1,pa1,curr,m,dm) of
| NONE => NONE
| SOME (hd,ws,i2,pa2,m2,c2) =>
if ~(word_msb y) then SOME (hd,ws,i2,pa2,m2,c2) else
case word_gc_move_bitmaps conf (Word (w+1w),ws,bitmaps,i2,pa2,curr,m2,dm) of
| NONE => NONE
| SOME (hd3,ws3,i3,pa3,m3,c3) =>
SOME (hd++hd3,ws3,i3,pa3,m3,c2 /\ c3)
Proof
full_simp_tac(srw_ss())[word_gc_move_bitmaps_def,full_read_bitmap_def]
\\ Cases_on `w = 0w` \\ full_simp_tac(srw_ss())[]
\\ Cases_on `DROP (w2n (w + -1w)) bitmaps`
\\ full_simp_tac(srw_ss())[read_bitmap_def]
\\ reverse (Cases_on `word_msb h`)
THEN1
(full_simp_tac(srw_ss())[word_gc_move_bitmap_def,get_bits_def,LET_THM]
\\ CASE_TAC \\ rename1 `_ = SOME y` \\ PairCases_on `y`
\\ full_simp_tac(srw_ss())[]
\\ pairarg_tac \\ full_simp_tac(srw_ss())[]
\\ CASE_TAC \\ rename1 `_ = SOME y` \\ PairCases_on `y`
\\ full_simp_tac(srw_ss())[]
\\ strip_tac \\ rpt var_eq_tac \\ full_simp_tac(srw_ss())[])
\\ full_simp_tac(srw_ss())[] \\ Cases_on `read_bitmap t`
\\ full_simp_tac(srw_ss())[]
\\ CASE_TAC \\ rename1 `_ = SOME y`
\\ PairCases_on `y` \\ full_simp_tac(srw_ss())[LET_THM]
\\ pairarg_tac \\ full_simp_tac(srw_ss())[]
\\ CASE_TAC \\ rename1 `_ = SOME z`
\\ PairCases_on `z` \\ full_simp_tac(srw_ss())[LET_THM]
\\ full_simp_tac(srw_ss())[word_gc_move_bitmap_def,LET_THM] \\ rev_full_simp_tac(srw_ss())[get_bits_intro]
\\ strip_tac \\ rpt var_eq_tac
\\ IF_CASES_TAC THEN1
(sg `F`
\\ full_simp_tac(srw_ss())[wordsLib.WORD_DECIDE ``w+1w=0w <=> (w = -1w)``]
\\ rpt var_eq_tac \\ full_simp_tac(srw_ss())[good_dimindex_def]
\\ full_simp_tac(srw_ss())[word_2comp_def] \\ full_simp_tac(srw_ss())[dimword_def]
\\ imp_res_tac DROP_IMP_LESS_LENGTH \\ decide_tac)
\\ `DROP (w2n w) bitmaps = t` by
(`w2n w = SUC (w2n (w + -1w))` suffices_by
metis_tac [DROP_EQ_CONS_IMP_DROP_SUC]
\\ Cases_on `w` \\ full_simp_tac(srw_ss())[word_add_n2w]
\\ `~(n < 1) /\ n - 1 < dimword (:'a)` by decide_tac
\\ full_simp_tac std_ss [GSYM word_sub_def,addressTheory.word_arith_lemma2]
\\ full_simp_tac(srw_ss())[] \\ decide_tac) \\ full_simp_tac(srw_ss())[] \\ pop_assum kall_tac
\\ full_simp_tac(srw_ss())[filter_bitmap_APPEND]
\\ CASE_TAC \\ full_simp_tac(srw_ss())[]
\\ PairCases_on `x` \\ full_simp_tac(srw_ss())[]
\\ Cases_on `filter_bitmap x' x1` \\ full_simp_tac(srw_ss())[]
\\ PairCases_on `x` \\ full_simp_tac(srw_ss())[]
\\ rpt var_eq_tac \\ full_simp_tac(srw_ss())[]
\\ full_simp_tac(srw_ss())[word_gc_move_roots_APPEND,LET_THM]
\\ pairarg_tac \\ full_simp_tac(srw_ss())[]
\\ pairarg_tac \\ full_simp_tac(srw_ss())[]
\\ rpt var_eq_tac \\ full_simp_tac(srw_ss())[]
\\ qpat_x_assum `filter_bitmap (get_bits h) stack = SOME (x0,x1)` assume_tac
\\ drule (map_bitmap_APPEND_APPEND |> GEN_ALL)
\\ `LENGTH x0 = LENGTH wl'` by (imp_res_tac word_gc_move_roots_IMP_LENGTH \\ full_simp_tac(srw_ss())[])
\\ disch_then drule
\\ disch_then (qspecl_then [`ws2`,`x'`] mp_tac)
\\ strip_tac \\ full_simp_tac(srw_ss())[] \\ pop_assum kall_tac
\\ CASE_TAC \\ full_simp_tac(srw_ss())[]
\\ PairCases_on `x` \\ full_simp_tac(srw_ss())[]
\\ drule filter_bitmap_map_bitmap
\\ once_rewrite_tac [EQ_SYM_EQ] \\ disch_then drule
\\ once_rewrite_tac [EQ_SYM_EQ] \\ disch_then drule
\\ strip_tac \\ rpt var_eq_tac \\ full_simp_tac(srw_ss())[]
\\ CASE_TAC \\ full_simp_tac(srw_ss())[]
\\ PairCases_on `x` \\ full_simp_tac(srw_ss())[]
QED
Triviality word_gc_move_bitmap_unroll:
word_gc_move_bitmap conf (w,stack,i1,pa1,curr,m,dm) =
if w = 0w:'a word then SOME ([],stack,i1,pa1,m,T) else
if w = 1w then SOME ([],stack,i1,pa1,m,T) else
case stack of
| [] => NONE
| (x::xs) =>
if (w && 1w) = 0w then
case word_gc_move_bitmap conf (w >>> 1,xs,i1,pa1,curr,m,dm) of
| NONE => NONE
| SOME (new,stack,i1,pa1,m,c) => SOME (x::new,stack,i1,pa1,m,c)
else
let (x1,i1,pa1,m1,c1) = word_gc_move conf (x,i1,pa1,curr,m,dm) in
case word_gc_move_bitmap conf (w >>> 1,xs,i1,pa1,curr,m1,dm) of
| NONE => NONE
| SOME (new,stack,i1,pa1,m,c) => SOME (x1::new,stack,i1,pa1,m,c1 /\ c)
Proof
simp [word_and_one_eq_0_iff]
\\ simp [Once word_gc_move_bitmap_def,get_bits_def]
\\ IF_CASES_TAC
\\ full_simp_tac(srw_ss())[EVAL ``bit_length 0w``,filter_bitmap_def,
map_bitmap_def,word_gc_move_roots_def]
\\ IF_CASES_TAC
\\ full_simp_tac(srw_ss())[EVAL ``bit_length 1w``,filter_bitmap_def,
map_bitmap_def,word_gc_move_roots_def]
\\ simp [bit_length_minus_1]
\\ full_simp_tac(srw_ss())[GSYM bit_length_eq_1]
\\ pop_assum (fn th => mp_tac (ONCE_REWRITE_RULE [bit_length_def] th))
\\ full_simp_tac(srw_ss())[] \\ strip_tac
\\ Cases_on `bit_length (w >>> 1)` \\ full_simp_tac(srw_ss())[]
\\ full_simp_tac(srw_ss())[GENLIST_CONS,o_DEF,ADD1,filter_bitmap_def]
\\ Cases_on `stack` \\ full_simp_tac(srw_ss())[] \\ full_simp_tac(srw_ss())[filter_bitmap_def]
\\ `get_bits (w >>> 1) = GENLIST (\x. w ' (x + 1)) n` by
(full_simp_tac(srw_ss())[get_bits_def,GENLIST_FUN_EQ] \\ srw_tac[][]
\\ `n + 1 <= dimindex (:'a)` by metis_tac [bit_length_LESS_EQ_dimindex]
\\ `x < dimindex (:'a)` by decide_tac
\\ full_simp_tac(srw_ss())[word_lsr_def,fcpTheory.FCP_BETA]
\\ eq_tac \\ full_simp_tac(srw_ss())[] \\ srw_tac[][] \\ decide_tac)
\\ IF_CASES_TAC \\ full_simp_tac(srw_ss())[filter_bitmap_def,map_bitmap_def]
THEN1
(full_simp_tac(srw_ss())[word_gc_move_bitmap_def,LET_THM]
\\ ntac 2 (CASE_TAC \\ full_simp_tac(srw_ss())[])
\\ pairarg_tac \\ full_simp_tac(srw_ss())[]
\\ rpt (CASE_TAC \\ full_simp_tac(srw_ss())[]))
\\ full_simp_tac(srw_ss())[word_gc_move_bitmap_def,LET_THM]
\\ CASE_TAC \\ full_simp_tac(srw_ss())[] THEN1 (pairarg_tac \\ full_simp_tac(srw_ss())[])
\\ CASE_TAC \\ full_simp_tac(srw_ss())[word_gc_move_roots_def,LET_THM]
\\ ntac 3 (pairarg_tac \\ full_simp_tac(srw_ss())[]) \\ rpt var_eq_tac \\ full_simp_tac(srw_ss())[]
\\ full_simp_tac(srw_ss())[map_bitmap_def]
\\ rpt (CASE_TAC \\ full_simp_tac(srw_ss())[])
QED
Theorem word_gc_move_code_thm:
word_gc_move conf (w,i,pa,old,m,dm) = (w1,i1,pa1,m1,T) /\
shift_length conf < dimindex (:'a) /\ word_shift (:'a) < dimindex (:'a) /\
2 < dimindex (:'a) /\ conf.len_size <> 0 /\
(!w:'a word. w << word_shift (:'a) = w * bytes_in_word) /\
FLOOKUP (s:('a,'c,'b)stackSem$state).store CurrHeap = SOME (Word old) /\ s.use_store /\
s.memory = m /\ s.mdomain = dm /\
0 IN FDOM s.regs /\
1 IN FDOM s.regs /\
2 IN FDOM s.regs /\
get_var 3 s = SOME (Word pa) /\
get_var 4 s = SOME (Word (i:'a word)) /\
get_var 5 s = SOME w /\
6 IN FDOM s.regs ==>
?ck r0 r1 r2 r6.
evaluate (word_gc_move_code conf,s with clock := s.clock + ck) =
(NONE,s with <| memory := m1;
regs := s.regs |++ [(0,r0);
(1,r1);
(2,r2);
(3,Word pa1);
(4,Word i1);
(5,w1);
(6,r6)] |>)
Proof
reverse (Cases_on `w`) \\ full_simp_tac(srw_ss())[word_gc_move_def] THEN1
(srw_tac[][word_gc_move_code_def,evaluate_def]
\\ full_simp_tac(srw_ss())[get_var_def] \\ tac
\\ full_simp_tac(srw_ss())[state_component_equality]
\\ full_simp_tac(srw_ss())[FUPDATE_LIST,GSYM fmap_EQ,FLOOKUP_DEF,EXTENSION,
FUN_EQ_THM,FAPPLY_FUPDATE_THM]
\\ once_rewrite_tac [split_num_forall_to_10]
\\ full_simp_tac(srw_ss())[nine_less])
\\ full_simp_tac(srw_ss())[get_var_def,word_gc_move_code_def,evaluate_def] \\ tac
\\ IF_CASES_TAC \\ full_simp_tac(srw_ss())[] THEN1
(tac \\ strip_tac \\ rpt var_eq_tac \\ full_simp_tac(srw_ss())[]
\\ qexists_tac `0` \\ full_simp_tac(srw_ss())[state_component_equality]
\\ full_simp_tac(srw_ss())[FUPDATE_LIST,GSYM fmap_EQ,FLOOKUP_DEF,EXTENSION,
FUN_EQ_THM,FAPPLY_FUPDATE_THM]
\\ once_rewrite_tac [split_num_forall_to_10]
\\ full_simp_tac(srw_ss())[nine_less])
\\ IF_CASES_TAC
THEN1
(full_simp_tac(srw_ss())[ptr_to_addr_def] \\ tac
\\ strip_tac \\ rpt var_eq_tac \\ tac
\\ full_simp_tac(srw_ss())[is_fwd_ptr_iff] \\ tac
\\ full_simp_tac(srw_ss())[clear_top_inst_def,evaluate_def] \\ tac
\\ qexists_tac `0` \\ full_simp_tac(srw_ss())[theWord_def]
\\ full_simp_tac(srw_ss())[update_addr_def,select_lower_lemma]
\\ full_simp_tac(srw_ss())[state_component_equality]
\\ full_simp_tac(srw_ss())[FUPDATE_LIST,GSYM fmap_EQ,FLOOKUP_DEF,EXTENSION,
FUN_EQ_THM,FAPPLY_FUPDATE_THM]
\\ once_rewrite_tac [split_num_forall_to_10]
\\ full_simp_tac(srw_ss())[nine_less])
\\ pairarg_tac \\ full_simp_tac(srw_ss())[ptr_to_addr_def,isWord_thm]
\\ strip_tac \\ rpt var_eq_tac \\ tac
\\ full_simp_tac(srw_ss())[is_fwd_ptr_def,theWord_def,clear_top_inst_def] \\ tac
\\ qabbrev_tac `len = decode_length conf v`
\\ full_simp_tac(srw_ss())[GSYM select_lower_lemma]
\\ qexists_tac `w2n (len + 1w)`
\\ drule memcpy_code_thm
\\ qpat_abbrev_tac `s3 = s with <| regs := _ ; clock := _ |>`
\\ disch_then (qspec_then `s3 with clock := s.clock` mp_tac)
\\ full_simp_tac(srw_ss())[]
\\ `s3 with clock := s.clock + w2n (len + 1w) = s3` by
(unabbrev_all_tac \\ full_simp_tac(srw_ss())[AC ADD_COMM ADD_ASSOC] \\ NO_TAC)
\\ full_simp_tac(srw_ss())[] \\ impl_tac THEN1
(unabbrev_all_tac \\ full_simp_tac(srw_ss())[get_var_def] \\ tac
\\ fs [decode_length_def])
\\ strip_tac \\ full_simp_tac(srw_ss())[FUPDATE_LIST]
\\ unabbrev_all_tac \\ full_simp_tac(srw_ss())[] \\ tac
\\ fs [LET_THM,decode_length_def]
\\ fs [] \\ tac \\ rpt var_eq_tac
\\ full_simp_tac(srw_ss())[] \\ tac
\\ full_simp_tac(srw_ss())[select_lower_lemma,
DECIDE ``n<>0 ==> m-(n-1)-1=m-n:num``]
\\ tac \\ full_simp_tac(srw_ss())[] \\ tac
\\ full_simp_tac(srw_ss())[update_addr_def]
\\ full_simp_tac(srw_ss())[state_component_equality]
\\ full_simp_tac(srw_ss())[FUPDATE_LIST,GSYM fmap_EQ,FLOOKUP_DEF,EXTENSION,
FUN_EQ_THM,FAPPLY_FUPDATE_THM]
\\ once_rewrite_tac [split_num_forall_to_10]
\\ full_simp_tac(srw_ss())[nine_less]
\\ `shift_length conf <> 0` by (EVAL_TAC \\ decide_tac)
\\ full_simp_tac(srw_ss())[select_lower_lemma,
DECIDE ``n<>0 ==> m-(n-1)-1=m-n:num``]
QED
Theorem word_gc_move_list_code_thm:
!l a (s:('a,'c,'b)stackSem$state) pa1 pa old m1 m i1 i dm conf a1.
word_gc_move_list conf (a:'a word,l,i,pa,old,m,dm) = (a1,i1,pa1,m1,T) /\
shift_length conf < dimindex (:'a) /\ word_shift (:'a) < dimindex (:'a) /\
2 < dimindex (:'a) /\ conf.len_size <> 0 /\
(!w:'a word. w << word_shift (:'a) = w * bytes_in_word) /\
FLOOKUP s.store CurrHeap = SOME (Word old) /\ s.use_store /\
s.memory = m /\ s.mdomain = dm /\
0 IN FDOM s.regs /\
1 IN FDOM s.regs /\
2 IN FDOM s.regs /\
get_var 3 s = SOME (Word pa) /\
get_var 4 s = SOME (Word (i:'a word)) /\
5 IN FDOM s.regs ==>
6 IN FDOM s.regs ==>
get_var 7 s = SOME (Word l) /\
get_var 8 s = SOME (Word a) ==>
?ck r0 r1 r2 r5 r6.
evaluate (word_gc_move_list_code conf,s with clock := s.clock + ck) =
(NONE,s with <| memory := m1;
regs := s.regs |++ [(0,r0);
(1,r1);
(2,r2);
(3,Word pa1);
(4,Word i1);
(5,r5);
(6,r6);
(7,Word 0w);
(8,Word a1)] |>)
Proof
Cases \\ Induct_on `n` \\ simp [] THEN1
(fs [Once word_gc_move_list_def] \\ rw []
\\ qexists_tac `0`
\\ fs [word_gc_move_list_code_def,get_var_def] \\ tac
\\ full_simp_tac(srw_ss())[state_component_equality]
\\ full_simp_tac(srw_ss())[FUPDATE_LIST,GSYM fmap_EQ,FLOOKUP_DEF,EXTENSION,
FUN_EQ_THM,FAPPLY_FUPDATE_THM]
\\ once_rewrite_tac [split_num_forall_to_10]
\\ full_simp_tac(srw_ss())[nine_less])
\\ once_rewrite_tac [word_gc_move_list_def] \\ simp [LET_THM]
\\ rpt strip_tac \\ simp [LET_THM]
\\ qpat_x_assum `_ = (a1,i1,pa1,m1,T)` mp_tac
\\ `n2w (SUC n) + -1w = n2w n` by fs [ADD1,GSYM word_add_n2w]