打印
[C语言]

请问 循环展开(loop unrolling)相对于M0 与 M3 有何不同

[复制链接]
781|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
mrbbsp|  楼主 | 2017-8-28 11:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
TI, TE, IO, rc, ps
在与一个朋友讨论时,发现 CMSIS DSP_lib 的函数中, 对于 M3核进行了循环展开,而M0并没有
请问 M3核 哪些特性 循环展开后 效率相对于M0核来说 效率更高?



-------------------------  以下是 CMSIS DSP_lib 的一个函数  ------------------------------------------------

/* ----------------------------------------------------------------------   
* Copyright (C) 2010 ARM Limited. All rights reserved.   
*   
* $Date:        15. July 2011  
* $Revision:         V1.0.10  
*   
* Project:             CMSIS DSP Library   
* Title:            arm_mult_f32.c   
*   
* Description:        Floating-point vector multiplication.   
*   
* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
*  
* Version 1.0.10 2011/7/15
*    Big Endian support added and Merged M0 and M3/M4 Source code.  
*   
* Version 1.0.3 2010/11/29  
*    Re-organized the CMSIS folders and updated documentation.   
*   
* Version 1.0.2 2010/11/11   
*    Documentation updated.   
*   
* Version 1.0.1 2010/10/05   
*    Production release and review comments incorporated.   
*   
* Version 1.0.0 2010/09/20   
*    Production release and review comments incorporated.   
*   
* Version 0.0.5  2010/04/26   
*    incorporated review comments and updated with latest CMSIS layer   
*   
* Version 0.0.3  2010/03/10   
*    Initial version   
* -------------------------------------------------------------------- */

#include "arm_math.h"

/**   
* @ingroup groupMath   
*/

/**   
* @defgroup BasicMult Vector Multiplication   
*   
* Element-by-element multiplication of two vectors.   
*   
* <pre>   
*     pDst[n] = pSrcA[n] * pSrcB[n],   0 <= n < blockSize.   
* </pre>   
*   
* There are separate functions for floating-point, Q7, Q15, and Q31 data types.   
*/

/**   
* @addtogroup BasicMult   
* @{   
*/

/**   
* @brief Floating-point vector multiplication.   
* @param[in]       *pSrcA points to the first input vector   
* @param[in]       *pSrcB points to the second input vector   
* @param[out]      *pDst points to the output vector   
* @param[in]       blockSize number of samples in each vector   
* @return none.   
*/

void arm_mult_f32(
  float32_t * pSrcA,
  float32_t * pSrcB,
  float32_t * pDst,
  uint32_t blockSize)
{
  uint32_t blkCnt;                               /* loop counters */

#ifndef ARM_MATH_CM0

/* Run the below code for Cortex-M4 and Cortex-M3 */

  /* loop Unrolling */
  blkCnt = blockSize >> 2u;

  /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.   
   ** a second loop below computes the remaining 1 to 3 samples. */
  while(blkCnt > 0u)
  {
    /* C = A * B */
    /* Multiply the inputs and store the results in output buffer */
    *pDst++ = (*pSrcA++) * (*pSrcB++);
    *pDst++ = (*pSrcA++) * (*pSrcB++);
    *pDst++ = (*pSrcA++) * (*pSrcB++);
    *pDst++ = (*pSrcA++) * (*pSrcB++);

    /* Decrement the blockSize loop counter */
    blkCnt--;
  }

  /* If the blockSize is not a multiple of 4, compute any remaining output samples here.   
   ** No loop unrolling is used. */
  blkCnt = blockSize % 0x4u;

#else

  /* Run the below code for Cortex-M0 */

  /* Initialize blkCnt with number of samples */
  blkCnt = blockSize;

#endif /* #ifndef ARM_MATH_CM0 */


  while(blkCnt > 0u)
  {
    /* C = A * B */
    /* Multiply the inputs and store the results in output buffer */
    *pDst++ = (*pSrcA++) * (*pSrcB++);

    /* Decrement the blockSize loop counter */
    blkCnt--;
  }

}

/**   
* @} end of BasicMult group   
*/

相关帖子

沙发
linqing171| | 2017-8-28 21:07 | 只看该作者
因为啊,M0同时执行的指令没有M3多.
M3能同时执行的指令多, 但是有个缺点, 循环回去的时候, 流水线里面后面有几个执行了一半的要废弃了.

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

12

主题

39

帖子

1

粉丝