Skip to content

Instantly share code, notes, and snippets.

@xtqqczze
Created January 22, 2021 23:32
Show Gist options
  • Save xtqqczze/b3a1c299bf0e7562ad2938dc7f036967 to your computer and use it in GitHub Desktop.
Save xtqqczze/b3a1c299bf0e7562ad2938dc7f036967 to your computer and use it in GitHub Desktop.
BenchmarkStringContains.Dissambly
## .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT
```assembly
; Program.ContainsStringLocal()
mov rdx,197EA839518
mov rdx,[rdx]
mov rcx,[rcx+8]
cmp [rcx],ecx
jmp near ptr System.String.Contains(System.String)
; Total bytes of code 24
```
```assembly
; System.String.Contains(System.String)
sub rsp,28
test rdx,rdx
je short M01_L00
cmp [rcx],ecx
mov [rsp+30],rcx
add rcx,0C
mov [rsp+38],rdx
lea r8,[rdx+0C]
mov r9,[rsp+30]
mov edx,[r9+8]
mov r9,[rsp+38]
mov r9d,[r9+8]
call System.SpanHelpers.IndexOf(Char ByRef, Int32, Char ByRef, Int32)
test eax,eax
setge al
movzx eax,al
add rsp,28
ret
M01_L00:
mov ecx,7
call System.ThrowHelper.ThrowArgumentNullException(System.ExceptionArgument)
int 3
; Total bytes of code 76
```
## .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT
```assembly
; Program.ContainsStringField()
mov [rsp+8],rcx
mov rcx,[rcx+8]
mov rdx,[rsp+8]
mov rdx,[rdx+10]
cmp [rcx],ecx
jmp near ptr System.String.Contains(System.String)
; Total bytes of code 25
```
```assembly
; System.String.Contains(System.String)
sub rsp,28
test rdx,rdx
je short M01_L00
cmp [rcx],ecx
mov [rsp+30],rcx
add rcx,0C
mov [rsp+38],rdx
lea r8,[rdx+0C]
mov r9,[rsp+30]
mov edx,[r9+8]
mov r9,[rsp+38]
mov r9d,[r9+8]
call System.SpanHelpers.IndexOf(Char ByRef, Int32, Char ByRef, Int32)
test eax,eax
setge al
movzx eax,al
add rsp,28
ret
M01_L00:
mov ecx,7
call System.ThrowHelper.ThrowArgumentNullException(System.ExceptionArgument)
int 3
; Total bytes of code 76
```
## .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT
```assembly
; Program.ContainsCharLocal()
mov r8,[rcx+8]
lea rcx,[r8+0C]
mov r8d,[r8+8]
mov edx,61
jmp near ptr System.SpanHelpers.Contains(Char ByRef, Char, Int32)
; Total bytes of code 22
```
```assembly
; System.SpanHelpers.Contains(Char ByRef, Char, Int32)
push rax
vzeroupper
xor eax,eax
mov [rsp],rax
mov [rsp],rcx
movsxd rax,r8d
lea r9,[rcx+rax*2]
cmp r8d,10
jl short M01_L01
mov r8d,ecx
and r8d,0F
mov eax,r8d
shr eax,1F
add eax,r8d
sar eax,1
mov r8d,eax
neg r8d
add r8d,8
and r8d,7
cmp r8d,4
jl short M01_L02
M01_L00:
add r8d,0FFFFFFFC
movzx r10d,dx
movzx eax,word ptr [rcx]
cmp r10d,eax
je near ptr M01_L08
movzx eax,word ptr [rcx+2]
cmp r10d,eax
je near ptr M01_L08
movzx eax,word ptr [rcx+4]
cmp r10d,eax
je near ptr M01_L08
movzx eax,word ptr [rcx+6]
cmp r10d,eax
je near ptr M01_L08
add rcx,8
M01_L01:
cmp r8d,4
jge short M01_L00
M01_L02:
test r8d,r8d
jle short M01_L04
movzx r10d,dx
M01_L03:
dec r8d
movzx eax,word ptr [rcx]
cmp r10d,eax
je near ptr M01_L08
add rcx,2
test r8d,r8d
jg short M01_L03
M01_L04:
cmp rcx,r9
jae near ptr M01_L07
mov r8,r9
sub r8,rcx
mov r10,r8
shr r10,3F
add r8,r10
sar r8,1
and r8d,0FFFFFFF8
movzx r10d,dx
imul eax,r10d,10001
vmovd xmm0,eax
vpshufd xmm0,xmm0,0
test r8d,r8d
jle short M01_L06
M01_L05:
vmovupd xmm1,[rcx]
vpcmpeqw xmm1,xmm0,xmm1
vxorps xmm2,xmm2,xmm2
vpcmpeqw xmm1,xmm2,xmm1
vpmovmskb eax,xmm1
cmp eax,0FFFF
jne short M01_L08
add rcx,10
add r8d,0FFFFFFF8
test r8d,r8d
jg short M01_L05
M01_L06:
cmp rcx,r9
jae short M01_L07
mov r8,r9
sub r8,rcx
mov rax,r8
shr rax,3F
add rax,r8
sar rax,1
mov r8d,eax
jmp near ptr M01_L01
M01_L07:
xor eax,eax
add rsp,8
ret
M01_L08:
mov eax,1
add rsp,8
ret
; Total bytes of code 313
```
## .NET Core 5.0.2 (CoreCLR 5.0.220.61120, CoreFX 5.0.220.61120), X64 RyuJIT
```assembly
; Program.ContainsCharField()
mov r8,[rcx+8]
movzx edx,word ptr [rcx+18]
lea rcx,[r8+0C]
mov r8d,[r8+8]
jmp near ptr System.SpanHelpers.Contains(Char ByRef, Char, Int32)
; Total bytes of code 21
```
```assembly
; System.SpanHelpers.Contains(Char ByRef, Char, Int32)
push rax
vzeroupper
xor eax,eax
mov [rsp],rax
mov [rsp],rcx
movsxd rax,r8d
lea r9,[rcx+rax*2]
cmp r8d,10
jl short M01_L01
mov r8d,ecx
and r8d,0F
mov eax,r8d
shr eax,1F
add eax,r8d
sar eax,1
mov r8d,eax
neg r8d
add r8d,8
and r8d,7
cmp r8d,4
jl short M01_L02
M01_L00:
add r8d,0FFFFFFFC
movzx r10d,dx
movzx eax,word ptr [rcx]
cmp r10d,eax
je near ptr M01_L08
movzx eax,word ptr [rcx+2]
cmp r10d,eax
je near ptr M01_L08
movzx eax,word ptr [rcx+4]
cmp r10d,eax
je near ptr M01_L08
movzx eax,word ptr [rcx+6]
cmp r10d,eax
je near ptr M01_L08
add rcx,8
M01_L01:
cmp r8d,4
jge short M01_L00
M01_L02:
test r8d,r8d
jle short M01_L04
movzx r10d,dx
M01_L03:
dec r8d
movzx eax,word ptr [rcx]
cmp r10d,eax
je near ptr M01_L08
add rcx,2
test r8d,r8d
jg short M01_L03
M01_L04:
cmp rcx,r9
jae near ptr M01_L07
mov r8,r9
sub r8,rcx
mov r10,r8
shr r10,3F
add r8,r10
sar r8,1
and r8d,0FFFFFFF8
movzx r10d,dx
imul eax,r10d,10001
vmovd xmm0,eax
vpshufd xmm0,xmm0,0
test r8d,r8d
jle short M01_L06
M01_L05:
vmovupd xmm1,[rcx]
vpcmpeqw xmm1,xmm0,xmm1
vxorps xmm2,xmm2,xmm2
vpcmpeqw xmm1,xmm2,xmm1
vpmovmskb eax,xmm1
cmp eax,0FFFF
jne short M01_L08
add rcx,10
add r8d,0FFFFFFF8
test r8d,r8d
jg short M01_L05
M01_L06:
cmp rcx,r9
jae short M01_L07
mov r8,r9
sub r8,rcx
mov rax,r8
shr rax,3F
add rax,r8
sar rax,1
mov r8d,eax
jmp near ptr M01_L01
M01_L07:
xor eax,eax
add rsp,8
ret
M01_L08:
mov eax,1
add rsp,8
ret
; Total bytes of code 313
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment