⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 idct.c

📁 TI DSP TMS320DM642 用定时器测试函数执行时间
💻 C
字号:


#define Clip1(a)            ((a)>255?255:((a)<0?0:(a)))
#define Clip3(min,max,val) (((val)<(min))?(min):(((val)>(max))?(max):(val)))
#define B8_SIZE         8 

void inv_transform_B8_1(short  curr_blk1[restrict][B8_SIZE]   )  // block to be inverse transformed.
 {
   short int xx=0, yy=0;
//   short int tmp[8];
    int m0,m1,m2,m3;
    int tmp0,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6,tmp7;
    int t=0;
//   short  int b[8];
    int b0,b1,b2,b3,b4,b5,b6,b7;
//   #pragma UNROLL(2);
   for(yy=0; yy<8; yy++)
   {
     // Horizontal inverse transform
     // Reorder
     tmp0=curr_blk1[yy][0];
     tmp1=curr_blk1[yy][4];
     tmp2=curr_blk1[yy][2];
     tmp3=curr_blk1[yy][6];
     tmp4=curr_blk1[yy][1];
     tmp5=curr_blk1[yy][3];
     tmp6=curr_blk1[yy][5];
     tmp7=curr_blk1[yy][7];
     
//     m0 = _lo(_memd8_const(&curr_blk1[yy][0]));
//     m1 = _hi(_memd8_const(&curr_blk1[yy][0]));
//     m2 = _lo(_memd8_const(&curr_blk1[yy][4]));
//     m3 = _hi(_memd8_const(&curr_blk1[yy][4]));
//     tmp0 = (short)m0;
//     tmp4 = m0>>16;
//     tmp2 = (short)m1;
//     tmp5 = m1>>16;
//     tmp1 = (short)m2;
//     tmp6 = m2>>16;
//     tmp3 = (short)m3;
//     tmp7 = m3>>16;
//     
//     
     // Downleft Butterfly
	b0 = ((tmp4 - tmp7)<<1) + tmp4;
	b1 = ((tmp5 + tmp6)<<1) + tmp5;
	b2 = ((tmp5 - tmp6)<<1) - tmp6;
	b3 = ((tmp4 + tmp7)<<1) + tmp7;

	b4 = ((b0 + b1 + b3)<<1) + b1;
	b5 = ((b0 - b1 + b2)<<1) + b0;
	b6 = ((-b1 - b2 + b3)<<1)+ b3;
	b7 = ((b0 - b2 - b3)<<1) - b2;
     
     // Upleft Butterfly
	 t=((tmp2*10)+(tmp3<<2));
	 tmp3=((tmp2<<2)-(tmp3*10));
     tmp2=t;
     
     t=(tmp0+tmp1)<<3;
     tmp1=(tmp0-tmp1)<<3;
     tmp0=t;
     
     b0=tmp0+tmp2;
     b1=tmp1+tmp3;
     b2=tmp1-tmp3;
     b3=tmp0-tmp2;	 
     
     // Last Butterfly
	 curr_blk1[yy][0]=((b0+b4)+4)>>3;
	 curr_blk1[yy][1]=((b1+b5)+4)>>3;
	 curr_blk1[yy][2]=((b2+b6)+4)>>3;
	 curr_blk1[yy][3]=((b3+b7)+4)>>3;
	 curr_blk1[yy][7]=((b0-b4)+4)>>3;
	 curr_blk1[yy][6]=((b1-b5)+4)>>3;
	 curr_blk1[yy][5]=((b2-b6)+4)>>3;
	 curr_blk1[yy][4]=((b3-b7)+4)>>3;
   }
   // Vertical inverse transform
   for(xx=0; xx<8; xx++)
   {
     
     // Reorder
     tmp0=curr_blk1[0][xx];
     tmp1=curr_blk1[4][xx];
     tmp2=curr_blk1[2][xx];
     tmp3=curr_blk1[6][xx];
     tmp4=curr_blk1[1][xx];
     tmp5=curr_blk1[3][xx];
     tmp6=curr_blk1[5][xx];
     tmp7=curr_blk1[7][xx];
     
     // Downleft Butterfly
	b0 = ((tmp4 - tmp7)<<1) + tmp4;
	b1 = ((tmp5 + tmp6)<<1) + tmp5;
	b2 = ((tmp5 - tmp6)<<1) - tmp6;
	b3 = ((tmp4 + tmp7)<<1) + tmp7;

	b4 = ((b0 + b1 + b3)<<1) + b1;
	b5 = ((b0 - b1 + b2)<<1) + b0;
	b6 = ((-b1 - b2 + b3)<<1) + b3;
    b7 = ((b0 - b2 - b3)<<1) - b2; 
     // Upleft Butterfly
	 t=((tmp2*10)+(tmp3<<2));
	 tmp3=((tmp2<<2)-(tmp3*10));
     tmp2=t;
     
     t=(tmp0+tmp1)<<3;
     tmp1=(tmp0-tmp1)<<3;
     tmp0=t;
     
     b0=tmp0+tmp2;
     b1=tmp1+tmp3;
     b2=tmp1-tmp3;
     b3=tmp0-tmp2;
     
     curr_blk1[0][xx]=(Clip3(-32768,32703,b0+b4)+64)>>7;  //(b0+b4+64)>>7;
     curr_blk1[1][xx]=(Clip3(-32768,32703,b1+b5)+64)>>7;  //(b1+b5+64)>>7;
     curr_blk1[2][xx]=(Clip3(-32768,32703,b2+b6)+64)>>7;  //(b2+b6+64)>>7;
     curr_blk1[3][xx]=(Clip3(-32768,32703,b3+b7)+64)>>7;  //(b3+b7+64)>>7;
     curr_blk1[7][xx]=(Clip3(-32768,32703,b0-b4)+64)>>7;  //(b0-b4+64)>>7;
     curr_blk1[6][xx]=(Clip3(-32768,32703,b1-b5)+64)>>7;  //(b1-b5+64)>>7;
     curr_blk1[5][xx]=(Clip3(-32768,32703,b2-b6)+64)>>7;  //(b2-b6+64)>>7;
     curr_blk1[4][xx]=(Clip3(-32768,32703,b3-b7)+64)>>7;  //(b3-b7+64)>>7;
	
   }
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
void inv_transform_B8_2(int curr_blk1[B8_SIZE][B8_SIZE]  // block to be inverse transformed.
   )
 {
   short int xx, yy;
//   short int tmp[8];
//   short  int b[8]; 
   short int tmp0,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6,tmp7;
   short  int b0,b1,b2,b3,b4,b5,b6,b7;   
   short int t;

	     
   for(yy=0; yy<8; yy++)
   {
/*
     tmp0=curr_blk1[yy][0];
     tmp1=curr_blk1[yy][4];
     tmp2=curr_blk1[yy][2];
     tmp3=curr_blk1[yy][6];
     tmp4=curr_blk1[yy][1];
     tmp5=curr_blk1[yy][3];
     tmp6=curr_blk1[yy][5];
     tmp7=curr_blk1[yy][7];
     
     // Downleft Butterfly

	b0 = ((tmp4 - tmp7)<<1) + tmp4;
	b1 = ((tmp5 + tmp6)<<1) + tmp5;
	b2 = ((tmp5 - tmp6)<<1) - tmp6;
	b3 = ((tmp4 + tmp7)<<1) + tmp7;

	b4 = ((b0 + b1 + b3)<<1) + b1;
	b5 = ((b0 - b1 + b2)<<1) + b0;
	b6 = ((-b1 - b2 + b3)<<1) + b3;
	b7 = ((b0 - b2 - b3)<<1) - b2;
     
     // Upleft Butterfly
	 t=((tmp2*10)+(tmp3<<2));
	 tmp3=((tmp2<<2)-(tmp3*10));
     tmp2=t;
     
     t=(tmp0+tmp1)<<3;
     tmp1=(tmp0-tmp1)<<3;
     tmp0=t;
     
     b0=tmp0+tmp2;
     b1=tmp1+tmp3;
     b2=tmp1-tmp3;
     b3=tmp0-tmp2;	 
     
     // Last Butterfly
	 curr_blk1[yy][0]=((b0+b4)+(1<<2))>>3;
	 curr_blk1[yy][1]=((b1+b5)+(1<<2))>>3;
	 curr_blk1[yy][2]=((b2+b6)+(1<<2))>>3;
	 curr_blk1[yy][3]=((b3+b7)+(1<<2))>>3;
	 curr_blk1[yy][7]=((b0-b4)+(1<<2))>>3;
	 curr_blk1[yy][6]=((b1-b5)+(1<<2))>>3;
	 curr_blk1[yy][5]=((b2-b6)+(1<<2))>>3;
	 curr_blk1[yy][4]=((b3-b7)+(1<<2))>>3;
*/
     tmp0=curr_blk1[yy][0];
     tmp1=curr_blk1[yy][4];
     tmp2=curr_blk1[yy][2];
     tmp3=curr_blk1[yy][6];
     tmp4=curr_blk1[yy][1];
     tmp5=curr_blk1[yy][3];
     tmp6=curr_blk1[yy][5];
     tmp7=curr_blk1[yy][7];
     
//     m0 = _lo(_memd8_const(&curr_blk1[yy][0]));
//     m1 = _hi(_memd8_const(&curr_blk1[yy][0]));
//     m2 = _lo(_memd8_const(&curr_blk1[yy][4]));
//     m3 = _hi(_memd8_const(&curr_blk1[yy][4]));
//     tmp0 = (short)m0;
//     tmp4 = m0>>16;
//     tmp2 = (short)m1;
//     tmp5 = m1>>16;
//     tmp1 = (short)m2;
//     tmp6 = m2>>16;
//     tmp3 = (short)m3;
//     tmp7 = m3>>16;
//     
//     
     // Downleft Butterfly
	b0 = ((tmp4 - tmp7)<<1) + tmp4;
	b1 = ((tmp5 + tmp6)<<1) + tmp5;
	b2 = ((tmp5 - tmp6)<<1) - tmp6;
	b3 = ((tmp4 + tmp7)<<1) + tmp7;

	b4 = ((b0 + b1 + b3)<<1) + b1;
	b5 = ((b0 - b1 + b2)<<1) + b0;
	b6 = ((-b1 - b2 + b3)<<1)+ b3;
	b7 = ((b0 - b2 - b3)<<1) - b2;
     
     // Upleft Butterfly
	 t=((tmp2*10)+(tmp3<<2));
	 tmp3=((tmp2<<2)-(tmp3*10));
     tmp2=t;
     
     t=(tmp0+tmp1)<<3;
     tmp1=(tmp0-tmp1)<<3;
     tmp0=t;
     
     b0=tmp0+tmp2;
     b1=tmp1+tmp3;
     b2=tmp1-tmp3;
     b3=tmp0-tmp2;	 
     
     // Last Butterfly
	 curr_blk1[yy][0]=((b0+b4)+4)>>3;
	 curr_blk1[yy][1]=((b1+b5)+4)>>3;
	 curr_blk1[yy][2]=((b2+b6)+4)>>3;
	 curr_blk1[yy][3]=((b3+b7)+4)>>3;
	 curr_blk1[yy][7]=((b0-b4)+4)>>3;
	 curr_blk1[yy][6]=((b1-b5)+4)>>3;
	 curr_blk1[yy][5]=((b2-b6)+4)>>3;
	 curr_blk1[yy][4]=((b3-b7)+4)>>3;
   }
   // Vertical inverse transform
   for(xx=0; xx<8; xx++)
   {
     
     // Reorder
     tmp0=curr_blk1[0][xx];
     tmp1=curr_blk1[4][xx];
     tmp2=curr_blk1[2][xx];
     tmp3=curr_blk1[6][xx];
     tmp4=curr_blk1[1][xx];
     tmp5=curr_blk1[3][xx];
     tmp6=curr_blk1[5][xx];
     tmp7=curr_blk1[7][xx];
     
     // Downleft Butterfly

	b0 = ((tmp4 - tmp7)<<1) + tmp4;
	b1 = ((tmp5 + tmp6)<<1) + tmp5;
	b2 = ((tmp5 - tmp6)<<1) - tmp6;
	b3 = ((tmp4 + tmp7)<<1) + tmp7;

	b4 = ((b0 + b1 + b3)<<1) + b1;
	b5 = ((b0 - b1 + b2)<<1) + b0;
	b6 = ((-b1 - b2 + b3)<<1) + b3;
	b7 = ((b0 - b2 - b3)<<1) - b2;
/*     
     // Upleft Butterfly
	 t=((tmp2*10)+(tmp3<<2));
	 tmp3=((tmp2<<2)-(tmp3*10));
     tmp2=t;
     
     t=(tmp0+tmp1)<<3;
     tmp1=(tmp0-tmp1)<<3;
     tmp0=t;

     b0=tmp0+tmp2;
     b1=tmp1+tmp3;
     b2=tmp1-tmp3;
     b3=tmp0-tmp2;
     
     // Last Butterfly
     // Last Butterfly
     curr_blk1[0][xx]=(Clip3(-32768,32703,b0+b4)+64)>>7;
     curr_blk1[1][xx]=(Clip3(-32768,32703,b1+b5)+64)>>7;
     curr_blk1[2][xx]=(Clip3(-32768,32703,b2+b6)+64)>>7;
     curr_blk1[3][xx]=(Clip3(-32768,32703,b3+b7)+64)>>7;
     curr_blk1[7][xx]=(Clip3(-32768,32703,b0-b4)+64)>>7;
     curr_blk1[6][xx]=(Clip3(-32768,32703,b1-b5)+64)>>7;
     curr_blk1[5][xx]=(Clip3(-32768,32703,b2-b6)+64)>>7;
     curr_blk1[4][xx]=(Clip3(-32768,32703,b3-b7)+64)>>7;
	
	 if((b0+b4)<=-32768 || (b0+b4)>=(32768-65 ))
		 printf("error\n");
	 if((b1+b5)<=-32768 || (b1+b5)>=(32768-65 ))
		 printf("error\n");
	 if((b2+b6)<=-32768 || (b2+b6)>=(32768-65 ))
		 printf("error\n");
	 if((b3+b7)<=-32768 || (b3+b7)>=(32768-65 ))
		 printf("error\n");
	 if((b0-b4)<=-32768 || (b0-b4)>=(32768-65 ))
		 printf("error\n");
	 if((b1-b5)<=-32768 || (b1-b5)>=(32768-65 ))
		 printf("error\n");
	 if((b2-b6)<=-32768 || (b2-b6)>=(32768-65 ))
		 printf("error\n"); 
	 if((b3-b7)<=-32768 || (b3-b7)>=(32768-65 ))
		 printf("error\n");
*/
/*     tmp0=curr_blk1[0][xx];
     tmp1=curr_blk1[4][xx];
     tmp2=curr_blk1[2][xx];
     tmp3=curr_blk1[6][xx];
     tmp4=curr_blk1[1][xx];
     tmp5=curr_blk1[3][xx];
     tmp6=curr_blk1[5][xx];
     tmp7=curr_blk1[7][xx];
     
     // Downleft Butterfly
	b0 = ((tmp4 - tmp7)<<1) + tmp4;
	b1 = ((tmp5 + tmp6)<<1) + tmp5;
	b2 = ((tmp5 - tmp6)<<1) - tmp6;
	b3 = ((tmp4 + tmp7)<<1) + tmp7;

	b4 = ((b0 + b1 + b3)<<1) + b1;
	b5 = ((b0 - b1 + b2)<<1) + b0;
	b6 = ((-b1 - b2 + b3)<<1) + b3;
*/     
     // Upleft Butterfly
	 t=((tmp2*10)+(tmp3<<2));
	 tmp3=((tmp2<<2)-(tmp3*10));
     tmp2=t;
     
     t=(tmp0+tmp1)<<3;
     tmp1=(tmp0-tmp1)<<3;
     tmp0=t;
     
     b0=tmp0+tmp2;
     b1=tmp1+tmp3;
     b2=tmp1-tmp3;
     b3=tmp0-tmp2;
     
     curr_blk1[0][xx]=(Clip3(-32768,32703,b0+b4)+64)>>7;  //(b0+b4+64)>>7;
     curr_blk1[1][xx]=(Clip3(-32768,32703,b1+b5)+64)>>7;  //(b1+b5+64)>>7;
     curr_blk1[2][xx]=(Clip3(-32768,32703,b2+b6)+64)>>7;  //(b2+b6+64)>>7;
     curr_blk1[3][xx]=(Clip3(-32768,32703,b3+b7)+64)>>7;  //(b3+b7+64)>>7;
     curr_blk1[7][xx]=(Clip3(-32768,32703,b0-b4)+64)>>7;  //(b0-b4+64)>>7;
     curr_blk1[6][xx]=(Clip3(-32768,32703,b1-b5)+64)>>7;  //(b1-b5+64)>>7;
     curr_blk1[5][xx]=(Clip3(-32768,32703,b2-b6)+64)>>7;  //(b2-b6+64)>>7;
     curr_blk1[4][xx]=(Clip3(-32768,32703,b3-b7)+64)>>7;  //(b3-b7+64)>>7;

   }
   

	   
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -