B-Lang-org / bsc

Bluespec Compiler (BSC)
Other
936 stars 143 forks source link

Bluesim's symbol-probing interface has wrong values for FIFO #677

Open quark17 opened 7 months ago

quark17 commented 7 months ago

This issue was uncovered on the b-lang-discuss mailing list ("How to get fifo's runtime status in bluetcl?"). Bluesim has a "symbols" interface which allows probing values in the modules of a design.

For the FIFO primitives, they appear to provide access to three things: the array of values in the FIFO, a "depth", and a "level":

% sim ls f.*
{f. {signal range(0:1)}} {f.depth signal} {f.level signal}

However, I think there's a bug in the implementation. I believe that depth is attempting to provide the configured depth of the FIFO (a constant value) and that level is the current number of elements (a dynamic value). What I observe is that depth returns the value of an invalid memory location! And level returns the static size. (The depth is defined as a pointer to a constructor argument, which is no longer a valid location after the constructor finishes.)

We can probably fix this by changing these two definitions in bsc/src/bluesim/bs_prim_mod_fifo.h (around line 73):

symbols[1].value = (void*)(&depth);
symbols[2].value = (void*)(&size);

to instead be:

symbols[1].value = (void*)(&size);
symbols[2].value = (void*)(&elems);

That is, depth should point to size (a local variable with constant value) and level should point to elems (a local variable that indicates the current number of elements).

Interactive mode is tested in bsc/testsuite/bsc.bluesim/interactive/ and there is a script prims.cmd for testing primitives, but it only tests that signals can be probed and not that they have the right dynamic values, so that would need to be added.