blob: 0399f8becc60226b84f4198321483cf5c3a621aa [file] [log] [blame]
Georgios Pinitas4ee8b152021-07-16 16:16:43 +01001/*
David Svantesson8964c892023-05-02 13:24:08 +00002 * Copyright (c) 2021-2023 Arm Limited.
Georgios Pinitas4ee8b152021-07-16 16:16:43 +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 *
David Svantesson8964c892023-05-02 13:24:08 +000013 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
Georgios Pinitas4ee8b152021-07-16 16:16:43 +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
David Svantesson8964c892023-05-02 13:24:08 +000020 * 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 Pinitas4ee8b152021-07-16 16:16:43 +010023 */
24
25#pragma once
26
Michael Tyler74921ee2023-04-12 17:43:17 +010027#if defined(__aarch64__)
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010028
29namespace {
30
31void 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 Tyler7d9a6262023-02-01 16:37:07 +000039 "mov x25, %x[in]\n"
40 "mov x24, %x[width]\n"
David Svantesson8964c892023-05-02 13:24:08 +000041 "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 Tyler7d9a6262023-02-01 16:37:07 +000046 "cmp x24, #0x4\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010047 "add %x[in], x20, %x[in_stride]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010048 "blt 3f\n"
49 "2:" // Main row loop: Column loop
Michael Tyler7d9a6262023-02-01 16:37:07 +000050 "ldr q19, [x25], #0x10\n"
David Svantesson8964c892023-05-02 13:24:08 +000051 "ldr q18, [x22], #0x10\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000052 "sub x24, x24, #0x4\n"
David Svantesson8964c892023-05-02 13:24:08 +000053 "ldr q17, [x21], #0x10\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010054 "ldr q16, [x20], #0x10\n"
David Svantesson8964c892023-05-02 13:24:08 +000055 "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 Pinitas4ee8b152021-07-16 16:16:43 +010061 "bge 2b\n"
62 "3:" // Main row loop: Column loop skip
David Svantesson8964c892023-05-02 13:24:08 +000063 "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 Pinitas4ee8b152021-07-16 16:16:43 +010069 "4:" // Main row loop: width 1 loop: loop
Michael Tyler7d9a6262023-02-01 16:37:07 +000070 "ldr s19, [x25], #0x4\n"
David Svantesson8964c892023-05-02 13:24:08 +000071 "ldr s18, [x22], #0x4\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000072 "sub x24, x24, #0x1\n"
David Svantesson8964c892023-05-02 13:24:08 +000073 "ldr s17, [x21], #0x4\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010074 "ldr s16, [x20], #0x4\n"
David Svantesson8964c892023-05-02 13:24:08 +000075 "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 Pinitas4ee8b152021-07-16 16:16:43 +010081 "bge 4b\n"
David Svantesson8964c892023-05-02 13:24:08 +000082 "5:" // Main row loop: odd col skip
Michael Tylerbe13cea2023-01-17 11:04:14 +000083 "cmp %x[height], #0x4\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000084 "add %x[out], %x[out], #0x40\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010085 "bge 1b\n"
86 "cbz %x[height], 12f\n"
87 "6:" // Main loop skip
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010088 "7:" // Tail row loop: Head
Michael Tyler7d9a6262023-02-01 16:37:07 +000089 "mov x20, %x[width]\n"
90 "mov x25, %x[in]\n"
David Svantesson8964c892023-05-02 13:24:08 +000091 "mov x23, %x[out]\n"
92 "sub %x[height], %x[height], #0x1\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000093 "cmp x20, #0x4\n"
94 "add %x[in], x25, %x[in_stride]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010095 "blt 9f\n"
96 "8:" // Tail row loop: Column loop
Michael Tyler7d9a6262023-02-01 16:37:07 +000097 "ldr q16, [x25], #0x10\n"
98 "sub x20, x20, #0x4\n"
99 "cmp x20, #0x4\n"
David Svantesson8964c892023-05-02 13:24:08 +0000100 "str q16, [x23, #0x0]\n"
101 "add x23, x23, %x[out_stride]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100102 "bge 8b\n"
103 "9:" // Tail row loop: Column loop skip
David Svantesson8964c892023-05-02 13:24:08 +0000104 "cbz x20, 11f\n"
105 "movi v16.4s, #0x0\n"
106 "str q16, [x23, #0x0]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100107 "10:" // Tail row loop: width 1 loop: loop
Michael Tyler7d9a6262023-02-01 16:37:07 +0000108 "ldr s16, [x25], #0x4\n"
109 "sub x20, x20, #0x1\n"
110 "cmp x20, #0x1\n"
David Svantesson8964c892023-05-02 13:24:08 +0000111 "str s16, [x23, #0x0]\n"
112 "add x23, x23, #0x4\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100113 "bge 10b\n"
David Svantesson8964c892023-05-02 13:24:08 +0000114 "11:" // Tail row loop: odd col skip
Michael Tylerbe13cea2023-01-17 11:04:14 +0000115 "cmp %x[height], #0x1\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000116 "add %x[out], %x[out], #0x10\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100117 "bge 7b\n"
118 "12:" // Done
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100119 : [height] "+&r" (height), [in] "+&r" (in), [out] "+&r" (out)
120 : [in_stride] "r" (in_stride), [out_stride] "r" (out_stride), [width] "r" (width)
Michael Tyler7d9a6262023-02-01 16:37:07 +0000121 : "cc", "memory", "v16", "v17", "v18", "v19", "x20", "x21", "x22", "x23", "x24", "x25"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100122 );
123}
124
125} // anonymous namespace
126
127template<>
128void 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 Tyler74921ee2023-04-12 17:43:17 +0100140
141#endif // defined(__aarch64__)