From 04a154eee0b8a2ad313e24ba46a4e5b4e0b9036f Mon Sep 17 00:00:00 2001 From: nitely Date: Wed, 2 Aug 2023 04:00:19 -0300 Subject: [PATCH] collation missing bitops --- src/unicodedb/collation.nim | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/unicodedb/collation.nim b/src/unicodedb/collation.nim index db72d74..257cf84 100644 --- a/src/unicodedb/collation.nim +++ b/src/unicodedb/collation.nim @@ -9,9 +9,22 @@ export collationMaxKeyLen when (NimMajor, NimMinor) < (1, 3): - func bitsliced[T: SomeInteger](v: T; slice: Slice[int]): T = + # Ported from Nim's stdlib + func bitsliced[T: SomeUnsignedInt](v: T; slice: Slice[int]): T = let upmost = sizeof(T) * 8 - 1 (v shl (upmost - slice.b) shr (upmost - slice.b + slice.a)).T + template typeMasked[T: SomeUnsignedInt](x: T): T = + when defined(js): + x and ((0xffffffff_ffffffff'u shr (64 - sizeof(T) * 8))) + else: + x + func toMask[T: SomeUnsignedInt](slice: Slice[int]): T = + let + upmost = sizeof(T) * 8 - 1 + bitmask = bitnot(0.T) + ((bitmask shl (upmost - slice.b + slice.a)).typeMasked shr (upmost - slice.b)).T + func clearMasked[T: SomeUnsignedInt](v: T; slice: Slice[int]): T = + bitand(v, bitnot(toMask[T](slice))) type CollationElement* = object