question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

setimmediatevalue doesnt work for signals wider than 32 bit

See original GitHub issue

cocotb_test.tar.gz

See attached testcase for details.

It looks like setimmediatevalue does not take effect if the signal width is greater than 32.

I tried the following variation and all of them fail

        dut.inp_short63.setimmediatevalue(0)
        dut.inp_short64.setimmediatevalue(BinaryValue(value=0,bits=65).value)
        dut.inp.setimmediatevalue(BinaryValue(value='0x0', bits=1024))

The normal assignment statement works

dut.inp_short70 <= BinaryValue(value=0xffffffffffffffff,bits=71).value

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
eric-wiesercommented, Jan 28, 2019

Here’s the bug:

// Value related functions
int VpiSignalObjHdl::set_signal_value(long value)
{
    FENTER
    s_vpi_value value_s;

    value_s.value.integer = value;
    value_s.format = vpiIntVal;

    s_vpi_time vpi_time_s;

    vpi_time_s.type = vpiSimTime;
    vpi_time_s.high = 0;
    vpi_time_s.low  = 0;

    // Use Inertial delay to schedule an event, thus behaving like a verilog testbench
    vpi_put_value(GpiObjHdl::get_handle<vpiHandle>(), &value_s, &vpi_time_s, vpiInertialDelay);
    check_vpi_error();

    FEXIT
    return 0;
}

int VpiSignalObjHdl::set_signal_value(double value)
{
    FENTER
    s_vpi_value value_s;

    value_s.value.real = value;
    value_s.format = vpiRealVal;

    s_vpi_time vpi_time_s;

    vpi_time_s.type = vpiSimTime;
    vpi_time_s.high = 0;
    vpi_time_s.low  = 0;

    vpi_put_value(GpiObjHdl::get_handle<vpiHandle>(), &value_s, &vpi_time_s, vpiInertialDelay);
    check_vpi_error();

    FEXIT
    return 0;
}

int VpiSignalObjHdl::set_signal_value(std::string &value)
{
    FENTER
    s_vpi_value value_s;

    std::vector<char> writable(value.begin(), value.end());
    writable.push_back('\0');

    value_s.value.str = &writable[0];
    value_s.format = vpiBinStrVal;

    // !!! this path is the only one that fails
    vpi_put_value(GpiObjHdl::get_handle<vpiHandle>(), &value_s, NULL, vpiNoDelay);
    check_vpi_error();

    FEXIT
    return 0;
}

set_signal_value(std::string &value) does not use vpiInertialDelay, unlike the others which do.

0reactions
eric-wiesercommented, Jan 28, 2019

Ah, this is probably #637 in a new and exciting form.

It only fails if the write happens before any events have been yielded.

This fails, but passes if do_wait is changed to True

import cocotb
from cocotb.triggers import Timer, RisingEdge, ReadOnly
from cocotb.regression import TestFactory

@cocotb.coroutinue()
def do_test(dut, do_wait=False):
    if do_wait:
        yield Timer(1)
    dut.inp.setimmediatevalue(0)
    yield RisingEdge(dut.done)
    assert dut.inp.value == 0
    yield ReadOnly()
Read more comments on GitHub >

github_iconTop Results From Across the Web

setimmediatevalue doesnt work for signals wider than 32 bit
This is the first time that I am using setimmediatevalue with multibit control signals. So I would classify it as a bug.
Read more >
setImmediate?
I'd like to get a concise explanation (and consensus) for why we should or should not implement setImmediate[1]. I'm personally not wild about...
Read more >
Bit masking 32bit integer resulting negative value in nodejs
Basically, bitwise operators except shifting don't work the way you expect if the highest bit is on because JS turns them into a...
Read more >
cocotb/Lobby - Gitter
It barfs on trying to do arithmetic with the return value: ... I know that the current implementation of cocotb doesn't allow that,...
Read more >
Node.js v19.3.0 Documentation
When decoding a Buffer into a string, using this encoding will additionally unset the highest bit of each byte before decoding as 'latin1'...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found