硬汉嵌入式论坛

 找回密码
 立即注册
查看: 6241|回复: 0
收起左侧

[客户分享] FPU实验:BasicMathFunctions之求和

[复制链接]

20

主题

55

回帖

20

积分

初级会员

积分
20
发表于 2012-12-21 21:28:59 | 显示全部楼层 |阅读模式
说明:基本函数里面做浮点数的运算很简单,该怎么算就怎么算,而定点数可能使用一些汇编指令
  1. /**   
  2. * @defgroup BasicAdd Vector Addition   
  3. *   
  4. * Element-by-element addition of two vectors.   
  5. *   
  6. * <pre>   
  7. *     pDst[n] = pSrcA[n] + pSrcB[n],   0 <= n < blockSize.   
  8. * </pre>   
  9. *   
  10. * There are separate functions for floating-point, Q7, Q15, and Q31 data types.   
  11. */
  12. /**   
  13. * @addtogroup BasicAdd   
  14. * @{   
  15. */
  16. /**   
  17. * @brief Floating-point vector addition.   
  18. * @param[in]       *pSrcA points to the first input vector   
  19. * @param[in]       *pSrcB points to the second input vector   
  20. * @param[out]      *pDst points to the output vector   
  21. * @param[in]       blockSize number of samples in each vector   
  22. * @return none.   
  23. */
  24. void arm_add_f32(
  25.   float32_t * pSrcA,
  26.   float32_t * pSrcB,
  27.   float32_t * pDst,
  28.   uint32_t blockSize)
  29. {
  30.   uint32_t blkCnt;                               /* loop counter */
  31. #ifndef ARM_MATH_CM0
  32. /* Run the below code for Cortex-M4 and Cortex-M3 */
  33.   /*loop Unrolling */
  34.   blkCnt = blockSize >> 2u;
  35.   /* First part of the processing with loop unrolling.  Compute 4 outputs at a time.   
  36.    ** a second loop below computes the remaining 1 to 3 samples. */
  37.   while(blkCnt > 0u)
  38.   {
  39.     /* C = A + B */
  40.     /* Add and then store the results in the destination buffer. */
  41.     *pDst++ = (*pSrcA++) + (*pSrcB++);
  42.     *pDst++ = (*pSrcA++) + (*pSrcB++);
  43.     *pDst++ = (*pSrcA++) + (*pSrcB++);
  44.     *pDst++ = (*pSrcA++) + (*pSrcB++);
  45.     /* Decrement the loop counter */
  46.     blkCnt--;
  47.   }
  48.   /* If the blockSize is not a multiple of 4, compute any remaining output samples here.   
  49.    ** No loop unrolling is used. */
  50.   blkCnt = blockSize % 0x4u;
  51. #else
  52.   /* Run the below code for Cortex-M0 */
  53.   /* Initialize blkCnt with number of samples */
  54.   blkCnt = blockSize;
  55. #endif /* #ifndef ARM_MATH_CM0 */
  56.   while(blkCnt > 0u)
  57.   {
  58.     /* C = A + B */
  59.     /* Add and then store the results in the destination buffer. */
  60.     *pDst++ = (*pSrcA++) + (*pSrcB++);
  61.     /* Decrement the loop counter */
  62.     blkCnt--;
  63.   }
  64. }
复制代码
天天向上
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-17 06:58 , Processed in 0.137550 second(s), 24 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表