forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document VecElement{T}. Support call-by-value of SIMD types on 64-bit…
… x86. Make C interop work for SSE types on 64-bit x86 and add tests for it, including cfunction round-trip test.
- Loading branch information
Arch D. Robison
committed
May 24, 2016
1 parent
c43b5e5
commit f88fb5c
Showing
11 changed files
with
176 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,7 @@ | |
stdlib/libdl | ||
stdlib/profile | ||
stdlib/stacktraces | ||
stdlib/simd-types | ||
|
||
.. _devdocs: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,4 @@ | |
libc | ||
libdl | ||
profile | ||
simd-types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
.. _stdlib-simd-types: | ||
|
||
**************** | ||
SIMD Support | ||
**************** | ||
|
||
Type ``VecElement{T}`` is intended for building libraries of SIMD operations. | ||
Practical use of it requires using ``llvmcall``. The type is defined as:: | ||
|
||
immutable VecElement{T} | ||
value::T | ||
end | ||
|
||
It has a special compilation rule: a homogeneous tuple of ``VecElement{T}`` | ||
maps to an LLVM ``vector`` type when ``T`` is a bitstype and the tuple | ||
length is in the set {2-6,8-10,16}. | ||
|
||
At ``-O3``, the compiler *might* automatically vectorize operations | ||
on such tuples. For example, the following program, when compiled | ||
with ``julia -O3`` generates two SIMD addition instructions (``addps``) | ||
on x86 systems:: | ||
|
||
typealias 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,)) | ||
|
||
However, since the automatic vectorization cannot be relied upon, | ||
future use will mostly be via libraries that use ``llvmcall``. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// This file is a part of Julia. License is MIT: http://julialang.org/license | ||
|
||
#ifndef ABI_X86_VEC_H | ||
#define ABI_X86_VEC_H | ||
|
||
// Determine if object of bitstype ty maps to a __m128, __m256, or __m512 type in C. | ||
static bool is_native_simd_type(jl_value_t *ty) { | ||
size_t size = jl_datatype_size(ty); | ||
if (size!=16 && size!=32 && size!=64) | ||
// Wrong size for xmm, ymm, or zmm register. | ||
return false; | ||
uint32_t n = jl_datatype_nfields(ty); | ||
if (n<2) | ||
// Not mapped to SIMD register. | ||
return false; | ||
jl_value_t *ft0 = jl_field_type(ty, 0); | ||
for (uint32_t i = 1; i < n; ++i) | ||
if (jl_field_type(ty, i)!=ft0) | ||
// Not homogeneous | ||
return false; | ||
// Type is homogeneous. Check if it maps to LLVM vector. | ||
return jl_special_vector_alignment(n,ft0) != 0; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters