diff options
author | Jin Kyu Song <jin.kyu.song@intel.com> | 2013-08-20 23:50:26 -0700 |
---|---|---|
committer | Cyrill Gorcunov <gorcunov@gmail.com> | 2013-08-28 14:27:17 +0400 |
commit | f9442f67d5ab30bb6ab5b713d87e50797a982e80 (patch) | |
tree | a9bf3aa85739f3b5df456ee52e4f03f237edd333 /test/gas2nasm.py | |
parent | 66c61926b1fa8d22773bb43014d75d54ef43bf38 (diff) | |
download | nasm-f9442f67d5ab30bb6ab5b713d87e50797a982e80.tar.gz |
AVX-512: Add a test case for EVEX encoded instructions
This was converted from a gas testsuite.
(gas/testsuite/gas/i386/x86-64-avx512f-intel.d)
A python script that is used for converting is also included.
Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Diffstat (limited to 'test/gas2nasm.py')
-rwxr-xr-x | test/gas2nasm.py | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/test/gas2nasm.py b/test/gas2nasm.py new file mode 100755 index 00000000..de167456 --- /dev/null +++ b/test/gas2nasm.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python -tt +# -*- python -*- +# Convert gas testsuite file to NASM test asm file +# usage > +# python gas2nasm.py -i input_gas_file -o output_nasm_file -b bits +# e.g. python gas2nasm.py -i x86-64-avx512f-intel.d -o avx512f.asm -b 64 + +import sys +import os +import optparse +import re + +def setup(): + parser = optparse.OptionParser() + parser.add_option('-i', dest='input', action='store', + default="", + help='Name for input gas testsuite file.') + parser.add_option('-o', dest='output', action='store', + default="", + help='Name for output NASM test asm file.') + parser.add_option('-b', dest='bits', action='store', + default="", + help='Bits for output ASM file.') + (options, args) = parser.parse_args() + return options + +def read(options): + with open(options.input, 'rb') as f: + recs = [] + for line in f: + if line[0] == '[': + d = [] + strr = line[16:].partition(' ') + if strr[1] == '': + strr = line[16:].partition('\t') + l = strr[0].strip() + r = strr[2].strip() + # Filter out Pseudo-op / vex instructions until those are added in insns.dat + if not (re.match('vcmp.+[ps][ds]', r) or re.match('vpcmp[^u]+u?[dq]', r) or r[0] == 'k'): + d.append(l) + d.append(r) + recs.append(d) + return recs + +def commas(recs): + replace_tbl = {' PTR':'', '\\':'', 'MM':'', '{':'\{', '}':'\}', 'XWORD':'OWORD'} + reccommas = [] + for insn in recs: + new = [] + byte = '0x' + insn[0].replace(' ', ', 0x') + for rep in replace_tbl.keys(): + insn[1] = insn[1].replace(rep, replace_tbl[rep]) + mnemonic = insn[1] + + # gas size specifier for gather and scatter insturctions seems wrong. just remove them. + if 'gather' in insn[1] or 'scatter' in insn[1]: + mnemonic = mnemonic.replace('ZWORD', '') + + new.append(byte) + new.append(mnemonic) + reccommas.append(new) + return reccommas + +# The spaces reserved here can be adjusted according to the output string length. +# maxlen printed out at the end of the process will give a hint for it. +outstrfmt = "testcase\t{ %-70s }, { %-60s }\n" + +macro = "%macro testcase 2\n %ifdef BIN\n db %1\n %endif\n %ifdef SRC\n %2\n %endif\n%endmacro\n\n\n" + +def write(data, options): + if options.output: + with open(options.output, 'wb') as out: + out.write(macro) + if options.bits: + out.write('bits ' + options.bits + '\n\n') + for insn in data: + outstr = outstrfmt % tuple(insn) + out.write(outstr) + +if __name__ == "__main__": + options = setup() + recs = read(options) + print "AVX3.1 instructions" + + recs = commas(recs) + + write(recs, options) + + maxlen = [0,0,0,0,0,0,0,0] + for insn in recs: +#print insn[0] + '\t<-\t' + insn[1] + print outstrfmt[:-1] % tuple(insn) + for i, strstr in enumerate(insn): + if maxlen[i] < len(strstr): maxlen[i] = len(strstr) + + print maxlen |