Unverified Commit c384c5d4 authored by Charlie Jenkins's avatar Charlie Jenkins Committed by Palmer Dabbelt
Browse files

selftests: riscv: Support xtheadvector in vector tests



Extend existing vector tests to be compatible with the xtheadvector
instructions.

Signed-off-by: default avatarCharlie Jenkins <charlie@rivosinc.com>
Tested-by: default avatarYangyu Chen <cyy@cyyself.name>
Link: https://lore.kernel.org/r/20241113-xtheadvector-v11-13-236c22791ef9@rivosinc.com


Signed-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
parent 57d7713a
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -18,6 +18,15 @@ int main(int argc, char **argv)
	unsigned long vl;
	int first = 1;

	if (argc > 2 && strcmp(argv[2], "x"))
		asm volatile (
			// 0 | zimm[10:0] | rs1 | 1 1 1 | rd |1010111| vsetvli
			// vsetvli	t4, x0, e8, m1, d1
			".4byte		0b00000000000000000111111011010111\n\t"
			"mv		%[vl], t4\n\t"
			: [vl] "=r" (vl) : : "t4"
		);
	else
		asm volatile (
			".option push\n\t"
			".option arch, +v\n\t"
+14 −3
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only

#include "../hwprobe/hwprobe.h"
#include <asm/vendor/thead.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

bool is_xtheadvector_supported(void)
{
	struct riscv_hwprobe pair;

	pair.key = RISCV_HWPROBE_KEY_VENDOR_EXT_THEAD_0;
	riscv_hwprobe(&pair, 1, 0, NULL, 0);
	return pair.value & RISCV_HWPROBE_VENDOR_EXT_XTHEADVECTOR;
}

bool is_vector_supported(void)
{
	struct riscv_hwprobe pair;
@@ -16,9 +26,9 @@ bool is_vector_supported(void)
	return pair.value & RISCV_HWPROBE_EXT_ZVE32X;
}

int launch_test(char *next_program, int test_inherit)
int launch_test(char *next_program, int test_inherit, int xtheadvector)
{
	char *exec_argv[3], *exec_envp[1];
	char *exec_argv[4], *exec_envp[1];
	int rc, pid, status;

	pid = fork();
@@ -30,7 +40,8 @@ int launch_test(char *next_program, int test_inherit)
	if (!pid) {
		exec_argv[0] = next_program;
		exec_argv[1] = test_inherit != 0 ? "x" : NULL;
		exec_argv[2] = NULL;
		exec_argv[2] = xtheadvector != 0 ? "x" : NULL;
		exec_argv[3] = NULL;
		exec_envp[0] = NULL;
		/* launch the program again to check inherit */
		rc = execve(next_program, exec_argv, exec_envp);
+3 −1
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-only */
#include <stdbool.h>

bool is_xtheadvector_supported(void);

bool is_vector_supported(void);

int launch_test(char *next_program, int test_inherit);
int launch_test(char *next_program, int test_inherit, int xtheadvector);
+9 −3
Original line number Diff line number Diff line
@@ -7,10 +7,16 @@

TEST(v_initval)
{
	if (!is_vector_supported())
	int xtheadvector = 0;

	if (!is_vector_supported()) {
		if (is_xtheadvector_supported())
			xtheadvector = 1;
		else
			SKIP(return, "Vector not supported");
	}

	ASSERT_EQ(0, launch_test(NEXT_PROGRAM, 0));
	ASSERT_EQ(0, launch_test(NEXT_PROGRAM, 0, xtheadvector));
}

TEST_HARNESS_MAIN
+13 −7
Original line number Diff line number Diff line
@@ -6,13 +6,16 @@

int main(int argc, char **argv)
{
	int rc, pid, status, test_inherit = 0;
	int rc, pid, status, test_inherit = 0, xtheadvector = 0;
	long ctrl, ctrl_c;
	char *exec_argv[2], *exec_envp[2];

	if (argc > 1)
	if (argc > 1 && strcmp(argv[1], "x"))
		test_inherit = 1;

	if (argc > 2 && strcmp(argv[2], "x"))
		xtheadvector = 1;

	ctrl = my_syscall1(__NR_prctl, PR_RISCV_V_GET_CONTROL);
	if (ctrl < 0) {
		puts("PR_RISCV_V_GET_CONTROL is not supported\n");
@@ -53,6 +56,9 @@ int main(int argc, char **argv)
				puts("child's vstate_ctrl not equal to parent's\n");
				exit(-1);
			}
			if (xtheadvector)
				asm volatile (".4byte	0x00007ed7");
			else
				asm volatile (".option push\n\t"
					".option arch, +v\n\t"
					"vsetvli x0, x0, e32, m8, ta, ma\n\t"
Loading