- 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:        15. July 2011
    00005 * $Revision:    V1.0.10
    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/Cortex-M0
    00013 *
    00014 * Version 1.0.10 2011/7/15
    00015 *    Big Endian support added and Merged M0 and M3/M4 Source code.
    00016 *
    00017 * Version 1.0.3 2010/11/29
    00018 *    Re-organized the CMSIS folders and updated documentation.
    00019 *
    00020 * Version 1.0.2 2010/11/11
    00021 *    Documentation updated.
    00022 *
    00023 * Version 1.0.1 2010/10/05
    00024 *    Production release and review comments incorporated.
    00025 *
    00026 * Version 1.0.0 2010/09/20
    00027 *    Production release and review comments incorporated.
    00028 *
    00029 * Version 0.0.5  2010/04/26
    00030 *    incorporated review comments and updated with latest CMSIS layer
    00031 *
    00032 * Version 0.0.3  2010/03/10
    00033 *    Initial version
    00034 * -------------------------------------------------------------------- */
    00035
    00036 #include "arm_math.h"
    00037
    00061 arm_status arm_mat_add_q15(
    00062   const arm_matrix_instance_q15 * pSrcA,
    00063   const arm_matrix_instance_q15 * pSrcB,
    00064   arm_matrix_instance_q15 * pDst)
    00065 {
    00066   q15_t *pInA = pSrcA->pData;                    /* input data matrix pointer A  */
    00067   q15_t *pInB = pSrcB->pData;                    /* input data matrix pointer B */
    00068   q15_t *pOut = pDst->pData;                     /* output data matrix pointer */
    00069   uint16_t numSamples;                           /* total number of elements in the matrix  */
    00070   uint32_t blkCnt;                               /* loop counters  */
    00071   arm_status status;                             /* status of matrix addition  */
    00072
    00073 #ifdef ARM_MATH_MATRIX_CHECK
    00074
    00075
    00076   /* Check for matrix mismatch condition */
    00077   if((pSrcA->numRows != pSrcB->numRows) ||
    00078      (pSrcA->numCols != pSrcB->numCols) ||
    00079      (pSrcA->numRows != pDst->numRows) || (pSrcA->numCols != pDst->numCols))
    00080   {
    00081     /* Set status as ARM_MATH_SIZE_MISMATCH */
    00082     status = ARM_MATH_SIZE_MISMATCH;
    00083   }
    00084   else
    00085 #endif /*    #ifdef ARM_MATH_MATRIX_CHECK    */
    00086
    00087   {
    00088     /* Total number of samples in the input matrix */
    00089     numSamples = (uint16_t) (pSrcA->numRows * pSrcA->numCols);
    00090
    00091 #ifndef ARM_MATH_CM0
    00092
    00093     /* Run the below code for Cortex-M4 and Cortex-M3 */
    00094
    00095     /* Loop unrolling */
    00096     blkCnt = (uint32_t) numSamples >> 2u;
    00097
    00098     /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
    00099      ** a second loop below computes the remaining 1 to 3 samples. */
    00100     while(blkCnt > 0u)
    00101     {
    00102       /* C(m,n) = A(m,n) + B(m,n) */
    00103       /* Add, Saturate and then store the results in the destination buffer. */
    00104       *__SIMD32(pOut)++ = __QADD16(*__SIMD32(pInA)++, *__SIMD32(pInB)++);
    00105       *__SIMD32(pOut)++ = __QADD16(*__SIMD32(pInA)++, *__SIMD32(pInB)++);
    00106
    00107       /* Decrement the loop counter */
    00108       blkCnt--;
    00109     }
    00110
    00111     /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
    00112      ** No loop unrolling is used. */
    00113     blkCnt = (uint32_t) numSamples % 0x4u;
    00114
    00115     /* q15 pointers of input and output are initialized */
    00116
    00117     while(blkCnt > 0u)
    00118     {
    00119       /* C(m,n) = A(m,n) + B(m,n) */
    00120       /* Add, Saturate and then store the results in the destination buffer. */
    00121       *pOut++ = (q15_t) __QADD16(*pInA++, *pInB++);
    00122
    00123       /* Decrement the loop counter */
    00124       blkCnt--;
    00125     }
    00126
    00127 #else
    00128
    00129     /* Run the below code for Cortex-M0 */
    00130
    00131     /* Initialize blkCnt with number of samples */
    00132     blkCnt = (uint32_t) numSamples;
    00133
    00134
    00135     /* q15 pointers of input and output are initialized */
    00136     while(blkCnt > 0u)
    00137     {
    00138       /* C(m,n) = A(m,n) + B(m,n) */
    00139       /* Add, Saturate and then store the results in the destination buffer. */
    00140       *pOut++ = (q15_t) __SSAT(((q31_t) * pInA++ + *pInB++), 16);
    00141
    00142       /* Decrement the loop counter */
    00143       blkCnt--;
    00144     }
    00145
    00146 #endif /* #ifndef ARM_MATH_CM0 */
    00147
    00148     /* set status as ARM_MATH_SUCCESS */
    00149     status = ARM_MATH_SUCCESS;
    00150   }
    00151
    00152   /* Return to application */
    00153   return (status);
    00154 }
    00155

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines