From abdaf710e6f4ee5f13a7bc8702bd5cbbfd4ad7bf Mon Sep 17 00:00:00 2001 From: saji Date: Sat, 4 May 2024 21:41:53 -0500 Subject: [PATCH] add chip argument, untested 22v10 --- compiler/src/fitter.rs | 39 ++++++++++++++++++++++++--------------- compiler/src/main.rs | 22 ++++++++++++++++++++-- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/compiler/src/fitter.rs b/compiler/src/fitter.rs index c3493cc..0be84a4 100644 --- a/compiler/src/fitter.rs +++ b/compiler/src/fitter.rs @@ -33,10 +33,7 @@ pub enum MappingError { // attempt to map graph into blueprint /// Acquire the SOP associated with the OLMC. If it's -fn get_sop_for_olmc( - graph: &Graph, - olmc_idx: &NodeIdx, -) -> Result { +fn get_sop_for_olmc(graph: &Graph, olmc_idx: &NodeIdx) -> Result { let input = graph.get_node_port_conns(olmc_idx, "A"); debug!("Found connections into OLMC Input: {:?}", input); debug!("OLMC {:?}", graph.get_node(olmc_idx)); @@ -56,9 +53,7 @@ fn get_sop_for_olmc( // find the row that contains this olmc. // we know this exists because mapping has already finished. let newsop = GalSop { - connections: HashMap::from([ - ("A".to_string(), vec![i.net.clone()]), - ]), + connections: HashMap::from([("A".to_string(), vec![i.net.clone()])]), parameters: GalSopParameters { depth: 1, width: 1, @@ -66,8 +61,7 @@ fn get_sop_for_olmc( }, }; Some(newsop) - - }, + } _ => None, } }) @@ -117,10 +111,21 @@ fn map_remaining_olmc( } } + +fn chip_to_olmc_offset(chip: &Chip) -> usize { + match chip { + Chip::GAL16V8 => 12, + Chip::GAL22V10 => 14, + _ => panic!("Invalid chip!"), + } + +} + fn find_hwpin_for_net( graph: &Graph, pcf: &PcfFile, - olmcmap: &Vec>, + olmcmap: &[Option], + chip: &Chip, net: &Net, ) -> Result { // this does a double lookup. first it finds the Input on the net, @@ -169,9 +174,12 @@ fn find_hwpin_for_net( .iter() .position(|node| node == inputs[0]) .unwrap(); - let olmc_row = olmcmap.iter().position(|r| r == &Some(NodeIdx(olmc_idx))).unwrap(); + let olmc_row = olmcmap + .iter() + .position(|r| r == &Some(NodeIdx(olmc_idx))) + .unwrap(); // we have the row. - let pin = olmc_row + 12; // TODO: fix! + let pin = olmc_row + chip_to_olmc_offset(chip); // TODO: fix! debug!("OLMC discovered on {pin}"); Ok(pin as u32) } @@ -182,7 +190,8 @@ fn find_hwpin_for_net( fn make_term_from_sop( graph: &Graph, pcf: &PcfFile, - olmcmap: &Vec>, + olmcmap: &[Option], + chip: &Chip, sop: GalSop, ) -> Term { let table = sop.parameters.table.as_bytes(); @@ -207,7 +216,7 @@ fn make_term_from_sop( let net_for_pin = input_nets.get(idx).unwrap(); // now use the helper to find the true hardware pin let hwpin: usize = - find_hwpin_for_net(graph, pcf, olmcmap, net_for_pin).unwrap() as usize; + find_hwpin_for_net(graph, pcf, olmcmap, &chip, net_for_pin).unwrap() as usize; // we now have our hardware pin number! match *product { "01" => Some(Pin { @@ -353,7 +362,7 @@ pub fn graph_convert(graph: &Graph, pcf: PcfFile, chip: Chip) -> anyhow::Result< debug!("Mapping node {node} at row {idx}"); let sop = get_sop_for_olmc(graph, node)?; debug!("Got SOP {:?} attached to node", sop); - let term = make_term_from_sop(graph, &pcf, &olmcmap, sop); + let term = make_term_from_sop(graph, &pcf, &olmcmap, &chip, sop); debug!("Got term {:?}", term); let gal_olmc_node = graph.get_node(node).unwrap(); if let Node::Olmc(o) = gal_olmc_node { diff --git a/compiler/src/main.rs b/compiler/src/main.rs index 5202b08..e46afb5 100644 --- a/compiler/src/main.rs +++ b/compiler/src/main.rs @@ -2,7 +2,7 @@ pub mod pcf; pub mod yosys_parser; mod fitter; -use clap::{Parser, Subcommand, Args}; +use clap::{Parser, Subcommand, ValueEnum, Args}; use galette::gal_builder::build; use galette::writer::{make_jedec, Config}; use crate::pcf::parse_pcf; @@ -35,6 +35,21 @@ struct ValidateArgs { file: PathBuf, } +#[derive(ValueEnum, Debug, Clone)] +enum ChipType { + GAL16V8, + GAL22V10 +} + +impl ChipType { + fn to_galette(&self) -> Chip { + match self { + Self::GAL16V8 => Chip::GAL16V8, + Self::GAL22V10 => Chip::GAL22V10, + } + } +} + #[derive(Args)] struct SynthArgs { @@ -42,6 +57,9 @@ struct SynthArgs { netlist: PathBuf, #[arg(required = true, value_hint = clap::ValueHint::DirPath)] constraints: PathBuf, + + #[arg(value_enum, long, default_value_t=ChipType::GAL16V8)] + chip: ChipType } @@ -83,7 +101,7 @@ fn synth(s: SynthArgs) -> Result<()> { let pcf_string = std::str::from_utf8(pcf_file)?; let pcf = parse_pcf(pcf_string); - let res = graph_convert(&g, pcf, Chip::GAL16V8)?; + let res = graph_convert(&g, pcf, s.chip.to_galette())?; let mut gal = build(&res)?;