This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -52,7 +52,14 @@ unsafe impl<T> IsZero for *mut T {
5252unsafe impl < T : IsZero , const N : usize > IsZero for [ T ; N ] {
5353 #[ inline]
5454 fn is_zero ( & self ) -> bool {
55- self . iter ( ) . all ( IsZero :: is_zero)
55+ // Because this is generated as a runtime check, it's not obvious that
56+ // it's worth doing if the array is really long. The threshold here
57+ // is largely arbitrary, but was picked because as of 2022-05-01 LLVM
58+ // can const-fold the check in `vec![[0; 32]; n]` but not in
59+ // `vec![[0; 64]; n]`: https://godbolt.org/z/WTzjzfs5b
60+ // Feel free to tweak if you have better evidence.
61+
62+ N <= 32 && self . iter ( ) . all ( IsZero :: is_zero)
5663 }
5764}
5865
Original file line number Diff line number Diff line change 1+ // compile-flags: -O
2+ // only-x86_64
3+ // ignore-debug
4+
5+ #![ crate_type = "lib" ]
6+
7+ // CHECK-LABEL: @vec_zero_scalar
8+ #[ no_mangle]
9+ pub fn vec_zero_scalar ( n : usize ) -> Vec < i32 > {
10+ // CHECK-NOT: __rust_alloc(
11+ // CHECK: __rust_alloc_zeroed(
12+ // CHECK-NOT: __rust_alloc(
13+ vec ! [ 0 ; n]
14+ }
15+
16+ // CHECK-LABEL: @vec_zero_rgb48
17+ #[ no_mangle]
18+ pub fn vec_zero_rgb48 ( n : usize ) -> Vec < [ u16 ; 3 ] > {
19+ // CHECK-NOT: __rust_alloc(
20+ // CHECK: __rust_alloc_zeroed(
21+ // CHECK-NOT: __rust_alloc(
22+ vec ! [ [ 0 , 0 , 0 ] ; n]
23+ }
24+
25+ // CHECK-LABEL: @vec_zero_array_32
26+ #[ no_mangle]
27+ pub fn vec_zero_array_32 ( n : usize ) -> Vec < [ i64 ; 32 ] > {
28+ // CHECK-NOT: __rust_alloc(
29+ // CHECK: __rust_alloc_zeroed(
30+ // CHECK-NOT: __rust_alloc(
31+ vec ! [ [ 0_i64 ; 32 ] ; n]
32+ }
You can’t perform that action at this time.
0 commit comments