Skip to content

Latest commit

 

History

History
215 lines (137 loc) · 6.82 KB

069.md

File metadata and controls

215 lines (137 loc) · 6.82 KB
layout title
post
第69期

C++ 中文周刊 第69期

reddit/hackernews/lobsters/meetingcpp摘抄一些c++动态

周刊项目地址在线地址知乎专栏 |腾讯云+社区

欢迎投稿,推荐或自荐文章/软件/资源等,请提交 issue

2022 07 01


资讯

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

编译器信息最新动态推荐关注hellogcc公众号 本周更新 2022-06-29 第156期

文章

#include <span>
#include <spanstream>
#include <iostream>

int main() {
  char input[] = "1 2 3";
  std::ispanstream is{std::span<char>{input}};
  int i1, i2, i3;
  is >> i1 >> i2 >> i3;
  std::cout << i1 << i2 << i3; // prints 123
}

看不懂有啥用

介绍一些优化经验

介绍用range做轮子

代码走读,挺有意思的

科普了一些基本概念

好像没有很新啊,还是带排队的自选锁

了解一点编译器知识

看不懂了

让枚举更紧凑的语义

#include <iostream>

enum class CarOptions : char {
    isAutomaticFlag = 0b1,
    isElectricFlag = 0b10,
    is4x4Flag = 0b100,
    hasRooftopFlag = 0b100,
    hasGPSFlag = 0b10000,
};

CarOptions operator|(CarOptions lhs, CarOptions rhs) {
    using CarOptionsType = std::underlying_type<CarOptions>::type;
    return CarOptions(static_cast<CarOptionsType>(lhs) | static_cast<CarOptionsType>(rhs));
}

CarOptions operator&(CarOptions lhs, CarOptions rhs) {
    using CarOptionsType = std::underlying_type<CarOptions>::type;
    return CarOptions(static_cast<CarOptionsType>(lhs) & static_cast<CarOptionsType>(rhs));
}

int main() {
    // flag 32: mutually exclusive with 8, has skibox
    CarOptions flags = CarOptions::isElectricFlag | CarOptions::hasRooftopFlag;
    
    std::cout << std::boolalpha;
    std::cout << static_cast<bool>(flags & CarOptions::isAutomaticFlag) << '\n';
    std::cout << static_cast<bool>(flags & CarOptions::isElectricFlag) << '\n';
    std::cout << static_cast<bool>(flags & CarOptions::is4x4Flag) << '\n';
    std::cout << static_cast<bool>(flags & CarOptions::hasRooftopFlag) << '\n';
    std::cout << static_cast<bool>(flags & CarOptions::hasGPSFlag) << '\n';
    
}

还是SWAR方法

uint64_t tolower8(uint64_t octets) {
    uint64_t all_bytes = 0x0101010101010101;
    uint64_t heptets = octets & (0x7F * all_bytes);
    uint64_t is_gt_Z = heptets + (0x7F - 'Z') * all_bytes;
    uint64_t is_ge_A = heptets + (0x80 - 'A') * all_bytes;
    //uint64_t is_ascii = ~octets;
    //uint64_t to_lower = (is_upper >> 2) & (0x20 * all_bytes);
    //return (octets | to_lower);
    uint64_t is_ascii = ~octets & (0x80 * all_bytes);
    uint64_t is_upper = is_ascii & (is_ge_A ^ is_gt_Z);
    return (octets | is_upper >> 2);
}

比默认实现快一倍。我简单压了一下,效果确实是快了一倍 https://quick-bench.com/q/DTrgQdcp2JIXG2UKP1_jQDjooUA

当然如果不考虑费ascii的话可以用更猥琐的

include(FetchContent) # once in the project to include the module

FetchContent_Declare(googletest
                     GIT_REPOSITORY https://github.com/google/googletest.git
                     GIT_TAG        703bd9caab50b139428cea1aaff9974ebee5742e # release-1.10.0)
FetchContent_MakeAvailable(googletest)

# Link against googletest's CMake targets now.

fetchcontent也可以解析zip源码包

lamire常用的gdb

查某段代码的汇编

gdb -q ./benchmark -ex "set pagination off" -ex "set print asm-demangle" -ex "disas 0x000000000001b540" -ex quit > gdbasm.txt

关注生成的指令

 gdb -q ./benchmark -ex "set pagination off" -ex "set print asm-demangle" -ex "disas 0x000000000001b540" -ex quit | awk '{print $3}' | sort |uniq -c | sort -r | head
     32 and
     24 tbl
     24 ext
     18 cmhi
     17 orr
     16 ushr
     16 eor
     14 ldr
     13 mov
     10 movi

视频

用extern template能快点。

开源项目需要人手

  • asteria 一个脚本语言,可嵌入,长期找人,希望胖友们帮帮忙,也可以加群753302367和作者对线

新项目介绍/版本更新

工作招聘

有没有需要看大门的我要被开了


本文永久链接