blob: 501d6bf075fc3e46164117e4862f576ffb166416 [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;
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
83 __asm __volatile(
84 // Load up 8 elements (2 vectors) from each of 8 sources.
Pablo Tello99ef8402018-03-20 16:46:55 +000085 "VLD1.32 {d0-d3}, [%[inptr0]]!\n" // q0=A0A1A2A3
86 "VLD1.32 {d4-d7}, [%[inptr1]]!\n" // q2=B0B1B2B3
87 "VLD1.32 {d8-d11}, [%[inptr2]]!\n" // q4=C0C1C2C3
88 "VZIP.32 q0, q4\n" // q0=A0C0A1C1, q4 = A2C2A3C3
89 "VLD1.32 {d12-d15}, [%[inptr3]]!\n" // q6=D0D1D2D3
90 "VZIP.32 q2, q6\n" // q2=B0D0B1D1, q6 = B2D2B3D3
91 "VLD1.32 {d16-d19}, [%[inptr4]]!\n"
92 "VLD1.32 {d20-d23}, [%[inptr5]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +000093 "VZIP.32 q8, q10\n" // q8=E0F0E1F1, q10 = E2F2E3F3
94 ASM_PREFETCH("[%[inptr0], #128]")
95 "VZIP.32 q0, q2\n" // q0 = A0B0C0D0, q2 = A1B1C1D1
96
97 // Store first elements
Pablo Tello99ef8402018-03-20 16:46:55 +000098 "VST1.32 {d0-d1}, [%[outptr]]!\n"
99 "VST1.32 {d16}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000100
101 "VZIP.32 q4, q6\n" // q4 = A2B2C2D2, q6 = A3B3C3D3
102
103 // Store second elements
Pablo Tello99ef8402018-03-20 16:46:55 +0000104 "VST1.32 {d4-d5}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000105 "VZIP.32 q1, q5\n" ASM_PREFETCH("[%[inptr1], #128]")
Pablo Tello99ef8402018-03-20 16:46:55 +0000106 "VST1.32 {d17}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000107 "VZIP.32 q3, q7\n"
108
109 // Store third elements
110 "VZIP.32 q9, q11\n"
Pablo Tello99ef8402018-03-20 16:46:55 +0000111 "VST1.32 {d8-d9}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000112 "VZIP.32 q1, q3\n" ASM_PREFETCH("[%[inptr2], #128]")
Pablo Tello99ef8402018-03-20 16:46:55 +0000113 "VST1.32 {d20}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000114
115 // Store fourth elements
116 "VZIP.32 q5, q7\n"
Pablo Tello99ef8402018-03-20 16:46:55 +0000117 "VST1.32 {d12-d13}, [%[outptr]]!\n" ASM_PREFETCH("[%[inptr3], #128]")
118 "VST1.32 {d21}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000119
120 // Fifth
Pablo Tello99ef8402018-03-20 16:46:55 +0000121 "VST1.32 {d2-d3}, [%[outptr]]!\n" ASM_PREFETCH("[%[inptr4], #128]")
122 "VST1.32 {d18}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000123
124 // Sixth
Pablo Tello99ef8402018-03-20 16:46:55 +0000125 "VST1.32 {d6-d7}, [%[outptr]]!\n" ASM_PREFETCH("[%[inptr5], #128]")
126 "VST1.32 {d19}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000127
128 // Seventh
Pablo Tello99ef8402018-03-20 16:46:55 +0000129 "VST1.32 {d10-d11}, [%[outptr]]!\n"
130 "VST1.32 {d22}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000131
132 // Eighth
Pablo Tello99ef8402018-03-20 16:46:55 +0000133 "VST1.32 {d14-d15}, [%[outptr]]!\n"
134 "VST1.32 {d23}, [%[outptr]]!\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000135
136 : [inptr0] "+r"(inptr0), [inptr1] "+r"(inptr1), [inptr2] "+r"(inptr2), [inptr3] "+r"(inptr3),
137 [inptr4] "+r"(inptr4), [inptr5] "+r"(inptr5), [outptr] "+r"(outptr)
138 :
139 : "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", "q12");
140 }
141
142 for(; x > 0; x--)
143 {
144 *outptr++ = *inptr0++;
145 *outptr++ = *inptr1++;
146 *outptr++ = *inptr2++;
147 *outptr++ = *inptr3++;
148 *outptr++ = *inptr4++;
149 *outptr++ = *inptr5++;
150 }
151 }
152}
153
154#endif // __arm__