From f7fc239f75eb0116562158fd2ce88e7fb7ed479e Mon Sep 17 00:00:00 2001 From: SpaceCat-Chan <49094338+SpaceCat-Chan@users.noreply.github.com> Date: Sun, 27 Nov 2022 20:57:00 +0100 Subject: [PATCH] improve partition sanity check quality of life --- common/route/awooter/rust/src/lib.rs | 65 +----------------- common/route/awooter/rust/src/partition.rs | 78 ++++++++++++++++++++++ 2 files changed, 79 insertions(+), 64 deletions(-) diff --git a/common/route/awooter/rust/src/lib.rs b/common/route/awooter/rust/src/lib.rs index 92135099..49a71d14 100644 --- a/common/route/awooter/rust/src/lib.rs +++ b/common/route/awooter/rust/src/lib.rs @@ -151,7 +151,7 @@ fn route(ctx: &mut npnr::Context) -> bool { let arcs = extract_arcs_from_nets(ctx, nets); - let (x_part, y_part, ne, se, sw, nw) = partition::find_partition_point( + let (x_part, y_part, ne, se, sw, nw) = partition::find_partition_point_and_sanity_check( ctx, &arcs[..], pips, @@ -165,69 +165,6 @@ fn route(ctx: &mut npnr::Context) -> bool { log_info!("Partitioning took {:.2}s\n", time.as_secs_f32()); - let mut invalid_arcs_in_ne = 0; - let mut invalid_arcs_in_se = 0; - let mut invalid_arcs_in_sw = 0; - let mut invalid_arcs_in_nw = 0; - - for arc in &ne { - if arc.get_source_loc().x > x_part - || arc.get_source_loc().y > y_part - || arc.get_sink_loc().x > x_part - || arc.get_sink_loc().y > y_part - { - invalid_arcs_in_ne += 1; - } - } - for arc in &se { - if arc.get_source_loc().x < x_part - || arc.get_source_loc().y > y_part - || arc.get_sink_loc().x < x_part - || arc.get_sink_loc().y > y_part - { - invalid_arcs_in_se += 1; - } - } - for arc in &sw { - if arc.get_source_loc().x < x_part - || arc.get_source_loc().y < y_part - || arc.get_sink_loc().x < x_part - || arc.get_sink_loc().y < y_part - { - invalid_arcs_in_sw += 1; - } - } - for arc in &nw { - if arc.get_source_loc().x > x_part - || arc.get_source_loc().y < y_part - || arc.get_sink_loc().x > x_part - || arc.get_sink_loc().y < y_part - { - invalid_arcs_in_nw += 1; - } - } - - if [ - invalid_arcs_in_ne, - invalid_arcs_in_se, - invalid_arcs_in_sw, - invalid_arcs_in_nw, - ] - .into_iter() - .all(|x| x == 0) - { - log_info!( - "{}\n", - "Found no arcs crossing partition boundaries.".green() - ); - } else { - println!("{}", "found arcs crossing partition boundaries!".yellow()); - println!("count in ne: {}", invalid_arcs_in_ne.to_string().bold()); - println!("count in se: {}", invalid_arcs_in_se.to_string().bold()); - println!("count in sw: {}", invalid_arcs_in_sw.to_string().bold()); - println!("count in nw: {}", invalid_arcs_in_nw.to_string().bold()); - } - let mut router = route::Router::new(Coord::new(0, 0), Coord::new(x_part, y_part)); router.route(ctx, &ne); diff --git a/common/route/awooter/rust/src/partition.rs b/common/route/awooter/rust/src/partition.rs index e0a1b000..f427a09f 100644 --- a/common/route/awooter/rust/src/partition.rs +++ b/common/route/awooter/rust/src/partition.rs @@ -560,3 +560,81 @@ fn partition>( (ne, se, sw, nw) } + +pub fn find_partition_point_and_sanity_check( + ctx: &npnr::Context, + arcs: &[Arc], + pips: &[npnr::PipId], + x_start: i32, + x_finish: i32, + y_start: i32, + y_finish: i32, +) -> (i32, i32, Vec, Vec, Vec, Vec) { + let (x_part, y_part, ne, se, sw, nw) = + find_partition_point(ctx, arcs, pips, x_start, x_finish, y_start, y_finish); + + let mut invalid_arcs_in_ne = 0; + let mut invalid_arcs_in_se = 0; + let mut invalid_arcs_in_sw = 0; + let mut invalid_arcs_in_nw = 0; + + for arc in &ne { + if arc.get_source_loc().x > x_part + || arc.get_source_loc().y > y_part + || arc.get_sink_loc().x > x_part + || arc.get_sink_loc().y > y_part + { + invalid_arcs_in_ne += 1; + } + } + for arc in &se { + if arc.get_source_loc().x < x_part + || arc.get_source_loc().y > y_part + || arc.get_sink_loc().x < x_part + || arc.get_sink_loc().y > y_part + { + invalid_arcs_in_se += 1; + } + } + for arc in &sw { + if arc.get_source_loc().x < x_part + || arc.get_source_loc().y < y_part + || arc.get_sink_loc().x < x_part + || arc.get_sink_loc().y < y_part + { + invalid_arcs_in_sw += 1; + } + } + for arc in &nw { + if arc.get_source_loc().x > x_part + || arc.get_source_loc().y < y_part + || arc.get_sink_loc().x > x_part + || arc.get_sink_loc().y < y_part + { + invalid_arcs_in_nw += 1; + } + } + + if [ + invalid_arcs_in_ne, + invalid_arcs_in_se, + invalid_arcs_in_sw, + invalid_arcs_in_nw, + ] + .into_iter() + .all(|x| x == 0) + { + log_info!( + "{}\n", + "Found no arcs crossing partition boundaries.".green() + ); + } else { + println!("{}", "found arcs crossing partition boundaries!".yellow()); + println!("count in ne: {}", invalid_arcs_in_ne.to_string().bold()); + println!("count in se: {}", invalid_arcs_in_se.to_string().bold()); + println!("count in sw: {}", invalid_arcs_in_sw.to_string().bold()); + println!("count in nw: {}", invalid_arcs_in_nw.to_string().bold()); + } + + (x_part, y_part, ne, se, sw, nw) +}