@@ -990,9 +990,29 @@ std::string JSWriter::getAssignIfNeeded(const Value *V) {
990
990
return std::string ();
991
991
}
992
992
993
+ int SIMDNumElements (VectorType *t) {
994
+ assert (t->getElementType ()->getPrimitiveSizeInBits () <= 128 );
995
+
996
+ if (t->getElementType ()->getPrimitiveSizeInBits () == 1 ) { // Bool8x16, Bool16x8, Bool32x4 or Bool64x2
997
+ if (t->getNumElements () <= 2 ) return 2 ;
998
+ if (t->getNumElements () <= 4 ) return 4 ;
999
+ if (t->getNumElements () <= 8 ) return 8 ;
1000
+ if (t->getNumElements () <= 16 ) return 16 ;
1001
+ // fall-through to error
1002
+ } else { // Int/Float 8x16, 16x8, 32x4 or 64x2
1003
+ if (t->getElementType ()->getPrimitiveSizeInBits () > 32 && t->getNumElements () <= 2 ) return 2 ;
1004
+ if (t->getElementType ()->getPrimitiveSizeInBits () > 16 && t->getNumElements () <= 4 ) return 4 ;
1005
+ if (t->getElementType ()->getPrimitiveSizeInBits () > 8 && t->getNumElements () <= 8 ) return 8 ;
1006
+ if (t->getElementType ()->getPrimitiveSizeInBits () <= 8 && t->getNumElements () <= 16 ) return 16 ;
1007
+ // fall-through to error
1008
+ }
1009
+ errs () << *t << " \n " ;
1010
+ report_fatal_error (" Unsupported type!" );
1011
+ return 0 ;
1012
+ }
1013
+
993
1014
const char *SIMDType (VectorType *t) {
994
- int primSize = t->getElementType ()->getPrimitiveSizeInBits ();
995
- assert (primSize <= 128 );
1015
+ assert (t->getElementType ()->getPrimitiveSizeInBits () <= 128 );
996
1016
997
1017
if (t->getElementType ()->isIntegerTy ()) {
998
1018
if (t->getElementType ()->getPrimitiveSizeInBits () == 1 ) {
@@ -1645,8 +1665,7 @@ std::string JSWriter::getConstantVector(const ConstantVectorType *C) {
1645
1665
}
1646
1666
}
1647
1667
1648
- int primSize = C->getType ()->getElementType ()->getPrimitiveSizeInBits ();
1649
- const int SIMDJsRetNumElements = 128 / primSize;
1668
+ const int SIMDJsRetNumElements = SIMDNumElements (C->getType ());
1650
1669
1651
1670
std::string c;
1652
1671
if (!hasSpecialNaNs) {
@@ -1852,7 +1871,7 @@ std::string JSWriter::getSIMDCast(VectorType *fromType, VectorType *toType, cons
1852
1871
}
1853
1872
1854
1873
// Promote smaller than 128-bit vector types to 128-bit since smaller ones do not exist in SIMD.js. (pad with zero lanes)
1855
- int toNumElems = 128 / toPrimSize ;
1874
+ const int toNumElems = SIMDNumElements (toType) ;
1856
1875
1857
1876
bool fromIsBool = (fromInt && fromPrimSize == 1 );
1858
1877
bool toIsBool = (toInt && toPrimSize == 1 );
@@ -1899,8 +1918,8 @@ void JSWriter::generateShuffleVectorExpression(const ShuffleVectorInst *SVI, raw
1899
1918
int OpNumElements = op0->getNumElements ();
1900
1919
int ResultNumElements = SVI->getType ()->getNumElements ();
1901
1920
// Promote smaller than 128-bit vector types to 128-bit since smaller ones do not exist in SIMD.js. (pad with zero lanes)
1902
- int SIMDJsRetNumElements = 128 / cast<VectorType>(SVI->getType ())-> getElementType ()-> getPrimitiveSizeInBits ( );
1903
- int SIMDJsOp0NumElements = 128 / op0-> getElementType ()-> getPrimitiveSizeInBits ( );
1921
+ const int SIMDJsRetNumElements = SIMDNumElements ( cast<VectorType>(SVI->getType ()));
1922
+ const int SIMDJsOp0NumElements = SIMDNumElements (op0 );
1904
1923
bool swizzleA = true ;
1905
1924
bool swizzleB = true ;
1906
1925
for (int i = 0 ; i < ResultNumElements; ++i) {
0 commit comments