On Tuesday, April 14, 2020 at 2:58:12 PM UTC-4, Richard Damon wrote:
> On 4/13/20 10:54 PM, Rick C wrote:
> > On Monday, April 13, 2020 at 9:51:06 PM UTC-4, Richard Damon wrote:
> >> On 4/13/20 9:08 PM, Rick C wrote:
> >>>
> >>> This is the sort of issue I have been warned about with Verilog. I would like to learn the details so I can use the language without fighting issues like this. Is there a good book on the language that explains all the default assumptions the language uses so as to fully understand what to expect? I've asked about this a number of times and no one seems to know of a good reference.
> >>>
> >>
> >> I figured it out with a bit of google-fu, where I found this document:
> >> <
https://sutherland-hdl.com/papers/2006-SNUG-Boston_standard_gotchas_presentation.pdf>
> >>
> >> Which explains a number of traps like that.
> >
> > Great guide. The one on sign extending literals is pathological. I like that they tell you to avoid this problem to "learn Verilog's sign extension rules!" but don't tell you how to do it correctly. I guess there is no "correct" way other than entering all the bits?
>
> Yes, because the literal is ALWAYS zero extended to its declared size.
> Sign extension of the value only happens after that, and only if the
> operation will be done as a signed operation. You only get signed
> operations if ALL the signals in the expression are signed.
Not sure I get what you are saying. After there are zeros appended to match sizes, there is no extension. What do you mean by "Sign extension of the value only happens after that"??? It looks like there is never automatic sign extension. Once the zeros are appended it's too late anyway.