Example #1
0
void arm_negate_q7(
  q7_t * pSrc,
  q7_t * pDst,
  uint32_t blockSize)
{
  uint32_t blkCnt;                               /* loop counter */
  q7_t in;

#ifndef ARM_MATH_CM0_FAMILY

/* Run the below code for Cortex-M4 and Cortex-M3 */
  q31_t input;                                   /* Input values1-4 */
  q31_t zero = 0x00000000;


  /*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 */
    /* Read four inputs */
    input = *__SIMD32(pSrc)++;

    /* Store the Negated results in the destination buffer in a single cycle by packing the results */
    *__SIMD32(pDst)++ = __QSUB8(zero, input);

    /* Decrement the 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_FAMILY */

  while(blkCnt > 0u)
  {
    /* C = -A */
    /* Negate and then store the results in the destination buffer. */ \
      in = *pSrc++;
    *pDst++ = (in == (q7_t) 0x80) ? 0x7f : -in;

    /* Decrement the loop counter */
    blkCnt--;
  }
}
void arm_abs_q7(
  q7_t * pSrc,
  q7_t * pDst,
  uint32_t blockSize)
{
  uint32_t blkCnt;                               /* loop counter */
  q7_t in;                                       /* Input value1 */

#ifndef ARM_MATH_CM0_FAMILY

  /* Run the below code for Cortex-M4 and Cortex-M3 */
  q31_t in1, in2, in3, in4;                      /* temporary input variables */
  q31_t out1, out2, out3, out4;                  /* temporary output variables */

  /*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| */
    /* Read inputs */
    in1 = (q31_t) * pSrc;
    in2 = (q31_t) * (pSrc + 1);
    in3 = (q31_t) * (pSrc + 2);

    /* find absolute value */
    out1 = (in1 > 0) ? in1 : (q31_t)__QSUB8(0, in1);

    /* read input */
    in4 = (q31_t) * (pSrc + 3);

    /* find absolute value */
    out2 = (in2 > 0) ? in2 : (q31_t)__QSUB8(0, in2);

    /* store result to destination */
    *pDst = (q7_t) out1;

    /* find absolute value */
    out3 = (in3 > 0) ? in3 : (q31_t)__QSUB8(0, in3);

    /* find absolute value */
    out4 = (in4 > 0) ? in4 : (q31_t)__QSUB8(0, in4);

    /* store result to destination */
    *(pDst + 1) = (q7_t) out2;

    /* store result to destination */
    *(pDst + 2) = (q7_t) out3;

    /* store result to destination */
    *(pDst + 3) = (q7_t) out4;

    /* update pointers to process next samples */
    pSrc += 4u;
    pDst += 4u;

    /* Decrement the 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 */
  blkCnt = blockSize;

#endif //      #define ARM_MATH_CM0_FAMILY

  while(blkCnt > 0u)
  {
    /* C = |A| */
    /* Read the input */
    in = *pSrc++;

    /* Store the Absolute result in the destination buffer */
    *pDst++ = (in > 0) ? in : ((in == (q7_t) 0x80) ? 0x7f : -in);

    /* Decrement the loop counter */
    blkCnt--;
  }
}
void arm_sub_q7(
  q7_t * pSrcA,
  q7_t * pSrcB,
  q7_t * pDst,
  uint32_t blockSize)
{
  uint32_t blkCnt;                               /* loop counter */

#ifndef ARM_MATH_CM0_FAMILY

/* 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 */
    /* Subtract and then store the results in the destination buffer 4 samples at a time. */
    *__SIMD32(pDst)++ = __QSUB8(*__SIMD32(pSrcA)++, *__SIMD32(pSrcB)++);

    /* Decrement the 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;

  while(blkCnt > 0u)
  {
    /* C = A - B */
    /* Subtract and then store the result in the destination buffer. */
    *pDst++ = __SSAT(*pSrcA++ - *pSrcB++, 8);

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

#else

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

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

  while(blkCnt > 0u)
  {
    /* C = A - B */
    /* Subtract and then store the result in the destination buffer. */
    *pDst++ = (q7_t) __SSAT((q15_t) * pSrcA++ - *pSrcB++, 8);

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

#endif /* #ifndef ARM_MATH_CM0_FAMILY */


}
Example #4
0
void arm_sub_q7(     
  q7_t * pSrcA,     
  q7_t * pSrcB,     
  q7_t * pDst,     
  uint32_t blockSize)     
{     
  uint32_t blkCnt;                               /* loop counter */     
  q31_t inA1, inB1, inA2, inB2;	 				 /* temporary input variabels */  
  q7_t inA, inB;								 /* temporary variables */  
  q31_t out1, out2, out3, out4;					 /* temporary output variables */  
     
     
  /*loop Unrolling */     
  blkCnt = blockSize >> 4u;     
     
  /* First part of the processing with loop unrolling.  Compute 16 outputs at a time.      
   ** a second loop below computes the remaining 1 to 15 samples. */     
  while(blkCnt > 0u)     
  {     
    /* C = A - B */     
    /* Subtract and then store the results in the destination buffer 4 samples at a time. */     
	/* read 4 samples at a time from sourceA */  
	inA1 = _SIMD32_OFFSET(pSrcA);  
	/* read 4 samples at a time from sourceB */  
	inB1 = _SIMD32_OFFSET(pSrcB);  
	/* read 4 samples at a time from sourceA */  
	inA2 = _SIMD32_OFFSET(pSrcA + 4);  
  
	/* out = saturate(sourceA - sourceB) four samples at a time */  
	out1 = __QSUB8(inA1, inB1);  
  
	/* read 4 samples at a time from sourceB */  
	inB2 = _SIMD32_OFFSET(pSrcB + 4);  
  
	/* store result to destination four samples at a time */  
	_SIMD32_OFFSET(pDst) = out1;  
  
	/* out = saturate(sourceA - sourceB) four samples at a time */  
	out2 = __QSUB8(inA2, inB2);  
  
	/* read 4 samples at a time from sourceA */  
	inA1 = _SIMD32_OFFSET(pSrcA + 8);  
	/* read 4 samples at a time from sourceB */  
	inB1 = _SIMD32_OFFSET(pSrcB + 8);  
	/* read 4 samples at a time from sourceA */  
	inA2 = _SIMD32_OFFSET(pSrcA + 12);  
  
	/* out = saturate(sourceA - sourceB) four samples at a time */  
	out3 = __QSUB8(inA1, inB1);  
  
	/* read 4 samples at a time from sourceB */  
	inB2 = _SIMD32_OFFSET(pSrcB + 12);  
	  
	/* increment sourceA pointer by 16 to process next samples */  
	pSrcA += 16u;  
  
	/* store result to destination four samples at a time */  
	_SIMD32_OFFSET(pDst + 4) = out2;  
  
	/* out = saturate(sourceA - sourceB) four samples at a time */  
	out4 = __QSUB8(inA2, inB2);  
	  
	/* store result to destination four samples at a time */  
	_SIMD32_OFFSET(pDst + 8) = out3;  
  
	/* Update source pointer to process next sampels */  
	pSrcB += 16u;  
  
	/* store result to destination four samples at a time */  
	_SIMD32_OFFSET(pDst + 12) = out4;  
  
	/* Update destination pointer to process next sampels */  
	pDst += 16u;  
  
    /* Decrement the loop counter */     
    blkCnt--;     
  }     
     
  /* If the blockSize is not a multiple of 16, compute any remaining output samples here.      
   ** No loop unrolling is used. */     
  blkCnt = blockSize % 0x10u;     
     
  while(blkCnt > 0u)     
  {     
    /* C = A - B */     
    /* Subtract and then store the result in the destination buffer. */     
	inA = *pSrcA++;  
	inB = *pSrcB++;  
#ifdef CCS   
    *pDst++ = __SSATA(inA - inB, 0, 8);     
#else   
    *pDst++ = __SSAT(inA - inB, 8);     
#endif	//#ifdef CCS   
     
    /* Decrement the loop counter */     
    blkCnt--;     
  }     
     
}     
Example #5
0
/**
\brief Test case: TC_CoreSimd_ParAddSub8
\details
- Check Parallel 8-bit addition and subtraction:
  __SADD8                                   S  Signed
  __SSUB8                                   Q  Signed Saturating
  __SHADD8                                  SH Signed Halving
  __SHSUB8                                  U  Unsigned
  __QADD8                                   UQ Unsigned Saturating
  __QSUB8                                   UH Unsigned Halving
  __UADD8
  __USUB8
  __UHADD8
  __UHSUB8
  __UQADD8
  __UQSUB8
*/
void TC_CoreSimd_ParAddSub8 (void) {
#if ((defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__  == 1)) || \
     (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))     )
  volatile uint32_t op1_u32, op2_u32;
  volatile uint32_t res_u32;

  volatile int32_t op1_s32, op2_s32;
  volatile int32_t res_s32;

  /* --- __SADD8 Test ---------------------------------------------- */
  op1_s32 = (int32_t)0x87858381;
  op2_s32 = (int32_t)0x08060402;
  res_s32 = __SADD8(op1_s32, op2_s32);
  ASSERT_TRUE(res_s32 == (int32_t)0x8F8B8783);

  /* --- __SSUB8 Test ---------------------------------------------- */
  op1_s32 = (int32_t)0x8F8B8783;
  op2_s32 = (int32_t)0x08060402;
  res_s32 = __SSUB8(op1_s32, op2_s32);
  ASSERT_TRUE(res_s32 == (int32_t)0x87858381);

  /* --- __SHADD8 Test ---------------------------------------------- */
  op1_s32 = 0x07050302;
  op2_s32 = 0x08060402;
  res_s32 = __SHADD8(op1_s32, op2_s32);
  ASSERT_TRUE(res_s32 == 0x07050302);

  /* --- __SHSUB8 Test ---------------------------------------------- */
  op1_s32 = (int32_t)0x8F8B8783;
  op2_s32 = 0x08060402;
  res_s32 = __SHSUB8(op1_s32, op2_s32);
  ASSERT_TRUE(res_s32 == (int32_t)0xC3C2C1C0);

  /* --- __QADD8 Test ---------------------------------------------- */
  op1_s32 = (int32_t)0x8085837F;
  op2_s32 = (int32_t)0xFF060402;
  res_s32 = __QADD8(op1_s32, op2_s32);
  ASSERT_TRUE(res_s32 == (int32_t)0x808B877F);

  /* --- __QSUB8 Test ---------------------------------------------- */
  op1_s32 = (int32_t)0x808B8783;
  op2_s32 = (int32_t)0x08060402;
  res_s32 = __QSUB8(op1_s32, op2_s32);
  ASSERT_TRUE(res_s32 == (int32_t)0x80858381);

  /* --- __UADD8 Test ---------------------------------------------- */
  op1_u32 = 0x07050301;
  op2_u32 = 0x08060402;
  res_u32 = __UADD8(op1_u32, op2_u32);
  ASSERT_TRUE(res_u32 == 0x0F0B0703);

  /* --- __USUB8 Test ---------------------------------------------- */
  op1_u32 = 0x0F0B0703;
  op2_u32 = 0x08060402;
  res_u32 = __USUB8(op1_u32, op2_u32);
  ASSERT_TRUE(res_u32 == 0x07050301);

  /* --- __UHADD8 Test ---------------------------------------------- */
  op1_u32 = 0x07050302;
  op2_u32 = 0x08060402;
  res_u32 = __UHADD8(op1_u32, op2_u32);
  ASSERT_TRUE(res_u32 == 0x07050302);

  /* --- __UHSUB8 Test ---------------------------------------------- */
  op1_u32 = 0x0F0B0703;
  op2_u32 = 0x08060402;
  res_u32 = __UHSUB8(op1_u32, op2_u32);
  ASSERT_TRUE(res_u32 == 0x03020100);

  /* --- __UQADD8 Test ---------------------------------------------- */
  op1_u32 = 0xFF050301;
  op2_u32 = 0x08060402;
  res_u32 = __UQADD8(op1_u32, op2_u32);
  ASSERT_TRUE(res_u32 == 0xFF0B0703);

  /* --- __UQSUB8 Test ---------------------------------------------- */
  op1_u32 = 0x080B0702;
  op2_u32 = 0x0F060408;
  res_u32 = __UQSUB8(op1_u32, op2_u32);
  ASSERT_TRUE(res_u32 == 0x00050300);
#endif
}