more fixes for --cpu:avr [backport] (#12748)
This commit is contained in:
parent
80b508d337
commit
fd85a5ae05
4 changed files with 8 additions and 5 deletions
|
|
@ -137,10 +137,10 @@ const
|
||||||
]
|
]
|
||||||
|
|
||||||
proc msbit(x: uint32): int {.inline.} =
|
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)
|
(if x <= 0xff: 0 else: 8)
|
||||||
else:
|
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
|
result = int(fsLookupTable[byte(x shr a)]) + a
|
||||||
|
|
||||||
proc lsbit(x: uint32): int {.inline.} =
|
proc lsbit(x: uint32): int {.inline.} =
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,13 @@
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
const
|
||||||
|
TableSize = when sizeof(int) <= 2: 0xff else: 0xff_ffff
|
||||||
|
|
||||||
type
|
type
|
||||||
PtrTable = ptr object
|
PtrTable = ptr object
|
||||||
counter, max: int
|
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 hashPtr(key: pointer): int = cast[int](key) shr 8
|
||||||
template allocPtrTable: untyped =
|
template allocPtrTable: untyped =
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ proc reprEnum(e: int, typ: PNimType): string {.compilerRtl.} =
|
||||||
result = $e & " (invalid data!)"
|
result = $e & " (invalid data!)"
|
||||||
|
|
||||||
type
|
type
|
||||||
PByteArray = ptr array[0xffff, byte]
|
PByteArray = ptr UncheckedArray[byte] # array[0xffff, byte]
|
||||||
|
|
||||||
proc addSetElem(result: var string, elem: int, typ: PNimType) {.benign.} =
|
proc addSetElem(result: var string, elem: int, typ: PNimType) {.benign.} =
|
||||||
case typ.kind
|
case typ.kind
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ proc countBits32(n: uint32): int {.compilerproc.} =
|
||||||
var v = uint32(n)
|
var v = uint32(n)
|
||||||
v = v - ((v shr 1'u32) and 0x55555555'u32)
|
v = v - ((v shr 1'u32) and 0x55555555'u32)
|
||||||
v = (v and 0x33333333'u32) + ((v shr 2'u32) and 0x33333333'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.} =
|
proc countBits64(n: uint64): int {.compilerproc, inline.} =
|
||||||
# generic formula is from: https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
|
# generic formula is from: https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue