Grieverheart/dsfmt-rs — pull request #2 by huonw (2014-11-25 08:55:27+00:00)
Title: Replace inline ASM with simd.

This has several advantages.

- it is faster in the microbenchmark (after a patch to rustc),
presumably due to the fact the compiler has full control over data
flow and data types, and so can arrange the loads optimally and avoid
unnecessarily placing things onto the stack. It also means the
compiler can see the SIMD vectors are always in the integer domain and
so use (on x86) MOVDQA rather than the floating-point MOVAPS, avoiding
the cross-domain penalties on platforms which have them.

- the library is now usable on x86 platforms without SSE2, and also on
non-x86 platforms, possibly at a performance penalty (but maybe not,
e.g. it may work with ARM's NEON), but this is better than not being
usable at all.

- the danger and problems of `asm!` is completely removed, replaced with
a pair of easy to verify `transmute`s.

Before:

test bench_mt19937_1_000_000_rands ... bench: 1606892 ns/iter (+/- 57461)

After, with rust-lang/rust#19294:

test bench_mt19937_1_000_000_rands ... bench: 1539038 ns/iter (+/- 33623)

Without that patch it takes `2787449 ns/iter`.

---

Also, `range_inclusive` always counts up, so `range_inclusive(1, 0)` is an
empty iterator. A correct way to iterate downwards is
`range_inclusive(0, 1).rev()`, that is, take an iterator `[0, 1]` and
run it backwards. (You can experiment with it on [the playpen](http://is.gd/osBsu6).)