问题描述
我在读手臂手册和来此建议,但没有被提及的原因。
为什么无符号类型更快?
解决方案
我在读手臂手册和来此建议,但没有被提及的原因。
为什么无符号类型更快?
ARMv4之前,ARM曾装载半字和有符号字节没有原生支持
LDRB
一个符号字节再签收延长值( LSL
它那么 ASR
它背下来)。这是痛苦所以字符
是无符号
默认在ARM版本的指令被添加到处理半字和符号值。这些新指令必须挤进可用指令空间。可在空间限制意味着它们不能被制成柔性的原始指令,加载值时,其能够执行各种地址计算
所以,你可能会发现, LDRSB
,例如,是无法结合的内存地址计算,而 LDRB $ C抓取$ C>可能。这可以花费的周期。有时候,我们可以返工
短
- 重型code上对 int的操作
来避免这个问题。
有在这里我的网站的详细信息:http://www.davespace.co.uk/arm/efficient-c-for-arm/memaccess.html
I'm reading an arm manual and come to this suggestion, but the reason is not mentioned.
Why unsigned types are faster?
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.
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.
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.
There's more info on my site here: http://www.davespace.co.uk/arm/efficient-c-for-arm/memaccess.html
这篇关于为什么无符号的类型是ARM CPU比较有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!