When I program on a normal day, I’m sure that all branches will most likely not be accepted.
int retval = do_somting(); if(!retval) { /* Less-than-likely event*/ }
These are predictions of optimistic branches, as a result of which the processor predictor bit is set to “not accept”. However, if the predictor bit (s) is forcibly returned to "accept" after the for?
// prediction = "likely take" if(false) { } // prediction = "probably take" if(false) { } // prediction = "probably not take" if(false) { } // prediction = "likely not take" if(false) { } /* ... thousands of other if(false) that are speedy-fast */ for(int i = 0; i < 5; i++) { } // prediction = "likely take"?
I know this is an unrealistic and tiny optimization, but hey, the more you know.
EDIT: Assume that GCC does not destroy all of this code above, and also allows talking only about the amd64 architecture. Since I did not understand how low this question is.
, CPU.
, . . , if for. .
if
for
, . , .
... , , .
( AMD64) / / , / / . , , , . do-while , for while, - ; , .
gcc -O3 __builtin_expect(). , , , , . . : -O3 gcc , .
__builtin_expect()
, , , , . , , , , , . "" , - (, 4 ) , .
Source: https://habr.com/ru/post/1667897/More articles:How to check if a queue name already exists in IBM MQ for Linux? - ibm-mqPostgres, why is swap usage increasing? How to reduce it? - AWS RDS - memory-managementHow to use environment variables in docker.env file? - environment-variablesHow to rotate an image (converted from source) clockwise correctly CSS / Javascript - javascriptПоддержка Android Wear 2.0 для приложения Face Face - androidUsing RWeka M5P in RStudio gives java.lang.NoClassDefFoundError: no / uib / cipr / matrix / Matrix - javaPandas frame rotation when deduplicating extra columns - pythonWhy does RNN always output 1 - rReact - display a display of one component from onClick of another component - javascriptFormat data time series for short-term forecasting using repetitive neural networks - rAll Articles