`cg_gcc` does not respect -Ctarget-cpu, and uses the host feature set by default.
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
首先追踪 cg_gcc 如何处理 Rust 目标特性和 -Ctarget-cpu 选项,然后比较默认目标与 x86-64-v1 或 nehalem 的生成汇编。默认构建避免使用不受支持的特定于主机的指令,并且包括 nehalem 在内的显式目标 CPU 反映在生成的汇编中后,该 issue 即完成。
由索引模型根据 Issue 内容生成。
描述
By default, the Rust compiler uses the x86-64-v1 feature level, which does not include the AVX instructions.
cg_gcc, however, creates assembly files containing those instructions.
use std::hint::black_box;
#[unsafe(no_mangle)]
fn reverse_u8() {
// odd length and offset by 1 to be as unaligned as possible
let mut v: Vec<_> = (0..1 + (0xFFFFF / size_of::<u8>() as u64))
.map(|x| x as u8)
.collect();
black_box( black_box(&mut v[1..]).reverse());
}
As you can see(by analysing the assembly created by GCC and LLVM), GCC uses AVX instructions, while LLVM does not.
; Sample of GCC code
mov r11d, 4
vpunpcklqdq xmm9, xmm6, xmm6
vmovdqa xmm14, XMMWORD PTR .LC8[rip]
vpunpcklqdq xmm5, xmm5, xmm5
vmovq xmm6, rsi
sal rdi, 4
lea rax, -16[r9+rsi]
vmovdqa XMMWORD PTR 80[rsp], xmm5
vmovq xmm5, r11
mov r11d, 6
vpunpcklqdq xmm6, xmm6, xmm6
vpunpcklqdq xmm5, xmm5, xmm5
mov r10, rax
vmovdqa XMMWORD PTR 64[rsp], xmm6
vmovdqa xmm15, XMMWORD PTR .LC0[rip]
vmovdqa XMMWORD PTR 96[rsp], xmm5
; Sample of LLVM code
movdqa xmm0, xmmword ptr [rip + .LCPI0_0]
mov ecx, 112
movdqa xmm1, xmmword ptr [rip + .LCPI0_1]
movdqa xmm2, xmmword ptr [rip + .LCPI0_2]
movdqa xmm3, xmmword ptr [rip + .LCPI0_3]
movdqa xmm4, xmmword ptr [rip + .LCPI0_4]
movdqa xmm5, xmmword ptr [rip + .LCPI0_5]
movdqa xmm6, xmmword ptr [rip + .LCPI0_6]
movdqa xmm7, xmmword ptr [rip + .LCPI0_7]
movdqa xmm8, xmmword ptr [rip + .LCPI0_8]
LLVM-based rustc will only emit AVX instructions when they are explicitly enabled(-Ctarget-cpu=x86-64-v3).
; LLVM code compiled with AVX enabled
je .LBB0_18
mov ecx, 480
vmovdqa ymm0, ymmword ptr [rip + .LCPI0_0]
vmovdqa ymm1, ymmword ptr [rip + .LCPI0_1]
vmovdqa ymm2, ymmword ptr [rip + .LCPI0_2]
vmovdqa ymm3, ymmword ptr [rip + .LCPI0_3]
vmovdqa ymm4, ymmword ptr [rip + .LCPI0_4]
vmovaps ymm5, ymmword ptr [rip + .LCPI0_5]
vmovaps ymm6, ymmword ptr [rip + .LCPI0_6]
vmovaps ymm7, ymmword ptr [rip + .LCPI0_7]
cg_gcc should mimic this behaviour. Currently, it seems like cg_gcc just inherits the target features of the host processor, which is inccorect(a processor with AVX should still build code that does not depend on AVX).
Moreover, -Ctarget-cpu seems to be currently not respected.
Despite explicitly setting -Ctarget-cpu=nehalem, I can see that cg_gcc still uses AVX instructions. That CPU does not support them.
https://godbolt.org/z/7s6Gss8bE
This will lead code compiled by cg_gcc to crash on CPUs older than the build host.
- 主要语言
- Rust
- 星标
- 1.2k
- 派生
- 106
- 平均合并
- 5 小时 50 分钟
- 30 天内合并 PR
- 25
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rust-lang/rustc_codegen_gcc 的其他 Issue
-
tests
难度 2/5 1-3 小时 新手友好度 62/100
rust-lang/rustc_codegen_gcc#993 ·
维护者通常 1 天内回复
-
Cannot compile sysroot if having a build.build-dir cargo config可能已有人在做 @GuillaumeGomez 今天认领。 未关闭
rust-lang/rustc_codegen_gcc#1011 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
tests
难度 4/5 3-5 天 新手友好度 30/100
rust-lang/rustc_codegen_gcc#992 ·
维护者通常 1 天内回复
-
bug
难度 5/5 一周以上 新手友好度 35/100
rust-lang/rustc_codegen_gcc#970 · 5 条评论 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 20/100
rust-lang/rustc_codegen_gcc#943 ·
维护者通常 1 天内回复
查看 rust-lang/rustc_codegen_gcc 的全部 Issue
相似的 Issue
-
proxy: include denial_category in the "proxy request denied" log line可能已有人在做 @sreyas-endor 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 77/100
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 68/100
metasequoiaime/msime#9113 ·
维护者通常 1 天内回复
-
area:desktop priority:p2 type:chore
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
area: supply-chain
难度 1/5 1 小时以内 新手友好度 73/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 67/100