verilog simulator bug?

F

Francisco Camarero

Guest
Because I could not find a proper power operator for verilog,
and ^ is already taken by the bitwise xor, I decided to try
VHDL's one (**):

module bug ;

parameter exp1=3;
parameter exp2=4;

integer n1;
integer n2;

initial
begin
n1 = -2**exp1;
n2 = -2**exp2;
$display("n1=%4d; n2=%4d;",n1,n2);

end

endmodule

My simulator prints out:

# n1= -8; n2= 16;

What for me seems like ** has less precedence than - , not very common I would
say.

-2**e seems to mean (-2)**e, and not -(2**e)

how do other simulators behave?
 
On Thu, 10 Jun 2004 14:53:34 +0200, Francisco Camarero <no.sp@a.m>
wrote:

Because I could not find a proper power operator for verilog,
and ^ is already taken by the bitwise xor, I decided to try
VHDL's one (**):
** is the 'proper' Verilog power operator. It was only standardised
in 2001 though, so old textbooks won't mention it.

The unary operators +, -, !, ~ all have a higher precedence that the
binary operators such as **.
Your simulator is behaving properly.

Regards,
Allan.
 
Allan Herriman <allan.herriman.hates.spam@ctam.com.au.invalid> wrote in message news:<tcngc0tql4t1kcr35p488oh5vlggrubuec@4ax.com>...
** is the 'proper' Verilog power operator. It was only standardised
in 2001 though, so old textbooks won't mention it.

The unary operators +, -, !, ~ all have a higher precedence that the
binary operators such as **.
Your simulator is behaving properly.
Allen is correct. The new ** operator was given higher precedence than
any other binary operator, but is lower than the unary operators.

Note that many users may consider the "-2" in "-2**N" to be a negative
constant, rather than a unary minus operator applied to a positive
constant (which is how tools actually treat it). Giving the unary
minus a higher precedence makes this behave as they would expect.
 
Francisco:
LOL Don't know where you got your "verilog simulator" but mine printed
out precisely what I expected:

C:\Documents and Settings\Owner\My Documents>iverilog simtst.v
simtst.v:11: parse error
simtst.v:11: error: malformed statement
simtst.v:12: parse error
simtst.v:12: error: malformed statement
Command signaled:
C:\iverilog\lib\ivl\ivlpp -L -D__ICARUS__=1 -fC:\DOCUME~1\Owner\LOCALS~1\Te
mp\ivrlg2f3f | C:\iverilo
g\lib\ivl\ivl -CC:\DOCUME~1\Owner\LOCALS~1\Temp\ivrlh2f3f -g3.0 -tdll
-fDLL=C:\iverilog\lib\ivl\vvp.tgt -fVVP_EXEC
UTABLE=C:\iverilog\lib\ivl\..\..\bin\vvp -Fcprop -Fnodangle -oa.out -- -


----------------------------------------------------------------------------
----------------------------------------------------------
Thanks again Steven.
--
bj Porcella
http://pages.sbcglobal.net/bporcella/
"Francisco Camarero" <no.sp@a.m> wrote in message
news:40C859CE.3DC7FC3E@a.m...
Because I could not find a proper power operator for verilog,
and ^ is already taken by the bitwise xor, I decided to try
VHDL's one (**):

module bug ;

parameter exp1=3;
parameter exp2=4;

integer n1;
integer n2;

initial
begin
n1 = -2**exp1;
n2 = -2**exp2;
$display("n1=%4d; n2=%4d;",n1,n2);

end

endmodule

My simulator prints out:

# n1= -8; n2= 16;

What for me seems like ** has less precedence than - , not very common I
would
say.

-2**e seems to mean (-2)**e, and not -(2**e)

how do other simulators behave?
 
bj Porcella wrote:
Francisco:
LOL Don't know where you got your "verilog simulator" but mine printed
out precisely what I expected:

C:\Documents and Settings\Owner\My Documents>iverilog simtst.v
simtst.v:11: parse error
simtst.v:11: error: malformed statement
simtst.v:12: parse error
simtst.v:12: error: malformed statement
As has been pointed out elsewhere on the list, the ** operator
exists in Verilog-2001 and has precedence less then unary
operators. The commercial simulator that the original poster
tried aparently supports that operator correctly.

Icarus Verilog aparently does not:-( This is worthy of a
bug report.
--
Steve Williams "The woods are lovely, dark and deep.
steve at icarus.com But I have promises to keep,
http://www.icarus.com and lines to code before I sleep,
http://www.picturel.com And lines to code before I sleep."
 
Well heck. Guess I got some egg on my face for:
1) not knowing that ** is supported in 2001
2) Using a deficient verilog.
Oh well what do you expect for nothing :)
btw. I'm sure Steve can fix iverilog -- but I can't see much use for **
(don't think anybody wants that synthesized).
Anyone know why it was added?



bj Porcella
http://pages.sbcglobal.net/bporcella/
"Stephen Williams" <spamtrap@icarus.com> wrote in message
news:52d05$40c9c80e$40695902$26628@msgid.meganewsservers.com...
bj Porcella wrote:
Francisco:
LOL Don't know where you got your "verilog simulator" but mine
printed
out precisely what I expected:

C:\Documents and Settings\Owner\My Documents>iverilog simtst.v
simtst.v:11: parse error
simtst.v:11: error: malformed statement
simtst.v:12: parse error
simtst.v:12: error: malformed statement

As has been pointed out elsewhere on the list, the ** operator
exists in Verilog-2001 and has precedence less then unary
operators. The commercial simulator that the original poster
tried aparently supports that operator correctly.

Icarus Verilog aparently does not:-( This is worthy of a
bug report.
--
Steve Williams "The woods are lovely, dark and deep.
steve at icarus.com But I have promises to keep,
http://www.icarus.com and lines to code before I sleep,
http://www.picturel.com And lines to code before I sleep."
 
bj Porcella wrote:
Well heck. Guess I got some egg on my face for:
1) not knowing that ** is supported in 2001
2) Using a deficient verilog.
Oh well what do you expect for nothing :)
Hey, throw me some money and it won't be "nothing" anymore:)

btw. I'm sure Steve can fix iverilog -- but I can't see much use for **
(don't think anybody wants that synthesized).
Anyone know why it was added?
Actually, raising to a constant power is perfectly synthesizeable.
Certain powers would be pretty convenient, actually. But I imagine
it is most useful in test benches.

--
Steve Williams "The woods are lovely, dark and deep.
steve at icarus.com But I have promises to keep,
http://www.icarus.com and lines to code before I sleep,
http://www.picturel.com And lines to code before I sleep."
 

Welcome to EDABoard.com

Sponsor

Back
Top