答案是不能,但是__builtin_expect_with_probability 可以 godbolt https://godbolt.org/z/Gzr7bEaef #define LIKELY(x https://godbolt.org/z/ehhfzYqed while ((pos1 < size1) & (pos2 < size2)) { v1 = input1[pos1]; v2 v1 : v2; pos1 += (v1 <= v2); pos2 += (v1 >= v2); } LLVM 后端引入分支避免生成cmov godbolt https://godbolt.org /z/oM5aWeYW4 godbolt https://godbolt.org/z/oM5aWeYW4 #include <cstddef> #include <cstdint> // Select https://godbolt.org/z/3GqMsY6v3 unsigned foo(unsigned a, unsigned b) { unsigned t = ((a > 2) !
结果很奇怪 https://godbolt.org/z/Kx6hn9ccM 需要调查 • 构造慢的原因? godbolt https://godbolt.org/z/r4YsxvvM8 另外这个代码不挂sanitize可能会炸,我godbolt没复现 https://godbolt.org/z/TWxWcKoTd 使用friend tag绕过,非常猥琐 godbolt https://godbolt.org/z/xhzr6nE73 #include <memory> struct Arg1 {}; struct v=O8HndvYNvQ4 看一下这个例子 观察drop take语义区别 godbolt https://godbolt.org/z/Yz7M6zo5s #include <string> #include 而take每次都会计算,不会缓存结果 代码就不贴了,godbolt https://godbolt.org/z/8P3MfvcKb 开源项目介绍 • asteria https://github.com
大概意思就是move only function封装用executor来管理/分配内存/生命周期管理,作者还给了POC https://godbolt.org/z/rrbW6veYd 没有细看 • Type-aware 这个很干净 实现godbolt https://godbolt.org/z/65fEd3axf • A Relocating Swap https://www.open-std.org/jtc1/sc22 编译器信息最新动态推荐关注hellogcc公众号 本周更新 2024-0522第255期 文章 超好用的 C++ 在线编译器(VSCode 版)https://zhuanlan.zhihu.com/p/694365783 godbolt 注意这个坑 godbolt https://godbolt.org/z/9EWYexK6E Looking up a C++ Hash Table with a pre-known hash https
4; std::cout << i << std::endl; // prints 9 std::cout << j << std::endl; // prints 4 } https://godbolt.org return r; } int main() { const Rng z = bar(); std::cout << &z << std::endl; } https://godbolt.org time_point now() { return {};} }; template <> constexpr auto clock_impl<> = test_clock{}; https://godbolt.org T> make_optional(A); template<class A> optional make_optional(A); 然后她举了个例子,怎么设计强制制定T和忽略T https://godbolt.org /z/MvYfbEP8r https://godbolt.org/z/57zsK9rEn 设计的挺有意思的,鉴于篇幅,放在后面 手动优化C++代码来加快编译速度?!
分别是:wanbox、godbolt、quick-bench与build-bench。 1.在线编译 不想在本地配置C++环境,那么这个网站很有用! https://godbolt.org/ 3.基准测试 benchmark,我们知道go的test是支持的,那么在c++中,对一个函数或者接口测试的时候可以使用gtest,但是想要一个基准结果,就需要
godbolt 这个就比较适合用来查看汇编代码了,严格来说不算在线编译器,而是汇编查看器,主要特点: 实时查看C/C++代码的汇编代码,而不用使用gdb,objdump等工具反汇编 地址: https: //godbolt.org/ ?
# TAILCALL .LBB0_1: jmp fallback # TAILCALL 可以https://godbolt.org /z/K8Mo6hcGa 在godbolt上看一看 注意return fallback,如果没有return,这里就不会优化,解决方法,使用 __attribute__((preserve_most)) cppinsights.io/ https://wg21.link/ https://eel.is/c++draft/ https://compiler-explorer.com/ - https://godbolt.org / - https://gcc.godbolt.org/ https://en.cppreference.com/w/ Blogs https://www.fluentcpp.com/ https:/
https://godbolt.org/z/xx3eWcP8x #include <iostream> #include <typeinfo> #include <expected> #include 感觉这就是面试题 File modes in C++20 https://euroquis.nl//blabla/2024/04/30/chmod.html 直接贴godbolt和代码吧 https:/ /godbolt.org/z/xc5MjTrob #include <iostream> #include <sys/stat.h> namespace detail { // Tag classes 类似TLSF 这里标记个TODO有时间研究一下 • https://github.com/Jaysmito101/rusty.hpp 抄rust的特性实现 • 一个function实现 https://godbolt.org
直接上llvm-mca分析 https://godbolt.org/z/odox8Wdr5 首先插入一个简单粗暴的教程,如何看懂llvm-mca https://llvm.org/docs/CommandGuide /llvm-mca.html 就是机器码分析器,模拟机器码执行效果,我们不用装llvm-mca,直接用godbolt内置的工具。 显然越接近Dispatch Width越说明资源受限制,利用率太高了,相当于CPU高了,需要找到瓶颈来源 • 剩下的是执行模拟以及在哪里卡了,具体分析可以用-bottleneck-analysis,得本地搞了godbolt 貌似不能玩 好了,根据上面的godbolt结果,直接把数据差异对比一下 另外 网上搜到了google的两个实现,把数据补充上 https://godbolt.org/z/9nsczeT5c int hammingWeightV2
在线网站 https://godbolt.org/
https://godbolt.org/z/PPsn4KM7Y 简单来说还是embed,借助embed实现concept reflexpr Getting in trouble with mixed construction 讨论optional各种构造转换 c++20 编译期解析(compile-time parsing)以及实现类似rust macro rule https://godbolt.org/z/zKbWc7MhE https://godbolt.org/z/5ajjYs754 直接贴代码了。 Enough Assembly for Compiler Explorer - Anders Schau Knatten - Meeting C++ 2022 我觉得还是直接看ppt吧,非常容易懂,我记得以前godbolt
// } /* foo(not_null<int>): jmp consume(not_null<int>) */ 感谢anms nugine ni fvs zwuis 讨论 godbolt https://godbolt.org/z/fbqEa4M1r noexcept Can (Sometimes) Help (or Hurt) Performance https://16bpp.net
<< fA()<< "\n"; std::cout << fB()<< "\n"; std::cout << fC()<< "\n"; return 0; } https://godbolt.org 24.193993753 Warsaw: 2024-11-15 23:31 New York: 2024-11-15 17:31 Tokyo: 2024-11-16 07:31 */ https://godbolt.org 编译器激进到直接return 1 这个可以看lancern文章有介绍过 https://zhuanlan.zhihu.com/p/391088391 感谢zwuis提醒 析构栈溢出一个例子 https://godbolt.org in_place_type_t 上面的代码还算容易看懂,其实就是tag把类型带过来,有点像identity_type那种玩法 不过构造函数模板不如类模板来的直观一些,这么玩有点复杂, 代码 https://godbolt.org
看这段代码,演示在这里https://godbolt.org/z/jEGK1z3nT class iapi { public: virtual ~iapi() = default; virtual gcc trunk分支已经支持了,可以在godbolt上玩一玩 Roi Barkan “Argument passing, Core guidelines and concepts” 讨论参数的。
some-informal-remarks-towards-a-new-theory-of-trait-customization/ tag_invoke疑似有点太泛型了,作者觉得还是rust traits直观,提出了个traits object的概念 看代码 https://godbolt.org 作者提出了一种模版特化校验的方法 没有任何额外开销 https://godbolt.org/z/hcEWeqf6P 就是我没看明白怎么用的 raymond chen windows环节 • How to
3,4}}) { std::cout << "{" << e.x << ',' << e.y << '}'; // prints {1,2}{3,4} } } if里面啥花活都能整了属于是 godbolt to be called only once in C++ 怎么保证一个函数只被调用一次呢,这里有个点子,Destructive separation: move away and call Matt Godbolt do_something_else(); } 当 x y不是NaN就可以这样优化 -ffinite-math-only告诉编译器,没有NaN,大胆去优化,但是如果x y恰巧是NaN,那就完了 一个汇编例子 godbolt
有点出乎意料,在 go.godbolt.org[1]查看两段代码的汇编 (要加上func main,不然编译不过) f: TEXT main.main(SB), LEAF|NOFRAME 但u1s1,编译器不该屏蔽这样的细节差异吗...要靠这样犄角旮旯的tricks达到最佳性能,一定程度并不符合Go的理念 推荐阅读:Go 函数调用 ━ 栈和寄存器视角[2] 参考资料 [1] go.godbolt.org : https://go.godbolt.org/ [2] Go 函数调用 ━ 栈和寄存器视角: https://studygolang.com/articles/21875
LINE__) VARIADIC() // `empty` VARIADIC(a) // `line` 4 VARIADIC(a, b) // `line` 5 效果 https://godbolt.org unsigned char memory[1024] = {}; execute<add3>(memory); 旧版godbolt https://godbolt.org/z/MaPffqxGT 新版godbolt https://godbolt.org/z/Gd3zKWvKE 开O2能直接算出结果,constexpr的好处还是很明显的 CTRE基本上也是这个原理 CTRE library
assert(OVERLOAD(g)(5) == 6); MyClass obj; assert(OVERLOAD(obj.f)(5) == 6); return 0; } godbolt https://godbolt.org/z/zrcsaG9xE P3312就是这盘饺子 https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024
https://github.com/facebook/zstd/releases/tag/v1.5.0 文章 std::variant支持继承,再实现operator()更方便std::visit 在线演示godbolt