Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/powerpc: Add matrix multiply assist (MMA) test

Adds a simple test of some basic matrix multiply assist (MMA)
instructions.

Signed-off-by: Alistair Popple <alistair@popple.id.au>
Tested-by: Joel Stanley <joel@jms.id.au>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200622021832.15870-1-alistair@popple.id.au

authored by

Alistair Popple and committed by
Michael Ellerman
3527e1ab 40a75584

+89 -1
+5
tools/testing/selftests/powerpc/include/utils.h
··· 135 135 #define PPC_FEATURE2_ARCH_3_1 0x00040000 136 136 #endif 137 137 138 + /* POWER10 features */ 139 + #ifndef PPC_FEATURE2_MMA 140 + #define PPC_FEATURE2_MMA 0x00020000 141 + #endif 142 + 138 143 #if defined(__powerpc64__) 139 144 #define UCONTEXT_NIA(UC) (UC)->uc_mcontext.gp_regs[PT_NIP] 140 145 #define UCONTEXT_MSR(UC) (UC)->uc_mcontext.gp_regs[PT_MSR]
+3 -1
tools/testing/selftests/powerpc/math/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - TEST_GEN_PROGS := fpu_syscall fpu_preempt fpu_signal fpu_denormal vmx_syscall vmx_preempt vmx_signal vsx_preempt 2 + TEST_GEN_PROGS := fpu_syscall fpu_preempt fpu_signal fpu_denormal vmx_syscall vmx_preempt vmx_signal vsx_preempt mma 3 3 4 4 top_srcdir = ../../../../.. 5 5 include ../../lib.mk ··· 17 17 18 18 $(OUTPUT)/vsx_preempt: CFLAGS += -mvsx 19 19 $(OUTPUT)/vsx_preempt: vsx_asm.S ../utils.c 20 + 21 + $(OUTPUT)/mma: mma.c mma.S ../utils.c
+33
tools/testing/selftests/powerpc/math/mma.S
··· 1 + /* SPDX-License-Identifier: GPL-2.0-or-later 2 + * 3 + * Test basic matrix multiply assist (MMA) functionality if available. 4 + * 5 + * Copyright 2020, Alistair Popple, IBM Corp. 6 + */ 7 + .global test_mma 8 + test_mma: 9 + /* Load accumulator via VSX registers from image passed in r3 */ 10 + lxvh8x 4,0,3 11 + lxvh8x 5,0,4 12 + 13 + /* Clear and prime the accumulator (xxsetaccz) */ 14 + .long 0x7c030162 15 + 16 + /* Prime the accumulator with MMA VSX move to accumulator 17 + * X-form (xxmtacc) (not needed due to above zeroing) */ 18 + //.long 0x7c010162 19 + 20 + /* xvi16ger2s */ 21 + .long 0xec042958 22 + 23 + /* Store result in image passed in r5 */ 24 + stxvw4x 0,0,5 25 + addi 5,5,16 26 + stxvw4x 1,0,5 27 + addi 5,5,16 28 + stxvw4x 2,0,5 29 + addi 5,5,16 30 + stxvw4x 3,0,5 31 + addi 5,5,16 32 + 33 + blr
+48
tools/testing/selftests/powerpc/math/mma.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * Test basic matrix multiply assist (MMA) functionality if available. 4 + * 5 + * Copyright 2020, Alistair Popple, IBM Corp. 6 + */ 7 + #include <stdio.h> 8 + #include <stdint.h> 9 + 10 + #include "utils.h" 11 + 12 + extern void test_mma(uint16_t (*)[8], uint16_t (*)[8], uint32_t (*)[4*4]); 13 + 14 + static int mma(void) 15 + { 16 + int i; 17 + int rc = 0; 18 + uint16_t x[] = {1, 0, 2, 0, 3, 0, 4, 0}; 19 + uint16_t y[] = {1, 0, 2, 0, 3, 0, 4, 0}; 20 + uint32_t z[4*4]; 21 + uint32_t exp[4*4] = {1, 2, 3, 4, 22 + 2, 4, 6, 8, 23 + 3, 6, 9, 12, 24 + 4, 8, 12, 16}; 25 + 26 + SKIP_IF_MSG(!have_hwcap2(PPC_FEATURE2_ARCH_3_1), "Need ISAv3.1"); 27 + SKIP_IF_MSG(!have_hwcap2(PPC_FEATURE2_MMA), "Need MMA"); 28 + 29 + test_mma(&x, &y, &z); 30 + 31 + for (i = 0; i < 16; i++) { 32 + printf("MMA[%d] = %d ", i, z[i]); 33 + 34 + if (z[i] == exp[i]) { 35 + printf(" (Correct)\n"); 36 + } else { 37 + printf(" (Incorrect)\n"); 38 + rc = 1; 39 + } 40 + } 41 + 42 + return rc; 43 + } 44 + 45 + int main(int argc, char *argv[]) 46 + { 47 + return test_harness(mma, "mma"); 48 + }