branch-prediction Questions

4

Solved

This is a great article which talks about low level optimization techniques and shows an example where the author converts expensive divisions into cheap comparisons. https://www.facebook.com/notes...

4

Solved

The problem: I'm trying to figure out how to write a code (C preffered, ASM only if there is no other solution) that would make the branch prediction miss in 50% of the cases. So it has to be a p...

0

I am currently looking for answers to why gcc generates strange instructions like "rep ret" in the generated assembly code. I came across a question on Stack Overflow where someone raised...

1

Solved

Let's attempt to define a function that returns the maximum of two values x and y. A sufficient condition for these formulas to be valid is that, for signed integers, –2^30 <= x, y <= 2^30 – ...

3

Solved

I came across this very nice infographic which gives a rough estimation about the CPU-cylces used for certain operations. While studying I noticed an entry "Right branch of if" which I as...
Ottillia asked 8/10, 2022 at 13:29

1

While trying to benchmark implementations of a simple sparse unit lower triangular backward solve in CSC format, I observe strange behavior. The performance seems to vary drastically, depending on ...

9

Solved

I am reading this book by Fedor Pikus and he has some very very interesting examples which for me were a surprise. Particularly this benchmark caught me, where the only difference is that in one of...
Eileen asked 8/2, 2022 at 19:40

18

Solved

I can't, for the life of me, remember what exactly our teacher said that day and I'm hoping you would probably know. The module is "Data Structures and Algorithms" and he told us something along t...
Abjuration asked 24/11, 2008 at 20:18

25

Solved

In this C++ code, sorting the data (before the timed region) makes the primary loop ~6x faster: #include <algorithm> #include <ctime> #include <iostream> int main() { // Generat...
Mozarab asked 27/6, 2012 at 13:51

1

Consider the following two alternative pieces of code: Alternative 1: if (variable != new_val) // (1) variable = new_val; f(); // This function reads `variable`. Alternative 2: variable = ...
Busterbustle asked 25/10, 2021 at 16:36

1

I'm struggling to understand the difference between data dependence and control dependence . So what I saw as an example was : data dependence e.g., instruction uses data created by another instruc...

3

Solved

Is there a way to convert the following C code to something without any conditional statements? I have profiled some of my code and noticed that it is getting many branch misses on an if statement ...
Chumash asked 13/4, 2017 at 2:8

2

Solved

Last Branch Record refers to a collection of register pairs (MSRs) that store the source and destination addresses related to recently executed branches. http://css.csail.mit.edu/6.858/2012/reading...
Rockefeller asked 3/2, 2013 at 8:7

0

I'm a long-time user of cachegrind for program profiling, and recently went back to check the official documentation once more: https://valgrind.org/docs/manual/cg-manual.html In it, there are mult...

2

All benchmarks are run on either Icelake or Whiskey Lake (In Skylake Family). Summary I am seeing a strange phenomina where it appears that when a loop transitions from running out of the Uop Cache...

6

Options 1: boolean isFirst = true; for (CardType cardType : cardTypes) { if (!isFirst) { descriptionBuilder.append(" or "); } else { isFirst = false; } //other code not relevant to this t...

1

Solved

I discovered this popular ~9-year-old SO question and decided to double-check its outcomes. So, I have AMD Ryzen 9 5950X, clang++ 10 and Linux, I copy-pasted code from the question and here is what...
Falgout asked 7/3, 2021 at 20:57

1

Solved

C++20 has handy [[likely]]/[[unlikely]] attributes which guide code generation. For example, you can specify a branch is likely to be taken by: if (b) [[likely]] { /*...*/ } Similarly, it is possi...
Absorbent asked 5/3, 2021 at 16:29

1

As I understood, Return Stack Buffer only supports 4 to 16 entries (from wiki: http://en.wikipedia.org/wiki/Branch_predictor#Prediction_of_function_returns) and is not pair of key-value(based on in...

3

Solved

This relates to this question Thinking about it though, on a modern intel CPU the SEC phase is implemented in microcode meaning there would be a check whereby a burned in key is used to verify the...

1

Solved

The code snippet iterates through a 1D matrix. (N is the size of the matrix). for (i=0; i< N; i++) // outer loop for Rows When I run this piece of code on a processor simulator to measure TAGE ...
Halverson asked 21/1, 2021 at 4:35

2

Solved

I am currently looking at the various parts of the CPU pipeline which can detect branch mispredictions. I have found these are: Branch Target Buffer (BPU CLEAR) Branch Address Calculator (BA CLEA...
Seldom asked 7/7, 2015 at 22:58

3

Solved

I've come across a few scenarios where I want to say a function's return value is likely inside the body of a function, not the if statement that will call it. For example, say I want to port code ...
Pitch asked 9/10, 2020 at 20:24

0

I'm learning memory barrier so I referred to memory-barriers documentation in linux kernel source code. And there is one description that I can't understand: Control dependencies can be a bit tric...

1

Linux defines an assembler macro to use BX on CPUs that support it, which makes me suspect there is some performance reason. This answer and the Cortex-A7 MPCore Technical Reference Manual also sta...

© 2022 - 2024 — McMap. All rights reserved.