blob: 49014623e42747d62660fb4bd9fbd4430db5e0d0 [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[] = {
Jan Voung7fa813b2014-07-18 13:01:08 -070031 0, 1,
32 0x7e, 0x7f,
33 0x80, 0x81,
34 0xfe, 0xff,
35 0x7ffe, 0x7fff,
36 0x8000, 0x8001,
37 0xfffe, 0xffff,
38 0xc0de, 0xabcd,
39 0xdcba, 0x007fffff /*Max subnormal + */,
40 0x00800000 /*Min+ */, 0x7f7fffff /*Max+ */,
41 0x7f800000 /*+Inf*/, 0xff800000 /*-Inf*/,
42 0x7fa00000 /*SNaN*/, 0x7fc00000 /*QNaN*/,
43 0x7ffffffe, 0x7fffffff,
44 0x80000000, 0x80000001,
45 0xfffffffe, 0xffffffff,
46 0x12345678, 0xabcd1234,
47 0x1234dcba, 0x100000000ll,
48 0x100000001ll, 0x123456789abcdef1ll,
49 0x987654321ab1fedcll, 0x000fffffffffffffll /*Max subnormal + */,
50 0x0010000000000000ll /*Min+ */, 0x7fefffffffffffffll /*Max+ */,
51 0x7ff0000000000000ll /*+Inf*/, 0xfff0000000000000ll /*-Inf*/,
52 0x7ff0000000000001ll /*SNaN*/, 0x7ff8000000000000ll /*QNaN*/,
53 0x7ffffffffffffffell, 0x7fffffffffffffffll,
54 0x8000000000000000ll, 0x8000000000000001ll,
55 0xfffffffffffffffell, 0xffffffffffffffffll};
Jan Vounge4da26f2014-07-15 17:52:39 -070056
57const static size_t NumValues = sizeof(Values) / sizeof(*Values);
58
59template <typename Type>
60void testBitManip(size_t &TotalTests, size_t &Passes, size_t &Failures) {
61 typedef Type (*FuncType)(Type);
62 static struct {
63 const char *Name;
64 FuncType FuncLlc;
65 FuncType FuncSz;
66 } Funcs[] = {
Jim Stichnothdd842db2015-01-27 12:53:53 -080067#define X(inst) \
68 { STR(inst), test_##inst, Subzero_::test_##inst } \
69 , {STR(inst) "_alloca", test_alloca_##inst, Subzero_::test_alloca_##inst}, \
70 {STR(inst) "_const", test_const_##inst, Subzero_::test_const_##inst},
71 BMI_OPS
Jan Vounge4da26f2014-07-15 17:52:39 -070072#undef X
Jim Stichnothdd842db2015-01-27 12:53:53 -080073 };
Jan Vounge4da26f2014-07-15 17:52:39 -070074 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
75
76 for (size_t f = 0; f < NumFuncs; ++f) {
77 for (size_t i = 0; i < NumValues; ++i) {
78 Type Value = static_cast<Type>(Values[i]);
79 ++TotalTests;
80 Type ResultSz = Funcs[f].FuncSz(Value);
81 Type ResultLlc = Funcs[f].FuncLlc(Value);
82 if (ResultSz == ResultLlc) {
83 ++Passes;
84 } else {
85 ++Failures;
Jim Stichnothdd842db2015-01-27 12:53:53 -080086 std::cout << "test_" << Funcs[f].Name << (CHAR_BIT * sizeof(Type))
87 << "(" << static_cast<uint64_t>(Value)
Jan Vounge4da26f2014-07-15 17:52:39 -070088 << "): sz=" << static_cast<uint64_t>(ResultSz)
Jim Stichnothdd842db2015-01-27 12:53:53 -080089 << " llc=" << static_cast<uint64_t>(ResultLlc) << "\n";
Jan Vounge4da26f2014-07-15 17:52:39 -070090 }
91 }
92 }
93}
94
Jan Voung7fa813b2014-07-18 13:01:08 -070095template <typename Type>
96void testByteSwap(size_t &TotalTests, size_t &Passes, size_t &Failures) {
Jan Voung3b43b892014-09-24 13:32:39 -070097 typedef Type (*FuncType)(Type);
98 static struct {
99 const char *Name;
100 FuncType FuncLlc;
101 FuncType FuncSz;
102 } Funcs[] = {
103 {"bswap", test_bswap, Subzero_::test_bswap},
104 {"bswap_alloca", test_bswap_alloca, Subzero_::test_bswap_alloca}};
105 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
106 for (size_t f = 0; f < NumFuncs; ++f) {
107 for (size_t i = 0; i < NumValues; ++i) {
108 Type Value = static_cast<Type>(Values[i]);
109 ++TotalTests;
110 Type ResultSz = Funcs[f].FuncSz(Value);
111 Type ResultLlc = Funcs[f].FuncLlc(Value);
112 if (ResultSz == ResultLlc) {
113 ++Passes;
114 } else {
115 ++Failures;
116 std::cout << "test_" << Funcs[f].Name << (CHAR_BIT * sizeof(Type))
117 << "(" << static_cast<uint64_t>(Value)
118 << "): sz=" << static_cast<uint64_t>(ResultSz)
119 << " llc=" << static_cast<uint64_t>(ResultLlc) << "\n";
120 }
Jan Voung7fa813b2014-07-18 13:01:08 -0700121 }
122 }
123}
124
Jan Vounge4da26f2014-07-15 17:52:39 -0700125int main(int argc, char **argv) {
126 size_t TotalTests = 0;
127 size_t Passes = 0;
128 size_t Failures = 0;
129
130 testBitManip<uint32_t>(TotalTests, Passes, Failures);
131 testBitManip<uint64_t>(TotalTests, Passes, Failures);
Jan Voung7fa813b2014-07-18 13:01:08 -0700132 testByteSwap<uint16_t>(TotalTests, Passes, Failures);
133 testByteSwap<uint32_t>(TotalTests, Passes, Failures);
134 testByteSwap<uint64_t>(TotalTests, Passes, Failures);
Jan Vounge4da26f2014-07-15 17:52:39 -0700135
136 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes
137 << " Failures=" << Failures << "\n";
138 return Failures;
139}