Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 1 | /* |
Michael Tyler | ba20975 | 2022-12-15 12:39:29 +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 | ba20975 | 2022-12-15 12:39:29 +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 | ba20975 | 2022-12-15 12:39:29 +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 | |
| 27 | #ifdef __aarch64__ |
| 28 | |
| 29 | namespace { |
| 30 | |
| 31 | void a64_transpose_interleave_16(uint32_t *out, const uint32_t *in, size_t width, size_t in_stride, size_t height) |
| 32 | { |
| 33 | size_t out_stride = 4 * height * sizeof(uint32_t); |
| 34 | |
| 35 | __asm__ __volatile__( |
| 36 | "cmp %x[height], #0x4\n" |
| 37 | "blt 6f\n" |
| 38 | "1:" // Main row loop: Head |
Michael Tyler | ba20975 | 2022-12-15 12:39:29 +0000 | [diff] [blame] | 39 | "mov x25, %x[in]\n" |
| 40 | "mov x24, %x[width]\n" |
| 41 | "add x23, x25, %x[in_stride]\n" |
| 42 | "add x22, x23, %x[in_stride]\n" |
| 43 | "add x20, x22, %x[in_stride]\n" |
| 44 | "cmp x24, #0x4\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 45 | "add %x[in], x20, %x[in_stride]\n" |
Michael Tyler | ba20975 | 2022-12-15 12:39:29 +0000 | [diff] [blame] | 46 | "mov x21, %x[out]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 47 | "sub %x[height], %x[height], #0x4\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 48 | "blt 3f\n" |
| 49 | "2:" // Main row loop: Column loop |
Michael Tyler | ba20975 | 2022-12-15 12:39:29 +0000 | [diff] [blame] | 50 | "ldr q19, [x25], #0x10\n" |
| 51 | "ldr q18, [x23], #0x10\n" |
| 52 | "sub x24, x24, #0x4\n" |
| 53 | "cmp x24, #0x4\n" |
| 54 | "ldr q17, [x22], #0x10\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 55 | "ldr q16, [x20], #0x10\n" |
Michael Tyler | ba20975 | 2022-12-15 12:39:29 +0000 | [diff] [blame] | 56 | "str q19, [x21, #0x0]\n" |
| 57 | "str q18, [x21, #0x10]\n" |
| 58 | "str q17, [x21, #0x20]\n" |
| 59 | "str q16, [x21, #0x30]\n" |
| 60 | "add x21, x21, %x[out_stride]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 61 | "bge 2b\n" |
| 62 | "3:" // Main row loop: Column loop skip |
Michael Tyler | ba20975 | 2022-12-15 12:39:29 +0000 | [diff] [blame] | 63 | "cmp x24, #0x1\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 64 | "blt 5f\n" |
| 65 | "4:" // Main row loop: width 1 loop: loop |
Michael Tyler | ba20975 | 2022-12-15 12:39:29 +0000 | [diff] [blame] | 66 | "ldr s19, [x25], #0x4\n" |
| 67 | "ldr s18, [x23], #0x4\n" |
| 68 | "sub x24, x24, #0x1\n" |
| 69 | "cmp x24, #0x1\n" |
| 70 | "ldr s17, [x22], #0x4\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 71 | "ldr s16, [x20], #0x4\n" |
Michael Tyler | ba20975 | 2022-12-15 12:39:29 +0000 | [diff] [blame] | 72 | "str s19, [x21, #0x0]\n" |
| 73 | "str s18, [x21, #0x10]\n" |
| 74 | "str s17, [x21, #0x20]\n" |
| 75 | "str s16, [x21, #0x30]\n" |
| 76 | "add x21, x21, #0x4\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 77 | "bge 4b\n" |
| 78 | "5:" // Main row loop: width 1 loop: skip |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 79 | "cmp %x[height], #0x4\n" |
Michael Tyler | ba20975 | 2022-12-15 12:39:29 +0000 | [diff] [blame] | 80 | "add %x[out], %x[out], #0x40\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 81 | "bge 1b\n" |
| 82 | "cbz %x[height], 12f\n" |
| 83 | "6:" // Main loop skip |
| 84 | |
| 85 | "7:" // Tail row loop: Head |
Michael Tyler | ba20975 | 2022-12-15 12:39:29 +0000 | [diff] [blame] | 86 | "mov x20, %x[width]\n" |
| 87 | "mov x25, %x[in]\n" |
| 88 | "cmp x20, #0x4\n" |
| 89 | "add %x[in], x25, %x[in_stride]\n" |
| 90 | "mov x21, %x[out]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 91 | "sub %x[height], %x[height], #0x1\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 92 | "blt 9f\n" |
| 93 | "8:" // Tail row loop: Column loop |
Michael Tyler | ba20975 | 2022-12-15 12:39:29 +0000 | [diff] [blame] | 94 | "ldr q16, [x25], #0x10\n" |
| 95 | "sub x20, x20, #0x4\n" |
| 96 | "cmp x20, #0x4\n" |
| 97 | "str q16, [x21, #0x0]\n" |
| 98 | "add x21, x21, %x[out_stride]\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 99 | "bge 8b\n" |
| 100 | "9:" // Tail row loop: Column loop skip |
Michael Tyler | ba20975 | 2022-12-15 12:39:29 +0000 | [diff] [blame] | 101 | "cmp x20, #0x1\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 102 | "blt 11f\n" |
| 103 | "10:" // Tail row loop: width 1 loop: loop |
Michael Tyler | ba20975 | 2022-12-15 12:39:29 +0000 | [diff] [blame] | 104 | "ldr s16, [x25], #0x4\n" |
| 105 | "sub x20, x20, #0x1\n" |
| 106 | "cmp x20, #0x1\n" |
| 107 | "str s16, [x21, #0x0]\n" |
| 108 | "add x21, x21, #0x4\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 109 | "bge 10b\n" |
| 110 | "11:" // Tail row loop: width 1 loop: skip |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 111 | "cmp %x[height], #0x1\n" |
Michael Tyler | ba20975 | 2022-12-15 12:39:29 +0000 | [diff] [blame] | 112 | "add %x[out], %x[out], #0x10\n" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 113 | "bge 7b\n" |
| 114 | "12:" // Done |
| 115 | |
| 116 | : [height] "+&r" (height), [in] "+&r" (in), [out] "+&r" (out) |
| 117 | : [in_stride] "r" (in_stride), [out_stride] "r" (out_stride), [width] "r" (width) |
Michael Tyler | ba20975 | 2022-12-15 12:39:29 +0000 | [diff] [blame] | 118 | : "cc", "memory", "v16", "v17", "v18", "v19", "x20", "x21", "x22", "x23", "x24", "x25" |
Georgios Pinitas | 4ee8b15 | 2021-07-16 16:16:43 +0100 | [diff] [blame] | 119 | ); |
| 120 | } |
| 121 | |
| 122 | } // anonymous namespace |
| 123 | |
| 124 | template<> |
| 125 | void Transform<4, 1, true, VLType::None>( |
| 126 | float *out, const float *in, int stride, int x0, int xmax, int k0, int kmax) |
| 127 | { |
| 128 | a64_transpose_interleave_16( |
| 129 | reinterpret_cast<uint32_t *>(out), |
| 130 | reinterpret_cast<const uint32_t *>(in + k0 * stride + x0), |
| 131 | (xmax-x0) * sizeof(float) / 4, |
| 132 | stride * sizeof(float), |
| 133 | (kmax-k0) |
| 134 | ); |
| 135 | } |
| 136 | |
| 137 | #endif |