Skip to content

Commit 79ba5c1

Browse files
IEncinas10Alexandre Ghiti
authored andcommitted
selftests: riscv: fix v_exec_initval_nolibc.c
Vector registers are zero initialized by the kernel. Stop accepting "all ones" as a clean value. Note that this was not working as expected given that value == 0xff can be assumed to be always false by the compiler as value's range is [-128, 127]. Both GCC (-Wtype-limits) and clang (-Wtautological-constant-out-of-range-compare) warn about this. Reviewed-by: Charlie Jenkins <charlie@rivosinc.com> Tested-by: Charlie Jenkins <charlie@rivosinc.com> Signed-off-by: Ignacio Encinas <ignacio@iencinas.com> Link: https://lore.kernel.org/r/20250306-fix-v_exec_initval_nolibc-v2-1-97f9dc8a7faf@iencinas.com Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
1 parent 83d78ac commit 79ba5c1

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

tools/testing/selftests/riscv/vector/v_exec_initval_nolibc.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66
* the values. To further ensure consistency, this file is compiled without
77
* libc and without auto-vectorization.
88
*
9-
* To be "clean" all values must be either all ones or all zeroes.
9+
* To be "clean" all values must be all zeroes.
1010
*/
1111

1212
#define __stringify_1(x...) #x
1313
#define __stringify(x...) __stringify_1(x)
1414

1515
int main(int argc, char **argv)
1616
{
17-
char prev_value = 0, value;
17+
char value = 0;
1818
unsigned long vl;
19-
int first = 1;
2019

2120
if (argc > 2 && strcmp(argv[2], "x"))
2221
asm volatile (
@@ -44,14 +43,11 @@ int main(int argc, char **argv)
4443
"vsrl.vi " __stringify(register) ", " __stringify(register) ", 8\n\t" \
4544
".option pop\n\t" \
4645
: "=r" (value)); \
47-
if (first) { \
48-
first = 0; \
49-
} else if (value != prev_value || !(value == 0x00 || value == 0xff)) { \
46+
if (value != 0x00) { \
5047
printf("Register " __stringify(register) \
5148
" values not clean! value: %u\n", value); \
5249
exit(-1); \
5350
} \
54-
prev_value = value; \
5551
} \
5652
})
5753

0 commit comments

Comments
 (0)