ISSUE 216

Number 216
Category errata
Synopsis 9.5: when is case default executed
State lrmdraft
Class errata-simple
Arrival-DateDec 11 2002
Originator Shalom.Bresticker@motorola.com
Release 2001b: 9.5
Environment
Description

When is a case default executed if it is not last in the
case item list?

9.5 says,

"The case item expressions shall be evaluated and compared
in the exact order in which they are given. During the
linear search, if one of the case item expressions matches
the case expression given in parentheses, then the statement
associated with that case item shall be executed. If all
comparisons fail and the default item is given, then the
default item statement shall be executed. If the default
statement is not given and all of the comparisons fail, then
none of the case item statements shall be executed."

From sentences 1 and 2, it would be understood that the
default is executed when it is encountered in the linear
search. If it is first, then it will always be executed.

From sentence 3, it would be understood that the default is
outside the linear search and is executed only if the linear
search among the non-default items is executed.

This should be clarified.
Alternately, the grammar could be changed to require that
the default always be last.
Fix
After the sentence

"The case item expressions shall be evaluated
and compared in the exact order in which they
are given."

insert the following sentence

"If there is a default case item, it is ignored
during this linear search."


Audit-Trail

From: "Brad Pierce" <Brad.Pierce@synopsys.com>
To: <etf-bugs@boyd.com>
Cc:
Subject: Re: errata/216: 9.5: when is case default executed
Date: Wed, 11 Dec 2002 11:47:30 -0800

The problem seems to be that in the BNF, A "case_item" can be a default
statement. The first sentence is talking about non-default case items.
The BNF does not restrict the default to occur at most once, nor to occur
only at the end.

A C "switch" construct allows at most one "default", but does not require
that it occur at the end. However, that default will not be followed unless
none of the cases match. That is, you can put the default as the first
item instead of the last item in C and it won't change the meaning.

But I've never seen C code that actually puts the default anywhere but at
the end. It seems like a reasonable restriction. Just because C allows
something weird doesn't mean Verilog should.

case_statement ::=
case (expression)
case_item {case_item} [case_default_item] endcase
| ...

case_item ::= expression {, expression } : statement_or_null

case_default_item ::= default [ : ] statement_or_null

Likewise for function_case_statement.

-- Brad


From: Steven Sharp <sharp@cadence.com>
To: etf-bugs@boyd.com, Brad.Pierce@synopsys.com
Cc:
Subject: Re: errata/216: 9.5: when is case default executed
Date: Wed, 11 Dec 2002 15:32:30 -0500 (EST)

> The problem seems to be that in the BNF, A "case_item" can be a default
> statement. The first sentence is talking about non-default case items.
> The BNF does not restrict the default to occur at most once, nor to occur
> only at the end.

That is because the default is not restricted to occur only at the end in
Verilog. And given that, it is hard to specify grammatically that it occur
only once. That becomes a semantic check.

> But I've never seen C code that actually puts the default anywhere but at
> the end. It seems like a reasonable restriction. Just because C allows
> something weird doesn't mean Verilog should.

Sure, but Verilog does and always has. We're not talking about some new
feature being tweaked before being added to the language. We are talking
about an existing feature in the language that needs to be documented in
the BNF.

> case_statement ::=
> case (expression)
> case_item {case_item} [case_default_item] endcase
> | ...
>
> case_item ::= expression {, expression } : statement_or_null
>
> case_default_item ::= default [ : ] statement_or_null

But that does not correctly express the Verilog syntax. You can't
simplify the BNF if the result is wrong.

Steven Sharp
sharp@cadence.com


From: "Brad Pierce" <Brad.Pierce@synopsys.com>
To: <etf-bugs@boyd.com>
Cc:
Subject: Re: errata/216: 9.5: when is case default executed
Date: Wed, 11 Dec 2002 12:46:53 -0800

I didn't mean to suggest that the alternative BNF was a correct
expression of current Verilog syntax. Instead it was intended
as an example of one possibility for improving Verilog.
If many Verilog programs already put default statements
somewhere other than at the end, then such a change
would break too much existing code. If almost all Verilog
programs simply put the default at the end, then the traditional
Verilog syntax might as well be improved.

-- Brad




From: Steven Sharp <sharp@cadence.com>
To: etf-bugs@boyd.com
Cc:
Subject: Re: errata/216: 9.5: when is case default executed
Date: Wed, 11 Dec 2002 16:27:59 -0500 (EST)

> If almost all Verilog
> programs simply put the default at the end, then the traditional
> Verilog syntax might as well be improved.

As long as "almost all" includes all the designs being used by _our_
customers, I'll agree.

Steven Sharp
sharp@cadence.com


From: Gordon Vreugdenhil <gvreugde@Synopsys.COM>
To: Steven Sharp <sharp@cadence.com>
Cc: etf-bugs@boyd.com
Subject: Re: errata/216: 9.5: when is case default executed
Date: Wed, 11 Dec 2002 13:50:16 -0800

Although I really like the "default at the end" rule from a
language design perspective, I consider this to be a non-essential
change in terms of adding backwards compliance risk. If we want
to clarify the behaviour, fine, but let's not just introduce
legacy incompatibility unless there is a compelling reason.

Gord.

Steven Sharp wrote:
>
> Precedence: bulk
>
> The following reply was made to PR errata/216; it has been noted by GNATS.
>
> From: Steven Sharp <sharp@cadence.com>
> To: etf-bugs@boyd.com
> Cc:
> Subject: Re: errata/216: 9.5: when is case default executed
> Date: Wed, 11 Dec 2002 16:27:59 -0500 (EST)
>
> > If almost all Verilog
> > programs simply put the default at the end, then the traditional
> > Verilog syntax might as well be improved.
>
> As long as "almost all" includes all the designs being used by _our_
> customers, I'll agree.
>
> Steven Sharp
> sharp@cadence.com
>

--
----------------------------------------------------------------------
Gord Vreugdenhil gvreugde@synopsys.com
Staff Engineer, VCS (Verification Tech. Group) (503) 547-6054
Synopsys Inc., Beaverton OR

From: Steven Sharp <sharp@cadence.com>
To: etf-bugs@boyd.com
Cc:
Subject: Re: errata/216: 9.5: when is case default executed
Date: Wed, 11 Dec 2002 19:32:55 -0500 (EST)

>"The case item expressions shall be evaluated and compared
>in the exact order in which they are given. During the
>linear search, if one of the case item expressions matches
>the case expression given in parentheses, then the statement
>associated with that case item shall be executed. If all
>comparisons fail and the default item is given, then the
>default item statement shall be executed. If the default
>statement is not given and all of the comparisons fail, then
>none of the case item statements shall be executed."
>
>From sentences 1 and 2, it would be understood that the
>default is executed when it is encountered in the linear
>search. If it is first, then it will always be executed.

No. Read it again. There is a linear search through the
case item expressions. When there is a match, the statement
associated with it is executed. A default item does not have
a case item expression, so it could not be executed during
the linear search.

If the LRM said that "default" acts like a "match-anything"
case item expression, then you would be correct. It would
execute when it was reached in the linear search through
case item expressions. But that isn't what the LRM says.

The description is not perfect, but I don't see how it can
be misinterpreted by someone who actually reads what it says.

Steven Sharp
sharp@cadence.com


From: "Brad Pierce" <Brad.Pierce@synopsys.com>
To: <etf-bugs@boyd.com>
Cc:
Subject: Re: errata/216: 9.5: when is case default executed
Date: Wed, 11 Dec 2002 18:43:11 -0800

Steven,

Yes, there is no case item expression in a default case item.

And according to 9.5 --

"Use of multiple default statements in one case statement
shall be illegal."

So I think this issue 216 could be closed.

-- Brad



From: Shalom Bresticker <Shalom.Bresticker@motorola.com>
To: etf-bugs@boyd.com
Cc:
Subject: Re: errata/216: 9.5: when is case default executed
Date: Thu, 12 Dec 2002 09:53:13 +0200

There is an ambiguity here.

Even if you can claim that you should be able to figure out the meaning,
it is not obvious. Let's be honest. Both the standard writers and the
standard readers are human beings.

The writers do not always write precisely,
and the readers unconsciously take that into account.

It is very logical to interpret "case item expression" as
"any case_item, which in the general case is an expression".

It does not use a formal term such as case_item_expression
(which does not exist).

The fact is that I found a code checking tool manual with a check
that claims that a non-last default will be executed according to the linear
search order.

The fact is that when I read the standard, it was not obvious even to me
what is the correct behavior, or even whether the standard writers thought about
that case.

Only when I ran a simulation on Verilog-XL last night did I find support for the
other
interpretation. I still do not know what other simulators and other tools do.

Since it is legal, and since according to Verilog-XL, the default is always
executed at the end,
I would not change the BNF, but it is necessary to clarify the text.

It could be as simple as changing "The case item expressions ..." to
"The case item expressions, excluding the default case item, ..."


From: Steven Sharp <sharp@cadence.com>
To: etf-bugs@boyd.com
Cc:
Subject: Re: errata/216: 9.5: when is case default executed
Date: Thu, 12 Dec 2002 19:38:16 -0500 (EST)

> I would not change the BNF, but it is necessary to clarify the text.

I would support a clarification, as long as it doesn't introduce new
issues, and doesn't take too much discussion time.

> It could be as simple as changing "The case item expressions ..." to
> "The case item expressions, excluding the default case item, ..."

This wording could be confusing, since the default case item is not a case
item expression. I would suggest instead adding after that sentence, a
separate sentence saying: "Any default case item is ignored during the
linear search."

Steven Sharp
sharp@cadence.com

Unformatted


Hosted by Boyd Technology