blob: 49d2acf1cd5f131c82a34a5f3d30d6858786a60f [file] [log] [blame]
Viet-Hoa Do03b29712022-06-01 11:47:14 +01001/*
Michael Tylerba209752022-12-15 12:39:29 +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 Tylerba209752022-12-15 12:39:29 +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 Tylerba209752022-12-15 12:39:29 +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#if defined(__ARM_FEATURE_SVE)
26
27template <>
28void interleave_block<4, 4, VLType::SME, true>(
29 uint8_t * &out, const uint8_t * const *in,
30 size_t width, size_t height, size_t row_offset, bool first
31)
32{
33 __asm__ __volatile__(
34 ".inst 0xd503477f // SMSTART ZA\n"
Viet-Hoa Do03b29712022-06-01 11:47:14 +010035 "cntw x16\n"
Michael Tylerba209752022-12-15 12:39:29 +000036 "cntw x15\n"
37 "mov z24.b, #0x1\n"
38 "cntw x14, ALL, MUL #2\n"
39 "cntw x13, ALL, MUL #3\n"
40 "mov z23.s, #0x0\n"
41 "mov z22.s, #0x0\n"
42 "cmp %x[height], x16\n"
43 "csel x16, %x[height], x16, LT\n"
Viet-Hoa Do03b29712022-06-01 11:47:14 +010044 "mov z21.s, #0x0\n"
Viet-Hoa Do03b29712022-06-01 11:47:14 +010045 "mov z20.s, #0x0\n"
Michael Tylerba209752022-12-15 12:39:29 +000046 "whilelt p12.b, XZR, %x[height]\n"
47 "whilelt p10.b, x15, %x[height]\n"
48 "whilelt p9.b, x14, %x[height]\n"
49 "whilelt p8.b, x13, %x[height]\n"
50 "zip1 p12.b, p12.b, p9.b\n"
51 "zip1 p10.b, p10.b, p8.b\n"
52 "ptrue p2.b\n"
Viet-Hoa Do03b29712022-06-01 11:47:14 +010053 "cntb x11\n"
54 "ptrue p11.s\n"
Michael Tylerba209752022-12-15 12:39:29 +000055 "sub x16, x16, #0x1\n"
56 "zip1 p10.b, p12.b, p10.b\n"
57 "mov x10, %x[row_offset]\n"
58 "mov x9, %x[out]\n"
Viet-Hoa Do03b29712022-06-01 11:47:14 +010059 "cbnz %x[first], 1f\n"
Michael Tylerba209752022-12-15 12:39:29 +000060 "addvl x9, x9, #-4\n"
61 "ld1w { z23.s }, p2/Z, [x9]\n"
62 "ld1w { z22.s }, p2/Z, [x9, #1, MUL VL]\n"
63 "ld1w { z21.s }, p2/Z, [x9, #2, MUL VL]\n"
64 "ld1w { z20.s }, p2/Z, [x9, #3, MUL VL]\n"
Viet-Hoa Do03b29712022-06-01 11:47:14 +010065 "1:" // Initialise row sums: End
Michael Tylerba209752022-12-15 12:39:29 +000066 "mov x28, #0x0\n"
67 "whilelt p9.b, x28, %x[width]\n"
68 "whilelt p8.b, x28, %x[width]\n"
Viet-Hoa Do03b29712022-06-01 11:47:14 +010069 "2:" // Width loop
Michael Tylerba209752022-12-15 12:39:29 +000070 "add x27, %x[in], XZR, LSL #3\n"
71 "add x26, %x[in], x15, LSL #3\n"
72 "ldr x25, [x27], #0x8\n"
73 "add x24, %x[in], x14, LSL #3\n"
74 "add x23, %x[in], x13, LSL #3\n"
75 "ldr x20, [x26], #0x8\n"
76 "mov x12, #0x0\n"
77 "ldr x22, [x24], #0x8\n"
78 "ldr x21, [x23], #0x8\n"
79 "cbz x16, 4f\n"
Viet-Hoa Do03b29712022-06-01 11:47:14 +010080 "3:" // Loads: Loop
Michael Tylerba209752022-12-15 12:39:29 +000081 ".inst 0x25246140 // psel p0.b, p8.b/Z, p10.b[w12]\n"
82 ".inst 0xe00a0320 // ld1b { za0h.b[x12] }, p0/Z, [x25, x10]\n"
83 ".inst 0x252c6140 // psel p0.b, p8.b/Z, p10.b[w12, #1]\n"
84 "ldr x25, [x27], #0x8\n"
85 ".inst 0xe00a0281 // ld1b { za0h.b[x12, #1] }, p0/Z, [x20, x10]\n"
86 ".inst 0x25346141 // psel p1.b, p8.b/Z, p10.b[w12, #2]\n"
87 ".inst 0x253c6140 // psel p0.b, p8.b/Z, p10.b[w12, #3]\n"
88 "ldr x20, [x26], #0x8\n"
89 ".inst 0xe00a06c2 // ld1b { za0h.b[x12, #2] }, p1/Z, [x22, x10]\n"
90 "ldr x22, [x24], #0x8\n"
91 ".inst 0xe00a02a3 // ld1b { za0h.b[x12, #3] }, p0/Z, [x21, x10]\n"
92 "add x12, x12, #0x4\n"
93 "cmp x12, x16, LSL #2\n"
94 "ldr x21, [x23], #0x8\n"
Viet-Hoa Do03b29712022-06-01 11:47:14 +010095 "blt 3b\n"
96 "4:" // Loads: Tail
Michael Tylerba209752022-12-15 12:39:29 +000097 ".inst 0x25246140 // psel p0.b, p8.b/Z, p10.b[w12]\n"
98 ".inst 0xe00a0320 // ld1b { za0h.b[x12] }, p0/Z, [x25, x10]\n"
99 ".inst 0x252c6140 // psel p0.b, p8.b/Z, p10.b[w12, #1]\n"
100 ".inst 0xe00a0281 // ld1b { za0h.b[x12, #1] }, p0/Z, [x20, x10]\n"
101 ".inst 0x25346140 // psel p0.b, p8.b/Z, p10.b[w12, #2]\n"
102 "sub x20, %x[width], x28\n"
103 ".inst 0xe00a02c2 // ld1b { za0h.b[x12, #2] }, p0/Z, [x22, x10]\n"
104 "cmp x20, x11\n"
105 "csel x20, x20, x11, LT\n"
106 ".inst 0x253c6140 // psel p0.b, p8.b/Z, p10.b[w12, #3]\n"
107 "add x20, x20, #0x3\n"
108 ".inst 0xe00a02a3 // ld1b { za0h.b[x12, #3] }, p0/Z, [x21, x10]\n"
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100109 "mov x12, #0x0\n"
Michael Tylerba209752022-12-15 12:39:29 +0000110 "lsr x20, x20, #0x2\n"
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100111 "5:" // Stores: Loop
Michael Tylerba209752022-12-15 12:39:29 +0000112 ".inst 0x25306d20 // psel p0.s, p11.s/Z, p9.s[w12]\n"
113 ".inst 0xe0bf8120 // st1w { za0v.s[x12] }, p0/Z, [x9, XZR, LSL #2]\n"
114 ".inst 0x25306d20 // psel p0.s, p11.s/Z, p9.s[w12]\n"
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100115 ".inst 0xc0828813 // mova z19.s, p2/M, za0v.s[x12]\n"
Michael Tylerba209752022-12-15 12:39:29 +0000116 ".inst 0xe0af8124 // st1w { za1v.s[x12] }, p0/Z, [x9, x15, LSL #2]\n"
117 ".inst 0x25306d21 // psel p1.s, p11.s/Z, p9.s[w12]\n"
118 ".inst 0x25306d20 // psel p0.s, p11.s/Z, p9.s[w12]\n"
119 ".inst 0xc0828891 // mova z17.s, p2/M, za1v.s[x12]\n"
120 ".inst 0xe0ae8528 // st1w { za2v.s[x12] }, p1/Z, [x9, x14, LSL #2]\n"
121 ".inst 0xc0828912 // mova z18.s, p2/M, za2v.s[x12]\n"
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100122 "udot z23.s, z19.b, z24.b\n"
Michael Tylerba209752022-12-15 12:39:29 +0000123 ".inst 0xe0ad812c // st1w { za3v.s[x12] }, p0/Z, [x9, x13, LSL #2]\n"
124 ".inst 0xc0828990 // mova z16.s, p2/M, za3v.s[x12]\n"
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100125 "add x12, x12, #0x1\n"
Michael Tylerba209752022-12-15 12:39:29 +0000126 "cmp x12, x20\n"
127 "udot z22.s, z17.b, z24.b\n"
128 "udot z21.s, z18.b, z24.b\n"
129 "addvl x9, x9, #4\n"
130 "udot z20.s, z16.b, z24.b\n"
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100131 "blt 5b\n"
Michael Tylerba209752022-12-15 12:39:29 +0000132 "incb x28\n"
133 "whilelt p9.b, x28, %x[width]\n"
134 "whilelt p8.b, x28, %x[width]\n"
135 "incb x10\n"
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100136 "b.any 2b\n"
Michael Tylerba209752022-12-15 12:39:29 +0000137 "st1w { z23.s }, p2, [x9]\n"
138 "st1w { z22.s }, p2, [x9, #1, MUL VL]\n"
139 "st1w { z21.s }, p2, [x9, #2, MUL VL]\n"
140 "st1w { z20.s }, p2, [x9, #3, MUL VL]\n"
141 "addvl x9, x9, #4\n"
142 "mov %x[out], x9\n"
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100143 ".inst 0xd503467f // SMSTOP\n"
144 : [out] "+&r" (out)
145 : [first] "r" (first), [height] "r" (height), [in] "r" (in), [row_offset] "r" (row_offset), [width] "r" (width)
Michael Tylerba209752022-12-15 12:39:29 +0000146 : "cc", "memory", "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "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"
Viet-Hoa Do03b29712022-06-01 11:47:14 +0100147 );
148}
149
150#endif // defined(__ARM_FEATURE_SVE)