bluespec.com Forum Index bluespec.com
Bluespec Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

repeat(n) in state machines, not behaving as expected

 
Post new topic   Reply to topic    bluespec.com Forum Index -> Designing with BSV's Rules, Interfaces, ...
View previous topic :: View next topic  
Author Message
jwhitham



Joined: 28 Sep 2012
Posts: 3

PostPosted: Fri Sep 28, 2012 12:49 pm    Post subject: repeat(n) in state machines, not behaving as expected Reply with quote

I am a newcomer to BSV. I am using the following code within an FSM in order to send bytes via a UART ("u"). The action is supposed to be repeated four times.
Code:
repeat(4) action
  u.enq(send_bytes[31:24]);
  send_bytes <= {send_bytes[23:0], ?};
endaction

However, it seems that the action is only repeated three times. Can anyone here shed any light on why this might be happening? If I replace the "repeat(4)" statement with a "while" loop and a counter register, it all works as expected.
Back to top
View user's profile Send private message
jwhitham



Joined: 28 Sep 2012
Posts: 3

PostPosted: Mon Oct 01, 2012 6:17 am    Post subject: Reply with quote

More information -- I think I have found a bug here. The semantics of "repeat(N)" are "repeat the following N times". But, under some circumstances, the implementation only repeats N-1 times.

I'm attaching a test case to reveal this. In the "repeat4" subdirectory I use "repeat(4)" to implement a loop within a state machine. In the "while4" subdirectory I use "while" and a counter register to implement the same thing. The first case fails (loop repeats 3 times). The second case works as expected.

I suspect the problem has something to do with my use of a VHDL component named "sc_uart.vhd" via BVI. But, if I change N (as in repeat(5) or repeat(3)) I get the same behaviour, which suggests it is not a bug in my interface or the VHDL. My investigation continues.



testcase-repeat4-1.tar.gz
 Description:

Download
 Filename:  testcase-repeat4-1.tar.gz
 Filesize:  64.81 KB
 Downloaded:  579 Time(s)

Back to top
View user's profile Send private message
jwhitham



Joined: 28 Sep 2012
Posts: 3

PostPosted: Mon Oct 01, 2012 9:14 am    Post subject: Reply with quote

I have made a simpler test case that reproduces the problem.

Seems that the initial increment of the repeat counter does not check the ready signals of the methods invoked within the action block.

When simulated, the attached source code should print out:
Code:
new cycle
send byte
18
send byte
52
send byte
86
send byte
120

but the final two lines are never printed. I get the same behaviour with both isim and bluesim.



Fault.bsv
 Description:

Download
 Filename:  Fault.bsv
 Filesize:  1.33 KB
 Downloaded:  573 Time(s)

Back to top
View user's profile Send private message
jnewbern



Joined: 18 Jul 2007
Posts: 71

PostPosted: Mon Oct 01, 2012 11:19 am    Post subject: Reply with quote

Thank you for the detailed bug report. I have been able to confirm the failure locally.

This is happening because of a bug in the way the FSM repeat construct is translated into atomic rules. The actions in the loop body each form a rule, and there is a separate rule which is managing the loop iteration count. The rule that manages the iteration count is not accounting for the implicit conditions in the loop body rule in your example, and this allows it to advance the iteration count one time without the loop body rule actually executing.

Now that we have this testcase, we should be able to fix this bug easily. In the meantime, I recommend using the while-loop workaround that you discussed.

Jeff
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    bluespec.com Forum Index -> Designing with BSV's Rules, Interfaces, ... All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
bluespec.com topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP