How would you improve the performance

Assignment Help C/C++ Programming
Reference no: EM132948306

Greatest Common Divisor (GCD) Calculator

The greatest common divisor or the highest common factor is the largest natural number that divides two numbers without leaving a remainder. Hope you remember GCD calculations used in algebra and solving fractions in your secondary classes. In addition to that GCD is used in various other applications such as cryptography etc. One of the GCD estimation method is known as Euclid's GCD method, which is described using C language-style syntax below.

a <= ain;
b <= bin;
while (a b){ if (a > b)
a = a - b;
else
b = b - a;

G C D a ;

A dry-run for the GCD algorithm is given in Table 1. You may try it with other number combinations to familiarise the algorithm better.

Step

a

b

Operation

1.

55

35

Data in a and b

2.

55-35 = 20

35

a >  b .  a     a - b

3.

20

35-20 = 15

b > a . . b      b    a

4.

20-15=5

15

a > b . . a     a - b

5.

5

15-5=10

6 > a . . b      6    a

6.

5

10-5=5

6 > a . . b     -6       a


7. 5 5 a b . . GCD a

Table 1: Euclid's GCD Algorithm Example

Since System Verilog is quite rich in programming constructs the above algorithm can easily be im- plemented as shown in Code . There is one to one relationship between the algorithm and the SystemVerilog code except the additional inputs and some control signals. We have two 8-bit inputs (Air and 6/u) and one 8-bit output (GUDout). Apart from the inputs and the output, there are two control signals s/ r/ and done. The start is a 1-bit input signal to inform the module that the data is ready and the module can start calculating the GCD, while done is a 1-bit output signal to signal that the GCD calculation is complete. Also, we first copy the data into two temporary variables named A and B, which is not essential, but advisable since the data is manipulated and copied onto the same variable during the process.

The GCD SystemVerilog implementation in Example is working accurately (See Figure 1), but this is not a hardware model implemented in System Verilog . In addition to that the model will not synthesis to a hardware which can be implemented on a FPGA specially because the while loop is not finite - it is data dependant. A hardware system should always be finite.

Now think like a hardware designer - how would one implement an algorithm with conditional state- ments in hardware? You do not have a luxury of using infinite amount to functional units or storage.

Therefore, it is better to reuse hardware components. Now, in order to execute the algorithm you might have to use one functional unit several times and data is written again and again to registers. We call them as register transfer operations. Every register-transfer operation must complete within one clock cycle (which is equivalent to one state of the FSM, since the FSM changes state at ev- ery clock cycle).Furthermore, in a single register-transfer operation, a functional unit cannot be used more than once. However, the same functional unit can be used more than once if it is used by different register-transfer operations. In other words, a functional unit can be used only once in the same clock cycle, but can be used again in a different clock cycle.

The datapath requires a comparator and a subtractor in order to carry out the operations in the algorithm. Let us assume that we have two registers to store the values for A and B, known as RegA and RegB. First we can compare the numbers - that means we require a comparator. Therefore the output of RegA and RegB (RegAout and RegBout) are the inputs to the comparator. At the same time, these outputs are connected to a subtractor. To make things simple, lets use two substractors: one subtractor to calculate A-B, and the other for B-A. The result of A-B should be fed back to RegA (and B-A to RegB). The input to RegA (or RegB) has two paths, one is the initial data which the user need to enter and other is, the subtractor output. Now we have to determine which input to select depending on the comparator decision. Therefore we are going to use a multiplexor at the input of RegA (and RegB). The datapath we require is shown in Figure 2. The functional units in the datapath required to be controlled based on the current and/or the next statement the datapath should carry out.

The multiplexors (muxA and muxB) has a select signal controlled by the control unit: when the data is loaded into registers select signals for the multiplexors will be 0; when the subtractor output is to be loaded sel signal will be 1. To load any data available at the input of registers, the load (loadA or loadB) should be asserted. Once the data is loaded to the registers, the comparator and the subtract units will compute the results. The comparison results will be fed into the control unit which will either stop the operation or load necessary results (A-B or B-A) to RegA or RegB. This will continue until A is equal to B.

Design and implement the GCD Calculator as shown Figure 2.

Deliverables for Submission

You are required to submit a logbook style document not more than 10 pages long containing the following details:

1. State Diagram for the controller and control-word table

2. SystemVerilog Codes for the Datapath including sub modules, Controller and the overall system Give explanations for the code with reference to the block diagram. Marks will be awarded for the mastery of HDL programming methods used.

3. Functional Simulation Results for at least five non-zero value pairs Give reasons for your value selection. A sample testbench code is given in the Appendix

4. What happens if one or both values for ain and bin are zero? Where do you think the issue is?
Propose a fix for this.

5. How would you improve the performance of this GCD Calculator? Clearly explain the exten- sion/improvement introduced to the circuit and its effect.

Attachment:- CourseWork.rar

Reference no: EM132948306

Questions Cloud

What are the hcltv-ltv and cltv : Mortgage Balance is $200,000. They are going to subordinate a HELOC that has a Current balance of $50,000 and a total Line amount of $75,000. The property appra
Difference between moral and immoral leadership : What is the difference between moral and immoral leadership? Provide an example.
Explain people management process : Discuss how these tasks add value to the people management process.
How will use understanding of different personality styles : How will use the understanding of different personality styles to better communicate and lead? Define the four personality types and how they relate to you.
How would you improve the performance : How would you improve the performance of this GCD Calculator? Clearly explain the exten- sion/improvement introduced to the circuit and its effect
Identify common financial key performance indicators : Identify common financial key performance indicators that likely align with Patagonia's CSR initiatives and its mission, vision, and values.
Develop mathematical functions : The two basic inventory decisions that managers face are how much to order or produce for additional inventory, and when to order or produce it to minimize tota
Would describe as a formal or informal leader : Who will you work with as a mentor (just identify the position of a potential mentor) to help you grow into this leadership position and why?
Can we have effective world approaches to csr : Can we have effective World approaches to CSR?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd