//! Writes the dataflow member's RV32IM programs, exactly as the device runs
//! them (conforming and mutants), as assembly listings and as the machine words
//! this crate encodes, so an independent assembler can be checked against the
//! encoder:
//!
//! ```text
//! cargo run --example rv32_listing --features quantum_fabric_dataflow --
//! ```
//!
//! In ``, for each program ``: `.s` (the listing, with a
//! `.text` header) and `.bin` (the words, little-endian).
use wai_quantum::quantum_fabric::vector_engine::{self, Constants};
use wai_quantum::quantum_fabric_dataflow::{Variant, programs};
fn main() {
let dir = std::path::PathBuf::from(std::env::args().nth(1).expect("an output directory"));
std::fs::create_dir_all(&dir).expect("the directory");
// The programs the device runs: the rows and probe programs of the
// conforming kernel and of each mutant (M3's probe is the conforming one).
let mut all = Vec::new();
for (tag, v) in [("", Variant::Conforming), ("_m1", Variant::M1), ("_m2", Variant::M2), ("_m3", Variant::M3)] {
let (rows, probe) = programs(v);
all.push((format!("rows{tag}"), rows));
if v != Variant::M3 {
all.push((format!("probe{tag}"), probe));
}
}
// The vector engine's, over a full pass, with a sample gate's entries.
let m = [0x2000_0000, -0x2000_0000, 0x1234_5678, -0x0765_4321, 1, -1, i32::MAX, i32::MIN];
for (tag, v) in [("", Variant::Conforming), ("_m1", Variant::M1), ("_m2", Variant::M2), ("_m3", Variant::M3)] {
let (rnd, shift, last_add) = v.constants();
let c = Constants { round_bit: rnd.trailing_zeros(), shift, last_add };
all.push((format!("vector_rows{tag}"), vector_engine::rows_program(&m, c, 16)));
if v != Variant::M3 {
all.push((format!("vector_probe{tag}"), vector_engine::probe_program(c, 16)));
}
}
for (name, (words, text)) in all {
std::fs::write(dir.join(format!("{name}.s")), format!(".text\n.option norvc\n{text}")).expect("the listing");
std::fs::write(dir.join(format!("{name}.bin")), words.iter().flat_map(|w| w.to_le_bytes()).collect::>()).expect("the words");
println!("{name}: {} words", words.len());
}
}