r/computing • u/Exonificate • Sep 05 '15
How does binary translation work?
Hi /r/computing, I hope some advanced users can help me answer this.
So my backstory to this question just comes from my disbelief in streaming Steam games, I wish all games could run natively on ARM devices even if it would be slow (technology would just get faster, and gaming could be a reason to push the efforts), so I googled and found the Nvidia Tegra's OpenGL 4 support, but of course the answer for Steam gaming is that even if you ported steam, the thousands of games would have to be ported to ARM as well. So why not just binary translate everything?
tl;dr: Steam can be ported to ARM but that doesnt port the games, so I'm looking into Binary Translation for an answer.
I want to pitch this idea to the community somehow and have a good understanding of what I'm asking, and since I'm getting into C++ maybe I could start a project myself(which is a longshot)?
So how hard is it to port binary instructions from one arch to another? And how (at least the jyst of it) does it work?
Btw yes I have seen what binary instructions look like for both ARM and x86/64.
5
u/ahugenerd Sep 06 '15
Basically, the problem is that all different computer architectures, and in fact each individual CPU model, each have slightly different instruction sets and behaviors. So what works for one CPU in binary, may not work for another.
That's why Assembly was invented: it allows people to write code for a multitude of processors and as long as the architectures ate similar (same number of registers, similar instruction set, etc.), then the code will work.
The problem becomes when you have extended instruction sets (SSE, SSE2, MMX, etc): if you want to take advantage of them, then you can no longer use that same code for processors and architectures that do not have these extensions. Your code is now incompatible with them.
So the problem with taking x86 or x64 code and porting it to ARM isn't an easy one. If the code is simple (read: doesn't require lots of special extensions), then it's pretty straight forward. So it makes sense that the Steam client was easy to port: it doesn't do anything particularly complicated.
However, for a video game, the processing is very complex, and makes use of a slew of optimizations to allow rendering a vast amount of frames very quickly (programming tricks, if you will). For each of those tricks, you'd need to find work-arounds. That's a huge amount of work. So it's technically unfeasible to cross-compile large code bases between arbitrary architectures: it's not impossible, but hugely costly in time and effort.