blob: 20ad301a18224a8dd433a7da69b6cc159e725e5d [file] [log] [blame]
Pablo Telloeb82fd22018-02-23 13:43:50 +00001/*
2 * Copyright (c) 2017-2018 ARM Limited.
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 *
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);
Pablo Telloeb82fd22018-02-23 13:43:50 +000037
Georgios Pinitasdd0bf482019-05-23 11:07:33 +010038 uint32_t zerobuff[16] = { 0 }; // 8 for asm loop plus up to 7 for overflow loop
Pablo Telloeb82fd22018-02-23 13:43:50 +000039
Anthony Barbier5f707732018-07-03 16:22:02 +010040 for (int y=y0; y<ymax; y+=6) {
Pablo Telloeb82fd22018-02-23 13:43:50 +000041 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
48 //prefetch_2x(inptr0);
49 //prefetch_2x(inptr1);
50 //prefetch_2x(inptr2);
51 //prefetch_2x(inptr3);
52 //prefetch_2x(inptr4);
53 //prefetch_2x(inptr5);
54
Anthony Barbier5f707732018-07-03 16:22:02 +010055 int x=(kmax-k0);
56 for (;x>7;x-=8) {
Pablo Telloeb82fd22018-02-23 13:43:50 +000057 /* Cope with ragged cases by copying from a buffer of zeroes instead */
Anthony Barbier5f707732018-07-03 16:22:02 +010058 if ((y + 5) >= ymax) {
59 switch ((y + 5) - ymax) {
Pablo Telloeb82fd22018-02-23 13:43:50 +000060 /* Everything falls through in here */
61 case 4:
62 inptr1 = zerobuff;
63 case 3:
64 inptr2 = zerobuff;
65 case 2:
66 inptr3 = zerobuff;
67 case 1:
68 inptr4 = zerobuff;
69 case 0:
70 inptr5 = zerobuff;
Pablo Telloeb82fd22018-02-23 13:43:50 +000071 break;
Pablo Tello99ef8402018-03-20 16:46:55 +000072
73 default:
74 UNREACHABLE("Impossible.");
Pablo Telloeb82fd22018-02-23 13:43:50 +000075 }
76 }
77
Anthony Barbier5f707732018-07-03 16:22:02 +010078
79 __asm __volatile (
Pablo Telloeb82fd22018-02-23 13:43:50 +000080 // Load up 8 elements (2 vectors) from each of 8 sources.
Anthony Barbier5f707732018-07-03 16:22:02 +010081 "VLD1.32 {d0-d3}, [%[inptr0]]!\n" // q0=A0A1A2A3
82 "VLD1.32 {d4-d7}, [%[inptr1]]!\n" // q2=B0B1B2B3
83 "VLD1.32 {d8-d11}, [%[inptr2]]!\n" // q4=C0C1C2C3
84 "VZIP.32 q0, q4\n" // q0=A0C0A1C1, q4 = A2C2A3C3
85 "VLD1.32 {d12-d15}, [%[inptr3]]!\n" // q6=D0D1D2D3
86 "VZIP.32 q2, q6\n" // q2=B0D0B1D1, q6 = B2D2B3D3
87 "VLD1.32 {d16-d19}, [%[inptr4]]!\n"
88 "VLD1.32 {d20-d23}, [%[inptr5]]!\n"
89 "VZIP.32 q8, q10\n" // q8=E0F0E1F1, q10 = E2F2E3F3
Pablo Telloeb82fd22018-02-23 13:43:50 +000090 ASM_PREFETCH("[%[inptr0], #128]")
Anthony Barbier5f707732018-07-03 16:22:02 +010091 "VZIP.32 q0, q2\n" // q0 = A0B0C0D0, q2 = A1B1C1D1
Pablo Telloeb82fd22018-02-23 13:43:50 +000092
93 // Store first elements
Anthony Barbier5f707732018-07-03 16:22:02 +010094 "VST1.32 {d0-d1}, [%[outptr]]!\n"
95 "VST1.32 {d16}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +000096
Anthony Barbier5f707732018-07-03 16:22:02 +010097 "VZIP.32 q4, q6\n" // q4 = A2B2C2D2, q6 = A3B3C3D3
Pablo Telloeb82fd22018-02-23 13:43:50 +000098
99 // Store second elements
Anthony Barbier5f707732018-07-03 16:22:02 +0100100 "VST1.32 {d4-d5}, [%[outptr]]!\n"
101 "VZIP.32 q1, q5\n"
102 ASM_PREFETCH("[%[inptr1], #128]")
103 "VST1.32 {d17}, [%[outptr]]!\n"
104 "VZIP.32 q3, q7\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000105
106 // Store third elements
Anthony Barbier5f707732018-07-03 16:22:02 +0100107 "VZIP.32 q9, q11\n"
108 "VST1.32 {d8-d9}, [%[outptr]]!\n"
109 "VZIP.32 q1, q3\n"
110 ASM_PREFETCH("[%[inptr2], #128]")
111 "VST1.32 {d20}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000112
113 // Store fourth elements
Anthony Barbier5f707732018-07-03 16:22:02 +0100114 "VZIP.32 q5, q7\n"
115 "VST1.32 {d12-d13}, [%[outptr]]!\n"
116 ASM_PREFETCH("[%[inptr3], #128]")
117 "VST1.32 {d21}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000118
119 // Fifth
Anthony Barbier5f707732018-07-03 16:22:02 +0100120 "VST1.32 {d2-d3}, [%[outptr]]!\n"
121 ASM_PREFETCH("[%[inptr4], #128]")
122 "VST1.32 {d18}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000123
124 // Sixth
Anthony Barbier5f707732018-07-03 16:22:02 +0100125 "VST1.32 {d6-d7}, [%[outptr]]!\n"
126 ASM_PREFETCH("[%[inptr5], #128]")
127 "VST1.32 {d19}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000128
129 // Seventh
Anthony Barbier5f707732018-07-03 16:22:02 +0100130 "VST1.32 {d10-d11}, [%[outptr]]!\n"
131 "VST1.32 {d22}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000132
133 // Eighth
Anthony Barbier5f707732018-07-03 16:22:02 +0100134 "VST1.32 {d14-d15}, [%[outptr]]!\n"
135 "VST1.32 {d23}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000136
Anthony Barbier5f707732018-07-03 16:22:02 +0100137 : [inptr0] "+r" (inptr0), [inptr1] "+r" (inptr1), [inptr2] "+r" (inptr2), [inptr3] "+r" (inptr3),
138 [inptr4] "+r" (inptr4), [inptr5] "+r" (inptr5), [outptr] "+r" (outptr)
Pablo Telloeb82fd22018-02-23 13:43:50 +0000139 :
Georgios Pinitasd636bc52018-11-07 16:35:35 +0000140 : "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", "q12", "memory"
Anthony Barbier5f707732018-07-03 16:22:02 +0100141 );
Pablo Telloeb82fd22018-02-23 13:43:50 +0000142 }
143
Anthony Barbier5f707732018-07-03 16:22:02 +0100144 for (;x>0;x--) {
Pablo Telloeb82fd22018-02-23 13:43:50 +0000145 *outptr++ = *inptr0++;
146 *outptr++ = *inptr1++;
147 *outptr++ = *inptr2++;
148 *outptr++ = *inptr3++;
149 *outptr++ = *inptr4++;
150 *outptr++ = *inptr5++;
151 }
152 }
153}
154
Anthony Barbier5f707732018-07-03 16:22:02 +0100155#endif // __arm__