ARM、Thumb 和 Thumb 2 指令编码有什么区别? [英] What is the difference between the ARM, Thumb and Thumb 2 instruction encodings?

查看:11
本文介绍了ARM、Thumb 和 Thumb 2 指令编码有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对指令集有点困惑.有 Thumb、ARM 和 Thumb 2.根据我的阅读,Thumb 指令都是 16 位的,但在 ARMv7M 用户手册(第 vi 页)中有 Thumb 16 位和 Thumb 32 位指令提及.

I am a bit confused about instruction sets. There are Thumb, ARM and Thumb 2. From what I have read Thumb instructions are all 16-bit but inside the ARMv7M user manual (page vi) there are Thumb 16-bit and Thumb 32-bit instructions mentioned.

现在我必须克服这种困惑.据说 Thumb 2 支持 16 位和 32 位指令.那么 ARMv7M 实际上是否支持 Thumb 2 指令而不仅仅是 Thumb?

Now I have to overcome this confusion. It is said that Thumb 2 supports 16-bit and 32-bit instructions. So is ARMv7M in fact supporting Thumb 2 instructions and not just Thumb?

还有一件事.我能说 Thumb(32 位)和 ARM 指令一样,都是 32 位吗?

One more thing. Can I say that Thumb (32-bit) is the same as ARM instructions which are allso 32-bit?

推荐答案

哦,ARM 和它们愚蠢的命名......

Oh, ARM and their silly naming...

这是一个常见的误解,但官方并没有Thumb-2 指令集"之类的东西.

It's a common misconception, but officially there's no such thing as a "Thumb-2 instruction set".

忽略 ARMv8(所有内容都被重命名并且 AArch64 使事情变得复杂),从 ARMv4T 到 ARMv7-A 有两个指令集:ARM 和 Thumb.从某种意义上说,它们都是32 位",它们在具有 32 位地址的 32 位宽寄存器中操作高达 32 位宽的数据.事实上,在它们重叠的地方,它们代表完全相同的指令——只是指令编码不同,CPU实际上只有两个不同的解码前端到它的流水线,它可以在它们之间切换.为清楚起见,我现在将故意避免使用32 位"和16 位"这两个术语...

Ignoring ARMv8 (where everything is renamed and AArch64 complicates things), from ARMv4T to ARMv7-A there are two instruction sets: ARM and Thumb. They are both "32-bit" in the sense that they operate on up-to-32-bit-wide data in 32-bit-wide registers with 32-bit addresses. In fact, where they overlap they represent the exact same instructions - it is only the instruction encoding which differs, and the CPU effectively just has two different decode front-ends to its pipeline which it can switch between. For clarity, I shall now deliberately avoid the terms "32-bit" and "16-bit"...

ARM 指令具有固定宽度的 4 字节编码,需要 4 字节对齐.Thumb 指令具有可变长度(2 或 4 字节,现在称为窄"和宽")编码,需要 2 字节对齐 - 大多数指令具有 2 字节编码,但 blblx 一直有 4 字节编码*.真正令人困惑的是 ARMv6T2,它引入了Thumb-2 技术".Thumb-2 不仅包括向 Thumb 添加更多指令(主要使用 4 字节编码)以使其几乎与 ARM 相当,而且还扩展了执行状态以允许有条件地执行大多数 Thumb 指令,最后引入了一个全新的汇编语法(UAL,统一汇编语言")取代了之前单独的 ARM 和 Thumb 语法,允许编写一次代码并将其汇编到任一指令集而无需修改.

ARM instructions have fixed-width 4-byte encodings which require 4-byte alignment. Thumb instructions have variable-length (2 or 4-byte, now known as "narrow" and "wide") encodings requiring 2-byte alignment - most instructions have 2-byte encodings, but bl and blx have always had 4-byte encodings*. The really confusing bit came in ARMv6T2, which introduced "Thumb-2 Technology". Thumb-2 encompassed not just adding a load more instructions to Thumb (mostly with 4-byte encodings) to bring it almost to parity with ARM, but also extending the execution state to allow for conditional execution of most Thumb instructions, and finally introducing a whole new assembly syntax (UAL, "Unified Assembly Language") which replaced the previous separate ARM and Thumb syntaxes and allowed writing code once and assembling it to either instruction set without modification.

Cortex-M 架构仅实现 Thumb 指令集 - ARMv7-M (Cortex-M3/M4/M7) 支持大部分Thumb-2 技术",包括 VFP 指令的条件执行和编码,而 ARMv6-M(Cortex-M0/M0+) 仅以少数 4 字节系统指令的形式使用 Thumb-2.

The Cortex-M architectures only implement the Thumb instruction set - ARMv7-M (Cortex-M3/M4/M7) supports most of "Thumb-2 Technology", including conditional execution and encodings for VFP instructions, whereas ARMv6-M (Cortex-M0/M0+) only uses Thumb-2 in the form of a handful of 4-byte system instructions.

因此,新的 4 字节编码(以及后来在 ARMv7 修订版中添加的那些)仍然是 Thumb 指令 - 它们的Thumb-2"方面是它们可以具有 4 字节编码,并且它们可以(大多数情况下)通过 it 有条件地执行(而且,我想它们的记忆法仅在 UAL 中定义).

Thus, the new 4-byte encodings (and those added later in ARMv7 revisions) are still Thumb instructions - the "Thumb-2" aspect of them is that they can have 4-byte encodings, and that they can (mostly) be conditionally executed via it (and, I suppose, that their menmonics are only defined in UAL).

* 在 ARMv6T2 之前,关于 bl(或 blx)是作为 4 字节指令执行还是作为一对2字节的指令.架构定义是后者,但由于它们只能作为一对按顺序执行,因此出于性能原因将它们融合到一条指令中几乎没有什么损失(除了中途中断的能力).ARMv6T2 只是在融合的单指令执行方面重新定义了事物

* Before ARMv6T2, it was actually a complicated implementation detail as to whether bl (or blx) was executed as a 4-byte instruction or as a pair of 2-byte instructions. The architectural definition was the latter, but since they could only ever be executed as a pair in sequence there was little to lose (other than the ability to take an interrupt halfway through) by fusing them into a single instruction for performance reasons. ARMv6T2 just redefined things in terms of the fused single-instruction execution

这篇关于ARM、Thumb 和 Thumb 2 指令编码有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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