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