前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C++ 中文周刊 第107期

C++ 中文周刊 第107期

作者头像
王很水
发布2023-04-01 12:49:29
2710
发布2023-04-01 12:49:29
举报

C++ 中文周刊 第107期

周刊项目地址


资讯

标准委员会动态/ide/编译器信息放在这里

编译器信息最新动态推荐关注hellogcc公众号 本周没更

CLion 2023.1 出了,QT Creater10也出了

文章

不是啥新鲜点子啊,用shared_ptr + atomic_load/atomic_store 来做版本管理。代码在这里 https://github.com/f-squirrel/shared_config

不过atomic_load加载shared_ptr已经被废弃了,不建议使用

空大讲execution的文章,感兴趣的可以看看,前几期列一下

每(几)天学一点 C++ Execution(一) 每(几)天学一点C++ Execution(二) 每(几)天学一点 C++ Execution(三) 每(几)天学一点 C++ Execution(四

主要是他的fast_float库用上了这个特性,显摆一下,编译期的场景能加加速

llvm的,不是很懂

值得鼓励

直接看代码吧,之前也介绍过,参数可读性问题

代码语言:javascript
复制
/* We define a "type tag" so we can pass types as values */
template <typename T>
inline constinit std::type_identity<T> ttag{};

/* The config now becomes a template */
template <typename Tint_type = decltype(ttag<uint64_t>)>
struct algo_config
{
    bool heuristic42    = true;
    Tint_type int_type  = ttag<uint64_t>;
    size_t threads      = 4ull;
};

/* And also the algorithm */
template <typename ...Ts>
auto algo(auto data, algo_config<Ts...> const & cfg)
{
    /* implementation */
}

int main()
{
    /* Setting just "value parameters" still works with and without "algo_config" */
    algo("data", algo_config{.heuristic42 = false, .threads = 8});
    algo("data",            {.heuristic42 = false, .threads = 8});

    /* When setting a "type parameter", we need to add "algo_config" */
    algo("data", algo_config{.int_type = ttag<uint32_t>, .threads = 8});
}

有点过度设计,但是点表达式构造这个c++早就该引入了,c一直有,c++一直没加,这个还是对可读性有帮助的

降低内存访问浪费,尽可能利用寄存器

尽量不要使用指针,如果用,restrict,避免 Pointer Aliasing,让临时对象的生命周期尽可能的短,降低寄存器使用浪费(循环中的依赖计算)

循环分析寄存器这个得展开讲讲,gcc用-fopt-info-all-optall,clang用-Rpass-missed=.* -Rpass=.* -Rpass-analysis=.* 报告很多很不好读

clang还有先进工具 -fsave-optimization-record + opt-viewer(装个llvm-12-tools)

会生成很漂亮的图

绿色是优化成功,红色是优化失败,要改的也是这里。我说的只是皮毛,这里的细节很复杂,https://johnnysswlab.com/loop-optimizations-interpreting-the-compiler-optimization-report/

需要仔细读一读

思路就是用编译期编出来N个版本,然后挨个FUZZ,重复,比较结果集,有点意思

代码在这里https://github.com/shao-hua-li/compdiff

视频

感兴趣的可以看看

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • C++ 中文周刊 第107期
    • 资讯
      • 文章
        • 视频
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档