blob: 2df5d1bd28348767321cd4e6a4bea646aee551b5 [file] [log] [blame]
Pablo Telloeb82fd22018-02-23 13:43:50 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2018 Arm Limited.
Pablo Telloeb82fd22018-02-23 13:43:50 +00003 *
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 __arm__
27
28#include <arm_neon.h>
29
30#include "../asmlib.hpp"
31
Anthony Barbier5f707732018-07-03 16:22:02 +010032template<>
33template<typename T>
David Manselld93991e2018-07-06 14:52:52 +010034inline void TransformImpl<6, 1, false, 4, 4, false>::Transform(T *out, const T *in, int ldin, int y0, int ymax, int k0, int kmax) {
Anthony Barbier5f707732018-07-03 16:22:02 +010035 uint32_t *outptr = reinterpret_cast<uint32_t *>(out);
36 const uint32_t *inptr = reinterpret_cast<const uint32_t *>(in);
Georgios Pinitas572576a2019-09-24 14:42:23 +010037 bool first = true;
Pablo Telloeb82fd22018-02-23 13:43:50 +000038
Georgios Pinitasdd0bf482019-05-23 11:07:33 +010039 uint32_t zerobuff[16] = { 0 }; // 8 for asm loop plus up to 7 for overflow loop
Pablo Telloeb82fd22018-02-23 13:43:50 +000040
Anthony Barbier5f707732018-07-03 16:22:02 +010041 for (int y=y0; y<ymax; y+=6) {
Pablo Telloeb82fd22018-02-23 13:43:50 +000042 const uint32_t *inptr0 = inptr + y * ldin + k0;
43 const uint32_t *inptr1 = inptr0 + ldin;
44 const uint32_t *inptr2 = inptr1 + ldin;
45 const uint32_t *inptr3 = inptr2 + ldin;
46 const uint32_t *inptr4 = inptr3 + ldin;
47 const uint32_t *inptr5 = inptr4 + ldin;
48
49 //prefetch_2x(inptr0);
50 //prefetch_2x(inptr1);
51 //prefetch_2x(inptr2);
52 //prefetch_2x(inptr3);
53 //prefetch_2x(inptr4);
54 //prefetch_2x(inptr5);
55
Anthony Barbier5f707732018-07-03 16:22:02 +010056 int x=(kmax-k0);
Georgios Pinitas572576a2019-09-24 14:42:23 +010057 for (;(x>7) || first;x-=8) {
Pablo Telloeb82fd22018-02-23 13:43:50 +000058 /* Cope with ragged cases by copying from a buffer of zeroes instead */
Georgios Pinitas572576a2019-09-24 14:42:23 +010059 /* 'first' forces this to always run at least once, needed if the total size is <=7. */
Anthony Barbier5f707732018-07-03 16:22:02 +010060 if ((y + 5) >= ymax) {
61 switch ((y + 5) - ymax) {
Pablo Telloeb82fd22018-02-23 13:43:50 +000062 case 4:
63 inptr1 = zerobuff;
Georgios Pinitas37d080f2019-06-21 18:43:12 +010064 // fall through
Pablo Telloeb82fd22018-02-23 13:43:50 +000065 case 3:
66 inptr2 = zerobuff;
Georgios Pinitas37d080f2019-06-21 18:43:12 +010067 // fall through
Pablo Telloeb82fd22018-02-23 13:43:50 +000068 case 2:
69 inptr3 = zerobuff;
Georgios Pinitas37d080f2019-06-21 18:43:12 +010070 // fall through
Pablo Telloeb82fd22018-02-23 13:43:50 +000071 case 1:
72 inptr4 = zerobuff;
Georgios Pinitas37d080f2019-06-21 18:43:12 +010073 // fall through
Pablo Telloeb82fd22018-02-23 13:43:50 +000074 case 0:
75 inptr5 = zerobuff;
Pablo Telloeb82fd22018-02-23 13:43:50 +000076 break;
Pablo Tello99ef8402018-03-20 16:46:55 +000077
78 default:
79 UNREACHABLE("Impossible.");
Pablo Telloeb82fd22018-02-23 13:43:50 +000080 }
81 }
82
Georgios Pinitas572576a2019-09-24 14:42:23 +010083 if (first) {
84 if (x<=7) {
85 break;
86 }
87
88 first = false;
89 }
Anthony Barbier5f707732018-07-03 16:22:02 +010090
91 __asm __volatile (
Pablo Telloeb82fd22018-02-23 13:43:50 +000092 // Load up 8 elements (2 vectors) from each of 8 sources.
Anthony Barbier5f707732018-07-03 16:22:02 +010093 "VLD1.32 {d0-d3}, [%[inptr0]]!\n" // q0=A0A1A2A3
94 "VLD1.32 {d4-d7}, [%[inptr1]]!\n" // q2=B0B1B2B3
95 "VLD1.32 {d8-d11}, [%[inptr2]]!\n" // q4=C0C1C2C3
96 "VZIP.32 q0, q4\n" // q0=A0C0A1C1, q4 = A2C2A3C3
97 "VLD1.32 {d12-d15}, [%[inptr3]]!\n" // q6=D0D1D2D3
98 "VZIP.32 q2, q6\n" // q2=B0D0B1D1, q6 = B2D2B3D3
99 "VLD1.32 {d16-d19}, [%[inptr4]]!\n"
100 "VLD1.32 {d20-d23}, [%[inptr5]]!\n"
101 "VZIP.32 q8, q10\n" // q8=E0F0E1F1, q10 = E2F2E3F3
Pablo Telloeb82fd22018-02-23 13:43:50 +0000102 ASM_PREFETCH("[%[inptr0], #128]")
Anthony Barbier5f707732018-07-03 16:22:02 +0100103 "VZIP.32 q0, q2\n" // q0 = A0B0C0D0, q2 = A1B1C1D1
Pablo Telloeb82fd22018-02-23 13:43:50 +0000104
105 // Store first elements
Anthony Barbier5f707732018-07-03 16:22:02 +0100106 "VST1.32 {d0-d1}, [%[outptr]]!\n"
107 "VST1.32 {d16}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000108
Anthony Barbier5f707732018-07-03 16:22:02 +0100109 "VZIP.32 q4, q6\n" // q4 = A2B2C2D2, q6 = A3B3C3D3
Pablo Telloeb82fd22018-02-23 13:43:50 +0000110
111 // Store second elements
Anthony Barbier5f707732018-07-03 16:22:02 +0100112 "VST1.32 {d4-d5}, [%[outptr]]!\n"
113 "VZIP.32 q1, q5\n"
114 ASM_PREFETCH("[%[inptr1], #128]")
115 "VST1.32 {d17}, [%[outptr]]!\n"
116 "VZIP.32 q3, q7\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000117
118 // Store third elements
Anthony Barbier5f707732018-07-03 16:22:02 +0100119 "VZIP.32 q9, q11\n"
120 "VST1.32 {d8-d9}, [%[outptr]]!\n"
121 "VZIP.32 q1, q3\n"
122 ASM_PREFETCH("[%[inptr2], #128]")
123 "VST1.32 {d20}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000124
125 // Store fourth elements
Anthony Barbier5f707732018-07-03 16:22:02 +0100126 "VZIP.32 q5, q7\n"
127 "VST1.32 {d12-d13}, [%[outptr]]!\n"
128 ASM_PREFETCH("[%[inptr3], #128]")
129 "VST1.32 {d21}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000130
131 // Fifth
Anthony Barbier5f707732018-07-03 16:22:02 +0100132 "VST1.32 {d2-d3}, [%[outptr]]!\n"
133 ASM_PREFETCH("[%[inptr4], #128]")
134 "VST1.32 {d18}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000135
136 // Sixth
Anthony Barbier5f707732018-07-03 16:22:02 +0100137 "VST1.32 {d6-d7}, [%[outptr]]!\n"
138 ASM_PREFETCH("[%[inptr5], #128]")
139 "VST1.32 {d19}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000140
141 // Seventh
Anthony Barbier5f707732018-07-03 16:22:02 +0100142 "VST1.32 {d10-d11}, [%[outptr]]!\n"
143 "VST1.32 {d22}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000144
145 // Eighth
Anthony Barbier5f707732018-07-03 16:22:02 +0100146 "VST1.32 {d14-d15}, [%[outptr]]!\n"
147 "VST1.32 {d23}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000148
Anthony Barbier5f707732018-07-03 16:22:02 +0100149 : [inptr0] "+r" (inptr0), [inptr1] "+r" (inptr1), [inptr2] "+r" (inptr2), [inptr3] "+r" (inptr3),
150 [inptr4] "+r" (inptr4), [inptr5] "+r" (inptr5), [outptr] "+r" (outptr)
Pablo Telloeb82fd22018-02-23 13:43:50 +0000151 :
Georgios Pinitasd636bc52018-11-07 16:35:35 +0000152 : "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", "q12", "memory"
Anthony Barbier5f707732018-07-03 16:22:02 +0100153 );
Pablo Telloeb82fd22018-02-23 13:43:50 +0000154 }
155
Anthony Barbier5f707732018-07-03 16:22:02 +0100156 for (;x>0;x--) {
Pablo Telloeb82fd22018-02-23 13:43:50 +0000157 *outptr++ = *inptr0++;
158 *outptr++ = *inptr1++;
159 *outptr++ = *inptr2++;
160 *outptr++ = *inptr3++;
161 *outptr++ = *inptr4++;
162 *outptr++ = *inptr5++;
163 }
164 }
165}
166
Anthony Barbier5f707732018-07-03 16:22:02 +0100167#endif // __arm__