←back to thread

386 points ingve | 2 comments | | HN request time: 0.674s | source
Show context
SleepyMyroslav ◴[] No.35738552[source]
If being branchless is important property of the algorithm then it is better to enforce it. Or at least test for it. If his GCC version will get an update and it will stop producing assembly that he wants no-one will ever know.

Which brings us back to regular discussion: C ( and C++ ) does not match hardware anymore. There is no real control over important properties of generated code. Programmers need tools to control what they write. Plug and pray compilation is not a solid engineering approach.

replies(6): >>35738629 #>>35738633 #>>35738677 #>>35738943 #>>35741009 #>>35745436 #
1. eklitzke ◴[] No.35745436[source]
Every C and C++ compiler has supported inline asm for decades, so that's what you should use if you really need to control the assembly output. The fact that you can switch between the two within the same function is one of the selling points of both languages.
replies(1): >>35746161 #
2. muricula ◴[] No.35746161[source]
msvc does not support inline asm for x86_64 code. Additionally, inline asm can be quite fragile, can impede other optimization opportunities, and it is easy to misstate your inline asm's invariants and side effects to the compiler.