1 /*
2  * Copyright (C) 2010-2020 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_nn_accumulate_q7_to_q15.c
22  * Description:  Accumulate q7 vector into q15 one.
23  *
24  * $Date:        09. October 2020
25  * $Revision:    V.1.0.2
26  *
27  * pSrc Processor:  Cortex-M CPUs
28  *
29  * -------------------------------------------------------------------- */
30 
31 #include "arm_nnfunctions.h"
32 #include "arm_nnsupportfunctions.h"
33 
34 /**
35  * @ingroup groupSupport
36  */
37 
38 /**
39  * @addtogroup NNBasicMath
40  * @{
41  */
42 
arm_nn_accumulate_q7_to_q15(q15_t * pDst,const q7_t * pSrc,uint32_t length)43 void arm_nn_accumulate_q7_to_q15(q15_t *pDst, const q7_t *pSrc, uint32_t length)
44 {
45     q15_t *pCnt = pDst;
46     const q7_t *pV = pSrc;
47     q31_t v1, v2, vo1, vo2;
48     int32_t cnt = length >> 2;
49     q31_t in;
50 
51     while (cnt > 0l)
52     {
53         q31_t value = arm_nn_read_q7x4_ia(&pV);
54         v1 = __SXTB16(__ROR((uint32_t)value, 8));
55         v2 = __SXTB16(value);
56 #ifndef ARM_MATH_BIG_ENDIAN
57         vo2 = (q31_t)__PKHTB(v1, v2, 16);
58         vo1 = (q31_t)__PKHBT(v2, v1, 16);
59 #else
60         vo1 = (q31_t)__PKHTB(v1, v2, 16);
61         vo2 = (q31_t)__PKHBT(v2, v1, 16);
62 #endif
63 
64         in = arm_nn_read_q15x2(pCnt);
65         arm_nn_write_q15x2_ia(&pCnt, __QADD16(vo1, in));
66 
67         in = arm_nn_read_q15x2(pCnt);
68         arm_nn_write_q15x2_ia(&pCnt, __QADD16(vo2, in));
69 
70         cnt--;
71     }
72     cnt = length & 0x3;
73     while (cnt > 0l)
74     {
75         *pCnt++ += *pV++;
76         cnt--;
77     }
78 }
79 
80 /**
81  * @} end of NNBasicMath group
82  */
83