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

[wip] Creating fmaddsub for these intrinsics #89

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
18 changes: 18 additions & 0 deletions src/LLVM_intrinsics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ end
const MULADD_INTRINSICS = [
:fmuladd,
:fma,

]

for f in MULADD_INTRINSICS
Expand All @@ -430,6 +431,23 @@ for f in MULADD_INTRINSICS
end
end

const AVX_EXTS = [("d" , 2, Float64), ("s" , 4, Float32),
("d.256", 4, Float64), ("s.256", 8, Float32),
# ("d.512", 8, Float64), ("s.512", 16, Float32) # These don't seem supported by LLVM yet
]
const MULALTADD_INTRINSICS = [:vfmaddsub, :vfmsubadd]

for f in MULALTADD_INTRINSICS
for (t, N, T) in AVX_EXTS
@eval @generated function ($f)(a::LVec{$N, $T}, b::LVec{$N, $T}, c::LVec{$N, $T})
ff = "llvm.x86.fma."*(string($f))*".p"*($t)
return :(
$(Expr(:meta, :inline));
ccall($ff, llvmcall, LVec{$($N), $($T)}, (LVec{$($N), $($T)}, LVec{$($N), $($T)}, LVec{$($N), $($T)}), a, b, c)
)
end
end
Copy link
Owner

Choose a reason for hiding this comment

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

In the end we will also need test cases.

end

################
# Load / store #
Expand Down
2 changes: 1 addition & 1 deletion src/SIMD.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using Base: @propagate_inbounds

export Vec, vload, vloada, vloadnt, vloadx, vstore, vstorea, vstorent, vstorec,
vgather, vgathera, vscatter, vscattera, shufflevector, vifelse, valloc,
VecRange
VecRange, vfmaddsub, vfmasubadd

const VE = Base.VecElement
const LVec{N, T} = NTuple{N, VE{T}}
Expand Down
3 changes: 3 additions & 0 deletions src/simdvec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,9 @@ for (op, llvmop) in [(:fma, Intrinsics.fma), (:muladd, Intrinsics.fmuladd)]
end
end

@inline vfmaddsub(a::Vec{N,T}, b::Vec{N,T}, c::Vec{N,T}) where {N, T <: FloatingTypes} = Vec{N,T}(Intrinsics.vfmaddsub(a.data, b.data, c.data))
@inline vfmsubadd(a::Vec{N,T}, b::Vec{N,T}, c::Vec{N,T}) where {N, T <: FloatingTypes} = Vec{N,T}(Intrinsics.vfmaddsub(a.data, b.data, c.data))

if isdefined(Base, :bitrotate)
@inline Base.bitrotate(x::Vec, k::Vec) = Vec(Intrinsics.fshl(x.data, x.data, k.data))
@inline Base.bitrotate(x::Vec{N, T}, k::Integer) where {N, T} = bitrotate(x, Vec{N, T}(k))
Expand Down