10

My code:

module adder(a,b,result);
   input wire [9:0] a,b;
   output wire [10:0] result;
   assign result = a + b;
endmodule

My company recently changed policy to escalate the linting rule (W164a and W164b) mismatch of LHS and RHS bit widths from warnings to errors. Now I either have to waive these lines of code to tell the linting software not to freak out, or I have to prepend 1'b0 to both a & b.

What is the right approach here?

toolic
  • 8,262
  • 7
  • 24
  • 35

2 Answers2

13

The right approach is to discuss this situation with the people in your company who recently changed the policy. Your Verilog code is very clean, and it is a common way to add numbers together. Prepending 1'b0 to both a & b will result in code that is not commonly seen.

If you can not convince them to change this back to a warning, then you should waive these lines of code.

toolic
  • 8,262
  • 7
  • 24
  • 35
  • 1
    The reason stated for changing this was a lesson learnt in a previous project where they found some issue because they ignored this warning. I didn't discuss exactly what yet, but will do it. Thanks for the reply! – nebuchadnezzar_II May 05 '23 at 19:59
  • 3
    @nebuchadnezzar_II found some issue because they ignored this warning is unexpected. – greybeard May 06 '23 at 05:13
  • 1
    The obvious error case is where a or b is a signed quantity with a negative value and the variable is not marked signed. – grahamj42 May 07 '23 at 07:12
  • @greybeard, I agree and I'm not able to imagine such a situation. As grahamj42 points out, we do have the datapath switching in certain modes to signed representation. – nebuchadnezzar_II May 08 '23 at 19:27
8

IMHO, padding 0's should not be an error. Only implicit casting with the potential loss of data should be a warning or error. Consider using SystemVerilog's explicit casting in place of waivers

assign result = 11'(a + b);
dave_59
  • 8,312
  • 1
  • 15
  • 27