Skip to content
Snippets Groups Projects
Commit 7febcf6c authored by Xavier Routh's avatar Xavier Routh
Browse files

no clue what i changed

parent 3cf5ed71
No related branches found
No related tags found
No related merge requests found
Pipeline #202281 failed
...@@ -16,19 +16,72 @@ use crate::*; ...@@ -16,19 +16,72 @@ use crate::*;
#[derive(Clone, Debug, Copy)] #[derive(Clone, Debug, Copy)]
pub struct Switchbox { pub struct Switchbox<const W: usize> {
pub output_wires: (usize, usize), // A, B pub output_wires: (usize, usize), // A, B
} }
impl <const W: usize> Switchbox<W> {
pub fn bits(self: &Self) -> Vec<bool> {
let sb_bits = u32::ilog2(W.try_into().unwrap());
let mut bits = vec![];
let outputs = vec![self.output_wires.0, self.output_wires.1];
for output in outputs {
bits.append(&mut Self::sb_word_bits(output.try_into().unwrap()))
}
// FOR CARRIES TODO: (@XROUTH) FIX THIS.
let mut fake_bits: Vec<bool> = (0..sb_bits).map(|a| false).collect();
bits.append(&mut fake_bits);
let mut fake_bits: Vec<bool> = (0..sb_bits).map(|a| false).collect();
bits.append(&mut fake_bits);
bits
}
pub fn sb_word_bits(word: u32) -> Vec<bool> {
let sb_bits = u32::ilog2(W.try_into().unwrap());
(0..sb_bits)
.rev() // Reverse to get most significant bit first
.map(|i| (word & (1 << i)) != 0) // Check if the i-th bit is set
.collect()
}
}
#[derive(Clone, Debug, Copy)] #[derive(Clone, Debug, Copy)]
pub struct FunctionalUnit { pub struct FunctionalUnit {
pub op_type: FuOp, pub op_type: FuOp,
} }
pub fn boolify(input: Vec<usize>) -> Vec<bool> {
input.iter().map(|a| if *a == 0 {false} else {true}).collect()
}
impl FunctionalUnit {
pub fn bits(self: &Self) -> Vec<bool> {
let mut bits = vec![];
bits.push(false); // set acc mode to false.
let vec = match self.op_type {
FuOp::Add => vec![0, 0, 0, 0],
FuOp::Mult => vec![0, 0, 0, 1],
FuOp::PassA => vec![1, 1, 1, 1],
FuOp::Default => vec![1, 1, 1, 1],
};
bits.append(&mut boolify(vec));
bits
}
}
#[derive(Clone, Debug, Copy)] #[derive(Clone, Debug, Copy)]
pub struct SliceDesc<const H: usize, const W: usize> where [(); H -1]: { pub struct SliceDesc<const H: usize, const W: usize> where [(); H -1]: {
pub functional_units: [[FunctionalUnit; W]; H], // is 8 x 8 // Indexed [height][width] pub functional_units: [[FunctionalUnit; W]; H], // is 8 x 8 // Indexed [height][width]
pub switchboxes: [[Switchbox; W]; H -1 ], // 1st row of functional units doesn't have switchboxes, so this is 7 x 8 pub switchboxes: [[Switchbox<W>; W]; H -1 ], // 1st row of functional units doesn't have switchboxes, so this is 7 x 8
} }
impl <const H: usize, const W: usize> SliceDesc<H,W> where [(); H -1]: { impl <const H: usize, const W: usize> SliceDesc<H,W> where [(); H -1]: {
...@@ -153,13 +206,54 @@ where [(); H -1]: ...@@ -153,13 +206,54 @@ where [(); H -1]:
chip.0.pretty_print(); chip.0.pretty_print();
// println!("chip: {:?}", chip); // println!("chip: {:?}", chip);
let bitstream = Self::assemble_slice(chip.0);
let binary_string: String = bitstream.iter().map(|&b| if b { '1' } else { '0' }).collect();
println!("bitstream :{:?}", binary_string);
todo!(); todo!();
// Assemble to bitstream. // Assemble to bitstream.
Ok(()) Ok(())
} }
fn assemble_slice(slice: SliceDesc<H, W>) -> Vec<bool> {
// First row of FUs
let mut bits = vec![];
for i in 0..W {
let mut bits_for_fu = slice.functional_units[0][i].bits();
bits.append(&mut bits_for_fu);
}
for i in 1..H {
let range = if i % 2 == 0{
W..0
} else {
0..W
};
for j in range {
let sb = slice.switchboxes[i - 1][j];
let fu = slice.functional_units[i][j];
// Switchbox,
let mut bits_for_sb = sb.bits();
println!("bits_for_sb: {:?}", bits_for_sb);
// FU
let mut bits_for_fu = fu.bits();
bits.append(&mut bits_for_sb);
bits.append(&mut bits_for_fu);
}
}
bits.reverse();
bits
}
fn get_free_col(live_outs: &HashMap<NodeID, usize>) -> usize { fn get_free_col(live_outs: &HashMap<NodeID, usize>) -> usize {
(0..W).find(|col| live_outs.values().cloned().find(|value| value == col).is_none()).unwrap() (0..W).find(|col| live_outs.values().cloned().find(|value| value == col).is_none()).unwrap()
} }
......
fn grape_kernel(a: i32, b: i32) -> i32 { fn grape_kernel(a: i32) -> i32 {
return a + b + 3; return a;
} }
#[entry] #[entry]
fn entry() -> i32 { fn entry() -> i32 {
return grape_kernel(2, 5); return grape_kernel(2);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment