forked from libre-chip/cpu
working on reg_alloc -- selected_unit_nums should be correct now
This commit is contained in:
parent
89717f8916
commit
5f7766777a
5 changed files with 15671 additions and 18 deletions
|
|
@ -6,7 +6,11 @@ use crate::{
|
|||
unit::{TrapData, UnitTrait},
|
||||
util::tree_reduce::tree_reduce_with_state,
|
||||
};
|
||||
use fayalite::{module::instance_with_loc, prelude::*, util::ready_valid::ReadyValid};
|
||||
use fayalite::{
|
||||
module::{instance_with_loc, wire_with_loc},
|
||||
prelude::*,
|
||||
util::ready_valid::ReadyValid,
|
||||
};
|
||||
use std::num::NonZeroUsize;
|
||||
|
||||
pub mod unit_free_regs_tracker;
|
||||
|
|
@ -73,13 +77,19 @@ pub fn reg_alloc(config: &CpuConfig) {
|
|||
selected_unit_nums[fetch_index],
|
||||
tree_reduce_with_state(
|
||||
0..config.unit_kinds.len(),
|
||||
&mut (),
|
||||
&mut 0usize,
|
||||
|_state, unit_index| {
|
||||
#[hdl]
|
||||
let selected_unit_leaf = wire(HdlOption[config.unit_num()]);
|
||||
let selected_unit_leaf = wire_with_loc(
|
||||
&format!("selected_unit_leaf_{fetch_index}_{unit_index}"),
|
||||
SourceLocation::caller(),
|
||||
HdlOption[config.unit_num()],
|
||||
);
|
||||
connect(selected_unit_leaf, HdlOption[config.unit_num()].HdlNone());
|
||||
#[hdl]
|
||||
let unit_num = wire(config.unit_num());
|
||||
let unit_num = wire_with_loc(
|
||||
&format!("unit_num_{fetch_index}_{unit_index}"),
|
||||
SourceLocation::caller(),
|
||||
config.unit_num(),
|
||||
);
|
||||
connect_any(unit_num.value, unit_index);
|
||||
#[hdl]
|
||||
if available_units[fetch_index][unit_index] {
|
||||
|
|
@ -87,9 +97,13 @@ pub fn reg_alloc(config: &CpuConfig) {
|
|||
}
|
||||
selected_unit_leaf
|
||||
},
|
||||
|_state, l, r| {
|
||||
#[hdl]
|
||||
let selected_unit_node = wire(Expr::ty(l));
|
||||
|state, l, r| {
|
||||
let selected_unit_node = wire_with_loc(
|
||||
&format!("selected_unit_node_{fetch_index}_{state}"),
|
||||
SourceLocation::caller(),
|
||||
Expr::ty(l),
|
||||
);
|
||||
*state += 1;
|
||||
connect(selected_unit_node, l);
|
||||
#[hdl]
|
||||
if let HdlNone = l {
|
||||
|
|
@ -101,6 +115,19 @@ pub fn reg_alloc(config: &CpuConfig) {
|
|||
.expect("expected at least one unit"),
|
||||
);
|
||||
}
|
||||
// must come after to override connects in loop above
|
||||
for fetch_index in 0..config.fetch_width.get() {
|
||||
// TODO: handle assigning multiple instructions to a unit at a time
|
||||
for later_fetch_index in fetch_index + 1..config.fetch_width.get() {
|
||||
#[hdl]
|
||||
if let HdlSome(selected_unit_num) = selected_unit_nums[fetch_index] {
|
||||
connect(
|
||||
available_units[later_fetch_index][selected_unit_num.value],
|
||||
false,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (unit_index, &unit_kind) in config.unit_kinds.iter().enumerate() {
|
||||
let dyn_unit = unit_kind.unit(config);
|
||||
let unit = instance_with_loc(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue