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

ccall should pass vectorized tuples by value instead of reference #16138

Closed
ArchRobison opened this issue Apr 30, 2016 · 4 comments
Closed

ccall should pass vectorized tuples by value instead of reference #16138

ArchRobison opened this issue Apr 30, 2016 · 4 comments
Labels
compiler:codegen Generation of LLVM IR and native code

Comments

@ArchRobison
Copy link
Contributor

While writing the docs for #15244, I discovered that ccall is passing tuples of VecElement by reference instead of value. Passing by value would be more consistent with the C ABI for SIMD types, e.g. pass a NTuple{8,VecElement{Float32}} as if it were a C AVX __m256.

I'll poke around ccall to see what I need to teach it. Below is the example I was playing with.

typealias m256 NTuple{8,VecElement{Float32}}

convert(::Type{VecElement{Float32}},x::Float32) = VecElement(x)

a = m256(ntuple(i->VecElement(sin(Float32(i))),8))
b = m256(ntuple(i->VecElement(cos(Float32(i))),8))
println(typeof(a))
println(typeof(b))

function call_dist(a::m256, b::m256)
    ccall((:dist, "libdist"), m256, (m256, m256), a, b)  # C prototype is __m256 dist( __m256 a, __m256 b ) 
end

@code_llvm call_dist(a,b)
@ArchRobison
Copy link
Contributor Author

Looks like the fix involves changing the Classification logic to understand the special tuples. Can someone explain the purpose of the two classes fields here in abi_x86_64.cpp?

struct Classification {
    bool isMemory;
    ArgClass classes[2];

@yuyichao
Copy link
Contributor

yuyichao commented Apr 30, 2016

Right. All the abi needs to be updated.

@ArchRobison
Copy link
Contributor Author

What's the difference between classes[0] and classes[1]?

@ArchRobison
Copy link
Contributor Author

Closed by #16258.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code
Projects
None yet
Development

No branches or pull requests

3 participants