Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 1 | /* |
Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 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 __aarch64__ |
| 27 | |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 28 | #include <arm_neon.h> |
| 29 | |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 30 | #include "../asmlib.hpp" |
| 31 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame^] | 32 | template<> |
| 33 | template<typename T> |
| 34 | inline void TransformImpl<8, 1, false, 4, 4>::Transform(T *out, const T *in, int ldin, int y0, int ymax, int k0, int kmax) { |
| 35 | uint32_t *outptr = (uint32_t *)out; |
| 36 | const uint32_t *inptr = (uint32_t *)in; |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 37 | |
| 38 | uint32_t zerobuff[8]; |
| 39 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame^] | 40 | for (int y=y0; y<ymax; y+=8) { |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 41 | 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 | const uint32_t *inptr6 = inptr5 + ldin; |
| 48 | const uint32_t *inptr7 = inptr6 + 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 | prefetch_2x(inptr6); |
| 57 | prefetch_2x(inptr7); |
| 58 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame^] | 59 | int x=(kmax-k0); |
| 60 | for (;x>7;x-=8) { |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 61 | /* Cope with ragged cases by copying from a buffer of zeroes instead */ |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame^] | 62 | if ((y + 7) >= ymax) { |
| 63 | switch ((y + 7) - ymax) { |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 64 | /* Everything falls through in here */ |
| 65 | case 6: |
| 66 | inptr1 = zerobuff; |
| 67 | case 5: |
| 68 | inptr2 = zerobuff; |
| 69 | case 4: |
| 70 | inptr3 = zerobuff; |
| 71 | case 3: |
| 72 | inptr4 = zerobuff; |
| 73 | case 2: |
| 74 | inptr5 = zerobuff; |
| 75 | case 1: |
| 76 | inptr6 = zerobuff; |
| 77 | case 0: |
| 78 | inptr7 = zerobuff; |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 79 | break; |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 80 | |
| 81 | default: |
| 82 | UNREACHABLE("Impossible."); |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame^] | 86 | __asm __volatile ( |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 87 | // Load up 8 elements (2 vectors) from each of 8 sources. |
| 88 | "LDP q0, q1, [%[inptr0]], #32\n" // q0=A0A1A2A3 |
| 89 | "LDP q2, q3, [%[inptr1]], #32\n" // q2=B0B1B2B3 |
| 90 | "LDP q4, q5, [%[inptr2]], #32\n" // q4=C0C1C2C3 |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame^] | 91 | "ZIP1 v16.4s, v0.4s, v4.4s\n" // q16=A0C0A1C1 |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 92 | ASM_PREFETCH("[%[inptr0], #128]") |
| 93 | "LDP q6, q7, [%[inptr3]], #32\n" // q6=D0D1D2D3 |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame^] | 94 | "ZIP1 v17.4s, v2.4s, v6.4s\n" // q17=B0D0B1D1 |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 95 | "LDP q8, q9, [%[inptr4]], #32\n" |
| 96 | "LDP q10, q11, [%[inptr5]], #32\n" |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 97 | "LDP q12, q13, [%[inptr6]], #32\n" |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame^] | 98 | "ZIP1 v18.4s, v8.4s, v12.4s\n" |
| 99 | ASM_PREFETCH("[%[inptr1], #128]") |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 100 | "LDP q14, q15, [%[inptr7]], #32\n" |
| 101 | "ZIP1 v19.4s, v10.4s, v14.4s\n" |
| 102 | |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 103 | "ZIP1 v20.4s, v16.4s, v17.4s\n" // q20=A0B0C0D0 |
Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 104 | ASM_PREFETCH("[%[inptr2], #128]") |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 105 | "ZIP1 v21.4s, v18.4s, v19.4s\n" |
| 106 | "ZIP2 v22.4s, v16.4s, v17.4s\n" |
| 107 | "ZIP2 v23.4s, v18.4s, v19.4s\n" |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 108 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame^] | 109 | "ZIP2 v16.4s, v0.4s, v4.4s\n" |
| 110 | ASM_PREFETCH("[%[inptr3], #128]") |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 111 | "ZIP2 v17.4s, v2.4s, v6.4s\n" |
| 112 | "STP q20, q21, [%[outptr]], #32\n" // Write back the first element of each source |
| 113 | |
| 114 | "ZIP2 v18.4s, v8.4s, v12.4s\n" |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 115 | "ZIP2 v19.4s, v10.4s, v14.4s\n" |
| 116 | "STP q22, q23, [%[outptr]], #32\n" // Write back the second element of each source |
| 117 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame^] | 118 | "ZIP1 v20.4s, v16.4s, v17.4s\n" |
| 119 | ASM_PREFETCH("[%[inptr4], #128]") |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 120 | "ZIP1 v21.4s, v18.4s, v19.4s\n" |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 121 | "ZIP2 v22.4s, v16.4s, v17.4s\n" |
| 122 | "ZIP2 v23.4s, v18.4s, v19.4s\n" |
| 123 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame^] | 124 | "ZIP1 v16.4s, v1.4s, v5.4s\n" |
| 125 | ASM_PREFETCH("[%[inptr5], #128]") |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 126 | "ZIP1 v17.4s, v3.4s, v7.4s\n" |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 127 | "STP q20, q21, [%[outptr]], #32\n" // Third element |
| 128 | |
| 129 | "ZIP1 v18.4s, v9.4s, v13.4s\n" |
| 130 | "ZIP1 v19.4s, v11.4s, v15.4s\n" |
| 131 | "STP q22, q23, [%[outptr]], #32\n" // Fourth element |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 132 | |
| 133 | "ZIP1 v20.4s, v16.4s, v17.4s\n" |
| 134 | "ZIP1 v21.4s, v18.4s, v19.4s\n" |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame^] | 135 | "ZIP2 v22.4s, v16.4s, v17.4s\n" |
| 136 | ASM_PREFETCH("[%[inptr6], #128]") |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 137 | "ZIP2 v23.4s, v18.4s, v19.4s\n" |
| 138 | |
| 139 | "ZIP2 v16.4s, v1.4s, v5.4s\n" |
| 140 | "ZIP2 v17.4s, v3.4s, v7.4s\n" |
| 141 | "STP q20, q21, [%[outptr]], #32\n" // Fifth element |
| 142 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame^] | 143 | "ZIP2 v18.4s, v9.4s, v13.4s\n" |
| 144 | ASM_PREFETCH("[%[inptr7], #128]") |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 145 | "ZIP2 v19.4s, v11.4s, v15.4s\n" |
| 146 | "STP q22, q23, [%[outptr]], #32\n" // Sixth element |
| 147 | |
| 148 | "ZIP1 v20.4s, v16.4s, v17.4s\n" |
| 149 | "ZIP1 v21.4s, v18.4s, v19.4s\n" |
| 150 | "STP q20, q21, [%[outptr]], #32\n" // Seventh element |
| 151 | |
| 152 | "ZIP2 v22.4s, v16.4s, v17.4s\n" |
| 153 | "ZIP2 v23.4s, v18.4s, v19.4s\n" |
| 154 | "STP q22, q23, [%[outptr]], #32\n" // Eighth element |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame^] | 155 | : [inptr0] "+r" (inptr0), [inptr1] "+r" (inptr1), [inptr2] "+r" (inptr2), [inptr3] "+r" (inptr3), |
| 156 | [inptr4] "+r" (inptr4), [inptr5] "+r" (inptr5), [inptr6] "+r" (inptr6), [inptr7] "+r" (inptr7), [outptr] "+r" (outptr) |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 157 | : |
| 158 | : "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "v12", |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame^] | 159 | "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23" |
| 160 | ); |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 161 | } |
| 162 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame^] | 163 | for (;x>0;x--) { |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 164 | *outptr++ = *inptr0++; |
| 165 | *outptr++ = *inptr1++; |
| 166 | *outptr++ = *inptr2++; |
| 167 | *outptr++ = *inptr3++; |
| 168 | *outptr++ = *inptr4++; |
| 169 | *outptr++ = *inptr5++; |
| 170 | *outptr++ = *inptr6++; |
| 171 | *outptr++ = *inptr7++; |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame^] | 176 | #endif // __aarch64__ |