`cg_gcc` does not respect -Ctarget-cpu, and uses the host feature set by default.
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu bằng cách theo dõi cách cg_gcc xử lý các tính năng target của Rust và tùy chọn -Ctarget-cpu, sau đó so sánh assembly được tạo ra cho target mặc định và cho x86-64-v1 hoặc nehalem. Issue được hoàn thành khi các bản build mặc định tránh các instruction dành riêng cho host nhưng không được hỗ trợ, và các CPU target rõ ràng, bao gồm nehalem, được phản ánh trong assembly được tạo ra.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Rust
- Star
- 1.2k
- Fork
- 105
- Merge trung bình
- 6 giờ 30 phút
- Pull request đã merge (30 ngày)
- 22
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rust-lang/rustc_codegen_gcc
-
Re-enable -fno-lto testĐang mởtests
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
rust-lang/rustc_codegen_gcc#993 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Enable librsvg tests on Aarch64Đang mởtests
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
rust-lang/rustc_codegen_gcc#992 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
rust-lang/rustc_codegen_gcc#970 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Support `#[no_builtin]`Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
rust-lang/rustc_codegen_gcc#943 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 64/100
rust-lang/rustc_codegen_gcc#930 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của rust-lang/rustc_codegen_gcc
Issue tương tự
-
Bump anybuf version to ^1.0.0Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
wormhole-foundation/wormhole#5062 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
RUSTSEC-2026-0348: Brotli certificate decompression can allocate up to 1 GiB before authenticationĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 60/100
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 62/100
-
core: Amount::from_str panics on values above 21M BTC instead of returning an errorCó thể đã có người làm @bhuvan-somisetty đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
crate: spate-s3
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày