Robert Lopez / CMSIS5
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arm_mult_f32.c Source File

arm_mult_f32.c

00001 /* ----------------------------------------------------------------------
00002  * Project:      CMSIS DSP Library
00003  * Title:        arm_mult_f32.c
00004  * Description:  Floating-point vector multiplication
00005  *
00006  * $Date:        27. January 2017
00007  * $Revision:    V.1.5.1
00008  *
00009  * Target Processor: Cortex-M cores
00010  * -------------------------------------------------------------------- */
00011 /*
00012  * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved.
00013  *
00014  * SPDX-License-Identifier: Apache-2.0
00015  *
00016  * Licensed under the Apache License, Version 2.0 (the License); you may
00017  * not use this file except in compliance with the License.
00018  * You may obtain a copy of the License at
00019  *
00020  * www.apache.org/licenses/LICENSE-2.0
00021  *
00022  * Unless required by applicable law or agreed to in writing, software
00023  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
00024  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00025  * See the License for the specific language governing permissions and
00026  * limitations under the License.
00027  */
00028 
00029 #include "arm_math.h"
00030 
00031 /**
00032  * @ingroup groupMath
00033  */
00034 
00035 /**
00036  * @defgroup BasicMult Vector Multiplication
00037  *
00038  * Element-by-element multiplication of two vectors.
00039  *
00040  * <pre>
00041  *     pDst[n] = pSrcA[n] * pSrcB[n],   0 <= n < blockSize.
00042  * </pre>
00043  *
00044  * There are separate functions for floating-point, Q7, Q15, and Q31 data types.
00045  */
00046 
00047 /**
00048  * @addtogroup BasicMult
00049  * @{
00050  */
00051 
00052 /**
00053  * @brief Floating-point vector multiplication.
00054  * @param[in]       *pSrcA points to the first input vector
00055  * @param[in]       *pSrcB points to the second input vector
00056  * @param[out]      *pDst points to the output vector
00057  * @param[in]       blockSize number of samples in each vector
00058  * @return none.
00059  */
00060 
00061 void arm_mult_f32(
00062   float32_t * pSrcA,
00063   float32_t * pSrcB,
00064   float32_t * pDst,
00065   uint32_t blockSize)
00066 {
00067   uint32_t blkCnt;                               /* loop counters */
00068 #if defined (ARM_MATH_DSP)
00069 
00070   /* Run the below code for Cortex-M4 and Cortex-M3 */
00071   float32_t inA1, inA2, inA3, inA4;              /* temporary input variables */
00072   float32_t inB1, inB2, inB3, inB4;              /* temporary input variables */
00073   float32_t out1, out2, out3, out4;              /* temporary output variables */
00074 
00075   /* loop Unrolling */
00076   blkCnt = blockSize >> 2U;
00077 
00078   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.
00079    ** a second loop below computes the remaining 1 to 3 samples. */
00080   while (blkCnt > 0U)
00081   {
00082     /* C = A * B */
00083     /* Multiply the inputs and store the results in output buffer */
00084     /* read sample from sourceA */
00085     inA1 = *pSrcA;
00086     /* read sample from sourceB */
00087     inB1 = *pSrcB;
00088     /* read sample from sourceA */
00089     inA2 = *(pSrcA + 1);
00090     /* read sample from sourceB */
00091     inB2 = *(pSrcB + 1);
00092 
00093     /* out = sourceA * sourceB */
00094     out1 = inA1 * inB1;
00095 
00096     /* read sample from sourceA */
00097     inA3 = *(pSrcA + 2);
00098     /* read sample from sourceB */
00099     inB3 = *(pSrcB + 2);
00100 
00101     /* out = sourceA * sourceB */
00102     out2 = inA2 * inB2;
00103 
00104     /* read sample from sourceA */
00105     inA4 = *(pSrcA + 3);
00106 
00107     /* store result to destination buffer */
00108     *pDst = out1;
00109 
00110     /* read sample from sourceB */
00111     inB4 = *(pSrcB + 3);
00112 
00113     /* out = sourceA * sourceB */
00114     out3 = inA3 * inB3;
00115 
00116     /* store result to destination buffer */
00117     *(pDst + 1) = out2;
00118 
00119     /* out = sourceA * sourceB */
00120     out4 = inA4 * inB4;
00121     /* store result to destination buffer */
00122     *(pDst + 2) = out3;
00123     /* store result to destination buffer */
00124     *(pDst + 3) = out4;
00125 
00126 
00127     /* update pointers to process next samples */
00128     pSrcA += 4U;
00129     pSrcB += 4U;
00130     pDst += 4U;
00131 
00132     /* Decrement the blockSize loop counter */
00133     blkCnt--;
00134   }
00135 
00136   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
00137    ** No loop unrolling is used. */
00138   blkCnt = blockSize % 0x4U;
00139 
00140 #else
00141 
00142   /* Run the below code for Cortex-M0 */
00143 
00144   /* Initialize blkCnt with number of samples */
00145   blkCnt = blockSize;
00146 
00147 #endif /* #if defined (ARM_MATH_DSP) */
00148 
00149   while (blkCnt > 0U)
00150   {
00151     /* C = A * B */
00152     /* Multiply the inputs and store the results in output buffer */
00153     *pDst++ = (*pSrcA++) * (*pSrcB++);
00154 
00155     /* Decrement the blockSize loop counter */
00156     blkCnt--;
00157   }
00158 }
00159 
00160 /**
00161  * @} end of BasicMult group
00162  */
00163