Some changes to hadle different vector width

This commit is contained in:
Vsevolod Livinskiy
2015-02-27 10:27:53 +03:00
parent 0644b4a7fd
commit a98bfdf011
4 changed files with 106 additions and 58 deletions

View File

@@ -179,6 +179,50 @@ FORCEINLINE __vec4_i64::__vec4_i64(__vec4_d vd) {
v[1] = _mm_castpd_si128(vd.v[1]);
}
template <int num_bits>
struct iN {
int num[num_bits / (sizeof (int) * 8)];
iN () {}
iN (const char *val) {
if (val == NULL)
return;
int length = num_bits / (sizeof (int) * 8);
int val_len = 0;
for (val_len = 0; val[val_len]; (val_len)++);
for (int i = 0; (i < val_len && i < num_bits); i++)
num[i / (sizeof (int) * 8)] = (num[i / (sizeof (int) * 8)] << 1) | (val[i] - '0');
}
~iN () {}
iN operator >> (const iN rhs) {
iN res;
int length = num_bits / (sizeof (int) * 8);
int cells = rhs.num[0] / (sizeof(int) * 8);
for (int i = 0; i < (length - cells); i++)
res.num[i] = this->num[cells + i];
return res;
}
iN operator & (iN rhs) {
iN res;
int length = num_bits / (sizeof (int) * 8);
for (int i = 0; i < length; i++)
res.num[i] = (this->num[i]) & (rhs.num[i]);
return res;
}
operator uint32_t() { return this->num[0]; }
};
template <class T>
T __cast_bits (T to, __vec4_i32 from) {
for (int i = 0; i < 16; i++)
to.num[i] = ((uint32_t*)(&from))[i] ;
return to;
}
///////////////////////////////////////////////////////////////////////////
// SSE helpers / utility functions