Commit 109fa152 by Jan Voung

Add cross test for vector itofp and fptoi casts.

Add the SZ runtime functions for unsigned conversion. Add some more cast tests before doing emitIAS for cvt. BUG=none R=stichnot@chromium.org Review URL: https://codereview.chromium.org/639543002
parent 0b9eee52
......@@ -64,6 +64,7 @@ for optlevel in ${OPTLEVELS} ; do
--target=x8632 \
--dir="${OUTDIR}" \
--test=test_cast.cpp --test=test_cast_to_u1.ll \
--test=test_cast_vectors.ll \
--driver=test_cast_main.cpp \
--output=test_cast_O${optlevel}_${attribute}
......
......@@ -64,7 +64,9 @@
0xfffe, 0xffff, 0x10000, 0x10001 }
#define FP_VALUE_ARRAY(NegInf, PosInf, NegNan, NaN) \
{ 0, 1, 0x7e, \
{ 0, 1, 1.4, \
1.5, 1.6, -1.4, \
-1.5, -1.6, 0x7e, \
0x7f, 0x80, 0x81, \
0xfe, 0xff, 0x7ffe, \
0x7fff, 0x8000, 0x8001, \
......@@ -75,7 +77,7 @@
0x8000000000000000ll, 0x8000000000000001ll, 0xfffffffffffffffell, \
0xffffffffffffffffll, NegInf, PosInf, \
Nan, NegNan, -0.0, \
FLT_MIN, FLT_MAX, DBL_MIN, \
DBL_MAX }
10.0, FLT_MIN, FLT_MAX, \
DBL_MIN, DBL_MAX }
#endif // TEST_ARITH_DEF
......@@ -12,12 +12,17 @@
//===----------------------------------------------------------------------===//
/* crosstest.py --test=test_cast.cpp --test=test_cast_to_u1.ll \
--test=test_cast_vectors.ll \
--driver=test_cast_main.cpp --prefix=Subzero_ --output=test_cast */
#include <cfloat>
#include <cstring>
#include <iostream>
#include <stdint.h>
#include "test_arith.def"
#include "vectors.h"
// Include test_cast.h twice - once normally, and once within the
// Subzero_ namespace, corresponding to the llc and Subzero translated
// object files, respectively.
......@@ -48,6 +53,25 @@ namespace Subzero_ {
} \
} while (0)
#define COMPARE_VEC(Func, FromCName, ToCName, Input, FromString, ToString) \
do { \
ToCName ResultSz, ResultLlc; \
ResultLlc = Func<FromCName, ToCName>(Input); \
ResultSz = Subzero_::Func<FromCName, ToCName>(Input); \
++TotalTests; \
if (!memcmp(&ResultLlc, &ResultSz, sizeof(ToCName))) { \
++Passes; \
} else { \
++Failures; \
std::cout << std::fixed << XSTR(Func) << "<" << FromString << ", " \
<< ToString << ">(" << vectAsString<FromCName>(Input) \
<< "): "; \
std::cout << "sz=" << vectAsString<ToCName>(ResultSz) \
<< " llc=" << vectAsString<ToCName>(ResultLlc); \
std::cout << "\n"; \
} \
} while (0)
template <typename FromType>
void testValue(FromType Val, size_t &TotalTests, size_t &Passes,
size_t &Failures, const char *FromTypeString) {
......@@ -64,6 +88,28 @@ void testValue(FromType Val, size_t &TotalTests, size_t &Passes,
COMPARE(cast, FromType, double, Val, FromTypeString);
}
template <typename FromType, typename ToType>
void testVector(size_t &TotalTests, size_t &Passes, size_t &Failures,
const char *FromTypeString, const char *ToTypeString) {
const static size_t NumElementsInType = Vectors<FromType>::NumElements;
PRNG Index;
static const float NegInf = -1.0 / 0.0;
static const float PosInf = 1.0 / 0.0;
static const float Nan = 0.0 / 0.0;
static const float NegNan = -0.0 / 0.0;
volatile float Values[] = FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan);
static const size_t NumValues = sizeof(Values) / sizeof(*Values);
const size_t MaxTestsPerFunc = 20000;
for (size_t i = 0; i < MaxTestsPerFunc; ++i) {
// Initialize the test vectors.
FromType Value;
for (size_t j = 0; j < NumElementsInType; ++j) {
Value[j] = Values[Index() % NumValues];
}
COMPARE_VEC(cast, FromType, ToType, Value, FromTypeString, ToTypeString);
}
}
int main(int argc, char **argv) {
size_t TotalTests = 0;
size_t Passes = 0;
......@@ -131,36 +177,14 @@ int main(int argc, char **argv) {
};
static const size_t NumValsSi64 = sizeof(ValsSi64) / sizeof(*ValsSi64);
volatile float ValsF32[] = {
0, 1, 1.4,
1.5, 1.6, -1.4,
-1.5, -1.6, 0x7e,
0x7f, 0x80, 0x81,
0xfe, 0xff, 0x7ffe,
0x7fff, 0x8000, 0x8001,
0xfffe, 0xffff, 0x7ffffffe,
0x7fffffff, 0x80000000, 0x80000001,
0xfffffffe, 0xffffffff, 0x100000000ll,
0x100000001ll, 0x7ffffffffffffffell, 0x7fffffffffffffffll,
0x8000000000000000ll, 0x8000000000000001ll, 0xfffffffffffffffell,
0xffffffffffffffffll
};
static const double NegInf = -1.0 / 0.0;
static const double PosInf = 1.0 / 0.0;
static const double Nan = 0.0 / 0.0;
static const double NegNan = -0.0 / 0.0;
volatile float ValsF32[] = FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan);
static const size_t NumValsF32 = sizeof(ValsF32) / sizeof(*ValsF32);
volatile double ValsF64[] = {
0, 1, 1.4,
1.5, 1.6, -1.4,
-1.5, -1.6, 0x7e,
0x7f, 0x80, 0x81,
0xfe, 0xff, 0x7ffe,
0x7fff, 0x8000, 0x8001,
0xfffe, 0xffff, 0x7ffffffe,
0x7fffffff, 0x80000000, 0x80000001,
0xfffffffe, 0xffffffff, 0x100000000ll,
0x100000001ll, 0x7ffffffffffffffell, 0x7fffffffffffffffll,
0x8000000000000000ll, 0x8000000000000001ll, 0xfffffffffffffffell,
0xffffffffffffffffll
};
volatile double ValsF64[] = FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan);
static const size_t NumValsF64 = sizeof(ValsF64) / sizeof(*ValsF64);
for (size_t i = 0; i < NumValsUi1; ++i) {
......@@ -219,6 +243,10 @@ int main(int argc, char **argv) {
COMPARE(castBits, double, uint64_t, Val, "double");
}
}
testVector<v4ui32, v4f32>(TotalTests, Passes, Failures, "v4ui32", "v4f32");
testVector<v4si32, v4f32>(TotalTests, Passes, Failures, "v4si32", "v4f32");
testVector<v4f32, v4si32>(TotalTests, Passes, Failures, "v4f32", "v4si32");
testVector<v4f32, v4ui32>(TotalTests, Passes, Failures, "v4f32", "v4ui32");
std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes
<< " Failures=" << Failures << "\n";
......
target triple = "i686-pc-linux-gnu"
define <4 x float> @_Z4castIDv4_iDv4_fET0_T_(<4 x i32> %a) {
entry:
%0 = sitofp <4 x i32> %a to <4 x float>
ret <4 x float> %0
}
define <4 x i32> @_Z4castIDv4_fDv4_iET0_T_(<4 x float> %a) {
entry:
%0 = fptosi <4 x float> %a to <4 x i32>
ret <4 x i32> %0
}
define <4 x float> @_Z4castIDv4_jDv4_fET0_T_(<4 x i32> %a) {
entry:
%0 = uitofp <4 x i32> %a to <4 x float>
ret <4 x float> %0
}
define <4 x i32> @_Z4castIDv4_fDv4_jET0_T_(<4 x float> %a) {
entry:
%0 = fptoui <4 x float> %a to <4 x i32>
ret <4 x i32> %0
}
......@@ -21,6 +21,7 @@
#include <iostream>
#include "vectors.h"
#include "test_arith.def"
#include "test_fcmp.def"
#define X(cmp) \
......@@ -39,7 +40,6 @@ size_t NumValues;
void initializeValues() {
static const double NegInf = -1.0 / 0.0;
static const double Zero = 0.0;
static const double Ten = 10.0;
static const double PosInf = 1.0 / 0.0;
static const double Nan = 0.0 / 0.0;
static const double NegNan = -0.0 / 0.0;
......@@ -50,9 +50,8 @@ void initializeValues() {
assert(NegInf < Zero);
assert(NegInf < PosInf);
assert(Zero < PosInf);
static volatile double InitValues[] = {NegInf, -Zero, Zero, DBL_MIN,
FLT_MIN, Ten, FLT_MAX, DBL_MAX,
PosInf, Nan, NegNan};
static volatile double InitValues[] =
FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan);
NumValues = sizeof(InitValues) / sizeof(*InitValues);
Values = InitValues;
}
......
......@@ -18,6 +18,7 @@
#include <cstring>
#include <iostream>
#include "test_arith.def"
#include "test_select.h"
namespace Subzero_ {
......@@ -72,21 +73,7 @@ testSelect<v4f32, v4i1>(size_t &TotalTests, size_t &Passes, size_t &Failures) {
static const float PosInf = 1.0 / 0.0;
static const float Nan = 0.0 / 0.0;
static const float NegNan = -0.0 / 0.0;
volatile float Values[] = {
0, 1, 0x7e,
0x7f, 0x80, 0x81,
0xfe, 0xff, 0x7ffe,
0x7fff, 0x8000, 0x8001,
0xfffe, 0xffff, 0x7ffffffe,
0x7fffffff, 0x80000000, 0x80000001,
0xfffffffe, 0xffffffff, 0x100000000ll,
0x100000001ll, 0x7ffffffffffffffell, 0x7fffffffffffffffll,
0x8000000000000000ll, 0x8000000000000001ll, 0xfffffffffffffffell,
0xffffffffffffffffll, NegInf, PosInf,
Nan, NegNan, -0.0,
FLT_MIN, FLT_MAX, DBL_MIN,
DBL_MAX
};
volatile float Values[] = FP_VALUE_ARRAY(NegInf, PosInf, NegNan, Nan);
static const size_t NumValues = sizeof(Values) / sizeof(*Values);
static const size_t NumElements = 4;
PRNG Index;
......
......@@ -144,6 +144,9 @@ if __name__ == '__main__':
objs.append((
'{root}/toolchain_build/src/subzero/runtime/szrt.{ext}'
).format(root=nacl_root, ext='c' if pure_c else 'cpp'))
objs.append((
'{root}/toolchain_build/src/subzero/runtime/szrt_i686.ll'
).format(root=nacl_root))
linker = 'clang' if pure_c else 'clang++'
shellcmd([linker, '-g', '-m32', args.driver] +
objs +
......
......@@ -169,10 +169,9 @@ def ProcessPexe(args, pexe, exe):
'{root}/toolchain/linux_x86/pnacl_newlib/bin/llc'
).format(root=nacl_root)
opt_level = args.optlevel
opt_level_map = { 'm1':'0', '-1':'0', '0':'0', '1':'1', '2':'2' }
if args.force or NewerThanOrNotThere(pexe, obj_llc) or \
NewerThanOrNotThere(llcbin, obj_llc):
opt_level_map = { 'm1':'0', '-1':'0', '0':'0', '1':'1', '2':'2' }
shellcmd(['pnacl-translate',
'-ffunction-sections',
'-c',
......@@ -252,15 +251,20 @@ def ProcessPexe(args, pexe, exe):
shellcmd((
'objcopy --globalize-symbol=_user_start {partial}'
).format(partial=obj_partial), echo=args.verbose)
linker = (
'{root}/../third_party/llvm-build/Release+Asserts/bin/clang'
).format(root=nacl_root)
shellcmd((
'gcc -m32 {partial} -o {exe} ' +
'{ld} -m32 {partial} -o {exe} -O{opt_level} ' +
# Keep the rest of this command line (except szrt.c) in sync
# with RunHostLD() in pnacl-translate.py.
'{root}/toolchain/linux_x86/pnacl_newlib/translator/x86-32-linux/lib/' +
'{{unsandboxed_irt,irt_query_list}}.o ' +
'{root}/toolchain_build/src/subzero/runtime/szrt.c ' +
'{root}/toolchain_build/src/subzero/runtime/szrt_i686.ll ' +
'-lpthread -lrt'
).format(partial=obj_partial, exe=exe, root=nacl_root),
).format(ld=linker, partial=obj_partial, exe=exe,
opt_level=opt_level_map[opt_level], root=nacl_root),
echo=args.verbose)
# Put the extra verbose printing at the end.
if args.verbose:
......
......@@ -68,8 +68,6 @@ double cvtui64tod(uint64_t value) {
}
/* TODO(stichnot):
Sz_fptoui_v4f32
Sz_uitofp_v4i32
Sz_bitcast_v8i1_to_i8
Sz_bitcast_v16i1_to_i16
Sz_bitcast_i8_to_v8i1
......
target triple = "i386-unknown-linux-gnu"
define <4 x float> @Sz_uitofp_v4i32(<4 x i32> %a) {
entry:
%0 = uitofp <4 x i32> %a to <4 x float>
ret <4 x float> %0
}
define <4 x i32> @Sz_fptoui_v4f32(<4 x float> %a) {
entry:
%0 = fptoui <4 x float> %a to <4 x i32>
ret <4 x i32> %0
}
......@@ -270,6 +270,14 @@ entry:
; CHECK-LABEL: doubleToSigned32
; CHECK: cvttsd2si
define internal i32 @doubleToSigned32Const() {
entry:
%conv = fptosi double 867.5309 to i32
ret i32 %conv
}
; CHECK-LABEL: doubleToSigned32Const
; CHECK: cvttsd2si
define internal i32 @floatToSigned32(float %a) {
entry:
%conv = fptosi float %a to i32
......@@ -465,6 +473,15 @@ entry:
; CHECK: cvtsi2sd
; CHECK: fld
define internal double @signed32ToDoubleConst() {
entry:
%conv = sitofp i32 123 to double
ret double %conv
}
; CHECK-LABEL: signed32ToDoubleConst
; CHECK: cvtsi2sd {{.*[^1]}}
; CHECK: fld
define internal float @signed32ToFloat(i32 %a) {
entry:
%conv = sitofp i32 %a to float
......@@ -526,6 +543,15 @@ entry:
; CHECK: cvtsi2sd
; CHECK: fld
define internal double @unsigned16ToDoubleConst() {
entry:
%conv = uitofp i16 12345 to double
ret double %conv
}
; CHECK-LABEL: unsigned16ToDoubleConst
; CHECK: cvtsi2sd
; CHECK: fld
define internal float @unsigned16ToFloat(i32 %a) {
entry:
%a.arg_trunc = trunc i32 %a to i16
......@@ -596,6 +622,38 @@ entry:
; CHECK: cvtsi2ss
; CHECK: fld
define internal float @int32BitcastToFloat(i32 %a) {
entry:
%conv = bitcast i32 %a to float
ret float %conv
}
; CHECK-LABEL: int32BitcastToFloat
; CHECK: mov
define internal float @int32BitcastToFloatConst() {
entry:
%conv = bitcast i32 8675309 to float
ret float %conv
}
; CHECK-LABEL: int32BitcastToFloatConst
; CHECK: mov
define internal double @int64BitcastToDouble(i64 %a) {
entry:
%conv = bitcast i64 %a to double
ret double %conv
}
; CHECK-LABEL: int64BitcastToDouble
; CHECK: mov
define internal double @int64BitcastToDoubleConst() {
entry:
%conv = bitcast i64 9035768 to double
ret double %conv
}
; CHECK-LABEL: int64BitcastToDoubleConst
; CHECK: mov
define internal void @fcmpEq(float %a, float %b, double %c, double %d) {
entry:
%cmp = fcmp oeq float %a, %b
......
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