Elffuss BraidHub

kikocis/ncnn public

master · 1.8 KiBRawPermalink
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#include "absval_loongarch.h"
16
17#if __loongarch_sx
18#include <lsxintrin.h>
19#endif // __loongarch_sx
20
21namespace ncnn {
22
23AbsVal_loongarch::AbsVal_loongarch()
24{
25#if __loongarch_sx
26 support_packing = true;
27#endif
28}
29
30int AbsVal_loongarch::forward_inplace(Mat& bottom_top_blob, const Option& opt) const
31{
32 int w = bottom_top_blob.w;
33 int h = bottom_top_blob.h;
34 int d = bottom_top_blob.d;
35 int channels = bottom_top_blob.c;
36 int elempack = bottom_top_blob.elempack;
37 int size = w * h * d * elempack;
38
39 #pragma omp parallel for num_threads(opt.num_threads)
40 for (int q = 0; q < channels; q++)
41 {
42 float* ptr = bottom_top_blob.channel(q);
43
44 int i = 0;
45#if __loongarch_sx
46 for (; i + 3 < size; i += 4)
47 {
48 __builtin_prefetch(ptr + 16);
49 __m128i _p = __lsx_vld(ptr, 0);
50 __m128i _outp = __lsx_vbitclri_w(_p, 31);
51 __lsx_vst(_outp, ptr, 0);
52
53 ptr += 4;
54 }
55#endif // __loongarch_sx
56 for (; i < size; i++)
57 {
58 *ptr = *ptr > 0 ? *ptr : -*ptr;
59
60 ptr++;
61 }
62 }
63
64 return 0;
65}
66
67} // namespace ncnn