Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 1 | /* |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 2 | * Copyright (c) 2021, 2023 Arm Limited. |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 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 | * |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 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 |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 20 | * 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. |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 23 | */ |
| 24 | |
| 25 | #pragma once |
| 26 | |
Michael Tyler | 74921ee | 2023-04-12 17:43:17 +0100 | [diff] [blame^] | 27 | #if defined(ARM_COMPUTE_ENABLE_SVE) |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 28 | |
| 29 | namespace { |
| 30 | |
| 31 | void sve_transpose_interleave_8VL_1x8(uint8_t *out, const uint8_t *in, size_t width, size_t in_stride, size_t height) |
| 32 | { |
| 33 | uint8_t *pad_row = reinterpret_cast<uint8_t *>(alloca(width * sizeof(uint8_t))); |
| 34 | |
| 35 | if (height % 8) { |
| 36 | memset(pad_row, 0, width * sizeof(uint8_t)); |
| 37 | } |
| 38 | |
| 39 | size_t out_stride = 8 * roundup<size_t>(height, 8) * get_vector_length<uint64_t>(); |
| 40 | |
| 41 | __asm__ __volatile__( |
| 42 | "ptrue p1.b\n" |
| 43 | "1:" // Main row loop: Head |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 44 | "mov x10, %x[in]\n" |
| 45 | "add x9, x10, %x[in_stride]\n" |
| 46 | "add x28, x9, %x[in_stride]\n" |
| 47 | "add x27, x28, %x[in_stride]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 48 | "add x26, x27, %x[in_stride]\n" |
| 49 | "add x25, x26, %x[in_stride]\n" |
| 50 | "add x24, x25, %x[in_stride]\n" |
| 51 | "add x23, x24, %x[in_stride]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 52 | "cmp %x[height], #0x7\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 53 | "add %x[in], x23, %x[in_stride]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 54 | "csel x23, x23, %x[pad_row], GT\n" |
| 55 | "csel x24, x24, %x[pad_row], GE\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 56 | "cmp %x[height], #0x5\n" |
| 57 | "mov x22, %x[width]\n" |
| 58 | "cntb x21, ALL, MUL #2\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 59 | "csel x25, x25, %x[pad_row], GT\n" |
| 60 | "csel x26, x26, %x[pad_row], GE\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 61 | "cmp %x[height], #0x3\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 62 | "csel x27, x27, %x[pad_row], GT\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 63 | "csel x28, x28, %x[pad_row], GE\n" |
| 64 | "cmp %x[height], #0x1\n" |
| 65 | "csel x9, x9, %x[pad_row], GT\n" |
| 66 | "cmp x22, x21\n" |
| 67 | "mov x20, %x[out]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 68 | "sub %x[height], %x[height], #0x8\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 69 | "blt 3f\n" |
| 70 | "2:" // Main row loop: Unroll column loop |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 71 | "ld1b { z23.b }, p1/Z, [x10]\n" |
| 72 | "ld1b { z22.b }, p1/Z, [x9]\n" |
| 73 | "sub x22, x22, x21\n" |
| 74 | "cmp x22, x21\n" |
| 75 | "ld1b { z20.b }, p1/Z, [x28]\n" |
| 76 | "ld1b { z21.b }, p1/Z, [x27]\n" |
| 77 | "ld1b { z19.b }, p1/Z, [x26]\n" |
| 78 | "ld1b { z18.b }, p1/Z, [x25]\n" |
| 79 | "zip1 z5.b, z23.b, z19.b\n" |
| 80 | "zip1 z4.b, z22.b, z18.b\n" |
| 81 | "ld1b { z17.b }, p1/Z, [x24]\n" |
| 82 | "ld1b { z16.b }, p1/Z, [x23]\n" |
| 83 | "zip1 z3.b, z20.b, z17.b\n" |
| 84 | "zip1 z31.b, z21.b, z16.b\n" |
| 85 | "ld1b { z25.b }, p1/Z, [x10, #1, MUL VL]\n" |
| 86 | "ld1b { z24.b }, p1/Z, [x9, #1, MUL VL]\n" |
| 87 | "zip2 z2.b, z23.b, z19.b\n" |
| 88 | "zip2 z30.b, z20.b, z17.b\n" |
| 89 | "ld1b { z23.b }, p1/Z, [x28, #1, MUL VL]\n" |
| 90 | "ld1b { z20.b }, p1/Z, [x27, #1, MUL VL]\n" |
| 91 | "zip2 z22.b, z22.b, z18.b\n" |
| 92 | "zip2 z21.b, z21.b, z16.b\n" |
| 93 | "ld1b { z19.b }, p1/Z, [x26, #1, MUL VL]\n" |
| 94 | "ld1b { z18.b }, p1/Z, [x25, #1, MUL VL]\n" |
| 95 | "zip1 z29.b, z25.b, z19.b\n" |
| 96 | "zip1 z28.b, z24.b, z18.b\n" |
| 97 | "ld1b { z17.b }, p1/Z, [x24, #1, MUL VL]\n" |
| 98 | "ld1b { z16.b }, p1/Z, [x23, #1, MUL VL]\n" |
| 99 | "zip1 z27.b, z23.b, z17.b\n" |
| 100 | "zip1 z26.b, z20.b, z16.b\n" |
| 101 | "zip2 z1.b, z25.b, z19.b\n" |
| 102 | "zip2 z25.b, z23.b, z17.b\n" |
| 103 | "addvl x10, x10, #2\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 104 | "addvl x9, x9, #2\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 105 | "zip2 z24.b, z24.b, z18.b\n" |
| 106 | "zip2 z16.b, z20.b, z16.b\n" |
| 107 | "addvl x28, x28, #2\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 108 | "addvl x27, x27, #2\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 109 | "zip1 z0.b, z5.b, z3.b\n" |
| 110 | "zip1 z17.b, z4.b, z31.b\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 111 | "addvl x26, x26, #2\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 112 | "addvl x25, x25, #2\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 113 | "zip2 z20.b, z5.b, z3.b\n" |
| 114 | "zip2 z19.b, z4.b, z31.b\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 115 | "addvl x24, x24, #2\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 116 | "addvl x23, x23, #2\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 117 | "zip1 z31.b, z2.b, z30.b\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 118 | "zip1 z18.b, z22.b, z21.b\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 119 | "zip2 z30.b, z2.b, z30.b\n" |
| 120 | "zip2 z23.b, z22.b, z21.b\n" |
| 121 | "zip1 z22.b, z29.b, z27.b\n" |
| 122 | "zip1 z21.b, z28.b, z26.b\n" |
| 123 | "zip2 z29.b, z29.b, z27.b\n" |
| 124 | "zip2 z28.b, z28.b, z26.b\n" |
| 125 | "zip1 z27.b, z1.b, z25.b\n" |
| 126 | "zip1 z26.b, z24.b, z16.b\n" |
| 127 | "zip2 z25.b, z1.b, z25.b\n" |
| 128 | "zip2 z24.b, z24.b, z16.b\n" |
| 129 | "zip1 z16.b, z0.b, z17.b\n" |
| 130 | "zip2 z17.b, z0.b, z17.b\n" |
| 131 | "st1b { z16.b }, p1, [x20]\n" |
| 132 | "zip1 z16.b, z20.b, z19.b\n" |
| 133 | "zip2 z20.b, z20.b, z19.b\n" |
| 134 | "st1b { z17.b }, p1, [x20, #1, MUL VL]\n" |
| 135 | "zip1 z19.b, z31.b, z18.b\n" |
| 136 | "zip2 z18.b, z31.b, z18.b\n" |
| 137 | "st1b { z16.b }, p1, [x20, #2, MUL VL]\n" |
| 138 | "zip1 z17.b, z30.b, z23.b\n" |
| 139 | "zip2 z16.b, z30.b, z23.b\n" |
| 140 | "st1b { z20.b }, p1, [x20, #3, MUL VL]\n" |
| 141 | "st1b { z19.b }, p1, [x20, #4, MUL VL]\n" |
| 142 | "zip1 z23.b, z22.b, z21.b\n" |
| 143 | "zip2 z22.b, z22.b, z21.b\n" |
| 144 | "st1b { z18.b }, p1, [x20, #5, MUL VL]\n" |
| 145 | "zip1 z21.b, z29.b, z28.b\n" |
| 146 | "zip2 z20.b, z29.b, z28.b\n" |
| 147 | "st1b { z17.b }, p1, [x20, #6, MUL VL]\n" |
| 148 | "zip1 z19.b, z27.b, z26.b\n" |
| 149 | "zip2 z18.b, z27.b, z26.b\n" |
| 150 | "st1b { z16.b }, p1, [x20, #7, MUL VL]\n" |
| 151 | "add x20, x20, %x[out_stride]\n" |
| 152 | "zip1 z17.b, z25.b, z24.b\n" |
| 153 | "zip2 z16.b, z25.b, z24.b\n" |
| 154 | "st1b { z23.b }, p1, [x20]\n" |
| 155 | "st1b { z22.b }, p1, [x20, #1, MUL VL]\n" |
| 156 | "st1b { z21.b }, p1, [x20, #2, MUL VL]\n" |
| 157 | "st1b { z20.b }, p1, [x20, #3, MUL VL]\n" |
| 158 | "st1b { z19.b }, p1, [x20, #4, MUL VL]\n" |
| 159 | "st1b { z18.b }, p1, [x20, #5, MUL VL]\n" |
| 160 | "st1b { z17.b }, p1, [x20, #6, MUL VL]\n" |
| 161 | "st1b { z16.b }, p1, [x20, #7, MUL VL]\n" |
| 162 | "add x20, x20, %x[out_stride]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 163 | "bge 2b\n" |
| 164 | "3:" // Main row loop: Unroll column loop skip |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 165 | "cbz x22, 5f\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 166 | "4:" // Main row loop: Column loop |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 167 | "whilelt p0.b, XZR, x22\n" |
| 168 | "ld1b { z25.b }, p0/Z, [x10]\n" |
| 169 | "ld1b { z27.b }, p0/Z, [x9]\n" |
| 170 | "decd x22, ALL, MUL #8\n" |
| 171 | "ld1b { z26.b }, p0/Z, [x28]\n" |
| 172 | "ld1b { z24.b }, p0/Z, [x27]\n" |
| 173 | "cmp x22, #0x0\n" |
| 174 | "addvl x10, x10, #1\n" |
| 175 | "ld1b { z22.b }, p0/Z, [x26]\n" |
| 176 | "ld1b { z21.b }, p0/Z, [x25]\n" |
| 177 | "zip1 z20.b, z25.b, z22.b\n" |
| 178 | "zip1 z23.b, z27.b, z21.b\n" |
| 179 | "ld1b { z17.b }, p0/Z, [x24]\n" |
| 180 | "ld1b { z16.b }, p0/Z, [x23]\n" |
| 181 | "zip1 z19.b, z26.b, z17.b\n" |
| 182 | "zip1 z18.b, z24.b, z16.b\n" |
| 183 | "zip2 z25.b, z25.b, z22.b\n" |
| 184 | "zip2 z22.b, z26.b, z17.b\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 185 | "addvl x9, x9, #1\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 186 | "addvl x28, x28, #1\n" |
| 187 | "zip2 z21.b, z27.b, z21.b\n" |
| 188 | "zip2 z16.b, z24.b, z16.b\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 189 | "addvl x27, x27, #1\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 190 | "addvl x26, x26, #1\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 191 | "zip1 z24.b, z20.b, z19.b\n" |
| 192 | "zip1 z17.b, z23.b, z18.b\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 193 | "addvl x25, x25, #1\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 194 | "addvl x24, x24, #1\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 195 | "zip2 z20.b, z20.b, z19.b\n" |
| 196 | "zip2 z19.b, z23.b, z18.b\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 197 | "addvl x23, x23, #1\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 198 | "zip1 z23.b, z25.b, z22.b\n" |
| 199 | "zip1 z18.b, z21.b, z16.b\n" |
| 200 | "zip2 z22.b, z25.b, z22.b\n" |
| 201 | "zip2 z21.b, z21.b, z16.b\n" |
| 202 | "zip1 z16.b, z24.b, z17.b\n" |
| 203 | "zip2 z17.b, z24.b, z17.b\n" |
| 204 | "st1b { z16.b }, p1, [x20]\n" |
| 205 | "zip1 z16.b, z20.b, z19.b\n" |
| 206 | "zip2 z20.b, z20.b, z19.b\n" |
| 207 | "st1b { z17.b }, p1, [x20, #1, MUL VL]\n" |
| 208 | "zip1 z19.b, z23.b, z18.b\n" |
| 209 | "zip2 z18.b, z23.b, z18.b\n" |
| 210 | "st1b { z16.b }, p1, [x20, #2, MUL VL]\n" |
| 211 | "zip1 z17.b, z22.b, z21.b\n" |
| 212 | "zip2 z16.b, z22.b, z21.b\n" |
| 213 | "st1b { z20.b }, p1, [x20, #3, MUL VL]\n" |
| 214 | "st1b { z19.b }, p1, [x20, #4, MUL VL]\n" |
| 215 | "st1b { z18.b }, p1, [x20, #5, MUL VL]\n" |
| 216 | "st1b { z17.b }, p1, [x20, #6, MUL VL]\n" |
| 217 | "st1b { z16.b }, p1, [x20, #7, MUL VL]\n" |
| 218 | "add x20, x20, %x[out_stride]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 219 | "bgt 4b\n" |
| 220 | "5:" // Main row loop: Column loop skip |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 221 | "cmp %x[height], #0x1\n" |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 222 | "addvl %x[out], %x[out], #8\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 223 | "bge 1b\n" |
| 224 | : [height] "+&r" (height), [in] "+&r" (in), [out] "+&r" (out) |
| 225 | : [in_stride] "r" (in_stride), [out_stride] "r" (out_stride), [pad_row] "r" (pad_row), [width] "r" (width) |
Michael Tyler | 7d9a626 | 2023-02-01 16:37:07 +0000 | [diff] [blame] | 226 | : "cc", "memory", "p0", "p1", "x9", "x10", "x20", "x21", "x22", "x23", "x24", "x25", "x26", "x27", "x28", "z0", "z1", "z2", "z3", "z4", "z5", "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 227 | ); |
| 228 | } |
| 229 | |
| 230 | } // anonymous namespace |
| 231 | |
| 232 | template<> |
| 233 | void Transform<8, 8, true, VLType::SVE>( |
| 234 | uint8_t *out, const uint8_t *in, int stride, int x0, int xmax, int k0, int kmax) |
| 235 | { |
| 236 | sve_transpose_interleave_8VL_1x8( |
| 237 | reinterpret_cast<uint8_t *>(out), |
| 238 | reinterpret_cast<const uint8_t *>(in + k0 * stride + x0), |
| 239 | (xmax-x0) * sizeof(uint8_t) / 1, |
| 240 | stride * sizeof(uint8_t), |
| 241 | (kmax-k0) |
| 242 | ); |
| 243 | } |
| 244 | |
| 245 | template<> |
| 246 | void Transform<8, 8, true, VLType::SVE>( |
| 247 | int8_t *out, const int8_t *in, int stride, int x0, int xmax, int k0, int kmax) |
| 248 | { |
| 249 | sve_transpose_interleave_8VL_1x8( |
| 250 | reinterpret_cast<uint8_t *>(out), |
| 251 | reinterpret_cast<const uint8_t *>(in + k0 * stride + x0), |
| 252 | (xmax-x0) * sizeof(int8_t) / 1, |
| 253 | stride * sizeof(int8_t), |
| 254 | (kmax-k0) |
| 255 | ); |
| 256 | } |
| 257 | |
Michael Tyler | 74921ee | 2023-04-12 17:43:17 +0100 | [diff] [blame^] | 258 | |
| 259 | #endif // defined(ARM_COMPUTE_ENABLE_SVE) |