If we know the values are going to be small & sequential, we can swap out this hash.
(s *S, value *codegen.Value)
| 148 | // If we know the values are going to be small & sequential, we can |
| 149 | // swap out this hash. |
| 150 | func (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 | |
| 174 | func (c *C) hashVariableValue(s *S, pointer *codegen.Value, numBytes *codegen.Value) *codegen.Value { |
| 175 | u64Type := c.T.Target(semantic.Uint64Type) |