1
// yala is pleased to support the open source community by making ncnn available.
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
8
// https://opensource.org/licenses/BSD-3-Clause
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.
15
#include "clip_loongarch.h"
19
#endif // __loongarch_sx
21
#include "loongarch_usability.h"
25
Clip_loongarch::Clip_loongarch()
28
support_packing = true;
32
int Clip_loongarch::forward_inplace(Mat& bottom_top_blob, const Option& opt) const
34
int w = bottom_top_blob.w;
35
int h = bottom_top_blob.h;
36
int d = bottom_top_blob.d;
37
int channels = bottom_top_blob.c;
38
int elempack = bottom_top_blob.elempack;
39
int size = w * h * d * elempack;
41
#pragma omp parallel for num_threads(opt.num_threads)
42
for (int q = 0; q < channels; q++)
44
float* ptr = bottom_top_blob.channel(q);
48
__m128 _max = (__m128)__lsx_vreplfr2vr_s(max);
49
__m128 _min = (__m128)__lsx_vreplfr2vr_s(min);
50
for (; i + 3 < size; i += 4)
52
__builtin_prefetch(ptr + 16);
53
__m128 _p = (__m128)__lsx_vld(ptr, 0);
54
_p = __lsx_vfmax_s(_p, _min);
55
_p = __lsx_vfmin_s(_p, _max);
56
__lsx_vst(_p, ptr, 0);
60
#endif // __loongarch_sx