gpt4 book ai didi

这可以更快地完成吗?

转载 作者:太空宇宙 更新时间:2023-11-04 02:02:44 25 4
gpt4 key购买 nike

我有一个函数可以获取一些通过 DMA 通过 SPI 接收的数据。为了提高通过 SPI 传输时的速度,三个 10 位数据被打包成一个 32 位字(具有两个填充位)。收到后,我需要将其解压缩回三个 16 位字(十个实际数据位和六个填充位)。

这个函数被经常调用,所以任何速度优化都会大大缩短整体执行时间。它在 STMicro Cortex M3 上运行,使用 IAR EWARM 7.10 作为编译器,优化设置为高,针对速度进行了优化。

    /*******************************************************************************
* Function Name : Unpack
* Description : the previous adc sample has been
DMA'd into an array
unpack each 32 bit transfer into 3, 10bit samples
( low 16 spi word ) ( high 16 spi word )
{ p15 p14 ch1_9:0 ch2_9:0 ch3_9:0 } 32 bit packing

* Input : output buf 16 bit word (10 bit adc, right justified)
input buf 32 bit data
count in 32 bit input words

* Output : None.
* Return : None.
*******************************************************************************/
void Unpack( u16* pDest, u16* pSrc, u16 packed32_count)
{
u16 i;
u32 n;
u16 dest_index = 0;
u16 src_index = 0;

for ( i = 0; i < packed32_count ; i++ )
{
n = pSrc[src_index]; //get high 16
n <<= 16;
n |= pSrc[src_index+1]; //get low 16
src_index+=2;

pDest[dest_index+2] = n & 0x3ff;
n >>= 10;
pDest[dest_index+1] = n & 0x3ff;
n >>= 10;
pDest[dest_index] = n & 0x3ff;
dest_index+=3;
}
}

最佳答案

下面的代码不多,但它可能比上面的代码更快。您也可以尝试使用影响速度的优化进行编译。

void Unpack( u16* pDest, u32* pSrc, u16 packed32_count)
{
int i;
u32 val;

for(i = 0; i < packed32_count; i++)
{
val = pSrc[i];
pDest[2] = val & 0x3ff;
pDest[1] = (val >> 10) & 0x3ff;
pDest[0] = val >> 20;
pDest += 3;
}
}

关于这可以更快地完成吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24910227/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com