blob: af6c1b34be356f4a93d6a564feb122cdefeca384 [file] [log] [blame]
johpow0150ccb552020-11-10 19:22:13 -06001/*
Jayanth Dodderi Chidanandb3ffd3c2023-02-13 12:15:11 +00002 * Copyright (c) 2021-2023, ARM Limited and Contributors. All rights reserved.
johpow0150ccb552020-11-10 19:22:13 -06003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <asm_macros.S>
9#include <assert_macros.S>
10
johpow0150ccb552020-11-10 19:22:13 -060011 .arch armv8-a+sve
Arunachalam Ganapathy47b702c2023-06-06 13:31:46 +010012 .globl sme_rdsvl_1
johpow0150ccb552020-11-10 19:22:13 -060013 .globl sme_try_illegal_instruction
Jayanth Dodderi Chidanandb3ffd3c2023-02-13 12:15:11 +000014 .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
johpow0150ccb552020-11-10 19:22:13 -060057
58/*
Arunachalam Ganapathy47b702c2023-06-06 13:31:46 +010059 * RDSVL - Read multiple of Streaming SVE vector register size to scalar register
60 * RDSVL <Xd>, #<imm>
johpow0150ccb552020-11-10 19:22:13 -060061 *
Arunachalam Ganapathy47b702c2023-06-06 13:31:46 +010062 * Arguments/Opcode bit field:
63 * Xd : 64-bit name of the general-purpose base register.
64 * imm : signed immediate operand (imm6)
johpow0150ccb552020-11-10 19:22:13 -060065 */
Arunachalam Ganapathy47b702c2023-06-06 13:31:46 +010066.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 */
77func sme_rdsvl_1
78 _sme_rdsvl 0, 1
johpow0150ccb552020-11-10 19:22:13 -060079 ret
Arunachalam Ganapathy47b702c2023-06-06 13:31:46 +010080endfunc sme_rdsvl_1
johpow0150ccb552020-11-10 19:22:13 -060081
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 */
89func sme_try_illegal_instruction
90 rdffr p0.b
91 ret
92endfunc sme_try_illegal_instruction
93
Jayanth Dodderi Chidanandb3ffd3c2023-02-13 12:15:11 +000094
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 */
100func sme_vector_to_ZA
101 mov w12, wzr
102 _ldr_za 12, 0 // ZA.H[W12] loaded from [X0 / input_vector]
103 ret
104endfunc 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 */
111func sme_ZA_to_vector
112 mov w12, wzr
113 _str_za 12, 0 // ZA.H[W12] stored to [X0 / out_vector]
114 ret
115endfunc sme_ZA_to_vector