C6000软件优化经验总结(4)
<STRONG> 十一、copy程序的优化</STRONG>
<P>     <STRONG>   1、源代码:</STRONG></P>
<P>    Word16 i;</P>
<P>    for (i = 0; i < L; i++)</P>
<P>    {</P>
<P>        y[i] = x[i];</P>
<P>    }</P>
<P>      <STRONG>  2、改编代码:</STRONG></P>
<P>(1)要求数组长度能被2整除</P>
<P>    Word32 i;</P>
<P>    Word32   temp;</P>
<P>    int *p1 = (int *)&x[0];</P>
<P>    int *q1 = (int *)&y[0];</P>
<P>    for (i = 0; i < L/2; i++)</P>
<P>    {</P>
<P>        temp = *p1++;</P>
<P>        *q1++ = temp;</P>
<P>    }</P>
<P>(2)要求数组长度能被4整除</P>
<P>    Word32 i;</P>
<P>    Word32   temp1, temp2;</P>
<P>    Word32  *pin1, *pin2, *pout1, *pout2;</P>
<P>    pin1 = (Word32 *)&x[0]; </P>
<P>    pin2 = (Word32 *)&x[2]; </P>
<P>    pout1= (Word32 *)&y[0]; </P>
<P>    pout2= (Word32 *)&y[2]; </P>
<P>    for (i = 0; i < L/4; i++)</P>
<P>    {</P>
<P>        temp1 = *pin1;</P>
<P>        temp2 = *pin2;</P>
<P>        pin1+=2;</P>
<P>        pin2+=2;</P>
<P>        *pout1= temp1;</P>
<P>        *pout2= temp2;</P>
<P>        pout1+=2;</P>
<P>        pout2+=2;</P>
<P>    }</P>
<P>      <STRONG> 3、优化方法说明:</STRONG></P>
<P>       把一次循环拷贝一个word16的数改为一次循环拷贝2个word16或4个word16的数。</P>
<P>      <STRONG> 4、技巧:</STRONG></P>
<P>       充分利用c6xx一次读取32位数的特性,并利用一个指令周期能读取两个数据的特点。</P>
<P>    <STRONG>   十二、set_zero程序的优化</STRONG></P>
<P>      <STRONG>  1、源代码:</STRONG></P>
<P>    Word16 i;</P>
<P>    for (i = 0; i < L; i++)</P>
<P>    {</P>
<P>        x[i] = 0; </P>
<P>   }</P>
<P>     <STRONG>   2、改编代码:</STRONG></P>
<P>(1)数组长度能被2整除</P>
<P>    Word32 i;</P>
<P>    int *x1 = (int *)&x[0];</P>
<P>    for (i = 0; i < L/2; i++)</P>
<P>    {</P>
<P>        *x1++ = 0;</P>
<P>    }</P>
<P>(2)数组长度能被4整除</P>
相关资讯