• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC Design
  3. Verilog-A 2**integer yields wrong value

Stats

  • Locked Locked
  • Replies 1
  • Subscribers 125
  • Views 3825
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Verilog-A 2**integer yields wrong value

AlbertoGS
AlbertoGS over 9 years ago

Hi,

I have come across a very strange bug. I created a module in verilog-A that at some point converts a integer input into a binary number. To do so it successively divides the input by factors of 2

However, I found that using an expression of type:

2**i // i declared an integer

Does not result in the right number being generated!

Look at the following for loop

        for (i=`NUM_ADC_BITS-1; i>=0; i=i-1 ) begin
            $display("%d", 2**i);
        end

It ouputs:

2048
1024
511
255
127
63
32
15
8
4
2
1


Using a genvar or the function pow() solves the problem, however this behaviour seems to be potentially very dangerous to me. Does anyone have any insight of why this (should) happen?

Many thanks,

Alberto Gomez

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 9 years ago

    Hi Alberto,

    There's no good reason for this - it's a bug in the implementation as far as I can see. The ** operator was added in MMSIM13.1 (it was something introduced in the 2.3 VerilogAMS LRM).

    I've filed CCR 1526534 to get this fixed. You get slightly different behaviour depending on whether you're running 32 bit or 64 bit spectre (your output matches what I see in 64 bit spectre, whereas with with 32 bit spectre only 31 is wrong).

    I would suggest using 1<<i instead as that always works to get a power of 2 for integers (it does a 1 left-shifted i times) in the meantime.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information