+ Post New Thread
Results 1 to 4 of 4
  1. #1
    Full Member level 4
    Points: 1,635, Level: 9

    Join Date
    Jul 2014
    Posts
    203
    Helped
    14 / 14
    Points
    1,635
    Level
    9

    declaring a constant value for all modules in verilog

    hi,
    i had some 40 nos of 32 bit constant in a verilog module used for some calculations. i am replicating this module for some 10 times.
    so basically i am repeating the values in all the modules and wasting resources. so is it possible to declare it only once and use it in all the 10 modules.
    10 instantiations are from the same module.

    i declared it like this.
    reg [15:0] mem [0:40];
    so instead of repeating like this in all modules is it possible to declare only once and use it in all the 10 modules?

    how can i do it? if it do so will it reduce the logic utilization?

    any help is really appriciated

    thanks and regards

    •   Alt6th April 2018, 06:12

      advertising

        
       

  2. #2
    Super Moderator
    Points: 241,298, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    41,879
    Helped
    12747 / 12747
    Points
    241,298
    Level
    100

    Re: declaring a constant value for all modules in verilog

    Constants known at synthesis time are inserted in each expression separately. The definition method doesn't affect the logic or memory utilization. It's only a question of effective code writing.

    In the System Verilog world, packages are a suitable way to define global constants (as in VHDL since ever).

    In plain Verilog, including constant definitions is probably the best way.


    1 members found this post helpful.

    •   Alt6th April 2018, 06:30

      advertising

        
       

  3. #3
    Full Member level 4
    Points: 1,635, Level: 9

    Join Date
    Jul 2014
    Posts
    203
    Helped
    14 / 14
    Points
    1,635
    Level
    9

    Re: declaring a constant value for all modules in verilog

    hi,
    so if i use some compiler directive like `include (or some other way)and include all of my constants,

    it won't help me to reduce my logic utilization right?
    while elaborating, it will assigned in each module separately ... is it?

    thanks



    •   Alt6th April 2018, 07:26

      advertising

        
       

  4. #4
    Super Moderator
    Points: 241,298, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    41,879
    Helped
    12747 / 12747
    Points
    241,298
    Level
    100

    Re: declaring a constant value for all modules in verilog

    Yes. There are however some cases where array constants can be more effectively implemented as initialized block ram, e.g. when multiple constants are muxed to a single target.



--[[ ]]--