Subversion Repositories dashGPS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /* ----------------------------------------------------------------------
  2.  * Project:      CMSIS DSP Library
  3.  * Title:        arm_mat_sub_f32.c
  4.  * Description:  Floating-point 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.  * @defgroup MatrixSub Matrix Subtraction
  37.  *
  38.  * Subtract two matrices.
  39.  * \image html MatrixSubtraction.gif "Subraction of two 3 x 3 matrices"
  40.  *
  41.  * The functions check to make sure that
  42.  * <code>pSrcA</code>, <code>pSrcB</code>, and <code>pDst</code> have the same
  43.  * number of rows and columns.
  44.  */
  45.  
  46. /**
  47.  * @addtogroup MatrixSub
  48.  * @{
  49.  */
  50.  
  51. /**
  52.  * @brief Floating-point matrix subtraction
  53.  * @param[in]       *pSrcA points to the first input matrix structure
  54.  * @param[in]       *pSrcB points to the second input matrix structure
  55.  * @param[out]      *pDst points to output matrix structure
  56.  * @return              The function returns either
  57.  * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  58.  */
  59.  
  60. arm_status arm_mat_sub_f32(
  61.   const arm_matrix_instance_f32 * pSrcA,
  62.   const arm_matrix_instance_f32 * pSrcB,
  63.   arm_matrix_instance_f32 * pDst)
  64. {
  65.   float32_t *pIn1 = pSrcA->pData;                /* input data matrix pointer A */
  66.   float32_t *pIn2 = pSrcB->pData;                /* input data matrix pointer B */
  67.   float32_t *pOut = pDst->pData;                 /* output data matrix pointer  */
  68.  
  69. #if defined (ARM_MATH_DSP)
  70.  
  71.   float32_t inA1, inA2, inB1, inB2, out1, out2;  /* temporary variables */
  72.  
  73. #endif //      #if defined (ARM_MATH_DSP)
  74.  
  75.   uint32_t numSamples;                           /* total number of elements in the matrix  */
  76.   uint32_t blkCnt;                               /* loop counters */
  77.   arm_status status;                             /* status of matrix subtraction */
  78.  
  79. #ifdef ARM_MATH_MATRIX_CHECK
  80.   /* Check for matrix mismatch condition */
  81.   if ((pSrcA->numRows != pSrcB->numRows) ||
  82.      (pSrcA->numCols != pSrcB->numCols) ||
  83.      (pSrcA->numRows != pDst->numRows) || (pSrcA->numCols != pDst->numCols))
  84.   {
  85.     /* Set status as ARM_MATH_SIZE_MISMATCH */
  86.     status = ARM_MATH_SIZE_MISMATCH;
  87.   }
  88.   else
  89. #endif /*    #ifdef ARM_MATH_MATRIX_CHECK    */
  90.   {
  91.     /* Total number of samples in the input matrix */
  92.     numSamples = (uint32_t) pSrcA->numRows * pSrcA->numCols;
  93.  
  94. #if defined (ARM_MATH_DSP)
  95.  
  96.     /* Run the below code for Cortex-M4 and Cortex-M3 */
  97.  
  98.     /* Loop Unrolling */
  99.     blkCnt = numSamples >> 2U;
  100.  
  101.     /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
  102.      ** a second loop below computes the remaining 1 to 3 samples. */
  103.     while (blkCnt > 0U)
  104.     {
  105.       /* C(m,n) = A(m,n) - B(m,n) */
  106.       /* Subtract and then store the results in the destination buffer. */
  107.       /* Read values from source A */
  108.       inA1 = pIn1[0];
  109.  
  110.       /* Read values from source B */
  111.       inB1 = pIn2[0];
  112.  
  113.       /* Read values from source A */
  114.       inA2 = pIn1[1];
  115.  
  116.       /* out = sourceA - sourceB */
  117.       out1 = inA1 - inB1;
  118.  
  119.       /* Read values from source B */
  120.       inB2 = pIn2[1];
  121.  
  122.       /* Read values from source A */
  123.       inA1 = pIn1[2];
  124.  
  125.       /* out = sourceA - sourceB */
  126.       out2 = inA2 - inB2;
  127.  
  128.       /* Read values from source B */
  129.       inB1 = pIn2[2];
  130.  
  131.       /* Store result in destination */
  132.       pOut[0] = out1;
  133.       pOut[1] = out2;
  134.  
  135.       /* Read values from source A */
  136.       inA2 = pIn1[3];
  137.  
  138.       /* Read values from source B */
  139.       inB2 = pIn2[3];
  140.  
  141.       /* out = sourceA - sourceB */
  142.       out1 = inA1 - inB1;
  143.  
  144.  
  145.       /* out = sourceA - sourceB */
  146.       out2 = inA2 - inB2;
  147.  
  148.       /* Store result in destination */
  149.       pOut[2] = out1;
  150.  
  151.       /* Store result in destination */
  152.       pOut[3] = out2;
  153.  
  154.  
  155.       /* update pointers to process next sampels */
  156.       pIn1 += 4U;
  157.       pIn2 += 4U;
  158.       pOut += 4U;
  159.  
  160.       /* Decrement the loop counter */
  161.       blkCnt--;
  162.     }
  163.  
  164.     /* If the numSamples is not a multiple of 4, compute any remaining output samples here.
  165.      ** No loop unrolling is used. */
  166.     blkCnt = numSamples % 0x4U;
  167.  
  168. #else
  169.  
  170.     /* Run the below code for Cortex-M0 */
  171.  
  172.     /* Initialize blkCnt with number of samples */
  173.     blkCnt = numSamples;
  174.  
  175. #endif /* #if defined (ARM_MATH_DSP) */
  176.  
  177.     while (blkCnt > 0U)
  178.     {
  179.       /* C(m,n) = A(m,n) - B(m,n) */
  180.       /* Subtract and then store the results in the destination buffer. */
  181.       *pOut++ = (*pIn1++) - (*pIn2++);
  182.  
  183.       /* Decrement the loop counter */
  184.       blkCnt--;
  185.     }
  186.  
  187.     /* Set status as ARM_MATH_SUCCESS */
  188.     status = ARM_MATH_SUCCESS;
  189.   }
  190.  
  191.   /* Return to application */
  192.   return (status);
  193. }
  194.  
  195. /**
  196.  * @} end of MatrixSub group
  197.  */
  198.