likely-unlikely Questions

1

Some software (often performance-oriented, e.g. Linux kernel, DPDK) has C helpers for influencing branch prediction. I have an absolutely simple code snippet (suppose I know the percantage of a &gt...
Reasonable asked 6/7, 2023 at 11:47

2

IN SHORT: Is there a place to put the [[(un)likely]] attribute so that the control flow at cond2 is considered likely to take the false branch, without affecting the possibility of branches at cond...
Woodworm asked 25/5, 2022 at 9:14

8

Solved

GCC compiler supports __builtin_expect statement that is used to define likely and unlikely macros. eg. #define likely(expr) (__builtin_expect(!!(expr), 1)) #define unlikely(expr) (__builtin_expe...

7

Solved

I came across a #define in which they use __builtin_expect. The documentation says: Built-in Function: long __builtin_expect (long exp, long c) You may use __builtin_expect to provide the co...
Chimere asked 8/9, 2011 at 10:55

3

Solved

This question is about C++20's [[likely]]/[[unlikely]] feature, not compiler-defined macros. This documents (cppreference) only gave an example on applying them to a switch-case statement. This sw...
Chloramphenicol asked 11/8, 2018 at 8:36

2

Solved

How can I demonstrate for students the usability of likely and unlikely compiler hints (__builtin_expect)? Can you write an sample code, which will be several times faster with these hints compari...
Quinze asked 29/4, 2010 at 16:3

1

Solved

C++20 introduced the attributes [[likely]] and [[unlikely]] to the language, which can be used to allow the compiler to optimize for the case where one execution path is either much more likely or ...
Hallagan asked 5/6, 2020 at 18:45

1

Solved

In my objdump -t output, I see the following two lines: 00000000000004d2 l F .text.unlikely 00000000000000ec function-signature-goes-here [clone .cold.427] and 00000000000018e0 g F .text 000000...
Chura asked 3/2, 2020 at 19:37

4

Solved

I often find myself writing a code that looks something like this: if(a == nullptr) throw std::runtime_error("error at " __FILE__ ":" S__LINE__); Should I prefer handling errors with if unlikely...
Elijah asked 26/6, 2017 at 9:42

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

2

Solved

If I have: #define likely(x) __builtin_expect((x),1) #define unlikely(x) __builtin_expect((x),0) if (A) return true; else if (B) return false; ... else if (Z) return true; else //this will ne...
Myosotis asked 18/8, 2016 at 23:48

2

I am writing a critical piece of code with roughly the following logic if(expression is true){ //do something with extremely low latency before the nuke blows up. This branch is entered rarely, b...
Puli asked 6/6, 2012 at 21:29

2

Solved

Just see this construction in the linux kernel, and I can't get what does it mean. 110 return unlikely(sl->sequence != start); I know that likely/unlikely are made with __builtin_expect funct...
Flagstad asked 11/3, 2011 at 17:48

3

Solved

I came across these 2 macros in Linux kernel code. I know they are instructions to compiler (gcc) for optimizations in case of branching. My question is, can we use these macros in user space code?...
Knawel asked 3/11, 2009 at 15:25
1

© 2022 - 2024 — McMap. All rights reserved.