为什么无符号类型在 arm cpu 中更有效?

编程入门 行业动态 更新时间:2024-10-28 05:23:41
本文介绍了为什么无符号类型在 arm cpu 中更有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在阅读 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-16 16:25:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/890783.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:更有效   符号   类型   arm   cpu

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!