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

From: Neil Korpusik <neil.korpusik@oracle.com>
Date: Fri Oct 15 2010 - 18:03:22 PDT

It still seems a bit obtuse to me. I would like to suggest the following
alternative.

From:
    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, of which ENCODE_WIDTH has a default setting of the system
    task $clog2 (see 20.8.2 ? Integer math functions) of the required
    DECODE_WIDTH parameter. These parameters are used within each subroutine to
    define the size of the encoder and decoder.

To:
    Class C contains two static subroutines, ENCODER_f and DECODER_f. Each
    subroutine is parameterized by reusing the class parameters DECODE_WIDTH
    and ENCODE_WIDTH. The default value of parameter ENCODE_WIDTH is
    conveniently determined by using the system task $clog2 (see 20.8.2).
    These parameters are used within the subroutines to specify the size of the
    encoder and the size of the decoder.

Neil

On 10/15/10 09:33, Alsop, Thomas R wrote:
> How does this sound?
>
>
>
> 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, of which ENCODE_WIDTH has a default
> setting of the system task $clog2 (see 20.8.2 – Integer math functions)
> of the required DECODE_WIDTH parameter. These parameters are used
> within each subroutine to define the size of the encoder and decoder
>
>
>
> -Tom
>
>
>
> *From:* Bresticker, Shalom
> *Sent:* Wednesday, October 13, 2010 3:34 AM
> *To:* Alsop, Thomas R; Brad Pierce; sv-bc@eda.org
> *Subject:* RE: Proposal for Mantis 696 - Parameterized Functions/Tasks
>
>
>
> Hi, Tom.
>
>
>
> The following sentence is no longer correct:
>
>
>
> "Each subroutine is parameterized by the class using the parameters
> DECODE_WIDTH and ENCODE_WIDTH, both of which have default settings."
>
>
>
> DECODE_WIDTH no longer has a default.
>
>
>
> Regards,
>
> Shalom
>
>
>
> *From:* Alsop, Thomas R
> *Sent:* Tuesday, October 12, 2010 12:51 AM
> *To:* Bresticker, Shalom; Brad Pierce; sv-bc@eda.org
> *Subject:* RE: Proposal for Mantis 696 - Parameterized Functions/Tasks
>
>
>
> The more I think about it, the more I like it, so I changed the example
> and used Brad’s version removing the “arbitrary” default of the decoder
> width and using the $clog2 system task to set the default encoder
> width. Uploaded onto Mantis for your viewing pleasure. -Tom
>
>
>
> http://www.eda.org/svdb/view.php?id=696
>
>
>
>
>
> *From:* Bresticker, Shalom
> *Sent:* Saturday, October 09, 2010 10:44 AM
> *To:* Alsop, Thomas R; Brad Pierce; sv-bc@eda.org
> *Subject:* RE: Proposal for Mantis 696 - Parameterized Functions/Tasks
>
>
>
> Many designers would use $clog2 if they were aware that it existed and
> if all the tools supported it.
>
> Many write their own functions to do it.
>
>
>
> Shalom
>
>
>
> *From:* owner-sv-bc@eda.org [mailto:owner-sv-bc@eda.org] *On Behalf Of
> *Alsop, Thomas R
> *Sent:* Saturday, October 09, 2010 2:13 AM
> *To:* Brad Pierce; sv-bc@eda.org
> *Subject:* [sv-bc] RE: Proposal for Mantis 696 - Parameterized
> Functions/Tasks
>
>
>
> 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* <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 15 18:04:07 2010

This archive was generated by hypermail 2.1.8 : Fri Oct 15 2010 - 18:06:38 PDT