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
runtime: decide what type len and cap params should have in runtime calls #15357
Comments
Code is permitted to pass a In gccgo I have two different functions, one that takes |
Good point. gc doesn't do this today. I'll do some instrumenting and find out how often we'd need to do a double-hop and what the benefit would actually be. |
I would guess the speed improvement is the same for all currently supported 32 bit systems whether it is int or uintptr. In makeslice and growslice uintptr is already used for e.g. lenmem, capmem, maxcap,... . Also the code already casts (new|old)(len|cap) to uintptr in a few places and newarray also takes a uintptr. Int would have the benefit that the slice header uses int for cap and len and that are likely to be the most used argument types. In any case we need to either check cap < 0 for int or cap > maxint for uintptr. I would be in favor to use uintptr. |
Having had a look a bit more int would indeed seem better fitting as josharian suggested. We already check len < 0 in makeslice so passing in a uint/uintptr instead of int that is to large should be caught already. As for uint64/int64 there needs to be a wrapper on 32bit platforms as ianlancetaylor pointed out. |
Rather than a wrapper, I think we should just add a check to the generated code. Before calling makeslice, on 32 bits systems: (1) check whether the arguments are constants that are too large, in which case fail at compile time, (2) check whether the arguments have int64 type, and if so, insert |
@josharian thanks. |
Great. Don't hesitate to ask (here or privately over email) if you have questions or want help. The compiler is much easier to work on now that it is in Go and has seen a lot of cleanup, but there's definitely still a learning curve. |
CL https://golang.org/cl/27851 mentions this issue. |
We have three candidates, according to the current code:
uintptr
,int64
, andint
. It seems to me that they should have type int, which would be an improvement for 32 bit systems. @randall77 ?The text was updated successfully, but these errors were encountered: