Reformat test harness code (#940)

* Reformat common help text

Signed-off-by: Stuart Brady <stuart.brady@arm.com>

* Reformat test harness code

This goes part of the way to fixing issue #625.

Signed-off-by: Stuart Brady <stuart.brady@arm.com>
This commit is contained in:
Stuart Brady
2020-10-30 14:13:52 +00:00
committed by GitHub
parent 55976fad35
commit af7d914514
38 changed files with 7676 additions and 6692 deletions

View File

@@ -1,6 +1,6 @@
//
// Copyright (c) 2017 The Khronos Group Inc.
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
@@ -15,7 +15,7 @@
//
#include "compat.h"
#if defined ( _MSC_VER )
#if defined(_MSC_VER)
#include <limits.h>
#include <stdlib.h>
@@ -24,7 +24,7 @@
#include <windows.h>
#if _MSC_VER < 1900 && ! defined( __INTEL_COMPILER )
#if _MSC_VER < 1900 && !defined(__INTEL_COMPILER)
///////////////////////////////////////////////////////////////////
//
@@ -32,9 +32,12 @@
//
///////////////////////////////////////////////////////////////////
float copysignf( float x, float y )
float copysignf(float x, float y)
{
union{ cl_uint u; float f; }ux, uy;
union {
cl_uint u;
float f;
} ux, uy;
ux.f = x;
uy.f = y;
@@ -44,9 +47,12 @@ float copysignf( float x, float y )
return ux.f;
}
double copysign( double x, double y )
double copysign(double x, double y)
{
union{ cl_ulong u; double f; }ux, uy;
union {
cl_ulong u;
double f;
} ux, uy;
ux.f = x;
uy.f = y;
@@ -56,13 +62,16 @@ double copysign( double x, double y )
return ux.f;
}
long double copysignl( long double x, long double y )
long double copysignl(long double x, long double y)
{
union
{
union {
long double f;
struct{ cl_ulong m; cl_ushort sexp; }u;
}ux, uy;
struct
{
cl_ulong m;
cl_ushort sexp;
} u;
} ux, uy;
ux.f = x;
uy.f = y;
@@ -76,12 +85,12 @@ float rintf(float x)
{
float absx = fabsf(x);
if( absx < 8388608.0f /* 0x1.0p23f */ )
if (absx < 8388608.0f /* 0x1.0p23f */)
{
float magic = copysignf( 8388608.0f /* 0x1.0p23f */, x );
float magic = copysignf(8388608.0f /* 0x1.0p23f */, x);
float rounded = x + magic;
rounded -= magic;
x = copysignf( rounded, x );
x = copysignf(rounded, x);
}
return x;
@@ -91,12 +100,12 @@ double rint(double x)
{
double absx = fabs(x);
if( absx < 4503599627370496.0 /* 0x1.0p52f */ )
if (absx < 4503599627370496.0 /* 0x1.0p52f */)
{
double magic = copysign( 4503599627370496.0 /* 0x1.0p52 */, x );
double magic = copysign(4503599627370496.0 /* 0x1.0p52 */, x);
double rounded = x + magic;
rounded -= magic;
x = copysign( rounded, x );
x = copysign(rounded, x);
}
return x;
@@ -106,12 +115,13 @@ long double rintl(long double x)
{
double absx = fabs(x);
if( absx < 9223372036854775808.0L /* 0x1.0p64f */ )
if (absx < 9223372036854775808.0L /* 0x1.0p64f */)
{
long double magic = copysignl( 9223372036854775808.0L /* 0x1.0p63L */, x );
long double magic =
copysignl(9223372036854775808.0L /* 0x1.0p63L */, x);
long double rounded = x + magic;
rounded -= magic;
x = copysignl( rounded, x );
x = copysignl(rounded, x);
}
return x;
@@ -125,30 +135,31 @@ long double rintl(long double x)
//
///////////////////////////////////////////////////////////////////
#ifndef FP_ILOGB0
#define FP_ILOGB0 INT_MIN
#define FP_ILOGB0 INT_MIN
#endif
#ifndef FP_ILOGBNAN
#define FP_ILOGBNAN INT_MIN
#define FP_ILOGBNAN INT_MIN
#endif
int ilogb (double x)
int ilogb(double x)
{
union{ double f; cl_ulong u;} u;
union {
double f;
cl_ulong u;
} u;
u.f = x;
cl_ulong absx = u.u & CL_LONG_MAX;
if( absx - 0x0001000000000000ULL >= 0x7ff0000000000000ULL - 0x0001000000000000ULL)
if (absx - 0x0001000000000000ULL
>= 0x7ff0000000000000ULL - 0x0001000000000000ULL)
{
switch( absx )
switch (absx)
{
case 0:
return FP_ILOGB0;
case 0x7ff0000000000000ULL:
return INT_MAX;
case 0: return FP_ILOGB0;
case 0x7ff0000000000000ULL: return INT_MAX;
default:
if( absx > 0x7ff0000000000000ULL )
return FP_ILOGBNAN;
if (absx > 0x7ff0000000000000ULL) return FP_ILOGBNAN;
// subnormal
u.u = absx | 0x3ff0000000000000ULL;
@@ -161,23 +172,23 @@ int ilogb (double x)
}
int ilogbf (float x)
int ilogbf(float x)
{
union{ float f; cl_uint u;} u;
union {
float f;
cl_uint u;
} u;
u.f = x;
cl_uint absx = u.u & 0x7fffffff;
if( absx - 0x00800000U >= 0x7f800000U - 0x00800000U)
if (absx - 0x00800000U >= 0x7f800000U - 0x00800000U)
{
switch( absx )
switch (absx)
{
case 0:
return FP_ILOGB0;
case 0x7f800000U:
return INT_MAX;
case 0: return FP_ILOGB0;
case 0x7f800000U: return INT_MAX;
default:
if( absx > 0x7f800000 )
return FP_ILOGBNAN;
if (absx > 0x7f800000) return FP_ILOGBNAN;
// subnormal
u.u = absx | 0x3f800000U;
@@ -189,32 +200,33 @@ int ilogbf (float x)
return (absx >> 23) - 127;
}
int ilogbl (long double x)
int ilogbl(long double x)
{
union
{
union {
long double f;
struct{ cl_ulong m; cl_ushort sexp; }u;
struct
{
cl_ulong m;
cl_ushort sexp;
} u;
} u;
u.f = x;
int exp = u.u.sexp & 0x7fff;
if( 0 == exp )
if (0 == exp)
{
if( 0 == u.u.m )
return FP_ILOGB0;
if (0 == u.u.m) return FP_ILOGB0;
//subnormal
// subnormal
u.u.sexp = 0x3fff;
u.f -= 1.0f;
exp = u.u.sexp & 0x7fff;
return exp - (0x3fff + 0x3ffe);
}
else if( 0x7fff == exp )
else if (0x7fff == exp)
{
if( u.u.m & CL_LONG_MAX )
return FP_ILOGBNAN;
if (u.u.m & CL_LONG_MAX) return FP_ILOGBNAN;
return INT_MAX;
}
@@ -232,7 +244,10 @@ int ilogbl (long double x)
static void GET_BITS_SP32(float fx, unsigned int* ux)
{
volatile union {float f; unsigned int u;} _bitsy;
volatile union {
float f;
unsigned int u;
} _bitsy;
_bitsy.f = (fx);
*ux = _bitsy.u;
}
@@ -244,7 +259,10 @@ static void GET_BITS_SP32(float fx, unsigned int* ux)
/* } */
static void PUT_BITS_SP32(unsigned int ux, float* fx)
{
volatile union {float f; unsigned int u;} _bitsy;
volatile union {
float f;
unsigned int u;
} _bitsy;
_bitsy.u = (ux);
*fx = _bitsy.f;
}
@@ -256,13 +274,19 @@ static void PUT_BITS_SP32(unsigned int ux, float* fx)
/* } */
static void GET_BITS_DP64(double dx, unsigned __int64* lx)
{
volatile union {double d; unsigned __int64 l;} _bitsy;
volatile union {
double d;
unsigned __int64 l;
} _bitsy;
_bitsy.d = (dx);
*lx = _bitsy.l;
}
static void PUT_BITS_DP64(unsigned __int64 lx, double* dx)
{
volatile union {double d; unsigned __int64 l;} _bitsy;
volatile union {
double d;
unsigned __int64 l;
} _bitsy;
_bitsy.l = (lx);
*dx = _bitsy.d;
}
@@ -287,8 +311,7 @@ int SIGNBIT_DP64(double x )
that x is NaN; gcc does. */
double fmax(double x, double y)
{
if( isnan(y) )
return x;
if (isnan(y)) return x;
return x >= y ? x : y;
}
@@ -301,17 +324,15 @@ double fmax(double x, double y)
double fmin(double x, double y)
{
if( isnan(y) )
return x;
if (isnan(y)) return x;
return x <= y ? x : y;
}
float fmaxf( float x, float y )
float fmaxf(float x, float y)
{
if( isnan(y) )
return x;
if (isnan(y)) return x;
return x >= y ? x : y;
}
@@ -323,31 +344,31 @@ float fmaxf( float x, float y )
float fminf(float x, float y)
{
if( isnan(y) )
return x;
if (isnan(y)) return x;
return x <= y ? x : y;
}
long double scalblnl(long double x, long n)
{
union
{
union {
long double d;
struct{ cl_ulong m; cl_ushort sexp;}u;
}u;
struct
{
cl_ulong m;
cl_ushort sexp;
} u;
} u;
u.u.m = CL_LONG_MIN;
if( x == 0.0L || n < -2200)
return copysignl( 0.0L, x );
if (x == 0.0L || n < -2200) return copysignl(0.0L, x);
if( n > 2200 )
return INFINITY;
if (n > 2200) return INFINITY;
if( n < 0 )
if (n < 0)
{
u.u.sexp = 0x3fff - 1022;
while( n <= -1022 )
while (n <= -1022)
{
x *= u.d;
n += 1022;
@@ -357,10 +378,10 @@ long double scalblnl(long double x, long n)
return x;
}
if( n > 0 )
if (n > 0)
{
u.u.sexp = 0x3fff + 1023;
while( n >= 1023 )
while (n >= 1023)
{
x *= u.d;
n -= 1023;
@@ -378,15 +399,12 @@ long double scalblnl(long double x, long n)
// log2
//
///////////////////////////////////////////////////////////////////
const static cl_double log_e_base2 = 1.4426950408889634074;
const static cl_double log_10_base2 = 3.3219280948873623478;
const static cl_double log_e_base2 = 1.4426950408889634074;
const static cl_double log_10_base2 = 3.3219280948873623478;
//double log10(double x);
// double log10(double x);
double log2(double x)
{
return 1.44269504088896340735992468100189214 * log(x);
}
double log2(double x) { return 1.44269504088896340735992468100189214 * log(x); }
long double log2l(long double x)
{
@@ -397,23 +415,23 @@ double trunc(double x)
{
double absx = fabs(x);
if( absx < 4503599627370496.0 /* 0x1.0p52f */ )
if (absx < 4503599627370496.0 /* 0x1.0p52f */)
{
cl_long rounded = x;
x = copysign( (double) rounded, x );
x = copysign((double)rounded, x);
}
return x;
}
float truncf(float x)
float truncf(float x)
{
float absx = fabsf(x);
if( absx < 8388608.0f /* 0x1.0p23f */ )
if (absx < 8388608.0f /* 0x1.0p23f */)
{
cl_int rounded = x;
x = copysignf( (float) rounded, x );
x = copysignf((float)rounded, x);
}
return x;
@@ -423,75 +441,69 @@ long lround(double x)
{
double absx = fabs(x);
if( absx < 0.5 )
return 0;
if (absx < 0.5) return 0;
if( absx < 4503599627370496.0 /* 0x1.0p52 */)
if (absx < 4503599627370496.0 /* 0x1.0p52 */)
{
absx += 0.5;
cl_long rounded = absx;
absx = rounded;
x = copysign( absx, x );
x = copysign(absx, x);
}
if( x >= (double) LONG_MAX )
return LONG_MAX;
if (x >= (double)LONG_MAX) return LONG_MAX;
return (long) x;
return (long)x;
}
long lroundf(float x)
{
float absx = fabsf(x);
if( absx < 0.5f )
return 0;
if (absx < 0.5f) return 0;
if( absx < 8388608.0f )
if (absx < 8388608.0f)
{
absx += 0.5f;
cl_int rounded = absx;
absx = rounded;
x = copysignf( absx, x );
x = copysignf(absx, x);
}
if( x >= (float) LONG_MAX )
return LONG_MAX;
if (x >= (float)LONG_MAX) return LONG_MAX;
return (long) x;
return (long)x;
}
double round(double x)
{
double absx = fabs(x);
if( absx < 0.5 )
return copysign( 0.0, x);
if (absx < 0.5) return copysign(0.0, x);
if( absx < 4503599627370496.0 /* 0x1.0p52 */)
if (absx < 4503599627370496.0 /* 0x1.0p52 */)
{
absx += 0.5;
cl_long rounded = absx;
absx = rounded;
x = copysign( absx, x );
x = copysign(absx, x);
}
return x;
}
float roundf(float x)
float roundf(float x)
{
float absx = fabsf(x);
if( absx < 0.5f )
return copysignf( 0.0f, x);
if (absx < 0.5f) return copysignf(0.0f, x);
if( absx < 8388608.0f )
if (absx < 8388608.0f)
{
absx += 0.5f;
cl_int rounded = absx;
absx = rounded;
x = copysignf( absx, x );
x = copysignf(absx, x);
}
return x;
@@ -501,65 +513,59 @@ long double roundl(long double x)
{
long double absx = fabsl(x);
if( absx < 0.5L )
return copysignl( 0.0L, x);
if (absx < 0.5L) return copysignl(0.0L, x);
if( absx < 9223372036854775808.0L /*0x1.0p63L*/ )
if (absx < 9223372036854775808.0L /*0x1.0p63L*/)
{
absx += 0.5L;
cl_ulong rounded = absx;
absx = rounded;
x = copysignl( absx, x );
x = copysignl(absx, x);
}
return x;
}
float cbrtf( float x )
float cbrtf(float x)
{
float z = pow( fabs((double) x), 1.0 / 3.0 );
return copysignf( z, x );
float z = pow(fabs((double)x), 1.0 / 3.0);
return copysignf(z, x);
}
double cbrt( double x )
{
return copysign( pow( fabs( x ), 1.0 / 3.0 ), x );
}
double cbrt(double x) { return copysign(pow(fabs(x), 1.0 / 3.0), x); }
long int lrint (double x)
long int lrint(double x)
{
double absx = fabs(x);
if( x >= (double) LONG_MAX )
return LONG_MAX;
if (x >= (double)LONG_MAX) return LONG_MAX;
if( absx < 4503599627370496.0 /* 0x1.0p52 */ )
if (absx < 4503599627370496.0 /* 0x1.0p52 */)
{
double magic = copysign( 4503599627370496.0 /* 0x1.0p52 */, x );
double magic = copysign(4503599627370496.0 /* 0x1.0p52 */, x);
double rounded = x + magic;
rounded -= magic;
return (long int) rounded;
return (long int)rounded;
}
return (long int) x;
return (long int)x;
}
long int lrintf (float x)
long int lrintf(float x)
{
float absx = fabsf(x);
if( x >= (float) LONG_MAX )
return LONG_MAX;
if (x >= (float)LONG_MAX) return LONG_MAX;
if( absx < 8388608.0f /* 0x1.0p23f */ )
if (absx < 8388608.0f /* 0x1.0p23f */)
{
float magic = copysignf( 8388608.0f /* 0x1.0p23f */, x );
float magic = copysignf(8388608.0f /* 0x1.0p23f */, x);
float rounded = x + magic;
rounded -= magic;
return (long int) rounded;
return (long int)rounded;
}
return (long int) x;
return (long int)x;
}
#endif // _MSC_VER < 1900
@@ -574,13 +580,12 @@ long int lrintf (float x)
int fetestexcept(int excepts)
{
unsigned int status = _statusfp();
return excepts & (
((status & _SW_INEXACT) ? FE_INEXACT : 0) |
((status & _SW_UNDERFLOW) ? FE_UNDERFLOW : 0) |
((status & _SW_OVERFLOW) ? FE_OVERFLOW : 0) |
((status & _SW_ZERODIVIDE) ? FE_DIVBYZERO : 0) |
((status & _SW_INVALID) ? FE_INVALID : 0)
);
return excepts
& (((status & _SW_INEXACT) ? FE_INEXACT : 0)
| ((status & _SW_UNDERFLOW) ? FE_UNDERFLOW : 0)
| ((status & _SW_OVERFLOW) ? FE_OVERFLOW : 0)
| ((status & _SW_ZERODIVIDE) ? FE_DIVBYZERO : 0)
| ((status & _SW_INVALID) ? FE_INVALID : 0));
}
int feclearexcept(int excepts)
@@ -592,33 +597,36 @@ int feclearexcept(int excepts)
#endif // __INTEL_COMPILER
#if _MSC_VER < 1900 && ( ! defined( __INTEL_COMPILER ) || __INTEL_COMPILER < 1300 )
#if _MSC_VER < 1900 && (!defined(__INTEL_COMPILER) || __INTEL_COMPILER < 1300)
float nanf( const char* str)
float nanf(const char* str)
{
cl_uint u = atoi( str );
cl_uint u = atoi(str);
u |= 0x7fc00000U;
return *( float*)(&u);
return *(float*)(&u);
}
double nan( const char* str)
double nan(const char* str)
{
cl_ulong u = atoi( str );
cl_ulong u = atoi(str);
u |= 0x7ff8000000000000ULL;
return *( double*)(&u);
return *(double*)(&u);
}
// double check this implementatation
long double nanl( const char* str)
long double nanl(const char* str)
{
union
{
union {
long double f;
struct { cl_ulong m; cl_ushort sexp; }u;
}u;
struct
{
cl_ulong m;
cl_ushort sexp;
} u;
} u;
u.u.sexp = 0x7fff;
u.u.m = 0x8000000000000000ULL | atoi( str );
u.u.m = 0x8000000000000000ULL | atoi(str);
return u.f;
}
@@ -632,32 +640,35 @@ long double nanl( const char* str)
///////////////////////////////////////////////////////////////////
/*
// This function is commented out because the Windows implementation should never call munmap.
// This function is commented out because the Windows implementation should
never call munmap.
// If it is calling it, we have a bug. Please file a bugzilla.
int munmap(void *addr, size_t len)
{
// FIXME: this is not correct. munmap is like free() http://www.opengroup.org/onlinepubs/7990989775/xsh/munmap.html
// FIXME: this is not correct. munmap is like free()
// http://www.opengroup.org/onlinepubs/7990989775/xsh/munmap.html
return (int)VirtualAlloc( (LPVOID)addr, len,
MEM_COMMIT|MEM_RESERVE, PAGE_NOACCESS );
}
*/
uint64_t ReadTime( void )
uint64_t ReadTime(void)
{
LARGE_INTEGER current;
QueryPerformanceCounter(&current);
return (uint64_t)current.QuadPart;
}
double SubtractTime( uint64_t endTime, uint64_t startTime )
double SubtractTime(uint64_t endTime, uint64_t startTime)
{
static double PerformanceFrequency = 0.0;
if (PerformanceFrequency == 0.0) {
if (PerformanceFrequency == 0.0)
{
LARGE_INTEGER frequency;
QueryPerformanceFrequency(&frequency);
PerformanceFrequency = (double) frequency.QuadPart;
PerformanceFrequency = (double)frequency.QuadPart;
}
return (double)(endTime - startTime) / PerformanceFrequency * 1e9;
@@ -665,40 +676,38 @@ double SubtractTime( uint64_t endTime, uint64_t startTime )
int cf_signbit(double x)
{
union
{
union {
double f;
cl_ulong u;
}u;
} u;
u.f = x;
return u.u >> 63;
}
int cf_signbitf(float x)
{
union
{
union {
float f;
cl_uint u;
}u;
} u;
u.f = x;
return u.u >> 31;
}
float int2float (int32_t ix)
float int2float(int32_t ix)
{
union {
float f;
float f;
int32_t i;
} u;
u.i = ix;
return u.f;
}
int32_t float2int (float fx)
int32_t float2int(float fx)
{
union {
float f;
float f;
int32_t i;
} u;
u.f = fx;
@@ -722,27 +731,50 @@ int __builtin_clz(unsigned int pattern)
return 31 - res;
#endif
unsigned long index;
unsigned char res = _BitScanReverse( &index, pattern);
if (res) {
return 8*sizeof(int) - 1 - index;
} else {
return 8*sizeof(int);
unsigned char res = _BitScanReverse(&index, pattern);
if (res)
{
return 8 * sizeof(int) - 1 - index;
}
else
{
return 8 * sizeof(int);
}
}
#else
int __builtin_clz(unsigned int pattern)
{
int count;
if (pattern == 0u) {
return 32;
}
count = 31;
if (pattern >= 1u<<16) { pattern >>= 16; count -= 16; }
if (pattern >= 1u<<8) { pattern >>= 8; count -= 8; }
if (pattern >= 1u<<4) { pattern >>= 4; count -= 4; }
if (pattern >= 1u<<2) { pattern >>= 2; count -= 2; }
if (pattern >= 1u<<1) { count -= 1; }
return count;
int count;
if (pattern == 0u)
{
return 32;
}
count = 31;
if (pattern >= 1u << 16)
{
pattern >>= 16;
count -= 16;
}
if (pattern >= 1u << 8)
{
pattern >>= 8;
count -= 8;
}
if (pattern >= 1u << 4)
{
pattern >>= 4;
count -= 4;
}
if (pattern >= 1u << 2)
{
pattern >>= 2;
count -= 2;
}
if (pattern >= 1u << 1)
{
count -= 1;
}
return count;
}
#endif // !defined(_WIN64)
@@ -756,9 +788,9 @@ int usleep(int usec)
return 0;
}
unsigned int sleep( unsigned int sec )
unsigned int sleep(unsigned int sec)
{
Sleep( sec * 1000 );
Sleep(sec * 1000);
return 0;
}