Author Topic: Calculateing the size of a pipeline vector  (Read 2066 times)

0 Members and 1 Guest are viewing this topic.

Offline RainwaterTopic starter

  • Regular Contributor
  • *
  • Posts: 68
  • Country: us
Calculateing the size of a pipeline vector
« on: August 11, 2024, 06:23:31 pm »
I have not been able to find the name of this algorithm/math function that returns the sum of all values of 'A' when 'A = A - 1' is loop until 'A == 0'.
Code: [Select]
// verilog
function automatic integer f_pipeline_register_size;
    input integer a;
    for( f_pipeline_register_size = 0; a > 0; a = a - 1)
        f_pipeline_register_size = f_pipeline_register_size + a;
endfunction
Usage: I have a set of vectors, that I want to store and use one part at a time. like this.
Code: [Select]
<0> <1> <2> <3>
    <1> <2> <3>
        <2> <3>
            <3>
the total is 4+3+2+1 = 10;
anyone have a name, and maybe a quicker way than brute force?
"You can't do that" - challenge accepted
 

Offline ejeffrey

  • Super Contributor
  • ***
  • Posts: 3889
  • Country: us
Re: Calculateing the size of a pipeline vector
« Reply #1 on: August 11, 2024, 07:02:09 pm »
I don't remember if it has a specific name but the formula is n*(n+1)/2.
 
The following users thanked this post: Rainwater

Offline KE5FX

  • Super Contributor
  • ***
  • Posts: 2004
  • Country: us
    • KE5FX.COM
Re: Calculateing the size of a pipeline vector
« Reply #2 on: August 11, 2024, 08:31:25 pm »
Apocryphally credited to Gauss, when assigned the problem in a math class.
 
The following users thanked this post: Rainwater

Offline dmendesf

  • Frequent Contributor
  • **
  • Posts: 336
  • Country: br
Re: Calculateing the size of a pipeline vector
« Reply #3 on: August 13, 2024, 11:21:40 pm »
Sum of a finite arithmetic progression?
 

Offline RainwaterTopic starter

  • Regular Contributor
  • *
  • Posts: 68
  • Country: us
Re: Calculateing the size of a pipeline vector
« Reply #4 on: August 14, 2024, 09:51:31 am »
The name isnt too important, but the formula is priceless.
Im using it like shown below in order to handle a varable width structure
Code: [Select]
////////////////////////////////////
// General functions              //             
// f_GetPipelineVectorSize        //
// f_GetPipelineDepthStartAddress //
// f_GetPipelineDepthEndAddress   //
// f_GetPipelineDepthSize         //
// f_GetPipelineDepth             //
//
// returns the total size of continually reducing pipeline vector.
// <2> <1> <0>
//     <4> <3>
//         <5>
// base:3 total_units: 6
function automatic integer f_GetPipelineVectorSize;
    input integer base, unit_width;
    f_GetPipelineVectorSize = (base * ( base + 1 ) / 2) * unit_width;
endfunction
// initial begin:test_SumOfSubtrahend integer idx;for(idx=0;idx<5;idx=idx+1)begin $display("f_GetPipelineVectorSize(%1d):%1d",idx,f_GetPipelineVectorSize(idx, 1));end end

// returns the start address of a level of a continually reducing vector
// level 0: <2> <1> <0>
// level 1:     <4> <3>
// level 2:         <5>
// base:3 unit_width:1
// request_depth:0 returns 0
// request_depth:1 returns 3
// request_depth:2 returns 5
// request_depth:3 returns -1. error out of bounds. invalid depth
function automatic integer f_GetPipelineDepthStartAddress;
    input integer base, unit_width, request_depth;
    begin
        if( request_depth >= base) begin
            f_GetPipelineDepthStartAddress = ~0;
        end else begin
            f_GetPipelineDepthStartAddress = ( f_GetPipelineVectorSize(base, 1) - f_GetPipelineVectorSize(base-request_depth, 1) ) * unit_width;
        end
    end
endfunction
// initial begin:test_GetPipeLineDepthStartAddress integer idx;for(idx=0;idx<5;idx=idx+1)begin $display("f_GetPipelineDepthStartAddress( 3, 1, %1d ):%1d",idx,f_GetPipelineDepthStartAddress(3,1, idx));end end

// returns the end address of a level of a continually reducing vector
// level 0: <2> <1> <0>
// level 1:     <4> <3>
// level 2:         <5>
// base:3 unit_width:1
// request_depth:0 returns 2
// request_depth:1 returns 4
// request_depth:2 returns 5
// request_depth:3 returns -1. error out of bounds. invalid depth
function automatic integer f_GetPipelineDepthEndAddress;
    input integer base, unit_width, request_depth;
    begin
        if( request_depth >= base) begin
            f_GetPipelineDepthEndAddress = ~0;
        end else begin
            f_GetPipelineDepthEndAddress = f_GetPipelineDepthStartAddress(base, 1, request_depth) + (base - request_depth - 1) * unit_width;
        end
    end
endfunction
// initial begin:test_GetPipelineDepthEndAddress integer idx;for(idx=0;idx<5;idx=idx+1)begin $display("f_GetPipelineDepthEndAddress( 3, 1, %1d ):%1d",idx,f_GetPipelineDepthEndAddress(3,1, idx));end end

// returns the size of a level of a continually reducing vector
function automatic integer f_GetPipelineDepthSize;
    input integer base, unit_width, request_depth;
    begin
        if( request_depth >= base) begin
            f_GetPipelineDepthSize = ~0;
        end else begin
            f_GetPipelineDepthSize = f_GetPipelineDepthEndAddress(base, unit_width, request_depth) - f_GetPipelineDepthStartAddress(base, unit_width, request_depth) + unit_width;
        end
    end
endfunction
// initial begin:test_GetPipelineDepthSize integer idx;for(idx=0;idx<5;idx=idx+1)begin $display("f_GetPipelineDepthSize( 3, 1, %1d ):%1d",idx,f_GetPipelineDepthSize(3,1, idx));end end

function automatic integer f_GetPipelineDepth;
    input integer input_count;
    f_GetPipelineDepth = input_count - 1;
endfunction
"You can't do that" - challenge accepted
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6289
  • Country: 00
Re: Calculateing the size of a pipeline vector
« Reply #5 on: August 15, 2024, 02:07:26 pm »
It seems that your question is about summing an arithmetic sequence.

https://en.wikipedia.org/wiki/Arithmetic_progression

 
The following users thanked this post: Rainwater

Offline bson

  • Supporter
  • ****
  • Posts: 2445
  • Country: us
Re: Calculateing the size of a pipeline vector
« Reply #6 on: September 16, 2024, 05:28:29 pm »
 
The following users thanked this post: rstofer

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6856
  • Country: fi
    • My home page and email address
Re: Calculateing the size of a pipeline vector
« Reply #7 on: September 17, 2024, 06:06:29 am »
Also, the sum of integers from a to b, inclusive, is (a+b)(b+1-a)/2.

I probably should not admit this, but I did once wonder whether zero should be included in such arithmetic progression sums or not.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15312
  • Country: fr
Re: Calculateing the size of a pipeline vector
« Reply #8 on: September 17, 2024, 07:01:03 am »
I probably should not admit this, but I did once wonder whether zero should be included in such arithmetic progression sums or not.

Depends if you're considering the sums in a group with addition and zero as the identity element for addition, or not.
 ^-^
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6856
  • Country: fi
    • My home page and email address
Re: Calculateing the size of a pipeline vector
« Reply #9 on: September 17, 2024, 07:52:05 am »
I probably should not admit this, but I did once wonder whether zero should be included in such arithmetic progression sums or not.

Depends if you're considering the sums in a group with addition and zero as the identity element for addition, or not.
 ^-^
You know too much math. ;D
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf