Improve MTdataHolder design and use it in math_brute_force (#1490)

Improve the design of the MTdataHolder wrapper:

 * Make it a class instead of a struct with a private member, to make
   it clearer that there is no direct access to the MTdata member.

 * Make the 1-arg constructor `explicit` to avoid unintended
   conversions.

 * Forbid copy construction/assignment as MTdataHolder is never
   initialised from an MTdataHolder object in the codebase.

 * Define move construction/assignment as per the "rule of five".

Use the MTdataHolder class throughout math_brute_force, to simplify
code by avoiding manual resource management.

Original patch by Marco Antognini.

Signed-off-by: Marco Antognini <marco.antognini@arm.com>
Signed-off-by: Sven van Haastregt <sven.vanhaastregt@arm.com>

Signed-off-by: Marco Antognini <marco.antognini@arm.com>
Signed-off-by: Sven van Haastregt <sven.vanhaastregt@arm.com>
This commit is contained in:
Sven van Haastregt
2022-09-20 16:52:22 +01:00
committed by GitHub
parent a87e686757
commit 8f9c1960ff
14 changed files with 56 additions and 79 deletions

View File

@@ -98,7 +98,7 @@ cl_mem gInBuffer2 = NULL;
cl_mem gInBuffer3 = NULL;
cl_mem gOutBuffer[VECTOR_SIZE_COUNT] = { NULL, NULL, NULL, NULL, NULL, NULL };
cl_mem gOutBuffer2[VECTOR_SIZE_COUNT] = { NULL, NULL, NULL, NULL, NULL, NULL };
static MTdata gMTdata;
static MTdataHolder gMTdata;
cl_device_fp_config gFloatCapabilities = 0;
int gWimpyReductionFactor = 32;
int gVerboseBruteForce = 0;
@@ -326,7 +326,7 @@ int main(int argc, const char *argv[])
vlog("\n-------------------------------------------------------------------"
"----------------------------------------\n");
gMTdata = init_genrand(gRandomSeed);
gMTdata = MTdataHolder(gRandomSeed);
FPU_mode_type oldMode;
DisableFTZ(&oldMode);
@@ -336,8 +336,6 @@ int main(int argc, const char *argv[])
RestoreFPState(&oldMode);
free_mtdata(gMTdata);
if (gQueue)
{
int error_code = clFinish(gQueue);