blob: 827f0e78f0db5a9bb23dfb4ff6bdfb81fb29590c [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"
John Porto1d235422015-08-12 12:37:53 -070026#include "xdefs.h"
27
Jan Vounge4da26f2014-07-15 17:52:39 -070028namespace Subzero_ {
29#include "test_bitmanip.h"
30}
31
Antonio Maioranoca8a16e2020-11-10 16:56:20 -050032volatile uint64 Values[] = {0,
33 1,
34 0x7e,
35 0x7f,
36 0x80,
37 0x81,
38 0xfe,
39 0xff,
40 0x7ffe,
41 0x7fff,
42 0x8000,
43 0x8001,
44 0xfffe,
45 0xffff,
46 0xc0de,
47 0xabcd,
48 0xdcba,
49 0x007fffff /*Max subnormal + */,
50 0x00800000 /*Min+ */,
51 0x7f7fffff /*Max+ */,
52 0x7f800000 /*+Inf*/,
53 0xff800000 /*-Inf*/,
54 0x7fa00000 /*SNaN*/,
55 0x7fc00000 /*QNaN*/,
56 0x7ffffffe,
57 0x7fffffff,
58 0x80000000,
59 0x80000001,
60 0xfffffffe,
61 0xffffffff,
62 0x12345678,
63 0xabcd1234,
64 0x1234dcba,
65 0x100000000ll,
66 0x100000001ll,
67 0x123456789abcdef1ll,
68 0x987654321ab1fedcll,
69 0x000fffffffffffffll /*Max subnormal + */,
70 0x0010000000000000ll /*Min+ */,
71 0x7fefffffffffffffll /*Max+ */,
72 0x7ff0000000000000ll /*+Inf*/,
73 0xfff0000000000000ll /*-Inf*/,
74 0x7ff0000000000001ll /*SNaN*/,
75 0x7ff8000000000000ll /*QNaN*/,
76 0x7ffffffffffffffell,
77 0x7fffffffffffffffll,
78 0x8000000000000000ll,
79 0x8000000000000001ll,
80 0xfffffffffffffffell,
81 0xffffffffffffffffll};
Jan Vounge4da26f2014-07-15 17:52:39 -070082
83const static size_t NumValues = sizeof(Values) / sizeof(*Values);
84
85template <typename Type>
86void testBitManip(size_t &TotalTests, size_t &Passes, size_t &Failures) {
87 typedef Type (*FuncType)(Type);
88 static struct {
89 const char *Name;
90 FuncType FuncLlc;
91 FuncType FuncSz;
92 } Funcs[] = {
Jim Stichnothdd842db2015-01-27 12:53:53 -080093#define X(inst) \
Antonio Maioranoca8a16e2020-11-10 16:56:20 -050094 {STR(inst), test_##inst, Subzero_::test_##inst}, \
95 {STR(inst) "_alloca", test_alloca_##inst, Subzero_::test_alloca_##inst}, \
Jim Stichnothdd842db2015-01-27 12:53:53 -080096 {STR(inst) "_const", test_const_##inst, Subzero_::test_const_##inst},
Jim Stichnothd9dc82e2015-03-03 17:06:33 -080097 BMI_OPS
Jan Vounge4da26f2014-07-15 17:52:39 -070098#undef X
Jim Stichnothd9dc82e2015-03-03 17:06:33 -080099 };
Jan Vounge4da26f2014-07-15 17:52:39 -0700100 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
101
102 for (size_t f = 0; f < NumFuncs; ++f) {
103 for (size_t i = 0; i < NumValues; ++i) {
104 Type Value = static_cast<Type>(Values[i]);
105 ++TotalTests;
106 Type ResultSz = Funcs[f].FuncSz(Value);
107 Type ResultLlc = Funcs[f].FuncLlc(Value);
108 if (ResultSz == ResultLlc) {
109 ++Passes;
110 } else {
111 ++Failures;
Jim Stichnothdd842db2015-01-27 12:53:53 -0800112 std::cout << "test_" << Funcs[f].Name << (CHAR_BIT * sizeof(Type))
John Porto1d235422015-08-12 12:37:53 -0700113 << "(" << static_cast<uint64>(Value)
114 << "): sz=" << static_cast<uint64>(ResultSz)
115 << " llc=" << static_cast<uint64>(ResultLlc) << "\n";
Jan Vounge4da26f2014-07-15 17:52:39 -0700116 }
117 }
118 }
119}
120
Jan Voung7fa813b2014-07-18 13:01:08 -0700121template <typename Type>
122void testByteSwap(size_t &TotalTests, size_t &Passes, size_t &Failures) {
Jan Voung3b43b892014-09-24 13:32:39 -0700123 typedef Type (*FuncType)(Type);
124 static struct {
125 const char *Name;
126 FuncType FuncLlc;
127 FuncType FuncSz;
128 } Funcs[] = {
Jim Stichnothd9dc82e2015-03-03 17:06:33 -0800129 {"bswap", test_bswap, Subzero_::test_bswap},
130 {"bswap_alloca", test_bswap_alloca, Subzero_::test_bswap_alloca}};
Jan Voung3b43b892014-09-24 13:32:39 -0700131 const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
132 for (size_t f = 0; f < NumFuncs; ++f) {
133 for (size_t i = 0; i < NumValues; ++i) {
134 Type Value = static_cast<Type>(Values[i]);
135 ++TotalTests;
136 Type ResultSz = Funcs[f].FuncSz(Value);
137 Type ResultLlc = Funcs[f].FuncLlc(Value);
138 if (ResultSz == ResultLlc) {
139 ++Passes;
140 } else {
141 ++Failures;
142 std::cout << "test_" << Funcs[f].Name << (CHAR_BIT * sizeof(Type))
John Porto1d235422015-08-12 12:37:53 -0700143 << "(" << static_cast<uint64>(Value)
144 << "): sz=" << static_cast<uint64>(ResultSz)
145 << " llc=" << static_cast<uint64>(ResultLlc) << "\n";
Jan Voung3b43b892014-09-24 13:32:39 -0700146 }
Jan Voung7fa813b2014-07-18 13:01:08 -0700147 }
148 }
149}
150
John Porto1d235422015-08-12 12:37:53 -0700151int main(int argc, char *argv[]) {
Jan Vounge4da26f2014-07-15 17:52:39 -0700152 size_t TotalTests = 0;
153 size_t Passes = 0;
154 size_t Failures = 0;
155
156 testBitManip<uint32_t>(TotalTests, Passes, Failures);
John Porto1d235422015-08-12 12:37:53 -0700157 testBitManip<uint64>(TotalTests, Passes, Failures);
Jan Voung7fa813b2014-07-18 13:01:08 -0700158 testByteSwap<uint16_t>(TotalTests, Passes, Failures);
159 testByteSwap<uint32_t>(TotalTests, Passes, Failures);
John Porto1d235422015-08-12 12:37:53 -0700160 testByteSwap<uint64>(TotalTests, Passes, Failures);
Jan Vounge4da26f2014-07-15 17:52:39 -0700161
162 std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes
163 << " Failures=" << Failures << "\n";
164 return Failures;
165}