Elffuss BraidHub

kikocis/ncnn public

master · 1.9 KiBRawPermalink
1// Tencent is pleased to support the open source community by making ncnn available.
2//
3// Copyright (C) 2019 Leo <leo@nullptr.com.cn>. All rights reserved.
4// Copyright (C) 2021 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
16#include "absval_mips.h"
17
18#if __mips_msa
19#include <msa.h>
20#endif // __mips_msa
21
22namespace ncnn {
23
24AbsVal_mips::AbsVal_mips()
25{
26#if __mips_msa
27 support_packing = true;
28#endif
29}
30
31int AbsVal_mips::forward_inplace(Mat& bottom_top_blob, const Option& opt) const
32{
33 int w = bottom_top_blob.w;
34 int h = bottom_top_blob.h;
35 int d = bottom_top_blob.d;
36 int channels = bottom_top_blob.c;
37 int elempack = bottom_top_blob.elempack;
38 int size = w * h * d * elempack;
39
40 #pragma omp parallel for num_threads(opt.num_threads)
41 for (int q = 0; q < channels; q++)
42 {
43 float* ptr = bottom_top_blob.channel(q);
44
45 int i = 0;
46#if __mips_msa
47 for (; i + 3 < size; i += 4)
48 {
49 __builtin_prefetch(ptr + 16);
50 v4u32 _p = (v4u32)__msa_ld_w(ptr, 0);
51 v4f32 _outp = (v4f32)__msa_bclri_w(_p, 31);
52 __msa_st_w((v4i32)_outp, ptr, 0);
53
54 ptr += 4;
55 }
56#endif // __mips_msa
57 for (; i < size; i++)
58 {
59 *ptr = *ptr > 0 ? *ptr : -*ptr;
60
61 ptr++;
62 }
63 }
64
65 return 0;
66}
67
68} // namespace ncnn