Minor code standard cleanup.

This commit is contained in:
Peter Pettersson 2013-04-22 21:09:34 +02:00
parent b78edadf6d
commit 3da9ab8821
3 changed files with 43 additions and 43 deletions

View File

@ -71,8 +71,8 @@ inline unsigned RandomWELL512a::GetUnsigned()
unsigned index_13 = (index + 13) & 15;
unsigned index_15 = (index + 15) & 15;
unsigned state_index = state[index];
unsigned state_index_9 = state[index_9];
unsigned state_index = state[index];
unsigned state_index_9 = state[index_9];
unsigned state_index_13 = state[index_13];
unsigned state_index_15 = state[index_15];

View File

@ -44,40 +44,40 @@ public:
void GetDouble4(double *result4);
private:
__m128i xmm_state[16];
unsigned index;
__m128i state[16];
unsigned index;
// Helper to allow us to return one number per call.
unsigned result[4];
unsigned resultIndex;
unsigned result[4];
unsigned result_index;
};
inline RandomWELL512a_SSE2::RandomWELL512a_SSE2(int seed)
: index(0)
, resultIndex(4)
, result_index(4)
{
srand(seed);
for (int i = 0; i < 16; ++i)
xmm_state[i] = _mm_set_epi32(rand(), rand(), rand(), rand());
state[i] = _mm_set_epi32(rand(), rand(), rand(), rand());
}
inline RandomWELL512a_SSE2::RandomWELL512a_SSE2(unsigned *seed)
: index(0)
, resultIndex(4)
, result_index(4)
{
for (int i = 0; i < 16; ++i)
xmm_state[i] = _mm_set_epi32(seed[i + 48], seed[i + 32], seed[i + 16], seed[i]);
state[i] = _mm_set_epi32(seed[i + 48], seed[i + 32], seed[i + 16], seed[i]);
}
inline unsigned RandomWELL512a_SSE2::GetUnsigned()
{
if (resultIndex >= 4)
if (result_index >= 4)
{
GetUnsigned4(result);
resultIndex = 0;
result_index = 0;
}
return result[resultIndex++];
return result[result_index++];
}
inline double RandomWELL512a_SSE2::GetDouble()
@ -89,37 +89,37 @@ inline double RandomWELL512a_SSE2::GetDouble()
inline void RandomWELL512a_SSE2::GetUnsigned4(unsigned *result4)
{
unsigned index_15 = (index + 15) & 15;
__m128i state_index = xmm_state[index];
__m128i state_index_9 = xmm_state[(index + 9) & 15];
__m128i state_index_13 = xmm_state[(index + 13) & 15];
__m128i state_index_15 = xmm_state[index_15];
__m128i state_index = state[index];
__m128i state_index_9 = state[(index + 9) & 15];
__m128i state_index_13 = state[(index + 13) & 15];
__m128i state_index_15 = state[index_15];
const __m128i kMix = _mm_set1_epi32(0xda442d24);
__m128i left = _mm_xor_si128(state_index, _mm_slli_epi32(state_index, 16));
__m128i right = _mm_xor_si128(state_index_13, _mm_slli_epi32(state_index_13, 15));
__m128i z1 = _mm_xor_si128(left, right);
__m128i z2 = _mm_xor_si128(state_index_9, _mm_srli_epi32(state_index_9, 11));
__m128i left = _mm_xor_si128(state_index, _mm_slli_epi32(state_index, 16));
__m128i right = _mm_xor_si128(state_index_13, _mm_slli_epi32(state_index_13, 15));
__m128i z1 = _mm_xor_si128(left, right);
__m128i z2 = _mm_xor_si128(state_index_9, _mm_srli_epi32(state_index_9, 11));
__m128i result0 = _mm_xor_si128(z1, z2);
xmm_state[index] = result0;
state[index] = result0;
__m128i result1 = _mm_xor_si128(state_index_15, _mm_slli_epi32(state_index_15, 2));
result1 = _mm_xor_si128(result1, _mm_xor_si128(z1, _mm_slli_epi32(z1, 18)));
result1 = _mm_xor_si128(result1, _mm_slli_epi32(z2, 28));
result1 = _mm_xor_si128(result1, _mm_xor_si128(result0, _mm_and_si128(_mm_slli_epi32(result0, 5), kMix)));
index = index_15;
xmm_state[index] = result1;
result1 = _mm_xor_si128(result1, _mm_xor_si128(z1, _mm_slli_epi32(z1, 18)));
result1 = _mm_xor_si128(result1, _mm_slli_epi32(z2, 28));
result1 = _mm_xor_si128(result1, _mm_xor_si128(result0, _mm_and_si128(_mm_slli_epi32(result0, 5), kMix)));
index = index_15;
state[index] = result1;
_mm_storeu_si128((__m128i *)result4, result1);
}
inline void RandomWELL512a_SSE2::GetDouble4(double *result4)
{
unsigned unsignedResult[4];
GetUnsigned4(unsignedResult);
unsigned unsigned_result[4];
GetUnsigned4(unsigned_result);
const double kToFloat = 2.32830643653869628906e-10;
for (unsigned loop = 0; loop < 4; ++loop)
result4[loop] = unsignedResult[loop] * kToFloat;
result4[loop] = unsigned_result[loop] * kToFloat;
}
#endif // RANDOM_WELL512A_SSE2_H

View File

@ -99,24 +99,24 @@ void Test()
unsigned seed[4 * 16];
for (unsigned i = 0; i < 4 * 16; ++i)
seed[i] = rand();
RandomWELL512a randomWell0(seed + 0 * 16);
RandomWELL512a randomWell1(seed + 1 * 16);
RandomWELL512a randomWell2(seed + 2 * 16);
RandomWELL512a randomWell3(seed + 3 * 16);
RandomWELL512a random_well0(seed + 0 * 16);
RandomWELL512a random_well1(seed + 1 * 16);
RandomWELL512a random_well2(seed + 2 * 16);
RandomWELL512a random_well3(seed + 3 * 16);
RandomWELL512a_SSE2 randomWellSSE2(seed);
RandomWELL512a_SSE2 random_well_SSE2(seed);
for (unsigned i = 0; i < kNumIterations; i += 4)
{
result0[i + 0] = randomWell0.GetDouble();
result0[i + 1] = randomWell1.GetDouble();
result0[i + 2] = randomWell2.GetDouble();
result0[i + 3] = randomWell3.GetDouble();
result0[i + 0] = random_well0.GetDouble();
result0[i + 1] = random_well1.GetDouble();
result0[i + 2] = random_well2.GetDouble();
result0[i + 3] = random_well3.GetDouble();
result1[i + 0] = randomWellSSE2.GetDouble();
result1[i + 1] = randomWellSSE2.GetDouble();
result1[i + 2] = randomWellSSE2.GetDouble();
result1[i + 3] = randomWellSSE2.GetDouble();
result1[i + 0] = random_well_SSE2.GetDouble();
result1[i + 1] = random_well_SSE2.GetDouble();
result1[i + 2] = random_well_SSE2.GetDouble();
result1[i + 3] = random_well_SSE2.GetDouble();
}
if (memcmp(result0, result1, kNumIterations * sizeof(double)))