简体   繁体   English

用于可综合代码的verilog编码风格

[英]verilog coding style for synthesizable code

I coded something like the following: 我编写了如下内容:

always @(state or i1 or i2 or i3 or i4) begin
next = 5'bx;
err = 0; n_o1 = 1;
o2 = 0; o3 = 0; o4 = 0;
case (state) // synopsys full_case parallel_case
IDLE: begin
if (!i1) next = IDLE;
else if ( i2) next = S1;
else if ( i3) next = S2;
else next = ERROR;
end
S1: begin
if (!i2) next = S1;
else if ( i3) next = S2;
else if ( i4) next = S3;
else next = ERROR;**strong text**
...

My manager, of course I don't want to argue with him before I have some strong argument, but he reviewed my code and said writing 我的经理当然,在我有一些强烈的争论之前,我不想和他争论,但他回顾了我的代码,并说写作

next = 5'bx;
err = 0; n_o1 = 1;
o2 = 0; o3 = 0; o4 = 0;

in a combinational logic without putting the right side in the sensitivity list will cause problems in synthesis.By not having these 3 lines, I need to explicitly write the else part inside each individual case, and he said yes. 在没有将右侧置于敏感性列表中的组合逻辑中将导致综合问题。由于没有这3行,我需要在每个单独的案例中明确地写出else部分,并且他说是。

I am wondering is there anything wrong with this coding style? 我想知道这种编码风格有什么问题吗? And will it cause a synthesis problem or any sort of problem(maybe some version or old synthesis tool won't synthesize?) by initializing these values in the combinational logic? 并且它会通过在组合逻辑中初始化这些值而导致合成问题或任何类型的问题(可能某些版本或旧的综合工具不会合成?) What he said does make sense to me and I actually never thought about it because he said this is software logic, and every wire gets its initial value from the logic before it with the initial condition. 他说的话对我来说很有意义,我实际上从未想过它,因为他说这是软件逻辑,并且每条线在初始条件之前从逻辑中得到它的初始值。 I told him school taught us this, he was like school cares less any synthesis but industry does. 我告诉他学校教给我们这个,他就像学校一样关心任何合成,但行业确实如此。

Thank you for your help! 谢谢您的帮助! Guess I am not trying to convince him anything even I have a answer, since the team need to stick with one style anyways, but i am confused by him since I have seen others doing this all the time and he is also a guy with tons of experience, so...confused 猜猜我也没有试图说服他什么,即使我有答案,因为团队需要坚持一种风格,但我很困惑,因为我看到其他人一直这样做,他也是一个有吨的人经验,所以...困惑

First of all, you should be using always @(*) from Verilog-2001 or even better always_comb from SystemVerilog so the sensitivity list get constructed automatically for you. 首先,您应该always @(*)使用来自Verilog-2001的always @(*) ,或者甚至更好地always_comb SystemVerilog中的always_comb ,以便自动构建灵敏度列表。

The problem with your code is the use of the full case synthesis pragma as described in this paper . 您的代码的问题是使用full case合成编译指示,如本文所述 Your coding style removes the need for full case as long as you are sure you made assignments to every variable in the always block for all possible flows through the block. 只要您确定为always块中的每个变量分配了通过块的所有可能流,您的编码样式就不再需要完整的大小写。

I think what your boss means by "software logic" is that your coding style requires the designer to think sequentially. 我认为你的老板对“软件逻辑”的意思是你的编码风格要求设计师按顺序思考。 In other words, when I read your always block, I am first forced to think about all the values being initialized to their default values, then I must evaluate the case logic. 换句话说,当我读取你的always块时,我首先被迫考虑所有被初始化为默认值的值,然后我必须评估案例逻辑。 In reality, the logic will synthesize into the equivalent of a default case. 实际上,逻辑将合成为default情况的等价物。 This causes a disparity between the logic that represents the RTL and the logic of how I evaluate your expression in my mind. 这导致了代表RTL的逻辑与我在脑海中评估你的表达的逻辑之间的差异。 If you know what your doing, then this should be fine most of the time . 如果你知道自己在做什么,那么大部分时间都应该没问题。 But you are working for a company, so your code should be considerate of the other engineers working on a project. 但是你在为一家公司工作,所以你的代码应该考虑到从事项目的其他工程师。 Each different team in the design flow is going to view the same logic through a potentially different lens (for example, the physical design team is not concerned with Verilog but the synthesized RTL). 设计流程中的每个不同团队将通过可能不同的镜头来查看相同的逻辑(例如,物理设计团队不关心Verilog而是合成的RTL)。 If we write our Verilog to reflect the final RTL (ie "hardware logic"), then everyone is analyzing the logic in a similar fashion. 如果我们编写Verilog来反映最终的RTL(即“硬件逻辑”),那么每个人都在以类似的方式分析逻辑。 If I look at an output in a circuit and I know all the values of the inputs at a given time step, then I can visually trace the output through the circuit and determine its value without giving any consideration to the other logic. 如果我查看电路中的输出并且我知道给定时间步长的所有输入值,那么我可以通过电路直观地跟踪输出并确定其值而不考虑其他逻辑。 Your Verilog code should be written in the same way. 您的Verilog代码应以相同的方式编写。

To summarize, your initialization statements are nothing more than another case in the selection mux in the RTL. 总而言之,您的初始化语句只不过是RTL中选择多路复用器的另一种情况。 So, you should write it that way. 所以,你应该这样写。 Use a default case and explicitly assign every output of the block in each case. 使用default情况并在每种情况下显式分配块的每个输出。 This is generally considered best practice. 这通常被认为是最佳做法。 It may not be the most clever or elegant way to write Verilog, but it is the most readable and results in far fewer errors (and in industry, people are more concerned with design verification to reduce costs than the cleverness of Verilog). 它可能不是编写Verilog最聪明或最优雅的方式,但它最具可读性并且导致错误少得多(在工业中,人们更关心设计验证以降低成本而不是Verilog的聪明才智)。

Also, as @dave_59 brought up, if you use the full_case Synopsis directive, then it will create default output drivers for you where the outputs are set to "don't cares." 另外,正如@ dave_59所提出的那样,如果你使用full_case Synopsis指令,那么它将为你创建默认输出驱动程序,其输出设置为“不关心”。 This is not a result that anyone wants, and it would be flagged by the verification team. 这不是任何人想要的结果,它将由验证团队标记。 To fix it, you would need to make sure every output is being assigned by adding them to all the cases like your boss mentioned. 要解决这个问题,你需要确保通过将它们添加到像老板提到的所有案例中来分配每个输出。 If you are forced to do this anyways, then full_case is redundant because you have explicitly made the case statement full. 如果你无论如何都被迫这样做,那么full_case是多余的,因为你已经明确地将case语句填满了。 As for older synthesis tools, I don't see that being as big of an issue for this particular subject, but it is a consideration that is always given in industry. 至于较旧的综合工具,我认为这个特定主题并不是一个大问题,但它是一个始终在工业界给予的考虑。 What would be more of an issue is if your company has configured downstream tools to force older constructs in an effort to reduce verification costs. 如果您的公司已配置下游工具以强制使用较旧的结构以降低验证成本,那么问题就更大了。

Trust your manager's experience on this issue. 相信您的经理在这个问题上的经验。 Coding style in industry is largely affected by collaboration with other engineers, costs, and legacy than by technical details. 工业中的编码风格很大程度上受到与其他工程师,成本和遗产的合作的影响,而不是技术细节。 This is where your manager's experience will be valuable. 这是您经理的经验值得珍惜的地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM