bit_test.py revision 7690:ae58aacfab8f
1# Copyright (c) 2007-2008 The Hewlett-Packard Development Company
2# All rights reserved.
3#
4# The license below extends only to copyright in the software and shall
5# not be construed as granting a license to any other intellectual
6# property including but not limited to intellectual property relating
7# to a hardware implementation of the functionality of the software
8# licensed hereunder.  You may use the software subject to the license
9# terms below provided that you ensure that this notice is replicated
10# unmodified and in its entirety in all distributions of the software,
11# modified or unmodified, in source code or in binary form.
12#
13# Copyright (c) 2008 The Regents of The University of Michigan
14# All rights reserved.
15#
16# Redistribution and use in source and binary forms, with or without
17# modification, are permitted provided that the following conditions are
18# met: redistributions of source code must retain the above copyright
19# notice, this list of conditions and the following disclaimer;
20# redistributions in binary form must reproduce the above copyright
21# notice, this list of conditions and the following disclaimer in the
22# documentation and/or other materials provided with the distribution;
23# neither the name of the copyright holders nor the names of its
24# contributors may be used to endorse or promote products derived from
25# this software without specific prior written permission.
26#
27# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38#
39# Authors: Gabe Black
40
41microcode = '''
42def macroop BT_R_I {
43    sexti t0, reg, imm, flags=(CF,)
44};
45
46def macroop BT_M_I {
47    limm t1, imm, dataSize=asz
48    # This fudges just a tiny bit, but it's reasonable to expect the
49    # microcode generation logic to have the log of the various sizes
50    # floating around as well.
51    ld t1, seg, sib, disp
52    sexti t0, t1, imm, flags=(CF,)
53};
54
55def macroop BT_P_I {
56    rdip t7
57    limm t1, imm, dataSize=asz
58    ld t1, seg, riprel, disp, dataSize=asz
59    sexti t0, t1, imm, flags=(CF,)
60};
61
62def macroop BT_R_R {
63    sext t0, reg, regm, flags=(CF,)
64};
65
66def macroop BT_M_R {
67    srai t2, reg, 3, dataSize=asz
68    srai t3, t2, ldsz, dataSize=asz
69    lea t3, flatseg, [dsz, t3, base], dataSize=asz
70    ld t1, seg, [scale, index, t3], disp
71    sext t0, t1, reg, flags=(CF,)
72};
73
74def macroop BT_P_R {
75    rdip t7
76    srai t2, reg, 3, dataSize=asz
77    srai t3, t2, ldsz, dataSize=asz
78    ld t1, seg, [dsz, t3, t7], disp
79    sext t0, t1, reg, flags=(CF,)
80};
81
82def macroop BTC_R_I {
83    sexti t0, reg, imm, flags=(CF,)
84    limm t1, 1
85    roli t1, t1, imm
86    xor reg, reg, t1
87};
88
89def macroop BTC_M_I {
90    limm t1, imm, dataSize=asz
91    # This fudges just a tiny bit, but it's reasonable to expect the
92    # microcode generation logic to have the log of the various sizes
93    # floating around as well.
94    limm t4, 1
95    roli t4, t4, imm
96    ldst t1, seg, sib, disp
97    sexti t0, t1, imm, flags=(CF,)
98    xor t1, t1, t4
99    st t1, seg, sib, disp
100};
101
102def macroop BTC_P_I {
103    rdip t7, dataSize=asz
104    limm t1, imm, dataSize=asz
105    limm t4, 1
106    roli t4, t4, imm
107    ldst t1, seg, riprel, disp
108    sexti t0, t1, imm, flags=(CF,)
109    xor t1, t1, t4
110    st t1, seg, riprel, disp
111};
112
113def macroop BTC_LOCKED_M_I {
114    limm t1, imm, dataSize=asz
115    limm t4, 1
116    roli t4, t4, imm
117    ldstl t1, seg, sib, disp
118    sexti t0, t1, imm, flags=(CF,)
119    xor t1, t1, t4
120    stul t1, seg, sib, disp
121};
122
123def macroop BTC_LOCKED_P_I {
124    rdip t7, dataSize=asz
125    limm t1, imm, dataSize=asz
126    limm t4, 1
127    roli t4, t4, imm
128    ldstl t1, seg, riprel, disp
129    sexti t0, t1, imm, flags=(CF,)
130    xor t1, t1, t4
131    stul t1, seg, riprel, disp
132};
133
134def macroop BTC_R_R {
135    sext t0, reg, regm, flags=(CF,)
136    limm t1, 1
137    rol t1, t1, regm
138    xor reg, reg, t1
139};
140
141def macroop BTC_M_R {
142    srai t2, reg, 3, dataSize=asz
143    srai t3, t2, ldsz, dataSize=asz
144    lea t3, flatseg, [dsz, t3, base], dataSize=asz
145    limm t4, 1
146    rol t4, t4, reg
147    ldst t1, seg, [scale, index, t3], disp
148    sext t0, t1, reg, flags=(CF,)
149    xor t1, t1, t4
150    st t1, seg, [scale, index, t3], disp
151};
152
153def macroop BTC_P_R {
154    rdip t7, dataSize=asz
155    srai t2, reg, 3, dataSize=asz
156    srai t3, t2, ldsz, dataSize=asz
157    limm t4, 1
158    rol t4, t4, reg
159    ldst t1, seg, [dsz, t3, t7], disp
160    sext t0, t1, reg, flags=(CF,)
161    xor t1, t1, t4
162    st t1, seg, [dsz, t3, t7], disp
163};
164
165def macroop BTC_LOCKED_M_R {
166    srai t2, reg, 3, dataSize=asz
167    srai t3, t2, ldsz, dataSize=asz
168    lea t3, flatseg, [dsz, t3, base], dataSize=asz
169    limm t4, 1
170    rol t4, t4, reg
171    ldstl t1, seg, [scale, index, t3], disp
172    sext t0, t1, reg, flags=(CF,)
173    xor t1, t1, t4
174    stul t1, seg, [scale, index, t3], disp
175};
176
177def macroop BTC_LOCKED_P_R {
178    rdip t7, dataSize=asz
179    srai t2, reg, 3, dataSize=asz
180    srai t3, t2, ldsz, dataSize=asz
181    limm t4, 1
182    rol t4, t4, reg
183    ldstl t1, seg, [dsz, t3, t7], disp
184    sext t0, t1, reg, flags=(CF,)
185    xor t1, t1, t4
186    stul t1, seg, [dsz, t3, t7], disp
187};
188
189def macroop BTR_R_I {
190    sexti t0, reg, imm, flags=(CF,)
191    limm t1, "(uint64_t(-(2ULL)))"
192    roli t1, t1, imm
193    and reg, reg, t1
194};
195
196def macroop BTR_M_I {
197    limm t1, imm, dataSize=asz
198    limm t4, "(uint64_t(-(2ULL)))"
199    roli t4, t4, imm
200    ldst t1, seg, sib, disp
201    sexti t0, t1, imm, flags=(CF,)
202    and t1, t1, t4
203    st t1, seg, sib, disp
204};
205
206def macroop BTR_P_I {
207    rdip t7, dataSize=asz
208    limm t1, imm, dataSize=asz
209    limm t4, "(uint64_t(-(2ULL)))"
210    roli t4, t4, imm
211    ldst t1, seg, riprel, disp
212    sexti t0, t1, imm, flags=(CF,)
213    and t1, t1, t4
214    st t1, seg, riprel, disp
215};
216
217def macroop BTR_LOCKED_M_I {
218    limm t1, imm, dataSize=asz
219    limm t4, "(uint64_t(-(2ULL)))"
220    roli t4, t4, imm
221    ldstl t1, seg, sib, disp
222    sexti t0, t1, imm, flags=(CF,)
223    and t1, t1, t4
224    stul t1, seg, sib, disp
225};
226
227def macroop BTR_LOCKED_P_I {
228    rdip t7, dataSize=asz
229    limm t1, imm, dataSize=asz
230    limm t4, "(uint64_t(-(2ULL)))"
231    roli t4, t4, imm
232    ldstl t1, seg, riprel, disp
233    sexti t0, t1, imm, flags=(CF,)
234    and t1, t1, t4
235    stul t1, seg, riprel, disp
236};
237
238def macroop BTR_R_R {
239    sext t0, reg, regm, flags=(CF,)
240    limm t1, "(uint64_t(-(2ULL)))"
241    rol t1, t1, regm
242    and reg, reg, t1
243};
244
245def macroop BTR_M_R {
246    srai t2, reg, 3, dataSize=asz
247    srai t3, t2, ldsz, dataSize=asz
248    lea t3, flatseg, [dsz, t3, base], dataSize=asz
249    limm t4, "(uint64_t(-(2ULL)))"
250    rol t4, t4, reg
251    ldst t1, seg, [scale, index, t3], disp
252    sext t0, t1, reg, flags=(CF,)
253    and t1, t1, t4
254    st t1, seg, [scale, index, t3], disp
255};
256
257def macroop BTR_P_R {
258    rdip t7, dataSize=asz
259    srai t2, reg, 3, dataSize=asz
260    srai t3, t2, ldsz, dataSize=asz
261    limm t4, "(uint64_t(-(2ULL)))"
262    rol t4, t4, reg
263    ldst t1, seg, [dsz, t3, t7], disp
264    sext t0, t1, reg, flags=(CF,)
265    and t1, t1, t4
266    st t1, seg, [dsz, t3, t7], disp
267};
268
269def macroop BTR_LOCKED_M_R {
270    srai t2, reg, 3, dataSize=asz
271    srai t3, t2, ldsz, dataSize=asz
272    lea t3, flatseg, [dsz, t3, base], dataSize=asz
273    limm t4, "(uint64_t(-(2ULL)))"
274    rol t4, t4, reg
275    ldstl t1, seg, [scale, index, t3], disp
276    sext t0, t1, reg, flags=(CF,)
277    and t1, t1, t4
278    stul t1, seg, [scale, index, t3], disp
279};
280
281def macroop BTR_LOCKED_P_R {
282    rdip t7, dataSize=asz
283    srai t2, reg, 3, dataSize=asz
284    srai t3, t2, ldsz, dataSize=asz
285    limm t4, "(uint64_t(-(2ULL)))"
286    rol t4, t4, reg
287    ldstl t1, seg, [dsz, t3, t7], disp
288    sext t0, t1, reg, flags=(CF,)
289    and t1, t1, t4
290    stul t1, seg, [dsz, t3, t7], disp
291};
292
293def macroop BTS_R_I {
294    sexti t0, reg, imm, flags=(CF,)
295    limm t1, 1
296    roli t1, t1, imm
297    or reg, reg, t1
298};
299
300def macroop BTS_M_I {
301    limm t1, imm, dataSize=asz
302    limm t4, 1
303    roli t4, t4, imm
304    ldst t1, seg, sib, disp
305    sexti t0, t1, imm, flags=(CF,)
306    or t1, t1, t4
307    st t1, seg, sib, disp
308};
309
310def macroop BTS_P_I {
311    rdip t7, dataSize=asz
312    limm t1, imm, dataSize=asz
313    limm t4, 1
314    roli t4, t4, imm
315    ldst t1, seg, riprel, disp
316    sexti t0, t1, imm, flags=(CF,)
317    or t1, t1, t4
318    st t1, seg, riprel, disp
319};
320
321def macroop BTS_LOCKED_M_I {
322    limm t1, imm, dataSize=asz
323    limm t4, 1
324    roli t4, t4, imm
325    ldstl t1, seg, sib, disp
326    sexti t0, t1, imm, flags=(CF,)
327    or t1, t1, t4
328    stul t1, seg, sib, disp
329};
330
331def macroop BTS_LOCKED_P_I {
332    rdip t7, dataSize=asz
333    limm t1, imm, dataSize=asz
334    limm t4, 1
335    roli t4, t4, imm
336    ldstl t1, seg, riprel, disp
337    sexti t0, t1, imm, flags=(CF,)
338    or t1, t1, t4
339    stul t1, seg, riprel, disp
340};
341
342def macroop BTS_R_R {
343    sext t0, reg, regm, flags=(CF,)
344    limm t1, 1
345    rol t1, t1, regm
346    or reg, reg, t1
347};
348
349def macroop BTS_M_R {
350    srai t2, reg, 3, dataSize=asz
351    srai t3, t2, ldsz, dataSize=asz
352    lea t3, flatseg, [dsz, t3, base], dataSize=asz
353    limm t4, 1
354    rol t4, t4, reg
355    ldst t1, seg, [scale, index, t3], disp
356    sext t0, t1, reg, flags=(CF,)
357    or t1, t1, t4
358    st t1, seg, [scale, index, t3], disp
359};
360
361def macroop BTS_P_R {
362    rdip t7, dataSize=asz
363    srai t2, reg, 3, dataSize=asz
364    srai t3, t2, ldsz, dataSize=asz
365    lea t3, flatseg, [dsz, t3, base], dataSize=asz
366    limm t4, 1
367    rol t4, t4, reg
368    ldst t1, seg, [1, t3, t7], disp
369    sext t0, t1, reg, flags=(CF,)
370    or t1, t1, t4
371    st t1, seg, [1, t3, t7], disp
372};
373
374def macroop BTS_LOCKED_M_R {
375    srai t2, reg, 3, dataSize=asz
376    srai t3, t2, ldsz, dataSize=asz
377    lea t3, flatseg, [dsz, t3, base], dataSize=asz
378    limm t4, 1
379    rol t4, t4, reg
380    ldstl t1, seg, [scale, index, t3], disp
381    sext t0, t1, reg, flags=(CF,)
382    or t1, t1, t4
383    stul t1, seg, [scale, index, t3], disp
384};
385
386def macroop BTS_LOCKED_P_R {
387    rdip t7, dataSize=asz
388    srai t2, reg, 3, dataSize=asz
389    srai t3, t2, ldsz, dataSize=asz
390    lea t3, flatseg, [dsz, t3, base], dataSize=asz
391    limm t4, 1
392    rol t4, t4, reg
393    ldstl t1, seg, [1, t3, t7], disp
394    sext t0, t1, reg, flags=(CF,)
395    or t1, t1, t4
396    stul t1, seg, [1, t3, t7], disp
397};
398'''
399