mma.c 964 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include "utils.h"
  10. extern void test_mma(uint16_t (*)[8], uint16_t (*)[8], uint32_t (*)[4*4]);
  11. static int mma(void)
  12. {
  13. int i;
  14. int rc = 0;
  15. uint16_t x[] = {1, 0, 2, 0, 3, 0, 4, 0};
  16. uint16_t y[] = {1, 0, 2, 0, 3, 0, 4, 0};
  17. uint32_t z[4*4];
  18. uint32_t exp[4*4] = {1, 2, 3, 4,
  19. 2, 4, 6, 8,
  20. 3, 6, 9, 12,
  21. 4, 8, 12, 16};
  22. SKIP_IF_MSG(!have_hwcap2(PPC_FEATURE2_ARCH_3_1), "Need ISAv3.1");
  23. SKIP_IF_MSG(!have_hwcap2(PPC_FEATURE2_MMA), "Need MMA");
  24. test_mma(&x, &y, &z);
  25. for (i = 0; i < 16; i++) {
  26. printf("MMA[%d] = %d ", i, z[i]);
  27. if (z[i] == exp[i]) {
  28. printf(" (Correct)\n");
  29. } else {
  30. printf(" (Incorrect)\n");
  31. rc = 1;
  32. }
  33. }
  34. return rc;
  35. }
  36. int main(int argc, char *argv[])
  37. {
  38. return test_harness(mma, "mma");
  39. }