“注册机”到底是什么?

发布于 2024-08-09 17:59:51 字数 494 浏览 7 评论 0原文

来自 http://code.google.com/p/unladen-swallow/wiki/ ProjectPlan 我引用:

“使用 JIT 还允许我们将 Python 从基于堆栈的机器移动到寄存器机器,这已被证明可以提高其他类似语言的性能(Ierusalimschy 等人,2005 年;Shi 等人)等人,2005)。”

在大学里,我为具有递归过程的语言构建了一个简单的编译器 - 它为每个调用的过程维护堆栈框架 - 以便可以递归地调用它们,以便参数和返回值可以工作......

有两件事:

1)我是吗考虑到上面引用中使用的术语,我是否认为我实现的将被视为“基于堆栈的机器”?

2)如果我在第(1)点中的假设是正确的,那么“寄存器机”如何工作?即它与基于堆栈的机器有何不同?

谢谢!

From http://code.google.com/p/unladen-swallow/wiki/ProjectPlan I quote:

"Using a JIT will also allow us to move Python from a stack-based machine to a register machine, which has been shown to improve performance in other similar languages (Ierusalimschy et al, 2005; Shi et al, 2005)."

In college I built a simple compiler for a language with recursive procedures - which maintained stack frames for each procedure called - so that they can be called recursively and so that parameters and return values would work....

2 things:

1) Am I right in thinking that what I implemented would be considered a "stack-based machine" given the terminology used in the quotation above?

2) If my assumption in point (1) was right, how does a "register machine" work? i.e. how is it different from a stack-based machine?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

霓裳挽歌倾城醉 2024-08-16 17:59:51

寄存器机是一种硬件或软件单元,在处理数据时,它从内存中取出数据,将其放在可以快速处理的位置,然后返回结果。

例如,常规 CPU 是寄存器机。由于 ALU(CPU 中处理数字的单元)只能处理寄存器中的数字。

基于堆栈的机器将数据添加到堆栈中,然后将数据弹出或推入其中。

例如,将两个数字相加,

Push 2 // Push 2 onto the stack
Push 3 // Push 3 onto the stack
Add // Add the top two things on the stack.

当在寄存器机中时,它会是这样的。

Load x, r0 // Load x onto register 0
Load y, r1 // Load y onto register 1
Add r0, r1, r2 // Add 1 and 2 and store the result in register 2

A register machine is a hardware or software unit that when working with data takes it from memory, puts it in a location where it can work with it quickly, and then returns the result.

For example a regular CPU is a register machine. Since the ALU (the unit that works with numbers in a CPU) can only work with numbers in a register.

A stack based machine adds the data onto a stack and then either pops or pushes stuff onto it.

For example, adding two numbers would be

Push 2 // Push 2 onto the stack
Push 3 // Push 3 onto the stack
Add // Add the top two things on the stack.

When in a register machine it would be something like this.

Load x, r0 // Load x onto register 0
Load y, r1 // Load y onto register 1
Add r0, r1, r2 // Add 1 and 2 and store the result in register 2
烈酒灼喉 2024-08-16 17:59:51

寄存器机几乎也总是有一个堆栈。

但是堆栈机很少有架构上可见的寄存器,或者可能只有一两个。

寄存器机可能有一些堆栈操作,甚至可能有堆栈寻址模式。

区别在于方向之一。寄存器机主要具有对寄存器进行操作的指令,并且具有少量用于在寄存器和堆栈或内存之间加载和存储的操作。

堆栈机..这些非常罕见,因为实际的硬件设备..将使用其指令直接在堆栈上操作,并且将有一些用于在堆栈和内存之间加载和存储的操作。

现在,根据引用的论文,硬件寄存器机比硬件堆栈机更快的原因可能与软件“寄存器”VM 比软件“堆栈”机更快的原因无关。

对于软件虚拟机来说,显然需要执行的指令更少。这是根据引用论文中的主张凭经验确定的,但我想这是因为寄存器机中需要执行的开销指令(例如推送、弹出和交换)要少得多,并且因为寄存器机可以轻松地重用操作数(如果它们仍然是)位于寄存器文件中,无需加载或推送操作。当然,这一切都只是记忆而已;它们是虚拟寄存器。

A register machine almost always has a stack, also.

But a stack machine rarely has architecturally visible registers, or it may only have one or two.

A register machine may have some stack ops and may even have a stack addressing mode.

The difference is one of orientation. The register machine will mostly have instructions that operate on registers, and will have a handful of ops for loading and storing between the registers and the stack or memory.

A stack machine .. and these are very rare as actual hardware devices .. will operate directly on the stack with its instructions and wll have a handlful of ops for loading and storing between the stack and memory.

Now, the reasons that hardware register machines are faster than hardware stack machines are possibly unrelated to the reasons that software "register" VM's are faster, according to the cited paper, than software "stack" machines.

For the software VM's, it's apparently the case that fewer instructions need to be executed. This was determined empirically according to claims in the cited paper, but I imagine it's because far fewer overhead instructions like push, pop, and exchange need to be done in the register machine, and because the register machine can reuse operands easily if they are still lying around in the register file, without needing load or push ops. Of course, it's all just memory really; they are virtual registers.

始终不够 2024-08-16 17:59:51

寄存器机使用固定数量的寄存器或桶来存储用于计算的中间值。例如,“add”指令可以将两个特定寄存器中的值相加并将结果存储在另一个寄存器中。

基于堆栈的机器使用堆栈来存储计算期间的中间值。例如,要添加两个数字,“add”指令会从堆栈中弹出两个值,将它们相加,然后将结果推回堆栈。

A register machine uses a fixed number of registers or buckets for storing intermediate values for computation. For example the "add" instruction could add the values in two specific registers and store the result in another register.

A stack based machine uses a stack for storing intermediate values during computation. For example, to add two numbers the "add" instructions pops off two values from the stack, adds them, and pushes the result back onto the stack.

感悟人生的甜 2024-08-16 17:59:51

1)我的想法正确吗?
实施将被视为
“基于堆栈的机器”给定
引文中使用的术语
上面?

并不真地。某种堆栈几乎是实现递归函数调用的唯一方法。但是“基于堆栈的机器”在通过堆栈完成所有事情方面走得更远。不仅是函数调用,还包括算术运算。在某种程度上,它们的行为就好像每个机器指令都是通过堆栈处理的函数调用。它使得机器设计非常简单,但很难编写汇编程序/机器代码。

2)如果我在第(1)点中的假设是
对了,“注册机”是怎么做到的
工作?即它与 a 有什么不同
基于堆栈的机器?

寄存器机具有一些快速的内部存储(寄存器),并对这些寄存器中的数据执行大部分操作。还有用于在寄存器和主存储器之间复制数据的附加机器指令。

IIRC 有两种堆栈机:

  • 累加器机器有一个“累加器”,它基本上是一个保存计算结果(也可能提供操作数)的寄存器,大多数机器指令在累加器上运行。
  • “纯”堆栈机在消耗操作数后将计算结果放在堆栈顶部。

1) Am I right in thinking that what I
implemented would be considered a
"stack-based machine" given the
terminology used in the quotation
above?

Not really. A stack of some sort is pretty much the only way to implement recursive function calls. But a "stack-based machine" goes much further in doing everything via the stack. Not just function calls, but also arithmetic operations. In a way, they behave as if every machine instruction is a function call handled via the stack. It makes for a very simple machine design, but rather hard-to-write assembler/machine code.

2) If my assumption in point (1) was
right, how does a "register machine"
work? i.e. how is it different from a
stack-based machine?

A register machine has some fast internal storage (registers) and performs most of its operations on data in these registers. There are additional machine instructions for copying data between registers and main memory.

IIRC there are two kinds of stack machines:

  • Accumulator machines have an "accumulator", which is basically a single register that holds the result of calculations (and may also supply an operand), with most machine instructions operating on the accumulator.
  • "Pure" stack machines put the result of calculations on top of the stack after consuming the operands.
无远思近则忧 2024-08-16 17:59:51

寄存器机是一种抽象机,其操作码是通过引用它们在一组命名寄存器上的操作来定义的,而不是通过它们在堆栈顶部的操作来定义的。

在寄存器机中:add 可以被定义为以三个寄存器名称作为操作数,将前两个的内容相加,并将结果放入第三个。 (更常见的设计是只命名一两个操作数,结果总是放入特殊的累加器寄存器中,但这不是重点。)

在堆栈机中:add 可以定义为从堆栈中弹出两个操作数,然后将它们相加,并将结果压入堆栈。

A register machine is an abstract machine whose opcodes are defined by reference to their operation on a set of named registers, rather than by their operation on the top portion of a stack.

In a register machine: add could be defined to take three register names as operands, add the contents of the first two, and place the result in the third. (More common is the design where only one or two are named and the result always goes in a special accumulator register, but that's not the point.)

In a stack machine: add could be defined to pop two operands from the stack, add them, and push the result onto the stack.

懵少女 2024-08-16 17:59:51

你的编译器生成机器代码了吗?如果是这样,那么它的目标是寄存器机(几乎所有 CPU 设计都是寄存器机)。

堆栈机将所有值存储在堆栈上,而寄存器机具有固定数量的存储槽,其“地址”不会改变(与堆栈机不同)。

Did your compiler generate machine code? If so, then its target was a register machine (nearly all CPU designs are register machines).

Stack machines store all values on a stack, whereas register machines have a fixed number of storage slots whose "addresses" do not change (unlike stack machines).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文