为什么这 8 个字节写入没有优化为 MOV
Why are these 8 byte-writes not optimized into a MOV?
我和我的同事没有成功地解释为什么GCC,ICC和Clang没有优化这个功能
void f(std::uint64_t a, void * p) {
std::uint8_t *x = reinterpret_cast<std::uint8_t *>(p);
x[7] = a >> 56;
x[6] = a >> 48;
x[5] = a >> 40;
x[4] = a >> 32;
x[3] = a >> 24;
x[2] = a >> 16;
x[1] = a >> 8;
x[0] = a;
}
进入这个
mov QWORD PTR [rsi], rdi
如果我们用memcpy
来表述f
,它只发出那个mov
。如果我们执行看似微不足道的字节写入序列,为什么不会发生这种情况?
我不是专家,但 gcc 只获得了在 gcc 7 中合并相邻存储以获得即时常量的能力:
- 立即常量的已关闭错误:https://gcc.gnu.org/bugzilla/show_bug.cgi?id=23684
- 打开用于分配小结构的错误:https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78821
- 商店合并密码:https://github.com/gcc-mirror/gcc/blob/master/gcc/gimple-ssa-store-merging.c
如果我不得不猜测,到第二个错误时,等待可能不会太久。
相关文章:
- 空基优化子对象的地址
- 关闭||运算符优化
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- 返回值优化:显式移动还是隐式
- 人脸跟踪arduino代码的优化
- 使用仅使用一次的变量调用的复制构造函数.这可能是通过调用move构造函数进行编译器优化的情况吗
- C++如何仅使用MOV在x86上实现发布和获取
- 纯函数,为什么没有优化
- 为什么大多数 pair 实现默认不使用压缩(空基优化)?
- 如何以优化的方式同时迭代两个间距不相等的数组
- 小字符串优化(调试与发布模式)
- 浮点定向舍入和优化
- Visual Studio 调试优化如何工作?
- 为什么开关的优化方式与 c/c++ 中的链接不同?
- 线性优化目标函数中的绝对值
- GCC 会优化内联访问器吗?
- gcc 如何优化此循环?
- 如何使用libav编写.mov文件,如果文件未正确完成,则可以播放
- 如何防止 CUDA-GDB 中的<优化输出>值
- 为什么我的程序在 O0 和 O2 的优化级别返回不同的结果