Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(754)

Unified Diff: pydir/gen_test_arith_ll.py

Issue 2013863002: Subzero: Crosstest test_arith properly tests i8/i16. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Use a python script to auto-generate .ll tests Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « crosstest/test_arith_ll.ll ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pydir/gen_test_arith_ll.py
diff --git a/pydir/gen_test_arith_ll.py b/pydir/gen_test_arith_ll.py
new file mode 100644
index 0000000000000000000000000000000000000000..05ed9a57f5af4fea6ddb8a36da3aa0e080bf2206
--- /dev/null
+++ b/pydir/gen_test_arith_ll.py
@@ -0,0 +1,56 @@
+def mangle(op, op_type, signed):
+ # suffixMap gives the C++ name-mangling suffixes for a function that takes two
+ # arguments of the given type. The first entry is for the unsigned version of
+ # the type, and the second entry is for the signed version.
+ suffixMap = { 'i1': ['bb', 'bb'],
+ 'i8': ['hh', 'aa'],
+ 'i16': ['tt', 'ss'],
+ 'i32': ['jj', 'ii'],
+ 'i64': ['yy', 'xx'],
+ 'float': ['ff', 'ff'],
+ 'double': ['dd', 'dd'],
+ '<4 x i32>': ['Dv4_jS_', 'Dv4_iS_'],
+ '<8 x i16>': ['Dv8_tS_', 'Dv8_sS_'],
+ '<16 x i8>': ['Dv16_hS_', 'Dv16_aS_'],
+ '<4 x float>': ['Dv4_fS_', 'Dv4_fS_'],
+ }
+ base = 'test' + op.capitalize()
+ return '_Z' + str(len(base)) + base + suffixMap[op_type][signed]
+
+def arith(Native, Type, Op):
+ _TEMPLATE_ = """
+define internal {{native}} @{{name}}({{native}} %a, {{native}} %b) {{{{
+ {trunc_a}
+ {trunc_b}
+ %result{{trunc}} = {{op}} {{type}} %a{{trunc}}, %b{{trunc}}
+ {zext}
+ ret {{native}} %result
+}}}}"""
+
+ Signed = Op in {'sdiv', 'srem', 'ashr'}
+ Name = mangle(Op, Type, Signed)
+ # Most i1 operations are invalid for PNaCl, so map them to i32.
+ if Type == 'i1' and (Op not in {'and', 'or', 'xor'}):
+ Type = 'i32'
+ x = _TEMPLATE_.format(
+ trunc_a = '%a.trunc = trunc {native} %a to {type}' if
+ Native != Type else '',
+ trunc_b = '%b.trunc = trunc {native} %b to {type}' if
+ Native != Type else '',
+ zext = '%result = ' + ('sext' if Signed else 'zext') +
+ ' {type} %result.trunc to {native}' if Native != Type else '')
+ lines = x.format(native=Native, type=Type, op=Op, name=Name,
+ trunc='.trunc' if Native != Type else '')
+ # Strip trailing whitespace from each line to keep git happy.
+ print '\n'.join([line.rstrip() for line in lines.splitlines()])
+
+for op in ['add', 'sub', 'mul', 'sdiv', 'udiv', 'srem', 'urem', 'shl', 'lshr',
+ 'ashr', 'and', 'or', 'xor']:
+ for op_type in ['i1', 'i8', 'i16', 'i32']:
+ arith('i32', op_type, op)
+ for op_type in ['i64', '<4 x i32>', '<8 x i16>', '<16 x i8>']:
+ arith(op_type, op_type, op)
+
+for op in ['fadd', 'fsub', 'fmul', 'fdiv', 'frem']:
+ for op_type in ['float', 'double', '<4 x float>']:
+ arith(op_type, op_type, op)
« no previous file with comments | « crosstest/test_arith_ll.ll ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698