Some changes was made to support older llvm versions.

This commit is contained in:
Vsevolod Livinskiy
2015-02-27 16:02:55 +03:00
parent 4c629d0a7c
commit 19d18b6e4e
3 changed files with 103 additions and 51 deletions

View File

@@ -2753,7 +2753,7 @@ void CWriter::printModuleTypes() {
Out << " double Double;\n";
Out << "} llvmBitCastUnion;\n";
Out << "\n/* It is special class, designed for operations with long int.*/ \n";
Out << "\n/* This is special class, designed for operations with long int.*/ \n";
Out << "template <int num_bits> \n";
Out << "struct iN { \n";
Out << " int num[num_bits / (sizeof (int) * 8)]; \n";
@@ -2796,14 +2796,27 @@ void CWriter::printModuleTypes() {
Out << " } \n";
Out << " \n";
Out << " operator uint32_t() { return this->num[0]; } \n";
Out << "}; \n";
Out << " \n";
Out << "template <class T> \n";
Out << "T __cast_bits (T to, __vec" << vectorWidth << "_i32 from) { \n";
Out << " for (int i = 0; i < 16; i++) \n";
Out << " to.num[i] = ((uint32_t*)(&from))[i]; \n";
Out << " template <class T> \n";
Out << " friend iN<num_bits> __cast_bits(iN<num_bits> to, T from) { \n";
Out << " for (int i = 0; i <" << vectorWidth << "; i++) \n";
Out << " to.num[i] = ((int*)(&from))[i]; \n";
Out << " return to; \n";
Out << "} \n";
Out << " } \n";
Out << " \n";
Out << " template <class T> \n";
Out << " friend T __cast_bits(T to, iN<num_bits> from) { \n";
Out << " for (int i = 0; i <" << vectorWidth << "; i++) \n";
Out << " ((int*)(&to))[i] = from.num[i]; \n";
Out << " return to; \n";
Out << " } \n";
Out << " \n";
Out << " template <int ALIGN, class T> \n";
Out << " friend void __store(T *p, iN<num_bits> val) { \n";
Out << " for (int i = 0; i <" << vectorWidth << "; i++) \n";
Out << " ((int*)p)[i] = val.num[i]; \n";
Out << " } \n";
Out << "}; \n";
Out << "\n";
// Get all of the struct types used in the module.

View File

@@ -977,6 +977,25 @@ CAST_BITS_SCALAR(int64_t, double)
CAST_BITS_SCALAR(double, uint64_t)
CAST_BITS_SCALAR(double, int64_t)
#define CAST_BITS_TRIVIAL(TYPE) \
static FORCEINLINE TYPE __cast_bits(TYPE, TYPE v) { return v; }
CAST_BITS_TRIVIAL(float)
CAST_BITS_TRIVIAL(double)
CAST_BITS_TRIVIAL(int8_t)
CAST_BITS_TRIVIAL(uint8_t)
CAST_BITS_TRIVIAL(int16_t)
CAST_BITS_TRIVIAL(uint16_t)
CAST_BITS_TRIVIAL(int32_t)
CAST_BITS_TRIVIAL(uint32_t)
CAST_BITS_TRIVIAL(int64_t)
CAST_BITS_TRIVIAL(uint64_t)
CAST_BITS_TRIVIAL(__vec16_f)
CAST_BITS_TRIVIAL(__vec16_d)
CAST_BITS_TRIVIAL(__vec16_i8)
CAST_BITS_TRIVIAL(__vec16_i16)
CAST_BITS_TRIVIAL(__vec16_i32)
CAST_BITS_TRIVIAL(__vec16_i64)
///////////////////////////////////////////////////////////////////////////
// various math functions

View File

@@ -295,6 +295,26 @@ CAST_BITS_SCALAR(int64_t, double)
CAST_BITS_SCALAR(double, uint64_t)
CAST_BITS_SCALAR(double, int64_t)
#define CAST_BITS_TRIVIAL(TYPE) \
static FORCEINLINE TYPE __cast_bits(TYPE, TYPE v) { return v; }
CAST_BITS_TRIVIAL(float)
CAST_BITS_TRIVIAL(double)
CAST_BITS_TRIVIAL(int8_t)
CAST_BITS_TRIVIAL(uint8_t)
CAST_BITS_TRIVIAL(int16_t)
CAST_BITS_TRIVIAL(uint16_t)
CAST_BITS_TRIVIAL(int32_t)
CAST_BITS_TRIVIAL(uint32_t)
CAST_BITS_TRIVIAL(int64_t)
CAST_BITS_TRIVIAL(uint64_t)
CAST_BITS_TRIVIAL(__vec4_f)
CAST_BITS_TRIVIAL(__vec4_d)
CAST_BITS_TRIVIAL(__vec4_i8)
CAST_BITS_TRIVIAL(__vec4_i16)
CAST_BITS_TRIVIAL(__vec4_i32)
CAST_BITS_TRIVIAL(__vec4_i64)
#define CMP_AND_MASK_ONE(FUNC, TYPE) \
static FORCEINLINE __vec4_i1 FUNC##_and_mask(TYPE a, TYPE b, __vec4_i1 m) { \
return __and(FUNC(a, b), m); \