-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
cmd/compile: use mapaccess1_fast64 for small keys #66446
Comments
\cc @randall77, maybe related to #66413? |
Not directly related, no. We're pretty careful about not including data in padding as part of equality (and thus hash). I don't know if anyone really takes advantage of that, but I'm not sure we would want to change that at this point. That assumption is probably baked in in a few places (e.g. code that initializes stack variables might not zero those fields currently).
It does for me. Even with bools. Only padding causes problems. Could you double-check and post a repro if you have one? |
Ah, your right. I was testing with: type key struct {
a uint8
b uint16
c uint32
d uint8
} While that adds up to 64-bits, I had forgotten about alignment. |
Since mapaccess1_fast64 passes the key by register, and we know where the padding holes are in the type even when shaping is applied, so we could always just load the value and zero any padding bytes with a mask before calling into the runtime. |
Sure, that's a good idea. |
One complication: mapacess1_fast64 uses uint64 |
Go version
go1.22
Output of
go env
in your module/workspace:What did you do?
Compile the following program:
What did you see happen?
The compiler output:
What did you expect to see?
runtime.mapaccess1_fast64
being used on both since thekey
type is smaller than a uint64.That said, there is some complications. For example, through
unsafe
, someone could writes values to the padding in-between thebool
field and theuint32
. Also, someone usingunsafe
could write a bit pattern to the bool that isn't 0 or 1.It isn't clear to me that this is something that someone can rely on.
However, even if we make the
key
struct exactly 64-bits wide with no padding and no bools, it still doesn't useruntime.mapaccess1_fast64
.The text was updated successfully, but these errors were encountered: