3,405 questions
1 vote
1 answer
76 views
Is the C compiler allowed to emit spaghetti assembly for the sake of optimization? [duplicate]
So I have the following code: float param1 = SOME_VALUE; switch (State) { case A: { foo(param1); break; } case B: { bar(); break; } case C:...
Advice
2 votes
6 replies
113 views
determine cpu after c++ compilation with gcc?
Does anyone know if there is, in c++, any way to determine at runtime the cpu characteristics of the machine that compiled the code? For example, in gcc (which I'm using) the preprocessor variable ...
3 votes
2 answers
187 views
Why do GCC and Clang fail to auto-vectorize simple loop?
I have two functions counting the occurrences of a target char in the given input buffer. The functions vary only in how they communicate the result back to the caller; one returns the result and the ...
Best practices
2 votes
10 replies
277 views
How to tell the C compiler that data pointed to by a pointer won't be constantly modified by another thread after being passed to a function?
In C, when I pass a pointer to a function, the compiler always seems to assume that the data pointed to by that pointer might be continuously modified in another thread, even though in actual API ...
3 votes
5 answers
631 views
What is special about a ternary statement instead of a if-else statement in terms of optimization?
I'm talking from a language point of view in C or C++, where the compiler sees: return condition ? a : b; vs: if (condition) return a; else return b; I've tried in my code, and both of them ...
25 votes
2 answers
4k views
Does excessive use of [[likely]] and [[unlikely]] really degrade program performance in C++?
The C++ standard [dcl.attr.likelihood] says: [Note 2: Excessive usage of either of these attributes is liable to result in performance degradation. — end note] I’m trying to understand what “...
0 votes
0 answers
43 views
How to build a gcc_tree_node from custom language Nodes
Nodes: building a gcc_tree_node for a custom prograimming language compile and base on C++26 the modules are avilable the language using tab-block system every keyword start with '/' I want to ...
5 votes
3 answers
291 views
How to make the optimiser treat a local function as a black box and not optimise based on its implementation?
I thought that the noinline function attribute would force the compiler to treat a local function as a black box: __attribute__((noinline)) void touch_noinline(int&) {} void touch_external(int&...