logoalt Hacker News

grishkalast Wednesday at 11:48 PM3 repliesview on HN

I've also heard the opinion that modern compilers are better at generating optimized code than someone writing assembly by hand. Not sure how true it is, but considering the unfathomable complexity of modern CPUs, it does feel believable.


Replies

mabsterlast Thursday at 7:53 AM

As a low level performance guy I trust the compiler nowadays, especially with deep instruction pipelines. The compiler is beatable - a lot of the decisions are heuristic - but it takes a lot of work to beat it.

GianFabienlast Thursday at 9:56 AM

Last time I looked intel CPUs had like 1700 instructions. Every generation comes with an even more expanded ISA. I doubt that compilers use even a fraction of the ISA. Especially considering that binaries are often expected to run on a wide range of older CPUs. I know that there are intrinsic functions which provide access to some of the powerful, yet special purpose instructions. It is unrealistic to expect the compiler to make effective use of all the fancy instructions you paid for with your latest hardware upgrade.

show 2 replies
mystified5016last Thursday at 8:49 PM

If and only if someone has taken time to write specific optimizations for your specific CPU.

In embedded land, if your microcontroller is unpopular, you don't get much in the way of optimization. The assembly GCC generates is frankly hot steaming trash and an intern with an hour of assembly experience can do better. This is not in any way an exaggeration.

I've run into several situations where hand-optimized assembly is tens of times faster than optimized C mangled by GCC.

I do not trust compilers anymore unless it's specifically for x86_64, and only for CPUs made this decade

show 1 reply