Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 5aa1a0b | 2020-07-02 20:02:20 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 Arm Limited. |
Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [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 | |
| 28 | #include <arm_neon.h> |
Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 29 | |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 30 | #include "../asmlib.hpp" |
| 31 | #include "../utils.hpp" |
| 32 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 33 | template<> |
| 34 | template<typename T> |
David Mansell | d93991e | 2018-07-06 14:52:52 +0100 | [diff] [blame] | 35 | void TransformImpl<4, 16, false, 1, 1, false>::Transform(T *out, const T *in, int ldin, int y0, int ymax, int k0, int kmax) { |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 36 | uint8_t *outptr = (uint8_t *)out; |
| 37 | const uint8_t *inptr = (uint8_t *)in; |
Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 38 | |
Georgios Pinitas | dd0bf48 | 2019-05-23 11:07:33 +0100 | [diff] [blame] | 39 | uint8_t zerobuff[16] = { 0 }; |
Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 40 | |
Georgios Pinitas | 5aa1a0b | 2020-07-02 20:02:20 +0100 | [diff] [blame] | 41 | for (int y=y0; y<ymax; y+=4) { |
| 42 | const uint8_t *inptr0 = inptr + static_cast<intptr_t>(y) * ldin + k0; |
Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 43 | 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 Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 52 | int x=(kmax-k0); |
| 53 | for (;x>15;x-=16) { |
Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 54 | /* Cope with ragged cases by copying from a buffer of zeroes instead */ |
Georgios Pinitas | 5aa1a0b | 2020-07-02 20:02:20 +0100 | [diff] [blame] | 55 | if ((y + 3) >= ymax) { |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 56 | switch ((y + 3) - ymax) { |
Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 57 | case 2: |
| 58 | inptr1 = zerobuff; |
Georgios Pinitas | 37d080f | 2019-06-21 18:43:12 +0100 | [diff] [blame] | 59 | // fall through |
Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 60 | case 1: |
| 61 | inptr2 = zerobuff; |
Georgios Pinitas | 37d080f | 2019-06-21 18:43:12 +0100 | [diff] [blame] | 62 | // fall through |
Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 63 | case 0: |
| 64 | inptr3 = zerobuff; |
Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 65 | break; |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 66 | |
| 67 | default: |
| 68 | UNREACHABLE("Impossible."); |
Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 72 | __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 Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 85 | : |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 86 | : "v0", "v1" |
| 87 | ); |
Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 90 | if (x>0) { |
Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 91 | /* Need to duplicate this here, in case we didn't run the main loop. */ |
Georgios Pinitas | 5aa1a0b | 2020-07-02 20:02:20 +0100 | [diff] [blame] | 92 | if ((y + 3) >= ymax) { |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 93 | switch ((y + 3) - ymax) { |
Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 94 | case 2: |
| 95 | inptr1 = zerobuff; |
Georgios Pinitas | 37d080f | 2019-06-21 18:43:12 +0100 | [diff] [blame] | 96 | // fall through |
Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 97 | case 1: |
| 98 | inptr2 = zerobuff; |
Georgios Pinitas | 37d080f | 2019-06-21 18:43:12 +0100 | [diff] [blame] | 99 | // fall through |
Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 100 | case 0: |
| 101 | inptr3 = zerobuff; |
Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 102 | break; |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 103 | |
| 104 | default: |
| 105 | UNREACHABLE("Impossible."); |
Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | |
| 109 | /* We have to write out 16 values, copy as many legal values as there are and pad with 0 */ |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 110 | auto f = [&outptr, x](const uint8_t *&p) { |
| 111 | for (int i=0; i<16; i++) { |
| 112 | if (i < x) { |
Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 113 | *outptr++ = *p++; |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 114 | } else { |
Pablo Tello | 11c3b33 | 2018-01-25 15:05:13 +0000 | [diff] [blame] | 115 | *outptr++ = 0; |
| 116 | } |
| 117 | } |
| 118 | }; |
| 119 | |
| 120 | f(inptr0); |
| 121 | f(inptr1); |
| 122 | f(inptr2); |
| 123 | f(inptr3); |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
Anthony Barbier | 5f70773 | 2018-07-03 16:22:02 +0100 | [diff] [blame] | 128 | #endif // __aarch64__ |