blob: 2756327815349541b4bc33a5ab42b717976f5338 [file] [log] [blame]
Viet-Hoa Do03b29712022-06-01 11:47:14 +01001/*
Michael Tyler7d9a6262023-02-01 16:37:07 +00002 * Copyright (c) 2022-2023 Arm Limited.
Viet-Hoa Do03b29712022-06-01 11:47:14 +01003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
Michael Tyler7d9a6262023-02-01 16:37:07 +000013 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
Viet-Hoa Do03b29712022-06-01 11:47:14 +010015 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Michael Tyler7d9a6262023-02-01 16:37:07 +000020 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
Viet-Hoa Do03b29712022-06-01 11:47:14 +010023 */
24
25#pragma once
26
Michael Tyler74921ee2023-04-12 17:43:17 +010027#if defined(ARM_COMPUTE_ENABLE_SME)
Viet-Hoa Do03b29712022-06-01 11:47:14 +010028
29namespace {
30
31void sme_transpose_interleave_16VL_2x2_fp32bf16(bfloat16 *out, const float *in, size_t width, size_t in_stride, size_t height)
32{
33 float *pad_row = reinterpret_cast<float *>(alloca(width * sizeof(float)));
34
35 if (height % 2) {
36 memset(pad_row, 0, width * sizeof(float));
37 }
38
39 size_t out_stride = 16 * roundup<size_t>(height, 2) * sme::get_vector_length<uint16_t>();
40
41 __asm__ __volatile__(
42 ".inst 0xd503477f // SMSTART ZA\n"
43 "ptrue p7.b\n"
44 "1:" // Main row loop: Head
Michael Tyler7d9a6262023-02-01 16:37:07 +000045 "mov x25, %x[in]\n"
46 "add x24, x25, %x[in_stride]\n"
Viet-Hoa Do03b29712022-06-01 11:47:14 +010047 "cmp %x[height], #0x1\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000048 "add %x[in], x24, %x[in_stride]\n"
49 "mov x23, %x[out]\n"
50 "csel x24, x24, %x[pad_row], GT\n"
Viet-Hoa Do03b29712022-06-01 11:47:14 +010051 "sub %x[height], %x[height], #0x2\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000052 "mov x22, %x[width]\n"
Viet-Hoa Do03b29712022-06-01 11:47:14 +010053 "2:" // Main row loop: Column loop
Michael Tyler7d9a6262023-02-01 16:37:07 +000054 "mov x21, x22\n"
55 "whilelt p1.s, XZR, x21\n"
56 "ld1w { z16.s }, p1/Z, [x25]\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +000057 ".inst 0x658abe00 // bfcvt z0.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000058 "decw x21\n"
59 "whilelt p0.s, XZR, x21\n"
60 "ld1w { z16.s }, p0/Z, [x25, #1, MUL VL]\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +000061 ".inst 0x658abe1f // bfcvt z31.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000062 "decw x21\n"
63 "whilelt p6.s, XZR, x21\n"
64 "ld1w { z16.s }, p6/Z, [x25, #2, MUL VL]\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +000065 ".inst 0x658abe1e // bfcvt z30.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000066 "decw x21\n"
67 "whilelt p5.s, XZR, x21\n"
68 "ld1w { z16.s }, p5/Z, [x25, #3, MUL VL]\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +000069 ".inst 0x658abe1d // bfcvt z29.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000070 "decw x21\n"
71 "whilelt p4.s, XZR, x21\n"
72 "ld1w { z16.s }, p4/Z, [x25, #4, MUL VL]\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +000073 ".inst 0x658abe1c // bfcvt z28.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000074 "decw x21\n"
75 "whilelt p3.s, XZR, x21\n"
76 "ld1w { z16.s }, p3/Z, [x25, #5, MUL VL]\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +000077 ".inst 0x658abe1b // bfcvt z27.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000078 "decw x21\n"
79 "whilelt p2.s, XZR, x21\n"
80 "ld1w { z16.s }, p2/Z, [x25, #6, MUL VL]\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +000081 ".inst 0x658abe1a // bfcvt z26.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000082 "decw x21\n"
83 "ld1w { z16.s }, p1/Z, [x24]\n"
84 "whilelt p1.s, XZR, x21\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +000085 ".inst 0x648abe00 // bfcvtnt z0.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000086 "decw x21\n"
87 "ld1w { z16.s }, p1/Z, [x25, #7, MUL VL]\n"
88 "addvl x25, x25, #16\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +000089 ".inst 0x658abe19 // bfcvt z25.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000090 "ld1w { z16.s }, p0/Z, [x24, #1, MUL VL]\n"
91 "whilelt p0.s, XZR, x21\n"
92 "decw x21\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +000093 ".inst 0x648abe1f // bfcvtnt z31.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000094 "ld1w { z16.s }, p0/Z, [x25, #-8, MUL VL]\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +000095 ".inst 0x658abe18 // bfcvt z24.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000096 "mov x20, x23\n"
97 "decw x22, ALL, MUL #16\n"
98 "ld1w { z16.s }, p6/Z, [x24, #2, MUL VL]\n"
99 "whilelt p6.s, XZR, x21\n"
100 "decw x21\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000101 ".inst 0x648abe1e // bfcvtnt z30.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000102 "ld1w { z16.s }, p6/Z, [x25, #-7, MUL VL]\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000103 ".inst 0x658abe17 // bfcvt z23.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000104 "add x23, x23, %x[out_stride]\n"
105 "ld1w { z16.s }, p5/Z, [x24, #3, MUL VL]\n"
106 "whilelt p5.s, XZR, x21\n"
107 "decw x21\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000108 ".inst 0x648abe1d // bfcvtnt z29.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000109 "ld1w { z16.s }, p5/Z, [x25, #-6, MUL VL]\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000110 ".inst 0x658abe16 // bfcvt z22.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000111 "ld1w { z16.s }, p4/Z, [x24, #4, MUL VL]\n"
112 "whilelt p4.s, XZR, x21\n"
113 "decw x21\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000114 ".inst 0x648abe1c // bfcvtnt z28.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000115 "ld1w { z16.s }, p4/Z, [x25, #-5, MUL VL]\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000116 ".inst 0x658abe15 // bfcvt z21.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000117 "ld1w { z16.s }, p3/Z, [x24, #5, MUL VL]\n"
118 "whilelt p3.s, XZR, x21\n"
119 "decw x21\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000120 ".inst 0x648abe1b // bfcvtnt z27.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000121 "ld1w { z16.s }, p3/Z, [x25, #-4, MUL VL]\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000122 ".inst 0x658abe14 // bfcvt z20.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000123 "ld1w { z16.s }, p2/Z, [x24, #6, MUL VL]\n"
124 "whilelt p2.s, XZR, x21\n"
125 "decw x21\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000126 ".inst 0x648abe1a // bfcvtnt z26.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000127 "ld1w { z16.s }, p2/Z, [x25, #-3, MUL VL]\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000128 ".inst 0x658abe13 // bfcvt z19.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000129 "ld1w { z16.s }, p1/Z, [x24, #7, MUL VL]\n"
130 "whilelt p1.s, XZR, x21\n"
131 "decw x21\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000132 ".inst 0x648abe19 // bfcvtnt z25.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000133 "ld1w { z16.s }, p1/Z, [x25, #-2, MUL VL]\n"
134 "addvl x24, x24, #16\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000135 ".inst 0x658abe12 // bfcvt z18.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000136 "ld1w { z16.s }, p0/Z, [x24, #-8, MUL VL]\n"
137 "whilelt p0.s, XZR, x21\n"
138 "cmp x22, #0x0\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000139 ".inst 0x648abe18 // bfcvtnt z24.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000140 "ld1w { z16.s }, p0/Z, [x25, #-1, MUL VL]\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000141 ".inst 0x658abe11 // bfcvt z17.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000142 "ld1w { z16.s }, p6/Z, [x24, #-7, MUL VL]\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000143 ".inst 0x648abe17 // bfcvtnt z23.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000144 "ld1w { z16.s }, p5/Z, [x24, #-6, MUL VL]\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000145 ".inst 0x648abe16 // bfcvtnt z22.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000146 "ld1w { z16.s }, p4/Z, [x24, #-5, MUL VL]\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000147 ".inst 0x648abe15 // bfcvtnt z21.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000148 "ld1w { z16.s }, p3/Z, [x24, #-4, MUL VL]\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000149 ".inst 0x648abe14 // bfcvtnt z20.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000150 "ld1w { z16.s }, p2/Z, [x24, #-3, MUL VL]\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000151 ".inst 0x648abe13 // bfcvtnt z19.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000152 "ld1w { z16.s }, p1/Z, [x24, #-2, MUL VL]\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000153 ".inst 0x648abe12 // bfcvtnt z18.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000154 "ld1w { z16.s }, p0/Z, [x24, #-1, MUL VL]\n"
155 "st1h { z0.h }, p7, [x20]\n"
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100156 ".inst 0x648abe11 // bfcvtnt z17.h, p7/M, z16.s\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000157 "st1h { z31.h }, p7, [x20, #1, MUL VL]\n"
158 "st1h { z30.h }, p7, [x20, #2, MUL VL]\n"
159 "st1h { z29.h }, p7, [x20, #3, MUL VL]\n"
160 "st1h { z28.h }, p7, [x20, #4, MUL VL]\n"
161 "st1h { z27.h }, p7, [x20, #5, MUL VL]\n"
162 "st1h { z26.h }, p7, [x20, #6, MUL VL]\n"
163 "st1h { z25.h }, p7, [x20, #7, MUL VL]\n"
164 "addvl x20, x20, #16\n"
165 "st1h { z24.h }, p7, [x20, #-8, MUL VL]\n"
166 "st1h { z23.h }, p7, [x20, #-7, MUL VL]\n"
167 "st1h { z22.h }, p7, [x20, #-6, MUL VL]\n"
168 "st1h { z21.h }, p7, [x20, #-5, MUL VL]\n"
169 "st1h { z20.h }, p7, [x20, #-4, MUL VL]\n"
170 "st1h { z19.h }, p7, [x20, #-3, MUL VL]\n"
171 "st1h { z18.h }, p7, [x20, #-2, MUL VL]\n"
172 "st1h { z17.h }, p7, [x20, #-1, MUL VL]\n"
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100173 "bgt 2b\n"
174 "3:" // Main row loop: Column loop skip
175 "cmp %x[height], #0x1\n"
176 "addvl %x[out], %x[out], #16\n"
177 "bge 1b\n"
178 ".inst 0xd503467f // SMSTOP\n"
179 : [height] "+&r" (height), [in] "+&r" (in), [out] "+&r" (out)
180 : [in_stride] "r" (in_stride), [out_stride] "r" (out_stride), [pad_row] "r" (pad_row), [width] "r" (width)
Michael Tyler7d9a6262023-02-01 16:37:07 +0000181 : "cc", "memory", "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", "x20", "x21", "x22", "x23", "x24", "x25", "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31"
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100182 );
183}
184
185} // anonymous namespace
186template<>
187void Transform<16, 2, true, VLType::SME>(
188 bfloat16 *out, const float *in, int stride, int x0, int xmax, int k0, int kmax)
189{
190 sme_transpose_interleave_16VL_2x2_fp32bf16(
191 out,
192 in + k0 * stride + x0,
193 (xmax-x0),
194 stride * sizeof(float),
195 (kmax-k0)
196 );
197}
198
Michael Tyler74921ee2023-04-12 17:43:17 +0100199
200#endif // defined(ARM_COMPUTE_ENABLE_SME)