| 1 | // yala is pleased to support the open source community by making ncnn available. |
| 2 | // |
| 3 | // |
| 4 | // Copyright (C) 2022 yala <zhaojunchao@loongson.cn>;<junchao82@qq.com>. All rights reserved. |
| 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except |
| 6 | // in compliance with the License. You may obtain a copy of the License at |
| 7 | // |
| 8 | // https://opensource.org/licenses/BSD-3-Clause |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software distributed |
| 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 13 | // specific language governing permissions and limitations under the License. |
| 14 | |
| 15 | static void padding_constant_pack4_lsx(const Mat& src, Mat& dst, int top, int bottom, int left, int right, __m128 v) |
| 16 | { |
| 17 | const float* ptr = src; |
| 18 | float* outptr = dst; |
| 19 | int top_size = top * dst.w; |
| 20 | int bottom_size = bottom * dst.w; |
| 21 | |
| 22 | // fill top |
| 23 | for (int y = 0; y < top_size; y++) |
| 24 | { |
| 25 | __lsx_vst(v, outptr, 0); |
| 26 | outptr += 4; |
| 27 | } |
| 28 | // fill center |
| 29 | for (int y = 0; y < src.h; y++) |
| 30 | { |
| 31 | for (int x = 0; x < left; x++) |
| 32 | { |
| 33 | __lsx_vst(v, outptr, 0); |
| 34 | outptr += 4; |
| 35 | } |
| 36 | for (int x = 0; x < src.w; x++) |
| 37 | { |
| 38 | __builtin_prefetch(ptr + 32); |
| 39 | __lsx_vst(__lsx_vld(ptr, 0), outptr, 0); |
| 40 | ptr += 4; |
| 41 | outptr += 4; |
| 42 | } |
| 43 | for (int x = 0; x < right; x++) |
| 44 | { |
| 45 | __lsx_vst(v, outptr, 0); |
| 46 | outptr += 4; |
| 47 | } |
| 48 | } |
| 49 | // fill top |
| 50 | for (int y = 0; y < bottom_size; y++) |
| 51 | { |
| 52 | __lsx_vst(v, outptr, 0); |
| 53 | outptr += 4; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | static void padding_replicate_pack4_lsx(const Mat& src, Mat& dst, int top, int bottom, int left, int right) |
| 58 | { |
| 59 | const float* ptr = src; |
| 60 | float* outptr = dst; |
| 61 | |
| 62 | // fill top |
| 63 | for (int y = 0; y < top; y++) |
| 64 | { |
| 65 | const float* ptr0 = ptr; |
| 66 | __m128 _p = (__m128)__lsx_vld(ptr0, 0); |
| 67 | for (int x = 0; x < left; x++) |
| 68 | { |
| 69 | __lsx_vst(_p, outptr, 0); |
| 70 | outptr += 4; |
| 71 | } |
| 72 | for (int x = 0; x < src.w; x++) |
| 73 | { |
| 74 | _p = (__m128)__lsx_vld(ptr0, 0); |
| 75 | __lsx_vst(_p, outptr, 0); |
| 76 | ptr0 += 4; |
| 77 | outptr += 4; |
| 78 | } |
| 79 | for (int x = 0; x < right; x++) |
| 80 | { |
| 81 | __lsx_vst(_p, outptr, 0); |
| 82 | outptr += 4; |
| 83 | } |
| 84 | } |
| 85 | // fill center |
| 86 | for (int y = 0; y < src.h; y++) |
| 87 | { |
| 88 | __m128 _p = (__m128)__lsx_vld(ptr, 0); |
| 89 | for (int x = 0; x < left; x++) |
| 90 | { |
| 91 | __lsx_vst(_p, outptr, 0); |
| 92 | outptr += 4; |
| 93 | } |
| 94 | for (int x = 0; x < src.w; x++) |
| 95 | { |
| 96 | _p = (__m128)__lsx_vld(ptr, 0); |
| 97 | __lsx_vst(_p, outptr, 0); |
| 98 | ptr += 4; |
| 99 | outptr += 4; |
| 100 | } |
| 101 | for (int x = 0; x < right; x++) |
| 102 | { |
| 103 | __lsx_vst(_p, outptr, 0); |
| 104 | outptr += 4; |
| 105 | } |
| 106 | } |
| 107 | // fill bottom |
| 108 | ptr -= src.w * 4; |
| 109 | for (int y = 0; y < bottom; y++) |
| 110 | { |
| 111 | const float* ptr0 = ptr; |
| 112 | __m128 _p = (__m128)__lsx_vld(ptr0, 0); |
| 113 | for (int x = 0; x < left; x++) |
| 114 | { |
| 115 | __lsx_vst(_p, outptr, 0); |
| 116 | outptr += 4; |
| 117 | } |
| 118 | for (int x = 0; x < src.w; x++) |
| 119 | { |
| 120 | _p = (__m128)__lsx_vld(ptr0, 0); |
| 121 | __lsx_vst(_p, outptr, 0); |
| 122 | ptr0 += 4; |
| 123 | outptr += 4; |
| 124 | } |
| 125 | for (int x = 0; x < right; x++) |
| 126 | { |
| 127 | __lsx_vst(_p, outptr, 0); |
| 128 | outptr += 4; |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | static void padding_reflect_pack4_lsx(const Mat& src, Mat& dst, int top, int bottom, int left, int right) |
| 134 | { |
| 135 | const float* ptr = src; |
| 136 | float* outptr = dst; |
| 137 | |
| 138 | // fill top |
| 139 | ptr += top * src.w * 4; |
| 140 | for (int y = 0; y < top; y++) |
| 141 | { |
| 142 | const float* ptr0 = ptr; |
| 143 | for (int x = 0; x < left; x++) |
| 144 | { |
| 145 | __m128 _p = (__m128)__lsx_vld(ptr0 + (left - x) * 4, 0); |
| 146 | __lsx_vst(_p, outptr, 0); |
| 147 | outptr += 4; |
| 148 | } |
| 149 | for (int x = 0; x < src.w; x++) |
| 150 | { |
| 151 | __m128 _p = (__m128)__lsx_vld(ptr0, 0); |
| 152 | __lsx_vst(_p, outptr, 0); |
| 153 | ptr0 += 4; |
| 154 | outptr += 4; |
| 155 | } |
| 156 | for (int x = 0; x < right; x++) |
| 157 | { |
| 158 | __m128 _p = (__m128)__lsx_vld(ptr0 - 8 - x * 4, 0); |
| 159 | __lsx_vst(_p, outptr, 0); |
| 160 | outptr += 4; |
| 161 | } |
| 162 | ptr -= src.w * 4; |
| 163 | } |
| 164 | // fill center |
| 165 | for (int y = 0; y < src.h; y++) |
| 166 | { |
| 167 | for (int x = 0; x < left; x++) |
| 168 | { |
| 169 | __m128 _p = (__m128)__lsx_vld(ptr + (left - x) * 4, 0); |
| 170 | __lsx_vst(_p, outptr, 0); |
| 171 | outptr += 4; |
| 172 | } |
| 173 | for (int x = 0; x < src.w; x++) |
| 174 | { |
| 175 | __m128 _p = (__m128)__lsx_vld(ptr, 0); |
| 176 | __lsx_vst(_p, outptr, 0); |
| 177 | ptr += 4; |
| 178 | outptr += 4; |
| 179 | } |
| 180 | for (int x = 0; x < right; x++) |
| 181 | { |
| 182 | __m128 _p = (__m128)__lsx_vld(ptr - 8 - x * 4, 0); |
| 183 | __lsx_vst(_p, outptr, 0); |
| 184 | outptr += 4; |
| 185 | } |
| 186 | } |
| 187 | // fill bottom |
| 188 | ptr -= 2 * src.w * 4; |
| 189 | for (int y = 0; y < bottom; y++) |
| 190 | { |
| 191 | const float* ptr0 = ptr; |
| 192 | for (int x = 0; x < left; x++) |
| 193 | { |
| 194 | __m128 _p = (__m128)__lsx_vld(ptr0 + (left - x) * 4, 0); |
| 195 | __lsx_vst(_p, outptr, 0); |
| 196 | outptr += 4; |
| 197 | } |
| 198 | for (int x = 0; x < src.w; x++) |
| 199 | { |
| 200 | __m128 _p = (__m128)__lsx_vld(ptr0, 0); |
| 201 | __lsx_vst(_p, outptr, 0); |
| 202 | ptr0 += 4; |
| 203 | outptr += 4; |
| 204 | } |
| 205 | for (int x = 0; x < right; x++) |
| 206 | { |
| 207 | __m128 _p = (__m128)__lsx_vld(ptr0 - 8 - x * 4, 0); |
| 208 | __lsx_vst(_p, outptr, 0); |
| 209 | outptr += 4; |
| 210 | } |
| 211 | ptr -= src.w * 4; |
| 212 | } |
| 213 | } |