Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 1 | /* |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 2 | * Copyright (c) 2021 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 | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all 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 | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 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. |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 23 | */ |
| 24 | |
| 25 | #pragma once |
| 26 | |
| 27 | #ifdef __ARM_FEATURE_SVE |
| 28 | |
| 29 | |
| 30 | namespace { |
| 31 | |
| 32 | void sve_transpose_interleave_4VL(uint16_t *out, const uint16_t *in, size_t width, size_t in_stride, size_t height) |
| 33 | { |
| 34 | size_t out_stride = 4 * height * get_vector_length<uint8_t>(); |
| 35 | |
| 36 | __asm__ __volatile__( |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 37 | "ptrue p3.b\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 38 | "cmp %x[height], #0x4\n" |
| 39 | "blt 4f\n" |
| 40 | "1:" // Main row loop: Head |
| 41 | "mov x26, %x[in]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 42 | "mov x25, %x[out]\n" |
| 43 | "add x24, x26, %x[in_stride]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 44 | "add x23, x24, %x[in_stride]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 45 | "add x22, x23, %x[in_stride]\n" |
| 46 | "add %x[in], x22, %x[in_stride]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 47 | "sub %x[height], %x[height], #0x4\n" |
| 48 | "mov x21, %x[width]\n" |
| 49 | "2:" // Main row loop: Column loop |
| 50 | "mov x20, x21\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 51 | "mov x19, x25\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 52 | "whilelt p0.h, XZR, x20\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 53 | "ld1h { z31.h }, p0/Z, [x26]\n" |
| 54 | "ld1h { z30.h }, p0/Z, [x24]\n" |
| 55 | "dech x20\n" |
| 56 | "ld1h { z29.h }, p0/Z, [x23]\n" |
| 57 | "whilelt p2.h, XZR, x20\n" |
| 58 | "ld1h { z28.h }, p0/Z, [x22]\n" |
| 59 | "dech x20\n" |
| 60 | "ld1h { z27.h }, p2/Z, [x26, #1, MUL VL]\n" |
| 61 | "whilelt p1.h, XZR, x20\n" |
| 62 | "ld1h { z26.h }, p2/Z, [x24, #1, MUL VL]\n" |
| 63 | "dech x20\n" |
| 64 | "ld1h { z25.h }, p1/Z, [x26, #2, MUL VL]\n" |
| 65 | "whilelt p0.h, XZR, x20\n" |
| 66 | "ld1h { z24.h }, p1/Z, [x24, #2, MUL VL]\n" |
| 67 | "add x25, x25, %x[out_stride]\n" |
| 68 | "ld1h { z23.h }, p0/Z, [x26, #3, MUL VL]\n" |
Michael Tyler | ba20975 | 2022-12-15 12:39:29 +0000 | [diff] [blame] | 69 | "addvl x26, x26, #4\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 70 | "ld1h { z22.h }, p0/Z, [x24, #3, MUL VL]\n" |
Michael Tyler | ba20975 | 2022-12-15 12:39:29 +0000 | [diff] [blame] | 71 | "addvl x24, x24, #4\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 72 | "ld1h { z21.h }, p2/Z, [x23, #1, MUL VL]\n" |
| 73 | "dech x21, ALL, MUL #4\n" |
| 74 | "ld1h { z20.h }, p1/Z, [x23, #2, MUL VL]\n" |
| 75 | "cmp x21, #0x0\n" |
| 76 | "ld1h { z19.h }, p0/Z, [x23, #3, MUL VL]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 77 | "addvl x23, x23, #4\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 78 | "ld1h { z18.h }, p2/Z, [x22, #1, MUL VL]\n" |
| 79 | "ld1h { z17.h }, p1/Z, [x22, #2, MUL VL]\n" |
| 80 | "ld1h { z16.h }, p0/Z, [x22, #3, MUL VL]\n" |
| 81 | "addvl x22, x22, #4\n" |
| 82 | "st1h { z31.h }, p3, [x19]\n" |
| 83 | "st1h { z27.h }, p3, [x19, #1, MUL VL]\n" |
| 84 | "st1h { z25.h }, p3, [x19, #2, MUL VL]\n" |
| 85 | "st1h { z23.h }, p3, [x19, #3, MUL VL]\n" |
| 86 | "st1h { z30.h }, p3, [x19, #4, MUL VL]\n" |
| 87 | "st1h { z26.h }, p3, [x19, #5, MUL VL]\n" |
| 88 | "st1h { z24.h }, p3, [x19, #6, MUL VL]\n" |
| 89 | "st1h { z22.h }, p3, [x19, #7, MUL VL]\n" |
| 90 | "addvl x19, x19, #16\n" |
| 91 | "st1h { z29.h }, p3, [x19, #-8, MUL VL]\n" |
| 92 | "st1h { z21.h }, p3, [x19, #-7, MUL VL]\n" |
| 93 | "st1h { z20.h }, p3, [x19, #-6, MUL VL]\n" |
| 94 | "st1h { z19.h }, p3, [x19, #-5, MUL VL]\n" |
| 95 | "st1h { z28.h }, p3, [x19, #-4, MUL VL]\n" |
| 96 | "st1h { z18.h }, p3, [x19, #-3, MUL VL]\n" |
| 97 | "st1h { z17.h }, p3, [x19, #-2, MUL VL]\n" |
| 98 | "st1h { z16.h }, p3, [x19, #-1, MUL VL]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 99 | "bgt 2b\n" |
| 100 | "3:" // Main row loop: Column loop skip |
Michael Tyler | ba20975 | 2022-12-15 12:39:29 +0000 | [diff] [blame] | 101 | "addvl %x[out], %x[out], #16\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 102 | "cmp %x[height], #0x4\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 103 | "bge 1b\n" |
| 104 | "cbz %x[height], 8f\n" |
| 105 | "4:" // Main loop skip |
| 106 | |
| 107 | "5:" // Tail row loop: Head |
| 108 | "mov x26, %x[in]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 109 | "mov x25, %x[out]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 110 | "add %x[in], x26, %x[in_stride]\n" |
| 111 | "sub %x[height], %x[height], #0x1\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 112 | "mov x20, %x[width]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 113 | "6:" // Tail row loop: Column loop |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 114 | "mov x19, x20\n" |
| 115 | "dech x20, ALL, MUL #4\n" |
| 116 | "whilelt p0.h, XZR, x19\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 117 | "ld1h { z19.h }, p0/Z, [x26]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 118 | "dech x19\n" |
| 119 | "whilelt p0.h, XZR, x19\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 120 | "ld1h { z18.h }, p0/Z, [x26, #1, MUL VL]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 121 | "dech x19\n" |
| 122 | "whilelt p0.h, XZR, x19\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 123 | "ld1h { z17.h }, p0/Z, [x26, #2, MUL VL]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 124 | "dech x19\n" |
| 125 | "whilelt p0.h, XZR, x19\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 126 | "ld1h { z16.h }, p0/Z, [x26, #3, MUL VL]\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 127 | "st1h { z19.h }, p3, [x25]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 128 | "addvl x26, x26, #4\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 129 | "st1h { z18.h }, p3, [x25, #1, MUL VL]\n" |
| 130 | "cmp x20, #0x0\n" |
| 131 | "st1h { z17.h }, p3, [x25, #2, MUL VL]\n" |
| 132 | "st1h { z16.h }, p3, [x25, #3, MUL VL]\n" |
| 133 | "add x25, x25, %x[out_stride]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 134 | "bgt 6b\n" |
| 135 | "7:" // Tail row loop: Column loop skip |
Michael Tyler | ba20975 | 2022-12-15 12:39:29 +0000 | [diff] [blame] | 136 | "addvl %x[out], %x[out], #4\n" |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 137 | "cmp %x[height], #0x1\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 138 | "bge 5b\n" |
| 139 | "8:" // Done |
| 140 | |
| 141 | : [height] "+&r" (height), [in] "+&r" (in), [out] "+&r" (out) |
| 142 | : [in_stride] "r" (in_stride), [out_stride] "r" (out_stride), [width] "r" (width) |
Michael Tyler | be13cea | 2023-01-17 11:04:14 +0000 | [diff] [blame] | 143 | : "cc", "memory", "p0", "p1", "p2", "p3", "x19", "x20", "x21", "x22", "x23", "x24", "x25", "x26", "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] | 144 | ); |
| 145 | } |
| 146 | |
| 147 | } // anonymous namespace |
| 148 | |
| 149 | template<> |
| 150 | void Transform<4, 1, true, VLType::SVE>( |
| 151 | float *out, const float *in, int stride, int x0, int xmax, int k0, int kmax) |
| 152 | { |
| 153 | sve_transpose_interleave_4VL( |
| 154 | reinterpret_cast<uint16_t *>(out), |
| 155 | reinterpret_cast<const uint16_t *>(in + k0 * stride + x0), |
| 156 | (xmax-x0) * sizeof(float) / 2, |
| 157 | stride * sizeof(float), |
| 158 | (kmax-k0) |
| 159 | ); |
| 160 | } |
| 161 | |
| 162 | template<> |
| 163 | void Transform<4, 1, true, VLType::SVE>( |
| 164 | __fp16 *out, const __fp16 *in, int stride, int x0, int xmax, int k0, int kmax) |
| 165 | { |
| 166 | sve_transpose_interleave_4VL( |
| 167 | reinterpret_cast<uint16_t *>(out), |
| 168 | reinterpret_cast<const uint16_t *>(in + k0 * stride + x0), |
| 169 | (xmax-x0) * sizeof(__fp16) / 2, |
| 170 | stride * sizeof(__fp16), |
| 171 | (kmax-k0) |
| 172 | ); |
| 173 | } |
| 174 | |
| 175 | template<> |
| 176 | void Transform<4, 1, true, VLType::SVE>( |
| 177 | double *out, const double *in, int stride, int x0, int xmax, int k0, int kmax) |
| 178 | { |
| 179 | sve_transpose_interleave_4VL( |
| 180 | reinterpret_cast<uint16_t *>(out), |
| 181 | reinterpret_cast<const uint16_t *>(in + k0 * stride + x0), |
| 182 | (xmax-x0) * sizeof(double) / 2, |
| 183 | stride * sizeof(double), |
| 184 | (kmax-k0) |
| 185 | ); |
| 186 | } |
| 187 | |
| 188 | #endif |