use super::{Op, Resources};
pub const BUDGET: Resources = Resources::new(0x1412316);
pub const SPILL_COST: Resources = Resources::new(0x0010202);
pub const SLOT_COST: Resources = Resources::new(0x0001100);
#[derive(Debug)]
pub struct Cost {
pub latency: u8,
pub resources: Resources,
}
pub const INPUT_COST: Cost = Cost {
latency: 0,
resources: Resources::new(0x0000000),
};
pub const GUARD_COST: Cost = Cost {
latency: 0xFF,
resources: Resources::new(0x0100012),
};
pub const CONST_COST: Cost = Cost {
latency: 0,
resources: Resources::new(0x0100001),
};
pub const UNARY_COST: Cost = Cost {
latency: 1,
resources: Resources::new(0x0100001),
};
pub const BINARY_COST: Cost = Cost {
latency: 1,
resources: Resources::new(0x0100001),
};
pub const ABS_COST: Cost = Cost {
latency: 2,
resources: Resources::new(0x0200013),
};
pub const CONDITIONAL_COST: Cost = Cost {
latency: 2,
resources: Resources::new(0x0200013),
};
pub const MUL_COST: Cost = Cost {
latency: 3,
resources: Resources::new(0x1100001),
};
pub const DIV_COST: Cost = Cost {
latency: 30,
resources: Resources::new(0x1012306),
};
pub const SHIFT_COST: Cost = Cost {
latency: 1,
resources: Resources::new(0x0100002),
};
pub const LOAD_COST: Cost = Cost {
latency: 3,
resources: Resources::new(0x0001101),
};
pub const STORE_COST: Cost = Cost {
latency: 0,
resources: Resources::new(0x0010101),
};
pub const SEND_COST: Cost = Cost {
latency: 0,
resources: Resources::new(0x0000000),
};
pub const DEBUG_COST: Cost = Cost {
latency: 0xFF,
resources: Resources::new(0x0000000),
};
#[allow(clippy::module_name_repetitions)]
pub fn op_cost(op: Op) -> &'static Cost {
use Op::*;
use super::code::{UnaryOp::*, BinaryOp::*};
match op {
Guard => &GUARD_COST,
Input => &INPUT_COST,
Constant(_) => &CONST_COST, Unary(_, op) => match op {
Abs => &ABS_COST,
Negate | Not => &UNARY_COST,
},
Binary(_, op) => match op {
Add | Sub | And| Or| Xor => &BINARY_COST,
Mul => &MUL_COST,
UDiv | SDiv => &DIV_COST,
Lsl | Lsr | Asr => &SHIFT_COST,
Lt | Ult | Eq | Max | Min => &CONDITIONAL_COST,
},
Load(_, _) => &LOAD_COST,
Store(_, _) => &STORE_COST,
Send => &SEND_COST,
Debug => &DEBUG_COST,
}
}