ARM memcpy and alignment

岁酱吖の 提交于 2019-12-06 11:34:46

问题


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

For example:

; 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 */

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?


回答1:


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.

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



来源:https://stackoverflow.com/questions/13804215/arm-memcpy-and-alignment

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!