#![allow(clippy::type_complexity)]
#![allow(unused_variables)]
#![allow(clippy::large_types_passed_by_value)]
use super::helpers::*;
use crate::dag::{DagArmSeed, DagBuilder};
use crate::pipeline::PipelineBuilder;
use crate::{Handler, IntoHandler, World};
#[inline(never)]
pub fn stress_pipe_30_steps(world: &mut World, input: u64) -> u64 {
let reg = world.registry();
let mut p = PipelineBuilder::<u64>::new()
.then(add_one, ®)
.then(double, ®)
.then(add_three, ®)
.then(square, ®)
.then(sub_ten, ®)
.then(shr_one, ®)
.then(xor_mask, ®)
.then(add_seven, ®)
.then(triple, ®)
.then(add_forty_two, ®)
.then(add_one, ®)
.then(double, ®)
.then(add_three, ®)
.then(square, ®)
.then(sub_ten, ®)
.then(shr_one, ®)
.then(xor_mask, ®)
.then(add_seven, ®)
.then(triple, ®)
.then(add_forty_two, ®)
.then(add_one, ®)
.then(double, ®)
.then(add_three, ®)
.then(square, ®)
.then(sub_ten, ®)
.then(shr_one, ®)
.then(xor_mask, ®)
.then(add_seven, ®)
.then(triple, ®)
.then(add_forty_two, ®);
p.run(world, input)
}
#[inline(never)]
pub fn stress_pipe_50_steps(world: &mut World, input: u64) -> u64 {
let reg = world.registry();
let mut p = PipelineBuilder::<u64>::new()
.then(add_one, ®)
.then(double, ®)
.then(add_three, ®)
.then(square, ®)
.then(sub_ten, ®)
.then(shr_one, ®)
.then(xor_mask, ®)
.then(add_seven, ®)
.then(triple, ®)
.then(add_forty_two, ®)
.then(add_one, ®)
.then(double, ®)
.then(add_three, ®)
.then(square, ®)
.then(sub_ten, ®)
.then(shr_one, ®)
.then(xor_mask, ®)
.then(add_seven, ®)
.then(triple, ®)
.then(add_forty_two, ®)
.then(add_one, ®)
.then(double, ®)
.then(add_three, ®)
.then(square, ®)
.then(sub_ten, ®)
.then(shr_one, ®)
.then(xor_mask, ®)
.then(add_seven, ®)
.then(triple, ®)
.then(add_forty_two, ®)
.then(add_one, ®)
.then(double, ®)
.then(add_three, ®)
.then(square, ®)
.then(sub_ten, ®)
.then(shr_one, ®)
.then(xor_mask, ®)
.then(add_seven, ®)
.then(triple, ®)
.then(add_forty_two, ®)
.then(add_one, ®)
.then(double, ®)
.then(add_three, ®)
.then(square, ®)
.then(sub_ten, ®)
.then(shr_one, ®)
.then(xor_mask, ®)
.then(add_seven, ®)
.then(triple, ®)
.then(add_forty_two, ®);
p.run(world, input)
}
#[inline(never)]
pub fn stress_pipe_all_combinators(world: &mut World, input: u64) -> u64 {
let reg = world.registry();
fn log_error(_err: u32) {}
let tee_side = DagArmSeed::<u64>::new().then(ref_consume, ®);
let on_true = PipelineBuilder::<u64>::new().then(double, ®);
let on_false = PipelineBuilder::<u64>::new().then(add_one, ®);
let mut p = PipelineBuilder::<u64>::new()
.then(add_one, ®) .tap(|_x: &u64| {}, ®) .tee(tee_side) .guard(|x: &u64| *x > 0, ®) .filter(|x: &u64| *x < 10000, ®) .inspect(|_x: &u64| {}, ®) .on_none(|| {}, ®) .ok_or(0u32) .map(double, ®) .inspect(|_x: &u64| {}, ®) .inspect_err(|_e: &u32| {}, ®) .map_err(|e: u32| e, ®) .catch(log_error, ®) .unwrap_or(0) .then(add_three, ®) .then(is_even, ®) .and(|| true, ®) .or(|| false, ®) .not() .xor(|| true, ®) .then(|b: bool| if b { 100u64 } else { 0u64 }, ®) .route(|x: &u64| *x > 50, ®, on_true, on_false); p.run(world, input)
}
#[inline(never)]
pub fn stress_pipe_transition_chain(world: &mut World, input: u64) -> u64 {
let reg = world.registry();
fn log_error(_err: u32) {}
let mut p = PipelineBuilder::<u64>::new()
.then(|x: u64| x, ®)
.guard(|x: &u64| *x > 0, ®)
.ok_or(0u32)
.catch(log_error, ®)
.unwrap_or(0)
.guard(|x: &u64| *x > 0, ®)
.ok_or(0u32)
.catch(log_error, ®)
.unwrap_or(0)
.then(add_one, ®);
p.run(world, input)
}
#[inline(never)]
pub fn stress_pipe_route_4_deep(world: &mut World, input: u64) -> u64 {
let reg = world.registry();
let l1 = PipelineBuilder::<u64>::new().then(add_one, ®);
let l2 = PipelineBuilder::<u64>::new().then(double, ®);
let l3 = PipelineBuilder::<u64>::new().then(add_three, ®);
let l4 = PipelineBuilder::<u64>::new().then(triple, ®);
let l5 = PipelineBuilder::<u64>::new().then(add_seven, ®);
let l6 = PipelineBuilder::<u64>::new().then(square, ®);
let l7 = PipelineBuilder::<u64>::new().then(sub_ten, ®);
let l8 = PipelineBuilder::<u64>::new().then(shr_one, ®);
let r3a =
PipelineBuilder::<u64>::new()
.then(|x: u64| x, ®)
.route(|x: &u64| *x > 10, ®, l1, l2);
let r3b =
PipelineBuilder::<u64>::new()
.then(|x: u64| x, ®)
.route(|x: &u64| *x > 20, ®, l3, l4);
let r3c =
PipelineBuilder::<u64>::new()
.then(|x: u64| x, ®)
.route(|x: &u64| *x > 30, ®, l5, l6);
let r3d =
PipelineBuilder::<u64>::new()
.then(|x: u64| x, ®)
.route(|x: &u64| *x > 40, ®, l7, l8);
let r2a = PipelineBuilder::<u64>::new().then(|x: u64| x, ®).route(
|x: &u64| *x > 50,
®,
r3a,
r3b,
);
let r2b = PipelineBuilder::<u64>::new().then(|x: u64| x, ®).route(
|x: &u64| *x > 60,
®,
r3c,
r3d,
);
let mut p = PipelineBuilder::<u64>::new().then(|x: u64| x, ®).route(
|x: &u64| *x > 100,
®,
r2a,
r2b,
);
p.run(world, input)
}
#[inline(never)]
pub fn stress_dag_fork_route_mix(world: &mut World, input: u64) {
let reg = world.registry();
let on_true = DagArmSeed::<u64>::new().then(ref_double, ®);
let on_false = DagArmSeed::<u64>::new().then(ref_triple, ®);
let mut d = DagBuilder::<u64>::new()
.root(add_one, ®)
.fork()
.arm(|a| {
a.then(ref_add_one, ®)
.route(|x: &u64| *x > 50, ®, on_true, on_false)
})
.arm(|a| a.then(ref_add_seven, ®))
.arm(|a| a.then(ref_square, ®))
.merge(merge_3, ®)
.then(ref_consume, ®)
.build();
d.run(world, input);
}
#[inline(never)]
pub fn stress_batch_pipe_30_steps(world: &mut World) {
let reg = world.registry();
let mut bp = PipelineBuilder::<u64>::new()
.then(add_one, ®)
.then(double, ®)
.then(add_three, ®)
.then(square, ®)
.then(sub_ten, ®)
.then(shr_one, ®)
.then(xor_mask, ®)
.then(add_seven, ®)
.then(triple, ®)
.then(add_forty_two, ®)
.then(add_one, ®)
.then(double, ®)
.then(add_three, ®)
.then(square, ®)
.then(sub_ten, ®)
.then(shr_one, ®)
.then(xor_mask, ®)
.then(add_seven, ®)
.then(triple, ®)
.then(add_forty_two, ®)
.then(add_one, ®)
.then(double, ®)
.then(add_three, ®)
.then(square, ®)
.then(sub_ten, ®)
.then(shr_one, ®)
.then(xor_mask, ®)
.then(add_seven, ®)
.then(triple, ®)
.then(add_forty_two, ®)
.then(consume_val, ®)
.build_batch(64);
bp.input_mut().extend(0..64);
bp.run(world);
}
#[inline(never)]
pub fn stress_batch_dag_nested(world: &mut World) {
let reg = world.registry();
let mut bd = DagBuilder::<u64>::new()
.root(add_one, ®)
.fork()
.arm(|a| {
a.then(ref_double, ®)
.fork()
.arm(|b| b.then(ref_add_one, ®))
.arm(|b| b.then(ref_triple, ®))
.merge(merge_add, ®)
})
.arm(|a| a.then(ref_add_seven, ®))
.merge(merge_add, ®)
.then(ref_consume, ®)
.build_batch(64);
bd.input_mut().extend(0..64);
bd.run(world);
}
#[inline(never)]
pub fn stress_pipe_large_type(world: &mut World, input: u64) -> [u8; 4096] {
fn make_large(x: u64) -> [u8; 4096] {
let mut arr = [0u8; 4096];
arr[0] = x as u8;
arr
}
fn touch_large(x: [u8; 4096]) -> [u8; 4096] {
let mut out = x;
out[1] = out[0].wrapping_add(1);
out
}
let reg = world.registry();
let mut p = PipelineBuilder::<u64>::new()
.then(make_large, ®)
.then(touch_large, ®)
.then(touch_large, ®);
p.run(world, input)
}
#[inline(never)]
pub fn stress_pipe_many_closures(world: &mut World, input: u64) -> u64 {
let reg = world.registry();
let mut p = PipelineBuilder::<u64>::new()
.then(|x: u64| x, ®)
.guard(|x: &u64| *x > 0, ®)
.filter(|x: &u64| *x < 10000, ®)
.filter(|x: &u64| *x > 5, ®)
.inspect(|_x: &u64| {}, ®)
.on_none(|| {}, ®)
.map(double, ®)
.filter(|x: &u64| *x < 50000, ®)
.filter(|x: &u64| *x > 1, ®)
.inspect(|_x: &u64| {}, ®)
.unwrap_or_else(|| 0, ®)
.then(add_one, ®);
p.run(world, input)
}
#[inline(never)]
pub fn stress_dag_wide_fork(world: &mut World, input: u64) {
let reg = world.registry();
let mut d = DagBuilder::<u64>::new()
.root(add_one, ®)
.fork()
.arm(|a| {
a.then(ref_double, ®)
.fork()
.arm(|b| b.then(ref_add_one, ®))
.arm(|b| b.then(ref_triple, ®))
.arm(|b| b.then(ref_add_seven, ®))
.arm(|b| b.then(ref_xor_mask, ®))
.merge(merge_4, ®)
})
.arm(|a| {
a.then(ref_triple, ®)
.fork()
.arm(|b| b.then(ref_square, ®))
.arm(|b| b.then(ref_shr_one, ®))
.arm(|b| b.then(ref_sub_ten, ®))
.arm(|b| b.then(ref_add_forty_two, ®))
.merge(merge_4, ®)
})
.arm(|a| {
a.then(ref_add_seven, ®)
.fork()
.arm(|b| b.then(ref_double, ®))
.arm(|b| b.then(ref_add_three, ®))
.arm(|b| b.then(ref_triple, ®))
.arm(|b| b.then(ref_add_one, ®))
.merge(merge_4, ®)
})
.arm(|a| {
a.then(ref_xor_mask, ®)
.fork()
.arm(|b| b.then(ref_shr_one, ®))
.arm(|b| b.then(ref_sub_ten, ®))
.arm(|b| b.then(ref_square, ®))
.arm(|b| b.then(ref_add_forty_two, ®))
.merge(merge_4, ®)
})
.merge(merge_4, ®)
.then(ref_consume, ®)
.build();
d.run(world, input);
}
#[inline(never)]
pub fn stress_pipe_splat_chain(world: &mut World, input: u64) -> u64 {
let reg = world.registry();
let mut p = PipelineBuilder::<u64>::new()
.then(split_u64, ®)
.splat()
.then(splat_add, ®)
.then(split_u64, ®)
.splat()
.then(splat_add, ®);
p.run(world, input)
}
#[inline(never)]
pub fn stress_pipe_dedup_in_batch(world: &mut World) {
let reg = world.registry();
let mut bp = PipelineBuilder::<u64>::new()
.then(add_one, ®)
.dedup()
.map(double, ®)
.unwrap_or(0)
.then(consume_val, ®)
.build_batch(64);
bp.input_mut().extend(0..64);
bp.run(world);
}
#[inline(never)]
pub fn stress_pipe_tee_in_route(world: &mut World, input: u64) -> u64 {
let reg = world.registry();
let tee_side = DagArmSeed::<u64>::new()
.then(ref_add_one, ®)
.then(ref_double, ®)
.then(ref_consume, ®);
let arm_t = PipelineBuilder::<u64>::new()
.then(double, ®)
.tee(tee_side)
.then(add_three, ®);
let arm_f = PipelineBuilder::<u64>::new().then(add_one, ®);
let mut p = PipelineBuilder::<u64>::new().then(|x: u64| x, ®).route(
|x: &u64| *x > 100,
®,
arm_t,
arm_f,
);
p.run(world, input)
}
#[inline(never)]
pub fn stress_mixed_everything(world: &mut World, input: u64) {
let reg = world.registry();
fn log_error(_err: u32) {}
let tee_side = DagArmSeed::<u64>::new().then(ref_consume, ®);
let on_true = PipelineBuilder::<u64>::new().then(double, ®);
let on_false = PipelineBuilder::<u64>::new().then(add_one, ®);
let handler = consume_val.into_handler(®);
let mut p = PipelineBuilder::<u64>::new()
.then(add_one, ®)
.tap(|_x: &u64| {}, ®)
.tee(tee_side)
.guard(|x: &u64| *x > 0, ®)
.map(double, ®)
.filter(|x: &u64| *x < 100_000, ®)
.ok_or(0u32)
.map(add_three, ®)
.catch(log_error, ®)
.unwrap_or(0)
.route(|x: &u64| *x > 50, ®, on_true, on_false)
.then(split_u64, ®)
.splat()
.then(splat_add, ®)
.dispatch(handler);
p.run(world, input);
}