1 /*
2 * Copyright (c) 2022 Arm Limited.
3 *
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 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
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
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
25 #if defined(__ARM_FEATURE_SVE)
26
27 template <>
interleave_block(float * & out,const float * const * in,size_t width,size_t height,size_t row_offset,bool first)28 void interleave_block<1, 1, VLType::SME, false>(
29 float * &out, const float * const *in,
30 size_t width, size_t height, size_t row_offset, bool first
31 )
32 {
33 ARM_COMPUTE_UNUSED(first);
34
35 __asm__ __volatile__(
36 ".inst 0xd503477f // SMSTART ZA\n"
37 "cntw x10\n"
38 "mov x19, %x[width]\n"
39 "incw x19\n"
40 "sub x19, x19, #0x1\n"
41 "udiv x19, x19, x10\n" // n_passes = ceildiv(width, VL<T>)
42 "sub x9, x19, #0x1\n"
43 "lsr x9, x9, #0x1\n" // n_loops = (n_passes - 1) / 2
44 "and x28, x19, #0x1\n" // odd_tail = bool(n_passes & 0x1)
45 "mov x19, %x[width]\n"
46 "sub x27, x10, #0x1\n"
47 "ands x27, x19, x27\n"
48 "csel x27, x27, x10, NE\n"
49 "sub x26, x10, #0x2\n"
50 "ptrue p11.s\n"
51 "whilelt p10.s, XZR, %x[height]\n"
52 "mov x25, %x[row_offset]\n"
53 "mov x24, %x[out]\n"
54 "mov x23, #0x0\n"
55 "whilelt p9.s, x23, %x[width]\n"
56 "whilelt p8.s, x23, %x[width]\n"
57 "mov x22, %x[in]\n"
58 "ldr x21, [x22, #0x0]\n"
59 "ldr x20, [x22, #0x8]\n"
60 "add x22, x22, #0x10\n"
61 "mov x12, #0x0\n"
62 "cbz x26, 2f\n"
63 "1:" // K loop: Charge: Loop
64 ".inst 0x25306140 // dup p0.s, p8.s/Z, p10.s[w12]\n"
65 ".inst 0xe09902a0 // ld1w { za0h.s[x12] }, p0/Z, [x21, x25, LSL #2]\n"
66 ".inst 0x25706140 // dup p0.s, p8.s/Z, p10.s[w12, #1]\n"
67 "ldr x21, [x22, #0x0]\n"
68 ".inst 0xe0990281 // ld1w { za0h.s[x12, #1] }, p0/Z, [x20, x25, LSL #2]\n"
69 "ldr x20, [x22, #0x8]\n"
70 "add x22, x22, #0x10\n"
71 "add x12, x12, #0x2\n"
72 "cmp x12, x26\n"
73 "blt 1b\n"
74 "2:" // K loop: Charge: End
75 ".inst 0x25306140 // dup p0.s, p8.s/Z, p10.s[w12]\n"
76 ".inst 0xe09902a0 // ld1w { za0h.s[x12] }, p0/Z, [x21, x25, LSL #2]\n"
77 ".inst 0x25706140 // dup p0.s, p8.s/Z, p10.s[w12, #1]\n"
78 "mov x22, %x[in]\n"
79 ".inst 0xe0990281 // ld1w { za0h.s[x12, #1] }, p0/Z, [x20, x25, LSL #2]\n"
80 "ldr x21, [x22, #0x0]\n"
81 "ldr x20, [x22, #0x8]\n"
82 "add x22, x22, #0x10\n"
83 "incw x25\n"
84 "incw x23\n"
85 "cbz x9, 8f\n"
86 "mov x19, x9\n"
87 "3:" // K loop: Main loop
88 "whilelt p8.s, x23, %x[width]\n"
89 "mov x12, #0x0\n"
90 "cbz x26, 5f\n"
91 "4:" // K loop: Main loop: First: Loop
92 ".inst 0x25306140 // dup p0.s, p8.s/Z, p10.s[w12]\n"
93 ".inst 0xe09902a8 // ld1w { za2h.s[x12] }, p0/Z, [x21, x25, LSL #2]\n"
94 ".inst 0x25706140 // dup p0.s, p8.s/Z, p10.s[w12, #1]\n"
95 "ldr x21, [x22, #0x0]\n"
96 ".inst 0xe0990289 // ld1w { za2h.s[x12, #1] }, p0/Z, [x20, x25, LSL #2]\n"
97 "ldr x20, [x22, #0x8]\n"
98 "add x22, x22, #0x10\n"
99 ".inst 0x25306d20 // dup p0.s, p11.s/Z, p9.s[w12]\n"
100 ".inst 0xe0bf8300 // st1w { za0v.s[x12] }, p0/Z, [x24, XZR, LSL #2]\n"
101 ".inst 0x25706d20 // dup p0.s, p11.s/Z, p9.s[w12, #1]\n"
102 ".inst 0xe0aa8301 // st1w { za0v.s[x12, #1] }, p0/Z, [x24, x10, LSL #2]\n"
103 "addvl x24, x24, #2\n"
104 "add x12, x12, #0x2\n"
105 "cmp x12, x26\n"
106 "blt 4b\n"
107 "5:" // K loop: Main loop: First: Tail
108 "mov x22, %x[in]\n"
109 ".inst 0x25306140 // dup p0.s, p8.s/Z, p10.s[w12]\n"
110 ".inst 0xe09902a8 // ld1w { za2h.s[x12] }, p0/Z, [x21, x25, LSL #2]\n"
111 ".inst 0x25706140 // dup p0.s, p8.s/Z, p10.s[w12, #1]\n"
112 "ldr x21, [x22, #0x0]\n"
113 ".inst 0xe0990289 // ld1w { za2h.s[x12, #1] }, p0/Z, [x20, x25, LSL #2]\n"
114 "ldr x20, [x22, #0x8]\n"
115 "add x22, x22, #0x10\n"
116 ".inst 0x25306d20 // dup p0.s, p11.s/Z, p9.s[w12]\n"
117 ".inst 0xe0bf8300 // st1w { za0v.s[x12] }, p0/Z, [x24, XZR, LSL #2]\n"
118 ".inst 0x25706d20 // dup p0.s, p11.s/Z, p9.s[w12, #1]\n"
119 "whilelt p9.s, x23, %x[width]\n"
120 ".inst 0xe0aa8301 // st1w { za0v.s[x12, #1] }, p0/Z, [x24, x10, LSL #2]\n"
121 "addvl x24, x24, #2\n"
122 "incw x23\n"
123 "incw x25\n"
124 "whilelt p8.s, x23, %x[width]\n"
125 "mov x12, #0x0\n"
126 "cbz x26, 7f\n"
127 "6:" // K loop: Main loop: Second: Loop
128 ".inst 0x25306140 // dup p0.s, p8.s/Z, p10.s[w12]\n"
129 ".inst 0xe09902a0 // ld1w { za0h.s[x12] }, p0/Z, [x21, x25, LSL #2]\n"
130 ".inst 0x25706140 // dup p0.s, p8.s/Z, p10.s[w12, #1]\n"
131 "ldr x21, [x22, #0x0]\n"
132 ".inst 0xe0990281 // ld1w { za0h.s[x12, #1] }, p0/Z, [x20, x25, LSL #2]\n"
133 "ldr x20, [x22, #0x8]\n"
134 "add x22, x22, #0x10\n"
135 ".inst 0x25306d20 // dup p0.s, p11.s/Z, p9.s[w12]\n"
136 ".inst 0xe0bf8308 // st1w { za2v.s[x12] }, p0/Z, [x24, XZR, LSL #2]\n"
137 ".inst 0x25706d20 // dup p0.s, p11.s/Z, p9.s[w12, #1]\n"
138 ".inst 0xe0aa8309 // st1w { za2v.s[x12, #1] }, p0/Z, [x24, x10, LSL #2]\n"
139 "addvl x24, x24, #2\n"
140 "add x12, x12, #0x2\n"
141 "cmp x12, x26\n"
142 "blt 6b\n"
143 "7:" // K loop: Main loop: Second: Tail
144 "mov x22, %x[in]\n"
145 ".inst 0x25306140 // dup p0.s, p8.s/Z, p10.s[w12]\n"
146 ".inst 0xe09902a0 // ld1w { za0h.s[x12] }, p0/Z, [x21, x25, LSL #2]\n"
147 ".inst 0x25706140 // dup p0.s, p8.s/Z, p10.s[w12, #1]\n"
148 "ldr x21, [x22, #0x0]\n"
149 ".inst 0xe0990281 // ld1w { za0h.s[x12, #1] }, p0/Z, [x20, x25, LSL #2]\n"
150 "ldr x20, [x22, #0x8]\n"
151 "add x22, x22, #0x10\n"
152 ".inst 0x25306d20 // dup p0.s, p11.s/Z, p9.s[w12]\n"
153 ".inst 0xe0bf8308 // st1w { za2v.s[x12] }, p0/Z, [x24, XZR, LSL #2]\n"
154 ".inst 0x25706d20 // dup p0.s, p11.s/Z, p9.s[w12, #1]\n"
155 "whilelt p9.s, x23, %x[width]\n"
156 ".inst 0xe0aa8309 // st1w { za2v.s[x12, #1] }, p0/Z, [x24, x10, LSL #2]\n"
157 "addvl x24, x24, #2\n"
158 "incw x23\n"
159 "incw x25\n"
160 "subs x19, x19, #0x1\n"
161 "bgt 3b\n"
162 "8:" // K loop: Tails
163 "cbnz x28, 11f\n"
164 "mov x22, %x[in]\n"
165 "whilelt p8.s, x23, %x[width]\n"
166 "mov x12, #0x0\n"
167 "9:" // K loop: Tails: Even: First
168 ".inst 0x25306d20 // dup p0.s, p11.s/Z, p9.s[w12]\n"
169 ".inst 0xe0bf8300 // st1w { za0v.s[x12] }, p0/Z, [x24, XZR, LSL #2]\n"
170 ".inst 0x25306140 // dup p0.s, p8.s/Z, p10.s[w12]\n"
171 "addvl x24, x24, #1\n"
172 "ldr x21, [x22, #0x0]\n"
173 ".inst 0xe09902a8 // ld1w { za2h.s[x12] }, p0/Z, [x21, x25, LSL #2]\n"
174 "add x22, x22, #0x8\n"
175 "add x12, x12, #0x1\n"
176 "cmp x12, x10\n"
177 "blt 9b\n"
178 "whilelt p9.s, x23, %x[width]\n"
179 "whilelt p8.s, x23, %x[width]\n"
180 "mov x12, #0x0\n"
181 "10:" // K loop: Tails: Even: Second
182 ".inst 0x25306d20 // dup p0.s, p11.s/Z, p9.s[w12]\n"
183 ".inst 0xe0bf8308 // st1w { za2v.s[x12] }, p0/Z, [x24, XZR, LSL #2]\n"
184 "addvl x24, x24, #1\n"
185 "add x12, x12, #0x1\n"
186 "cmp x12, x27\n"
187 "blt 10b\n"
188 "whilelt p9.s, x23, %x[width]\n"
189 "b 13f\n"
190 "11:" // K loop: Tails: Odd
191 "mov x12, #0x0\n"
192 "12:" // K loop: Tails: Odd: Loop
193 ".inst 0x25306d20 // dup p0.s, p11.s/Z, p9.s[w12]\n"
194 ".inst 0xe0bf8300 // st1w { za0v.s[x12] }, p0/Z, [x24, XZR, LSL #2]\n"
195 "addvl x24, x24, #1\n"
196 "add x12, x12, #0x1\n"
197 "cmp x12, x27\n"
198 "blt 12b\n"
199 "13:" // K loop: End
200 "mov %x[out], x24\n"
201 ".inst 0xd503467f // SMSTOP\n"
202 : [out] "+&r" (out)
203 : [height] "r" (height), [in] "r" (in), [row_offset] "r" (row_offset), [width] "r" (width)
204 : "cc", "memory", "p0", "p8", "p9", "p10", "p11", "x9", "x10", "x12", "x19", "x20", "x21", "x22", "x23", "x24", "x25", "x26", "x27", "x28", "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"
205 );
206 }
207
208 #endif // defined(__ARM_FEATURE_SVE)
209