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

问题描述

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

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繁重的代码以对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/efficiency-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-29 16:37