branch-prediction Questions

1

Solved

CPU's use branch prediction to speed up code, but only if the first branch is actually taken. Why not simply take both branches? That is, assume both branches will be hit, cache both sides, and t...

5

Solved

After reading this post (answer on StackOverflow) (at the optimization section), I was wondering why conditional moves are not vulnerable for Branch Prediction Failure. I found on an article on con...

2

Solved

I read that a perfectly predicted branch has zero / almost-zero overhead. (For example in an answer on Effects of branch prediction on performance?) I don't quite understand what people mean by thi...
Cookhouse asked 16/3, 2018 at 2:31

4

Solved

Everything I've read seems to indicate that a branch misprediction always results in the entire pipeline being flushed, which means a lot of wasted cycles. I never hear anyone mention any exception...

1

Solved

Branches prediction have been addressed a couple of time on StackOverflow. However, I didn't specifically found the answer to what I am looking for. During the optimization phase, I need to avoid b...
Orren asked 5/1, 2018 at 21:42

1

This is a follow up to some comments made in this prior thread: Recursive fibonacci Assembly The following code snippets calculate Fibonacci, the first example with a loop, the second example wit...

10

Solved

Specifically, if I have a series of if...else if statements, and I somehow know beforehand the relative probability that each statement will evaluate to true, how much difference in execution time ...
Pescara asked 19/10, 2017 at 15:17

2

From my university course, I heard, that by convention it is better to place more probable condition in if rather than in else, which may help the static branch predictor. For instance: if (check_...
Moschatel asked 26/1, 2017 at 18:49

4

Solved

In the latest Intel software dev manual it describes two opcode prefixes: Group 2 > Branch Hints 0x2E: Branch Not Taken 0x3E: Branch Taken These allow for explicit branch prediction of Jum...
Clincher asked 15/1, 2013 at 7:20

10

Solved

I have a quick question, suppose I have the following code and it's repeated in a simliar way 10 times for example. if blah then number = number + 2^n end if Would it be faster to evaluate: nu...
Monopteros asked 26/10, 2010 at 13:35

8

Solved

I'm reading around that branch misprediction can be a hot bottleneck for the performance of an application. As I can see, people often show assembly code that unveil the problem and state that prog...
Dogcatcher asked 15/9, 2015 at 8:48

2

Solved

From reading this I came across the next two quotes: First quote: A typical case of unpredictable branch behavior is when the comparison result is dependent on data. Second quote: No...
Husserl asked 10/2, 2017 at 20:24

5

Solved

I just read about Branch-Prediction and wanted to try how this works with Java 8 Streams. However the performance with Streams is always turning out to be worse than traditional loops. int total...
Heteronym asked 22/12, 2016 at 8:26

2

Solved

I recently asked a question on Code Review to review a sorting algorithm named QuickMergeSort. I won't get in the details, but at some point the algorithm performs an internal mergesort: instead of...
Preemie asked 13/12, 2016 at 19:53

4

Solved

I had a function which looked like this (showing only the important part): double CompareShifted(const std::vector<uint16_t>& l, const std::vector<uint16_t> &curr, int shift, in...
Barthol asked 6/12, 2016 at 9:22

10

Solved

I've been digging through some parts of the Linux kernel, and found calls like this: if (unlikely(fd < 0)) { /* Do something */ } or if (likely(!err)) { /* Do something */ } I've found the d...
Freetown asked 20/9, 2008 at 23:4

1

Solved

The issue of the repz ret has been covered here [1] as well as in other sources [2, 3] quite satisfactorily. However, reading neither of these sources, I found answers to the following: What is t...

7

Solved

In this code: if (value >= x && value <= y) { when value >= x and value <= y are as likely true as false with no particular pattern, would using the & operator be faster ...

5

Solved

Let A be an array that contains an odd number of zeros and ones. If n is the size of A, then A is constructed such that the first ceil(n/2) elements are 0 and the remaining elements 1. So if n = 9...
Surgeonfish asked 15/9, 2016 at 14:44

1

Solved

As follow up to my question The advantages of using 32bit registers/instructions in x86-64, I started to measure the costs of instructions. I'm aware that this have been done multiple times (e.g. A...
Broomstick asked 7/8, 2016 at 7:23

1

Solved

Are there any way to determine or any resource where I can find the branch Target Buffer size for Haswell, Sandy Bridge, Ivy Bridge, and Skylake Intel processors?
Lentiginous asked 21/7, 2016 at 19:33

1

Solved

I tried to duplicate the example in this famous question. My code looks like this: #![feature(test)] extern crate rand; extern crate test; use test::Bencher; use rand::{thread_rng, Rng}; type It...
Regretful asked 13/6, 2016 at 22:24

1

In x86-64, if you use the following assembly code: MOV RAX, (memory address) JMP RAX Does the pipeline stall before executing the branch (to wait for MOV to finish with RAX), or will it flush th...

1

Solved

If I understand branching correctly (x86), the processor will sometimes speculatively take a code path and perform the instructions and 'cancel' the results of the wrong path. What if the operation...
Zellers asked 8/3, 2016 at 0:46

6

Solved

I'm writing some code in Java where, at some point, the flow of the program is determined by whether two int variables, "a" and "b", are non-zero (note: a and b are never negati...

© 2022 - 2024 — McMap. All rights reserved.