Using rdmsr/rdpmc for branch prediction accuracy
问题 I am trying to understand how does a branch prediction unit work in a CPU. I have used papi and also linux's perf-events but both of them do not give accurate results (for my case). This is my code: void func(int* arr, int sequence_len){ for(int i = 0; i < sequence_len; i++){ // region starts if(arr[i]){ do_sth(); } // region ends } } My array consists of 0's and 1's. It has a pattern with a size of sequence_len . For example, if my size is 8, then it has a pattern of 0 1 0 1 0 0 1 1 or