add_and_subtract.py (5119:a4469f2919f3) add_and_subtract.py (6081:e5da3985fa99)
1# Copyright (c) 2007 The Hewlett-Packard Development Company
2# All rights reserved.
3#
4# Redistribution and use of this software in source and binary forms,
5# with or without modification, are permitted provided that the
6# following conditions are met:
7#
8# The software must be used only for Non-Commercial Use which means any
9# use which is NOT directed to receiving any direct monetary
10# compensation for, or commercial advantage from such use. Illustrative
11# examples of non-commercial use are academic research, personal study,
12# teaching, education and corporate research & development.
13# Illustrative examples of commercial use are distributing products for
14# commercial advantage and providing services using the software for
15# commercial advantage.
16#
17# If you wish to use this software or functionality therein that may be
18# covered by patents for commercial use, please contact:
19# Director of Intellectual Property Licensing
20# Office of Strategy and Technology
21# Hewlett-Packard Company
22# 1501 Page Mill Road
23# Palo Alto, California 94304
24#
25# Redistributions of source code must retain the above copyright notice,
26# this list of conditions and the following disclaimer. Redistributions
27# in binary form must reproduce the above copyright notice, this list of
28# conditions and the following disclaimer in the documentation and/or
29# other materials provided with the distribution. Neither the name of
30# the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
31# contributors may be used to endorse or promote products derived from
32# this software without specific prior written permission. No right of
33# sublicense is granted herewith. Derivatives of the software and
34# output created using the software may be prepared, but only for
35# Non-Commercial Uses. Derivatives of the software may be shared with
36# others provided: (i) the others agree to abide by the list of
37# conditions herein which includes the Non-Commercial Use restrictions;
38# and (ii) such Derivatives of the software include the above copyright
39# notice to acknowledge the contribution from this software where
40# applicable, this list of conditions and the disclaimer below.
41#
42# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53#
54# Authors: Gabe Black
55
56microcode = '''
57def macroop ADD_R_R
58{
59 add reg, reg, regm, flags=(OF,SF,ZF,AF,PF,CF)
60};
61
62def macroop ADD_R_I
63{
64 limm t1, imm
65 add reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
66};
67
68def macroop ADD_M_I
69{
70 limm t2, imm
71 ldst t1, seg, sib, disp
72 add t1, t1, t2, flags=(OF,SF,ZF,AF,PF,CF)
73 st t1, seg, sib, disp
74};
75
76def macroop ADD_P_I
77{
78 rdip t7
79 limm t2, imm
80 ldst t1, seg, riprel, disp
81 add t1, t1, t2, flags=(OF,SF,ZF,AF,PF,CF)
82 st t1, seg, riprel, disp
83};
84
1# Copyright (c) 2007 The Hewlett-Packard Development Company
2# All rights reserved.
3#
4# Redistribution and use of this software in source and binary forms,
5# with or without modification, are permitted provided that the
6# following conditions are met:
7#
8# The software must be used only for Non-Commercial Use which means any
9# use which is NOT directed to receiving any direct monetary
10# compensation for, or commercial advantage from such use. Illustrative
11# examples of non-commercial use are academic research, personal study,
12# teaching, education and corporate research & development.
13# Illustrative examples of commercial use are distributing products for
14# commercial advantage and providing services using the software for
15# commercial advantage.
16#
17# If you wish to use this software or functionality therein that may be
18# covered by patents for commercial use, please contact:
19# Director of Intellectual Property Licensing
20# Office of Strategy and Technology
21# Hewlett-Packard Company
22# 1501 Page Mill Road
23# Palo Alto, California 94304
24#
25# Redistributions of source code must retain the above copyright notice,
26# this list of conditions and the following disclaimer. Redistributions
27# in binary form must reproduce the above copyright notice, this list of
28# conditions and the following disclaimer in the documentation and/or
29# other materials provided with the distribution. Neither the name of
30# the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
31# contributors may be used to endorse or promote products derived from
32# this software without specific prior written permission. No right of
33# sublicense is granted herewith. Derivatives of the software and
34# output created using the software may be prepared, but only for
35# Non-Commercial Uses. Derivatives of the software may be shared with
36# others provided: (i) the others agree to abide by the list of
37# conditions herein which includes the Non-Commercial Use restrictions;
38# and (ii) such Derivatives of the software include the above copyright
39# notice to acknowledge the contribution from this software where
40# applicable, this list of conditions and the disclaimer below.
41#
42# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53#
54# Authors: Gabe Black
55
56microcode = '''
57def macroop ADD_R_R
58{
59 add reg, reg, regm, flags=(OF,SF,ZF,AF,PF,CF)
60};
61
62def macroop ADD_R_I
63{
64 limm t1, imm
65 add reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
66};
67
68def macroop ADD_M_I
69{
70 limm t2, imm
71 ldst t1, seg, sib, disp
72 add t1, t1, t2, flags=(OF,SF,ZF,AF,PF,CF)
73 st t1, seg, sib, disp
74};
75
76def macroop ADD_P_I
77{
78 rdip t7
79 limm t2, imm
80 ldst t1, seg, riprel, disp
81 add t1, t1, t2, flags=(OF,SF,ZF,AF,PF,CF)
82 st t1, seg, riprel, disp
83};
84
85def macroop ADD_LOCKED_M_I
86{
87 limm t2, imm
88 ldstl t1, seg, sib, disp
89 add t1, t1, t2, flags=(OF,SF,ZF,AF,PF,CF)
90 stul t1, seg, sib, disp
91};
92
93def macroop ADD_LOCKED_P_I
94{
95 rdip t7
96 limm t2, imm
97 ldstl t1, seg, riprel, disp
98 add t1, t1, t2, flags=(OF,SF,ZF,AF,PF,CF)
99 stul t1, seg, riprel, disp
100};
101
85def macroop ADD_M_R
86{
87 ldst t1, seg, sib, disp
88 add t1, t1, reg, flags=(OF,SF,ZF,AF,PF,CF)
89 st t1, seg, sib, disp
90};
91
92def macroop ADD_P_R
93{
94 rdip t7
95 ldst t1, seg, riprel, disp
96 add t1, t1, reg, flags=(OF,SF,ZF,AF,PF,CF)
97 st t1, seg, riprel, disp
98};
99
102def macroop ADD_M_R
103{
104 ldst t1, seg, sib, disp
105 add t1, t1, reg, flags=(OF,SF,ZF,AF,PF,CF)
106 st t1, seg, sib, disp
107};
108
109def macroop ADD_P_R
110{
111 rdip t7
112 ldst t1, seg, riprel, disp
113 add t1, t1, reg, flags=(OF,SF,ZF,AF,PF,CF)
114 st t1, seg, riprel, disp
115};
116
117def macroop ADD_LOCKED_M_R
118{
119 ldstl t1, seg, sib, disp
120 add t1, t1, reg, flags=(OF,SF,ZF,AF,PF,CF)
121 stul t1, seg, sib, disp
122};
123
124def macroop ADD_LOCKED_P_R
125{
126 rdip t7
127 ldstl t1, seg, riprel, disp
128 add t1, t1, reg, flags=(OF,SF,ZF,AF,PF,CF)
129 stul t1, seg, riprel, disp
130};
131
100def macroop ADD_R_M
101{
102 ld t1, seg, sib, disp
103 add reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
104};
105
106def macroop ADD_R_P
107{
108 rdip t7
109 ld t1, seg, riprel, disp
110 add reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
111};
112
113def macroop SUB_R_R
114{
115 sub reg, reg, regm, flags=(OF,SF,ZF,AF,PF,CF)
116};
117
118def macroop SUB_R_I
119{
120 limm t1, imm
121 sub reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
122};
123
124def macroop SUB_R_M
125{
126 ld t1, seg, sib, disp
127 sub reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
128};
129
130def macroop SUB_R_P
131{
132 rdip t7
133 ld t1, seg, riprel, disp
134 sub reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
135};
136
137def macroop SUB_M_I
138{
139 limm t2, imm
140 ldst t1, seg, sib, disp
141 sub t1, t1, t2, flags=(OF,SF,ZF,AF,PF,CF)
142 st t1, seg, sib, disp
143};
144
145def macroop SUB_P_I
146{
147 rdip t7
148 limm t2, imm
149 ldst t1, seg, riprel, disp
150 sub t1, t1, t2, flags=(OF,SF,ZF,AF,PF,CF)
151 st t1, seg, riprel, disp
152};
153
154def macroop SUB_M_R
155{
156 ldst t1, seg, sib, disp
157 sub t1, t1, reg, flags=(OF,SF,ZF,AF,PF,CF)
158 st t1, seg, sib, disp
159};
160
161def macroop SUB_P_R
162{
163 rdip t7
164 ldst t1, seg, riprel, disp
165 sub t1, t1, reg, flags=(OF,SF,ZF,AF,PF,CF)
166 st t1, seg, riprel, disp
167};
168
169def macroop ADC_R_R
170{
171 adc reg, reg, regm, flags=(OF,SF,ZF,AF,PF,CF)
172};
173
174def macroop ADC_R_I
175{
176 limm t1, imm
177 adc reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
178};
179
180def macroop ADC_M_I
181{
182 limm t2, imm
183 ldst t1, seg, sib, disp
184 adc t1, t1, t2, flags=(OF,SF,ZF,AF,PF,CF)
185 st t1, seg, sib, disp
186};
187
188def macroop ADC_P_I
189{
190 rdip t7
191 limm t2, imm
192 ldst t1, seg, riprel, disp
193 adc t1, t1, t2, flags=(OF,SF,ZF,AF,PF,CF)
194 st t1, seg, riprel, disp
195};
196
197def macroop ADC_M_R
198{
199 ldst t1, seg, sib, disp
200 adc t1, t1, reg, flags=(OF,SF,ZF,AF,PF,CF)
201 st t1, seg, sib, disp
202};
203
204def macroop ADC_P_R
205{
206 rdip t7
207 ldst t1, seg, riprel, disp
208 adc t1, t1, reg, flags=(OF,SF,ZF,AF,PF,CF)
209 st t1, seg, riprel, disp
210};
211
212def macroop ADC_R_M
213{
214 ld t1, seg, sib, disp
215 adc reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
216};
217
218def macroop ADC_R_P
219{
220 rdip t7
221 ld t1, seg, riprel, disp
222 adc reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
223};
224
225def macroop SBB_R_R
226{
227 sbb reg, reg, regm, flags=(OF,SF,ZF,AF,PF,CF)
228};
229
230def macroop SBB_R_I
231{
232 limm t1, imm
233 sbb reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
234};
235
236def macroop SBB_R_M
237{
238 ld t1, seg, sib, disp
239 sbb reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
240};
241
242def macroop SBB_R_P
243{
244 rdip t7
245 ld t1, seg, riprel, disp
246 sbb reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
247};
248
249def macroop SBB_M_I
250{
251 limm t2, imm
252 ldst t1, seg, sib, disp
253 sbb t1, t1, t2, flags=(OF,SF,ZF,AF,PF,CF)
254 st t1, seg, sib, disp
255};
256
257def macroop SBB_P_I
258{
259 rdip t7
260 limm t2, imm
261 ldst t1, seg, riprel, disp
262 sbb t1, t1, t2, flags=(OF,SF,ZF,AF,PF,CF)
263 st t1, seg, riprel, disp
264};
265
266def macroop SBB_M_R
267{
268 ldst t1, seg, sib, disp
269 sbb t1, t1, reg, flags=(OF,SF,ZF,AF,PF,CF)
270 st t1, seg, sib, disp
271};
272
273def macroop SBB_P_R
274{
275 rdip t7
276 ldst t1, seg, riprel, disp
277 sbb t1, t1, reg, flags=(OF,SF,ZF,AF,PF,CF)
278 st t1, seg, riprel, disp
279};
280
281def macroop NEG_R
282{
283 sub reg, t0, reg, flags=(CF,OF,SF,ZF,AF,PF)
284};
285
286def macroop NEG_M
287{
288 ldst t1, seg, sib, disp
289 sub t1, t0, t1, flags=(CF,OF,SF,ZF,AF,PF)
290 st t1, seg, sib, disp
291};
292
293def macroop NEG_P
294{
295 rdip t7
296 ldst t1, seg, riprel, disp
297 sub t1, t0, t1, flags=(CF,OF,SF,ZF,AF,PF)
298 st t1, seg, riprel, disp
299};
300'''
132def macroop ADD_R_M
133{
134 ld t1, seg, sib, disp
135 add reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
136};
137
138def macroop ADD_R_P
139{
140 rdip t7
141 ld t1, seg, riprel, disp
142 add reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
143};
144
145def macroop SUB_R_R
146{
147 sub reg, reg, regm, flags=(OF,SF,ZF,AF,PF,CF)
148};
149
150def macroop SUB_R_I
151{
152 limm t1, imm
153 sub reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
154};
155
156def macroop SUB_R_M
157{
158 ld t1, seg, sib, disp
159 sub reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
160};
161
162def macroop SUB_R_P
163{
164 rdip t7
165 ld t1, seg, riprel, disp
166 sub reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
167};
168
169def macroop SUB_M_I
170{
171 limm t2, imm
172 ldst t1, seg, sib, disp
173 sub t1, t1, t2, flags=(OF,SF,ZF,AF,PF,CF)
174 st t1, seg, sib, disp
175};
176
177def macroop SUB_P_I
178{
179 rdip t7
180 limm t2, imm
181 ldst t1, seg, riprel, disp
182 sub t1, t1, t2, flags=(OF,SF,ZF,AF,PF,CF)
183 st t1, seg, riprel, disp
184};
185
186def macroop SUB_M_R
187{
188 ldst t1, seg, sib, disp
189 sub t1, t1, reg, flags=(OF,SF,ZF,AF,PF,CF)
190 st t1, seg, sib, disp
191};
192
193def macroop SUB_P_R
194{
195 rdip t7
196 ldst t1, seg, riprel, disp
197 sub t1, t1, reg, flags=(OF,SF,ZF,AF,PF,CF)
198 st t1, seg, riprel, disp
199};
200
201def macroop ADC_R_R
202{
203 adc reg, reg, regm, flags=(OF,SF,ZF,AF,PF,CF)
204};
205
206def macroop ADC_R_I
207{
208 limm t1, imm
209 adc reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
210};
211
212def macroop ADC_M_I
213{
214 limm t2, imm
215 ldst t1, seg, sib, disp
216 adc t1, t1, t2, flags=(OF,SF,ZF,AF,PF,CF)
217 st t1, seg, sib, disp
218};
219
220def macroop ADC_P_I
221{
222 rdip t7
223 limm t2, imm
224 ldst t1, seg, riprel, disp
225 adc t1, t1, t2, flags=(OF,SF,ZF,AF,PF,CF)
226 st t1, seg, riprel, disp
227};
228
229def macroop ADC_M_R
230{
231 ldst t1, seg, sib, disp
232 adc t1, t1, reg, flags=(OF,SF,ZF,AF,PF,CF)
233 st t1, seg, sib, disp
234};
235
236def macroop ADC_P_R
237{
238 rdip t7
239 ldst t1, seg, riprel, disp
240 adc t1, t1, reg, flags=(OF,SF,ZF,AF,PF,CF)
241 st t1, seg, riprel, disp
242};
243
244def macroop ADC_R_M
245{
246 ld t1, seg, sib, disp
247 adc reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
248};
249
250def macroop ADC_R_P
251{
252 rdip t7
253 ld t1, seg, riprel, disp
254 adc reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
255};
256
257def macroop SBB_R_R
258{
259 sbb reg, reg, regm, flags=(OF,SF,ZF,AF,PF,CF)
260};
261
262def macroop SBB_R_I
263{
264 limm t1, imm
265 sbb reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
266};
267
268def macroop SBB_R_M
269{
270 ld t1, seg, sib, disp
271 sbb reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
272};
273
274def macroop SBB_R_P
275{
276 rdip t7
277 ld t1, seg, riprel, disp
278 sbb reg, reg, t1, flags=(OF,SF,ZF,AF,PF,CF)
279};
280
281def macroop SBB_M_I
282{
283 limm t2, imm
284 ldst t1, seg, sib, disp
285 sbb t1, t1, t2, flags=(OF,SF,ZF,AF,PF,CF)
286 st t1, seg, sib, disp
287};
288
289def macroop SBB_P_I
290{
291 rdip t7
292 limm t2, imm
293 ldst t1, seg, riprel, disp
294 sbb t1, t1, t2, flags=(OF,SF,ZF,AF,PF,CF)
295 st t1, seg, riprel, disp
296};
297
298def macroop SBB_M_R
299{
300 ldst t1, seg, sib, disp
301 sbb t1, t1, reg, flags=(OF,SF,ZF,AF,PF,CF)
302 st t1, seg, sib, disp
303};
304
305def macroop SBB_P_R
306{
307 rdip t7
308 ldst t1, seg, riprel, disp
309 sbb t1, t1, reg, flags=(OF,SF,ZF,AF,PF,CF)
310 st t1, seg, riprel, disp
311};
312
313def macroop NEG_R
314{
315 sub reg, t0, reg, flags=(CF,OF,SF,ZF,AF,PF)
316};
317
318def macroop NEG_M
319{
320 ldst t1, seg, sib, disp
321 sub t1, t0, t1, flags=(CF,OF,SF,ZF,AF,PF)
322 st t1, seg, sib, disp
323};
324
325def macroop NEG_P
326{
327 rdip t7
328 ldst t1, seg, riprel, disp
329 sub t1, t0, t1, flags=(CF,OF,SF,ZF,AF,PF)
330 st t1, seg, riprel, disp
331};
332'''