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

"Well, at least in clang (3.4). Gcc (4.8.2) is too smart to fall for this separate destination thing and “optimizes” the code back to something like our original version."

This resonated quite heavily with me. I've spent rather large amount of time figuring out how to trick various compilers. This is especially critical in cases where there is no inline assembly, such as shaders. It's really sad how in some cases you can 'optimize' code by hiding information. In what sane world code runs faster if you make something not a compile time constant as an example?

I really wish that every compiler would have "Shut up! I know what I'm doing!" mode where it would basically do what you say as close as possible. 1:1 mapping on registers to certain variables and the few temp regs required for evaluating expressions.

This is not needed often but it's absolutely mandatory for going from 40-50% of theoretical speed to >90%. And in games and other soft real time applications this can spell the difference between 30 and 60 fps.



> I really wish that every compiler would have "Shut up! I know what I'm doing!" mode where it would basically do what you say as close as possible. 1:1 mapping on registers to certain variables and the few temp regs required for evaluating expressions.

Seconded. When I'm testing out algorithms the compiler hasn't seen before, it takes too much work that amounts to telling the compiler "STFU and do as I say."


That mode is called "assembly". I use it all the time.


It's a very useful mode, but assuming you don't write the entire program in assembly, what's the best way you've found to integrate the assembly with the non-assembly code? Is there any Windows/Mac/Linux portable and self-contained way of doing it short of writing assembly functions in separate files and distributing NASM along with the source? Does even that work?


Why would you distribute NASM, or any other assembler, with your own code? You list it as a requirement to build your code. Would you also distribute GCC?


Logically this makes fine sense, but for whatever reason, I don't think I've ever encountered a popular open source program that required a specific assembler other than 'gas' unless the entire codebase was written for that assembler. I don't think I've encountered it in academic code either.

But for whatever reason I've encountered a few that distribute NASM or another assembler. I don't know exactly why this would be. I'm trying to find out. Do you have examples where requiring NASM (or another assembler) as an external dependency has worked for projects in the past? I'm sure they must exist --- I just don't know of any.


FFmpeg. It requires NASM or YASM if you don't want to cripple it by disabling the external assembly.


I especially mentioned in the the case where assembly is not available.

Examples: Shaders for graphics. OpenCL kernel language. Compute shaders.

It's the difference between getting 5TFlops or 2TFlops out of your GPU.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: