Elffuss BraidHub

kikocis/ncnn public

master · 4.1 KiBRawPermalink
1// Tencent is pleased to support the open source community by making ncnn available.
2//
3// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
4//
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
15static void padding_constant_pack8_int8_sse(const Mat& src, Mat& dst, int top, int bottom, int left, int right, int64_t _v)
16{
17 const int64_t* ptr = src;
18 int64_t* outptr = dst;
19
20 // fill top
21 for (int y = 0; y < top; y++)
22 {
23 for (int x = 0; x < dst.w; x++)
24 {
25 *outptr++ = _v;
26 }
27 }
28 // fill center
29 for (int y = 0; y < src.h; y++)
30 {
31 for (int x = 0; x < left; x++)
32 {
33 *outptr++ = _v;
34 }
35 for (int x = 0; x < src.w; x++)
36 {
37 *outptr++ = *ptr++;
38 }
39 for (int x = 0; x < right; x++)
40 {
41 *outptr++ = _v;
42 }
43 }
44 // fill bottom
45 for (int y = 0; y < bottom; y++)
46 {
47 for (int x = 0; x < dst.w; x++)
48 {
49 *outptr++ = _v;
50 }
51 }
52}
53
54static void padding_replicate_pack8_int8_sse(const Mat& src, Mat& dst, int top, int bottom, int left, int right)
55{
56 const int64_t* ptr = src;
57 int64_t* outptr = dst;
58
59 // fill top
60 for (int y = 0; y < top; y++)
61 {
62 const int64_t* ptr0 = ptr;
63 for (int x = 0; x < left; x++)
64 {
65 *outptr++ = *ptr0;
66 }
67 for (int x = 0; x < src.w; x++)
68 {
69 *outptr++ = *ptr0++;
70 }
71 for (int x = 0; x < right; x++)
72 {
73 *outptr++ = ptr0[-1];
74 }
75 }
76 // fill center
77 for (int y = 0; y < src.h; y++)
78 {
79 for (int x = 0; x < left; x++)
80 {
81 *outptr++ = *ptr;
82 }
83 for (int x = 0; x < src.w; x++)
84 {
85 *outptr++ = *ptr++;
86 }
87 for (int x = 0; x < right; x++)
88 {
89 *outptr++ = ptr[-1];
90 }
91 }
92 // fill bottom
93 ptr -= src.w;
94 for (int y = 0; y < bottom; y++)
95 {
96 const int64_t* ptr0 = ptr;
97 for (int x = 0; x < left; x++)
98 {
99 *outptr++ = *ptr0;
100 }
101 for (int x = 0; x < src.w; x++)
102 {
103 *outptr++ = *ptr0++;
104 }
105 for (int x = 0; x < right; x++)
106 {
107 *outptr++ = ptr0[-1];
108 }
109 }
110}
111
112static void padding_reflect_pack8_int8_sse(const Mat& src, Mat& dst, int top, int bottom, int left, int right)
113{
114 const int64_t* ptr = src;
115 int64_t* outptr = dst;
116
117 // fill top
118 ptr += top * src.w;
119 for (int y = 0; y < top; y++)
120 {
121 const int64_t* ptr0 = ptr;
122 for (int x = 0; x < left; x++)
123 {
124 *outptr++ = ptr0[left - x];
125 }
126 for (int x = 0; x < src.w; x++)
127 {
128 *outptr++ = *ptr0++;
129 }
130 for (int x = 0; x < right; x++)
131 {
132 *outptr++ = ptr0[-2 - x];
133 }
134 ptr -= src.w;
135 }
136 // fill center
137 for (int y = 0; y < src.h; y++)
138 {
139 for (int x = 0; x < left; x++)
140 {
141 *outptr++ = ptr[left - x];
142 }
143 for (int x = 0; x < src.w; x++)
144 {
145 *outptr++ = *ptr++;
146 }
147 for (int x = 0; x < right; x++)
148 {
149 *outptr++ = ptr[-2 - x];
150 }
151 }
152 // fill bottom
153 ptr -= 2 * src.w;
154 for (int y = 0; y < bottom; y++)
155 {
156 const int64_t* ptr0 = ptr;
157 for (int x = 0; x < left; x++)
158 {
159 *outptr++ = ptr0[left - x];
160 }
161 for (int x = 0; x < src.w; x++)
162 {
163 *outptr++ = *ptr0++;
164 }
165 for (int x = 0; x < right; x++)
166 {
167 *outptr++ = ptr0[-2 - x];
168 }
169 ptr -= src.w;
170 }
171}