The CMSIS DSP 5 library

Dependents:   Nucleo-Heart-Rate ejercicioVrms2 PROYECTOFINAL ejercicioVrms ... more

Committer:
xorjoep
Date:
Thu Jun 21 11:56:27 2018 +0000
Revision:
3:4098b9d3d571
Parent:
1:24714b45cd1b
headers is a folder not a library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xorjoep 1:24714b45cd1b 1 /* ----------------------------------------------------------------------
xorjoep 1:24714b45cd1b 2 * Project: CMSIS DSP Library
xorjoep 1:24714b45cd1b 3 * Title: arm_mat_sub_f32.c
xorjoep 1:24714b45cd1b 4 * Description: Floating-point matrix subtraction
xorjoep 1:24714b45cd1b 5 *
xorjoep 1:24714b45cd1b 6 * $Date: 27. January 2017
xorjoep 1:24714b45cd1b 7 * $Revision: V.1.5.1
xorjoep 1:24714b45cd1b 8 *
xorjoep 1:24714b45cd1b 9 * Target Processor: Cortex-M cores
xorjoep 1:24714b45cd1b 10 * -------------------------------------------------------------------- */
xorjoep 1:24714b45cd1b 11 /*
xorjoep 1:24714b45cd1b 12 * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
xorjoep 1:24714b45cd1b 13 *
xorjoep 1:24714b45cd1b 14 * SPDX-License-Identifier: Apache-2.0
xorjoep 1:24714b45cd1b 15 *
xorjoep 1:24714b45cd1b 16 * Licensed under the Apache License, Version 2.0 (the License); you may
xorjoep 1:24714b45cd1b 17 * not use this file except in compliance with the License.
xorjoep 1:24714b45cd1b 18 * You may obtain a copy of the License at
xorjoep 1:24714b45cd1b 19 *
xorjoep 1:24714b45cd1b 20 * www.apache.org/licenses/LICENSE-2.0
xorjoep 1:24714b45cd1b 21 *
xorjoep 1:24714b45cd1b 22 * Unless required by applicable law or agreed to in writing, software
xorjoep 1:24714b45cd1b 23 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
xorjoep 1:24714b45cd1b 24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
xorjoep 1:24714b45cd1b 25 * See the License for the specific language governing permissions and
xorjoep 1:24714b45cd1b 26 * limitations under the License.
xorjoep 1:24714b45cd1b 27 */
xorjoep 1:24714b45cd1b 28
xorjoep 1:24714b45cd1b 29 #include "arm_math.h"
xorjoep 1:24714b45cd1b 30
xorjoep 1:24714b45cd1b 31 /**
xorjoep 1:24714b45cd1b 32 * @ingroup groupMatrix
xorjoep 1:24714b45cd1b 33 */
xorjoep 1:24714b45cd1b 34
xorjoep 1:24714b45cd1b 35 /**
xorjoep 1:24714b45cd1b 36 * @defgroup MatrixSub Matrix Subtraction
xorjoep 1:24714b45cd1b 37 *
xorjoep 1:24714b45cd1b 38 * Subtract two matrices.
xorjoep 1:24714b45cd1b 39 * \image html MatrixSubtraction.gif "Subraction of two 3 x 3 matrices"
xorjoep 1:24714b45cd1b 40 *
xorjoep 1:24714b45cd1b 41 * The functions check to make sure that
xorjoep 1:24714b45cd1b 42 * <code>pSrcA</code>, <code>pSrcB</code>, and <code>pDst</code> have the same
xorjoep 1:24714b45cd1b 43 * number of rows and columns.
xorjoep 1:24714b45cd1b 44 */
xorjoep 1:24714b45cd1b 45
xorjoep 1:24714b45cd1b 46 /**
xorjoep 1:24714b45cd1b 47 * @addtogroup MatrixSub
xorjoep 1:24714b45cd1b 48 * @{
xorjoep 1:24714b45cd1b 49 */
xorjoep 1:24714b45cd1b 50
xorjoep 1:24714b45cd1b 51 /**
xorjoep 1:24714b45cd1b 52 * @brief Floating-point matrix subtraction
xorjoep 1:24714b45cd1b 53 * @param[in] *pSrcA points to the first input matrix structure
xorjoep 1:24714b45cd1b 54 * @param[in] *pSrcB points to the second input matrix structure
xorjoep 1:24714b45cd1b 55 * @param[out] *pDst points to output matrix structure
xorjoep 1:24714b45cd1b 56 * @return The function returns either
xorjoep 1:24714b45cd1b 57 * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
xorjoep 1:24714b45cd1b 58 */
xorjoep 1:24714b45cd1b 59
xorjoep 1:24714b45cd1b 60 arm_status arm_mat_sub_f32(
xorjoep 1:24714b45cd1b 61 const arm_matrix_instance_f32 * pSrcA,
xorjoep 1:24714b45cd1b 62 const arm_matrix_instance_f32 * pSrcB,
xorjoep 1:24714b45cd1b 63 arm_matrix_instance_f32 * pDst)
xorjoep 1:24714b45cd1b 64 {
xorjoep 1:24714b45cd1b 65 float32_t *pIn1 = pSrcA->pData; /* input data matrix pointer A */
xorjoep 1:24714b45cd1b 66 float32_t *pIn2 = pSrcB->pData; /* input data matrix pointer B */
xorjoep 1:24714b45cd1b 67 float32_t *pOut = pDst->pData; /* output data matrix pointer */
xorjoep 1:24714b45cd1b 68
xorjoep 1:24714b45cd1b 69 #if defined (ARM_MATH_DSP)
xorjoep 1:24714b45cd1b 70
xorjoep 1:24714b45cd1b 71 float32_t inA1, inA2, inB1, inB2, out1, out2; /* temporary variables */
xorjoep 1:24714b45cd1b 72
xorjoep 1:24714b45cd1b 73 #endif // #if defined (ARM_MATH_DSP)
xorjoep 1:24714b45cd1b 74
xorjoep 1:24714b45cd1b 75 uint32_t numSamples; /* total number of elements in the matrix */
xorjoep 1:24714b45cd1b 76 uint32_t blkCnt; /* loop counters */
xorjoep 1:24714b45cd1b 77 arm_status status; /* status of matrix subtraction */
xorjoep 1:24714b45cd1b 78
xorjoep 1:24714b45cd1b 79 #ifdef ARM_MATH_MATRIX_CHECK
xorjoep 1:24714b45cd1b 80 /* Check for matrix mismatch condition */
xorjoep 1:24714b45cd1b 81 if ((pSrcA->numRows != pSrcB->numRows) ||
xorjoep 1:24714b45cd1b 82 (pSrcA->numCols != pSrcB->numCols) ||
xorjoep 1:24714b45cd1b 83 (pSrcA->numRows != pDst->numRows) || (pSrcA->numCols != pDst->numCols))
xorjoep 1:24714b45cd1b 84 {
xorjoep 1:24714b45cd1b 85 /* Set status as ARM_MATH_SIZE_MISMATCH */
xorjoep 1:24714b45cd1b 86 status = ARM_MATH_SIZE_MISMATCH;
xorjoep 1:24714b45cd1b 87 }
xorjoep 1:24714b45cd1b 88 else
xorjoep 1:24714b45cd1b 89 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
xorjoep 1:24714b45cd1b 90 {
xorjoep 1:24714b45cd1b 91 /* Total number of samples in the input matrix */
xorjoep 1:24714b45cd1b 92 numSamples = (uint32_t) pSrcA->numRows * pSrcA->numCols;
xorjoep 1:24714b45cd1b 93
xorjoep 1:24714b45cd1b 94 #if defined (ARM_MATH_DSP)
xorjoep 1:24714b45cd1b 95
xorjoep 1:24714b45cd1b 96 /* Run the below code for Cortex-M4 and Cortex-M3 */
xorjoep 1:24714b45cd1b 97
xorjoep 1:24714b45cd1b 98 /* Loop Unrolling */
xorjoep 1:24714b45cd1b 99 blkCnt = numSamples >> 2U;
xorjoep 1:24714b45cd1b 100
xorjoep 1:24714b45cd1b 101 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
xorjoep 1:24714b45cd1b 102 ** a second loop below computes the remaining 1 to 3 samples. */
xorjoep 1:24714b45cd1b 103 while (blkCnt > 0U)
xorjoep 1:24714b45cd1b 104 {
xorjoep 1:24714b45cd1b 105 /* C(m,n) = A(m,n) - B(m,n) */
xorjoep 1:24714b45cd1b 106 /* Subtract and then store the results in the destination buffer. */
xorjoep 1:24714b45cd1b 107 /* Read values from source A */
xorjoep 1:24714b45cd1b 108 inA1 = pIn1[0];
xorjoep 1:24714b45cd1b 109
xorjoep 1:24714b45cd1b 110 /* Read values from source B */
xorjoep 1:24714b45cd1b 111 inB1 = pIn2[0];
xorjoep 1:24714b45cd1b 112
xorjoep 1:24714b45cd1b 113 /* Read values from source A */
xorjoep 1:24714b45cd1b 114 inA2 = pIn1[1];
xorjoep 1:24714b45cd1b 115
xorjoep 1:24714b45cd1b 116 /* out = sourceA - sourceB */
xorjoep 1:24714b45cd1b 117 out1 = inA1 - inB1;
xorjoep 1:24714b45cd1b 118
xorjoep 1:24714b45cd1b 119 /* Read values from source B */
xorjoep 1:24714b45cd1b 120 inB2 = pIn2[1];
xorjoep 1:24714b45cd1b 121
xorjoep 1:24714b45cd1b 122 /* Read values from source A */
xorjoep 1:24714b45cd1b 123 inA1 = pIn1[2];
xorjoep 1:24714b45cd1b 124
xorjoep 1:24714b45cd1b 125 /* out = sourceA - sourceB */
xorjoep 1:24714b45cd1b 126 out2 = inA2 - inB2;
xorjoep 1:24714b45cd1b 127
xorjoep 1:24714b45cd1b 128 /* Read values from source B */
xorjoep 1:24714b45cd1b 129 inB1 = pIn2[2];
xorjoep 1:24714b45cd1b 130
xorjoep 1:24714b45cd1b 131 /* Store result in destination */
xorjoep 1:24714b45cd1b 132 pOut[0] = out1;
xorjoep 1:24714b45cd1b 133 pOut[1] = out2;
xorjoep 1:24714b45cd1b 134
xorjoep 1:24714b45cd1b 135 /* Read values from source A */
xorjoep 1:24714b45cd1b 136 inA2 = pIn1[3];
xorjoep 1:24714b45cd1b 137
xorjoep 1:24714b45cd1b 138 /* Read values from source B */
xorjoep 1:24714b45cd1b 139 inB2 = pIn2[3];
xorjoep 1:24714b45cd1b 140
xorjoep 1:24714b45cd1b 141 /* out = sourceA - sourceB */
xorjoep 1:24714b45cd1b 142 out1 = inA1 - inB1;
xorjoep 1:24714b45cd1b 143
xorjoep 1:24714b45cd1b 144
xorjoep 1:24714b45cd1b 145 /* out = sourceA - sourceB */
xorjoep 1:24714b45cd1b 146 out2 = inA2 - inB2;
xorjoep 1:24714b45cd1b 147
xorjoep 1:24714b45cd1b 148 /* Store result in destination */
xorjoep 1:24714b45cd1b 149 pOut[2] = out1;
xorjoep 1:24714b45cd1b 150
xorjoep 1:24714b45cd1b 151 /* Store result in destination */
xorjoep 1:24714b45cd1b 152 pOut[3] = out2;
xorjoep 1:24714b45cd1b 153
xorjoep 1:24714b45cd1b 154
xorjoep 1:24714b45cd1b 155 /* update pointers to process next sampels */
xorjoep 1:24714b45cd1b 156 pIn1 += 4U;
xorjoep 1:24714b45cd1b 157 pIn2 += 4U;
xorjoep 1:24714b45cd1b 158 pOut += 4U;
xorjoep 1:24714b45cd1b 159
xorjoep 1:24714b45cd1b 160 /* Decrement the loop counter */
xorjoep 1:24714b45cd1b 161 blkCnt--;
xorjoep 1:24714b45cd1b 162 }
xorjoep 1:24714b45cd1b 163
xorjoep 1:24714b45cd1b 164 /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
xorjoep 1:24714b45cd1b 165 ** No loop unrolling is used. */
xorjoep 1:24714b45cd1b 166 blkCnt = numSamples % 0x4U;
xorjoep 1:24714b45cd1b 167
xorjoep 1:24714b45cd1b 168 #else
xorjoep 1:24714b45cd1b 169
xorjoep 1:24714b45cd1b 170 /* Run the below code for Cortex-M0 */
xorjoep 1:24714b45cd1b 171
xorjoep 1:24714b45cd1b 172 /* Initialize blkCnt with number of samples */
xorjoep 1:24714b45cd1b 173 blkCnt = numSamples;
xorjoep 1:24714b45cd1b 174
xorjoep 1:24714b45cd1b 175 #endif /* #if defined (ARM_MATH_DSP) */
xorjoep 1:24714b45cd1b 176
xorjoep 1:24714b45cd1b 177 while (blkCnt > 0U)
xorjoep 1:24714b45cd1b 178 {
xorjoep 1:24714b45cd1b 179 /* C(m,n) = A(m,n) - B(m,n) */
xorjoep 1:24714b45cd1b 180 /* Subtract and then store the results in the destination buffer. */
xorjoep 1:24714b45cd1b 181 *pOut++ = (*pIn1++) - (*pIn2++);
xorjoep 1:24714b45cd1b 182
xorjoep 1:24714b45cd1b 183 /* Decrement the loop counter */
xorjoep 1:24714b45cd1b 184 blkCnt--;
xorjoep 1:24714b45cd1b 185 }
xorjoep 1:24714b45cd1b 186
xorjoep 1:24714b45cd1b 187 /* Set status as ARM_MATH_SUCCESS */
xorjoep 1:24714b45cd1b 188 status = ARM_MATH_SUCCESS;
xorjoep 1:24714b45cd1b 189 }
xorjoep 1:24714b45cd1b 190
xorjoep 1:24714b45cd1b 191 /* Return to application */
xorjoep 1:24714b45cd1b 192 return (status);
xorjoep 1:24714b45cd1b 193 }
xorjoep 1:24714b45cd1b 194
xorjoep 1:24714b45cd1b 195 /**
xorjoep 1:24714b45cd1b 196 * @} end of MatrixSub group
xorjoep 1:24714b45cd1b 197 */