blob: 83391cc59fc71bcdd479037b706bf3d6f30eae43 [file] [log] [blame]
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +01001/*
Pablo Tello11c3b332018-01-25 15:05:13 +00002 * Copyright (c) 2017-2018 ARM Limited.
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +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 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
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
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.
23 */
24#pragma once
25
26#ifdef __aarch64__
27
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010028#include <arm_neon.h>
29
Pablo Telloeb82fd22018-02-23 13:43:50 +000030#include "../asmlib.hpp"
31
Anthony Barbier5f707732018-07-03 16:22:02 +010032template<>
33template<typename T>
34inline void TransformImpl<8, 1, false, 4, 4>::Transform(T *out, const T *in, int ldin, int y0, int ymax, int k0, int kmax) {
35 uint32_t *outptr = (uint32_t *)out;
36 const uint32_t *inptr = (uint32_t *)in;
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010037
38 uint32_t zerobuff[8];
39
Anthony Barbier5f707732018-07-03 16:22:02 +010040 for (int y=y0; y<ymax; y+=8) {
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010041 const uint32_t *inptr0 = inptr + y * ldin + k0;
42 const uint32_t *inptr1 = inptr0 + ldin;
43 const uint32_t *inptr2 = inptr1 + ldin;
44 const uint32_t *inptr3 = inptr2 + ldin;
45 const uint32_t *inptr4 = inptr3 + ldin;
46 const uint32_t *inptr5 = inptr4 + ldin;
47 const uint32_t *inptr6 = inptr5 + ldin;
48 const uint32_t *inptr7 = inptr6 + ldin;
49
50 prefetch_2x(inptr0);
51 prefetch_2x(inptr1);
52 prefetch_2x(inptr2);
53 prefetch_2x(inptr3);
54 prefetch_2x(inptr4);
55 prefetch_2x(inptr5);
56 prefetch_2x(inptr6);
57 prefetch_2x(inptr7);
58
Anthony Barbier5f707732018-07-03 16:22:02 +010059 int x=(kmax-k0);
60 for (;x>7;x-=8) {
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010061 /* Cope with ragged cases by copying from a buffer of zeroes instead */
Anthony Barbier5f707732018-07-03 16:22:02 +010062 if ((y + 7) >= ymax) {
63 switch ((y + 7) - ymax) {
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010064 /* Everything falls through in here */
65 case 6:
66 inptr1 = zerobuff;
67 case 5:
68 inptr2 = zerobuff;
69 case 4:
70 inptr3 = zerobuff;
71 case 3:
72 inptr4 = zerobuff;
73 case 2:
74 inptr5 = zerobuff;
75 case 1:
76 inptr6 = zerobuff;
77 case 0:
78 inptr7 = zerobuff;
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010079 break;
Pablo Telloeb82fd22018-02-23 13:43:50 +000080
81 default:
82 UNREACHABLE("Impossible.");
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010083 }
84 }
85
Anthony Barbier5f707732018-07-03 16:22:02 +010086 __asm __volatile (
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010087 // Load up 8 elements (2 vectors) from each of 8 sources.
88 "LDP q0, q1, [%[inptr0]], #32\n" // q0=A0A1A2A3
89 "LDP q2, q3, [%[inptr1]], #32\n" // q2=B0B1B2B3
90 "LDP q4, q5, [%[inptr2]], #32\n" // q4=C0C1C2C3
Anthony Barbier5f707732018-07-03 16:22:02 +010091 "ZIP1 v16.4s, v0.4s, v4.4s\n" // q16=A0C0A1C1
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010092 ASM_PREFETCH("[%[inptr0], #128]")
93 "LDP q6, q7, [%[inptr3]], #32\n" // q6=D0D1D2D3
Anthony Barbier5f707732018-07-03 16:22:02 +010094 "ZIP1 v17.4s, v2.4s, v6.4s\n" // q17=B0D0B1D1
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010095 "LDP q8, q9, [%[inptr4]], #32\n"
96 "LDP q10, q11, [%[inptr5]], #32\n"
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010097 "LDP q12, q13, [%[inptr6]], #32\n"
Anthony Barbier5f707732018-07-03 16:22:02 +010098 "ZIP1 v18.4s, v8.4s, v12.4s\n"
99 ASM_PREFETCH("[%[inptr1], #128]")
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100100 "LDP q14, q15, [%[inptr7]], #32\n"
101 "ZIP1 v19.4s, v10.4s, v14.4s\n"
102
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100103 "ZIP1 v20.4s, v16.4s, v17.4s\n" // q20=A0B0C0D0
Pablo Tello11c3b332018-01-25 15:05:13 +0000104 ASM_PREFETCH("[%[inptr2], #128]")
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100105 "ZIP1 v21.4s, v18.4s, v19.4s\n"
106 "ZIP2 v22.4s, v16.4s, v17.4s\n"
107 "ZIP2 v23.4s, v18.4s, v19.4s\n"
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100108
Anthony Barbier5f707732018-07-03 16:22:02 +0100109 "ZIP2 v16.4s, v0.4s, v4.4s\n"
110 ASM_PREFETCH("[%[inptr3], #128]")
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100111 "ZIP2 v17.4s, v2.4s, v6.4s\n"
112 "STP q20, q21, [%[outptr]], #32\n" // Write back the first element of each source
113
114 "ZIP2 v18.4s, v8.4s, v12.4s\n"
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100115 "ZIP2 v19.4s, v10.4s, v14.4s\n"
116 "STP q22, q23, [%[outptr]], #32\n" // Write back the second element of each source
117
Anthony Barbier5f707732018-07-03 16:22:02 +0100118 "ZIP1 v20.4s, v16.4s, v17.4s\n"
119 ASM_PREFETCH("[%[inptr4], #128]")
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100120 "ZIP1 v21.4s, v18.4s, v19.4s\n"
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100121 "ZIP2 v22.4s, v16.4s, v17.4s\n"
122 "ZIP2 v23.4s, v18.4s, v19.4s\n"
123
Anthony Barbier5f707732018-07-03 16:22:02 +0100124 "ZIP1 v16.4s, v1.4s, v5.4s\n"
125 ASM_PREFETCH("[%[inptr5], #128]")
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100126 "ZIP1 v17.4s, v3.4s, v7.4s\n"
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100127 "STP q20, q21, [%[outptr]], #32\n" // Third element
128
129 "ZIP1 v18.4s, v9.4s, v13.4s\n"
130 "ZIP1 v19.4s, v11.4s, v15.4s\n"
131 "STP q22, q23, [%[outptr]], #32\n" // Fourth element
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100132
133 "ZIP1 v20.4s, v16.4s, v17.4s\n"
134 "ZIP1 v21.4s, v18.4s, v19.4s\n"
Anthony Barbier5f707732018-07-03 16:22:02 +0100135 "ZIP2 v22.4s, v16.4s, v17.4s\n"
136 ASM_PREFETCH("[%[inptr6], #128]")
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100137 "ZIP2 v23.4s, v18.4s, v19.4s\n"
138
139 "ZIP2 v16.4s, v1.4s, v5.4s\n"
140 "ZIP2 v17.4s, v3.4s, v7.4s\n"
141 "STP q20, q21, [%[outptr]], #32\n" // Fifth element
142
Anthony Barbier5f707732018-07-03 16:22:02 +0100143 "ZIP2 v18.4s, v9.4s, v13.4s\n"
144 ASM_PREFETCH("[%[inptr7], #128]")
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100145 "ZIP2 v19.4s, v11.4s, v15.4s\n"
146 "STP q22, q23, [%[outptr]], #32\n" // Sixth element
147
148 "ZIP1 v20.4s, v16.4s, v17.4s\n"
149 "ZIP1 v21.4s, v18.4s, v19.4s\n"
150 "STP q20, q21, [%[outptr]], #32\n" // Seventh element
151
152 "ZIP2 v22.4s, v16.4s, v17.4s\n"
153 "ZIP2 v23.4s, v18.4s, v19.4s\n"
154 "STP q22, q23, [%[outptr]], #32\n" // Eighth element
Anthony Barbier5f707732018-07-03 16:22:02 +0100155 : [inptr0] "+r" (inptr0), [inptr1] "+r" (inptr1), [inptr2] "+r" (inptr2), [inptr3] "+r" (inptr3),
156 [inptr4] "+r" (inptr4), [inptr5] "+r" (inptr5), [inptr6] "+r" (inptr6), [inptr7] "+r" (inptr7), [outptr] "+r" (outptr)
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100157 :
158 : "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "v12",
Anthony Barbier5f707732018-07-03 16:22:02 +0100159 "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23"
160 );
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100161 }
162
Anthony Barbier5f707732018-07-03 16:22:02 +0100163 for (;x>0;x--) {
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100164 *outptr++ = *inptr0++;
165 *outptr++ = *inptr1++;
166 *outptr++ = *inptr2++;
167 *outptr++ = *inptr3++;
168 *outptr++ = *inptr4++;
169 *outptr++ = *inptr5++;
170 *outptr++ = *inptr6++;
171 *outptr++ = *inptr7++;
172 }
173 }
174}
175
Anthony Barbier5f707732018-07-03 16:22:02 +0100176#endif // __aarch64__