MCPcopy Create free account
hub / github.com/google/gapid / hash64Bit

Method hash64Bit

gapil/compiler/map.go:150–172  ·  view source on GitHub ↗

If we know the values are going to be small & sequential, we can swap out this hash.

(s *S, value *codegen.Value)

Source from the content-addressed store, hash-verified

148// If we know the values are going to be small & sequential, we can
149// swap out this hash.
150func (c *C) hash64Bit(s *S, value *codegen.Value) *codegen.Value {
151 rotateRight := func(value *codegen.Value, bits int) *codegen.Value {
152 v := s.ShiftRight(value, s.Scalar(uint64(bits)))
153 v = s.ShiftLeft(value, s.Scalar(uint64(64-bits)))
154 v = s.Or(v, v)
155 return v.SetName(">>>")
156 }
157
158 shiftLeft := func(value *codegen.Value, bits int) *codegen.Value {
159 return s.ShiftLeft(value, s.Scalar(uint64(bits)))
160 }
161
162 v := value
163 v = s.Invert(v).SetName("_hash1")
164 v = s.Add(v, shiftLeft(v, 21)).SetName("_hash2")
165 v = s.Xor(v, rotateRight(v, 24)).SetName("_hash3")
166 v = s.Add(s.Add(v, shiftLeft(v, 3)), shiftLeft(v, 8)).SetName("_hash4")
167 v = s.Xor(v, rotateRight(v, 14)).SetName("_hash5")
168 v = s.Add(s.Add(v, shiftLeft(v, 2)), shiftLeft(v, 4)).SetName("_hash6")
169 v = s.Xor(v, rotateRight(v, 28)).SetName("_hash7")
170 v = s.Add(v, shiftLeft(v, 31)).SetName("_hash8")
171 return v
172}
173
174func (c *C) hashVariableValue(s *S, pointer *codegen.Value, numBytes *codegen.Value) *codegen.Value {
175 u64Type := c.T.Target(semantic.Uint64Type)

Callers 1

hashValueMethod · 0.95

Calls 8

ShiftRightMethod · 0.80
ShiftLeftMethod · 0.80
SetNameMethod · 0.80
InvertMethod · 0.80
XorMethod · 0.80
AddMethod · 0.65
ScalarMethod · 0.45
OrMethod · 0.45

Tested by

no test coverage detected