为什么无符号类型在 arm cpu 中更有效? [英] Why unsigned types are more efficient in arm cpu?

查看:29
本文介绍了为什么无符号类型在 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 中更有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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