Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | mjames | 1 | /* ---------------------------------------------------------------------- |
| 2 | * Project: CMSIS DSP Library |
||
| 3 | * Title: arm_mat_sub_q15.c |
||
| 4 | * Description: Q15 Matrix subtraction |
||
| 5 | * |
||
| 6 | * $Date: 27. January 2017 |
||
| 7 | * $Revision: V.1.5.1 |
||
| 8 | * |
||
| 9 | * Target Processor: Cortex-M cores |
||
| 10 | * -------------------------------------------------------------------- */ |
||
| 11 | /* |
||
| 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. |
||
| 13 | * |
||
| 14 | * SPDX-License-Identifier: Apache-2.0 |
||
| 15 | * |
||
| 16 | * Licensed under the Apache License, Version 2.0 (the License); you may |
||
| 17 | * not use this file except in compliance with the License. |
||
| 18 | * You may obtain a copy of the License at |
||
| 19 | * |
||
| 20 | * www.apache.org/licenses/LICENSE-2.0 |
||
| 21 | * |
||
| 22 | * Unless required by applicable law or agreed to in writing, software |
||
| 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
||
| 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
| 25 | * See the License for the specific language governing permissions and |
||
| 26 | * limitations under the License. |
||
| 27 | */ |
||
| 28 | |||
| 29 | #include "arm_math.h" |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @ingroup groupMatrix |
||
| 33 | */ |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @addtogroup MatrixSub |
||
| 37 | * @{ |
||
| 38 | */ |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @brief Q15 matrix subtraction. |
||
| 42 | * @param[in] *pSrcA points to the first input matrix structure |
||
| 43 | * @param[in] *pSrcB points to the second input matrix structure |
||
| 44 | * @param[out] *pDst points to output matrix structure |
||
| 45 | * @return The function returns either |
||
| 46 | * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. |
||
| 47 | * |
||
| 48 | * <b>Scaling and Overflow Behavior:</b> |
||
| 49 | * \par |
||
| 50 | * The function uses saturating arithmetic. |
||
| 51 | * Results outside of the allowable Q15 range [0x8000 0x7FFF] will be saturated. |
||
| 52 | */ |
||
| 53 | |||
| 54 | arm_status arm_mat_sub_q15( |
||
| 55 | const arm_matrix_instance_q15 * pSrcA, |
||
| 56 | const arm_matrix_instance_q15 * pSrcB, |
||
| 57 | arm_matrix_instance_q15 * pDst) |
||
| 58 | { |
||
| 59 | q15_t *pInA = pSrcA->pData; /* input data matrix pointer A */ |
||
| 60 | q15_t *pInB = pSrcB->pData; /* input data matrix pointer B */ |
||
| 61 | q15_t *pOut = pDst->pData; /* output data matrix pointer */ |
||
| 62 | uint32_t numSamples; /* total number of elements in the matrix */ |
||
| 63 | uint32_t blkCnt; /* loop counters */ |
||
| 64 | arm_status status; /* status of matrix subtraction */ |
||
| 65 | |||
| 66 | |||
| 67 | #ifdef ARM_MATH_MATRIX_CHECK |
||
| 68 | |||
| 69 | |||
| 70 | /* Check for matrix mismatch condition */ |
||
| 71 | if ((pSrcA->numRows != pSrcB->numRows) || |
||
| 72 | (pSrcA->numCols != pSrcB->numCols) || |
||
| 73 | (pSrcA->numRows != pDst->numRows) || (pSrcA->numCols != pDst->numCols)) |
||
| 74 | { |
||
| 75 | /* Set status as ARM_MATH_SIZE_MISMATCH */ |
||
| 76 | status = ARM_MATH_SIZE_MISMATCH; |
||
| 77 | } |
||
| 78 | else |
||
| 79 | #endif /* #ifdef ARM_MATH_MATRIX_CHECK */ |
||
| 80 | |||
| 81 | { |
||
| 82 | /* Total number of samples in the input matrix */ |
||
| 83 | numSamples = (uint32_t) pSrcA->numRows * pSrcA->numCols; |
||
| 84 | |||
| 85 | #if defined (ARM_MATH_DSP) |
||
| 86 | |||
| 87 | /* Run the below code for Cortex-M4 and Cortex-M3 */ |
||
| 88 | |||
| 89 | /* Apply loop unrolling */ |
||
| 90 | blkCnt = numSamples >> 2U; |
||
| 91 | |||
| 92 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time. |
||
| 93 | ** a second loop below computes the remaining 1 to 3 samples. */ |
||
| 94 | while (blkCnt > 0U) |
||
| 95 | { |
||
| 96 | /* C(m,n) = A(m,n) - B(m,n) */ |
||
| 97 | /* Subtract, Saturate and then store the results in the destination buffer. */ |
||
| 98 | *__SIMD32(pOut)++ = __QSUB16(*__SIMD32(pInA)++, *__SIMD32(pInB)++); |
||
| 99 | *__SIMD32(pOut)++ = __QSUB16(*__SIMD32(pInA)++, *__SIMD32(pInB)++); |
||
| 100 | |||
| 101 | /* Decrement the loop counter */ |
||
| 102 | blkCnt--; |
||
| 103 | } |
||
| 104 | |||
| 105 | /* If the blockSize is not a multiple of 4, compute any remaining output samples here. |
||
| 106 | ** No loop unrolling is used. */ |
||
| 107 | blkCnt = numSamples % 0x4U; |
||
| 108 | |||
| 109 | while (blkCnt > 0U) |
||
| 110 | { |
||
| 111 | /* C(m,n) = A(m,n) - B(m,n) */ |
||
| 112 | /* Subtract and then store the results in the destination buffer. */ |
||
| 113 | *pOut++ = (q15_t) __QSUB16(*pInA++, *pInB++); |
||
| 114 | |||
| 115 | /* Decrement the loop counter */ |
||
| 116 | blkCnt--; |
||
| 117 | } |
||
| 118 | |||
| 119 | #else |
||
| 120 | |||
| 121 | /* Run the below code for Cortex-M0 */ |
||
| 122 | |||
| 123 | /* Initialize blkCnt with number of samples */ |
||
| 124 | blkCnt = numSamples; |
||
| 125 | |||
| 126 | while (blkCnt > 0U) |
||
| 127 | { |
||
| 128 | /* C(m,n) = A(m,n) - B(m,n) */ |
||
| 129 | /* Subtract and then store the results in the destination buffer. */ |
||
| 130 | *pOut++ = (q15_t) __SSAT(((q31_t) * pInA++ - *pInB++), 16); |
||
| 131 | |||
| 132 | /* Decrement the loop counter */ |
||
| 133 | blkCnt--; |
||
| 134 | } |
||
| 135 | |||
| 136 | #endif /* #if defined (ARM_MATH_DSP) */ |
||
| 137 | |||
| 138 | /* Set status as ARM_MATH_SUCCESS */ |
||
| 139 | status = ARM_MATH_SUCCESS; |
||
| 140 | } |
||
| 141 | |||
| 142 | /* Return to application */ |
||
| 143 | return (status); |
||
| 144 | } |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @} end of MatrixSub group |
||
| 148 | */ |