bit_test.py revision 7087:fb8d5786ff30
18968Snilay@cs.wisc.edu# Copyright (c) 2007-2008 The Hewlett-Packard Development Company
28968Snilay@cs.wisc.edu# All rights reserved.
38968Snilay@cs.wisc.edu#
48968Snilay@cs.wisc.edu# The license below extends only to copyright in the software and shall
58968Snilay@cs.wisc.edu# not be construed as granting a license to any other intellectual
68968Snilay@cs.wisc.edu# property including but not limited to intellectual property relating
78968Snilay@cs.wisc.edu# to a hardware implementation of the functionality of the software
88968Snilay@cs.wisc.edu# licensed hereunder.  You may use the software subject to the license
98968Snilay@cs.wisc.edu# terms below provided that you ensure that this notice is replicated
108968Snilay@cs.wisc.edu# unmodified and in its entirety in all distributions of the software,
118968Snilay@cs.wisc.edu# modified or unmodified, in source code or in binary form.
128968Snilay@cs.wisc.edu#
138968Snilay@cs.wisc.edu# Copyright (c) 2008 The Regents of The University of Michigan
148968Snilay@cs.wisc.edu# All rights reserved.
158968Snilay@cs.wisc.edu#
168968Snilay@cs.wisc.edu# Redistribution and use in source and binary forms, with or without
178968Snilay@cs.wisc.edu# modification, are permitted provided that the following conditions are
188968Snilay@cs.wisc.edu# met: redistributions of source code must retain the above copyright
198968Snilay@cs.wisc.edu# notice, this list of conditions and the following disclaimer;
208968Snilay@cs.wisc.edu# redistributions in binary form must reproduce the above copyright
218968Snilay@cs.wisc.edu# notice, this list of conditions and the following disclaimer in the
228968Snilay@cs.wisc.edu# documentation and/or other materials provided with the distribution;
238968Snilay@cs.wisc.edu# neither the name of the copyright holders nor the names of its
248968Snilay@cs.wisc.edu# contributors may be used to endorse or promote products derived from
258968Snilay@cs.wisc.edu# this software without specific prior written permission.
268968Snilay@cs.wisc.edu#
278968Snilay@cs.wisc.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
288968Snilay@cs.wisc.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
298968Snilay@cs.wisc.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
308968Snilay@cs.wisc.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
318968Snilay@cs.wisc.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
328968Snilay@cs.wisc.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
338968Snilay@cs.wisc.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
348968Snilay@cs.wisc.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
358968Snilay@cs.wisc.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
369123Sandreas.hansson@arm.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
378968Snilay@cs.wisc.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
388968Snilay@cs.wisc.edu#
398968Snilay@cs.wisc.edu# Authors: Gabe Black
408968Snilay@cs.wisc.edu
418968Snilay@cs.wisc.edumicrocode = '''
428968Snilay@cs.wisc.edudef macroop BT_R_I {
438968Snilay@cs.wisc.edu    sexti t0, reg, imm, flags=(CF,)
448968Snilay@cs.wisc.edu};
458968Snilay@cs.wisc.edu
468968Snilay@cs.wisc.edudef macroop BT_M_I {
478968Snilay@cs.wisc.edu    limm t1, imm, dataSize=asz
488968Snilay@cs.wisc.edu    # This fudges just a tiny bit, but it's reasonable to expect the
498968Snilay@cs.wisc.edu    # microcode generation logic to have the log of the various sizes
508968Snilay@cs.wisc.edu    # floating around as well.
518968Snilay@cs.wisc.edu    ld t1, seg, sib, disp
528968Snilay@cs.wisc.edu    sexti t0, t1, imm, flags=(CF,)
538968Snilay@cs.wisc.edu};
548968Snilay@cs.wisc.edu
558968Snilay@cs.wisc.edudef macroop BT_P_I {
568968Snilay@cs.wisc.edu    rdip t7
578968Snilay@cs.wisc.edu    limm t1, imm, dataSize=asz
589826Sandreas.hansson@arm.com    ld t1, seg, riprel, disp, dataSize=asz
599802Snilay@cs.wisc.edu    sexti t0, t1, imm, flags=(CF,)
609827Sakash.bagdia@arm.com};
619827Sakash.bagdia@arm.com
629793Sakash.bagdia@arm.comdef macroop BT_R_R {
638968Snilay@cs.wisc.edu    sext t0, reg, regm, flags=(CF,)
649827Sakash.bagdia@arm.com};
659827Sakash.bagdia@arm.com
669827Sakash.bagdia@arm.comdef macroop BT_M_R {
679827Sakash.bagdia@arm.com    srai t2, reg, 3, dataSize=asz
689802Snilay@cs.wisc.edu    srai t3, t2, ldsz, dataSize=asz
699802Snilay@cs.wisc.edu    lea t3, flatseg, [dsz, t3, base], dataSize=asz
709793Sakash.bagdia@arm.com    ld t1, seg, [scale, index, t3], disp
7110519Snilay@cs.wisc.edu    sext t0, t1, reg, flags=(CF,)
728968Snilay@cs.wisc.edu};
739793Sakash.bagdia@arm.com
749827Sakash.bagdia@arm.comdef macroop BT_P_R {
759827Sakash.bagdia@arm.com    rdip t7
769793Sakash.bagdia@arm.com    srai t2, reg, 3, dataSize=asz
7710519Snilay@cs.wisc.edu    srai t3, t2, ldsz, dataSize=asz
7810519Snilay@cs.wisc.edu    lea t3, flatseg, [ldsz, t3, base], dataSize=asz
7910519Snilay@cs.wisc.edu    ld t1, seg, [1, t3, t7], disp
8010519Snilay@cs.wisc.edu    sext t0, t1, reg, flags=(CF,)
818968Snilay@cs.wisc.edu};
828968Snilay@cs.wisc.edu
838968Snilay@cs.wisc.edudef macroop BTC_R_I {
848968Snilay@cs.wisc.edu    sexti t0, reg, imm, flags=(CF,)
8510120Snilay@cs.wisc.edu    limm t1, 1
8610120Snilay@cs.wisc.edu    roli t1, t1, imm
8710120Snilay@cs.wisc.edu    xor reg, reg, t1
8810120Snilay@cs.wisc.edu};
8910519Snilay@cs.wisc.edu
9010120Snilay@cs.wisc.edudef macroop BTC_M_I {
9110120Snilay@cs.wisc.edu    limm t1, imm, dataSize=asz
9210120Snilay@cs.wisc.edu    # This fudges just a tiny bit, but it's reasonable to expect the
938968Snilay@cs.wisc.edu    # microcode generation logic to have the log of the various sizes
9410519Snilay@cs.wisc.edu    # floating around as well.
959826Sandreas.hansson@arm.com    limm t4, 1
969826Sandreas.hansson@arm.com    roli t4, t4, imm
978968Snilay@cs.wisc.edu    ldst t1, seg, sib, disp
988968Snilay@cs.wisc.edu    sexti t0, t1, imm, flags=(CF,)
99    xor t1, t1, t4
100    st t1, seg, sib, disp
101};
102
103def macroop BTC_P_I {
104    rdip t7, dataSize=asz
105    limm t1, imm, dataSize=asz
106    limm t4, 1
107    roli t4, t4, imm
108    ldst t1, seg, riprel, disp
109    sexti t0, t1, imm, flags=(CF,)
110    xor t1, t1, t4
111    st t1, seg, riprel, disp
112};
113
114def macroop BTC_LOCKED_M_I {
115    limm t1, imm, dataSize=asz
116    limm t4, 1
117    roli t4, t4, imm
118    ldstl t1, seg, sib, disp
119    sexti t0, t1, imm, flags=(CF,)
120    xor t1, t1, t4
121    stul t1, seg, sib, disp
122};
123
124def macroop BTC_LOCKED_P_I {
125    rdip t7, dataSize=asz
126    limm t1, imm, dataSize=asz
127    limm t4, 1
128    roli t4, t4, imm
129    ldstl t1, seg, riprel, disp
130    sexti t0, t1, imm, flags=(CF,)
131    xor t1, t1, t4
132    stul t1, seg, riprel, disp
133};
134
135def macroop BTC_R_R {
136    sext t0, reg, regm, flags=(CF,)
137    limm t1, 1
138    rol t1, t1, regm
139    xor reg, reg, t1
140};
141
142def macroop BTC_M_R {
143    srai t2, reg, 3, dataSize=asz
144    srai t3, t2, ldsz, dataSize=asz
145    lea t3, flatseg, [dsz, t3, base], dataSize=asz
146    limm t4, 1
147    rol t4, t4, reg
148    ldst t1, seg, [scale, index, t3], disp
149    sext t0, t1, reg, flags=(CF,)
150    xor t1, t1, t4
151    st t1, seg, [scale, index, t3], disp
152};
153
154def macroop BTC_P_R {
155    rdip t7, dataSize=asz
156    srai t2, reg, 3, dataSize=asz
157    srai t3, t2, ldsz, dataSize=asz
158    lea t3, flatseg, [dsz, t3, base], dataSize=asz
159    limm t4, 1
160    rol t4, t4, reg
161    ldst t1, seg, [1, t2, t7], disp
162    sext t0, t1, reg, flags=(CF,)
163    xor t1, t1, t4
164    st t1, seg, [1, t2, t7], disp
165};
166
167def macroop BTC_LOCKED_M_R {
168    srai t2, reg, 3, dataSize=asz
169    srai t3, t2, ldsz, dataSize=asz
170    lea t3, flatseg, [dsz, t3, base], dataSize=asz
171    limm t4, 1
172    rol t4, t4, reg
173    ldstl t1, seg, [scale, index, t3], disp
174    sext t0, t1, reg, flags=(CF,)
175    xor t1, t1, t4
176    stul t1, seg, [scale, index, t3], disp
177};
178
179def macroop BTC_LOCKED_P_R {
180    rdip t7, dataSize=asz
181    srai t2, reg, 3, dataSize=asz
182    srai t3, t2, ldsz, dataSize=asz
183    lea t3, flatseg, [dsz, t3, base], dataSize=asz
184    limm t4, 1
185    rol t4, t4, reg
186    ldstl t1, seg, [1, t2, t7], disp
187    sext t0, t1, reg, flags=(CF,)
188    xor t1, t1, t4
189    stul t1, seg, [1, t2, t7], disp
190};
191
192def macroop BTR_R_I {
193    sexti t0, reg, imm, flags=(CF,)
194    limm t1, "(uint64_t(-(2ULL)))"
195    roli t1, t1, imm
196    and reg, reg, t1
197};
198
199def macroop BTR_M_I {
200    limm t1, imm, dataSize=asz
201    limm t4, "(uint64_t(-(2ULL)))"
202    roli t4, t4, imm
203    ldst t1, seg, sib, disp
204    sexti t0, t1, imm, flags=(CF,)
205    and t1, t1, t4
206    st t1, seg, sib, disp
207};
208
209def macroop BTR_P_I {
210    rdip t7, dataSize=asz
211    limm t1, imm, dataSize=asz
212    limm t4, "(uint64_t(-(2ULL)))"
213    roli t4, t4, imm
214    ldst t1, seg, riprel, disp
215    sexti t0, t1, imm, flags=(CF,)
216    and t1, t1, t4
217    st t1, seg, riprel, disp
218};
219
220def macroop BTR_LOCKED_M_I {
221    limm t1, imm, dataSize=asz
222    limm t4, "(uint64_t(-(2ULL)))"
223    roli t4, t4, imm
224    ldstl t1, seg, sib, disp
225    sexti t0, t1, imm, flags=(CF,)
226    and t1, t1, t4
227    stul t1, seg, sib, disp
228};
229
230def macroop BTR_LOCKED_P_I {
231    rdip t7, dataSize=asz
232    limm t1, imm, dataSize=asz
233    limm t4, "(uint64_t(-(2ULL)))"
234    roli t4, t4, imm
235    ldstl t1, seg, riprel, disp
236    sexti t0, t1, imm, flags=(CF,)
237    and t1, t1, t4
238    stul t1, seg, riprel, disp
239};
240
241def macroop BTR_R_R {
242    sext t0, reg, regm, flags=(CF,)
243    limm t1, "(uint64_t(-(2ULL)))"
244    rol t1, t1, regm
245    and reg, reg, t1
246};
247
248def macroop BTR_M_R {
249    srai t2, reg, 3, dataSize=asz
250    srai t3, t2, ldsz, dataSize=asz
251    lea t3, flatseg, [dsz, t3, base], dataSize=asz
252    limm t4, "(uint64_t(-(2ULL)))"
253    rol t4, t4, reg
254    ldst t1, seg, [scale, index, t3], disp
255    sext t0, t1, reg, flags=(CF,)
256    and t1, t1, t4
257    st t1, seg, [scale, index, t3], disp
258};
259
260def macroop BTR_P_R {
261    rdip t7, dataSize=asz
262    srai t2, reg, 3, dataSize=asz
263    srai t3, t2, ldsz, dataSize=asz
264    lea t3, flatseg, [dsz, t3, base], dataSize=asz
265    limm t4, "(uint64_t(-(2ULL)))"
266    rol t4, t4, reg
267    ldst t1, seg, [1, t3, t7], disp
268    sext t0, t1, reg, flags=(CF,)
269    and t1, t1, t4
270    st t1, seg, [1, t3, t7], disp
271};
272
273def macroop BTR_LOCKED_M_R {
274    srai t2, reg, 3, dataSize=asz
275    srai t3, t2, ldsz, dataSize=asz
276    lea t3, flatseg, [dsz, t3, base], dataSize=asz
277    limm t4, "(uint64_t(-(2ULL)))"
278    rol t4, t4, reg
279    ldstl t1, seg, [scale, index, t3], disp
280    sext t0, t1, reg, flags=(CF,)
281    and t1, t1, t4
282    stul t1, seg, [scale, index, t3], disp
283};
284
285def macroop BTR_LOCKED_P_R {
286    rdip t7, dataSize=asz
287    srai t2, reg, 3, dataSize=asz
288    srai t3, t2, ldsz, dataSize=asz
289    lea t3, flatseg, [dsz, t3, base], dataSize=asz
290    limm t4, "(uint64_t(-(2ULL)))"
291    rol t4, t4, reg
292    ldstl t1, seg, [1, t3, t7], disp
293    sext t0, t1, reg, flags=(CF,)
294    and t1, t1, t4
295    stul t1, seg, [1, t3, t7], disp
296};
297
298def macroop BTS_R_I {
299    sexti t0, reg, imm, flags=(CF,)
300    limm t1, 1
301    roli t1, t1, imm
302    or reg, reg, t1
303};
304
305def macroop BTS_M_I {
306    limm t1, imm, dataSize=asz
307    limm t4, 1
308    roli t4, t4, imm
309    ldst t1, seg, sib, disp
310    sexti t0, t1, imm, flags=(CF,)
311    or t1, t1, t4
312    st t1, seg, sib, disp
313};
314
315def macroop BTS_P_I {
316    rdip t7, dataSize=asz
317    limm t1, imm, dataSize=asz
318    limm t4, 1
319    roli t4, t4, imm
320    ldst t1, seg, riprel, disp
321    sexti t0, t1, imm, flags=(CF,)
322    or t1, t1, t4
323    st t1, seg, riprel, disp
324};
325
326def macroop BTS_LOCKED_M_I {
327    limm t1, imm, dataSize=asz
328    limm t4, 1
329    roli t4, t4, imm
330    ldstl t1, seg, sib, disp
331    sexti t0, t1, imm, flags=(CF,)
332    or t1, t1, t4
333    stul t1, seg, sib, disp
334};
335
336def macroop BTS_LOCKED_P_I {
337    rdip t7, dataSize=asz
338    limm t1, imm, dataSize=asz
339    limm t4, 1
340    roli t4, t4, imm
341    ldstl t1, seg, riprel, disp
342    sexti t0, t1, imm, flags=(CF,)
343    or t1, t1, t4
344    stul t1, seg, riprel, disp
345};
346
347def macroop BTS_R_R {
348    sext t0, reg, regm, flags=(CF,)
349    limm t1, 1
350    rol t1, t1, regm
351    or reg, reg, t1
352};
353
354def macroop BTS_M_R {
355    srai t2, reg, 3, dataSize=asz
356    srai t3, t2, ldsz, dataSize=asz
357    lea t3, flatseg, [dsz, t3, base], dataSize=asz
358    limm t4, 1
359    rol t4, t4, reg
360    ldst t1, seg, [scale, index, t3], disp
361    sext t0, t1, reg, flags=(CF,)
362    or t1, t1, t4
363    st t1, seg, [scale, index, t3], disp
364};
365
366def macroop BTS_P_R {
367    rdip t7, dataSize=asz
368    srai t2, reg, 3, dataSize=asz
369    srai t3, t2, ldsz, dataSize=asz
370    lea t3, flatseg, [dsz, t3, base], dataSize=asz
371    limm t4, 1
372    rol t4, t4, reg
373    ldst t1, seg, [1, t3, t7], disp
374    sext t0, t1, reg, flags=(CF,)
375    or t1, t1, t4
376    st t1, seg, [1, t3, t7], disp
377};
378
379def macroop BTS_LOCKED_M_R {
380    srai t2, reg, 3, dataSize=asz
381    srai t3, t2, ldsz, dataSize=asz
382    lea t3, flatseg, [dsz, t3, base], dataSize=asz
383    limm t4, 1
384    rol t4, t4, reg
385    ldstl t1, seg, [scale, index, t3], disp
386    sext t0, t1, reg, flags=(CF,)
387    or t1, t1, t4
388    stul t1, seg, [scale, index, t3], disp
389};
390
391def macroop BTS_LOCKED_P_R {
392    rdip t7, dataSize=asz
393    srai t2, reg, 3, dataSize=asz
394    srai t3, t2, ldsz, dataSize=asz
395    lea t3, flatseg, [dsz, t3, base], dataSize=asz
396    limm t4, 1
397    rol t4, t4, reg
398    ldstl t1, seg, [1, t3, t7], disp
399    sext t0, t1, reg, flags=(CF,)
400    or t1, t1, t4
401    stul t1, seg, [1, t3, t7], disp
402};
403'''
404