ARM memcpy 和对齐 [英] ARM memcpy and alignment

查看:33
本文介绍了ARM memcpy 和对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 NEON使用 Cortex-A8 处理器上的 Windows Embedded Compact 7 ARM 汇编器从 ARM 网站使用预加载实现的内存复制.

I am using the NEON memory copy with preload implementation from the ARM website with the Windows Embedded Compact 7 ARM assembler on a Cortex-A8 processor.

我注意到当我为该函数提供非字对齐值时,我得到了数据类型未对齐异常

I notice that I get datatype misalignment exceptions when I provide that function with non word aligned values

例如:

; NEON memory copy with preload
ALIGN
LEAF_ENTRY NEONCopyPLD
    PLD [r1, #0xC0]
    VLDM r1!,{d0-d7} ;datatype misalignment
    VSTM r0!,{d0-d7}
    SUBS r2,r2,#0x40
    MOV R0, #0
    MOV PC, LR
ENTRY_END

size_t size = /* arbitrary */;
size_t offset = 1;
char* src = new char[ size + offset ];
char* dst = new char[ size ];

NEONCopyPLD( dst, src + offset, size );

memcpy( dst, src + offset, size ); /* works perfectly */

这是否适用于 VLDM 命令?文章没有提到这个实现仅限于字对齐的值.可以修复吗?如果是,怎么办?

Is this expected for the VLDM command? The article doesn't mention that this implementation is limited to word-aligned values. Is it fixable? If so, how?

推荐答案

即使您没有指定明确的对齐要求,您仍然需要在元素边界上对齐数据(即在这种情况下在双字边界上).此规则有一些例外情况,但最好不要依赖它们,除非您有充分的理由这样做.

Even if you don't specify an explicit alignment requirement you still need to align the data on an element boundary (i.e. on a doubleword boundary in this case). There are some exceptions to this rule, but it's probably best not to rely on them unless you have a really good reason to do so.

有关详细信息,请参阅 Cortex-A8 技术参考手册 (ARM DDI 0344J).

See the Cortex-A8 technical reference manual (ARM DDI 0344J) for more information.

这篇关于ARM memcpy 和对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆