This file contains hidden or 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
//! Calculates the probabilities of acceptance for various methods of random uniform sampling from | |
//! integer ranges. | |
use std::num::Wrapping; | |
use std::ops::Neg; | |
fn wmul(x: u8, y: u8) -> (u8, u8) { | |
let m = x as u16 * y as u16; | |
let hi = (m >> 8) as u8; | |
let lo = m as u8; |
This file contains hidden or 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
#![feature(test)] | |
#![feature(stdsimd)] | |
extern crate rand; | |
extern crate test; | |
use std::simd::*; | |
use std::mem; | |
use test::black_box; |
This file contains hidden or 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
macro_rules! simd_float_impls { | |
($ty:ident, $uty:ident, $f_scalar:ty, $u_scalar:ty, $fraction_bits:expr, $exponent_bias:expr, | |
$next_u:ident) => { | |
impl IntoFloat for $uty { | |
type F = $ty; | |
#[inline(always)] | |
fn into_float_with_exponent(self, exponent: i32) -> $ty { | |
// The exponent is encoded using an offset-binary representation | |
let exponent_bits: $u_scalar = | |
(($exponent_bias + exponent) as $u_scalar) << $fraction_bits; |
This file contains hidden or 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
import Foundation | |
private let measurements = 1_000 | |
private func measureExecutionTime(_ title: String, f: (() -> Any) ) { | |
let start = Date() | |
var result: Any? | |
for _ in 0..<measurements { | |
result = f() | |
} | |
let end = Date() |