Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rand: inform the optimiser that indexing is never out-of-bounds.
This uses a bitwise mask to ensure that there's no bounds checking for the array accesses when generating the next random number. This isn't costless, but the single instruction is nothing compared to the branch. A `debug_assert` for "bounds check" is preserved to ensure that refactoring doesn't accidentally break it (i.e. create values of `cnt` that are out of bounds with the masking causing it to silently wrap- around). Before: test test::rand_isaac ... bench: 990 ns/iter (+/- 24) = 808 MB/s test test::rand_isaac64 ... bench: 614 ns/iter (+/- 25) = 1302 MB/s After: test test::rand_isaac ... bench: 877 ns/iter (+/- 134) = 912 MB/s test test::rand_isaac64 ... bench: 470 ns/iter (+/- 30) = 1702 MB/s (It also removes the unsafe code in Isaac64Rng.next_u64, with a *gain* in performance; today is a good day.)
- Loading branch information
cc6a487
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from alexcrichton
at huonw@cc6a487
cc6a487
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging huonw/rust/isaac-oob-- = cc6a487 into auto
cc6a487
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
huonw/rust/isaac-oob-- = cc6a487 merged ok, testing candidate = 30e24f98
cc6a487
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some tests failed:
failure: http://buildbot.rust-lang.org/builders/auto-win32-32-nopt-t/builds/91
exception: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/1261
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/1260
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/1260
exception: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/1261
exception: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/1255
exception: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/1254
exception: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/1255
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/1259
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/1254
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/1254
exception: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android-t/builds/1258
exception: http://buildbot.rust-lang.org/builders/auto-win32-32-opt/builds/91
exception: http://buildbot.rust-lang.org/builders/auto-win32-32-nopt-c/builds/91
exception: http://buildbot.rust-lang.org/builders/auto-win64-64-nopt-t/builds/91
cc6a487
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from alexcrichton
at huonw@cc6a487
cc6a487
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging huonw/rust/isaac-oob-- = cc6a487 into auto
cc6a487
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
huonw/rust/isaac-oob-- = cc6a487 merged ok, testing candidate = 3884f5f
cc6a487
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all tests pass:
success: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/1270
success: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/1269
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/1269
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/1270
success: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/1264
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/1263
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/1264
success: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/1268
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/1263
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/1263
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android-t/builds/1267
success: http://buildbot.rust-lang.org/builders/auto-win32-32-opt/builds/100
success: http://buildbot.rust-lang.org/builders/auto-win32-32-nopt-t/builds/100
success: http://buildbot.rust-lang.org/builders/auto-win32-32-nopt-c/builds/100
success: http://buildbot.rust-lang.org/builders/auto-win64-64-opt/builds/100
success: http://buildbot.rust-lang.org/builders/auto-win64-64-nopt-t/builds/100
success: http://buildbot.rust-lang.org/builders/auto-win64-64-nopt-c/builds/100
cc6a487
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fast-forwarding master to auto = 3884f5f