Commit 7dbe8022 by Jim Stichnoth

Subzero: Crosstest test_arith properly tests i8/i16.

The problem is that because of C++ integral promotion rules, many of the i8 and i16 arithmetic tests were actually being performed as i32 operations. Thus we weren't actually testing everything we meant to test. The fix is to have a python script auto-generate the relevant tests with proper typing. BUG= none R=eholk@chromium.org, jpp@chromium.org, kschimpf@google.com Review URL: https://codereview.chromium.org/2013863002 .
parent d11d921e
......@@ -527,7 +527,7 @@ check-xtest check-xtest-lite: $(OBJDIR)/pnacl-sz make_symlink runtime
@echo "Crosstests disabled, minimal build"
else
check-xtest: $(OBJDIR)/pnacl-sz make_symlink runtime \
exists-nonsfi-x8632 exists-nonsfi-arm32
exists-nonsfi-x8632 exists-nonsfi-arm32 crosstest/test_arith_ll.ll
# Do all native/sse2 tests, but only test_vector_ops for native/sse4.1.
# For (slow) sandboxed tests, limit to Om1/sse4.1.
# run.py (used to run the sandboxed xtests) does not support
......@@ -549,7 +549,7 @@ check-xtest: $(OBJDIR)/pnacl-sz make_symlink runtime \
PNACL_BIN_PATH=$(PNACL_BIN_PATH) \
$(LLVM_SRC_PATH)/utils/lit/lit.py -sv $(CHECK_XTEST_TESTS)
check-xtest-lite: $(OBJDIR)/pnacl-sz make_symlink runtime \
exists-nonsfi-x8632 exists-nonsfi-arm32
exists-nonsfi-x8632 exists-nonsfi-arm32 crosstest/test_arith_ll.ll
# Do all native/sse2/neon tests, which are relatively fast.
# Limit to test_global+mem_intrin for sandbox+nonsfi because sandbox and
# nonsfi builds are slow, and test_global and mem_intrin are the most
......@@ -570,6 +570,8 @@ check-xtest-lite: $(OBJDIR)/pnacl-sz make_symlink runtime \
-e x8664,nonsfi
PNACL_BIN_PATH=$(PNACL_BIN_PATH) \
$(LLVM_SRC_PATH)/utils/lit/lit.py -sv $(CHECK_XTEST_TESTS)
crosstest/test_arith_ll.ll: pydir/gen_test_arith_ll.py
python $< > $@
endif
check-unit: $(OBJDIR)/run_unittests
......
......@@ -9,7 +9,14 @@ flags: --sz=-fmem-intrin-opt
[test_arith]
driver: test_arith_main.cpp
test: test_arith.cpp test_arith_frem.ll test_arith_sqrt.ll test_arith_fabs.ll
# Note: Originally test_arith.cpp was used to generate the bulk of the tests.
# However, the C++ integral promotion rules mean that most of the time i8 and
# i16 operations are not actually tested; instead, they are extended to i32 and
# only the i32 operation is tested. To help fix this, the relevant parts of
# test_arith.cpp are commented out, and instead a python script auto-generates
# test_arith_ll.ll which contains the proper functionality.
#test: test_arith.cpp test_arith_frem.ll test_arith_sqrt.ll test_arith_fabs.ll
test: test_arith_ll.ll test_arith.cpp test_arith_sqrt.ll test_arith_fabs.ll
[test_bitmanip]
driver: test_bitmanip_main.cpp
......
......@@ -19,6 +19,10 @@
#include "test_arith.h"
#include "xdefs.h"
#if 0
// The following is commented out, and instead, a python script auto-generates a
// .ll file with the equivalent functionality.
#define X(inst, op, isdiv, isshift) \
bool test##inst(bool a, bool b) { return a op b; } \
uint8_t test##inst(uint8_t a, uint8_t b) { return a op b; } \
......@@ -50,6 +54,8 @@ SINTOP_TABLE
FPOP_TABLE
#undef X
#endif // 0
#define X(mult_by) \
bool testMultiplyBy##mult_by(bool a, bool /*unused*/) { \
return a * (mult_by); \
......
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)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment