johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 1 | /* |
Jayanth Dodderi Chidanand | b3ffd3c | 2023-02-13 12:15:11 +0000 | [diff] [blame] | 2 | * Copyright (c) 2021-2023, ARM Limited and Contributors. All rights reserved. |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch.h> |
| 8 | #include <asm_macros.S> |
| 9 | #include <assert_macros.S> |
| 10 | |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 11 | .arch armv8-a+sve |
Arunachalam Ganapathy | 47b702c | 2023-06-06 13:31:46 +0100 | [diff] [blame] | 12 | .globl sme_rdsvl_1 |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 13 | .globl sme_try_illegal_instruction |
Jayanth Dodderi Chidanand | b3ffd3c | 2023-02-13 12:15:11 +0000 | [diff] [blame] | 14 | .globl sme_vector_to_ZA |
| 15 | .globl sme_ZA_to_vector |
| 16 | |
| 17 | |
| 18 | /* |
| 19 | * TODO: Due to the limitation with toolchain, SME intrinsics, still not being |
| 20 | * supported, instructions are manually encoded using the opcodes. |
| 21 | * Further, when the toolchain supports the requirements, these macros could |
| 22 | * be refactored. |
| 23 | */ |
| 24 | |
| 25 | |
| 26 | /* |
| 27 | * LDR (Loads a vector (an array of elements ) to ZA array ): |
| 28 | * LDR ZA[\nw, #\offset], [X\nxbase, #\offset, MUL VL] |
| 29 | * |
| 30 | * Arguments/Opcode bit field: |
| 31 | * nw : the vector select register W12-W15 |
| 32 | * nxbase : 64-bit name of the general-purpose base register. |
| 33 | * offset : vector select and optional memory offset. Default to 0. |
| 34 | */ |
| 35 | .macro _ldr_za nw, nxbase, offset=0 |
| 36 | .inst 0xe1000000 \ |
| 37 | | (((\nw) & 3) << 13) \ |
| 38 | | ((\nxbase) << 5) \ |
| 39 | | ((\offset) & 0xf) |
| 40 | .endm |
| 41 | |
| 42 | /* |
| 43 | * STR ( It stores an array of elements from ZA array to a vector ). |
| 44 | * STR ZA[\nw, #\offset], [X\nxbase, #\offset, MUL VL] |
| 45 | * |
| 46 | * Arguments/Opcode bit field: |
| 47 | * nw : the vector select register W12-W15 |
| 48 | * nxbase : 64-bit name of the general-purpose base register. |
| 49 | * offset : vector select and optional memory offset. Default to 0. |
| 50 | */ |
| 51 | .macro _str_za nw, nxbase, offset=0 |
| 52 | .inst 0xe1200000 \ |
| 53 | | (((\nw) & 3) << 13) \ |
| 54 | | ((\nxbase) << 5) \ |
| 55 | | ((\offset) & 0xf) |
| 56 | .endm |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 57 | |
| 58 | /* |
Arunachalam Ganapathy | 47b702c | 2023-06-06 13:31:46 +0100 | [diff] [blame] | 59 | * RDSVL - Read multiple of Streaming SVE vector register size to scalar register |
| 60 | * RDSVL <Xd>, #<imm> |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 61 | * |
Arunachalam Ganapathy | 47b702c | 2023-06-06 13:31:46 +0100 | [diff] [blame] | 62 | * Arguments/Opcode bit field: |
| 63 | * Xd : 64-bit name of the general-purpose base register. |
| 64 | * imm : signed immediate operand (imm6) |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 65 | */ |
Arunachalam Ganapathy | 47b702c | 2023-06-06 13:31:46 +0100 | [diff] [blame] | 66 | .macro _sme_rdsvl xd, imm |
| 67 | .inst 0x04bf5800 \ |
| 68 | | (((\imm) & 0x3f) << 5) \ |
| 69 | | (\xd) |
| 70 | .endm |
| 71 | |
| 72 | /* |
| 73 | * uint64_t sme_rdsvl_1(void); |
| 74 | * |
| 75 | * Run rdsvl instruction with imm #1. |
| 76 | */ |
| 77 | func sme_rdsvl_1 |
| 78 | _sme_rdsvl 0, 1 |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 79 | ret |
Arunachalam Ganapathy | 47b702c | 2023-06-06 13:31:46 +0100 | [diff] [blame] | 80 | endfunc sme_rdsvl_1 |
johpow01 | 50ccb55 | 2020-11-10 19:22:13 -0600 | [diff] [blame] | 81 | |
| 82 | /* |
| 83 | * void sme_try_illegal_instruction(void); |
| 84 | * |
| 85 | * This function tests that illegal instructions are allowed to run when |
| 86 | * FA64 is supported. RDFFR is explicitly stated to be illegal in the SME |
| 87 | * specification section F1.1.2 unless FA64 is supported and enabled. |
| 88 | */ |
| 89 | func sme_try_illegal_instruction |
| 90 | rdffr p0.b |
| 91 | ret |
| 92 | endfunc sme_try_illegal_instruction |
| 93 | |
Jayanth Dodderi Chidanand | b3ffd3c | 2023-02-13 12:15:11 +0000 | [diff] [blame] | 94 | |
| 95 | /** |
| 96 | * void sme_vector_to_ZA(uint64_t *input_vec) |
| 97 | * |
| 98 | * This function loads an vector of elements to an ZA Array storage |
| 99 | */ |
| 100 | func sme_vector_to_ZA |
| 101 | mov w12, wzr |
| 102 | _ldr_za 12, 0 // ZA.H[W12] loaded from [X0 / input_vector] |
| 103 | ret |
| 104 | endfunc sme_vector_to_ZA |
| 105 | |
| 106 | /** |
| 107 | * void sme_ZA_to_vector(uint64_t *out_vec) |
| 108 | * |
| 109 | * This function stores elements from ZA Array storage to an ZA vector |
| 110 | */ |
| 111 | func sme_ZA_to_vector |
| 112 | mov w12, wzr |
| 113 | _str_za 12, 0 // ZA.H[W12] stored to [X0 / out_vector] |
| 114 | ret |
| 115 | endfunc sme_ZA_to_vector |