处理器的大脑!小编带您读懂CPU指令集
● SSE4.1改进视频处理
SSE4.1是Intel在Penryn核心的Core 2 Duo与Core 2 Solo处理器时,新增的47条新多媒体指令集,用来加强视频编辑等方面的应用。另外,AMD也开发了属于自己的SSE4a多媒体指令集,并内建在Phenom与Opteron等K10架构处理器中,不过相关应用都差不多,并且无法与Intel的SSE4系列指令集相容。
缓慢的视频处理
据了解,在进行视频编码时需要进行动态预测(Motion Estimation)及差分编码方式去除相邻2张影像之相关性,这是一个非常复杂的运算动作。在没有SSE4指令集时,完成一个步骤需要以下指令语句:
for (int moveblock=0;moveblock<16;moveblock++)
for(int line=0; line<16; line++) // Does the 16 pixels large in 4 iteration
{
int i=0;
sum0+=abs( pBlock1[j]-pBlock2)+abs(pBlock1[j+1]-pBlock2[i+1])+abs(pBlock1[j+2]-pBlock2[i+2])+abs(pBlock1[j+3]-pBlock2[i+3]); // Compare with 0 pixel offset
sum1+=abs(pBlock1[j+1]-pBlock2)+abs(pBlock1[j+2]-pBlock2[i+1])+abs(pBlock1[j+3]-pBlock2[i+2])+abs(pBlock1[j+4]-pBlock2[i+3]); // Compare with 1 pixel offset
sum2+=abs(pBlock1[j+2]-pBlock2)+abs(pBlock1[j+3]-pBlock2[i+1])+abs(pBlock1[j+4]-pBlock2[i+2])+abs(pBlock1[j+5]-pBlock2[i+3]); // Compare with 2 pixel offset
sum3+=abs(pBlock1[j+3]-pBlock2)+abs(pBlock1[j+4]-pBlock2[i+1])+abs(pBlock1[j+5]-pBlock2[i+2])+abs(pBlock1[j+6]-pBlock2[i+3]); // Compare with 3 pixel offset
sum4+=abs(pBlock1[j+4]-pBlock2)+abs(pBlock1[j+5]-pBlock2[i+1])+abs(pBlock1[j+6]-pBlock2[i+2])+abs(pBlock1[j+7]-pBlock2[i+3]); // Compare with 4 pixel offset
sum5+=abs(pBlock1[j+5]-pBlock2)+abs(pBlock1[j+6]-pBlock2[i+1])+abs(pBlock1[j+7]-pBlock2[i+2])+abs(pBlock1[j+8]-pBlock2[i+3]); // Compare with 5 pixel offset
sum6+=abs(pBlock1[j+6]-pBlock2)+abs(pBlock1[j+7]-pBlock2[i+1])+abs(pBlock1[j+8]-pBlock2[i+2])+abs(pBlock1[j+9]-pBlock2[i+3]); // Compare with 6 pixel offset
sum7+=abs(pBlock1[j+7]-pBlock2)+abs(pBlock1[j+8]-pBlock2[i+1])+abs(pBlock1[j+9]-pBlock2[i+2])+abs(pBlock1[j+10]-pBlock2[i+3]); // Compare with 7 pixel offset
i=4;
j=moveblock+4;
…
… }
}
一大串的指令极度浪费处理器资源,而在支持SSE4指令集的处理器上,只需要采用4 SAD运算指令:
MPSADBW xmm0,xmm1,0
便完全代替了以上繁复的指令串,大幅提升动态预测(Motion Estimation)及差分编码的运算速度。