source: S-port/trunk/Drivers/CMSIS/NN/Source/ActivationFunctions/arm_relu_q15.c

Last change on this file was 1, checked in by AlexLir, 3 years ago
File size: 2.4 KB
Line 
1/*
2 * Copyright (C) 2010-2018 Arm Limited or its affiliates. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19/* ----------------------------------------------------------------------
20 * Project: CMSIS NN Library
21 * Title: arm_relu_q15.c
22 * Description: Q15 version of ReLU
23 *
24 * $Date: 17. January 2018
25 * $Revision: V.1.0.0
26 *
27 * Target Processor: Cortex-M cores
28 *
29 * -------------------------------------------------------------------- */
30
31#include "arm_math.h"
32#include "arm_nnfunctions.h"
33
34/**
35 * @ingroup groupNN
36 */
37
38/**
39 * @addtogroup Acti
40 * @{
41 */
42
43 /**
44 * @brief Q15 RELU function
45 * @param[in,out] data pointer to input
46 * @param[in] size number of elements
47 * @return none.
48 *
49 * @details
50 *
51 * Optimized relu with QSUB instructions.
52 *
53 */
54
55void arm_relu_q15(q15_t * data, uint16_t size)
56{
57
58#if defined (ARM_MATH_DSP)
59 /* Run the following code for Cortex-M4 and Cortex-M7 */
60
61 uint16_t i = size >> 1;
62 q15_t *pIn = data;
63 q15_t *pOut = data;
64 q31_t in;
65 q31_t buf;
66 q31_t mask;
67
68 while (i)
69 {
70 in = *__SIMD32(pIn)++;
71
72 /* extract the first bit */
73 buf = __ROR(in & 0x80008000, 15);
74
75 /* if MSB=1, mask will be 0xFF, 0x0 otherwise */
76 mask = __QSUB16(0x00000000, buf);
77
78 *__SIMD32(pOut)++ = in & (~mask);
79 i--;
80 }
81
82 if (size & 0x1)
83 {
84 if (*pIn < 0)
85 {
86 *pIn = 0;
87 }
88 pIn++;
89 }
90#else
91 /* Run the following code as reference implementation for Cortex-M0 and Cortex-M3 */
92 uint16_t i;
93
94 for (i = 0; i < size; i++)
95 {
96 if (data[i] < 0)
97 data[i] = 0;
98 }
99
100#endif /* ARM_MATH_DSP */
101
102}
103
104/**
105 * @} end of Acti group
106 */
Note: See TracBrowser for help on using the repository browser.