Home | History | Annotate | Download | only in crosstest
      1 //===- subzero/crosstest/test_strengthreduce_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 crosstesting arithmetic strength-reducing optimizations.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 /* crosstest.py --test=test_strengthreduce.cpp \
     15    --driver=test_strengthreduce_main.cpp \
     16    --prefix=Subzero_ --clang-opt=0 --output=test_strengthreduce */
     17 
     18 #include <iostream>
     19 
     20 // Include test_strengthreduce.h twice - once normally, and once
     21 // within the Subzero_ namespace, corresponding to the llc and Subzero
     22 // translated object files, respectively.
     23 #include "test_strengthreduce.h"
     24 namespace Subzero_ {
     25 #include "test_strengthreduce.h"
     26 }
     27 
     28 int main(int argc, char *argv[]) {
     29   size_t TotalTests = 0;
     30   size_t Passes = 0;
     31   size_t Failures = 0;
     32   static int32_t Values[] = {-100, -50, 0, 1, 8, 123, 0x33333333, 0x77777777};
     33   for (size_t i = 0; i < sizeof(Values) / sizeof(*Values); ++i) {
     34     int32_t SVal = Values[i];
     35     int32_t ResultLlcS, ResultSzS;
     36     uint32_t UVal = (uint32_t)Values[i];
     37     int32_t ResultLlcU, ResultSzU;
     38 
     39 #define X(constant, suffix)                                                    \
     40   ResultLlcS = multiplyByConst##suffix(UVal);                                  \
     41   ResultSzS = Subzero_::multiplyByConst##suffix(UVal);                         \
     42   if (ResultLlcS == ResultSzS) {                                               \
     43     ++Passes;                                                                  \
     44   } else {                                                                     \
     45     ++Failures;                                                                \
     46     std::cout << "multiplyByConstS" STR(suffix) "(" << SVal                    \
     47               << "): sz=" << ResultSzS << " llc=" << ResultLlcS << "\n";       \
     48   }                                                                            \
     49   ResultLlcU = multiplyByConst##suffix(UVal);                                  \
     50   ResultSzU = Subzero_::multiplyByConst##suffix(UVal);                         \
     51   if (ResultLlcU == ResultSzU) {                                               \
     52     ++Passes;                                                                  \
     53   } else {                                                                     \
     54     ++Failures;                                                                \
     55     std::cout << "multiplyByConstU" STR(suffix) "(" << UVal                    \
     56               << "): sz=" << ResultSzU << " llc=" << ResultLlcU << "\n";       \
     57   }
     58     CONST_TABLE
     59 #undef X
     60   }
     61 
     62   std::cout << "TotalTests=" << TotalTests << " Passes=" << Passes
     63             << " Failures=" << Failures << "\n";
     64   return Failures;
     65 }
     66