From 9dd1608f2b9f34a0f3a24c242043d7dfa470ce12 Mon Sep 17 00:00:00 2001 From: Chris Elrod Date: Tue, 15 Feb 2022 23:37:59 -0500 Subject: [PATCH 1/3] Pop first thread Co-authored-by: Yingbo Ma --- Project.toml | 2 +- src/unsignediterator.jl | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index f8aea91..5e4dbb4 100644 --- a/Project.toml +++ b/Project.toml @@ -15,7 +15,7 @@ BitTwiddlingConvenienceFunctions = "0.1" CPUSummary = "0.1.2" IfElse = "0.1" Static = "0.3.1, 0.4, 0.5" -ThreadingUtilities = "0.4.5" +ThreadingUtilities = "0.4.5, 0.5" julia = "1.5" [extras] diff --git a/src/unsignediterator.jl b/src/unsignediterator.jl index 61d4ddb..783ca61 100644 --- a/src/unsignediterator.jl +++ b/src/unsignediterator.jl @@ -25,7 +25,6 @@ Base.size(u::UnsignedIterator) = (count_ones(u.u),) (i, (i+0x00000001,uu)) end - """ UnsignedIteratorEarlyStop(thread_mask[, num_threads = count_ones(thread_mask)]) @@ -57,6 +56,38 @@ end UnsignedIteratorEarlyStop(u) = UnsignedIteratorEarlyStop(u, count_ones(u) % UInt32) UnsignedIteratorEarlyStop(u, i) = UnsignedIteratorEarlyStop(u, i % UInt32) +@inline _popfirstthread(::Tuple{}, ::Tuple{}, offset) = 0, (), () +@inline function _popfirstthread( + u::Tuple{U,Vararg{U,K}}, a::Tuple{TT,Vararg{TT,K}}, offset +) where {K,T,TT<:UnsignedIterator{T},U<:UnsignedIteratorEarlyStop{T}} + uf = first(u) + af = first(a) + u0 = uf.u + if iszero(u0) + tid0, tupi, tup = _popfirstthread(Base.tail(u), offset + 8sizeof(u0)) + return tid0, (uf, tupi...), (af, tup...) + end + tz = Base.trailing_zeros(u0) + mask = one(u0)< Date: Thu, 17 Feb 2022 12:39:06 -0500 Subject: [PATCH 2/3] fix UnsignedIterator --- src/unsignediterator.jl | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/unsignediterator.jl b/src/unsignediterator.jl index 783ca61..623689e 100644 --- a/src/unsignediterator.jl +++ b/src/unsignediterator.jl @@ -9,20 +9,13 @@ Base.eltype(::UnsignedIterator) = UInt32 Base.length(u::UnsignedIterator) = count_ones(u.u) Base.size(u::UnsignedIterator) = (count_ones(u.u),) -# @inline function Base.iterate(u::UnsignedIterator, uu = u.u) -# tz = trailing_zeros(uu) % UInt32 -# # tz ≥ 0x00000020 && return nothing -# tz > 0x0000001f && return nothing -# uu ⊻= (0x00000001 << tz) -# tz, uu -# end @inline function Base.iterate(u::UnsignedIterator, (i,uu) = (0x00000000,u.u)) - tz = trailing_zeros(uu) % UInt32 - tz == 0x00000020 && return nothing - i += tz - tz += 0x00000001 - uu >>>= tz - (i, (i+0x00000001,uu)) + tz = trailing_zeros(uu) % UInt32 + tz == oftype(uu, 8*sizeof(uu)) && return nothing + i += tz + tz += 0x00000001 + uu >>>= tz + (i, (i+0x00000001,uu)) end """ From fded43392edad174d268cd23c2afd31ca5beeef2 Mon Sep 17 00:00:00 2001 From: Chris Elrod Date: Wed, 2 Mar 2022 09:28:09 -0500 Subject: [PATCH 3/3] shift order --- src/unsignediterator.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/unsignediterator.jl b/src/unsignediterator.jl index 623689e..8f9ac7e 100644 --- a/src/unsignediterator.jl +++ b/src/unsignediterator.jl @@ -12,10 +12,10 @@ Base.size(u::UnsignedIterator) = (count_ones(u.u),) @inline function Base.iterate(u::UnsignedIterator, (i,uu) = (0x00000000,u.u)) tz = trailing_zeros(uu) % UInt32 tz == oftype(uu, 8*sizeof(uu)) && return nothing - i += tz tz += 0x00000001 + i += tz uu >>>= tz - (i, (i+0x00000001,uu)) + (i, (i, uu)) end """