Category : compiler-optimization

from gcc function attribute: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html the cold attribute can hint gcc partition caller’s cold to 2 part: normal part(the hold part) and cold part into separation function cold The cold attribute on functions is used to inform the compiler that the function is unlikely to be executed. The function is optimized for size rather than ..

Read more

The following code snippet can only be linked if optimization level was higher than O0: #include <cstdio> #include <utility> void vf(std::size_t n, …) {printf("%zun", n);} template<typename …ARGS> void vt(ARGS&&… args) {vf( sizeof…(ARGS), std::forward<ARGS>(args)… );} struct X {static constexpr int a = 123; X() {vt(a);}}; int main() {X();} You can run it here: http://cpp.sh/3dv7p Configuring C++11/14 ..

Read more

Getting totally unexpected results while comparing binary search vs linear search’s real time performance in C++ using the code below – typedef std::chrono::microseconds us; int linear_search(uint64_t* val, int s, int e, uint64_t k) { while (s < e) { if (!less<uint64_t>()(val[s], k)) { break; } ++s; } return {s}; } int binary_search(uint64_t* val, int s, ..

Read more

I have observed that my code is crashing randomly(once in 10 or 20 times) at the same place. This is the place(line no. 261) where it is crashing 259. void set_cfg_action(my_action& arg) 260. { 261. cfg_action = arg; 262. } and the function call is coming from here class_name& _object_name; my_action _my_action = my_action::MY_ACTION_CREATE; _object_name.set_cfg_action(_my_action) ..

Read more

server crashed and recieve SIGSEGV, with following info: IP=9e97b4f, RBP=7fc5de748fe0, RAX=7fc297d235d8, RCX=7fc297d23458, sig=11, sig_code=128, sig_addr=0, after disassembly code around IP, it show the movaps instruction access memory without 128bit aligned (see RCX‘s value); what confuse me is why compile generate block of movaps instructions to set the memory region to ZERO; before call the constructor ..

Read more