Skip to content

Error with the simulation #47

Description

@OscarLopezCentenera

I've been encountering an issue related to simulation value ranges. I'm sharing a link to a Rust HDL project that implements an 8-bit signed adder (Signed<8>), whose output is a 9-bit signed value (Signed<9>).

When running the simulation in Rust, I populate the test_cases variable with input values ranging from -127 to 127. This works correctly. However, if I use the full expected range for a Signed<8> — from -128 to 127 — the simulation fails specifically when testing the -128 case, resulting in an "overflowed" error.

This is not the first time I have experienced this issue, and it seems consistent when dealing with the value -128. If I adjust the input range to start at -127, which appears to be the default behavior, everything works correctly.

I would like to know whether this is due to a limitation of the tool — meaning that it does not support handling -128 correctly — or if it is simply an unimplemented feature in the current version of the simulation framework.

https://drive.google.com/drive/folders/1rBo9JDkt8n50aqYVuEfK90CKt5o6wpWF?usp=sharing

The code

let mut sim = Simulation::<Sumador>::new();
sim.add_testbench(move |mut ep| {
   
    let mut x = ep.init()?;

   //here, change (-127..128) to (-128..128) ant its fails
    let test_cases: Vec<(i32, i32)> = (-127..128).flat_map(|a| (-127..128).map(move |b| ((a,b)))).collect();

    for &(a, b) in test_cases.iter() {
        x.a.next = Signed::<8>::from(a as i64);
        x.b.next = Signed::<8>::from(b as i64);
        let x_clone = x.clone();
        let x = ep.wait(1, x_clone)?;
        //println!("a= {}, b= {}, sum= {}", x.a.val().bigint(), x.b.val().bigint(), x.sum.val().bigint());
        let expected_sum = a + b;
        sim_assert_eq!(ep, x.sum.val(), Signed::<9>::from(expected_sum as i64), x);
    }
    ep.done(x)?;
    Ok(())
});

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions