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

Unified Diff: crosstest/test_cast_main.cpp

Issue 639543002: Add cross test for vector itofp and fptoi casts. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: stuff Created 6 years, 2 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
Index: crosstest/test_cast_main.cpp
diff --git a/crosstest/test_cast_main.cpp b/crosstest/test_cast_main.cpp
index 4ac700e1f8c1c9d1bc359e3e198cb3bd40b00316..9a0370cf1aec44a23a595677fd9b2f68610454a6 100644
--- a/crosstest/test_cast_main.cpp
+++ b/crosstest/test_cast_main.cpp
@@ -12,12 +12,15 @@
//===----------------------------------------------------------------------===//
/* 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 <cstring>
#include <iostream>
#include <stdint.h>
+#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 +51,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 +86,37 @@ 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;
+ volatile float Values[] = {
Jim Stichnoth 2014/10/07 21:57:47 How about creating this array using FP_VALUE_ARRAY
jvoung (off chromium) 2014/10/07 22:55:54 Good idea -- done.
+ 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 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;
@@ -219,6 +272,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";
« no previous file with comments | « crosstest/runtests.sh ('k') | crosstest/test_cast_vectors.ll » ('j') | pydir/szbuild.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698