File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed
Sources/_CollectionsUtilities/IntegerTricks Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -41,13 +41,16 @@ extension UInt {
4141 var shift: Self = 0
4242 var n = Self(truncatingIfNeeded: n)
4343
44- if Self.bitWidth == 64 {
44+ if MemoryLayout<UInt>.size == 8 {
4545 let c32 = (self & 0xFFFFFFFF)._nonzeroBitCount
4646 if n >= c32 {
4747 shift &+= 32
4848 n &-= c32
4949 }
50+ } else {
51+ assert(MemoryLayout<Self>.size == 4, "Unknown platform")
5052 }
53+
5154 let c16 = ((self &>> shift) & 0xFFFF)._nonzeroBitCount
5255 if n >= c16 {
5356 shift &+= 16
Original file line number Diff line number Diff line change @@ -47,13 +47,16 @@ extension UInt {
4747 var shift : Self = 0
4848 var n = Self ( truncatingIfNeeded: n)
4949
50- if Self . bitWidth == 64 {
50+ if MemoryLayout < UInt > . size == 8 {
5151 let c32 = ( self & 0xFFFFFFFF ) . _nonzeroBitCount
5252 if n >= c32 {
5353 shift &+= 32
5454 n &-= c32
5555 }
56+ } else {
57+ assert ( MemoryLayout< Self> . size == 4 , " Unknown platform " )
5658 }
59+
5760 let c16 = ( ( self &>> shift) & 0xFFFF ) . _nonzeroBitCount
5861 if n >= c16 {
5962 shift &+= 16
@@ -184,13 +187,16 @@ extension UInt {
184187 var shift : Self = 0
185188 var n = Self ( truncatingIfNeeded: n)
186189
187- if Self . bitWidth == 64 {
190+ if MemoryLayout < UInt > . size == 8 {
188191 let c32 = ( self & 0xFFFFFFFF ) . _nonzeroBitCount
189192 if n >= c32 {
190193 shift &+= 32
191194 n &-= c32
192195 }
196+ } else {
197+ assert ( MemoryLayout< Self> . size == 4 , " Unknown platform " )
193198 }
199+
194200 let c16 = ( ( self &>> shift) & 0xFFFF ) . _nonzeroBitCount
195201 if n >= c16 {
196202 shift &+= 16
You can’t perform that action at this time.
0 commit comments