fixes #22481; fixes card undefined misalignment behavior (#22484)

* fixes `card` undefined misalignment behavior

* Update lib/system/sets.nim

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
(cherry picked from commit ade75a1483)
This commit is contained in:
ringabout
2023-08-16 05:31:44 +08:00
committed by narimiran
parent 320ecc69a0
commit 562fb0d14b

View File

@@ -13,9 +13,11 @@
proc cardSetImpl(s: ptr UncheckedArray[uint8], len: int): int {.inline.} =
var i = 0
result = 0
var num = 0'u64
when defined(x86) or defined(amd64):
while i < len - 8:
inc(result, countBits64((cast[ptr uint64](s[i].unsafeAddr))[]))
copyMem(addr num, addr s[i], 8)
inc(result, countBits64(num))
inc(i, 8)
while i < len: