2022-11-25 13:34:46 +08:00
|
|
|
use std::{collections::HashMap, ptr::NonNull};
|
|
|
|
|
|
|
|
use colored::Colorize;
|
|
|
|
use indicatif::{ProgressBar, ProgressStyle};
|
|
|
|
use rayon::prelude::*;
|
2022-11-20 11:20:09 +08:00
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
mod npnr;
|
2022-11-21 10:48:00 +08:00
|
|
|
|
|
|
|
enum Subpartition {
|
|
|
|
Part(Box<Partition>),
|
|
|
|
Nets(Vec<Net>),
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Partition {
|
|
|
|
parts: [Option<Subpartition>; 4],
|
2022-11-23 11:31:50 +08:00
|
|
|
borders: [[Vec<npnr::WireId>; 4]; 4],
|
2022-11-21 10:48:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Net {
|
|
|
|
source: npnr::WireId,
|
2022-11-23 11:31:50 +08:00
|
|
|
sinks: Vec<npnr::WireId>,
|
2022-11-21 10:48:00 +08:00
|
|
|
}
|
2022-11-20 11:20:09 +08:00
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn npnr_router_awooter(ctx: Option<NonNull<npnr::Context>>) -> bool {
|
|
|
|
std::panic::catch_unwind(move || {
|
|
|
|
let ctx: &mut npnr::Context = unsafe { ctx.expect("non-null context").as_mut() };
|
|
|
|
route(ctx)
|
|
|
|
})
|
|
|
|
.unwrap_or_else(|x| {
|
|
|
|
if let Ok(x) = x.downcast::<String>() {
|
|
|
|
log_error!("caught panic: {}", x);
|
|
|
|
}
|
|
|
|
false
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-11-23 11:31:50 +08:00
|
|
|
type ArcVec = Vec<((i32, i32), (i32, i32))>;
|
|
|
|
|
|
|
|
fn find_partition_point(
|
2022-11-25 13:34:46 +08:00
|
|
|
ctx: &npnr::Context,
|
|
|
|
nets: &npnr::Nets,
|
|
|
|
pips: &[npnr::PipId],
|
2022-11-23 11:31:50 +08:00
|
|
|
x_start: i32,
|
|
|
|
x_finish: i32,
|
|
|
|
y_start: i32,
|
|
|
|
y_finish: i32,
|
|
|
|
) -> (i32, i32, ArcVec, ArcVec, ArcVec, ArcVec) {
|
|
|
|
let mut x = ((x_finish - x_start) / 2) + x_start;
|
|
|
|
let mut y = ((y_finish - y_start) / 2) + y_start;
|
|
|
|
let mut x_diff = (x_finish - x_start) / 4;
|
|
|
|
let mut y_diff = (y_finish - y_start) / 4;
|
|
|
|
|
|
|
|
let mut ne = Vec::new();
|
|
|
|
let mut se = Vec::new();
|
|
|
|
let mut sw = Vec::new();
|
|
|
|
let mut nw = Vec::new();
|
|
|
|
|
|
|
|
while x_diff != 0 {
|
2022-11-25 13:34:46 +08:00
|
|
|
(ne, se, sw, nw) = partition_nets(ctx, nets, pips, x, y);
|
2022-11-23 11:31:50 +08:00
|
|
|
let north = ne.len() + nw.len();
|
|
|
|
let south = se.len() + sw.len();
|
2022-11-25 13:34:46 +08:00
|
|
|
|
|
|
|
let nets = (north + south) as f64;
|
|
|
|
|
|
|
|
let ne_dist = f64::abs(((ne.len() as f64) / nets) - 0.25);
|
|
|
|
let se_dist = f64::abs(((se.len() as f64) / nets) - 0.25);
|
|
|
|
let sw_dist = f64::abs(((sw.len() as f64) / nets) - 0.25);
|
|
|
|
let nw_dist = f64::abs(((nw.len() as f64) / nets) - 0.25);
|
|
|
|
|
|
|
|
let distortion = 100.0 * (ne_dist + se_dist + sw_dist + nw_dist);
|
|
|
|
|
|
|
|
// Stop early if Good Enough.
|
|
|
|
if distortion <= 5.0 {
|
|
|
|
return (x, y, ne, se, sw, nw);
|
|
|
|
}
|
|
|
|
|
2022-11-26 20:44:17 +08:00
|
|
|
x += match north.cmp(&south) {
|
|
|
|
std::cmp::Ordering::Less => x_diff,
|
|
|
|
std::cmp::Ordering::Equal => 0,
|
|
|
|
std::cmp::Ordering::Greater => -x_diff,
|
|
|
|
};
|
2022-11-23 11:31:50 +08:00
|
|
|
|
|
|
|
let east = ne.len() + se.len();
|
|
|
|
let west = nw.len() + sw.len();
|
2022-11-26 20:44:17 +08:00
|
|
|
y += match east.cmp(&west) {
|
|
|
|
std::cmp::Ordering::Less => y_diff,
|
|
|
|
std::cmp::Ordering::Equal => 0,
|
|
|
|
std::cmp::Ordering::Greater => -y_diff,
|
|
|
|
};
|
2022-11-23 11:31:50 +08:00
|
|
|
|
|
|
|
x_diff >>= 1;
|
|
|
|
y_diff >>= 1;
|
|
|
|
}
|
|
|
|
|
2022-11-25 13:34:46 +08:00
|
|
|
(ne, se, sw, nw) = partition_nets(ctx, nets, pips, x, y);
|
2022-11-23 11:31:50 +08:00
|
|
|
|
|
|
|
let north = ne.len() + nw.len();
|
|
|
|
let south = se.len() + sw.len();
|
|
|
|
let nets = (north + south) as f64;
|
|
|
|
|
|
|
|
let ne_dist = f64::abs(((ne.len() as f64) / nets) - 0.25);
|
|
|
|
let se_dist = f64::abs(((se.len() as f64) / nets) - 0.25);
|
|
|
|
let sw_dist = f64::abs(((sw.len() as f64) / nets) - 0.25);
|
|
|
|
let nw_dist = f64::abs(((nw.len() as f64) / nets) - 0.25);
|
|
|
|
|
|
|
|
log_info!(
|
|
|
|
"Distortion: {:.02}%\n",
|
|
|
|
100.0 * (ne_dist + se_dist + sw_dist + nw_dist)
|
|
|
|
);
|
|
|
|
|
|
|
|
(x, y, ne, se, sw, nw)
|
|
|
|
}
|
|
|
|
|
2022-11-25 13:34:46 +08:00
|
|
|
fn partition_nets(
|
|
|
|
ctx: &npnr::Context,
|
|
|
|
nets: &npnr::Nets,
|
|
|
|
pips: &[npnr::PipId],
|
|
|
|
x: i32,
|
|
|
|
y: i32,
|
|
|
|
) -> (ArcVec, ArcVec, ArcVec, ArcVec) {
|
|
|
|
let mut partition_pips = HashMap::new();
|
|
|
|
|
|
|
|
let mut ne = Vec::new();
|
|
|
|
let mut se = Vec::new();
|
|
|
|
let mut sw = Vec::new();
|
|
|
|
let mut nw = Vec::new();
|
|
|
|
let mut part_horiz = 0;
|
|
|
|
let mut part_vert = 0;
|
|
|
|
let mut part_diag = 0;
|
|
|
|
|
|
|
|
let x_str = format!("X = {}", x);
|
|
|
|
let y_str = format!("Y = {}", y);
|
|
|
|
log_info!(
|
|
|
|
"Partitioning arcs along {}, {}\n",
|
2022-11-26 20:44:17 +08:00
|
|
|
x_str.bold(),
|
|
|
|
y_str.bold()
|
2022-11-25 13:34:46 +08:00
|
|
|
);
|
|
|
|
|
2022-11-26 20:44:17 +08:00
|
|
|
// BUG: because pips don't specify direction, this puts pips of opposite directions
|
|
|
|
// in the same entry. This is bad, since it could lead to selecting a pip of the
|
|
|
|
// wrong direction.
|
|
|
|
//let mut pips_e2w = HashMap::new();
|
|
|
|
//let mut pips_w2e = HashMap::new();
|
|
|
|
|
2022-11-25 13:34:46 +08:00
|
|
|
for &pip in pips {
|
|
|
|
let loc = ctx.pip_location(pip);
|
|
|
|
if loc.x == x || loc.y == y {
|
2022-11-26 20:44:17 +08:00
|
|
|
let src = ctx.pip_src_wire(pip);
|
|
|
|
let dst = ctx.pip_dst_wire(pip);
|
|
|
|
|
2022-11-25 13:34:46 +08:00
|
|
|
partition_pips
|
|
|
|
.entry((loc.x, loc.y))
|
|
|
|
.and_modify(|pip_list: &mut Vec<(npnr::PipId, Vec<npnr::IdString>)>| {
|
|
|
|
pip_list.push((pip, Vec::new()))
|
|
|
|
})
|
|
|
|
.or_insert_with(|| vec![(pip, Vec::new())]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let progress = ProgressBar::new(nets.len() as u64);
|
|
|
|
progress.set_style(
|
2022-11-26 20:44:17 +08:00
|
|
|
ProgressStyle::with_template("[{elapsed}] [{bar:40.cyan/blue}] {msg}")
|
|
|
|
.unwrap()
|
|
|
|
.progress_chars("━╸ "),
|
2022-11-25 13:34:46 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
for (name, net) in nets.iter() {
|
|
|
|
let mut message = ctx.name_of(*name).to_str().unwrap().to_string();
|
2022-11-25 15:12:14 +08:00
|
|
|
let message = if message.len() > 31 {
|
|
|
|
message.truncate(28);
|
2022-11-25 13:34:46 +08:00
|
|
|
format!("{}...", message)
|
|
|
|
} else {
|
|
|
|
message
|
|
|
|
};
|
|
|
|
progress.set_message(message);
|
|
|
|
progress.inc(1);
|
|
|
|
let net = unsafe { net.as_mut().unwrap() };
|
|
|
|
|
|
|
|
if net.is_global() {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let source = unsafe { net.driver().as_ref().unwrap() };
|
|
|
|
|
|
|
|
let source = source.cell();
|
|
|
|
if source.is_none() {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let source = source.unwrap().location();
|
|
|
|
let source_is_north = source.x < x;
|
|
|
|
let source_is_east = source.y < y;
|
|
|
|
let source_wire = ctx.source_wire(net);
|
|
|
|
|
|
|
|
for sink in nets.users_by_name(*name).unwrap().iter() {
|
|
|
|
let sink = unsafe { sink.as_ref().unwrap() };
|
|
|
|
let sink_loc = sink.cell().unwrap().location();
|
|
|
|
let sink_is_north = sink_loc.x < x;
|
|
|
|
let sink_is_east = sink_loc.y < y;
|
|
|
|
|
|
|
|
for sink_wire in ctx.sink_wires(net, sink) {
|
|
|
|
if source_is_north == sink_is_north && source_is_east == sink_is_east {
|
|
|
|
let arc = ((source.x, source.y), (sink_loc.x, sink_loc.y));
|
|
|
|
match (source_is_north, source_is_east) {
|
|
|
|
(true, true) => ne.push(arc),
|
|
|
|
(true, false) => nw.push(arc),
|
|
|
|
(false, true) => se.push(arc),
|
|
|
|
(false, false) => sw.push(arc),
|
|
|
|
}
|
|
|
|
} else if source_is_north != sink_is_north && source_is_east == sink_is_east {
|
|
|
|
let middle = ((source.x + sink_loc.x) / 2, y);
|
|
|
|
let pips = partition_pips.get_mut(&middle).unwrap();
|
|
|
|
|
|
|
|
let (selected_pip, pip_uses) = pips
|
|
|
|
.par_iter_mut()
|
2022-11-26 20:44:17 +08:00
|
|
|
.min_by_key(|(pip, uses)| {
|
2022-11-25 13:34:46 +08:00
|
|
|
let src_to_pip =
|
|
|
|
ctx.estimate_delay(source_wire, ctx.pip_src_wire(*pip));
|
|
|
|
let pip_to_snk = ctx.estimate_delay(ctx.pip_dst_wire(*pip), sink_wire);
|
|
|
|
let uses = uses.len() - (uses.contains(name) as usize);
|
|
|
|
(1000.0 * (src_to_pip + ((uses + 1) as f32) * pip_to_snk)) as u64
|
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
pip_uses.push(*name);
|
|
|
|
|
|
|
|
let pip_loc = ctx.pip_location(*selected_pip);
|
|
|
|
let src_to_pip = ((source.x, source.y), (pip_loc.x, pip_loc.y));
|
|
|
|
let pip_to_dst = ((pip_loc.x, pip_loc.y), (sink_loc.x, sink_loc.y));
|
|
|
|
match (source_is_north, source_is_east) {
|
|
|
|
(true, true) => {
|
|
|
|
ne.push(src_to_pip);
|
|
|
|
se.push(pip_to_dst);
|
|
|
|
}
|
|
|
|
(true, false) => {
|
|
|
|
nw.push(src_to_pip);
|
|
|
|
sw.push(pip_to_dst);
|
|
|
|
}
|
|
|
|
(false, true) => {
|
|
|
|
se.push(src_to_pip);
|
|
|
|
ne.push(pip_to_dst);
|
|
|
|
}
|
|
|
|
(false, false) => {
|
|
|
|
sw.push(src_to_pip);
|
|
|
|
nw.push(pip_to_dst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
part_horiz += 1;
|
|
|
|
} else if source_is_north == sink_is_north && source_is_east != sink_is_east {
|
|
|
|
let middle = (x, (source.y + sink_loc.y) / 2);
|
|
|
|
let pips = partition_pips.get_mut(&middle).unwrap();
|
|
|
|
|
|
|
|
let (selected_pip, pip_uses) = pips
|
|
|
|
.par_iter_mut()
|
2022-11-26 20:44:17 +08:00
|
|
|
.min_by_key(|(pip, uses)| {
|
2022-11-25 13:34:46 +08:00
|
|
|
let src_to_pip =
|
|
|
|
ctx.estimate_delay(source_wire, ctx.pip_src_wire(*pip));
|
|
|
|
let pip_to_snk = ctx.estimate_delay(ctx.pip_dst_wire(*pip), sink_wire);
|
|
|
|
let uses = uses.len() - (uses.contains(name) as usize);
|
|
|
|
(1000.0 * (src_to_pip + ((uses + 1) as f32) * pip_to_snk)) as u64
|
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
pip_uses.push(*name);
|
|
|
|
|
|
|
|
let pip_loc = ctx.pip_location(*selected_pip);
|
|
|
|
let src_to_pip = ((source.x, source.y), (pip_loc.x, pip_loc.y));
|
|
|
|
let pip_to_dst = ((pip_loc.x, pip_loc.y), (sink_loc.x, sink_loc.y));
|
|
|
|
match (source_is_north, source_is_east) {
|
|
|
|
(true, true) => {
|
|
|
|
ne.push(src_to_pip);
|
|
|
|
nw.push(pip_to_dst);
|
|
|
|
}
|
|
|
|
(true, false) => {
|
|
|
|
nw.push(src_to_pip);
|
|
|
|
ne.push(pip_to_dst);
|
|
|
|
}
|
|
|
|
(false, true) => {
|
|
|
|
se.push(src_to_pip);
|
|
|
|
sw.push(pip_to_dst);
|
|
|
|
}
|
|
|
|
(false, false) => {
|
|
|
|
sw.push(src_to_pip);
|
|
|
|
se.push(pip_to_dst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
part_vert += 1;
|
|
|
|
} else {
|
2022-11-26 20:44:17 +08:00
|
|
|
// BUG: this doesn't bound the pip to be strictly east or west,
|
|
|
|
// leading to a possible situation where when connecting a NW source
|
|
|
|
// to a SE sink, the horizontal pip is found in the E boundary,
|
|
|
|
// then the
|
2022-11-25 13:34:46 +08:00
|
|
|
let middle = (x, (source.y + sink_loc.y) / 2);
|
|
|
|
let pips = partition_pips.get_mut(&middle).unwrap();
|
|
|
|
|
|
|
|
let (horiz_pip, pip_uses) = pips
|
|
|
|
.par_iter_mut()
|
2022-11-26 20:44:17 +08:00
|
|
|
.min_by_key(|(pip, uses)| {
|
2022-11-25 13:34:46 +08:00
|
|
|
let src_to_pip =
|
|
|
|
ctx.estimate_delay(source_wire, ctx.pip_src_wire(*pip));
|
|
|
|
let pip_to_snk = ctx.estimate_delay(ctx.pip_dst_wire(*pip), sink_wire);
|
|
|
|
let uses = uses.len() - (uses.contains(name) as usize);
|
|
|
|
(1000.0 * (src_to_pip + ((uses + 1) as f32) * pip_to_snk)) as u64
|
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
pip_uses.push(*name);
|
|
|
|
let horiz_pip = *horiz_pip;
|
|
|
|
|
|
|
|
let middle = ((source.x + sink_loc.x) / 2, y);
|
|
|
|
let pips = partition_pips.get_mut(&middle).unwrap();
|
|
|
|
|
|
|
|
let (vert_pip, pip_uses) = pips
|
|
|
|
.par_iter_mut()
|
2022-11-26 20:44:17 +08:00
|
|
|
.min_by_key(|(pip, uses)| {
|
2022-11-25 13:34:46 +08:00
|
|
|
let src_to_pip =
|
|
|
|
ctx.estimate_delay(source_wire, ctx.pip_src_wire(*pip));
|
|
|
|
let pip_to_snk = ctx.estimate_delay(ctx.pip_dst_wire(*pip), sink_wire);
|
|
|
|
let uses = uses.len() - (uses.contains(name) as usize);
|
|
|
|
(1000.0 * (src_to_pip + ((uses + 1) as f32) * pip_to_snk)) as u64
|
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
pip_uses.push(*name);
|
|
|
|
|
|
|
|
let horiz_loc = ctx.pip_location(horiz_pip);
|
|
|
|
let vert_loc = ctx.pip_location(*vert_pip);
|
|
|
|
let src_to_horiz = ((source.x, source.y), (horiz_loc.x, horiz_loc.y));
|
|
|
|
let horiz_to_vert = ((horiz_loc.x, horiz_loc.y), (vert_loc.x, vert_loc.y));
|
|
|
|
let vert_to_dst = ((vert_loc.x, vert_loc.y), (sink_loc.x, sink_loc.y));
|
|
|
|
match (source_is_north, source_is_east) {
|
|
|
|
(true, true) => {
|
|
|
|
ne.push(src_to_horiz);
|
|
|
|
nw.push(horiz_to_vert);
|
|
|
|
sw.push(vert_to_dst);
|
|
|
|
}
|
|
|
|
(true, false) => {
|
|
|
|
nw.push(src_to_horiz);
|
|
|
|
ne.push(horiz_to_vert);
|
|
|
|
se.push(vert_to_dst);
|
|
|
|
}
|
|
|
|
(false, true) => {
|
|
|
|
se.push(src_to_horiz);
|
|
|
|
sw.push(horiz_to_vert);
|
|
|
|
nw.push(vert_to_dst);
|
|
|
|
}
|
|
|
|
(false, false) => {
|
|
|
|
sw.push(src_to_horiz);
|
|
|
|
se.push(horiz_to_vert);
|
|
|
|
ne.push(vert_to_dst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
part_diag += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-25 15:12:14 +08:00
|
|
|
progress.finish_and_clear();
|
2022-11-25 13:34:46 +08:00
|
|
|
|
|
|
|
let north = ne.len() + nw.len();
|
|
|
|
let south = se.len() + sw.len();
|
|
|
|
|
|
|
|
let nets = (north + south) as f64;
|
|
|
|
|
2022-11-26 20:44:17 +08:00
|
|
|
let ne_dist = ((ne.len() as f64) / nets) - 0.25;
|
|
|
|
let se_dist = ((se.len() as f64) / nets) - 0.25;
|
|
|
|
let sw_dist = ((sw.len() as f64) / nets) - 0.25;
|
|
|
|
let nw_dist = ((nw.len() as f64) / nets) - 0.25;
|
2022-11-25 13:34:46 +08:00
|
|
|
|
|
|
|
let ne_str = ne.len().to_string();
|
|
|
|
let se_str = se.len().to_string();
|
|
|
|
let sw_str = sw.len().to_string();
|
|
|
|
let nw_str = nw.len().to_string();
|
|
|
|
|
2022-11-26 20:44:17 +08:00
|
|
|
let dist_str = |dist: f64| {
|
|
|
|
if dist > 0.20 {
|
|
|
|
"(way too many nets)".red()
|
|
|
|
} else if dist > 0.05 {
|
|
|
|
"(too many nets)".yellow()
|
|
|
|
} else if dist < -0.05 {
|
|
|
|
"(too few nets)".yellow()
|
|
|
|
} else if dist < -0.20 {
|
|
|
|
"(way too few nets)".red()
|
|
|
|
} else {
|
|
|
|
"(balanced)".green()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-11-25 13:34:46 +08:00
|
|
|
log_info!(
|
|
|
|
" {} arcs partitioned horizontally\n",
|
2022-11-26 20:44:17 +08:00
|
|
|
part_horiz.to_string().bold()
|
2022-11-25 13:34:46 +08:00
|
|
|
);
|
|
|
|
log_info!(
|
|
|
|
" {} arcs partitioned vertically\n",
|
2022-11-26 20:44:17 +08:00
|
|
|
part_vert.to_string().bold()
|
2022-11-25 13:34:46 +08:00
|
|
|
);
|
|
|
|
log_info!(
|
|
|
|
" {} arcs partitioned both ways\n",
|
2022-11-26 20:44:17 +08:00
|
|
|
part_diag.to_string().bold()
|
2022-11-25 13:34:46 +08:00
|
|
|
);
|
|
|
|
log_info!(
|
2022-11-26 20:44:17 +08:00
|
|
|
" {} arcs in the northeast {}\n",
|
|
|
|
ne_str.color(if ne_dist.abs() > 0.20 {
|
|
|
|
colored::Color::Red
|
|
|
|
} else if ne_dist.abs() > 0.05 {
|
|
|
|
colored::Color::Yellow
|
2022-11-25 13:34:46 +08:00
|
|
|
} else {
|
2022-11-26 20:44:17 +08:00
|
|
|
colored::Color::Green
|
|
|
|
}),
|
|
|
|
dist_str(ne_dist)
|
2022-11-25 13:34:46 +08:00
|
|
|
);
|
|
|
|
log_info!(
|
2022-11-26 20:44:17 +08:00
|
|
|
" {} arcs in the southeast {}\n",
|
|
|
|
se_str.color(if se_dist.abs() > 0.20 {
|
|
|
|
colored::Color::Red
|
|
|
|
} else if se_dist.abs() > 0.05 {
|
|
|
|
colored::Color::Yellow
|
2022-11-25 13:34:46 +08:00
|
|
|
} else {
|
2022-11-26 20:44:17 +08:00
|
|
|
colored::Color::Green
|
|
|
|
}),
|
|
|
|
dist_str(se_dist)
|
2022-11-25 13:34:46 +08:00
|
|
|
);
|
|
|
|
log_info!(
|
2022-11-26 20:44:17 +08:00
|
|
|
" {} arcs in the southwest {}\n",
|
|
|
|
sw_str.color(if sw_dist.abs() > 0.20 {
|
|
|
|
colored::Color::Red
|
|
|
|
} else if sw_dist.abs() > 0.05 {
|
|
|
|
colored::Color::Yellow
|
2022-11-25 13:34:46 +08:00
|
|
|
} else {
|
2022-11-26 20:44:17 +08:00
|
|
|
colored::Color::Green
|
|
|
|
}),
|
|
|
|
dist_str(sw_dist)
|
2022-11-25 13:34:46 +08:00
|
|
|
);
|
|
|
|
log_info!(
|
2022-11-26 20:44:17 +08:00
|
|
|
" {} arcs in the northwest {}\n",
|
|
|
|
nw_str.color(if nw_dist.abs() > 0.20 {
|
|
|
|
colored::Color::Red
|
|
|
|
} else if nw_dist.abs() > 0.05 {
|
|
|
|
colored::Color::Yellow
|
2022-11-25 13:34:46 +08:00
|
|
|
} else {
|
2022-11-26 20:44:17 +08:00
|
|
|
colored::Color::Green
|
|
|
|
}),
|
|
|
|
dist_str(nw_dist)
|
2022-11-25 13:34:46 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
(ne, se, sw, nw)
|
|
|
|
}
|
|
|
|
|
2022-11-20 11:20:09 +08:00
|
|
|
fn route(ctx: &mut npnr::Context) -> bool {
|
2022-11-26 20:44:17 +08:00
|
|
|
log_info!(
|
|
|
|
"{}{}{}{}{}{} from Rust!\n",
|
|
|
|
"A".red(),
|
|
|
|
"w".green(),
|
|
|
|
"o".yellow(),
|
|
|
|
"o".blue(),
|
|
|
|
"o".magenta(),
|
|
|
|
"o".cyan()
|
|
|
|
);
|
2022-11-20 11:20:09 +08:00
|
|
|
log_info!(
|
|
|
|
"Running on a {}x{} grid\n",
|
2022-11-26 20:44:17 +08:00
|
|
|
ctx.grid_dim_x().to_string().bold(),
|
|
|
|
ctx.grid_dim_y().to_string().bold(),
|
2022-11-20 11:20:09 +08:00
|
|
|
);
|
2022-11-21 10:48:00 +08:00
|
|
|
|
2022-11-25 13:34:46 +08:00
|
|
|
let wires = ctx.wires_leaking();
|
2022-11-26 20:44:17 +08:00
|
|
|
log_info!("Found {} wires\n", wires.len().to_string().bold());
|
2022-11-25 13:34:46 +08:00
|
|
|
|
|
|
|
let pips = ctx.pips_leaking();
|
2022-11-26 20:44:17 +08:00
|
|
|
log_info!("Found {} pips\n", pips.len().to_string().bold());
|
2022-11-24 07:55:33 +08:00
|
|
|
|
2022-11-24 07:02:30 +08:00
|
|
|
let nets = npnr::Nets::new(ctx);
|
2022-11-25 13:34:46 +08:00
|
|
|
let nets_str = nets.len().to_string();
|
2022-11-26 20:44:17 +08:00
|
|
|
log_info!("Found {} nets\n", nets_str.bold());
|
2022-11-21 10:48:00 +08:00
|
|
|
|
2022-11-23 11:31:50 +08:00
|
|
|
let mut count = 0;
|
2022-11-24 07:02:30 +08:00
|
|
|
for (name, net) in nets.iter() {
|
2022-11-23 11:31:50 +08:00
|
|
|
let _src = ctx.source_wire(*net);
|
|
|
|
let net = unsafe { net.as_mut().unwrap() };
|
2022-11-24 07:02:30 +08:00
|
|
|
let users = nets.users_by_name(*name).unwrap().iter();
|
|
|
|
for user in users {
|
2022-11-25 13:34:46 +08:00
|
|
|
count += ctx.sink_wires(net, *user).count();
|
2022-11-23 11:31:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-26 20:44:17 +08:00
|
|
|
log_info!("Found {} arcs\n", count.to_string().bold());
|
2022-11-23 11:31:50 +08:00
|
|
|
|
|
|
|
let (name, net) = nets
|
|
|
|
.iter()
|
2022-11-24 07:02:30 +08:00
|
|
|
.max_by_key(|(name, net)| {
|
2022-11-23 11:31:50 +08:00
|
|
|
let net = unsafe { net.as_mut().unwrap() };
|
|
|
|
if net.is_global() {
|
|
|
|
0
|
|
|
|
} else {
|
2022-11-24 07:02:30 +08:00
|
|
|
nets.users_by_name(**name)
|
|
|
|
.unwrap()
|
|
|
|
.iter()
|
2022-11-25 13:34:46 +08:00
|
|
|
.fold(0, |acc, sink| acc + ctx.sink_wires(net, *sink).count())
|
2022-11-23 11:31:50 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let net = unsafe { net.as_mut().unwrap() };
|
2022-11-24 07:02:30 +08:00
|
|
|
let count = nets
|
|
|
|
.users_by_name(*name)
|
|
|
|
.unwrap()
|
|
|
|
.iter()
|
2022-11-25 13:34:46 +08:00
|
|
|
.fold(0, |acc, sink| acc + ctx.sink_wires(net, *sink).count())
|
|
|
|
.to_string();
|
2022-11-23 11:31:50 +08:00
|
|
|
|
|
|
|
log_info!(
|
2022-11-26 20:44:17 +08:00
|
|
|
"Highest non-global fanout net is {}\n",
|
|
|
|
ctx.name_of(*name).to_str().unwrap().bold()
|
2022-11-23 11:31:50 +08:00
|
|
|
);
|
2022-11-26 20:44:17 +08:00
|
|
|
log_info!(" with {} arcs\n", count.bold());
|
2022-11-23 11:31:50 +08:00
|
|
|
|
|
|
|
let mut x0 = 0;
|
|
|
|
let mut y0 = 0;
|
|
|
|
let mut x1 = 0;
|
|
|
|
let mut y1 = 0;
|
|
|
|
|
2022-11-24 07:02:30 +08:00
|
|
|
for sink in nets.users_by_name(*name).unwrap().iter() {
|
2022-11-23 11:31:50 +08:00
|
|
|
let sink = unsafe { sink.as_ref().unwrap() };
|
2022-11-25 13:34:46 +08:00
|
|
|
let cell = sink.cell().unwrap().location();
|
|
|
|
x0 = x0.min(cell.x);
|
|
|
|
y0 = y0.min(cell.y);
|
|
|
|
x1 = x1.max(cell.x);
|
|
|
|
y1 = y1.max(cell.y);
|
2022-11-23 11:31:50 +08:00
|
|
|
}
|
|
|
|
|
2022-11-25 13:34:46 +08:00
|
|
|
let coords_min = format!("({}, {})", x0, y0);
|
|
|
|
let coords_max = format!("({}, {})", x1, y1);
|
|
|
|
log_info!(
|
2022-11-25 15:12:14 +08:00
|
|
|
" which spans from {} to {}\n",
|
2022-11-26 20:44:17 +08:00
|
|
|
coords_min.bold(),
|
|
|
|
coords_max.bold()
|
2022-11-25 13:34:46 +08:00
|
|
|
);
|
2022-11-23 11:31:50 +08:00
|
|
|
|
2022-11-25 13:34:46 +08:00
|
|
|
let _ = find_partition_point(ctx, &nets, pips, 0, ctx.grid_dim_x(), 0, ctx.grid_dim_y());
|
2022-11-24 07:55:33 +08:00
|
|
|
|
2022-11-23 11:31:50 +08:00
|
|
|
/*log_info!("=== level 2 NE:\n");
|
|
|
|
let _ = find_partition_point(&ne, x_start, x, y_start, y);
|
|
|
|
log_info!("=== level 2 SE:\n");
|
|
|
|
let _ = find_partition_point(&se, x, x_finish, y_start, y);
|
|
|
|
log_info!("=== level 2 SW:\n");
|
|
|
|
let _ = find_partition_point(&sw, x, x_finish, y, y_finish);
|
|
|
|
log_info!("=== level 2 NW:\n");
|
|
|
|
let _ = find_partition_point(&nw, x_start, x, y, y_finish);*/
|
|
|
|
|
2022-11-20 11:20:09 +08:00
|
|
|
true
|
2022-11-23 11:31:50 +08:00
|
|
|
}
|