Skip to content

Commit 9edd295

Browse files
SgrrZhfcarlescufi
authored andcommitted
tests: kernel: fpu_sharing: Add double type support
Use double type when FPU supports double precision. Signed-off-by: Huifeng Zhang <[email protected]>
1 parent 1cec85d commit 9edd295

File tree

1 file changed

+16
-0
lines changed
  • tests/kernel/fpu_sharing/generic/src

1 file changed

+16
-0
lines changed

tests/kernel/fpu_sharing/generic/src/pi.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040
* PI_NUM_ITERATIONS: This macro is defined in the project's Makefile and
4141
* is configurable from the command line.
4242
*/
43+
#ifdef CONFIG_CPU_HAS_FPU_DOUBLE_PRECISION
44+
static double reference_pi = 0.0f;
45+
#else
4346
static float reference_pi = 0.0f;
47+
#endif
4448

4549
/*
4650
* Test counters are "volatile" because GCC wasn't properly updating
@@ -64,9 +68,15 @@ static K_SEM_DEFINE(test_exit_sem, 0, 1);
6468
*/
6569
static void calculate_pi_low(void)
6670
{
71+
#ifdef CONFIG_CPU_HAS_FPU_DOUBLE_PRECISION
72+
volatile double pi; /* volatile to avoid optimizing out of loop */
73+
double divisor = 3.0f;
74+
double sign = -1.0f;
75+
#else
6776
volatile float pi; /* volatile to avoid optimizing out of loop */
6877
float divisor = 3.0f;
6978
float sign = -1.0f;
79+
#endif
7080
unsigned int ix;
7181

7282
/* Loop until the test finishes, or an error is detected. */
@@ -103,9 +113,15 @@ static void calculate_pi_low(void)
103113
*/
104114
static void calculate_pi_high(void)
105115
{
116+
#ifdef CONFIG_CPU_HAS_FPU_DOUBLE_PRECISION
117+
volatile double pi; /* volatile to avoid optimizing out of loop */
118+
double divisor = 3.0f;
119+
double sign = -1.0f;
120+
#else
106121
volatile float pi; /* volatile to avoid optimizing out of loop */
107122
float divisor = 3.0f;
108123
float sign = -1.0f;
124+
#endif
109125
unsigned int ix;
110126

111127
/* Run the test until the specified maximum test count is reached */

0 commit comments

Comments
 (0)