Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

C is what you use when you should actually be using assembler, but you are not insane enough to actually do that.


The statement "C is portable assembly" may have been true some time in the 1970's but compilers have improved since then and the statement is no longer valid.


[deleted]


> Believe me, there are a lot of cases where a human beats the compiler.

Oh, I do believe you. I do analyze and re-write assembly code from the C compiler every now and then. SIMD optimizations are especially tricky. But the compiler still wins at least 80% of the cases.

And when you add a single line of assembly code (inline or not) to your C code, you inhibit all optimizations that could take place.

So for your innermost loop it might make sense to hand write assembly, but for most optimizations just re-think your C code and/or add compiler intrinsics to get SIMD or other CPU facilities put to better use.


> when you add a single line of assembly code (inline or not) to your C code, you inhibit all optimizations that could take place.

That's a significant exaggeration with most compilers. You may inhibit some optimization which would require the compiler be able to reason about side-effects across the asm block, but that's a far cry from "all optimizations".


> compilers have improved

And hardware has changed. Remember, the C machine model (the virtual system you imagine in your head when you write C) doesn't have cache, doesn't have SIMD, and doesn't have any kind of ability to do things in parallel.


Really? Optimiser's are pretty damn good, so C has pretty much replaced assembler.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: