Skip to content

Commit

Permalink
fixes #22481; fixes card undefined misalignment behavior (#22484)
Browse files Browse the repository at this point in the history
* fixes `card` undefined misalignment behavior

* Update lib/system/sets.nim

---------

Co-authored-by: Andreas Rumpf <[email protected]>
  • Loading branch information
ringabout and Araq committed Aug 15, 2023
1 parent 6c4e783 commit ade75a1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/system/sets.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ade75a1

Please sign in to comment.