[sv-bc] RE: Proposal for Mantis 696 - Parameterized Functions/Tasks

From: Alsop, Thomas R <thomas.r.alsop@intel.com>
Date: Fri Oct 08 2010 - 17:12:30 PDT

This is a very minor change and I am amenable to it. To be honest though, the example was meant to be simple and most designers don't know or use mathematical log functions (that I know of anyway). But I know what an encoder and decoder do and what their values should be. So, we can change it, that's fine but I would rather not.

-Tom

From: owner-sv-bc@eda.org [mailto:owner-sv-bc@eda.org] On Behalf Of Brad Pierce
Sent: Wednesday, October 06, 2010 5:03 PM
To: sv-bc@eda.org
Subject: [sv-bc] RE: Proposal for Mantis 696 - Parameterized Functions/Tasks

Tom,

It's seems more natural to me that the default of the second parameter would not be 4, but rather $clog2(DECODE_WIDTH), and that the specializations would only override the first parameter -- C#(8) and C#(4).

Also, the default for the first parameter seems arbitrary.

So possibly

   class C#(parameter DECODE_WIDTH, parameter ENCODE_WIDTH=$clog2(DECODE_WIDTH));

-- Brad

From: owner-sv-bc@eda.org [mailto:owner-sv-bc@eda.org] On Behalf Of Alsop, Thomas R
Sent: Tuesday, September 28, 2010 5:05 PM
To: Bresticker, Shalom; sv-bc@eda.org
Subject: [sv-bc] RE: Proposal for Mantis 696 - Parameterized Functions/Tasks

Done. Thanks Shalom. See fixes in rev3. -Tom

From: Bresticker, Shalom
Sent: Tuesday, September 28, 2010 1:22 AM
To: Alsop, Thomas R; sv-bc@eda.org
Subject: RE: Proposal for Mantis 696 - Parameterized Functions/Tasks

Hi,

1. The entire added text should be colored blue to signify it is an addition.

2. "The example has one class with two subroutines which, in this case, share parameterization." - Please change "which" to "that".

3. Same in "The subroutine call of the generic encoder, ENCODER_f, uses specialized class parameter values of 8 and 3 which ..."

4. "ENCODER_f = {ENCODE_WIDTH{1'b0}};" , "DECODER_f = {DECODE_WIDTH{1'b0}};"

I had actually meant that a better SV code style for these is

"ENCODER_f = '0;" , "DECODER_f = '0;"
Thanks,
Shalom

From: Alsop, Thomas R
Sent: Monday, September 27, 2010 7:53 PM
To: Bresticker, Shalom; sv-bc@eda.org
Subject: RE: Proposal for Mantis 696 - Parameterized Functions/Tasks

I have attached the changes requested in the meeting today for Mantis 696. You can also get to this of course off the Mantis site. The plan is to vote on this by the next CC.

Thanks, -Tom

From: Bresticker, Shalom
Sent: Monday, September 27, 2010 5:03 AM
To: Alsop, Thomas R; sv-bc@eda.org
Subject: RE: Proposal for Mantis 696 - Parameterized Functions/Tasks

Some minor editorial comments:

"also know as subroutines" should be " also known as subroutines".

"they may provide the parameters" should be " he may provide the parameters".

"the use of static classes" - Classes are not static. It is the members of a class that may be static.

While the lines

ENCODER_f = {ENCODE_WIDTH{1'b0}};
and
DECODER_f = {DECODE_WIDTH{1'b0}};

are correct, they are better written using '0.

Regards,
Shalom

From: owner-sv-bc@eda.org [mailto:owner-sv-bc@eda.org] On Behalf Of Alsop, Thomas R
Sent: Monday, September 13, 2010 6:34 PM
To: sv-bc@eda.org
Subject: [sv-bc] Proposal for Mantis 696 - Parameterized Functions/Tasks

Hi,

I just uploaded the proposal for parameterized functions/tasks using static class methods. I have cut and pasted the proposal here so we can discuss it on the reflector if we don't have time to discuss it in the meeting today. At least we can start reviewing the content here.

Thanks, -Tom

Mantis 696

P1800-2012

Motivation
This Mantis item enables the use of parameterized functions and tasks. This is done primarily through the use of static methods inside of classes. The committee debated enhancing the existing syntax of functions and tasks to enable this, we realized pragmatically that using static class methods already enabled this feature.

Add sub-clause 13.8 to the Task and Function Clause as follows:
13.8 Parameterized Tasks and Functions

SystemVerilog provides a way to create parameterized tasks and functions, also know as subroutines. A parameterized subroutine allows the user to generically specify or define an implementation. When using that subroutine they may provide the parameters that fully define its behavior. This allows for only one definition to be written and maintained instead of multiple subroutines all with different array sizes, data types, variable widths, etc...

The way to implement parameterized subroutines is through the use of static classes (see 8.9 Static Methods and 8.24 Parameterized classes). The following example shows how to use static class methods along with class parameterization to implement parameterized subroutines. This is done with one class with two subroutines which share parameterization. This example contains both a generic encoder and decoder.

class C#(parameter DECODE_WIDTH = 16, parameter ENCODE_WIDTH = 4);
  static function logic [ENCODE_WIDTH-1:0] ENCODER_f(input logic [DECODE_WIDTH-1:0] DecodeIn);

      ENCODER_f = {ENCODE_WIDTH{1'b0}};
      for (int i=0; i<DECODE_WIDTH; i++) begin

         if(DecodeIn[i]) begin
           ENCODER_f = i[ENCODE_WIDTH-1:0];
           break;
         end

      end

  endfunction

  static function logic [DECODE_WIDTH-1:0] DECODER_f(input logic [ENCODE_WIDTH-1:0] EncodeIn);

      DECODER_f = {DECODE_WIDTH{1'b0}};
      DECODER_f[EncodeIn] = 1'b1;

  endfunction
endclass

The class contains two static subroutines, ENCODER_f and DECODER_f. Each subroutine is parameterized by the class using the parameters DECODE_WIDTH and ENCODE_WIDTH, both of which have default settings. These parameters are used within each subroutine to define the size of the encoder and decoder.

module top ();
   logic [7:0] encoder_in;
   logic [2:0] encoder_out;
   logic [1:0] decoder_in;
   logic [3:0] decoder_out;

   // Encoder and Decoder Input Assignments
   assign encoder_in = 8'b0100_0000;
   assign decoder_in = 2'b11;

   // Encoder and Decoder Function calls
   assign encoder_out = C#(8,3)::ENCODER_f(encoder_in);
   assign decoder_out = C#(4,2)::DECODER_f(decoder_in);

   initial begin
      #50;
      $display("Encoder input = %b Encoder output = %b\n", encoder_in, encoder_out );
      $display("Decoder input = %b Decoder output = %b\n", decoder_in, decoder_out );
   end

endmodule

The top level module first defines some intermediate variables used in this example, and then assigns constant values to the encoder and decoder inputs. The subroutine call of the generic encoder, ENCODER_f, is given the parameter values of 8 and 3 which represent the decoder and encoder width values respectively for that specific instance of the encoder while at the same time passing the input encoded value. This expression uses the static class scope resolution operator '::' (see 8.22) to access the encoder subroutine. The expression is assigned to an output variable to hold the result of the operation. The subroutine call for the generic decoder, DECODER_f, is similar using the parameter values of 4 and 2 respectively.

--
This message has been scanned for viruses and
dangerous content by MailScanner<http://www.mailscanner.info/>, and is
believed to be clean.
--
This message has been scanned for viruses and
dangerous content by MailScanner<http://www.mailscanner.info/>, and is
believed to be clean.
-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Fri Oct 8 17:12:57 2010

This archive was generated by hypermail 2.1.8 : Fri Oct 08 2010 - 17:15:41 PDT