From: Brad Pierce (Brad.Pierce@synopsys.com)
Date: Sat Jul 26 2003 - 08:08:08 PDT
Precedence: bulk
>Number: 402
>Category: errata
>Originator: "Brad Pierce" <Brad.Pierce@synopsys.com>
>Environment:
>Description:
Must a case expression be evaluated exactly once and before
any of the case item expressions? Or it would be legal to
implement a case by
if ( case_item_expression_1 == case_expression )
...
elsif ( case_item_expression_2 == case_expression )
...
I thought such an implementation would be incorrect in general,
because of the possibility of side-effects, but I see nothing
in the LRM to prohibit it. Here are two examples that highlight
the difference --
//------------------------------------------------------------------
module m_1 (o) ; /* Brad.Pierce@synopsys.com */
output [5:0] o ;
reg [5:0] o ;
integer i ;
integer j ;
function [5:0] f ;
input [5:0] n ;
begin
f = i ;
if ( n == i ) i = i + 1 ;
end
endfunction
task g ;
input [5:0] n ;
begin
$display(n) ;
j = j + n - 1 ;
end
endtask
always begin
i = 0 ;
j = 0 ;
while ( i <= 10 )
case ( i )
f(i) : g(i) ;
f(i) : g(i) ;
f(i) : g(i) ;
f(i) : g(i) ;
f(i) : g(i) ;
f(i) : g(i) ;
f(i) : g(i) ;
f(i) : g(i) ;
f(i) : g(i) ;
f(i) : g(i) ;
endcase
o = j ;
$display("should be %d? -- is %d", 10*(10+1)/2, o) ;
end
endmodule
//------------------------------------------------------------------
module m_2 (o) ; /* Brad.Pierce@synopsys.com */
output [5:0] o ;
reg [5:0] o ;
integer i ;
integer j ;
function [5:0] f ;
input [5:0] n ;
begin
if ( n == i ) i = i + 1 ;
f = i ;
end
endfunction
task g ;
input [5:0] n ;
j = j + n - 1 ;
endtask
always begin
i = 0 ;
j = 0 ;
while ( i <= 10 )
case ( i )
f(i) : g(i) ;
f(i) : g(i) ;
f(i) : g(i) ;
f(i) : g(i) ;
f(i) : g(i) ;
f(i) : g(i) ;
f(i) : g(i) ;
f(i) : g(i) ;
f(i) : g(i) ;
f(i) : g(i) ;
endcase
o = j ;
$display("should be %d? -- is %d", 0, o) ;
end
endmodule
//------------------------------------------------------------------
This archive was generated by hypermail 2.1.4
: Sat Jul 26 2003 - 08:11:04 PDT
and
sponsored by Boyd Technology, Inc.