rust/src
Huon Wilson 1a620661b7 Special-case transmute for primitive, SIMD & pointer types.
This detects (a subset of) the cases when `transmute::<T, U>(x)` can be
lowered to a direct `bitcast T x to U` in LLVM. This assists with
efficiently handling a SIMD vector as multiple different types,
e.g. swapping bytes/words/double words around inside some larger vector
type.

C compilers like GCC and Clang handle integer vector types as `__m128i`
for all widths, and implicitly insert bitcasts as required. This patch
allows Rust to express this, even if it takes a bit of `unsafe`, whereas
previously it was impossible to do at all without inline assembly.

Example:

    pub fn reverse_u32s(u: u64x2) -> u64x2 {
        unsafe {
            let tmp = mem::transmute::<_, u32x4>(u);
            let swapped = u32x4(tmp.3, tmp.2, tmp.1, tmp.0);
            mem::transmute::<_, u64x2>(swapped)
        }
    }

Compiling with `--opt-level=3` gives:

Before

    define <2 x i64> @_ZN12reverse_u32s20hbdb206aba18a03d8tbaE(<2 x i64>) unnamed_addr #0 {
    entry-block:
      %1 = bitcast <2 x i64> %0 to i128
      %u.0.extract.trunc = trunc i128 %1 to i32
      %u.4.extract.shift = lshr i128 %1, 32
      %u.4.extract.trunc = trunc i128 %u.4.extract.shift to i32
      %u.8.extract.shift = lshr i128 %1, 64
      %u.8.extract.trunc = trunc i128 %u.8.extract.shift to i32
      %u.12.extract.shift = lshr i128 %1, 96
      %u.12.extract.trunc = trunc i128 %u.12.extract.shift to i32
      %2 = insertelement <4 x i32> undef, i32 %u.12.extract.trunc, i64 0
      %3 = insertelement <4 x i32> %2, i32 %u.8.extract.trunc, i64 1
      %4 = insertelement <4 x i32> %3, i32 %u.4.extract.trunc, i64 2
      %5 = insertelement <4 x i32> %4, i32 %u.0.extract.trunc, i64 3
      %6 = bitcast <4 x i32> %5 to <2 x i64>
      ret <2 x i64> %6
    }

    _ZN12reverse_u32s20hbdb206aba18a03d8tbaE:
    	.cfi_startproc
    	movd	%xmm0, %rax
    	punpckhqdq	%xmm0, %xmm0
    	movd	%xmm0, %rcx
    	movq	%rcx, %rdx
    	shrq	$32, %rdx
    	movq	%rax, %rsi
    	shrq	$32, %rsi
    	movd	%eax, %xmm0
    	movd	%ecx, %xmm1
    	punpckldq	%xmm0, %xmm1
    	movd	%esi, %xmm2
    	movd	%edx, %xmm0
    	punpckldq	%xmm2, %xmm0
    	punpckldq	%xmm1, %xmm0
    	retq

After

    define <2 x i64> @_ZN12reverse_u32s20hbdb206aba18a03d8tbaE(<2 x i64>) unnamed_addr #0 {
    entry-block:
      %1 = bitcast <2 x i64> %0 to <4 x i32>
      %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
      %3 = bitcast <4 x i32> %2 to <2 x i64>
      ret <2 x i64> %3
    }

    _ZN12reverse_u32s20hbdb206aba18a03d8tbaE:
    	.cfi_startproc
    	pshufd	$27, %xmm0, %xmm0
    	retq
2014-12-03 17:15:02 -08:00
..
compiler-rt@62a4ca6055
compiletest Fixes to the roll-up 2014-11-23 15:23:39 -05:00
doc auto merge of #18140 : JelteF/rust-1/guide-fix, r=cmr 2014-11-23 13:51:47 +00:00
driver Register new snapshots 2014-11-21 14:15:33 -08:00
etc auto merge of #19021 : roysc/rust/emacs-pr, r=brson 2014-11-24 23:06:45 +00:00
grammar Adjust Antlr4 lexer to include suffixes. 2014-11-20 00:02:42 +11:00
jemalloc@b001609960 update jemalloc 2014-10-05 22:17:25 -04:00
liballoc rollup merge of #19225: reem/any-unnecessary-transmute-copy 2014-11-23 14:11:58 -05:00
libarena Remove lots of numeric traits from the preludes 2014-11-13 03:46:03 +11:00
libbacktrace
libcollections auto merge of #19236 : csouth3/rust/master, r=Gankro 2014-11-24 07:51:32 +00:00
libcore auto merge of #19248 : japaric/rust/str, r=alexcrichton 2014-11-24 11:56:34 +00:00
libcoretest core: Add Char::len_utf16 2014-11-21 13:17:09 -08:00
libflate std: Stabilize std::fmt 2014-11-18 21:16:22 -08:00
libfmt_macros unicode: Rename is_XID_start to is_xid_start, is_XID_continue to is_xid_continue 2014-11-21 13:18:08 -08:00
libgetopts unicode: Add stability attributes to u_char 2014-11-21 13:18:08 -08:00
libgraphviz core: Convert Char::escape_default, escape_unicode to iterators 2014-11-21 13:18:08 -08:00
liblibc Fallout from libgreen and libnative removal 2014-11-20 17:19:24 -08:00
liblog std: Add a new top-level thread_local module 2014-11-23 23:37:16 -08:00
librand auto merge of #19152 : alexcrichton/rust/issue-17863, r=aturon 2014-11-23 05:46:52 +00:00
librbml Rename remaining Failures to Panic 2014-11-20 23:45:42 +05:30
libregex Rename remaining Failures to Panic 2014-11-20 23:45:42 +05:30
libregex_macros rollup merge of #18398 : aturon/lint-conventions-2 2014-10-30 17:37:22 -07:00
librustc std: Add a new top-level thread_local module 2014-11-23 23:37:16 -08:00
librustc_back rollup merge of #19211: aochagavia/tuple-index 2014-11-23 14:11:56 -05:00
librustc_llvm Switch to purely namespaced enums 2014-11-17 07:35:51 -08:00
librustc_trans Special-case transmute for primitive, SIMD & pointer types. 2014-12-03 17:15:02 -08:00
librustdoc std: Add a new top-level thread_local module 2014-11-23 23:37:16 -08:00
librustrt std: Add a new top-level thread_local module 2014-11-23 23:37:16 -08:00
libserialize Clean up some logic/formatting in JSON module 2014-11-23 12:08:11 -05:00
libstd auto merge of #19285 : alexcrichton/rust/issue-19280, r=aturon 2014-11-25 01:06:41 +00:00
libsync Require <T: Send> for AtomicOption 2014-11-23 10:47:08 -08:00
libsyntax std: Add a new top-level thread_local module 2014-11-23 23:37:16 -08:00
libterm rollup merge of #19194: aturon/stab-ascii 2014-11-23 14:11:51 -05:00
libtest std: Stabilize std::fmt 2014-11-18 21:16:22 -08:00
libtime std: Stabilize std::fmt 2014-11-18 21:16:22 -08:00
libunicode unicode: Remove unused non_snake_case allows. 2014-11-21 13:18:08 -08:00
llvm@ec1fdb3b9d Update LLVM to get slightly better memcpy elision 2014-10-17 17:16:18 +02:00
rt remove the uv_support code 2014-10-02 05:05:12 -04:00
rustllvm optimize position independent code in executables 2014-10-12 09:18:14 -04:00
test auto merge of #19250 : kmcallister/rust/atomicoption, r=alexcrichton 2014-11-24 13:56:36 +00:00
README.md Fallout from libgreen and libnative removal 2014-11-20 17:19:24 -08:00
snapshots.txt Register new snapshots 2014-11-21 14:15:33 -08:00

This is a preliminary version of the Rust compiler, libraries and tools.

Source layout:

Path Description
librustc/ The self-hosted compiler
liballoc/ Rust's core allocation library
libcore/ The Rust core library
libdebug/ Debugging utilities
libstd/ The standard library (imported and linked by default)
libsyntax/ The Rust parser and pretty-printer
libtest/ Rust's test-runner code
------------------- ---------------------------------------------------------
libarena/ The arena (a fast but limited) memory allocator
libbacktrace/ The libbacktrace library
libcollections/ A collection of useful data structures and containers
libflate/ Simple compression library
libfmt_macros/ Macro support for format strings
libfourcc/ Data format identifier library
libgetopts/ Get command-line-options library
libglob/ Unix glob patterns library
libgraphviz/ Generating files for Graphviz
libhexfloat/ Hexadecimal floating-point literals
liblibc/ Bindings for the C standard library
liblog/ Utilities for program-wide and customizable logging
libnum/ Extended number support library (complex, rational, etc)
librand/ Random numbers and distributions
libregex/ Regular expressions
libregex_macros/ The regex! syntax extension
libsemver/ Rust's semantic versioning library
libserialize/ Encode-Decode types library
libsync/ Concurrency mechanisms and primitives
libterm/ ANSI color library for terminals
libtime/ Time operations library
liburl/ URL handling lirary
libuuid/ UUID's handling code
------------------- ---------------------------------------------------------
rt/ The runtime system
rt/rust_*.c - Some of the runtime services
rt/vg - Valgrind headers
rt/msvc - MSVC support
rt/sundown - The Markdown library used by rustdoc
------------------- ---------------------------------------------------------
compiletest/ The test runner
test/ Testsuite
test/codegen - Tests for the LLVM IR infrastructure
test/compile-fail - Tests that should fail to compile
test/debug-info - Tests for the debuginfo tool
test/run-fail - Tests that should compile, run and fail
test/run-make - Tests that depend on a Makefile infrastructure
test/run-pass - Tests that should compile, run and succeed
test/bench - Benchmarks and miscellaneous
test/pretty - Pretty-printer tests
test/auxiliary - Dependencies of tests
------------------- ---------------------------------------------------------
librustdoc/ The Rust API documentation tool
------------------- ---------------------------------------------------------
llvm/ The LLVM submodule
rustllvm/ LLVM support code
------------------- ---------------------------------------------------------
etc/ Scripts, editors support, misc

NOTE: This list (especially the second part of the table which contains modules and libraries) is highly volatile and subject to change.