• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- 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"
26 #include "xdefs.h"
27 
28 namespace Subzero_ {
29 #include "test_bitmanip.h"
30 }
31 
32 volatile uint64 Values[] = {
33     0, 1, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff, 0x7ffe, 0x7fff, 0x8000, 0x8001,
34     0xfffe, 0xffff, 0xc0de, 0xabcd, 0xdcba, 0x007fffff /*Max subnormal + */,
35     0x00800000 /*Min+ */, 0x7f7fffff /*Max+ */, 0x7f800000 /*+Inf*/,
36     0xff800000 /*-Inf*/, 0x7fa00000 /*SNaN*/, 0x7fc00000 /*QNaN*/, 0x7ffffffe,
37     0x7fffffff, 0x80000000, 0x80000001, 0xfffffffe, 0xffffffff, 0x12345678,
38     0xabcd1234, 0x1234dcba, 0x100000000ll, 0x100000001ll, 0x123456789abcdef1ll,
39     0x987654321ab1fedcll, 0x000fffffffffffffll /*Max subnormal + */,
40     0x0010000000000000ll /*Min+ */, 0x7fefffffffffffffll /*Max+ */,
41     0x7ff0000000000000ll /*+Inf*/, 0xfff0000000000000ll /*-Inf*/,
42     0x7ff0000000000001ll /*SNaN*/, 0x7ff8000000000000ll /*QNaN*/,
43     0x7ffffffffffffffell, 0x7fffffffffffffffll, 0x8000000000000000ll,
44     0x8000000000000001ll, 0xfffffffffffffffell, 0xffffffffffffffffll};
45 
46 const static size_t NumValues = sizeof(Values) / sizeof(*Values);
47 
48 template <typename Type>
testBitManip(size_t & TotalTests,size_t & Passes,size_t & Failures)49 void testBitManip(size_t &TotalTests, size_t &Passes, size_t &Failures) {
50   typedef Type (*FuncType)(Type);
51   static struct {
52     const char *Name;
53     FuncType FuncLlc;
54     FuncType FuncSz;
55   } Funcs[] = {
56 #define X(inst)                                                                \
57   { STR(inst), test_##inst, Subzero_::test_##inst }                            \
58   , {STR(inst) "_alloca", test_alloca_##inst, Subzero_::test_alloca_##inst},   \
59       {STR(inst) "_const", test_const_##inst, Subzero_::test_const_##inst},
60       BMI_OPS
61 #undef X
62   };
63   const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
64 
65   for (size_t f = 0; f < NumFuncs; ++f) {
66     for (size_t i = 0; i < NumValues; ++i) {
67       Type Value = static_cast<Type>(Values[i]);
68       ++TotalTests;
69       Type ResultSz = Funcs[f].FuncSz(Value);
70       Type ResultLlc = Funcs[f].FuncLlc(Value);
71       if (ResultSz == ResultLlc) {
72         ++Passes;
73       } else {
74         ++Failures;
75         std::cout << "test_" << Funcs[f].Name << (CHAR_BIT * sizeof(Type))
76                   << "(" << static_cast<uint64>(Value)
77                   << "): sz=" << static_cast<uint64>(ResultSz)
78                   << " llc=" << static_cast<uint64>(ResultLlc) << "\n";
79       }
80     }
81   }
82 }
83 
84 template <typename Type>
testByteSwap(size_t & TotalTests,size_t & Passes,size_t & Failures)85 void testByteSwap(size_t &TotalTests, size_t &Passes, size_t &Failures) {
86   typedef Type (*FuncType)(Type);
87   static struct {
88     const char *Name;
89     FuncType FuncLlc;
90     FuncType FuncSz;
91   } Funcs[] = {
92       {"bswap", test_bswap, Subzero_::test_bswap},
93       {"bswap_alloca", test_bswap_alloca, Subzero_::test_bswap_alloca}};
94   const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
95   for (size_t f = 0; f < NumFuncs; ++f) {
96     for (size_t i = 0; i < NumValues; ++i) {
97       Type Value = static_cast<Type>(Values[i]);
98       ++TotalTests;
99       Type ResultSz = Funcs[f].FuncSz(Value);
100       Type ResultLlc = Funcs[f].FuncLlc(Value);
101       if (ResultSz == ResultLlc) {
102         ++Passes;
103       } else {
104         ++Failures;
105         std::cout << "test_" << Funcs[f].Name << (CHAR_BIT * sizeof(Type))
106                   << "(" << static_cast<uint64>(Value)
107                   << "): sz=" << static_cast<uint64>(ResultSz)
108                   << " llc=" << static_cast<uint64>(ResultLlc) << "\n";
109       }
110     }
111   }
112 }
113 
main(int argc,char * argv[])114 int main(int argc, char *argv[]) {
115   size_t TotalTests = 0;
116   size_t Passes = 0;
117   size_t Failures = 0;
118 
119   testBitManip<uint32_t>(TotalTests, Passes, Failures);
120   testBitManip<uint64>(TotalTests, Passes, Failures);
121   testByteSwap<uint16_t>(TotalTests, Passes, Failures);
122   testByteSwap<uint32_t>(TotalTests, Passes, Failures);
123   testByteSwap<uint64>(TotalTests, Passes, Failures);
124 
125   std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes
126             << " Failures=" << Failures << "\n";
127   return Failures;
128 }
129