mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-17 08:34:20 +00:00
more fixes for --cpu:avr [backport] (#12748)
This commit is contained in:
@@ -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.} =
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user