本文介绍了为什么无符号类型在 arm cpu 中效率更高?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读arm手册并提出此建议,但未提及原因.

I'm reading an arm manual and come to this suggestion, but the reason is not mentioned.

为什么无符号类型更快?

Why unsigned types are faster?

推荐答案

在 ARMv4 之前,ARM 不支持加载半字和有符号字节.要加载有符号字节,您必须 LDRB 然后对值进行符号扩展(LSL 向上然后 ASR 向下).这很痛苦,所以 char 默认为 unsigned.

Prior to ARMv4, ARM had no native support for loading halfwords and signed bytes. To load a signed byte you had to LDRB then sign extend the value (LSL it up then ASR it back down). This is painful so char is unsigned by default.

在 ARMv4 中添加了指令来处理半字和有符号值.这些新指令必须被压缩到可用的指令空间中.可用空间的限制意味着它们不能像原始指令那样灵活,因为它们能够在加载值时进行各种地址计算.

In ARMv4 instructions were added to handle halfwords and signed values. These new instructions had to be squeezed into the available instruction space. Limits on the space available meant that they could not be made as flexible as the original instructions, which are able to do various address computations when loading the value.

因此,您可能会发现,例如,LDRSB 无法将从内存中提取与地址计算相结合,而 LDRB 可以.这可能会花费周期.有时我们可以重新编写 short-heavy 代码来操作成对的 ints 来避免这种情况.

So you may find that LDRSB, for example, is unable to combine a fetch from memory with an address computation whereas LDRB could. This can cost cycles. Sometimes we can rework short-heavy code to operate on pairs of ints to avoid this.

我的网站上有更多信息:http://www.davespace.co.uk/arm/efficient-c-for-arm/memaccess.html

There's more info on my site here: http://www.davespace.co.uk/arm/efficient-c-for-arm/memaccess.html

这篇关于为什么无符号类型在 arm cpu 中效率更高?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 03:10