| 1 | // |
| 2 | // SPDX-FileCopyrightText: Copyright 2024, 2026 Arm Limited and/or its affiliates <open-source-office@arm.com> |
| 3 | // |
| 4 | // SPDX-License-Identifier: Apache-2.0 |
| 5 | // |
| 6 | |
| 7 | #if !defined(__aarch64__) || !defined(__ARM_FEATURE_SVE) |
| 8 | #error This file must be compiled for AArch64, FEAT_SVE. |
| 9 | #else // Architectural features check. |
| 10 | |
| 11 | #include "test/common/sme.hpp" |
| 12 | |
| 13 | #include "test/common/cpu_info.hpp" |
| 14 | |
| 15 | namespace kai::test { |
| 16 | |
| 17 | template <> |
| 18 | uint64_t get_sme_vector_length<1>() { |
| 19 | static uint64_t res = 0; |
| 20 | |
| 21 | if (res == 0) { |
| 22 | if (cpu_has_sme()) { |
| 23 | __asm__ __volatile__( |
| 24 | ".inst 0xd503477f // SMSTART ZA\n" |
| 25 | "cntb %0\n" |
| 26 | ".inst 0xd503467f // SMSTOP\n" |
| 27 | : "=r"(res) |
| 28 | : |
| 29 | : "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", |
| 30 | "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", "z24", "z25", "z26", "z27", "z28", "z29", |
| 31 | "z30", "z31"); |
| 32 | } else { |
| 33 | res = 1; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | return res; |
| 38 | } |
| 39 | |
| 40 | template <> |
| 41 | uint64_t get_sme_vector_length<2>() { |
| 42 | static uint64_t res = 0; |
| 43 | |
| 44 | if (res == 0) { |
| 45 | if (cpu_has_sme()) { |
| 46 | __asm__ __volatile__( |
| 47 | ".inst 0xd503477f // SMSTART ZA\n" |
| 48 | "cnth %0\n" |
| 49 | ".inst 0xd503467f // SMSTOP\n" |
| 50 | : "=r"(res) |
| 51 | : |
| 52 | : "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", |
| 53 | "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", "z24", "z25", "z26", "z27", "z28", "z29", |
| 54 | "z30", "z31"); |
| 55 | } else { |
| 56 | res = 1; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | return res; |
| 61 | } |
| 62 | |
| 63 | template <> |
| 64 | uint64_t get_sme_vector_length<4>() { |
| 65 | static uint64_t res = 0; |
| 66 | |
| 67 | if (res == 0) { |
| 68 | if (cpu_has_sme()) { |
| 69 | __asm__ __volatile__( |
| 70 | ".inst 0xd503477f // SMSTART ZA\n" |
| 71 | "cntw %0\n" |
| 72 | ".inst 0xd503467f // SMSTOP\n" |
| 73 | : "=r"(res) |
| 74 | : |
| 75 | : "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", |
| 76 | "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", "z24", "z25", "z26", "z27", "z28", "z29", |
| 77 | "z30", "z31"); |
| 78 | } else { |
| 79 | res = 1; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | return res; |
| 84 | } |
| 85 | |
| 86 | uint64_t get_sme_vector_scale() { |
| 87 | static constexpr uint64_t VSCALE_UNIT_BYTES = 16; |
| 88 | return get_sme_vector_length<uint8_t>() / VSCALE_UNIT_BYTES; |
| 89 | } |
| 90 | } // namespace kai::test |
| 91 | |
| 92 | #endif // Architectural features check. |