Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Skip Null check and zero length checks of Pointers #541

Closed
Anderman opened this issue Dec 29, 2015 · 11 comments
Closed

Skip Null check and zero length checks of Pointers #541

Anderman opened this issue Dec 29, 2015 · 11 comments
Labels
Milestone

Comments

@Anderman
Copy link
Contributor

pointers to byte arrays are use as
fixed(byte* ptr arr)
the code generated will check if this is an null or zero length array

To skip these tests the statement can be written as
fixed(byte* ptr &arr[0])

see generated code

fixed(byte* ptr arr)

000007FF622857AB  mov         rax,rcx  
000007FF622857AE  test        rax,rax  
000007FF622857B1  je          000007FF622857BA  
000007FF622857B3  mov         ecx,dword ptr [rax+8]  
000007FF622857B6  test        ecx,ecx  
000007FF622857B8  jne         000007FF622857C3  
000007FF622857BA  xor         ecx,ecx  
000007FF622857BC  mov         qword ptr [rsp+20h],rcx  
000007FF622857C1  jmp         000007FF622857D1  
000007FF622857C3  cmp         ecx,0  
000007FF622857C6  jbe         000007FF622857FE  
000007FF622857C8  add         rax,10h  
000007FF622857CC  mov         qword ptr [rsp+20h],rax 

fixed(byte* ptr &arr[0])

000007FF6228582B  cmp         dword ptr [rcx+8],0  
000007FF6228582F  jbe         000007FF62285867  
000007FF62285831  add         rcx,10h  
000007FF62285835  mov         qword ptr [rsp+20h],rcx 
@benaadams
Copy link
Contributor

Interesting :)

@Anderman
Copy link
Contributor Author

This one is also nice to know Optimize generated code for Fixed statement. Looks like a clr or roslyn issue

benaadams added a commit to benaadams/KestrelHttpServer that referenced this issue Dec 29, 2015
benaadams added a commit to benaadams/KestrelHttpServer that referenced this issue Dec 29, 2015
@clrjunkie
Copy link
Contributor

+1

benaadams added a commit to benaadams/KestrelHttpServer that referenced this issue Jan 2, 2016
benaadams added a commit to benaadams/KestrelHttpServer that referenced this issue Jan 5, 2016
@halter73
Copy link
Member

halter73 commented Jan 5, 2016

@Anderman did #542 address all the places where we should use the fixed(byte* ptr &arr[0]) pattern?

@Anderman
Copy link
Contributor Author

Anderman commented Jan 5, 2016

Yes, all that I could find. I skipped 1 or 2 because they didn't have much impact.

@Anderman
Copy link
Contributor Author

Anderman commented Jan 5, 2016

@halter73 I think @benaadams did already change some in his PR

@halter73
Copy link
Member

halter73 commented Jan 5, 2016

I also noticed @benaadams used the same pattern in at least one of his PRs.

Thanks! Just wanted to double check before closing.

@halter73 halter73 added this to the 1.0.0-rc2 milestone Jan 5, 2016
@halter73 halter73 closed this as completed Jan 5, 2016
@benaadams
Copy link
Contributor

I also noticed @benaadams used the same pattern in at least one of his PRs.

@Anderman is making me up my game :)

@Anderman
Copy link
Contributor Author

Anderman commented Jan 5, 2016

Ha, Thx there still is many things that can be improved

@halter73
Copy link
Member

halter73 commented Jan 6, 2016

@Anderman No doubt there are many more things that can be improved, but we've decided we are going to lock down stop accepting new perf related PRs prior to our 1.0 release. This is meant to give us more time to focus on other things like stability and security.

@clrjunkie
Copy link
Contributor

@halter73
👍

rameel added a commit to rsdn/CodeJam that referenced this issue Nov 3, 2016
* Faster unsafe pointers
* Moved return statements inside fixed scope

See: aspnet/KestrelHttpServer#541
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants