github.com/gramework/runtimer@v0.0.0-20211014201118-d25b6e2ccefd/alg.go (about) 1 // Copyright 2014 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package runtimer 6 7 import "unsafe" // #nosec 8 9 const ( 10 C0 = uintptr((8-PtrSize)/4*2860486313 + (PtrSize-4)/4*33054211828000289) 11 C1 = uintptr((8-PtrSize)/4*3267000013 + (PtrSize-4)/4*23344194077549503) 12 ) 13 14 // type algorithms - known to compiler 15 const ( 16 AlgNOEQ = iota 17 AlgMEM0 18 AlgMEM8 19 AlgMEM16 20 AlgMEM32 21 AlgMEM64 22 AlgMEM128 23 AlgSTRING 24 AlgINTER 25 AlgNILINTER 26 AlgFLOAT32 27 AlgFLOAT64 28 AlgCPLX64 29 AlgCPLX128 30 AlgMax 31 ) 32 33 // TypeAlg is also copied/used in reflect/type.go. 34 // keep them in sync. 35 type TypeAlg struct { 36 // function for hashing objects of this type 37 // (ptr to object, seed) -> hash 38 Hash func(unsafe.Pointer, uintptr) uintptr 39 // function for comparing objects of this type 40 // (ptr to object A, ptr to object B) -> ==? 41 Equal func(unsafe.Pointer, unsafe.Pointer) bool 42 } 43 44 func Memhash0(p unsafe.Pointer, h uintptr) uintptr { 45 return memhash0(p, h) 46 } 47 48 //go:linkname memhash0 runtime.memhash0 49 func memhash0(p unsafe.Pointer, h uintptr) uintptr 50 51 func Memhash8(p unsafe.Pointer, h uintptr) uintptr { 52 return memhash8(p, h) 53 } 54 55 func Memhash16(p unsafe.Pointer, h uintptr) uintptr { 56 return memhash16(p, h) 57 } 58 59 func Memhash32(p unsafe.Pointer, h uintptr) uintptr { 60 return memhash32(p, h) 61 } 62 63 func Memhash64(p unsafe.Pointer, h uintptr) uintptr { 64 return memhash64(p, h) 65 } 66 67 //go:linkname memhash8 runtime.memhash8 68 func memhash8(p unsafe.Pointer, h uintptr) uintptr 69 70 //go:linkname memhash16 runtime.memhash16 71 func memhash16(p unsafe.Pointer, h uintptr) uintptr 72 73 //go:linkname memhash32 runtime.memhash32 74 func memhash32(p unsafe.Pointer, h uintptr) uintptr 75 76 //go:linkname memhash64 runtime.memhash64 77 func memhash64(p unsafe.Pointer, h uintptr) uintptr 78 79 func Memhash128(p unsafe.Pointer, h uintptr) uintptr { 80 return memhash128(p, h) 81 } 82 83 //go:linkname memhash128 runtime.memhash128 84 func memhash128(p unsafe.Pointer, h uintptr) uintptr 85 86 // MemhashVarlen is defined in runtime assembly because it needs access 87 // to the closure. It appears here to provide an argument 88 // signature for the assembly routine. 89 func MemhashVarlen(p unsafe.Pointer, h uintptr) uintptr { 90 return memhashVarlen(p, h) 91 } 92 93 //go:linkname memhashVarlen runtime.memhash_varlen 94 func memhashVarlen(p unsafe.Pointer, h uintptr) uintptr 95 96 var AlgArray = [AlgMax]TypeAlg{ 97 AlgNOEQ: {nil, nil}, 98 AlgMEM0: {Memhash0, Memequal0}, 99 AlgMEM8: {Memhash8, Memequal8}, 100 AlgMEM16: {Memhash16, Memequal16}, 101 AlgMEM32: {Memhash32, Memequal32}, 102 AlgMEM64: {Memhash64, Memequal64}, 103 AlgMEM128: {Memhash128, Memequal128}, 104 AlgSTRING: {Strhash, Strequal}, 105 AlgINTER: {Interhash, Interequal}, 106 AlgNILINTER: {Nilinterhash, Nilinterequal}, 107 AlgFLOAT32: {F32hash, F32equal}, 108 AlgFLOAT64: {F64hash, F64equal}, 109 AlgCPLX64: {C64hash, C64equal}, 110 AlgCPLX128: {C128hash, C128equal}, 111 } 112 113 func Aeshash(p unsafe.Pointer, h, s uintptr) uintptr { 114 return aeshash(p, h, s) 115 } 116 117 //go:linkname aeshash runtime.aeshash 118 func aeshash(p unsafe.Pointer, h, s uintptr) uintptr 119 120 func Aeshash32(p unsafe.Pointer, h uintptr) uintptr { 121 return aeshash32(p, h) 122 } 123 124 //go:linkname aeshash32 runtime.aeshash32 125 func aeshash32(p unsafe.Pointer, h uintptr) uintptr 126 127 func Aeshash64(p unsafe.Pointer, h uintptr) uintptr { 128 return aeshash64(p, h) 129 } 130 131 //go:linkname aeshash64 runtime.aeshash64 132 func aeshash64(p unsafe.Pointer, h uintptr) uintptr 133 134 func Aeshashstr(p unsafe.Pointer, h uintptr) uintptr { 135 return aeshashstr(p, h) 136 } 137 138 //go:linkname aeshashstr runtime.aeshashstr 139 func aeshashstr(p unsafe.Pointer, h uintptr) uintptr 140 141 func Strhash(p unsafe.Pointer, h uintptr) uintptr { 142 return strhash(p, h) 143 } 144 145 //go:linkname strhash runtime.strhash 146 func strhash(a unsafe.Pointer, h uintptr) uintptr 147 148 func F32hash(p unsafe.Pointer, h uintptr) uintptr { 149 return f32hash(p, h) 150 } 151 152 //go:linkname f32hash runtime.f32hash 153 func f32hash(p unsafe.Pointer, h uintptr) uintptr 154 155 func F64hash(p unsafe.Pointer, h uintptr) uintptr { 156 return f64hash(p, h) 157 } 158 159 //go:linkname f64hash runtime.f64hash 160 func f64hash(p unsafe.Pointer, h uintptr) uintptr 161 162 func C64hash(p unsafe.Pointer, h uintptr) uintptr { 163 return c64hash(p, h) 164 } 165 166 //go:linkname c64hash runtime.c64hash 167 func c64hash(p unsafe.Pointer, h uintptr) uintptr 168 169 func C128hash(p unsafe.Pointer, h uintptr) uintptr { 170 return c128hash(p, h) 171 } 172 173 //go:linkname c128hash runtime.c128hash 174 func c128hash(p unsafe.Pointer, h uintptr) uintptr 175 176 func Interhash(p unsafe.Pointer, h uintptr) uintptr { 177 return interhash(p, h) 178 } 179 180 //go:linkname interhash runtime.interhash 181 func interhash(p unsafe.Pointer, h uintptr) uintptr 182 183 func Nilinterhash(p unsafe.Pointer, h uintptr) uintptr { 184 return nilinterhash(p, h) 185 } 186 187 //go:linkname nilinterhash runtime.nilinterhash 188 func nilinterhash(p unsafe.Pointer, h uintptr) uintptr 189 190 func Memequal(a, b unsafe.Pointer, size uintptr) bool { 191 return memequal(a, b, size) 192 } 193 194 //go:linkname memequal runtime.memequal 195 func memequal(a, b unsafe.Pointer, size uintptr) bool 196 197 func Memequal0(p, q unsafe.Pointer) bool { 198 return memequal0(p, q) 199 } 200 201 //go:linkname memequal0 runtime.memequal0 202 func memequal0(p, q unsafe.Pointer) bool 203 204 func Memequal8(p, q unsafe.Pointer) bool { 205 return memequal8(p, q) 206 } 207 208 //go:linkname memequal8 runtime.memequal8 209 func memequal8(p, q unsafe.Pointer) bool 210 211 func Memequal16(p, q unsafe.Pointer) bool { 212 return memequal16(p, q) 213 } 214 215 //go:linkname memequal18 runtime.memequal18 216 func memequal16(p, q unsafe.Pointer) bool 217 218 func Memequal32(p, q unsafe.Pointer) bool { 219 return memequal32(p, q) 220 } 221 222 //go:linkname memequal32 runtime.memequal32 223 func memequal32(p, q unsafe.Pointer) bool 224 225 func Memequal64(p, q unsafe.Pointer) bool { 226 return memequal64(p, q) 227 } 228 229 //go:linkname memequal64 runtime.memequal64 230 func memequal64(p, q unsafe.Pointer) bool 231 232 func Memequal128(p, q unsafe.Pointer) bool { 233 return memequal128(p, q) 234 } 235 236 //go:linkname memequal128 runtime.memequal128 237 func memequal128(p, q unsafe.Pointer) bool 238 239 func F32equal(p, q unsafe.Pointer) bool { 240 return f32equal(p, q) 241 } 242 243 //go:linkname f32equal runtime.f32equal 244 func f32equal(p, q unsafe.Pointer) bool 245 246 func F64equal(p, q unsafe.Pointer) bool { 247 return f64equal(p, q) 248 } 249 250 //go:linkname f64equal runtime.f64equal 251 func f64equal(p, q unsafe.Pointer) bool 252 253 func C64equal(p, q unsafe.Pointer) bool { 254 return c64equal(p, q) 255 } 256 257 //go:linkname c64equal runtime.c64equal 258 func c64equal(p, q unsafe.Pointer) bool 259 260 func C128equal(p, q unsafe.Pointer) bool { 261 return c128equal(p, q) 262 } 263 264 //go:linkname c128equal runtime.c128equal 265 func c128equal(p, q unsafe.Pointer) bool 266 267 func Strequal(p, q unsafe.Pointer) bool { 268 return strequal(p, q) 269 } 270 271 //go:linkname strequal runtime.strequal 272 func strequal(p, q unsafe.Pointer) bool 273 274 func Interequal(p, q unsafe.Pointer) bool { 275 return interequal(p, q) 276 } 277 278 //go:linkname interequal runtime.interequal 279 func interequal(p, q unsafe.Pointer) bool 280 281 func Nilinterequal(p, q unsafe.Pointer) bool { 282 return nilinterequal(p, q) 283 } 284 285 //go:linkname nilinterequal runtime.nilinterequal 286 func nilinterequal(p, q unsafe.Pointer) bool 287 288 func Efaceeq(t *Type, x, y unsafe.Pointer) bool { 289 return efaceeq(t, x, y) 290 } 291 292 //go:linkname efaceeq runtime.efaceeq 293 func efaceeq(t *Type, x, y unsafe.Pointer) bool 294 295 func Ifaceeq(t *Itab, x, y unsafe.Pointer) bool { 296 return ifaceeq(t, x, y) 297 } 298 299 //go:linkname ifaceeq runtime.ifaceeq 300 func ifaceeq(tab *Itab, x, y unsafe.Pointer) bool 301 302 func StringHash(s string, seed uintptr) uintptr { 303 return stringHash(s, seed) 304 } 305 306 // Testing adapters for hash quality tests (see hash_test.go) 307 //go:linkname stringHash runtime.stringHash 308 func stringHash(s string, seed uintptr) uintptr 309 310 func BytesHash(b []byte, seed uintptr) uintptr { 311 return bytesHash(b, seed) 312 } 313 314 //go:linkname bytesHash runtime.bytesHash 315 func bytesHash(b []byte, seed uintptr) uintptr 316 317 func Int32Hash(i uint32, seed uintptr) uintptr { 318 return int32Hash(i, seed) 319 } 320 321 //go:linkname int32Hash runtime.int32Hash 322 func int32Hash(i uint32, seed uintptr) uintptr 323 324 func Int64Hash(i uint64, seed uintptr) uintptr { 325 return int64Hash(i, seed) 326 } 327 328 //go:linkname int64Hash runtime.int64Hash 329 func int64Hash(i uint64, seed uintptr) uintptr 330 331 func EfaceHash(i interface{}, seed uintptr) uintptr { 332 return efaceHash(i, seed) 333 } 334 335 //go:linkname efaceHash runtime.efaceHash 336 func efaceHash(i interface{}, seed uintptr) uintptr 337 338 func IfaceHash(i interface { 339 F() 340 }, seed uintptr) uintptr { 341 return ifaceHash(i, seed) 342 } 343 344 //go:linkname ifaceHash runtime.ifaceHash 345 func ifaceHash(i interface { 346 F() 347 }, seed uintptr) uintptr 348 349 const HashRandomBytes = PtrSize / 4 * 64 350 351 //go:linkname CPUIDECX runtime.cpuid_ecx 352 var CPUIDECX uint32