-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #115515 - the8472:zip-for-arrays, r=scottmcm
optimize zipping over array iterators Fixes #115339 (somewhat) the new assembly: ```asm zip_arrays: .cfi_startproc vmovups (%rdx), %ymm0 leaq 32(%rsi), %rcx vxorps %xmm1, %xmm1, %xmm1 vmovups %xmm1, -24(%rsp) movq $0, -8(%rsp) movq %rsi, -88(%rsp) movq %rdi, %rax movq %rcx, -80(%rsp) vmovups %ymm0, -72(%rsp) movq $0, -40(%rsp) movq $32, -32(%rsp) movq -24(%rsp), %rcx vmovups (%rsi,%rcx), %ymm0 vorps -72(%rsp,%rcx), %ymm0, %ymm0 vmovups %ymm0, (%rsi,%rcx) vmovups (%rsi), %ymm0 vmovups %ymm0, (%rdi) vzeroupper retq ``` This is still longer than the slice version given in the issue but at least it eliminates the terrible `vpextrb`/`orb` chain. I guess this is due to excessive memcpys again (haven't looked at the llvmir)? The `TrustedLen` specialization is a drive-by change since I had to do something for the default impl anyway to be able to specialize the `TrustedRandomAccessNoCoerce` impl.
- Loading branch information
Showing
4 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// assembly-output: emit-asm | ||
// # zen3 previously exhibited odd vectorization | ||
// compile-flags: --crate-type=lib -Ctarget-cpu=znver3 -O | ||
// only-x86_64 | ||
// ignore-sgx | ||
|
||
use std::iter; | ||
|
||
// previously this produced a long chain of | ||
// 56: vpextrb $6, %xmm0, %ecx | ||
// 57: orb %cl, 22(%rsi) | ||
// 58: vpextrb $7, %xmm0, %ecx | ||
// 59: orb %cl, 23(%rsi) | ||
// [...] | ||
|
||
// CHECK-LABEL: zip_arrays: | ||
#[no_mangle] | ||
pub fn zip_arrays(mut a: [u8; 32], b: [u8; 32]) -> [u8; 32] { | ||
// CHECK-NOT: vpextrb | ||
// CHECK-NOT: orb %cl | ||
// CHECK: vorps | ||
iter::zip(&mut a, b).for_each(|(a, b)| *a |= b); | ||
// CHECK: retq | ||
a | ||
} |