Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missed optimization on fixed-size bytes comparison #69024

Open
ordian opened this issue Feb 10, 2020 · 0 comments
Open

Missed optimization on fixed-size bytes comparison #69024

ordian opened this issue Feb 10, 2020 · 0 comments
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. C-optimization Category: An issue highlighting optimization opportunities or PRs implementing such I-slow Issue: Problems and improvements with respect to performance of generated code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ordian
Copy link

ordian commented Feb 10, 2020

https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=99eabb4a672da50556a9eb7d4f4016e9

cc #62531

The generated assembly calles into memcmp, but still is slower.

playground::H256::eq_libc:
	movdqu	(%rdi), %xmm0
	movdqu	16(%rdi), %xmm1
	movdqu	(%rsi), %xmm2
	pcmpeqb	%xmm0, %xmm2
	movdqu	16(%rsi), %xmm0
	pcmpeqb	%xmm1, %xmm0
	pand	%xmm2, %xmm0
	pmovmskb	%xmm0, %eax
	cmpl	$65535, %eax
	sete	%al
	retq

playground::H256::eq_derived:
	cmpq	%rsi, %rdi
	je	.LBB1_1
	movdqu	(%rdi), %xmm0
	movdqu	16(%rdi), %xmm1
	movdqu	(%rsi), %xmm2
	pcmpeqb	%xmm0, %xmm2
	movdqu	16(%rsi), %xmm0
	pcmpeqb	%xmm1, %xmm0
	pand	%xmm2, %xmm0
	pmovmskb	%xmm0, %eax
	cmpl	$65535, %eax
	sete	%al
	retq

.LBB1_1:
	movb	$1, %al
	retq

playground::H256::cmp_libc:
	pushq	%rax
	movl	$32, %edx
	callq	*memcmp@GOTPCREL(%rip)
	xorl	%ecx, %ecx
	testl	%eax, %eax
	setne	%cl
	movl	$255, %eax
	cmovnsl	%ecx, %eax
	popq	%rcx
	retq

playground::H256::cmp_derived:
	pushq	%rax
	movl	$32, %edx
	callq	*memcmp@GOTPCREL(%rip)
	testl	%eax, %eax
	setns	%cl
	addb	%cl, %cl
	addb	$-1, %cl
	testl	%eax, %eax
	movzbl	%cl, %ecx
	cmovnel	%ecx, %eax
	popq	%rcx
	retq
@jonas-schievink jonas-schievink added C-enhancement Category: An issue proposing an enhancement or a PR with one. I-slow Issue: Problems and improvements with respect to performance of generated code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 10, 2020
@workingjubilee workingjubilee added the C-optimization Category: An issue highlighting optimization opportunities or PRs implementing such label Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. C-optimization Category: An issue highlighting optimization opportunities or PRs implementing such I-slow Issue: Problems and improvements with respect to performance of generated code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants