Engee 文档

SIMD支持

`VecElement类型{T}'用于创建SIMD操作库。 对于其实际应用,有必要使用’llvmcall'。 类型定义如下。

struct VecElement{T}
    value::T
end

它有一个特殊的编译规则:同质元组'VecElement{T}如果`T`是基元位类型,则将`映射到LLVM`vector`类型。

使用'-O3`,编译器可以自动对具有此类元组的操作进行矢量化。 例如,当从julia-O3编译时,下面的程序在x86系统上生成两个SIMD加法指令(addps):

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,))

但是,由于不能指望自动矢量化,将来它将主要在使用llvmcall的库的帮助下使用。