Skip to content

Commit

Permalink
Merge pull request #9 from heltonmc/complexcast
Browse files Browse the repository at this point in the history
Improve efficiency of casting complex numbers to complex vectors.
  • Loading branch information
heltonmc authored Apr 17, 2023
2 parents abf7ec4 + bf302fe commit 6d2955e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/SIMDMath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ module SIMDMath

using Base: llvmcall, VecElement

using Base.Cartesian: @ntuple

export horner_simd, pack_poly
export horner, pack_horner

Expand Down
14 changes: 13 additions & 1 deletion src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,19 @@ end
const ComplexOrRealVec{N, T} = Union{Vec{N, T}, ComplexVec{N, T}}

ComplexVec(x::NTuple{N, T}, y::NTuple{N, T}) where {N, T <: FloatTypes} = ComplexVec(LVec{N, T}(x), LVec{N, T}(y))
ComplexVec(z::NTuple{N, Complex{T}}) where {N, T <: FloatTypes} = ComplexVec(real.(z), imag.(z))

@inline @generated function ComplexVec(z::NTuple{N, Complex{T}}) where {N, T <: FloatTypes}
len = 2*N
lenm1 = len - 1
return :(
begin
x = LVec{$len, T}(@ntuple $N i -> (reim(z[i])...))
b = shufflevector(x, Val(0:2:$lenm1))
c = shufflevector(x, Val(1:2:$lenm1))
return ComplexVec{$N, T}(b, c)
end
)
end

Base.convert(::Type{ComplexVec{N, T}}, z::ComplexVec{N, T}) where {N, T <: FloatTypes} = z
Base.convert(::Type{ComplexVec{N, T}}, z::Complex{T}) where {N, T <: FloatTypes} = constantvector(z, ComplexVec{N, T})
Expand Down

0 comments on commit 6d2955e

Please sign in to comment.