Calculateing the size of a pipeline vector - Page 1
Forum section: electronics / general

author: Rainwater
author_rank: Regular Contributor
timestamp: August 11, 2024, 06:23:31 pm
content: 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:// verilogfunction 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;endfunctionUsage: I have a set of vectors, that I want to store and use one part at a time. like this.Code:<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?

author: ejeffrey
author_rank: Super Contributor
timestamp: August 11, 2024, 07:02:09 pm
content: I don't remember if it has a specific name but the formula is n*(n+1)/2.

author: KE5FX
author_rank: Super Contributor
timestamp: August 11, 2024, 08:31:25 pm
content: Apocryphally credited toGauss,when assigned the problem in a math class.

author: dmendesf
author_rank: Frequent Contributor
timestamp: August 13, 2024, 11:21:40 pm
content: Sum of a finite arithmetic progression?

author: Rainwater
author_rank: Regular Contributor
timestamp: August 14, 2024, 09:51:31 am
content: The name isnt too important, but the formula is priceless.Im using it like shown below in order to handle a varable width structureCode:////////////////////////////////////// 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: 6function 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 depthfunction automatic integer f_GetPipelineDepthStartAddress;input integer base, unit_width, request_depth;beginif( request_depth >= base) beginf_GetPipelineDepthStartAddress = ~0;end else beginf_GetPipelineDepthStartAddress = ( f_GetPipelineVectorSize(base, 1) - f_GetPipelineVectorSize(base-request_depth, 1) ) * unit_width;endendendfunction// 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 depthfunction automatic integer f_GetPipelineDepthEndAddress;input integer base, unit_width, request_depth;beginif( request_depth >= base) beginf_GetPipelineDepthEndAddress = ~0;end else beginf_GetPipelineDepthEndAddress = f_GetPipelineDepthStartAddress(base, 1, request_depth) + (base - request_depth - 1) * unit_width;endendendfunction// 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 vectorfunction automatic integer f_GetPipelineDepthSize;input integer base, unit_width, request_depth;beginif( request_depth >= base) beginf_GetPipelineDepthSize = ~0;end else beginf_GetPipelineDepthSize = f_GetPipelineDepthEndAddress(base, unit_width, request_depth) - f_GetPipelineDepthStartAddress(base, unit_width, request_depth) + unit_width;endendendfunction// 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 endfunction automatic integer f_GetPipelineDepth;input integer input_count;f_GetPipelineDepth = input_count - 1;endfunction

author: zapta
author_rank: Super Contributor
timestamp: August 15, 2024, 02:07:26 pm
content: It seems that your question is about summing an arithmetic sequence.https://en.wikipedia.org/wiki/Arithmetic_progression

author: bson
author_rank: Unknown
timestamp: September 16, 2024, 05:28:29 pm
content: https://www.wolframalpha.com/input?i=Sum+i%2C+i%3D0+to+nI'd go with n^2/2 + n/2

author: Nominal Animal
author_rank: Super Contributor
timestamp: September 17, 2024, 06:06:29 am
content: Also, the sum of integers fromatob, 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.

author: SiliconWizard
author_rank: Super Contributor
timestamp: September 17, 2024, 07:01:03 am
content: Quote from: Nominal Animal on September 17, 2024, 06:06:29 amDepends if you're considering the sums in a group with addition and zero as the identity element for addition, or not.

author: Nominal Animal
author_rank: Super Contributor
timestamp: September 17, 2024, 07:52:05 am
content: Quote from: SiliconWizard on September 17, 2024, 07:01:03 amYou know too much math.