Skip to content

Commit

Permalink
Optionally enable zfinx and 32b floating point architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
mbertuletti committed Jan 28, 2025
1 parent 9153635 commit edd0675
Show file tree
Hide file tree
Showing 5 changed files with 400 additions and 131 deletions.
3 changes: 3 additions & 0 deletions config/mempool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ memory:
size: 0x10000
- name: mempool-dma
size: 0x1C
float_instr:
width: 32
zfinx: true
inst_latency:
mul: 3
mulh: 3
Expand Down
3 changes: 3 additions & 0 deletions config/terapool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ memory:
size: 0x10000
- name: mempool-dma
size: 0x1C
float_instr:
width: 32
zfinx: true
inst_latency:
mul: 4
mulh: 4
Expand Down
19 changes: 19 additions & 0 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub struct Configuration {
#[serde(default)]
pub address: Address,
#[serde(default)]
pub float_instr: FloatInstr,
#[serde(default)]
pub inst_latency: std::collections::HashMap<String, u64>,
#[serde(default)]
pub ssr: Ssr,
Expand All @@ -35,6 +37,7 @@ impl Default for Configuration {
bootrom: Default::default(),
memory: Default::default(),
address: Default::default(),
float_instr: Default::default(),
inst_latency: Default::default(),
ssr: Default::default(),
interrupt_latency: 10,
Expand All @@ -56,6 +59,7 @@ impl Configuration {
memory: Default::default(),
address: Default::default(),
inst_latency: Default::default(),
float_instr: Default::default(),
ssr: Default::default(),
interrupt_latency: 10,
}
Expand Down Expand Up @@ -246,6 +250,21 @@ impl Default for Ssr {
}
}

/// Struct to configure the floating-point ISA features
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct FloatInstr {
pub width: usize,
pub zfinx: bool,
}

impl Default for FloatInstr {
fn default() -> FloatInstr {

Check warning on line 261 in src/configuration.rs

View workflow job for this annotation

GitHub Actions / Format

Diff in /home/runner/work/banshee/banshee/src/configuration.rs
FloatInstr {
width: 32,
zfinx: false }
}
}

/// Description of the hierarchy
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
pub struct Architecture {
Expand Down
77 changes: 50 additions & 27 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1185,18 +1185,31 @@ impl<'a, 'b> Cpu<'a, 'b> {
// Assemble the arguments.
let args = accesses.iter().copied().zip(data.iter().copied());
let mut args = args.map(|(access, data)| match access {
// Memory access cases
TraceAccess::ReadMem(_x) => format!("RA:{:08x}", data as u32),
TraceAccess::WriteMem => format!("WA:{:08x}", data as u32),
TraceAccess::RMWMem => format!("AMO:{:08x}", data as u32),

// Register access cases
TraceAccess::ReadReg(x) => format!("x{}:{:08x}", x, data as u32),
TraceAccess::WriteReg(x) => format!("x{}={:08x}", x, data as u32),
TraceAccess::ReadFReg(x) => format!("f{:02}:{:>16.6}", x, f64::from_bits(data)),
TraceAccess::WriteFReg(x) => format!("f{:02}={:>16.6}", x, f64::from_bits(data)),
TraceAccess::ReadF32Reg(x) => {
format!("f{:02}:{:>12.4}", x, f32::from_bits(data as u32))
}
TraceAccess::WriteF32Reg(x) => {
format!("f{:02}={:>12.4}", x, f32::from_bits(data as u32))

// Floating-point register access cases
TraceAccess::ReadFReg(x)
| TraceAccess::WriteFReg(x)
| TraceAccess::ReadF32Reg(x)
| TraceAccess::WriteF32Reg(x) => {
if self.engine.config.float_instr.zfinx {
format!("x{}={:08x}", x, data as u32)

Check warning on line 1203 in src/engine.rs

View workflow job for this annotation

GitHub Actions / Format

Diff in /home/runner/work/banshee/banshee/src/engine.rs
} else {
match access {
TraceAccess::ReadFReg(_) => format!("f{:02}:{:>16.6}", x, f64::from_bits(data)),
TraceAccess::WriteFReg(_) => format!("f{:02}={:>16.6}", x, f64::from_bits(data)),
TraceAccess::ReadF32Reg(_) => format!("f{:02}:{:>12.4}", x, f32::from_bits(data as u32)),
TraceAccess::WriteF32Reg(_) => format!("f{:02}={:>12.4}", x, f32::from_bits(data as u32)),
_ => unreachable!(),
}
}
}
TraceAccess::Readf8Reg(x) => format!(
"f{:02}:[{:>5.3}]",
Expand All @@ -1218,26 +1231,36 @@ impl<'a, 'b> Cpu<'a, 'b> {
false

Check warning on line 1231 in src/engine.rs

View workflow job for this annotation

GitHub Actions / Format

Diff in /home/runner/work/banshee/banshee/src/engine.rs
) as u32),
),
TraceAccess::Readf16Reg(x) => format!(
"f{:02}=[{:>8.4}]",
x,
f32::from_bits(flexfloat::ff_instruction_cvt_to_s(
(data & 0x0000_0000_0000_ffff) >> 0,
flexfloat::FfOpCvt::Fcvt16f2f,
false,
false
) as u32),
),
TraceAccess::Writef16Reg(x) => format!(
"f{:02}=[{:>5.3}]",
x,
f32::from_bits(flexfloat::ff_instruction_cvt_to_s(
(data & 0x0000_0000_0000_00ff) >> 0,
flexfloat::FfOpCvt::Fcvt16f2f,
false,
false
) as u32),
),
TraceAccess::Readf16Reg(x) =>
if self.engine.config.float_instr.zfinx {
format!("x{}={:08x}", x, data as u32)
} else {
format!(
"f{:02}=[{:>8.4}]",
x,
f32::from_bits(flexfloat::ff_instruction_cvt_to_s(
(data & 0x0000_0000_0000_ffff) >> 0,
flexfloat::FfOpCvt::Fcvt16f2f,
false,
false

Check warning on line 1245 in src/engine.rs

View workflow job for this annotation

GitHub Actions / Format

Diff in /home/runner/work/banshee/banshee/src/engine.rs
) as u32),
)
},
TraceAccess::Writef16Reg(x) =>
if self.engine.config.float_instr.zfinx {
format!(
"f{:02}=[{:>5.3}]",
x,
f32::from_bits(flexfloat::ff_instruction_cvt_to_s(
(data & 0x0000_0000_0000_00ff) >> 0,
flexfloat::FfOpCvt::Fcvt16f2f,
false,
false
) as u32),
)
} else {
format!("x{}={:08x}", x, data as u32)
},
TraceAccess::Readvf64sReg(x) => format!(
"f{:02}:[{:>12.4}, {:>12.4}]",
x,
Expand Down
Loading

0 comments on commit edd0675

Please sign in to comment.