blob: dfb5d1a9bf538c6b6eb72e583b1deb6aa34b535e [file] [log] [blame]
Jan Vounge4da26f2014-07-15 17:52:39 -07001//===- subzero/crosstest/test_bitmanip_main.cpp - Driver for tests. -------===//
2//
3// The Subzero Code Generator
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Driver for cross testing bit manipulation intrinsics.
11//
12//===----------------------------------------------------------------------===//
13
14/* crosstest.py --test=test_bitmanip.cpp --test=test_bitmanip_intrin.ll \
15 --driver=test_bitmanip_main.cpp --prefix=Subzero_ --output=test_bitmanip */
16
17#include <stdint.h>
18
19#include <climits>
20#include <iostream>
21
22// Include test_bitmanip.h twice - once normally, and once within the
23// Subzero_ namespace, corresponding to the llc and Subzero translated
24// object files, respectively.
25#include "test_bitmanip.h"
26namespace Subzero_ {
27#include "test_bitmanip.h"
28}
29
30volatile uint64_t Values[] = {
Jim Stichnothd9dc82e2015-03-03 17:06:33 -080031 0, 1, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff, 0x7ffe, 0x7fff, 0x8000, 0x8001,
32 0xfffe, 0xffff, 0xc0de, 0xabcd, 0xdcba, 0x007fffff /*Max subnormal + */,
33 0x00800000 /*Min+ */, 0x7f7fffff /*Max+ */, 0x7f800000 /*+Inf*/,
34 0xff800000 /*-Inf*/, 0x7fa00000 /*SNaN*/, 0x7fc00000 /*QNaN*/, 0x7ffffffe,
35 0x7fffffff, 0x80000000, 0x80000001, 0xfffffffe, 0xffffffff, 0x12345678,
36 0xabcd1234, 0x1234dcba, 0x100000000ll, 0x100000001ll, 0x123456789abcdef1ll,
37 0x987654321ab1fedcll, 0x000fffffffffffffll /*Max subnormal + */,
Jan Voung7fa813b2014-07-18 13:01:08 -070038 0x0010000000000000ll /*Min+ */, 0x7fefffffffffffffll /*Max+ */,
Jim Stichnothd9dc82e2015-03-03 17:06:33 -080039 0x7ff0000000000000ll /*+Inf*/, 0xfff0000000000000ll /*-Inf*/,
40 0x7ff0000000000001ll /*SNaN*/, 0x7ff8000000000000ll /*QNaN*/,
41 0x7ffffffffffffffell, 0x7fffffffffffffffll, 0x8000000000000000ll,
42 0x8000000000000001ll, 0xfffffffffffffffell, 0xffffffffffffffffll};
Jan Vounge4da26f2014-07-15 17:52:39 -070043
44const static size_t NumValues = sizeof(Values) / sizeof(*Values);
45
46template <typename Type>
47void testBitManip(size_t &TotalTests, size_t &Passes, size_t &Failures) {
48 typedef Type (*FuncType)(Type);
49 static struct {
50 const char *Name;
51 FuncType FuncLlc;
52 FuncType FuncSz;
53 } Funcs[] = {
Jim Stichnothdd842db2015-01-27 12:53:53 -080054#define X(inst) \
55 { STR(inst), test_##inst, Subzero_::test_##inst } \
56 , {STR(inst) "_alloca", test_alloca_##inst, Subzero_::test_alloca_##inst}, \
57 {STR(inst) "_const", test_const_##inst, Subzero_::test_const_##inst},
Jim Stichnothd9dc82e2015-03-03 17:06:33 -080058 BMI_OPS
Jan Vounge4da26f2014-07-15 17:52:39 -070059#undef X
Jim Stichnothd9dc82e2015-03-03 17:06:33 -080060 };
Jan Vounge4da26f2014-07-15 17:52:39 -070061 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
62
63 for (size_t f = 0; f < NumFuncs; ++f) {
64 for (size_t i = 0; i < NumValues; ++i) {
65 Type Value = static_cast<Type>(Values[i]);
66 ++TotalTests;
67 Type ResultSz = Funcs[f].FuncSz(Value);
68 Type ResultLlc = Funcs[f].FuncLlc(Value);
69 if (ResultSz == ResultLlc) {
70 ++Passes;
71 } else {
72 ++Failures;
Jim Stichnothdd842db2015-01-27 12:53:53 -080073 std::cout << "test_" << Funcs[f].Name << (CHAR_BIT * sizeof(Type))
74 << "(" << static_cast<uint64_t>(Value)
Jan Vounge4da26f2014-07-15 17:52:39 -070075 << "): sz=" << static_cast<uint64_t>(ResultSz)
Jim Stichnothdd842db2015-01-27 12:53:53 -080076 << " llc=" << static_cast<uint64_t>(ResultLlc) << "\n";
Jan Vounge4da26f2014-07-15 17:52:39 -070077 }
78 }
79 }
80}
81
Jan Voung7fa813b2014-07-18 13:01:08 -070082template <typename Type>
83void testByteSwap(size_t &TotalTests, size_t &Passes, size_t &Failures) {
Jan Voung3b43b892014-09-24 13:32:39 -070084 typedef Type (*FuncType)(Type);
85 static struct {
86 const char *Name;
87 FuncType FuncLlc;
88 FuncType FuncSz;
89 } Funcs[] = {
Jim Stichnothd9dc82e2015-03-03 17:06:33 -080090 {"bswap", test_bswap, Subzero_::test_bswap},
91 {"bswap_alloca", test_bswap_alloca, Subzero_::test_bswap_alloca}};
Jan Voung3b43b892014-09-24 13:32:39 -070092 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
93 for (size_t f = 0; f < NumFuncs; ++f) {
94 for (size_t i = 0; i < NumValues; ++i) {
95 Type Value = static_cast<Type>(Values[i]);
96 ++TotalTests;
97 Type ResultSz = Funcs[f].FuncSz(Value);
98 Type ResultLlc = Funcs[f].FuncLlc(Value);
99 if (ResultSz == ResultLlc) {
100 ++Passes;
101 } else {
102 ++Failures;
103 std::cout << "test_" << Funcs[f].Name << (CHAR_BIT * sizeof(Type))
104 << "(" << static_cast<uint64_t>(Value)
105 << "): sz=" << static_cast<uint64_t>(ResultSz)
106 << " llc=" << static_cast<uint64_t>(ResultLlc) << "\n";
107 }
Jan Voung7fa813b2014-07-18 13:01:08 -0700108 }
109 }
110}
111
Jan Vounge4da26f2014-07-15 17:52:39 -0700112int main(int argc, char **argv) {
113 size_t TotalTests = 0;
114 size_t Passes = 0;
115 size_t Failures = 0;
116
117 testBitManip<uint32_t>(TotalTests, Passes, Failures);
118 testBitManip<uint64_t>(TotalTests, Passes, Failures);
Jan Voung7fa813b2014-07-18 13:01:08 -0700119 testByteSwap<uint16_t>(TotalTests, Passes, Failures);
120 testByteSwap<uint32_t>(TotalTests, Passes, Failures);
121 testByteSwap<uint64_t>(TotalTests, Passes, Failures);
Jan Vounge4da26f2014-07-15 17:52:39 -0700122
123 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes
124 << " Failures=" << Failures << "\n";
125 return Failures;
126}