`cg_gcc` does not respect -Ctarget-cpu, and uses the host feature set by default.
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia tracciando come cg_gcc gestisce le funzionalità target di Rust e l'opzione -Ctarget-cpu, quindi confronta l'assembly generato per il target predefinito e per x86-64-v1 o nehalem. L'issue è completa quando le build predefinite evitano istruzioni specifiche dell'host non supportate e le CPU target esplicite, inclusa nehalem, vengono riflesse nell'assembly generato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Rust
- Stelle
- 1.2k
- Fork
- 105
- Merge medio
- 6h 28m
- PR unite (30g)
- 14
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rust-lang/rustc_codegen_gcc
-
Re-enable -fno-lto testApertatests
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
rust-lang/rustc_codegen_gcc#993 ·
I maintainer di solito rispondono entro 1 giorno
-
tests
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
rust-lang/rustc_codegen_gcc#992 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
rust-lang/rustc_codegen_gcc#970 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Support `#[no_builtin]`Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
rust-lang/rustc_codegen_gcc#943 ·
I maintainer di solito rispondono entro 1 giorno
-
documentation
Difficoltà 3/5 1-2 giorni Idoneità per principianti 64/100
rust-lang/rustc_codegen_gcc#930 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di rust-lang/rustc_codegen_gcc
Issue simili
-
[Bug]: Web chat input doesn't regain focus after a reply finishesForse già presa @GaijinSystems l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
zeroclaw-labs/zeroclaw#11658 ·
I maintainer di solito rispondono entro 2 giorni
-
good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
bytecodealliance/wasm-tools#2768 ·
I maintainer di solito rispondono entro 1 giorno
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
NuSkooler/enigma-bbs#907 ·
I maintainer di solito rispondono entro 1 giorno