为什么你在汇编程序? [英] Why do you program in assembly?

查看:130
本文介绍了为什么你在汇编程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对所有的铁杆水平低的黑客那里的问题。我在博客中整个句子跑去。我真的不认为源问题(这是哈克,如果你真的在乎),因为它似乎是一个共同声明。

I have a question for all the hardcore low level hackers out there. I ran across this sentence in a blog. I don't really think the source matters (it's Haack if you really care) because it seems to be a common statement.

例如,许多现代3-D游戏都有各自的高性能核心引擎写在C ++和汇编。

For example, many modern 3-D Games have their high performance core engine written in C++ and Assembly.

至于组装老话 - 是用汇编写的,因为你不想要一个编译器发出额外的指令或过度使用字节,或者你用更好的算法,你不能EX $ P $的code PSS在C(或可以不编译器不前preSS mussing起来)?

As far as the assembly goes - is the code written in assembly because you don't want a compiler emitting extra instructions or using excessive bytes, or are you using better algorithms that you can't express in C (or can't express without the compiler mussing them up)?

我完全得到理解低层次的东西是很重要的。我只是想了解的为什么的程序汇编你理解它了。

I completely get that it's important to understand the low-level stuff. I just want to understand the why program in assembly after you do understand it.

推荐答案

我觉得你误读这句话:

例如,许多现代3-D游戏都有各自的高性能核心引擎写在C ++和汇编。

For example, many modern 3-D Games have their high performance core engine written in C++ and Assembly.

游戏(和大多数程序,这些天)不汇编语言编写的他们以同样的方式写在C ++。这博客是不是说游戏的显著部分被设计在组装,或者一个团队的程序员坐在那里组装发展作为其主要的语言。

Games (and most programs these days) aren't "written in assembly" the same way they're "written in C++". That blog isn't saying that a significant fraction of the game is designed in assembly, or that a team of programmers sit around and develop in assembly as their primary language.

这是什么的真正的意思是,开发商先写游戏,并把它在C ++中工作。然后他们就配置文件,找出瓶颈是什么,如果它是值得的,他们优化赫克他们的汇编。或者,如果他们已经有经验,他们知道哪些部分将是瓶颈,他们已经得到了优化,从片其他游戏,他们已经建立了坐在身边。

What this really means is that developers first write the game and get it working in C++. Then they profile it, figure out what the bottlenecks are, and if it's worthwhile they optimize the heck out of them in assembly. Or, if they're already experienced, they know which parts are going to be bottlenecks, and they've got optimized pieces sitting around from other games they've built.

在汇编编程的的的是因为它一直是一样的:速度即可。这将是可笑的编写汇编一的$的很多的C $ C,但也有一些优化编译器是不知道的,并为code的一个足够小的窗口,是人会做的更好。

The point of programming in assembly is the same as it always has been: speed. It would be ridiculous to write a lot of code in assembler, but there are some optimizations the compiler isn't aware of, and for a small enough window of code, a human is going to do better.

例如,对于浮点,编译器往往是pretty保守,可能不知道一些你的架构的更先进的功能。如果你愿意接受一些错误,可以平时做比编译器更好,如果你发现大量的时间都花在这是值得写code的那一点点的组装。

For example, for floating point, compilers tend to be pretty conservative and may not be aware of some of the more advanced features of your architecture. If you're willing to accept some error, you can usually do better than the compiler, and it's worth writing that little bit of code in assembly if you find that lots of time is spent on it.

下面是一些有关的例子:

Here are some more relevant examples:

从游戏例子


  • <一个href=\"http://software.intel.com/en-us/articles/achieving-performance-an-approach-to-optimizing-a-game-engine/\">Article英特尔的有关优化使用SSE内在函数的游戏引擎。最后code使用内部函数(而不是内联汇编),所以纯汇编的量是非常小的。不过,他们在看汇编输出由编译器来找出最优化的是什么。

  • Article from Intel about optimizing a game engine using SSE intrinsics. The final code uses intrinsics (not inline assembler), so the amount of pure assembly is very small. But they look at the assembler output by the compiler to figure out exactly what to optimize.

雷神之锤的快速平方根倒数。再次,程序不必在它的汇编,但你需要了解一些建筑做这样的优化。笔者知道什么行动是快(乘,移动)和慢(除,开方)。于是,他们想出了一个非常棘手的实现,完全避免了操作速度慢平方根。

Quake's fast inverse square root. Again, the routine doesn't have assembler in it, but you need to know something about architecture to do this kind of optimization. The authors know what operations are fast (multiply, shift) and which are slow (divide, sqrt). So they come up with a very tricky implementation of square root that avoids the slow operations entirely.

高性能计算


  • 之外的游戏领域,人们在科学计算经常优化废话出来的东西,让他们在最新的硬件跑得快。把这看作游戏,你不能在物理作弊。

  • Outside the domain of games, people in scientific computing frequently optimize the crap out of things to get them to run fast on the latest hardware. Think of this as games where you can't cheat on the physics.

这方面的一个伟大的最近的例子是格子量子色动力学(QCD格)本文介绍如何这个问题pretty多归结为一个非常小的计算内核,这是大量优化为PowerPC 440的上 IBM蓝色基因/ L 。每440有两个的FPU,并且支持那些棘手的编译器利用一些特殊的三元操作。如果没有这些优化,格点QCD会一直跑慢得多,这是昂贵的,当你问题,需要昂贵的机器数百万个CPU小时。

A great recent example of this is Lattice Quantum Chromodynamics (Lattice QCD). This paper describes how the problem pretty much boils down to one very small computational kernel, which was optimized heavily for PowerPC 440's on an IBM Blue Gene/L. Each 440 has two FPUs, and they support some special ternary operations that are tricky for compilers to exploit. Without these optimizations, Lattice QCD would've run much slower, which is costly when your problem requires millions of CPU hours on expensive machines.

如果你想知道的为什么的这一点很重要,请查看文章在科学说出来这项工作。用格点QCD,这些家伙计算从第一原理质子的质量,并表明,去年,90%的质量来自于强大的力量结合能,并从夸克休息。这是 E = MC 2 在行动。 <一href=\"http://room538ccpp.word$p$pss.com/2008/11/23/ab-initio-qcd-calculation-of-the-proton-mass/\">Here's摘要。

If you are wondering why this is important, check out the article in Science that came out of this work. Using Lattice QCD, these guys calculated the mass of a proton from first principles, and showed last year that 90% of the mass comes from strong force binding energy, and the rest from quarks. That's E=mc2 in action. Here's a summary.

有关上述所有的应用程序的不可以设计或汇编语言编写100% - 甚至还没有接近。但是,当人们真正需要的速度,他们专注于自己的写作code的关键部位在特定硬件飞。

For all of the above, the applications are not designed or written 100% in assembly -- not even close. But when people really need speed, they focus on writing the key parts of their code to fly on specific hardware.

这篇关于为什么你在汇编程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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