tyInt tyUint fit target int bit width (#20829)

This commit is contained in:
Bung 2022-12-01 20:34:00 +08:00 • committed by GitHub
commit 658b28dc57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 306 additions and 267 deletions

View file

@ -24,7 +24,7 @@ template track(op, address, size) =
const
nimMinHeapPages {.intdefine.} = 128 # 0.5 MB
SmallChunkSize = PageSize
MaxFli = 30
MaxFli = when sizeof(int) > 2: 30 else: 14
MaxLog2Sli = 5 # 32, this cannot be increased without changing 'uint32'
# everywhere!
MaxSli = 1 shl MaxLog2Sli
@ -32,7 +32,7 @@ const
RealFli = MaxFli - FliOffset
# size of chunks in last matrix bin
MaxBigChunkSize = 1 shl MaxFli - 1 shl (MaxFli-MaxLog2Sli-1)
MaxBigChunkSize = int(1'i32 shl MaxFli - 1'i32 shl (MaxFli-MaxLog2Sli-1))
HugeChunkSize = MaxBigChunkSize + 1
type
@ -115,7 +115,7 @@ type
MemRegion = object
when not defined(gcDestructors):
minLargeObj, maxLargeObj: int
freeSmallChunks: array[0..SmallChunkSize div MemAlign-1, PSmallChunk]
freeSmallChunks: array[0..max(1,SmallChunkSize div MemAlign-1), PSmallChunk]
flBitmap: uint32
slBitmap: array[RealFli, uint32]
matrix: array[RealFli, array[MaxSli, PBigChunk]]
@ -196,7 +196,7 @@ proc mappingSearch(r, fl, sl: var int) {.inline.} =
let t = roundup((1 shl (msbit(uint32 r) - MaxLog2Sli)), PageSize) - 1
r = r + t
r = r and not t
r = min(r, MaxBigChunkSize)
r = min(r, MaxBigChunkSize).int
fl = msbit(uint32 r)
sl = (r shr (fl - MaxLog2Sli)) - MaxSli
dec fl, FliOffset
@ -472,7 +472,7 @@ proc requestOsChunks(a: var MemRegion, size: int): PBigChunk =
a.nextChunkSize = PageSize*4
else:
a.nextChunkSize = min(roundup(usedMem shr 2, PageSize), a.nextChunkSize * 2)
a.nextChunkSize = min(a.nextChunkSize, MaxBigChunkSize)
a.nextChunkSize = min(a.nextChunkSize, MaxBigChunkSize).int
var size = size
if size > a.nextChunkSize: