简体   繁体   English

中间语言的最小汇编指令集?

[英]Minimal set of Assembly Instructions for an Intermediate Language?

I was wondering the following:我想知道以下几点:

Is it possible to create a small set of Assembly Instructions that together can do all operations possible?是否可以创建一小组组装指令,一起完成所有可能的操作? Or maybe asked differently what are the Must-Have assembly instructions for about any architecture?或者可能会问不同的问题,关于任何架构的必备汇编指令是什么?

(For example, Jump and Add would be necessary to do about anything) (例如,执行任何操作都需要 Jump 和 Add)

I hope you guys can help me!我希望你们能帮助我!

To provide some background information: I am trying to design an Intermediate Language for my compiler and I'd like to use as few instructions as possible (where then later a bunch of those instructions could be substituted for one Complex Instruction for specific architectures).提供一些背景信息:我正在尝试为我的编译器设计一种中间语言,并且我想使用尽可能少的指令(然后可以用一组这些指令代替特定架构的一个复杂指令)。 But of course the IL itself should be portable.但当然,IL 本身应该是可移植的。

I think you want the opposite.我想你想要相反的。 Instead of making an IL that is as simple as possible, you want one that is very expressive.与其制作尽可能简单的 IL,不如制作一个非常具有表现力的 IL。 The more expressive the IL is, the easier it may be to optimize for a specific architecture. IL 的表现力越强,就越容易针对特定架构进行优化。

It is easier to expand a complex IL operation into many individual instructions than it is to coalesce many simple IL operations into a complicated instruction.将复杂的 IL 操作扩展为许多单独的指令比将许多简单的 IL 操作合并为一条复杂的指令更容易。 You might not need multiply, since it can be done with jump and add instructions.您可能不需要乘法,因为它可以通过跳转和加法指令来完成。 But when you're compiling for a chip which has a hardware multiply, you'd have to analyze the IL to determine this was an "add loop" and covert it back into a multiply.但是,当您为具有硬件乘法的芯片进行编译时,您必须分析 IL 以确定这是一个“加法循环”并将其转换回乘法。 That's a lot more work than coming across a multiply and saying "hmm, this architecture can't do that, I guess we'll have to make it an add loop."这比遇到乘法并说“嗯,这个架构不能这样做,我想我们必须让它成为一个加法循环”要多得多。

Another example, you might think your IL doesn't need floating point operations, since some ARM chips have to do floating point in software anyways.另一个例子,你可能认为你的 IL 不需要浮点运算,因为一些 ARM 芯片无论如何必须在软件中进行浮点运算。 But some ARM chips don't have to do that, and if your IL doesn't support FP operations then you'll need to convert complicated software FP IL back into a single hardware instruction.但是一些 ARM 芯片不必这样做,如果您的 IL 不支持 FP 操作,那么您需要将复杂的软件 FP IL 转换回单个硬件指令。

It's better to match your IL to the most advanced and complicated hardware features, and then "fall back" to "software emulation" of those features on processors that don't have them.最好将您的 IL 与最先进和最复杂的硬件功能相匹配,然后在没有这些功能的处理器上“退回”到这些功能的“软件仿真”。

The minimum is one instruction and it was even implemented in reality in the carbone nanotube computer or the MAXQ chip最少一条指令,甚至在碳纳米管计算机MAXQ芯片中实际实现

Although only one is enough but in fact it's much more complicated than you thought, and often needs more instruction to do the same work.虽然只有一个就够了,但实际上它比你想象的要复杂得多,而且通常需要更多的指导才能完成同样的工作。 If you need the chip's speed to be "usable" then IMO it should have at least some common instructions:如果您需要芯片的速度“可用”,那么 IMO 至少应该有一些通用说明:

  • 1 conditional jump instruction: jump on equal (or not equal) 1条条件跳转指令:等于(或不等于)跳转
  • 1 SUB instruction for arithmetics. 1 个用于算术的 SUB 指令。 This way you can do both addition and subtraction easily without a negate instruction这样您就可以轻松地进行加法和减法,而无需求反指令
  • 1 bitwise instruction: NAND (or NOR), with one of this you can do any logic operations needed 1 条按位指令:NAND(或 NOR),使用其中之一,您可以执行任何所需的逻辑运算
  • 1 MOV instruction 1 MOV 指令
  • 1 load/store instruction 1 条加载/存储指令

With sub or bitwise instruction you can do a move data so depend on your architecture and the opcode size you may remove MOV or load/store to simpify it even more.使用 sub 或 bitwise 指令,您可以移动数据,因此取决于您的架构和操作码大小,您可以删除 MOV 或加载/存储以进一步简化它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM