Live data from Hacker News

Ask HN: What is hand-coded assembly language used for these days?

news.ycombinator.com

21–30 of 60 posts

Re: Ask HN: What is hand-coded assembly language used for these days?

#21
Compiler intrinsics, binary patches and hooks (although EasyHook has made assembly a rarity here outside of the occasional shim where odd calling conventions are used), in-process debuggers, low-level bootloaders, hardware initialization/management, various thunking mechanisms.

Others have covered the optimization side of things well so I won't repeat it, but there are tiny fragments of assembly all over the place -- they hold your system together.

Re: Ask HN: What is hand-coded assembly language used for these days?

#22
Debugging and reverse engineering games.

When publishers/developers don't give a bleep, the fans take up the task of fixing the bugs themselves. I happen to run one such project in my spare time (for C&C: Red Alert 2), and it's amazing how much stuff is broken. It's not as "serious" as other projects mentioned here, but still a reason to know ASM. (And a good way to see bad programming practices in action :) )

Re: Ask HN: What is hand-coded assembly language used for these days?

#23

IMVU hand-rolled its SSE skinning loops and parts of the software 3D lighting code, because only 2/3 of our customers have GPUs. We need to run well on five-year-old Dells with Intel graphics. (Direct3D on Intel isn't as good as a dedicated software renderer. We chose RAD's Pixomatic.) In addition, look at how popular netbooks are becoming. The Intel Atom is an in-order CPU. Imagine a hyperthreaded, 1.6 GHz 486... On…

Oh, I forgot about another huge case for writing assembly language... These days, we have tons of different languages talking to each other, all in the same program. In Mozilla, for example, JavaScript talks to C++ objects via XPCOM/XPIDL. Since the C++ objects expect data laid out on the C stack in a certain order and JavaScript has no notion of the C stack, there is a bit of platform-specific assembly code in the m…

Exactly for this reason I found myself writing assembly again: Invoke C functions from a scripting language. The last I wrote was probably 15 years back.

Re: Ask HN: What is hand-coded assembly language used for these days?

#24
post #9
post #4

Contrary to popular belief, assembly is not only used for performance. Ask the security industry for more info.

That has more to do with reading assembly than writing it by hand.

There are certainly people who write shellcode. As I understand it, people have written shellcodes that use only bytes that happen to map to ASCII, are obfuscated to bypass intrusion detection systems, and so on. I'm sure it requires quite a bit of (specialized) knowledge.

Re: Ask HN: What is hand-coded assembly language used for these days?

#25
post #14

Anything that's worth spending time to do fast is worth spending time writing SIMD assembly for. You can get 5x, 10x, 20x, or more performance increases just by using the vector instructions given to you by the CPU. Until a magic compiler appears that can make proper use of them (read: never), hand-coded assembly will be critical for almost any application for which performance is critical, especially multimedia proc…

A compiler can't be made to make proper use of vector instructions? Why is that?

As I understand - and I may be mistaken - the problem is that it's very hard to make sure that the emitted code is correct in the presence of raw pointers à la C.

I am told that Fortran does better than C here; there is a reason it is still widely used in the scientific computing community, after all.

This is also part of the reasoning behind C99's new restrict keyword.

Re: Ask HN: What is hand-coded assembly language used for these days?

#26

Anything that's worth spending time to do fast is worth spending time writing SIMD assembly for. You can get 5x, 10x, 20x, or more performance increases just by using the vector instructions given to you by the CPU. Until a magic compiler appears that can make proper use of them (read: never), hand-coded assembly will be critical for almost any application for which performance is critical, especially multimedia proc…

Well, you can still use C with GCC and Intel intrinsics I guess.

Re: Ask HN: What is hand-coded assembly language used for these days?

#27
post #20
post #16

Earlier quoted context omitted.

I, for one, think that Assembly is just beautiful in its simplicity.

Having read and written assembly on a daily basis for years, I have to disagree entirely. The only simple thing about assembly is that it happens to map to machine code directly, but macros and quasi-instructions even make that iffy. There are so many idiosyncrasies in every ISA, so many ways in which the code you write has side effects. Assembly isn't just complex in practice, it's complex in concept. If you want si…

Try ARM. x86 assembly is ugly and wart ridden. ARM is like a breath of fresh air. Unbelievably well designed.

Re: Ask HN: What is hand-coded assembly language used for these days?

#28

IMVU hand-rolled its SSE skinning loops and parts of the software 3D lighting code, because only 2/3 of our customers have GPUs. We need to run well on five-year-old Dells with Intel graphics. (Direct3D on Intel isn't as good as a dedicated software renderer. We chose RAD's Pixomatic.) In addition, look at how popular netbooks are becoming. The Intel Atom is an in-order CPU. Imagine a hyperthreaded, 1.6 GHz 486... On…

Oh, I forgot about another huge case for writing assembly language... These days, we have tons of different languages talking to each other, all in the same program. In Mozilla, for example, JavaScript talks to C++ objects via XPCOM/XPIDL. Since the C++ objects expect data laid out on the C stack in a certain order and JavaScript has no notion of the C stack, there is a bit of platform-specific assembly code in the m…

Mozilla also use assembly for heavily used computationally expensive operations like image decoding. mmoy’s work is worth looking at:

https://bugzilla.mozilla.org/buglist.cgi?query_format=advanc...

Re: Ask HN: What is hand-coded assembly language used for these days?

#29
post #9
post #4

Contrary to popular belief, assembly is not only used for performance. Ask the security industry for more info.

That has more to do with reading assembly than writing it by hand.

Actually, no. If you're dealing with obfuscation, IDS and antivirus evasion etc. you need to know how to read, write and otherwise manipulate assembly code (debug, self-modification, name-it).

Re: Ask HN: What is hand-coded assembly language used for these days?

#30
post #26

Anything that's worth spending time to do fast is worth spending time writing SIMD assembly for. You can get 5x, 10x, 20x, or more performance increases just by using the vector instructions given to you by the CPU. Until a magic compiler appears that can make proper use of them (read: never), hand-coded assembly will be critical for almost any application for which performance is critical, especially multimedia proc…

Well, you can still use C with GCC and Intel intrinsics I guess.

Intrinsics are still worse (performance-wise) than hand-coded assembly, for two reasons.

The first reason is the whole category of optimizations that the compiler is worse than a human at (like register allocation) or cannot do effectively at all (messing with calling conventions, computed jumps).

The second reason is more subtle: in any case that you abstract yourself from some part of a problem, you inherently create a less efficient solution.

For example, intrinsics mean that you don't have to manually allocate registers. But this also means that if your algorithm uses too many registers and it would be more efficient to modify it to require fewer (and thus not need spills), you will have no way of knowing such a thing. By insulating yourself from that layer of complexity, you've also limited your ability to make higher-level optimizations that improve lower-level performance.

This applies on practically every level possible: any method of abstraction, no matter how well designed, will always in some fashion reduce the maximum performance you can achieve. Of course, this doesn't mean abstraction is bad--it provides an often-useful tradeoff between developer time and performance.

Post reply on HN