- Main Page
- Modules
- Data Structures
- Files
- Examples

- File List
- Globals

# arm_mat_add_q15.c

Go to the documentation of this file.

    00001 /* ----------------------------------------------------------------------
    00002 * Copyright (C) 2010 ARM Limited. All rights reserved.
    00003 *
    00004 * $Date:        29. November 2010
    00005 * $Revision:    V1.0.3
    00006 *
    00007 * Project:      CMSIS DSP Library
    00008 * Title:        arm_mat_add_q15.c
    00009 *
    00010 * Description:  Q15 matrix addition
    00011 *
    00012 * Target Processor: Cortex-M4/Cortex-M3
    00013 *
    00014 * Version 1.0.3 2010/11/29
    00015 *    Re-organized the CMSIS folders and updated documentation.
    00016 *
    00017 * Version 1.0.2 2010/11/11
    00018 *    Documentation updated.
    00019 *
    00020 * Version 1.0.1 2010/10/05
    00021 *    Production release and review comments incorporated.
    00022 *
    00023 * Version 1.0.0 2010/09/20
    00024 *    Production release and review comments incorporated.
    00025 *
    00026 * Version 0.0.5  2010/04/26
    00027 *    incorporated review comments and updated with latest CMSIS layer
    00028 *
    00029 * Version 0.0.3  2010/03/10
    00030 *    Initial version
    00031 * -------------------------------------------------------------------- */
    00032
    00033 #include "arm_math.h"
    00034
    00058 arm_status arm_mat_add_q15(
    00059   const arm_matrix_instance_q15 * pSrcA,
    00060   const arm_matrix_instance_q15 * pSrcB,
    00061   arm_matrix_instance_q15 * pDst)
    00062 {
    00063   q15_t *pInA = pSrcA->pData;                    /* input data matrix pointer A  */
    00064   q15_t *pInB = pSrcB->pData;                    /* input data matrix pointer B */
    00065   q15_t *pOut = pDst->pData;                     /* output data matrix pointer */
    00066   uint16_t numSamples;                           /* total number of elements in the matrix  */
    00067   uint32_t blkCnt;                               /* loop counters  */
    00068   arm_status status;                             /* status of matrix addition  */
    00069
    00070 #ifdef ARM_MATH_MATRIX_CHECK
    00071   /* Check for matrix mismatch condition */
    00072   if((pSrcA->numRows != pSrcB->numRows) ||
    00073      (pSrcA->numCols != pSrcB->numCols) ||
    00074      (pSrcA->numRows != pDst->numRows) || (pSrcA->numCols != pDst->numCols))
    00075   {
    00076     /* Set status as ARM_MATH_SIZE_MISMATCH */
    00077     status = ARM_MATH_SIZE_MISMATCH;
    00078   }
    00079   else
    00080 #endif
    00081   {
    00082     /* Total number of samples in the input matrix */
    00083     numSamples = (uint16_t) (pSrcA->numRows * pSrcA->numCols);
    00084
    00085     /* Loop unrolling */
    00086     blkCnt = (uint32_t) numSamples >> 2u;
    00087
    00088     /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
    00089      ** a second loop below computes the remaining 1 to 3 samples. */
    00090     while(blkCnt > 0u)
    00091     {
    00092       /* C(m,n) = A(m,n) + B(m,n) */
    00093       /* Add, Saturate and then store the results in the destination buffer. */
    00094       *__SIMD32(pOut)++ = __QADD16(*__SIMD32(pInA)++, *__SIMD32(pInB)++);
    00095       *__SIMD32(pOut)++ = __QADD16(*__SIMD32(pInA)++, *__SIMD32(pInB)++);
    00096
    00097       /* Decrement the loop counter */
    00098       blkCnt--;
    00099     }
    00100
    00101     /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
    00102      ** No loop unrolling is used. */
    00103     blkCnt = (uint32_t) numSamples % 0x4u;
    00104
    00105     /* q15 pointers of input and output are initialized */
    00106
    00107     while(blkCnt > 0u)
    00108     {
    00109       /* C(m,n) = A(m,n) + B(m,n) */
    00110       /* Add, Saturate and then store the results in the destination buffer. */
    00111       *pOut++ = (q15_t) __QADD16(*pInA++, *pInB++);
    00112
    00113       /* Decrement the loop counter */
    00114       blkCnt--;
    00115     }
    00116
    00117     /* set status as ARM_MATH_SUCCESS */
    00118     status = ARM_MATH_SUCCESS;
    00119   }
    00120
    00121   /* Return to application */
    00122   return (status);
    00123 }
    00124

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines