Skip to content

get_value does not handle signed values properly #265

@sgherbst

Description

@sgherbst

Just noticed that when get_value is used in conjunction with SInt types, the values are treated as unsigned. An example is shown below, where the value 214 is returned instead of -42. It appears the reason is that the generated testbench code does not attach the signed attribute to signed signals. However, this only ends up impacting get_value, not expect.

test.py

from pathlib import Path
import fault
import magma as m

class dut(m.Circuit):
    io = m.IO(
        a=m.In(m.SInt[8]),
        y=m.Out(m.SInt[8]),
        clk=m.ClockIn
    )

t = fault.Tester(dut, dut.clk)

t.poke(dut.a, -42)
t.step(2)
y = t.get_value(dut.a)

t.step(2)

t.compile_and_run(
    target='system-verilog',
    simulator='iverilog',
    ext_srcs=[Path('dut.sv').resolve()],
    ext_model_file=True
)

print('y', y.value)

dut.sv

module dut (
    input signed [7:0] a,
    input clk,
    output reg signed [7:0] y
);
    always @(posedge clk) begin
        y <= a;
    end
endmodule

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