rewrote normal RNG function to workaround the bug in gcc 3.4 (ticket #449)

This commit is contained in:
Vadim Pisarevsky 2010-07-12 08:46:00 +00:00
parent 998cce4a2d
commit ba5eb93a53
2 changed files with 11 additions and 28 deletions

View File

@ -426,46 +426,29 @@ Randn_( Mat& _arr, uint64* state, const void* _param )
{ {
const int RAND_BUF_SIZE = 96; const int RAND_BUF_SIZE = 96;
float buffer[RAND_BUF_SIZE]; float buffer[RAND_BUF_SIZE];
int pidx[RAND_BUF_SIZE];
const PT* param = (const PT*)_param; const PT* param = (const PT*)_param;
Size size = getContinuousSize(_arr, _arr.channels()); Size size = getContinuousSize(_arr, _arr.channels());
int i, n = std::min(size.width, RAND_BUF_SIZE);
for( i = 0; i < 12; i++ )
pidx[i] = i;
for( ; i < n; i++ )
pidx[i] = pidx[i - 12];
for( int y = 0; y < size.height; y++ ) for( int y = 0; y < size.height; y++ )
{ {
T* arr = (T*)(_arr.data + _arr.step*y); T* arr = (T*)(_arr.data + _arr.step*y);
int i, j, len = RAND_BUF_SIZE; int len = RAND_BUF_SIZE;
for( i = 0; i < size.width; i += RAND_BUF_SIZE ) for( i = 0; i < size.width; i += RAND_BUF_SIZE )
{ {
int k = 3;
const PT* p = param;
if( i + len > size.width ) if( i + len > size.width )
len = size.width - i; len = size.width - i;
Randn_0_1_32f_C1R( buffer, len, state ); Randn_0_1_32f_C1R( buffer, len, state );
for( j = 0; j <= len - 4; j += 4 ) for( int j = 0; j < len; j++ )
{ arr[i+j] = saturate_cast<T>(buffer[j]*param[pidx[j]+12] + param[pidx[j]]);
PT f0, f1;
f0 = buffer[j]*p[j+12] + p[j];
f1 = buffer[j+1]*p[j+13] + p[j+1];
arr[i+j] = saturate_cast<T>(f0);
arr[i+j+1] = saturate_cast<T>(f1);
f0 = buffer[j+2]*p[j+14] + p[j+2];
f1 = buffer[j+3]*p[j+15] + p[j+3];
arr[i+j+2] = saturate_cast<T>(f0);
arr[i+j+3] = saturate_cast<T>(f1);
if( --k == 0 )
{
k = 3;
p -= 12;
}
}
for( ; j < len; j++ )
arr[i+j] = saturate_cast<T>(buffer[j]*p[j+12] + p[j]);
} }
} }
} }

View File

@ -340,4 +340,4 @@ void CV_RandTest::run( int )
} }
} }
//CV_RandTest rand_test; CV_RandTest rand_test;