more fixes for --cpu:avr [backport] (#12748)

This commit is contained in:
Andreas Rumpf
2019-11-27 16:24:21 +01:00
committed by GitHub
parent 80b508d337
commit fd85a5ae05
4 changed files with 8 additions and 5 deletions

View File

@@ -137,10 +137,10 @@ const
]
proc msbit(x: uint32): int {.inline.} =
let a = if x <= 0xff_ff:
let a = if x <= 0xff_ff'u32:
(if x <= 0xff: 0 else: 8)
else:
(if x <= 0xff_ff_ff: 16 else: 24)
(if x <= 0xff_ff_ff'u32: 16 else: 24)
result = int(fsLookupTable[byte(x shr a)]) + a
proc lsbit(x: uint32): int {.inline.} =

View File

@@ -7,10 +7,13 @@
# distribution, for details about the copyright.
#
const
TableSize = when sizeof(int) <= 2: 0xff else: 0xff_ffff
type
PtrTable = ptr object
counter, max: int
data: array[0xff_ffff, (pointer, pointer)]
data: array[TableSize, (pointer, pointer)]
template hashPtr(key: pointer): int = cast[int](key) shr 8
template allocPtrTable: untyped =

View File

@@ -78,7 +78,7 @@ proc reprEnum(e: int, typ: PNimType): string {.compilerRtl.} =
result = $e & " (invalid data!)"
type
PByteArray = ptr array[0xffff, byte]
PByteArray = ptr UncheckedArray[byte] # array[0xffff, byte]
proc addSetElem(result: var string, elem: int, typ: PNimType) {.benign.} =
case typ.kind

View File

@@ -19,7 +19,7 @@ proc countBits32(n: uint32): int {.compilerproc.} =
var v = uint32(n)
v = v - ((v shr 1'u32) and 0x55555555'u32)
v = (v and 0x33333333'u32) + ((v shr 2'u32) and 0x33333333'u32)
result = (((v + (v shr 4'u32) and 0xF0F0F0F'u32) * 0x1010101) shr 24'u32).int
result = (((v + (v shr 4'u32) and 0xF0F0F0F'u32) * 0x1010101'u32) shr 24'u32).int
proc countBits64(n: uint64): int {.compilerproc, inline.} =
# generic formula is from: https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel