Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix depwarns and wrong use of reinterpret #14

Merged
merged 1 commit into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
julia 0.4
ArgParse
Compat 0.16.0
Compat 0.18.0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should only be 0.17 right, since none of the aliases are parametric?

22 changes: 15 additions & 7 deletions src/CRC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,17 @@ import Base.Cartesian: @nexprs
import Base: ==, isless, print
using Compat

typealias U Unsigned

const U = Unsigned

immutable UnalignedVector{T<:U}
a::Vector{UInt8}
end
# unsafe
@inline Base.getindex{T}(a::UnalignedVector{T}, i) = unsafe_load(Ptr{T}(pointer(a.a)), i)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boundscheck Base.checkbounds(a.a, i) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only limited user below is in @inbounds so I didn't bother...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Also because this package still support 0.4, which doesn't support the new bounds check elision yet?)

@inline Base.length{T}(a::UnalignedVector{T}) = length(a.a) ÷ sizeof(T)
@inline unaligned_reinterpret{T<:U}(::Type{T}, a::Vector{UInt8}) = UnalignedVector{T}(a)
@inline unaligned_reinterpret(::Type{UInt8}, a::Vector{UInt8}) = a
@compat MaybeUnalignedVector{T} = Union{UnalignedVector{T},Vector{T}}

# ---- CRC specifications from http://www.zlib.net/crc_v3.txt

Expand Down Expand Up @@ -279,7 +287,7 @@ end
# depends on whether the input input bytes are taken as given
# (Forwards) or reflected (Backwards).

abstract Direction{A<:U}
@compat abstract type Direction{A<:U} end

immutable Backwards{A<:U}<:Direction{A}
poly::A
Expand Down Expand Up @@ -310,7 +318,7 @@ end

# a calculation may use no, one, or many tables...

abstract Tables{A<:U}
@compat abstract type Tables{A<:U} end

immutable NoTables{A<:U}<:Tables{A}
@compat (::Type{NoTables{A}}){A}(direcn::Direction{A}) = new{A}()
Expand Down Expand Up @@ -433,7 +441,7 @@ end
for A in (UInt16, UInt32, UInt64, UInt128)
n_tables = sizeof(A)
@eval begin
function extend(direcn::Forwards{$A}, tables::Multiple{$A}, data::Vector{$A}, remainder::$A)
function extend(direcn::Forwards{$A}, tables::Multiple{$A}, data::MaybeUnalignedVector{$A}, remainder::$A)
word::$A, tmp::$A, remainder::$A = zero($A), zero($A), remainder
i = 1
while true
Expand Down Expand Up @@ -486,7 +494,7 @@ end
for A in (UInt16, UInt32, UInt64, UInt128)
n_tables = sizeof(A)
@eval begin
function extend(direcn::Backwards{$A}, tables::Multiple{$A}, data::Vector{$A}, remainder::$A)
function extend(direcn::Backwards{$A}, tables::Multiple{$A}, data::MaybeUnalignedVector{$A}, remainder::$A)
word::$A, tmp::$A, remainder::$A = zero($A), zero($A), remainder
i = 1
while true
Expand Down Expand Up @@ -518,7 +526,7 @@ function extend{A<:U}(direcn::Direction{A}, tables::Multiple{A}, data::Vector{UI
# words and then process those, which typically (64 bits) loads 8
# bytes at a time.
tail = length(data) % sizeof(A)
remainder = extend(direcn, tables, reinterpret(A, data), remainder)
remainder = extend(direcn, tables, unaligned_reinterpret(A, data), remainder)
# slurp up the final bytes that didn't fill a complete machine word.
extend(direcn, Single{A}(tables), data[end-tail+1:end], remainder)
end
Expand Down