tyInt tyUint fit target int bit width (#20829)
This commit is contained in:
parent
a70d3abd37
commit
658b28dc57
17 changed files with 306 additions and 267 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
proc succ*[T: Ordinal](x: T, y = 1): T {.magic: "Succ", noSideEffect.} =
|
||||
proc succ*[T, V: Ordinal](x: T, y: V = 1): T {.magic: "Succ", noSideEffect.} =
|
||||
## Returns the `y`-th successor (default: 1) of the value `x`.
|
||||
##
|
||||
## If such a value does not exist, `OverflowDefect` is raised
|
||||
|
|
@ -7,7 +7,7 @@ proc succ*[T: Ordinal](x: T, y = 1): T {.magic: "Succ", noSideEffect.} =
|
|||
assert succ(5) == 6
|
||||
assert succ(5, 3) == 8
|
||||
|
||||
proc pred*[T: Ordinal](x: T, y = 1): T {.magic: "Pred", noSideEffect.} =
|
||||
proc pred*[T, V: Ordinal](x: T, y: V = 1): T {.magic: "Pred", noSideEffect.} =
|
||||
## Returns the `y`-th predecessor (default: 1) of the value `x`.
|
||||
##
|
||||
## If such a value does not exist, `OverflowDefect` is raised
|
||||
|
|
@ -16,7 +16,7 @@ proc pred*[T: Ordinal](x: T, y = 1): T {.magic: "Pred", noSideEffect.} =
|
|||
assert pred(5) == 4
|
||||
assert pred(5, 3) == 2
|
||||
|
||||
proc inc*[T: Ordinal](x: var T, y = 1) {.magic: "Inc", noSideEffect.} =
|
||||
proc inc*[T, V: Ordinal](x: var T, y: V = 1) {.magic: "Inc", noSideEffect.} =
|
||||
## Increments the ordinal `x` by `y`.
|
||||
##
|
||||
## If such a value does not exist, `OverflowDefect` is raised or a compile
|
||||
|
|
@ -28,7 +28,7 @@ proc inc*[T: Ordinal](x: var T, y = 1) {.magic: "Inc", noSideEffect.} =
|
|||
inc(i, 3)
|
||||
assert i == 6
|
||||
|
||||
proc dec*[T: Ordinal](x: var T, y = 1) {.magic: "Dec", noSideEffect.} =
|
||||
proc dec*[T, V: Ordinal](x: var T, y: V = 1) {.magic: "Dec", noSideEffect.} =
|
||||
## Decrements the ordinal `x` by `y`.
|
||||
##
|
||||
## If such a value does not exist, `OverflowDefect` is raised or a compile
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
# Page size of the system; in most cases 4096 bytes. For exotic OS or
|
||||
# CPU this needs to be changed:
|
||||
const
|
||||
PageShift = when defined(nimPage256) or defined(cpu16): 8
|
||||
PageShift = when defined(nimPage256) or defined(cpu16): 3
|
||||
elif defined(nimPage512): 9
|
||||
elif defined(nimPage1k): 10
|
||||
else: 12 # \ # my tests showed no improvements for using larger page sizes.
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ proc cmpStrings(a, b: string): int {.inline, compilerproc.} =
|
|||
let blen = b.len
|
||||
let minlen = min(alen, blen)
|
||||
if minlen > 0:
|
||||
result = c_memcmp(unsafeAddr a[0], unsafeAddr b[0], cast[csize_t](minlen))
|
||||
result = c_memcmp(unsafeAddr a[0], unsafeAddr b[0], cast[csize_t](minlen)).int
|
||||
if result == 0:
|
||||
result = alen - blen
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ template frees(s) =
|
|||
|
||||
proc resize(old: int): int {.inline.} =
|
||||
if old <= 0: result = 4
|
||||
elif old < 65536: result = old * 2
|
||||
elif old <= high(int16): result = old * 2
|
||||
else: result = old * 3 div 2 # for large arrays * 3/2 is better
|
||||
|
||||
proc prepareAdd(s: var NimStringV2; addlen: int) {.compilerRtl.} =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue