Skip to content

Instantly share code, notes, and snippets.

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()
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;
@TheIronBorn
TheIronBorn / simd_pi_sim.rs
Last active May 31, 2022 21:19
Benchmarking Monte Carlo estimation of pi, using my SIMD branch of the rand crate https://github.com/TheIronBorn/rand/tree/simd
#![feature(test)]
#![feature(stdsimd)]
extern crate rand;
extern crate test;
use std::simd::*;
use std::mem;
use test::black_box;
//! 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;