tests: kernel: fpu_sharing: fix double-promotions
Double promotion warnings are generated with the flag -Wdouble-promotion Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
This commit is contained in:
parent
2e4e992644
commit
9ce16f8465
1 changed files with 32 additions and 40 deletions
|
@ -36,15 +36,19 @@
|
|||
#include "float_context.h"
|
||||
#include "test_common.h"
|
||||
|
||||
#ifdef CONFIG_CPU_HAS_FPU_DOUBLE_PRECISION
|
||||
#define FP_TYPE double
|
||||
#define FP_CONSTANT(x) x
|
||||
#else
|
||||
#define FP_TYPE float
|
||||
#define FP_CONSTANT(x) x##f
|
||||
#endif
|
||||
|
||||
/*
|
||||
* PI_NUM_ITERATIONS: This macro is defined in the project's Makefile and
|
||||
* is configurable from the command line.
|
||||
*/
|
||||
#ifdef CONFIG_CPU_HAS_FPU_DOUBLE_PRECISION
|
||||
static double reference_pi = 0.0f;
|
||||
#else
|
||||
static float reference_pi = 0.0f;
|
||||
#endif
|
||||
static FP_TYPE reference_pi = FP_CONSTANT(0.0);
|
||||
|
||||
/*
|
||||
* Test counters are "volatile" because GCC wasn't properly updating
|
||||
|
@ -68,37 +72,31 @@ static K_SEM_DEFINE(test_exit_sem, 0, 1);
|
|||
*/
|
||||
static void calculate_pi_low(void)
|
||||
{
|
||||
#ifdef CONFIG_CPU_HAS_FPU_DOUBLE_PRECISION
|
||||
volatile double pi; /* volatile to avoid optimizing out of loop */
|
||||
double divisor = 3.0f;
|
||||
double sign = -1.0f;
|
||||
#else
|
||||
volatile float pi; /* volatile to avoid optimizing out of loop */
|
||||
float divisor = 3.0f;
|
||||
float sign = -1.0f;
|
||||
#endif
|
||||
volatile FP_TYPE pi; /* volatile to avoid optimizing out of loop */
|
||||
FP_TYPE divisor = FP_CONSTANT(3.0);
|
||||
FP_TYPE sign = FP_CONSTANT(-1.0);
|
||||
unsigned int ix;
|
||||
|
||||
/* Loop until the test finishes, or an error is detected. */
|
||||
for (calc_pi_low_count = 0; !test_exited; calc_pi_low_count++) {
|
||||
|
||||
sign = -1.0f;
|
||||
pi = 1.0f;
|
||||
divisor = 3.0f;
|
||||
sign = FP_CONSTANT(-1.0);
|
||||
pi = FP_CONSTANT(1.0);
|
||||
divisor = FP_CONSTANT(3.0);
|
||||
|
||||
for (ix = 0; ix < PI_NUM_ITERATIONS; ix++) {
|
||||
pi += sign / divisor;
|
||||
divisor += 2.0f;
|
||||
sign *= -1.0f;
|
||||
divisor += FP_CONSTANT(2.0);
|
||||
sign *= FP_CONSTANT(-1.0);
|
||||
}
|
||||
|
||||
pi *= 4.0f;
|
||||
pi *= FP_CONSTANT(4.0);
|
||||
|
||||
if (reference_pi == 0.0f) {
|
||||
if (reference_pi == FP_CONSTANT(0.0)) {
|
||||
reference_pi = pi;
|
||||
} else if (reference_pi != pi) {
|
||||
printf("Computed pi %1.6f, reference pi %1.6f\n",
|
||||
pi, reference_pi);
|
||||
(double)pi, (double)reference_pi);
|
||||
}
|
||||
|
||||
zassert_equal(reference_pi, pi,
|
||||
|
@ -113,15 +111,9 @@ static void calculate_pi_low(void)
|
|||
*/
|
||||
static void calculate_pi_high(void)
|
||||
{
|
||||
#ifdef CONFIG_CPU_HAS_FPU_DOUBLE_PRECISION
|
||||
volatile double pi; /* volatile to avoid optimizing out of loop */
|
||||
double divisor = 3.0f;
|
||||
double sign = -1.0f;
|
||||
#else
|
||||
volatile float pi; /* volatile to avoid optimizing out of loop */
|
||||
float divisor = 3.0f;
|
||||
float sign = -1.0f;
|
||||
#endif
|
||||
volatile FP_TYPE pi; /* volatile to avoid optimizing out of loop */
|
||||
FP_TYPE divisor = FP_CONSTANT(3.0);
|
||||
FP_TYPE sign = FP_CONSTANT(-1.0);
|
||||
unsigned int ix;
|
||||
|
||||
/* Run the test until the specified maximum test count is reached */
|
||||
|
@ -129,14 +121,14 @@ static void calculate_pi_high(void)
|
|||
calc_pi_high_count <= MAX_TESTS;
|
||||
calc_pi_high_count++) {
|
||||
|
||||
sign = -1.0f;
|
||||
pi = 1.0f;
|
||||
divisor = 3.0f;
|
||||
sign = FP_CONSTANT(-1.0);
|
||||
pi = FP_CONSTANT(1.0);
|
||||
divisor = FP_CONSTANT(3.0);
|
||||
|
||||
for (ix = 0; ix < PI_NUM_ITERATIONS; ix++) {
|
||||
pi += sign / divisor;
|
||||
divisor += 2.0f;
|
||||
sign *= -1.0f;
|
||||
divisor += FP_CONSTANT(2.0);
|
||||
sign *= FP_CONSTANT(-1.0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -151,13 +143,13 @@ static void calculate_pi_high(void)
|
|||
*/
|
||||
k_sleep(K_MSEC(10));
|
||||
|
||||
pi *= 4.0f;
|
||||
pi *= FP_CONSTANT(4.0);
|
||||
|
||||
if (reference_pi == 0.0f) {
|
||||
if (reference_pi == FP_CONSTANT(0.0)) {
|
||||
reference_pi = pi;
|
||||
} else if (reference_pi != pi) {
|
||||
printf("Computed pi %1.6f, reference pi %1.6f\n",
|
||||
pi, reference_pi);
|
||||
(double)pi, (double)reference_pi);
|
||||
}
|
||||
|
||||
zassert_equal(reference_pi, pi,
|
||||
|
@ -167,7 +159,7 @@ static void calculate_pi_high(void)
|
|||
if ((calc_pi_high_count % 100) == 50) {
|
||||
printf("Pi calculation OK after %u (high) +"
|
||||
" %u (low) tests (computed %1.6lf)\n",
|
||||
calc_pi_high_count, calc_pi_low_count, pi);
|
||||
calc_pi_high_count, calc_pi_low_count, (double)pi);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue