-
Notifications
You must be signed in to change notification settings - Fork 1
/
peephole.smt2
189 lines (140 loc) · 4.57 KB
/
peephole.smt2
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
(define-sort ocaml-int () (_ BitVec 5))
(define-const ocaml-true ocaml-int #b00001)
(define-const ocaml-false ocaml-int #b00000)
;(define-fun ocaml-if ((cond ocaml-int) (ifso ocaml-int) (ifnot ocaml-int))
; (
(declare-datatypes () ((CMP EQ NE LT GT LE GE)))
(declare-datatypes () ((LOGI AND OR XOR)))
(define-fun ocaml-lsl ((x ocaml-int) (y ocaml-int)) ocaml-int
(bvshl x y))
(define-fun ocaml-lsr ((x ocaml-int) (y ocaml-int)) ocaml-int
(bvlshr x y))
(define-fun ocaml-or ((x ocaml-int) (y ocaml-int)) ocaml-int
(bvor x y))
(define-fun ocaml-and ((x ocaml-int) (y ocaml-int)) ocaml-int
(bvand x y))
(define-fun ocaml-xor ((x ocaml-int) (y ocaml-int)) ocaml-int
(bvxor x y))
(define-fun ocaml-has-tag ((x ocaml-int)) bool
(= (ocaml-and x #b00001) #b00001))
(define-fun ocaml-highest-bits-same ((x ocaml-int)) bool
(= ((_ extract 4 4) x) ((_ extract 3 3) x)))
(define-fun ocaml-asr-1 ((x ocaml-int)) ocaml-int
(concat
((_ extract 4 4) x)
((_ extract 3 0) (ocaml-lsr x #b00001))
))
(define-fun ocaml-lsr-1 ((x ocaml-int)) ocaml-int
(ocaml-lsr x #b00001))
(define-fun ocaml-addi ((x ocaml-int) (y ocaml-int)) ocaml-int
(bvadd x y))
(define-fun ocaml-subi ((x ocaml-int) (y ocaml-int)) ocaml-int
(bvsub x y))
(define-fun ocaml-tagi ((x ocaml-int)) ocaml-int
(bvadd (ocaml-lsl x #b00001) #b00001))
(define-fun ocaml-untagi ((x ocaml-int)) ocaml-int
(ocaml-asr-1 x))
(define-fun ocaml-to-int-untagged ((x ocaml-int)) Int
(+ (if (= ((_ extract 4 4) x) #b1) -16 0)
(bv2int ((_ extract 3 0) x))))
(define-fun ocaml-cmp-eq ((x ocaml-int) (y ocaml-int)) ocaml-int
(if (= x y) #b00001 #b00000))
(define-fun ocaml-cmp-ne ((x ocaml-int) (y ocaml-int)) ocaml-int
(if (not (= x y)) #b00001 #b00000))
(define-fun ocaml-cmp-lt ((x ocaml-int) (y ocaml-int)) ocaml-int
(if (< (ocaml-to-int-untagged x) (ocaml-to-int-untagged y))
#b00001 #b00000))
(define-fun ocaml-cmp-gt ((x ocaml-int) (y ocaml-int)) ocaml-int
(if (> (ocaml-to-int-untagged x) (ocaml-to-int-untagged y))
#b00001 #b00000))
(define-fun ocaml-cmp-le ((x ocaml-int) (y ocaml-int)) ocaml-int
(if (<= (ocaml-to-int-untagged x) (ocaml-to-int-untagged y))
#b00001 #b00000))
(define-fun ocaml-cmp-ge ((x ocaml-int) (y ocaml-int)) ocaml-int
(if (>= (ocaml-to-int-untagged x) (ocaml-to-int-untagged y))
#b00001 #b00000))
(define-fun ocaml-cmp ((cmp CMP) (x ocaml-int) (y ocaml-int)) ocaml-int
(match cmp
(case EQ (ocaml-cmp-eq x y))
(case NE (ocaml-cmp-ne x y))
(case LT (ocaml-cmp-lt x y))
(case GT (ocaml-cmp-gt x y))
(case LE (ocaml-cmp-le x y))
(case GE (ocaml-cmp-ge x y))
))
(define-fun ocaml-logi ((logi LOGI) (x ocaml-int) (y ocaml-int)) ocaml-int
(match logi
(case AND (ocaml-and x y))
(case OR (ocaml-or x y))
(case XOR (ocaml-xor x y))
))
;| Cop(Ccmpi cmpop
; , [ Cop(Caddi,[Cop(Clsl,[left;Cconst_int(1,_)],_);Cconst_int(1,_)],_)
; ; Cconst_int (right_i,right_dbg)
; ]
; , dbg_cmp
; ) ->
; Cop (Ccmpi cmpop, [ left; Cconst_int (right_i asr 1, right_dbg)], dbg_cmp)
(declare-const left ocaml-int)
(declare-const right ocaml-int)
(declare-const cmpop CMP)
(push 1)
(assert (not (=
(ocaml-cmp-eq (ocaml-tagi left) right)
(ocaml-cmp-eq left (ocaml-asr-1 right))
)))
(assert (ocaml-has-tag right))
(assert (ocaml-highest-bits-same left))
(check-sat)
(get-model)
(pop 1)
;-----------------------------------------
(push 1)
(assert (not (=
(ocaml-cmp cmpop (ocaml-tagi left) right)
(ocaml-cmp cmpop (ocaml-lsl left #b00001) (ocaml-subi right #b00001))
)))
(assert (ocaml-has-tag right))
(check-sat)
(get-model)
(pop 1)
;-----------------------------------------
(push 1)
(declare-const logi-op LOGI)
(assert-not (= logi-op XOR))
(assert-not (=
(ocaml-logi logi-op (ocaml-tagi left) (ocaml-tagi right))
(ocaml-tagi (ocaml-logi logi-op left right))
))
(check-sat)
(get-model)
(pop 1)
;-----------------------------------------
(push 1)
(assert-not (=
(ocaml-or (ocaml-xor (ocaml-tagi left) #b11111) #b00001)
;(ocaml-xor (ocaml-tagi x) #b11110)
(ocaml-tagi (ocaml-xor left #b11111))
))
(check-sat)
(get-model)
(pop 1)
;-----------------------------------------
(push 1)
(assert-not (=
(ocaml-or (ocaml-xor (ocaml-tagi left) right) #b00001)
(ocaml-tagi (ocaml-xor left (ocaml-asr-1 right)))
))
(check-sat)
(get-model)
(pop 1)
;-----------------------------------------
(push 1)
(assert-not (=
(ocaml-or (ocaml-xor (ocaml-tagi left) (ocaml-tagi right)) #b00001)
(ocaml-tagi (ocaml-xor left right))
))
(check-sat)
(get-model)
(pop 1)
;-----------------------------------------