{"action":"created","issue":{"url":"https://api.github.com/repos/eschnett/SIMD.jl/issues/5","repository_url":"https://api.github.com/repos/eschnett/SIMD.jl","labels_url":"https://api.github.com/repos/eschnett/SIMD.jl/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/eschnett/SIMD.jl/issues/5/comments","events_url":"https://api.github.com/repos/eschnett/SIMD.jl/issues/5/events","html_url":"https://github.com/eschnett/SIMD.jl/issues/5","id":140954670,"number":5,"title":"Using llvmcall with VecElements","user":{"login":"KristofferC","id":1282691,"avatar_url":"https://avatars.githubusercontent.com/u/1282691?v=3","gravatar_id":"","url":"https://api.github.com/users/KristofferC","html_url":"https://github.com/KristofferC","followers_url":"https://api.github.com/users/KristofferC/followers","following_url":"https://api.github.com/users/KristofferC/following{/other_user}","gists_url":"https://api.github.com/users/KristofferC/gists{/gist_id}","starred_url":"https://api.github.com/users/KristofferC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KristofferC/subscriptions","organizations_url":"https://api.github.com/users/KristofferC/orgs","repos_url":"https://api.github.com/users/KristofferC/repos","events_url":"https://api.github.com/users/KristofferC/events{/privacy}","received_events_url":"https://api.github.com/users/KristofferC/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-15T12:10:17Z","updated_at":"2016-03-15T16:56:23Z","closed_at":null,"body":"Please tell me if you think this is the wrong place to discuss this.\r\n\r\nI've been experimenting a little bit with using `llvmcall` on an immutable wrapper that wraps a tuple of `VecElements`.\r\n\r\nThe problem I have is that for `Vec`s of sizes that are not 2, 4, 8, LLVM gets the type info that this is a `[N x double]` instead of a `<N x double>` which causes the compilation to fail.\r\nFor sizes of 2, 4, 8 nice code is being generated and it even uses the AVX registers which is something that I hadn't got working without `llvmcall`\r\n\r\nThe code is here:\r\n\r\n```jl\r\ntypealias LLVMDataTypeString ASCIIString\r\nimport Base.VecElement\r\n\r\nd = Dict{DataType, LLVMDataTypeString}((\r\nFloat64 => \"double\",\r\nFloat32 => \"float\",\r\nInt32 => \"i32\",\r\nInt64 => \"i64\"\r\n))\r\n\r\nimmutable Vec{N, T}\r\n    data::NTuple{N, VecElement{T}}\r\nend\r\n\r\n@generated function Base.(:+){N, T}(x::Vec{N, T}, y::Vec{N, T})\r\n    exp = \"\"\"\r\n    %3 = fadd <$(N) x $(d[T])> %0, %1\r\n    ret <$(N) x $(d[T])> %3\r\n    \"\"\"\r\n    return quote\r\n            Vec(Base.llvmcall($exp,\r\n               NTuple{N, VecElement{T}},\r\n               Tuple{NTuple{N,VecElement{T}},NTuple{N,VecElement{T}}},\r\n               x.data, y.data))\r\n    end\r\nend\r\n\r\nF64 = VecElement(1.0)\r\nF32 = VecElement(1.0f0)\r\n\r\n# 128 bit xmm register used\r\n@code_native Vec((F64, F64)) + Vec((F64, F64))\r\n\r\n# 256 bit AVX register used\r\n@code_native Vec((F64, F64, F64, F64)) + Vec((F64, F64, F64, F64))\r\n\r\n# 2 256 bit AVX register vaddpd\r\n@code_native Vec((F64, F64, F64, F64, F64, F64, F64, F64)) + \r\n             Vec((F64, F64, F64, F64, F64, F64, F64, F64))\r\n\r\n\r\n# Erros because Vec((F64, F64, F64)) is interpreted as a [3 x double] instead\r\n# of <3 x double>\r\n@code_native Vec((F64, F64, F64)) + Vec((F64, F64, F64))\r\n```"},"comment":{"url":"https://api.github.com/repos/eschnett/SIMD.jl/issues/comments/196921207","html_url":"https://github.com/eschnett/SIMD.jl/issues/5#issuecomment-196921207","issue_url":"https://api.github.com/repos/eschnett/SIMD.jl/issues/5","id":196921207,"user":{"login":"eschnett","id":213514,"avatar_url":"https://avatars.githubusercontent.com/u/213514?v=3","gravatar_id":"","url":"https://api.github.com/users/eschnett","html_url":"https://github.com/eschnett","followers_url":"https://api.github.com/users/eschnett/followers","following_url":"https://api.github.com/users/eschnett/following{/other_user}","gists_url":"https://api.github.com/users/eschnett/gists{/gist_id}","starred_url":"https://api.github.com/users/eschnett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eschnett/subscriptions","organizations_url":"https://api.github.com/users/eschnett/orgs","repos_url":"https://api.github.com/users/eschnett/repos","events_url":"https://api.github.com/users/eschnett/events{/privacy}","received_events_url":"https://api.github.com/users/eschnett/received_events","type":"User","site_admin":false},"created_at":"2016-03-15T16:56:22Z","updated_at":"2016-03-15T16:56:22Z","body":"How did you make this work??? All my attempts led to segfaults. I was waiting for @ArchRobison's fixes. Thanks for the example!\r\n\r\nThe restriction on the tuple size you mention is hard-coded into Julia. It's easy to remove there. Look for `julia_struct_to_llvm` in `cgutils.cpp`. There's an ominous undated warning about \"LLVM assertion failures\" that is quite possibly very outdated by now."}}