Patches for building llvm on Solaris x86. Contributed by Nathan Keynes.
[oota-llvm.git] / utils / PerfectShuffle / PerfectShuffle.cpp
index c2c5bfcd8c8468e8e68320688010e94c0a45e1d4..26c4cf44c6e2e01824ba74415423391076ca3f42 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Chris Lattner and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -16,7 +16,8 @@
 
 #include <iostream>
 #include <vector>
-
+#include <cassert>
+#include <cstdlib>
 struct Operator;
 
 // Masks are 4-nibble hex numbers.  Values 0-7 in any nibble means that it takes
@@ -60,9 +61,11 @@ static bool isOnlyLHSMask(unsigned short Mask) {
 /// getLHSOnlyMask - Given a mask that refers to its LHS and RHS, modify it to
 /// refer to the LHS only (for when one argument value is passed into the same
 /// function twice).
+#if 0
 static unsigned short getLHSOnlyMask(unsigned short Mask) {
   return Mask & 0xBBBB;  // Keep only LHS and Undefs.
 }
+#endif
 
 /// getCompressedMask - Turn a 16-bit uncompressed mask (where each elt uses 4
 /// bits) into a compressed 13-bit mask, where each elt is multiplied by 9.
@@ -295,7 +298,6 @@ int main() {
         
       for (unsigned opnum = 0, e = TheOperators.size(); opnum != e; ++opnum) {
         Operator *Op = TheOperators[opnum];
-        unsigned short Mask = Op->ShuffleMask;
 
         // Evaluate op(LHS,LHS)
         unsigned ResultMask = Op->getTransformedMask(LHS, LHS);
@@ -381,7 +383,9 @@ int main() {
     
     // CostSat - The cost of this operation saturated to two bits.
     unsigned CostSat = ShufTab[i].Cost;
-    if (CostSat > 3) CostSat = 3;
+    if (CostSat > 4) CostSat = 4;
+    if (CostSat == 0) CostSat = 1;
+    --CostSat;  // Cost is now between 0-3.
     
     unsigned OpNum = ShufTab[i].Op ? ShufTab[i].Op->OpNum : 0;
     assert(OpNum < 16 && "Too few bits to encode operation!");
@@ -391,7 +395,7 @@ int main() {
     
     // Encode this as 2 bits of saturated cost, 4 bits of opcodes, 13 bits of
     // LHS, and 13 bits of RHS = 32 bits.
-    unsigned Val = (CostSat << 30) | (OpNum << 27) | (LHS << 13) | RHS;
+    unsigned Val = (CostSat << 30) | (OpNum << 26) | (LHS << 13) | RHS;
 
     std::cout << "  " << Val << "U,\t// ";
     PrintMask(i, std::cout);
@@ -457,7 +461,7 @@ enum {
   OP_VSPLTISW3,
   OP_VSLDOI4,
   OP_VSLDOI8,
-  OP_VSLDOI12,
+  OP_VSLDOI12
 };
 
 struct vmrghw : public Operator {