LIKELY&UNLIKELY 宏提示编译器做分支预测
source link: https://zhiqiang.org/coding/folly-likely-macro.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
LIKELY&UNLIKELY 宏提示编译器做分支预测
folly
的Likely.h
文件提供了 LIKELY 和 UNLIKELY 宏,提示编译器在分支预测时选择分支。其实现很简单:
#define LIKELY(x) (__builtin_expect((x), 1)) #define UNLIKELY(x) (__builtin_expect((x), 0))
用法如下:
#include <folly/likely.h> int a = 1; if (LIKELY(a == 1)) { a = 2; } if (UNLIKELY(a == 3)) { a = 3; }
只在gcc
下适用。
Q. E. D.
Recommend
-
79
-
31
最近在看 SQL 优化之 Code Generation 相关的内容,我们知道 Code Generation 是 SQL 优化的大杀器之一,不管是在 Apache Spark 还是 Apache Flink 中都有比较深入的应用(特别是在 Spark 中),Code Generation 最开始是在数据库中应用的,Spark 将其引入到 Spark S...
-
5
一文告诉你CPU分支预测对性能影响有多大 2019-09-30 分类:计算机原理 阅读(48...
-
1
Git 分支操作&存储原理浅谈作者:robertlong,腾讯 PCG 客户端开发工程师相信大家对于 git 版本控制系统都不陌生,大部分同学在工作中都会使用到 git,他帮助我们管理我们的代码,让我们能够随心所欲的提交代码,进行不同的实验而不用担心...
-
3
Don’t use the [[likely]] or [[unlikely]] attributes C++20 introduced the likelihood attributes [[likely]] and [[unlikely]] as a way for a programmer to give an optimization hint to their...
-
6
Birchtree By Matt Birchler I've been writing here since 2010! Back when personal blogs were all the rage. Kids, a...
-
7
Apple crackdown on ChatGPT apps unlikely, but new App Store rules likely forthcoming Friday, March 3, 2023 5:12 pm
-
3
springboot 处理请求的小分支-跳转 & cookie首先是跳转,应该说设置状态,其中跳转是其中一个状态,@RequestMapping(value = "request1", method = RequestMethod.GET) public void request1(HttpServletRequest reque...
-
6
现代分支预测:从学术界到工业界 浏览量: 112 预计阅读时间: 24 分钟 Branch Prediction Is Not A Solved Problem –Intel...
-
4
老实说,分支预测,是高手过招的杀手锏,但是对写业务代码没啥帮助。 ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK