Skip to content

Commit 2ba107f

Browse files
committed
selftests/powerpc: Generate better bit patterns for FPU tests
The fpu_preempt test randomly initialises an array of doubles to try and detect FPU register corruption. However the values it generates do not occupy the full range of values possible in the 64-bit double, meaning some partial register corruption could go undetected. Without getting too carried away, add some better initialisation to generate values that occupy more bits. Sample values before: f0 902677510 (raw 0x41cae6e203000000) f1 325217596 (raw 0x41b3626d3c000000) f2 1856578300 (raw 0x41dbaa48bf000000) f3 1247189984 (raw 0x41d295a6f8000000) And after: f0 1.1078153481413311e-09 (raw 0x3e13083932805cc2) f1 1.0576648474801922e+17 (raw 0x43777c20eb88c261) f2 -6.6245033413594075e-10 (raw 0xbe06c2f989facae9) f3 3.0085988827156291e+18 (raw 0x43c4e0585f2df37b) Signed-off-by: Michael Ellerman <[email protected]> Link: https://msgid.link/[email protected]
1 parent e5d00aa commit 2ba107f

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/*
3+
* Copyright 2023, Michael Ellerman, IBM Corporation.
4+
*/
5+
6+
#ifndef _SELFTESTS_POWERPC_FPU_H
7+
#define _SELFTESTS_POWERPC_FPU_H
8+
9+
static inline void randomise_darray(double *darray, int num)
10+
{
11+
long val;
12+
13+
for (int i = 0; i < num; i++) {
14+
val = random();
15+
if (val & 1)
16+
val *= -1;
17+
18+
if (val & 2)
19+
darray[i] = 1.0 / val;
20+
else
21+
darray[i] = val * val;
22+
}
23+
}
24+
25+
#endif /* _SELFTESTS_POWERPC_FPU_H */

tools/testing/selftests/powerpc/math/fpu_preempt.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <pthread.h>
2020

2121
#include "utils.h"
22+
#include "fpu.h"
2223

2324
/* Time to wait for workers to get preempted (seconds) */
2425
#define PREEMPT_TIME 20
@@ -39,12 +40,9 @@ extern int preempt_fpu(double *darray, int *threads_starting, int *running);
3940
void *preempt_fpu_c(void *p)
4041
{
4142
long rc;
42-
int i;
4343

4444
srand(pthread_self());
45-
for (i = 0; i < ARRAY_SIZE(darray); i++)
46-
darray[i] = rand();
47-
45+
randomise_darray(darray, ARRAY_SIZE(darray));
4846
rc = preempt_fpu(darray, &threads_starting, &running);
4947

5048
return (void *)rc;

0 commit comments

Comments
 (0)