原创 一个基于C6000的优化代码的例子

2011-7-5 11:41 2248 13 13 分类: 处理器与DSP

 

基于TI C6000的,计算一幅图像的特征值.蓝色为原来的代码,黑色为优化后的DSP代码

//
#ifdef __cplusplus
#pragma CODE_SECTION(".text:ComputeZoningFeature");
#else
#pragma CODE_SECTION(ComputeZoningFeature, ".text:ComputeZoningFeature");
#endif
void ComputeZoningFeature( IUCHAR *img, IINT16 width, IINT16 height,
                           IINT16 BoundaryBlockSize, IINT16 InterBlockSize,
                           IINT16 *FeatureVector, IINT16 *n )
{
 
#if 0 // 原代码
  IINT16 cols1, cols2, cols3;
  IINT16 rows1, rows2, rows3;
  IINT16 HalfBlock, diff;
  IINT16 i, j;
  IUCHAR *p;
  IINT16 row, col;
  IINT16 NumFeaturesPerRow; //, NumFeatures;
  IINT16 w, h, k;

  cols1 = BoundaryBlockSize;
  cols3 = BoundaryBlockSize;
  cols2 = (width-BoundaryBlockSize*2)/InterBlockSize;
  rows1 = BoundaryBlockSize;
  rows3 = BoundaryBlockSize;
  rows2 = (height-BoundaryBlockSize*2)/InterBlockSize;
  NumFeaturesPerRow = 8;//cols2 + 2;


  for(i=0;i<128;i++)
   FeatureVector=0;
  // first row.
  // first column.
  p = img;
  for( i=0; i<height; i++ )
  {
     if( i < rows1 ) row = 0;
     else if( i >= height-rows3 )
     row = 1 + (height-rows1-rows3)/InterBlockSize;
     else
     row = 1 + (i-rows1)/InterBlockSize;

     for( j=0; j<width; j++ )
     {
      if( j < cols1 ) col = 0;
      else if( j >= width-cols3 )
    col = 1 + (width-cols1-cols3)/InterBlockSize;
      else
    col = 1 + (j-cols1)/InterBlockSize;

      FeatureVector[ NumFeaturesPerRow*row + col ] += *p;
      ++ p;
     }
  }

  for( i=0; i<128; i++ )
  {
    FeatureVector = (IINT16)FixedPointDivide( FeatureVector, 0, 1020, 0, RADIXFORFEATURE );
  }

  *n = (rows2+2)*(cols2+2);

 #else // DSP 代码
  int i,j;
  unsigned int *pImg,s[8];

  pImg=(unsigned int *)img;
  for(i=0;i<128;i+=8)
  { 
     for(j=0;j<4;j++)
     {
    s[j*2]   = _sadd( _extu(*(pImg+j),  24,24),  _extu(*(pImg+j),  16,24) );
    s[j*2+1] = _sadd( _extu(*(pImg+j),   8,24),  _extu(*(pImg+j),   0,24) );
         
    s[j*2]   += _sadd( _extu(*(pImg+j+4),  24,24),  _extu(*(pImg+j+4),  16,24) );
    s[j*2+1] += _sadd( _extu(*(pImg+j+4),   8,24),  _extu(*(pImg+j+4),   0,24) );
         
     }
     for(j=0;j<8;j+=2)
      _amem4(&FeatureVector[i+j]) = s[j]<<(RADIXFORFEATURE-10)
             | s[j+1]<<(RADIXFORFEATURE-10+16);
     pImg+=8;
  }
   
  *n=128;
 #endif

}

文章评论0条评论)

登录后参与讨论
我要评论
0
13
关闭 站长推荐上一条 /2 下一条