SystemVerilog error in multiplexing channels : nonconstant index into instance arrayInstantiating a systemc module from a VHDL testbenchSystemVerilog generic multiplexerNonconstant index into instance arraySystemVerilog Interface multiplexerSystemVerilog Array IndexModelsim - Object not logged & no signal data while simulating verilog clock divider codeHow to pass a variable to the define macro used for accessing the path in system verilogHow to correctly slice an array of real numbers in SystemVerilog?Quartus Prime compilation ROMUnpredicted behavior of design in Cyclone V

Why is this estimator biased?

Keeping a ball lost forever

What is Cash Advance APR?

Has any country ever had 2 former presidents in jail simultaneously?

How should I respond when I lied about my education and the company finds out through background check?

Quoting Keynes in a lecture

Is there a RAID 0 Equivalent for RAM?

Can the US President recognize Israel’s sovereignty over the Golan Heights for the USA or does that need an act of Congress?

Can disgust be a key component of horror?

How does the math work for Perception checks?

Can a stoichiometric mixture of oxygen and methane exist as a liquid at standard pressure and some (low) temperature?

What does chmod -u do?

Yosemite Fire Rings - What to Expect?

What are the advantages of simplicial model categories over non-simplicial ones?

How can "mimic phobia" be cured or prevented?

What is the highest possible scrabble score for placing a single tile

How to hide some fields of struct in C?

Are Captain Marvel's powers affected by Thanos' actions in Infinity War

How do you respond to a colleague from another team when they're wrongly expecting that you'll help them?

Calculating total slots

When were female captains banned from Starfleet?

Extract more than nine arguments that occur periodically in a sentence to use in macros in order to typset

What exact color does ozone gas have?

How to fade a semiplane defined by line?



SystemVerilog error in multiplexing channels : nonconstant index into instance array


Instantiating a systemc module from a VHDL testbenchSystemVerilog generic multiplexerNonconstant index into instance arraySystemVerilog Interface multiplexerSystemVerilog Array IndexModelsim - Object not logged & no signal data while simulating verilog clock divider codeHow to pass a variable to the define macro used for accessing the path in system verilogHow to correctly slice an array of real numbers in SystemVerilog?Quartus Prime compilation ROMUnpredicted behavior of design in Cyclone V













0















I'm designing a module that accepts multiple channels and outputs one channel.
Each channel consists of valid signal and data of some widths.
If a channel has valid data, the module should output that channel. If multiple channels have valid data, the module should output one of them (in my case, channel with highest index) and rests are dropped.



My simple implementation looks like this:



module test1 #(
parameter NUM_CHANNEL = 8,
parameter DATA_WIDTH = 512
) (
input logic [DATA_WIDTH - 1 : 0] data_in [NUM_CHANNEL],
input logic valid_in [NUM_CHANNEL],
output logic [DATA_WIDTH - 1 : 0] data_out,
output logic valid_out
);

always_comb begin
valid_out = 0;
for (int i = 0; i < NUM_CHANNEL; ++i) begin
if (valid_in[i]) begin
valid_out = 1;
data_out = data_in[i];
end
end
end

endmodule


This works perfectly in both simulation and real circuit (FPGA).



However, channel can be complex type so I used interface like this:



interface channel #(
parameter DATA_WIDTH = 512
);

logic valid;
logic [DATA_WIDTH - 1 : 0] data;

modport in (
input valid,
input data
);

modport out (
output valid,
output data
);

endinterface // sub_csr_if

module test #(
parameter NUM_CHANNEL = 8,
parameter DATA_WIDTH = 512
) (
channel.in in[NUM_CHANNEL],
channel.out out
);

always_comb begin
out.valid = 0;
for (int i = 0; i < NUM_CHANNEL; ++i) begin
if (in[i].valid) begin
out.valid = 1;
out.data = in[i].data;
end
end
end

endmodule


Then, this code gets Nonconstant index into instance array 'sub_port'. error in ModelSim, and i is not a constant error in Quartus.



If I unroll the loop, it works but it becomes non-parametric code. (only works for fixed NUM_CHANNEL)



Why the latter one does not work, while the first one works flawlessly?










share|improve this question


























    0















    I'm designing a module that accepts multiple channels and outputs one channel.
    Each channel consists of valid signal and data of some widths.
    If a channel has valid data, the module should output that channel. If multiple channels have valid data, the module should output one of them (in my case, channel with highest index) and rests are dropped.



    My simple implementation looks like this:



    module test1 #(
    parameter NUM_CHANNEL = 8,
    parameter DATA_WIDTH = 512
    ) (
    input logic [DATA_WIDTH - 1 : 0] data_in [NUM_CHANNEL],
    input logic valid_in [NUM_CHANNEL],
    output logic [DATA_WIDTH - 1 : 0] data_out,
    output logic valid_out
    );

    always_comb begin
    valid_out = 0;
    for (int i = 0; i < NUM_CHANNEL; ++i) begin
    if (valid_in[i]) begin
    valid_out = 1;
    data_out = data_in[i];
    end
    end
    end

    endmodule


    This works perfectly in both simulation and real circuit (FPGA).



    However, channel can be complex type so I used interface like this:



    interface channel #(
    parameter DATA_WIDTH = 512
    );

    logic valid;
    logic [DATA_WIDTH - 1 : 0] data;

    modport in (
    input valid,
    input data
    );

    modport out (
    output valid,
    output data
    );

    endinterface // sub_csr_if

    module test #(
    parameter NUM_CHANNEL = 8,
    parameter DATA_WIDTH = 512
    ) (
    channel.in in[NUM_CHANNEL],
    channel.out out
    );

    always_comb begin
    out.valid = 0;
    for (int i = 0; i < NUM_CHANNEL; ++i) begin
    if (in[i].valid) begin
    out.valid = 1;
    out.data = in[i].data;
    end
    end
    end

    endmodule


    Then, this code gets Nonconstant index into instance array 'sub_port'. error in ModelSim, and i is not a constant error in Quartus.



    If I unroll the loop, it works but it becomes non-parametric code. (only works for fixed NUM_CHANNEL)



    Why the latter one does not work, while the first one works flawlessly?










    share|improve this question
























      0












      0








      0








      I'm designing a module that accepts multiple channels and outputs one channel.
      Each channel consists of valid signal and data of some widths.
      If a channel has valid data, the module should output that channel. If multiple channels have valid data, the module should output one of them (in my case, channel with highest index) and rests are dropped.



      My simple implementation looks like this:



      module test1 #(
      parameter NUM_CHANNEL = 8,
      parameter DATA_WIDTH = 512
      ) (
      input logic [DATA_WIDTH - 1 : 0] data_in [NUM_CHANNEL],
      input logic valid_in [NUM_CHANNEL],
      output logic [DATA_WIDTH - 1 : 0] data_out,
      output logic valid_out
      );

      always_comb begin
      valid_out = 0;
      for (int i = 0; i < NUM_CHANNEL; ++i) begin
      if (valid_in[i]) begin
      valid_out = 1;
      data_out = data_in[i];
      end
      end
      end

      endmodule


      This works perfectly in both simulation and real circuit (FPGA).



      However, channel can be complex type so I used interface like this:



      interface channel #(
      parameter DATA_WIDTH = 512
      );

      logic valid;
      logic [DATA_WIDTH - 1 : 0] data;

      modport in (
      input valid,
      input data
      );

      modport out (
      output valid,
      output data
      );

      endinterface // sub_csr_if

      module test #(
      parameter NUM_CHANNEL = 8,
      parameter DATA_WIDTH = 512
      ) (
      channel.in in[NUM_CHANNEL],
      channel.out out
      );

      always_comb begin
      out.valid = 0;
      for (int i = 0; i < NUM_CHANNEL; ++i) begin
      if (in[i].valid) begin
      out.valid = 1;
      out.data = in[i].data;
      end
      end
      end

      endmodule


      Then, this code gets Nonconstant index into instance array 'sub_port'. error in ModelSim, and i is not a constant error in Quartus.



      If I unroll the loop, it works but it becomes non-parametric code. (only works for fixed NUM_CHANNEL)



      Why the latter one does not work, while the first one works flawlessly?










      share|improve this question














      I'm designing a module that accepts multiple channels and outputs one channel.
      Each channel consists of valid signal and data of some widths.
      If a channel has valid data, the module should output that channel. If multiple channels have valid data, the module should output one of them (in my case, channel with highest index) and rests are dropped.



      My simple implementation looks like this:



      module test1 #(
      parameter NUM_CHANNEL = 8,
      parameter DATA_WIDTH = 512
      ) (
      input logic [DATA_WIDTH - 1 : 0] data_in [NUM_CHANNEL],
      input logic valid_in [NUM_CHANNEL],
      output logic [DATA_WIDTH - 1 : 0] data_out,
      output logic valid_out
      );

      always_comb begin
      valid_out = 0;
      for (int i = 0; i < NUM_CHANNEL; ++i) begin
      if (valid_in[i]) begin
      valid_out = 1;
      data_out = data_in[i];
      end
      end
      end

      endmodule


      This works perfectly in both simulation and real circuit (FPGA).



      However, channel can be complex type so I used interface like this:



      interface channel #(
      parameter DATA_WIDTH = 512
      );

      logic valid;
      logic [DATA_WIDTH - 1 : 0] data;

      modport in (
      input valid,
      input data
      );

      modport out (
      output valid,
      output data
      );

      endinterface // sub_csr_if

      module test #(
      parameter NUM_CHANNEL = 8,
      parameter DATA_WIDTH = 512
      ) (
      channel.in in[NUM_CHANNEL],
      channel.out out
      );

      always_comb begin
      out.valid = 0;
      for (int i = 0; i < NUM_CHANNEL; ++i) begin
      if (in[i].valid) begin
      out.valid = 1;
      out.data = in[i].data;
      end
      end
      end

      endmodule


      Then, this code gets Nonconstant index into instance array 'sub_port'. error in ModelSim, and i is not a constant error in Quartus.



      If I unroll the loop, it works but it becomes non-parametric code. (only works for fixed NUM_CHANNEL)



      Why the latter one does not work, while the first one works flawlessly?







      system-verilog modelsim quartus






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      csehydrogencsehydrogen

      657




      657






















          1 Answer
          1






          active

          oldest

          votes


















          2














          An array of instances (module or interface) is not a true array type. As your error message indicates, you cannot select a particular instance with a variable index. With a true array, every element is identical. Because of the way parameterization, defparam, and port connections work, each instance element could have differences. The elaboration process essentially flattens all hierarchy before simulation begins.



          What you can do is use a generate construct to select your instance as follows
          ;



          module test #(
          parameter NUM_CHANNEL = 8,
          parameter DATA_WIDTH = 512
          ) (
          channel.in in[NUM_CHANNEL],
          channel.out out
          );

          logic _valid[NUM_CHANNEL];
          logic [DATA_WIDTH - 1 : 0] _data[NUM_CHANNEL];

          for (genvar ii=0;ii<NUM_CHANNEL;ii++) begin
          assign _valid[ii] = in[ii].valid;
          assign _data[ii] = in[ii].data;
          end
          always_comb begin
          out.valid = 0;
          for (int i = 0; i < NUM_CHANNEL; ++i) begin
          if (_valid[i]) begin
          out.valid = 1;
          out.data = _data[i];
          end
          end
          end

          endmodule





          share|improve this answer























          • I got it. I became curious; do you have a good example of Because of the way parameterization, defparam, and port connections work, each instance element could have differences.?

            – csehydrogen
            yesterday










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55280467%2fsystemverilog-error-in-multiplexing-channels-nonconstant-index-into-instance-a%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          An array of instances (module or interface) is not a true array type. As your error message indicates, you cannot select a particular instance with a variable index. With a true array, every element is identical. Because of the way parameterization, defparam, and port connections work, each instance element could have differences. The elaboration process essentially flattens all hierarchy before simulation begins.



          What you can do is use a generate construct to select your instance as follows
          ;



          module test #(
          parameter NUM_CHANNEL = 8,
          parameter DATA_WIDTH = 512
          ) (
          channel.in in[NUM_CHANNEL],
          channel.out out
          );

          logic _valid[NUM_CHANNEL];
          logic [DATA_WIDTH - 1 : 0] _data[NUM_CHANNEL];

          for (genvar ii=0;ii<NUM_CHANNEL;ii++) begin
          assign _valid[ii] = in[ii].valid;
          assign _data[ii] = in[ii].data;
          end
          always_comb begin
          out.valid = 0;
          for (int i = 0; i < NUM_CHANNEL; ++i) begin
          if (_valid[i]) begin
          out.valid = 1;
          out.data = _data[i];
          end
          end
          end

          endmodule





          share|improve this answer























          • I got it. I became curious; do you have a good example of Because of the way parameterization, defparam, and port connections work, each instance element could have differences.?

            – csehydrogen
            yesterday















          2














          An array of instances (module or interface) is not a true array type. As your error message indicates, you cannot select a particular instance with a variable index. With a true array, every element is identical. Because of the way parameterization, defparam, and port connections work, each instance element could have differences. The elaboration process essentially flattens all hierarchy before simulation begins.



          What you can do is use a generate construct to select your instance as follows
          ;



          module test #(
          parameter NUM_CHANNEL = 8,
          parameter DATA_WIDTH = 512
          ) (
          channel.in in[NUM_CHANNEL],
          channel.out out
          );

          logic _valid[NUM_CHANNEL];
          logic [DATA_WIDTH - 1 : 0] _data[NUM_CHANNEL];

          for (genvar ii=0;ii<NUM_CHANNEL;ii++) begin
          assign _valid[ii] = in[ii].valid;
          assign _data[ii] = in[ii].data;
          end
          always_comb begin
          out.valid = 0;
          for (int i = 0; i < NUM_CHANNEL; ++i) begin
          if (_valid[i]) begin
          out.valid = 1;
          out.data = _data[i];
          end
          end
          end

          endmodule





          share|improve this answer























          • I got it. I became curious; do you have a good example of Because of the way parameterization, defparam, and port connections work, each instance element could have differences.?

            – csehydrogen
            yesterday













          2












          2








          2







          An array of instances (module or interface) is not a true array type. As your error message indicates, you cannot select a particular instance with a variable index. With a true array, every element is identical. Because of the way parameterization, defparam, and port connections work, each instance element could have differences. The elaboration process essentially flattens all hierarchy before simulation begins.



          What you can do is use a generate construct to select your instance as follows
          ;



          module test #(
          parameter NUM_CHANNEL = 8,
          parameter DATA_WIDTH = 512
          ) (
          channel.in in[NUM_CHANNEL],
          channel.out out
          );

          logic _valid[NUM_CHANNEL];
          logic [DATA_WIDTH - 1 : 0] _data[NUM_CHANNEL];

          for (genvar ii=0;ii<NUM_CHANNEL;ii++) begin
          assign _valid[ii] = in[ii].valid;
          assign _data[ii] = in[ii].data;
          end
          always_comb begin
          out.valid = 0;
          for (int i = 0; i < NUM_CHANNEL; ++i) begin
          if (_valid[i]) begin
          out.valid = 1;
          out.data = _data[i];
          end
          end
          end

          endmodule





          share|improve this answer













          An array of instances (module or interface) is not a true array type. As your error message indicates, you cannot select a particular instance with a variable index. With a true array, every element is identical. Because of the way parameterization, defparam, and port connections work, each instance element could have differences. The elaboration process essentially flattens all hierarchy before simulation begins.



          What you can do is use a generate construct to select your instance as follows
          ;



          module test #(
          parameter NUM_CHANNEL = 8,
          parameter DATA_WIDTH = 512
          ) (
          channel.in in[NUM_CHANNEL],
          channel.out out
          );

          logic _valid[NUM_CHANNEL];
          logic [DATA_WIDTH - 1 : 0] _data[NUM_CHANNEL];

          for (genvar ii=0;ii<NUM_CHANNEL;ii++) begin
          assign _valid[ii] = in[ii].valid;
          assign _data[ii] = in[ii].data;
          end
          always_comb begin
          out.valid = 0;
          for (int i = 0; i < NUM_CHANNEL; ++i) begin
          if (_valid[i]) begin
          out.valid = 1;
          out.data = _data[i];
          end
          end
          end

          endmodule






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered yesterday









          dave_59dave_59

          20.7k21639




          20.7k21639












          • I got it. I became curious; do you have a good example of Because of the way parameterization, defparam, and port connections work, each instance element could have differences.?

            – csehydrogen
            yesterday

















          • I got it. I became curious; do you have a good example of Because of the way parameterization, defparam, and port connections work, each instance element could have differences.?

            – csehydrogen
            yesterday
















          I got it. I became curious; do you have a good example of Because of the way parameterization, defparam, and port connections work, each instance element could have differences.?

          – csehydrogen
          yesterday





          I got it. I became curious; do you have a good example of Because of the way parameterization, defparam, and port connections work, each instance element could have differences.?

          – csehydrogen
          yesterday



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55280467%2fsystemverilog-error-in-multiplexing-channels-nonconstant-index-into-instance-a%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript