r/programming • • Oct 04 '13

What every programmer should know about memory, Part 1

http://lwn.net/Articles/250967/
660 Upvotes

223 comments sorted by

View all comments

Show parent comments

2

u/[deleted] Oct 05 '13

I don't know what platforms or compilers you're working on, but on x86 and arm the compilers are great. We (I work someplace you've heard of doing graphics and multimedia) have literally no assembly code. There is no reason why a good optimizing compiler can't generate fast asm, and often it thinks of optimizations that even our best engineers may miss.

You should try racing the compiler sometime on something more complex than a line or two of code. It will most likely win.

Also keep in mind that inserting asm throws off a ton of optimizations because the compiler can't guarantee you're following the c/c++ standards in your asm.

Edit: accidentally submitted to early.

1

u/felipec Oct 05 '13

I don't know what platforms or compilers you're working on, but on x86 and arm the compilers are great.

That's what you think, but they don't.

http://hardwarebug.org/2009/05/13/gcc-makes-a-mess/

We (I work someplace you've heard of doing graphics and multimedia) have literally no assembly code.

You are probably doing things wrong.

There is no reason why a good optimizing compiler can't generate fast asm, and often it thinks of optimizations that even our best engineers may miss.

I trust FFmpeg/x264 engineers over any gcc compiler.

You should try racing the compiler sometime on something more complex than a line or two of code. It will most likely win.

Wrong.

http://hardwarebug.org/2008/11/28/codesourcery-fails-again/

I also have worked in someplace you've heard doing multimedia, and I can assure you FFmpeg's assembly code is way faster than the C version, that's the whole reason why they have assembly code.

Do you want me to compile both and show you how wrong you are?

1

u/[deleted] Oct 06 '13

So what your examples of people needing to write ASM because it's faster are two obvious bugs in gcc? Ok.

1

u/felipec Oct 06 '13

You can never trust the compiler to generate the most optimal code, and the generated code can never be as optimal as what an expert engineer would write.

I guess you don't want me to compare the performance of C-only FFmpeg vs. C+ASM FFmpeg. Right?

I guess you already know what performs better.