Elffuss BraidHub

kikocis/ncnn public

master · 5.1 KiBRawPermalink
1// Tencent is pleased to support the open source community by making ncnn available.
2//
3// Copyright (C) 2019 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 pooling2x2s2_max_pack4_neon(const Mat& bottom_blob, Mat& top_blob, const Option& opt)
16{
17 int w = bottom_blob.w;
18 int inch = bottom_blob.c;
19
20 int outw = top_blob.w;
21 int outh = top_blob.h;
22
23 const int tailstep = (w - 2 * outw + w) * 4;
24
25 #pragma omp parallel for num_threads(opt.num_threads)
26 for (int q = 0; q < inch; q++)
27 {
28 const Mat img0 = bottom_blob.channel(q);
29 float* outptr = top_blob.channel(q);
30
31 const float* r0 = img0.row(0);
32 const float* r1 = img0.row(1);
33
34 for (int i = 0; i < outh; i++)
35 {
36 int j = 0;
37
38 for (; j + 3 < outw; j += 4)
39 {
40#if __aarch64__
41 asm volatile(
42 "prfm pldl1keep, [%1, #512] \n"
43 "ld1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%1], #64 \n"
44
45 "fmax v0.4s, v0.4s, v1.4s \n"
46 "fmax v2.4s, v2.4s, v3.4s \n"
47
48 "prfm pldl1keep, [%1, #512] \n"
49 "ld1 {v4.4s, v5.4s, v6.4s, v7.4s}, [%1], #64 \n"
50
51 "fmax v4.4s, v4.4s, v5.4s \n"
52 "fmax v6.4s, v6.4s, v7.4s \n"
53
54 "prfm pldl1keep, [%2, #512] \n"
55 "ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%2], #64 \n"
56
57 "fmax v16.4s, v16.4s, v17.4s \n"
58 "fmax v18.4s, v18.4s, v19.4s \n"
59
60 "prfm pldl1keep, [%2, #512] \n"
61 "ld1 {v20.4s, v21.4s, v22.4s, v23.4s}, [%2], #64 \n"
62
63 "fmax v20.4s, v20.4s, v21.4s \n"
64 "fmax v22.4s, v22.4s, v23.4s \n"
65
66 "fmax v0.4s, v0.4s, v16.4s \n"
67 "fmax v1.4s, v2.4s, v18.4s \n"
68 "fmax v2.4s, v4.4s, v20.4s \n"
69 "fmax v3.4s, v6.4s, v22.4s \n"
70
71 "st1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%0], #64 \n"
72
73 : "=r"(outptr), // %0
74 "=r"(r0), // %1
75 "=r"(r1) // %2
76 : "0"(outptr),
77 "1"(r0),
78 "2"(r1)
79 : "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23");
80#else // __aarch64__
81 asm volatile(
82 "pld [%1, #512] \n"
83 "vldm %1!, {d0-d7} \n"
84
85 "vmax.f32 q0, q0, q1 \n"
86 "vmax.f32 q2, q2, q3 \n"
87
88 "pld [%1, #512] \n"
89 "vldm %1!, {d8-d15} \n"
90
91 "vmax.f32 q4, q4, q5 \n"
92 "vmax.f32 q6, q6, q7 \n"
93
94 "pld [%2, #512] \n"
95 "vldm %2!, {d16-d23} \n"
96
97 "vmax.f32 q8, q8, q9 \n"
98 "vmax.f32 q10, q10, q11 \n"
99
100 "pld [%2, #512] \n"
101 "vldm %2!, {d24-d31} \n"
102
103 "vmax.f32 q12, q12, q13 \n"
104 "vmax.f32 q14, q14, q15 \n"
105
106 "vmax.f32 q0, q0, q8 \n"
107 "vmax.f32 q1, q2, q10 \n"
108 "vmax.f32 q2, q4, q12 \n"
109 "vmax.f32 q3, q6, q14 \n"
110
111 "vstm %0!, {d0-d7} \n"
112
113 : "=r"(outptr), // %0
114 "=r"(r0), // %1
115 "=r"(r1) // %2
116 : "0"(outptr),
117 "1"(r0),
118 "2"(r1)
119 : "memory", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15");
120#endif // __aarch64__
121 }
122 for (; j < outw; j++)
123 {
124 float32x4_t _r00 = vld1q_f32(r0);
125 float32x4_t _r01 = vld1q_f32(r0 + 4);
126 float32x4_t _r10 = vld1q_f32(r1);
127 float32x4_t _r11 = vld1q_f32(r1 + 4);
128
129 float32x4_t _max0 = vmaxq_f32(_r00, _r01);
130 float32x4_t _max1 = vmaxq_f32(_r10, _r11);
131 float32x4_t _max = vmaxq_f32(_max0, _max1);
132
133 vst1q_f32(outptr, _max);
134
135 r0 += 8;
136 r1 += 8;
137 outptr += 4;
138 }
139
140 r0 += tailstep;
141 r1 += tailstep;
142 }
143 }
144}