From 0504e4a201fe8935310563fb7449b4744f4adf6b Mon Sep 17 00:00:00 2001 From: Damian Gryski Date: Tue, 10 Jan 2023 20:46:54 -0800 Subject: compiler,runtime: make keySize and valueSize uintptr --- compiler/map.go | 4 +-- src/runtime/hashmap.go | 76 +++++++++++++++++++++++++------------------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/compiler/map.go b/compiler/map.go index e70c5ce7a..9d162bfc0 100644 --- a/compiler/map.go +++ b/compiler/map.go @@ -41,8 +41,8 @@ func (b *builder) createMakeMap(expr *ssa.MakeMap) (llvm.Value, error) { } keySize := b.targetData.TypeAllocSize(llvmKeyType) valueSize := b.targetData.TypeAllocSize(llvmValueType) - llvmKeySize := llvm.ConstInt(b.ctx.Int8Type(), keySize, false) - llvmValueSize := llvm.ConstInt(b.ctx.Int32Type(), valueSize, false) + llvmKeySize := llvm.ConstInt(b.uintptrType, keySize, false) + llvmValueSize := llvm.ConstInt(b.uintptrType, valueSize, false) sizeHint := llvm.ConstInt(b.uintptrType, 8, false) algEnum := llvm.ConstInt(b.ctx.Int8Type(), alg, false) if expr.Reserve != nil { diff --git a/src/runtime/hashmap.go b/src/runtime/hashmap.go index 2e077a45f..684d9cfbf 100644 --- a/src/runtime/hashmap.go +++ b/src/runtime/hashmap.go @@ -15,8 +15,8 @@ type hashmap struct { buckets unsafe.Pointer // pointer to array of buckets seed uintptr count uintptr - valueSize uint32 - keySize uint8 // maybe this can store the key type as well? E.g. keysize == 5 means string? + keySize uintptr // maybe this can store the key type as well? E.g. keysize == 5 means string? + valueSize uintptr bucketBits uint8 keyEqual func(x, y unsafe.Pointer, n uintptr) bool keyHash func(key unsafe.Pointer, size, seed uintptr) uint32 @@ -60,14 +60,14 @@ func hashmapTopHash(hash uint32) uint8 { } // Create a new hashmap with the given keySize and valueSize. -func hashmapMake(keySize uint8, valueSize uint32, sizeHint uintptr, alg uint8) *hashmap { +func hashmapMake(keySize, valueSize uintptr, sizeHint uintptr, alg uint8) *hashmap { numBuckets := sizeHint / 8 bucketBits := uint8(0) for numBuckets != 0 { numBuckets /= 2 bucketBits++ } - bucketBufSize := unsafe.Sizeof(hashmapBucket{}) + uintptr(keySize)*8 + uintptr(valueSize)*8 + bucketBufSize := unsafe.Sizeof(hashmapBucket{}) + keySize*8 + valueSize*8 buckets := alloc(bucketBufSize*(1<