blob: 9b6f4de543a235d6fcef148982b361f4ac728600 [file] [log] [blame]
Pablo Tello11c3b332018-01-25 15:05:13 +00001/*
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +01002 * Copyright (c) 2017-2020 Arm Limited.
Pablo Tello11c3b332018-01-25 15:05:13 +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 __aarch64__
27
28#include <arm_neon.h>
Pablo Tello11c3b332018-01-25 15:05:13 +000029
Pablo Telloeb82fd22018-02-23 13:43:50 +000030#include "../asmlib.hpp"
31#include "../utils.hpp"
32
Anthony Barbier5f707732018-07-03 16:22:02 +010033template<>
34template<typename T>
David Manselld93991e2018-07-06 14:52:52 +010035void TransformImpl<4, 16, false, 1, 1, false>::Transform(T *out, const T *in, int ldin, int y0, int ymax, int k0, int kmax) {
Anthony Barbier5f707732018-07-03 16:22:02 +010036 uint8_t *outptr = (uint8_t *)out;
37 const uint8_t *inptr = (uint8_t *)in;
Pablo Tello11c3b332018-01-25 15:05:13 +000038
Georgios Pinitasdd0bf482019-05-23 11:07:33 +010039 uint8_t zerobuff[16] = { 0 };
Pablo Tello11c3b332018-01-25 15:05:13 +000040
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +010041 for (int y=y0; y<ymax; y+=4) {
42 const uint8_t *inptr0 = inptr + static_cast<intptr_t>(y) * ldin + k0;
Pablo Tello11c3b332018-01-25 15:05:13 +000043 const uint8_t *inptr1 = inptr0 + ldin;
44 const uint8_t *inptr2 = inptr1 + ldin;
45 const uint8_t *inptr3 = inptr2 + ldin;
46
47 prefetch_2x(inptr0);
48 prefetch_2x(inptr1);
49 prefetch_2x(inptr2);
50 prefetch_2x(inptr3);
51
Anthony Barbier5f707732018-07-03 16:22:02 +010052 int x=(kmax-k0);
53 for (;x>15;x-=16) {
Pablo Tello11c3b332018-01-25 15:05:13 +000054 /* Cope with ragged cases by copying from a buffer of zeroes instead */
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +010055 if ((y + 3) >= ymax) {
Anthony Barbier5f707732018-07-03 16:22:02 +010056 switch ((y + 3) - ymax) {
Pablo Tello11c3b332018-01-25 15:05:13 +000057 case 2:
58 inptr1 = zerobuff;
Georgios Pinitas37d080f2019-06-21 18:43:12 +010059 // fall through
Pablo Tello11c3b332018-01-25 15:05:13 +000060 case 1:
61 inptr2 = zerobuff;
Georgios Pinitas37d080f2019-06-21 18:43:12 +010062 // fall through
Pablo Tello11c3b332018-01-25 15:05:13 +000063 case 0:
64 inptr3 = zerobuff;
Pablo Tello11c3b332018-01-25 15:05:13 +000065 break;
Pablo Telloeb82fd22018-02-23 13:43:50 +000066
67 default:
68 UNREACHABLE("Impossible.");
Pablo Tello11c3b332018-01-25 15:05:13 +000069 }
70 }
71
Anthony Barbier5f707732018-07-03 16:22:02 +010072 __asm __volatile (
73 "LDR q0, [%[inptr0]], #16\n"
74 ASM_PREFETCH("[%[inptr0], #176]")
75 "LDR q1, [%[inptr1]], #16\n"
76 ASM_PREFETCH("[%[inptr1], #176]")
77 "STP q0, q1, [%[outptr]], #32\n"
78 "LDR q0, [%[inptr2]], #16\n"
79 ASM_PREFETCH("[%[inptr2], #176]")
80 "LDR q1, [%[inptr3]], #16\n"
81 ASM_PREFETCH("[%[inptr3], #176]")
82 "STP q0, q1, [%[outptr]], #32\n"
83 : [inptr0] "+r" (inptr0), [inptr1] "+r" (inptr1), [inptr2] "+r" (inptr2), [inptr3] "+r" (inptr3),
84 [outptr] "+r" (outptr)
Pablo Tello11c3b332018-01-25 15:05:13 +000085 :
Anthony Barbier5f707732018-07-03 16:22:02 +010086 : "v0", "v1"
87 );
Pablo Tello11c3b332018-01-25 15:05:13 +000088 }
89
Anthony Barbier5f707732018-07-03 16:22:02 +010090 if (x>0) {
Pablo Tello11c3b332018-01-25 15:05:13 +000091 /* Need to duplicate this here, in case we didn't run the main loop. */
Georgios Pinitas5aa1a0b2020-07-02 20:02:20 +010092 if ((y + 3) >= ymax) {
Anthony Barbier5f707732018-07-03 16:22:02 +010093 switch ((y + 3) - ymax) {
Pablo Tello11c3b332018-01-25 15:05:13 +000094 case 2:
95 inptr1 = zerobuff;
Georgios Pinitas37d080f2019-06-21 18:43:12 +010096 // fall through
Pablo Tello11c3b332018-01-25 15:05:13 +000097 case 1:
98 inptr2 = zerobuff;
Georgios Pinitas37d080f2019-06-21 18:43:12 +010099 // fall through
Pablo Tello11c3b332018-01-25 15:05:13 +0000100 case 0:
101 inptr3 = zerobuff;
Pablo Tello11c3b332018-01-25 15:05:13 +0000102 break;
Pablo Telloeb82fd22018-02-23 13:43:50 +0000103
104 default:
105 UNREACHABLE("Impossible.");
Pablo Tello11c3b332018-01-25 15:05:13 +0000106 }
107 }
108
109 /* We have to write out 16 values, copy as many legal values as there are and pad with 0 */
Anthony Barbier5f707732018-07-03 16:22:02 +0100110 auto f = [&outptr, x](const uint8_t *&p) {
111 for (int i=0; i<16; i++) {
112 if (i < x) {
Pablo Tello11c3b332018-01-25 15:05:13 +0000113 *outptr++ = *p++;
Anthony Barbier5f707732018-07-03 16:22:02 +0100114 } else {
Pablo Tello11c3b332018-01-25 15:05:13 +0000115 *outptr++ = 0;
116 }
117 }
118 };
119
120 f(inptr0);
121 f(inptr1);
122 f(inptr2);
123 f(inptr3);
124 }
125 }
126}
127
Anthony Barbier5f707732018-07-03 16:22:02 +0100128#endif // __aarch64__