Elffuss BraidHub

kikocis/ncnn public

master · 1.9 KiBRawPermalink
1
2// Tencent is pleased to support the open source community by making ncnn available.
3//
4// Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5//
6// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
7// in compliance with the License. You may obtain a copy of the License at
8//
9// https://opensource.org/licenses/BSD-3-Clause
10//
11// Unless required by applicable law or agreed to in writing, software distributed
12// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13// CONDITIONS OF ANY KIND, either express or implied. See the License for the
14// specific language governing permissions and limitations under the License.
15
16static void pooling2x2s2_max_pack4_sse(const Mat& bottom_blob, Mat& top_blob, const Option& opt)
17{
18 int w = bottom_blob.w;
19 int inch = bottom_blob.c;
20
21 int outw = top_blob.w;
22 int outh = top_blob.h;
23
24 const int tailstep = (w - 2 * outw + w) * 4;
25
26 #pragma omp parallel for num_threads(opt.num_threads)
27 for (int q = 0; q < inch; q++)
28 {
29 const Mat img0 = bottom_blob.channel(q);
30 float* outptr = top_blob.channel(q);
31
32 const float* r0 = img0.row(0);
33 const float* r1 = img0.row(1);
34
35 for (int i = 0; i < outh; i++)
36 {
37 int j = 0;
38
39 for (; j < outw; j++)
40 {
41 __m128 _r00 = _mm_loadu_ps(r0);
42 __m128 _r01 = _mm_loadu_ps(r0 + 4);
43 __m128 _r10 = _mm_loadu_ps(r1);
44 __m128 _r11 = _mm_loadu_ps(r1 + 4);
45
46 __m128 _max0 = _mm_max_ps(_r00, _r01);
47 __m128 _max1 = _mm_max_ps(_r10, _r11);
48 __m128 _max = _mm_max_ps(_max0, _max1);
49
50 _mm_storeu_ps(outptr, _max);
51
52 r0 += 8;
53 r1 += 8;
54 outptr += 4;
55 }
56
57 r0 += tailstep;
58 r1 += tailstep;
59 }
60 }
61}