chisel-book icon indicating copy to clipboard operation
chisel-book copied to clipboard

Writing should have priority over reading

Open Phantom1003 opened this issue 4 years ago • 1 comments

Suppose there is only one element in the FIFO (depth is 2), both read and write happens, the emptyReg should be false after this cycle

Phantom1003 avatar Aug 25 '21 10:08 Phantom1003

Can you explain the difference? These are all concurrent statements.

schoeberl avatar Jul 27 '22 14:07 schoeberl

Sorry for the late reply, if I remember correctly, there is a race condition.

As I mentioned, considering a 2-element FIFO.

# init
itePtr = 0, nextWrite = 1
readPtr = 0, nextRead = 1
# write something
writePrt = 1, nextWrite = 0
readPtr = 0, nextRead = 1

Although all statements are executed in parallel in chisel, if they occur at the same time, the later one will actually be used. If both read and write happens, the emptyReg will be assigned to true (nextRead === writePtr). But it should be false, so I change the order.

It looks like the latest code has fixed this race condition, I will close this pull.

Phantom1003 avatar Apr 07 '23 10:04 Phantom1003