Reduce scope of variables (#1228)

Make variables local to loops, with appropriate types. These variables
are not read after the loop without being reset first, so this patch
doesn't change behaviour.

These variables should now be used for one purpose only, making it
easier to reason about the code. This will make future refactoring
easier.

Signed-off-by: Marco Antognini <marco.antognini@arm.com>
This commit is contained in:
Marco Antognini
2021-04-28 09:30:51 +01:00
committed by GitHub
parent cba7a8a537
commit 01497c402e
26 changed files with 420 additions and 471 deletions

View File

@@ -208,8 +208,6 @@ static const size_t specialValuesCount =
int TestFunc_Double_Double_Double_Double(const Func *f, MTdata d,
bool relaxedMode)
{
uint64_t i;
uint32_t j, k;
int error;
cl_program programs[VECTOR_SIZE_COUNT];
cl_kernel kernels[VECTOR_SIZE_COUNT];
@@ -234,22 +232,23 @@ int TestFunc_Double_Double_Double_Double(const Func *f, MTdata d,
return error;
}
for (i = 0; i < (1ULL << 32); i += step)
for (uint64_t i = 0; i < (1ULL << 32); i += step)
{
// Init input array
double *p = (double *)gIn;
double *p2 = (double *)gIn2;
double *p3 = (double *)gIn3;
j = 0;
size_t idx = 0;
if (i == 0)
{ // test edge cases
uint32_t x, y, z;
x = y = z = 0;
for (; j < BUFFER_SIZE / sizeof(double); j++)
for (; idx < BUFFER_SIZE / sizeof(double); idx++)
{
p[j] = specialValues[x];
p2[j] = specialValues[y];
p3[j] = specialValues[z];
p[idx] = specialValues[x];
p2[idx] = specialValues[y];
p3[idx] = specialValues[z];
if (++x >= specialValuesCount)
{
x = 0;
@@ -260,15 +259,15 @@ int TestFunc_Double_Double_Double_Double(const Func *f, MTdata d,
}
}
}
if (j == BUFFER_SIZE / sizeof(double))
if (idx == BUFFER_SIZE / sizeof(double))
vlog_error("Test Error: not all special cases tested!\n");
}
for (; j < BUFFER_SIZE / sizeof(double); j++)
for (; idx < BUFFER_SIZE / sizeof(double); idx++)
{
p[j] = DoubleFromUInt32(genrand_int32(d));
p2[j] = DoubleFromUInt32(genrand_int32(d));
p3[j] = DoubleFromUInt32(genrand_int32(d));
p[idx] = DoubleFromUInt32(genrand_int32(d));
p2[idx] = DoubleFromUInt32(genrand_int32(d));
p3[idx] = DoubleFromUInt32(genrand_int32(d));
}
if ((error = clEnqueueWriteBuffer(gQueue, gInBuffer, CL_FALSE, 0,
@@ -293,7 +292,7 @@ int TestFunc_Double_Double_Double_Double(const Func *f, MTdata d,
}
// write garbage into output arrays
for (j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
{
uint32_t pattern = 0xffffdead;
memset_pattern4(gOut[j], &pattern, BUFFER_SIZE);
@@ -308,7 +307,7 @@ int TestFunc_Double_Double_Double_Double(const Func *f, MTdata d,
}
// Run the kernels
for (j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
{
size_t vectorSize = sizeof(cl_double) * sizeValues[j];
size_t localCount = (BUFFER_SIZE + vectorSize - 1)
@@ -355,11 +354,11 @@ int TestFunc_Double_Double_Double_Double(const Func *f, MTdata d,
double *s = (double *)gIn;
double *s2 = (double *)gIn2;
double *s3 = (double *)gIn3;
for (j = 0; j < BUFFER_SIZE / sizeof(double); j++)
for (size_t j = 0; j < BUFFER_SIZE / sizeof(double); j++)
r[j] = (double)f->dfunc.f_fff(s[j], s2[j], s3[j]);
// Read the data back
for (j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
{
if ((error =
clEnqueueReadBuffer(gQueue, gOutBuffer[j], CL_TRUE, 0,
@@ -374,9 +373,9 @@ int TestFunc_Double_Double_Double_Double(const Func *f, MTdata d,
// Verify data
uint64_t *t = (uint64_t *)gOut_Ref;
for (j = 0; j < BUFFER_SIZE / sizeof(double); j++)
for (size_t j = 0; j < BUFFER_SIZE / sizeof(double); j++)
{
for (k = gMinVectorSizeIndex; k < gMaxVectorSizeIndex; k++)
for (auto k = gMinVectorSizeIndex; k < gMaxVectorSizeIndex; k++)
{
uint64_t *q = (uint64_t *)(gOut[k]);
@@ -731,7 +730,7 @@ int TestFunc_Double_Double_Double_Double(const Func *f, MTdata d,
exit:
// Release
for (k = gMinVectorSizeIndex; k < gMaxVectorSizeIndex; k++)
for (auto k = gMinVectorSizeIndex; k < gMaxVectorSizeIndex; k++)
{
clReleaseKernel(kernels[k]);
clReleaseProgram(programs[k]);