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(bfloat16 * & out,const float * const * in,size_t width,size_t height,size_t row_offset,bool first)28 void interleave_block<2, 2, VLType::SME, false>(
29 bfloat16 * &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 x21, ALL, MUL #2\n"
38 "cntw x28\n"
39 "sub x27, %x[width], #0x1\n"
40 "cntw x20, ALL, MUL #2\n"
41 "sub x19, x21, #0x1\n"
42 ".inst 0x25207815 // ptrue pn13.b\n"
43 "whilelt p12.s, XZR, %x[height]\n"
44 "whilelt p11.s, x28, %x[height]\n"
45 "add x27, x27, x20\n"
46 "ands x26, %x[width], x19\n"
47 "udiv x27, x27, x20\n"
48 "csel x26, x26, x21, NE\n"
49 "mov x25, #0x0\n"
50 "and x24, x27, #0x1\n"
51 "sub x27, x27, #0x1\n"
52 "add x26, x26, #0x1\n"
53 "mov x19, %x[width]\n"
54 "mov x23, %x[in]\n"
55 "ptrue p0.b\n"
56 "mov x22, %x[outptr_raw]\n"
57 "mov x21, %x[row_offset]\n"
58 "lsr x27, x27, #0x1\n"
59 "lsr x26, x26, #0x1\n"
60 "mov x12, #0x0\n"
61 ".inst 0x25b34732 // whilelt pn10.s, x25, x19, VLx2\n"
62 "add x20, x23, x28, LSL #3\n"
63 "1:" // Width loop: Preamble: Loop
64 "ldr x19, [x23], #0x8\n"
65 ".inst 0x25306989 // psel p9.s, p10.s/Z, p12.s[w12]\n"
66 ".inst 0x25306968 // psel p8.s, p10.s/Z, p11.s[w12]\n"
67 ".inst 0xa0154678 // ld1w { z24.s-z25.s }, pn9.s/Z, [x19, x21, LSL #2]\n"
68 "ldr x19, [x20], #0x8\n"
69 ".inst 0xa0154276 // ld1w { z22.s-z23.s }, pn8.s/Z, [x19, x21, LSL #2]\n"
70 ".inst 0xc160e318 // bfcvt z24.h, { z24.s-z25.s }\n"
71 ".inst 0xc160e2d6 // bfcvt z22.h, { z22.s-z23.s }\n"
72 ".inst 0xc0800300 // mova za0h.s[x12], p0/M, z24.s\n"
73 ".inst 0xc08002c4 // mova za1h.s[x12], p0/M, z22.s\n"
74 "add x12, x12, #0x1\n"
75 "cmp x12, x28\n"
76 "blt 1b\n"
77 "incw x21, ALL, MUL #2\n"
78 "incw x25, ALL, MUL #2\n"
79 "cbz x27, 5f\n"
80 "2:" // Width loop
81 "mov x19, %x[width]\n"
82 "mov x23, %x[in]\n"
83 "mov x12, #0x0\n"
84 ".inst 0x25b34732 // whilelt pn10.s, x25, x19, VLx2\n"
85 "add x20, x23, x28, LSL #3\n"
86 "3:" // Width loop: Odd: Loop
87 "ldr x19, [x23], #0x8\n"
88 ".inst 0x25306989 // psel p9.s, p10.s/Z, p12.s[w12]\n"
89 ".inst 0x25306968 // psel p8.s, p10.s/Z, p11.s[w12]\n"
90 ".inst 0xa0154676 // ld1w { z22.s-z23.s }, pn9.s/Z, [x19, x21, LSL #2]\n"
91 "ldr x19, [x20], #0x8\n"
92 ".inst 0xa015426a // ld1w { z10.s-z11.s }, pn8.s/Z, [x19, x21, LSL #2]\n"
93 ".inst 0xc160e2d6 // bfcvt z22.h, { z22.s-z23.s }\n"
94 ".inst 0xc160e14a // bfcvt z10.h, { z10.s-z11.s }\n"
95 ".inst 0xc08002c8 // mova za2h.s[x12], p0/M, z22.s\n"
96 ".inst 0xc080014c // mova za3h.s[x12], p0/M, z10.s\n"
97 ".inst 0xc0828008 // mova z8.s, p0/M, za0v.s[x12]\n"
98 ".inst 0xc0828089 // mova z9.s, p0/M, za1v.s[x12]\n"
99 "add x12, x12, #0x1\n"
100 "cmp x12, x28\n"
101 ".inst 0xa06056c8 // st1w { z8.s-z9.s }, pn13.b, [x22]\n"
102 "addvl x22, x22, #2\n"
103 "blt 3b\n"
104 "incw x25, ALL, MUL #2\n"
105 "mov x19, %x[width]\n"
106 "mov x23, %x[in]\n"
107 "incw x21, ALL, MUL #2\n"
108 "mov x12, #0x0\n"
109 ".inst 0x25b34732 // whilelt pn10.s, x25, x19, VLx2\n"
110 "add x20, x23, x28, LSL #3\n"
111 "4:" // Width loop: Even: Loop
112 "ldr x19, [x23], #0x8\n"
113 ".inst 0x25306989 // psel p9.s, p10.s/Z, p12.s[w12]\n"
114 ".inst 0x25306968 // psel p8.s, p10.s/Z, p11.s[w12]\n"
115 ".inst 0xa015467a // ld1w { z26.s-z27.s }, pn9.s/Z, [x19, x21, LSL #2]\n"
116 "ldr x19, [x20], #0x8\n"
117 ".inst 0xa015427e // ld1w { z30.s-z31.s }, pn8.s/Z, [x19, x21, LSL #2]\n"
118 ".inst 0xc160e35a // bfcvt z26.h, { z26.s-z27.s }\n"
119 ".inst 0xc160e3de // bfcvt z30.h, { z30.s-z31.s }\n"
120 ".inst 0xc0800340 // mova za0h.s[x12], p0/M, z26.s\n"
121 ".inst 0xc08003c4 // mova za1h.s[x12], p0/M, z30.s\n"
122 ".inst 0xc0828106 // mova z6.s, p0/M, za2v.s[x12]\n"
123 ".inst 0xc082818e // mova z14.s, p0/M, za3v.s[x12]\n"
124 "add x12, x12, #0x1\n"
125 "cmp x12, x28\n"
126 ".inst 0xa16056c6 // st1w { z6.s, z14.s }, pn13.b, [x22]\n"
127 "addvl x22, x22, #2\n"
128 "blt 4b\n"
129 "subs x27, x27, #0x1\n"
130 "incw x21, ALL, MUL #2\n"
131 "incw x25, ALL, MUL #2\n"
132 "bgt 2b\n"
133 "5:" // Width loop: Tails
134 "cbnz x24, 8f\n"
135 "mov x19, %x[width]\n"
136 "mov x23, %x[in]\n"
137 "mov x12, #0x0\n"
138 ".inst 0x25b34732 // whilelt pn10.s, x25, x19, VLx2\n"
139 "add x20, x23, x28, LSL #3\n"
140 "6:" // Width loop: Tails: Even: Odd: Loop
141 "ldr x19, [x23], #0x8\n"
142 ".inst 0x25306989 // psel p9.s, p10.s/Z, p12.s[w12]\n"
143 ".inst 0x25306968 // psel p8.s, p10.s/Z, p11.s[w12]\n"
144 ".inst 0xa015466c // ld1w { z12.s-z13.s }, pn9.s/Z, [x19, x21, LSL #2]\n"
145 "ldr x19, [x20], #0x8\n"
146 ".inst 0xa015426e // ld1w { z14.s-z15.s }, pn8.s/Z, [x19, x21, LSL #2]\n"
147 ".inst 0xc160e18c // bfcvt z12.h, { z12.s-z13.s }\n"
148 ".inst 0xc160e1ce // bfcvt z14.h, { z14.s-z15.s }\n"
149 ".inst 0xc0800188 // mova za2h.s[x12], p0/M, z12.s\n"
150 ".inst 0xc08001cc // mova za3h.s[x12], p0/M, z14.s\n"
151 ".inst 0xc0828007 // mova z7.s, p0/M, za0v.s[x12]\n"
152 ".inst 0xc082808f // mova z15.s, p0/M, za1v.s[x12]\n"
153 "add x12, x12, #0x1\n"
154 "cmp x12, x28\n"
155 ".inst 0xa16056c7 // st1w { z7.s, z15.s }, pn13.b, [x22]\n"
156 "addvl x22, x22, #2\n"
157 "blt 6b\n"
158 "mov x12, #0x0\n"
159 "7:" // Width loop: Tails: Even: Even: Loop
160 ".inst 0xc082810e // mova z14.s, p0/M, za2v.s[x12]\n"
161 ".inst 0xc082818f // mova z15.s, p0/M, za3v.s[x12]\n"
162 "add x12, x12, #0x1\n"
163 "cmp x12, x26\n"
164 ".inst 0xa06056ce // st1w { z14.s-z15.s }, pn13.b, [x22]\n"
165 "addvl x22, x22, #2\n"
166 "blt 7b\n"
167 "b 10f\n"
168 "8:" // Width loop: Tails: Odd
169 "mov x12, #0x0\n"
170 "9:" // Width loop: Tails: Odd: Loop
171 ".inst 0xc0828014 // mova z20.s, p0/M, za0v.s[x12]\n"
172 ".inst 0xc0828095 // mova z21.s, p0/M, za1v.s[x12]\n"
173 "add x12, x12, #0x1\n"
174 "cmp x12, x26\n"
175 ".inst 0xa06056d4 // st1w { z20.s-z21.s }, pn13.b, [x22]\n"
176 "addvl x22, x22, #2\n"
177 "blt 9b\n"
178 "10:" // End
179 "mov %x[outptr_raw], x22\n"
180 ".inst 0xd503467f // SMSTOP\n"
181 : [outptr_raw] "+&r" (out)
182 : [height] "r" (height), [in] "r" (in), [row_offset] "r" (row_offset), [width] "r" (width)
183 : "cc", "memory", "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", "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"
184 );
185 }
186
187 #endif // defined(__ARM_FEATURE_SVE)
188