+ Post New Thread
Results 1 to 8 of 8
  1. #1
    Advanced Member level 5
    Points: 12,859, Level: 27
    Achievements:
    7 years registered

    Join Date
    Aug 2011
    Posts
    2,586
    Helped
    300 / 300
    Points
    12,859
    Level
    27

    System Verilog - default type of a declared variable

    Hello,

    As far as I know (correct me if I'm wrong), if we declare a variable in Verilog without explicitly giving it a type - it defaults to a "wire".
    Is this rule the same with System Verilog ? Or the default is something else ( "logic" for example ) ?

    •   AltAdvertisment

        
       

  2. #2
    Advanced Member level 5
    Points: 7,230, Level: 20

    Join Date
    Apr 2016
    Posts
    1,536
    Helped
    265 / 265
    Points
    7,230
    Level
    20

    Re: System Verilog - default type of a declared variable

    Quote Originally Posted by shaiko View Post
    Hello,

    As far as I know (correct me if I'm wrong), if we declare a variable in Verilog without explicitly giving it a type - it defaults to a "wire".
    Is this rule the same with System Verilog ? Or the default is something else ( "logic" for example ) ?
    inputs/outputs in verilog default to wire. variables are the type you declared them to be.
    Really, I am not Sam.


    1 members found this post helpful.

  3. #3
    Advanced Member level 5
    Points: 12,859, Level: 27
    Achievements:
    7 years registered

    Join Date
    Aug 2011
    Posts
    2,586
    Helped
    300 / 300
    Points
    12,859
    Level
    27

    Re: System Verilog - default type of a declared variable

    With SV, is there a good reason why not declare all variables and ports as type "logic" ?



    •   AltAdvertisment

        
       

  4. #4
    Advanced Member level 3
    Points: 5,683, Level: 17

    Join Date
    Feb 2015
    Posts
    939
    Helped
    269 / 269
    Points
    5,683
    Level
    17

    Re: System Verilog - default type of a declared variable

    Verilog has `default_nettype option. this can be added to the top of any files you write. Verilog's default net type is wire and any undeclared variables will be of that type. This made a lot more sense when structural designs were popular. I've only seen `default_nettype none used, so I don't know if you can set `default_nettype logic. Doing so should convert any typos into 1 bit logic.



  5. #5
    Advanced Member level 5
    Points: 12,859, Level: 27
    Achievements:
    7 years registered

    Join Date
    Aug 2011
    Posts
    2,586
    Helped
    300 / 300
    Points
    12,859
    Level
    27

    Re: System Verilog - default type of a declared variable

    But isn't writing`default_nettype none equivalent to not writing anything at all ?



  6. #6
    Advanced Member level 3
    Points: 5,683, Level: 17

    Join Date
    Feb 2015
    Posts
    939
    Helped
    269 / 269
    Points
    5,683
    Level
    17

    Re: System Verilog - default type of a declared variable

    Verilog has an anti-feature that an undeclared name is treated as a wire. Before Verilog2001, this would always be 1 bit. After 2001, the width could be inferred. The intent seems to have been making it easier to connect module instances in a highly structural design.

    Because typos get treated as wires, some developers declare `default_nettype none. A side effect of this is that ports now need "input wire" vs just "input".


    1 members found this post helpful.

  7. #7
    Advanced Member level 5
    Points: 12,859, Level: 27
    Achievements:
    7 years registered

    Join Date
    Aug 2011
    Posts
    2,586
    Helped
    300 / 300
    Points
    12,859
    Level
    27

    Re: System Verilog - default type of a declared variable

    What do you do in your designs?
    Suppose, a signal is indeed logically a wire - do you explicitly declare it as a such?



    •   AltAdvertisment

        
       

  8. #8
    Advanced Member level 3
    Points: 6,244, Level: 18
    Achievements:
    Created Blog entry 7 years registered

    Join Date
    Dec 2011
    Location
    Fremont, CA, USA
    Posts
    764
    Helped
    350 / 350
    Points
    6,244
    Level
    18
    Blog Entries
    4

    Re: System Verilog - default type of a declared variable

    Dave Rich
    Senior Verification Consultant
    Mentor Graphics Corporation



--[[ ]]--