File: final.lisp

package info (click to toggle)
acl2 8.6%2Bdfsg-2
  • links: PTS
  • area: main
  • in suites: trixie
  • size: 1,111,420 kB
  • sloc: lisp: 17,818,294; java: 125,359; python: 28,122; javascript: 23,458; cpp: 18,851; ansic: 11,569; perl: 7,678; xml: 5,591; sh: 3,976; makefile: 3,833; ruby: 2,633; yacc: 1,126; ml: 763; awk: 295; csh: 233; lex: 197; php: 178; tcl: 49; asm: 23; haskell: 17
file content (896 lines) | stat: -rw-r--r-- 32,710 bytes parent folder | download | duplicates (3)
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
;; Cuong Chau <cuong.chau@arm.com>

;; January 2022

(in-package "RTL")

(include-book "round")

(local (arith-5-for-rtl))

;; ======================================================================

(local
 (defundd rz ()
   (if (and (equal (fzp) 1)
            (not (equal (f) (hp)))
            (or (denormp (opaw) (f))
                (denormp (opbw) (f))))
       (set-flag (idc) (rin))
     (rin))))

(local
 (encapsulate
   ()

   (local
    (defthm decode-opz-rewrite
      (implies (not (specialp))
               (and (equal (decode (opaz) (f)) (a))
	            (equal (decode (opbz) (f)) (b))))
      :hints (("Goal" :in-theory (enable specialp
                                         opaz
                                         opbz
                                         a
                                         b
                                         a-class
                                         b-class)))))

   (local
    (defthm arm-binary-spec-to-arm-binary-comp
      (implies (not (specialp))
               (equal (arm-binary-spec 'div (opaw) (opbw) (rin) (f))
                      (arm-binary-comp 'div (opaz) (opbz) (rz) (f))))
      :hints (("Goal" :in-theory (enable specialp
                                         opaz
                                         opbz
                                         rz
                                         fzp
                                         a-class
                                         b-class
                                         binary-undefined-p)))))

   (defthmd arm-binary-spec-to-arm-post-comp
     (implies (not (specialp))
              (equal (arm-binary-spec 'div (opaw) (opbw) (rin) (f))
                     (arm-post-comp (/ (a) (b)) (rz) (f))))
     :hints (("Goal"
              :in-theory (e/d (specialp
                               a-class
                               b-class
                               binary-eval)
                              (arm-binary-spec
                               arm-post-comp)))))
   ))

(local
 (defthmd data-non-special
   (implies (not (specialp))
            (equal (data)
                   (mv-nth 0 (final (qrnd)
                                    (inx)
                                    (sign)
                                    (expq)
                                    (rmode)
                                    (fzp)
                                    (fnum)
                                    (flags-b)))))
   :hints (("Goal" :in-theory (enable specialp data result)))))

(local
 (defthmd flags-non-special
   (implies (not (specialp))
            (equal (flags)
                   (mv-nth 1 (final (qrnd)
                                    (inx)
                                    (sign)
                                    (expq)
                                    (rmode)
                                    (fzp)
                                    (fnum)
                                    (flags-b)))))
   :hints (("Goal" :in-theory (enable specialp flags result)))))

(defthmd signa-a-rel
  (implies (not (specialp))
           (equal (signa)
                  (if (< (a) 0) 1 0)))
  :hints (("Goal"
           :use nonzero-a
           :in-theory (enable spec-fields a decode ndecode ddecode))))

(defthmd signb-b-rel
  (implies (not (specialp))
           (equal (signb)
                  (if (< (b) 0) 1 0)))
  :hints (("Goal"
           :use nonzero-b
           :in-theory (enable spec-fields b decode ndecode ddecode))))

(defthmd sign-a/b-rel
  (implies (not (specialp))
           (equal (sign)
                  (if (< (/ (a) (b)) 0)
                      1
                    0)))
  :hints (("Goal" :in-theory (enable sign signa-a-rel signb-b-rel))))

;; Overflow

(local
 (defthm fpscr-rc-to-rmode
   (equal (fpscr-rc (rin))
          (mode (rmode)))
   :hints (("Goal" :in-theory (enable fpscr-rc mode rmode)))))

(local
 (defthmd si13-expq-not-ovf
   (implies (and (<= 1 (si (expq) 13))
                 (not (specialp)))
            (equal (<= (rnd (abs (/ (a) (b)))
                            (rmode-prime (mode (rmode)) (sign))
                            (prec (f)))
                       (lpn (f)))
                   (<= (si (expq) 13)
                       (- (expt 2 (expw (f))) 2))))
   :hints (("Goal"
            :use (expo-rnd-abs-a/b
                  (:instance expo-monotone
                             (x (rnd (abs (/ (a) (b)))
                                     (rmode-prime (mode (rmode)) (sign))
                                     (prec (f))))
                             (y (lpn (f))))
                  (:instance expo-monotone
                             (x (lpn (f)))
                             (y (rnd (abs (/ (a) (b)))
                                     (rmode-prime (mode (rmode)) (sign))
                                     (prec (f)))))
                  (:instance exactp2
                             (x (rnd (abs (/ (a) (b)))
                                     (rmode-prime (mode (rmode)) (sign))
                                     (prec (f))))
                             (n (prec (f))))
                  (:instance expo-upper-bound
                             (x (rnd (abs (/ (a) (b)))
                                     (rmode-prime (mode (rmode)) (sign))
                                     (prec (f)))))
                  (:instance int+1<=
                             (x (* (rnd (abs (/ (a) (b)))
                                        (rmode-prime (mode (rmode)) (sign))
                                        (prec (f)))
                                   (expt 2 (- (1- (prec (f)))
                                              (expo
                                               (rnd (abs (/ (a) (b)))
                                                    (rmode-prime
                                                     (mode (rmode)) (sign))
                                                    (prec (f))))))))
                             (y (expt 2 (prec (f))))))
            :in-theory (enable f lpn)))))

(local
 (defthmd data-when-ovf
   (implies (and (not (specialp))
                 (< (lpn (f))
                    (rnd (abs (/ (a) (b)))
                         (rmode-prime (mode (rmode)) (sign))
                         (prec (f)))))
	    (equal (data)
	           (mv-nth 0 (arm-post-comp (/ (a) (b)) (rz) (f)))))
   :hints (("Goal"
            :use (si13-expq-not-ovf
                  rnd-abs-a/b-denormal-upper-bound)
            :in-theory (e/d (data-non-special
                             rz
                             f
                             final
                             rnd-minus
                             mode
                             sgn
                             lpn
                             nencode
                             sign-a/b-rel)
                            (acl2::default-expt-2))))))

(local
 (defthm logior-to-set-flag
   (and (equal (logior 8 (rin))
               (set-flag 3 (rin)))
        (equal (logior 16 (rin))
               (set-flag 4 (rin)))
        (equal (logior 20 (rin))
               (set-flag 2 (set-flag 4 (rin))))
        (equal (logior 24 (rin))
               (set-flag 4 (set-flag 3 (rin))))
        (equal (logior 128 (rin))
               (set-flag 7 (rin)))
        (equal (logior 136 (rin))
               (set-flag 3 (set-flag 7 (rin))))
        (equal (logior 144 (rin))
               (set-flag 4 (set-flag 7 (rin))))
        (equal (logior 148 (rin))
               (set-flag 2 (set-flag 4 (set-flag 7 (rin))))))
   :hints (("Goal" :in-theory (enable set-flag)))))

(local
 (defthmd flags-when-ovf
   (implies (and (not (specialp))
                 (< (lpn (f))
                    (rnd (abs (/ (a) (b)))
                         (rmode-prime (mode (rmode)) (sign))
                         (prec (f)))))
	    (equal (logior (rin) (flags))
	           (mv-nth 1 (arm-post-comp (/ (a) (b)) (rz) (f)))))
   :hints (("Goal"
            :use (si13-expq-not-ovf
                  rnd-abs-a/b-denormal-upper-bound)
            :in-theory (e/d (flags-non-special
                             rz
                             fzp
                             f
                             final
                             rnd-minus
                             mode
                             lpn
                             flags-b-rewrite
                             sign-a/b-rel)
                            (acl2::default-expt-2
                             acl2::default-logior-2))))))

;; Flush-to-zero

(local
 (defthmd fdivlane-correct-when-fz
   (implies (and (not (specialp))
                 (<= (rnd (abs (/ (a) (b)))
                          (rmode-prime (mode (rmode)) (sign))
                          (prec (f)))
                     (lpn (f)))
		 (< (abs (/ (a) (b))) (spn (f)))
		 (equal (fzp) 1))
	    (mv-let (data-spec r-spec) (arm-post-comp (/ (a) (b)) (rz) (f))
	      (and (equal (data) data-spec)
                   (equal (logior (rin) (flags)) r-spec))))
   :hints (("Goal"
            :use si13-expq-denormal
            :in-theory (enable data-non-special
                               flags-non-special
                               rz
                               fzp
                               f
                               final
                               rnd-minus
                               rmode-prime
                               flip-mode
                               flags-b-rewrite
                               bitn-logior
                               sign-a/b-rel)))))

;; Denormal round to zero

(local
 (defthmd data-when-drnd-=-0
   (implies (and (not (specialp))
                 (<= (rnd (abs (/ (a) (b)))
                          (rmode-prime (mode (rmode)) (sign))
                          (prec (f)))
                     (lpn (f)))
		 (< (abs (/ (a) (b))) (spn (f)))
		 (equal (fzp) 0)
		 (equal (drnd (/ (a) (b))
                              (mode (rmode))
                              (f))
                        0))
	    (equal (data)
	           (mv-nth 0 (arm-post-comp (/ (a) (b)) (rz) (f)))))
   :hints (("Goal"
            :use (si13-expq-denormal
                  drnd-abs-a/b-to-qrnd)
            :in-theory (enable data-non-special
                               rz
                               f
                               final
                               rnd-minus
                               drnd-minus
                               rmode-prime
                               flip-mode
                               sign-a/b-rel)))))

(local
 (defthmd flags-when-drnd-=-0
   (implies (and (not (specialp))
                 (<= (rnd (abs (/ (a) (b)))
                          (rmode-prime (mode (rmode)) (sign))
                          (prec (f)))
                     (lpn (f)))
		 (< (abs (/ (a) (b))) (spn (f)))
		 (equal (fzp) 0)
		 (equal (drnd (/ (a) (b))
                              (mode (rmode))
                              (f))
                        0))
	    (equal (logior (rin) (flags))
	           (mv-nth 1 (arm-post-comp (/ (a) (b)) (rz) (f)))))
   :hints (("Goal"
            :use (si13-expq-denormal
                  inx-exact-a/b-denormal-rel)
            :in-theory (enable flags-non-special
                               rz
                               fzp
                               final
                               rnd-minus
                               drnd-minus
                               rmode-prime
                               flip-mode
                               flags-b-rewrite
                               sign-a/b-rel)))))

;; Denormal round to SPN

(local
 (defthmd data-when-abs-drnd-=-spn
   (implies (and (not (specialp))
                 (<= (rnd (abs (/ (a) (b)))
                          (rmode-prime (mode (rmode)) (sign))
                          (prec (f)))
                     (lpn (f)))
		 (< (abs (/ (a) (b))) (spn (f)))
		 (equal (fzp) 0)
		 (equal (abs (drnd (/ (a) (b))
                                   (mode (rmode))
                                   (f)))
                        (spn (f))))
	    (equal (data)
	           (mv-nth 0 (arm-post-comp (/ (a) (b)) (rz) (f)))))
   :hints (("Goal"
            :use (si13-expq-denormal
                  drnd-abs-a/b-to-qrnd)
            :in-theory (e/d (data-non-special
                             rz
                             fzp
                             f
                             final
                             rnd-minus
                             drnd-minus
                             rmode-prime
                             flip-mode
                             spn
                             nencode
                             sign-a/b-rel)
                            (acl2::|(<= x (/ y)) with (< y 0)|
                             acl2::|(< (/ x) y) with (< x 0)|
                             acl2::not-integerp-1b
                             acl2::not-integerp-2b
                             acl2::not-integerp-3b
                             acl2::not-integerp-4b))))))

(local
 (defthmd flags-when-abs-drnd-=-spn
   (implies (and (not (specialp))
                 (<= (rnd (abs (/ (a) (b)))
                          (rmode-prime (mode (rmode)) (sign))
                          (prec (f)))
                     (lpn (f)))
		 (< (abs (/ (a) (b))) (spn (f)))
		 (equal (fzp) 0)
		 (equal (abs (drnd (/ (a) (b))
                                   (mode (rmode))
                                   (f)))
                        (spn (f))))
	    (equal (logior (rin) (flags))
	           (mv-nth 1 (arm-post-comp (/ (a) (b)) (rz) (f)))))
   :hints (("Goal"
            :use (si13-expq-denormal
                  inx-exact-a/b-denormal-rel)
            :in-theory (enable flags-non-special
                               rz
                               fzp
                               final
                               rnd-minus
                               drnd-minus
                               rmode-prime
                               flip-mode
                               flags-b-rewrite
                               sign-a/b-rel)))))

;; Denormal case

(local
 (defthm common-mode-p-rmode
   (common-mode-p (mode (rmode)))
   :hints (("Goal" :in-theory (enable mode)))))

(local
 (defthm sgnf-data
   (implies (not (specialp))
            (equal (sgnf (data) (f))
                   (sign)))
   :hints (("Goal" :in-theory (enable sgnf data-non-special f final bvecp)))))

(local
 (defthmd drnd-<=-spn
   (implies (<= (abs (/ (a) (b))) (spn (f)))
            (<= (abs (drnd (/ (a) (b))
                           (mode (rmode))
                           (f)))
                (spn (f))))
   :hints (("Goal"
            :use ((:instance rnd-monotone
                             (x (+ (/ (a) (b))
                                   (* (sgn (/ (a) (b)))
                                      (spn (f)))))
                             (y (+ (spn (f))
                                   (* (sgn (/ (a) (b)))
                                      (spn (f)))))
                             (mode (mode (rmode)))
                             (n (prec (f))))
                  (:instance rnd-monotone
                             (x (+ (- (spn (f)))
                                   (* (sgn (/ (a) (b)))
                                      (spn (f)))))
                             (y (+ (/ (a) (b))
                                   (* (sgn (/ (a) (b)))
                                      (spn (f)))))
                             (mode (mode (rmode)))
                             (n (prec (f)))))
            :in-theory (enable drnd-rewrite spn f mode sgn)))
   :rule-classes :linear))

(local
 (defthm expf-data-denormal
   (implies (and (not (specialp))
		 (< (abs (/ (a) (b))) (spn (f)))
                 (not (equal (abs (drnd (/ (a) (b))
                                        (mode (rmode))
                                        (f)))
                             (spn (f)))))
            (and (equal (expf (data) (f))
                        0)
                 (equal (bits (qrnd) (+ -1 (prec (f))) 0)
                        (bits (qrnd) (+ -2 (prec (f))) 0))))
   :hints (("Goal"
            :use (si13-expq-denormal
                  drnd-<=-spn
                  drnd-abs-a/b-to-qrnd
                  (:instance bitn-plus-bits
                             (x (qrnd))
                             (m 0)
                             (n (1- (prec (f))))))
            :in-theory (e/d (expf
                             data-non-special
                             f
                             final
                             drnd-minus
                             rmode-prime
                             flip-mode
                             spn
                             sign-a/b-rel)
                            (acl2::default-expt-2
                             acl2::|(<= x (/ y)) with (< y 0)|
                             acl2::|(< (/ x) y) with (< x 0)|
                             acl2::not-integerp-1b
                             acl2::not-integerp-2b
                             acl2::not-integerp-3b
                             acl2::not-integerp-4b))))))

(local
 (defthm manf-data-denormal
   (implies (and (not (specialp))
		 (< (abs (/ (a) (b))) (spn (f)))
                 (equal (fzp) 0))
            (equal (manf (data) (f))
                   (bits (qrnd) (- (prec (f)) 2) 0)))
   :hints (("Goal"
            :use si13-expq-denormal
            :in-theory (enable manf
                               data-non-special
                               f
                               final
                               sign-a/b-rel)))))

(defthm not-explicitp-f
  (not (explicitp (f)))
  :hints (("Goal" :in-theory (enable f))))

(local
 (defthmd drnd-to-ddecode-data
   (implies (and (not (specialp))
		 (< (abs (/ (a) (b))) (spn (f)))
                 (equal (fzp) 0)
                 (not (equal (abs (drnd (/ (a) (b))
                                        (mode (rmode))
                                        (f)))
                             (spn (f)))))
            (equal (drnd (/ (a) (b))
                         (mode (rmode))
                         (f))
                   (ddecode (data) (f))))
   :hints (("Goal"
            :use drnd-abs-a/b-to-qrnd
            :in-theory (enable ddecode
                               drnd-minus
                               rmode-prime
                               flip-mode
                               sign-a/b-rel)))))

(defthmd si-expq-non-neg
  (implies (<= 0 (si (expq) 13))
           (equal (si (expq) 13) (expq)))
  :hints (("Goal" :in-theory (enable si))))

(local
 (defthm encodingp-data
   (implies (not (specialp))
            (encodingp (data) (f)))
   :hints (("Goal"
            :cases ((equal (sign) 0))
            :use ((:instance bits-shift-up-1
                             (x (+ (expt 2 (expw (f)))
                                   (expq)))
                             (i 63)
                             (j (1- (prec (f))))
                             (k (1- (prec (f)))))
                  (:instance bits-shift-up-1
                             (x (+ (expt 2 (expw (f)))
                                   (bitn (qrnd) (1- (prec (f))))))
                             (i 63)
                             (j (1- (prec (f))))
                             (k (1- (prec (f)))))
                  (:instance bits-shift-up-1
                             (x (expq))
                             (i 63)
                             (j (1- (prec (f))))
                             (k (1- (prec (f)))))
                  (:instance bits-shift-up-1
                             (x (bitn (qrnd) (1- (prec (f)))))
                             (i 63)
                             (j (1- (prec (f))))
                             (k (1- (prec (f))))))
            :in-theory (enable encodingp
                               data-non-special
                               f
                               final
                               si-expq-non-neg
                               cat
                               bvecp)))))

(local
 (defthm denormp-data
   (implies (and (not (specialp))
		 (< (abs (/ (a) (b))) (spn (f)))
                 (equal (fzp) 0)
                 (not (equal (drnd (/ (a) (b))
                                   (mode (rmode))
                                   (f))
                             0))
                 (not (equal (abs (drnd (/ (a) (b))
                                        (mode (rmode))
                                        (f)))
                             (spn (f)))))
            (denormp (data) (f)))
   :hints (("Goal"
            :use drnd-abs-a/b-to-qrnd
            :in-theory (enable denormp
                               drnd-minus
                               rmode-prime
                               flip-mode
                               sign-a/b-rel)))))

(local
 (defthmd data-to-dencode-drnd
   (implies (and (not (specialp))
		 (< (abs (/ (a) (b))) (spn (f)))
                 (equal (fzp) 0)
                 (not (equal (drnd (/ (a) (b))
                                   (mode (rmode))
                                   (f))
                             0))
                 (not (equal (abs (drnd (/ (a) (b))
                                        (mode (rmode))
                                        (f)))
                             (spn (f)))))
            (equal (data)
                   (dencode (drnd (/ (a) (b))
                                  (mode (rmode))
                                  (f))
                            (f))))
   :hints (("Goal" :use drnd-to-ddecode-data))))

(local
 (defthmd data-when-denormal
   (implies (and (not (specialp))
		 (< (abs (/ (a) (b))) (spn (f)))
                 (equal (fzp) 0)
                 (not (equal (drnd (/ (a) (b))
                                   (mode (rmode))
                                   (f))
                             0))
                 (not (equal (abs (drnd (/ (a) (b))
                                        (mode (rmode))
                                        (f)))
                             (spn (f)))))
	    (equal (data)
	           (mv-nth 0 (arm-post-comp (/ (a) (b)) (rz) (f)))))
   :hints (("Goal"
            :use (si13-expq-denormal
                  rnd-abs-a/b-denormal-upper-bound)
            :in-theory (enable data-to-dencode-drnd
                               rz
                               fzp
                               f
                               rnd-minus
                               rmode-prime
                               flip-mode
                               lpn
                               sign-a/b-rel)))))

(local
 (defthmd flags-when-denormal
   (implies (and (not (specialp))
		 (< (abs (/ (a) (b))) (spn (f)))
                 (equal (fzp) 0)
                 (not (equal (drnd (/ (a) (b))
                                   (mode (rmode))
                                   (f))
                             0))
                 (not (equal (abs (drnd (/ (a) (b))
                                        (mode (rmode))
                                        (f)))
                             (spn (f)))))
	    (equal (logior (rin) (flags))
	           (mv-nth 1 (arm-post-comp (/ (a) (b)) (rz) (f)))))
   :hints (("Goal"
            :use (si13-expq-denormal
                  rnd-abs-a/b-denormal-upper-bound
                  inx-exact-a/b-denormal-rel)
            :in-theory (enable flags-non-special
                               rz
                               fzp
                               f
                               final
                               rnd-minus
                               drnd-minus
                               rmode-prime
                               flip-mode
                               flags-b-rewrite
                               lpn
                               sign-a/b-rel)))))

;; Normal case

(local
 (defthm expf-data-normal
   (implies (and (not (specialp))
                 (<= (rnd (abs (/ (a) (b)))
                          (rmode-prime (mode (rmode)) (sign))
                          (prec (f)))
                     (lpn (f)))
		 (<= (spn (f)) (abs (/ (a) (b)))))
            (equal (expf (data) (f))
                   (si (expq) 13)))
   :hints (("Goal"
            :use (si13-expq-denormal
                  si13-expq-not-ovf)
            :in-theory (enable expf
                               data-non-special
                               f
                               final
                               si-expq-non-neg
                               bvecp)))))

(local
 (defthm manf-data-normal
   (implies (and (not (specialp))
                 (<= (rnd (abs (/ (a) (b)))
                          (rmode-prime (mode (rmode)) (sign))
                          (prec (f)))
                     (lpn (f)))
		 (<= (spn (f)) (abs (/ (a) (b)))))
            (equal (manf (data) (f))
                   (bits (qrnd) (- (prec (f)) 2) 0)))
   :hints (("Goal"
            :use (si13-expq-denormal
                  si13-expq-not-ovf)
            :in-theory (enable manf
                               data-non-special
                               f
                               final
                               expo-lpn)))))

(local
 (defthmd rnd-to-ndecode-data
   (implies (and (not (specialp))
                 (<= (rnd (abs (/ (a) (b)))
                          (rmode-prime (mode (rmode)) (sign))
                          (prec (f)))
                     (lpn (f)))
		 (<= (spn (f)) (abs (/ (a) (b)))))
            (equal (rnd (/ (a) (b))
                        (mode (rmode))
                        (prec (f)))
                   (ndecode (data) (f))))
   :hints (("Goal"
            :use (rnd-abs-a/b-to-qrnd
                  si13-expq-denormal)
            :in-theory (enable ndecode
                               rnd-minus
                               rmode-prime
                               flip-mode
                               sign-a/b-rel)))))

(local
 (defthm normp-data
   (implies (and (not (specialp))
                 (<= (rnd (abs (/ (a) (b)))
                          (rmode-prime (mode (rmode)) (sign))
                          (prec (f)))
                     (lpn (f)))
		 (<= (spn (f)) (abs (/ (a) (b)))))
            (normp (data) (f)))
   :hints (("Goal"
            :use (si13-expq-denormal
                  si13-expq-not-ovf)
            :in-theory (enable normp)))))

(local
 (defthmd data-to-nencode-rnd
   (implies (and (not (specialp))
                 (<= (rnd (abs (/ (a) (b)))
                          (rmode-prime (mode (rmode)) (sign))
                          (prec (f)))
                     (lpn (f)))
		 (<= (spn (f)) (abs (/ (a) (b)))))
            (equal (data)
                   (nencode (rnd (/ (a) (b))
                                 (mode (rmode))
                                 (prec (f)))
                            (f))))
   :hints (("Goal" :use rnd-to-ndecode-data))))

(local
 (defthmd data-when-normal
   (implies (and (not (specialp))
                 (<= (rnd (abs (/ (a) (b)))
                          (rmode-prime (mode (rmode)) (sign))
                          (prec (f)))
                     (lpn (f)))
		 (<= (spn (f)) (abs (/ (a) (b)))))
	    (equal (data)
	           (mv-nth 0 (arm-post-comp (/ (a) (b)) (rz) (f)))))
   :hints (("Goal"
            :in-theory (enable data-to-nencode-rnd
                               rz
                               f
                               rnd-minus
                               rmode-prime
                               flip-mode
                               sign-a/b-rel)))))

(local
 (defthmd flags-when-normal
   (implies (and (not (specialp))
                 (<= (rnd (abs (/ (a) (b)))
                          (rmode-prime (mode (rmode)) (sign))
                          (prec (f)))
                     (lpn (f)))
		 (<= (spn (f)) (abs (/ (a) (b)))))
	    (equal (logior (rin) (flags))
	           (mv-nth 1 (arm-post-comp (/ (a) (b)) (rz) (f)))))
   :hints (("Goal"
            :use (si13-expq-denormal
                  si13-expq-not-ovf
                  inx-exact-a/b-rel)
            :in-theory (e/d (flags-non-special
                             rz
                             f
                             final
                             rnd-minus
                             rmode-prime
                             flip-mode
                             flags-b-rewrite
                             sign-a/b-rel)
                            (acl2::default-logior-2
                             acl2::not-integerp-1b
                             acl2::not-integerp-2b
                             acl2::not-integerp-3b
                             acl2::not-integerp-4b))))))

;; Combine all cases

(local
 (defthmd data-non-special-correct
   (implies (not (specialp))
	    (equal (data)
	           (mv-nth 0 (arm-binary-spec 'div (opaw) (opbw) (rin) (f)))))
   :hints (("Goal"
            :use (data-when-ovf
                  fdivlane-correct-when-fz
                  data-when-drnd-=-0
                  data-when-abs-drnd-=-spn
                  data-when-denormal
                  data-when-normal)
            :in-theory (e/d (arm-binary-spec-to-arm-post-comp)
                            (arm-binary-spec arm-post-comp abs))))))

(local
 (defthmd flags-non-special-correct
   (implies (not (specialp))
	    (equal (logior (rin) (flags))
	           (mv-nth 1 (arm-binary-spec 'div (opaw) (opbw) (rin) (f)))))
   :hints (("Goal"
            :use (flags-when-ovf
                  fdivlane-correct-when-fz
                  flags-when-drnd-=-0
                  flags-when-abs-drnd-=-spn
                  flags-when-denormal
                  flags-when-normal)
            :in-theory (e/d (arm-binary-spec-to-arm-post-comp)
                            (arm-binary-spec arm-post-comp abs))))))

(defthmd fdivlane-main
  (mv-let
    (data-spec r-spec)
    (arm-binary-spec 'div (opaw) (opbw) (rin) (f))
    (and (equal (data) data-spec)
         (equal (logior (rin) (flags)) r-spec)))
  :hints (("Goal"
           :use (fdivlane-special-correct
                 data-non-special-correct
                 flags-non-special-correct)
           :in-theory (disable arm-binary-spec))))

(local
 (defthmd fdivlane-main-inst
   (let* ((f (case (fnum) (1 (hp)) (2 (sp)) (3 (dp))))
          (fmtw (+ 1 (expw f) (sigw f)))
          (fzp (bitn (rin) 24))
          (dnp (bitn (rin) 25))
          (rmode (bits (rin) 23 22)))
     (mv-let (data flags) (fdivlane (opa) (opb) (fnum) (vec) fzp dnp rmode)
       (mv-let
         (data-spec r-spec)
         (arm-binary-spec 'div
                          (bits (opa) (1- fmtw) 0)
                          (bits (opb) (1- fmtw) 0)
                          (rin)
                          f)
         (and (equal data data-spec)
              (equal (logior (rin) flags) r-spec)))))
   :hints (("Goal"
            :use fdivlane-main
            :in-theory (e/d (fdivlane-lemma
                             data flags
                             opaw opbw fmtw
                             f
                             fzp dnp rmode)
                            (arm-binary-spec))))))

(local
 (defmacro ic ()
   '(input-constraints opa opb fnum vec rin)))

(defthmd fdivlane-correct
  (implies (input-constraints opa opb fnum vec rin)
           (let* ((f (case fnum (1 (hp)) (2 (sp)) (3 (dp))))
                  (fmtw (+ 1 (expw f) (sigw f)))
                  (fzp (bitn rin 24))
                  (dnp (bitn rin 25))
                  (rmode (bits rin 23 22)))
             (mv-let (data flags) (fdivlane opa opb fnum vec fzp dnp rmode)
               (mv-let
                 (data-spec r-spec)
                 (arm-binary-spec 'div
                                  (bits opa (1- fmtw) 0)
                                  (bits opb (1- fmtw) 0)
                                  rin
                                  f)
                 (and (equal data data-spec)
                      (equal (logior rin flags) r-spec))))))
  :hints (("Goal"
           :use (:functional-instance
                 fdivlane-main-inst
                 (opa (lambda () (if (ic) opa (opa))))
                 (opb (lambda () (if (ic) opb (opb))))
                 (fnum (lambda () (if (ic) fnum (fnum))))
                 (vec (lambda () (if (ic) vec (vec))))
                 (rin (lambda () (if (ic) rin (rin)))))
	   :in-theory (disable arm-binary-spec))))