1 /*
2  * SPDX-FileCopyrightText: Copyright 2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
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_q7x4 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_q7x4 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_s8_to_s16_unordered_with_offset.c
22  * Description:  Converts the elements of the S8 vector to S16 vector with an added offset
23  *
24  * $Date:        23 Mars 2023
25  * $Revision:    V.1.0.0
26  *
27  * Target :  Arm(R) M-Profile Architecture
28  *
29  * -------------------------------------------------------------------- */
30 
31 #include "arm_nnsupportfunctions.h"
32 
33 /**
34  * @ingroup groupSupport
35  */
36 
37 /**
38  * @addtogroup supportConversion
39  * @{
40  */
41 #if defined(ARM_MATH_DSP)
arm_s8_to_s16_unordered_with_offset(const int8_t * src,int16_t * dst,int32_t block_size,int16_t offset)42 void arm_s8_to_s16_unordered_with_offset(const int8_t *src, int16_t *dst, int32_t block_size, int16_t offset)
43 {
44     int32_t in_s8x4;
45     int32_t in_s16x2_1;
46     int32_t in_s16x2_2;
47     int32_t block_cnt = block_size >> 2;
48 
49     /* Compute 4 outputs at a time. */
50     const int32_t offset_s16x2 = PKHBT(offset, offset, 16);
51     while (block_cnt > 0)
52     {
53         in_s8x4 = arm_nn_read_s8x4_ia(&src);
54 
55         in_s16x2_1 = SXTAB16(offset_s16x2, in_s8x4);
56         in_s16x2_2 = SXTAB16(offset_s16x2, ROR(in_s8x4, 8));
57 
58         arm_nn_write_q15x2_ia(&dst, in_s16x2_1);
59         arm_nn_write_q15x2_ia(&dst, in_s16x2_2);
60 
61         block_cnt--;
62     }
63 
64     /* Handle left over samples. */
65     block_cnt = block_size % 4;
66     while (block_cnt > 0)
67     {
68         *dst++ = (int16_t)*src++ + offset;
69         block_cnt--;
70     }
71 }
72 #endif
73 
74 /**
75  * @} end of Doxygen group
76  */
77