SIMD支持
类型 VecElement{T} 用于构建SIMD操作库。 实际使用它需要使用 n.有限责任公司. 类型定义为:
struct VecElement{T}
value::T
end
它有一个特殊的编译规则: VecElement{T} 映射到LLVM 向量资料 类型时 T 是基元比特类型。
在 -O3,编译器_might_自动对此类元组的操作进行矢量化。 例如下面的程序,当用 朱莉娅-O3 生成两个SIMD加法指令(附加组件)在x86系统上:
const m128 = NTuple{4,VecElement{Float32}}
function add(a::m128, b::m128)
(VecElement(a[1].value+b[1].value),
VecElement(a[2].value+b[2].value),
VecElement(a[3].value+b[3].value),
VecElement(a[4].value+b[4].value))
end
triple(c::m128) = add(add(c,c),c)
code_native(triple,(m128,))
但是,由于不能依赖自动矢量化,因此将来的使用主要是通过使用 n.有限责任公司.