blob: f09e5a0e785e645b2e9433798699f9043e700f2c [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
32template <>
33template <typename T>
34inline void TransformImpl<6, 1, false, 4, 4>::Transform(T *out, const T *in, int ldin, int y0, int ymax, int k0, int kmax)
35{
36 uint32_t *outptr = reinterpret_cast<uint32_t *>(out);
37 const uint32_t *inptr = reinterpret_cast<const uint32_t *>(in);
38
39 uint32_t zerobuff[8];
40
41 for(int y = y0; y < ymax; y += 6)
42 {
43 const uint32_t *inptr0 = inptr + y * ldin + k0;
44 const uint32_t *inptr1 = inptr0 + ldin;
45 const uint32_t *inptr2 = inptr1 + ldin;
46 const uint32_t *inptr3 = inptr2 + ldin;
47 const uint32_t *inptr4 = inptr3 + ldin;
48 const uint32_t *inptr5 = inptr4 + 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
57 int x = (kmax - k0);
58 for(; x > 7; x -= 8)
59 {
60 /* Cope with ragged cases by copying from a buffer of zeroes instead */
61 if((y + 5) >= ymax)
62 {
63 switch((y + 5) - ymax)
64 {
65 /* Everything falls through in here */
66 case 4:
67 inptr1 = zerobuff;
68 case 3:
69 inptr2 = zerobuff;
70 case 2:
71 inptr3 = zerobuff;
72 case 1:
73 inptr4 = zerobuff;
74 case 0:
75 inptr5 = zerobuff;
76 default:
77 break;
78 }
79 }
80
81 __asm __volatile(
82 // Load up 8 elements (2 vectors) from each of 8 sources.
83 "VLD1.32 {d0-d3}, [%[inptr0]]!\n" // q0=A0A1A2A3
84 "VLD1.32 {d4-d7}, [%[inptr1]]!\n" // q2=B0B1B2B3
85 "VLD1.32 {d8-d11}, [%[inptr2]]!\n" // q4=C0C1C2C3
86 "VZIP.32 q0, q4\n" // q0=A0C0A1C1, q4 = A2C2A3C3
87 "VLD1.32 {d12-d15}, [%[inptr3]]!\n" // q6=D0D1D2D3
88 "VZIP.32 q2, q6\n" // q2=B0D0B1D1, q6 = B2D2B3D3
89 "VLD1.32 {d16-d19}, [%[inptr4]]!\n"
90 "VLD1.32 {d20-d23}, [%[inptr5]]!\n"
91 "VZIP.32 q8, q10\n" // q8=E0F0E1F1, q10 = E2F2E3F3
92 ASM_PREFETCH("[%[inptr0], #128]")
93 "VZIP.32 q0, q2\n" // q0 = A0B0C0D0, q2 = A1B1C1D1
94
95 // Store first elements
96 "VST1.32 {d0-d1}, [%[outptr]]!\n"
97 "VST1.32 {d16}, [%[outptr]]!\n"
98
99 "VZIP.32 q4, q6\n" // q4 = A2B2C2D2, q6 = A3B3C3D3
100
101 // Store second elements
102 "VST1.32 {d4-d5}, [%[outptr]]!\n"
103 "VZIP.32 q1, q5\n" ASM_PREFETCH("[%[inptr1], #128]")
104 "VST1.32 {d17}, [%[outptr]]!\n"
105 "VZIP.32 q3, q7\n"
106
107 // Store third elements
108 "VZIP.32 q9, q11\n"
109 "VST1.32 {d8-d9}, [%[outptr]]!\n"
110 "VZIP.32 q1, q3\n" ASM_PREFETCH("[%[inptr2], #128]")
111 "VST1.32 {d20}, [%[outptr]]!\n"
112
113 // Store fourth elements
114 "VZIP.32 q5, q7\n"
115 "VST1.32 {d12-d13}, [%[outptr]]!\n" ASM_PREFETCH("[%[inptr3], #128]")
116 "VST1.32 {d21}, [%[outptr]]!\n"
117
118 // Fifth
119 "VST1.32 {d2-d3}, [%[outptr]]!\n" ASM_PREFETCH("[%[inptr4], #128]")
120 "VST1.32 {d18}, [%[outptr]]!\n"
121
122 // Sixth
123 "VST1.32 {d6-d7}, [%[outptr]]!\n" ASM_PREFETCH("[%[inptr5], #128]")
124 "VST1.32 {d19}, [%[outptr]]!\n"
125
126 // Seventh
127 "VST1.32 {d10-d11}, [%[outptr]]!\n"
128 "VST1.32 {d22}, [%[outptr]]!\n"
129
130 // Eighth
131 "VST1.32 {d14-d15}, [%[outptr]]!\n"
132 "VST1.32 {d23}, [%[outptr]]!\n"
133
134 : [inptr0] "+r"(inptr0), [inptr1] "+r"(inptr1), [inptr2] "+r"(inptr2), [inptr3] "+r"(inptr3),
135 [inptr4] "+r"(inptr4), [inptr5] "+r"(inptr5), [outptr] "+r"(outptr)
136 :
137 : "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", "q12");
138 }
139
140 for(; x > 0; x--)
141 {
142 *outptr++ = *inptr0++;
143 *outptr++ = *inptr1++;
144 *outptr++ = *inptr2++;
145 *outptr++ = *inptr3++;
146 *outptr++ = *inptr4++;
147 *outptr++ = *inptr5++;
148 }
149 }
150}
151
152#endif // __arm__