Comments on this approach from Sergey Suslov
http://bradpierce.wordpress.com/2010/04/28/sv-parameterized-functions/#comment-2185
-- Brad
On Wed, Sep 29, 2010 at 1:42 PM, Alsop, Thomas R
<thomas.r.alsop@intel.com> wrote:
> HI Linc,
>
>
>
> Not naïve at all, this is a good question and a lot of end-users may not
> understand this. This highlights the difference between a static method and
> a dynamic one. Typical class usage requires that you construct it in order
> to use it and this is done dynamically. Static methods do not require
> this. As long as the method has the static qualifier, you can use it
> without constructing it. Notice I did not even need to create a handle to
> it either.
>
>
>
> Thanks,
>
> -Tom
>
>
>
> From: Linc JEPSON [mailto:linc@74ze.com]
> Sent: Tuesday, September 28, 2010 5:25 PM
> To: Alsop, Thomas R
> Subject: RE: [sv-bc] RE: Proposal for Mantis 696 - Parameterized
> Functions/Tasks
>
>
>
> Tom,
>
>
>
> A perhaps very naïve question here.
>
>
>
> I was unaware of this, but in doing this in your recent example:
>
> // 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);
>
>
>
> we call a class’ function w/o actually making an instance of that class?
> (i.e. “new()”) Is that right?
>
>
>
> Such an action never occurred to me. I’ll have to try it out tomorrow.
>
>
>
> thanks,
>
> Linc-
>
>
>
> 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, and is
> believed to be clean.
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, 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 Thu Sep 30 21:36:18 2010
This archive was generated by hypermail 2.1.8 : Thu Sep 30 2010 - 21:39:05 PDT