effective coding styles

22
Effective Coding Styles Presented By- S H I K H A S I N G H Vtp1456

Upload: shikha-singh

Post on 15-Aug-2015

33 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: Effective coding styles

Effective Coding Styles

Presented By-S H I K H A S I N G H

Vtp1456

Page 2: Effective coding styles

[email protected]

Fundamentals of efficient synthesizable Finite State Machines

Page 3: Effective coding styles

[email protected]

Two most commonly used FSM coding styles

• Combinational always block• Sequential always block

Page 4: Effective coding styles

[email protected]

Combinational always block

• Used to code combinational logic functionality• Strictly coded using blocking assignments• Combinational sensitivity list- a list without

posedge and negedge verilog keywords

Page 5: Effective coding styles

[email protected]

Sequential always block

• Used to code clocked or sequential logic• Strictly coded using non-blocking assignment• Contains an edge based sensitivity list

Page 6: Effective coding styles

[email protected]

Mealy & Moore FSMs

• A Moore FSM is a state machine where the outputs are only a function of the present state.

• A Mealy FSM is a state machine where one or more of the outputs is a function of the present state and one or more of the inputs.

Page 7: Effective coding styles

[email protected]

FSM (block diagram)

Page 8: Effective coding styles

[email protected]

Binary Encoded or One Hot Encoding

IDLE

S1

S2S3

S4

000

001

011010

110

Binary Encoded FSM (Highly Encoded)

IDLE

S1

S2S3

S4

00001

00010

0010001000

10000

One Hot Encoding

Page 9: Effective coding styles

[email protected]

Binary Encoded

• A binary-encoded FSM design only requires as many flip-flops as are needed to uniquely encode the number of states in the state machine.

• N, number of flip flops = ceiling (log-base-2 no. of states)

Page 10: Effective coding styles

[email protected]

One Hot Encoding

• A onehot FSM design requires a flip-flop for each state in the design and only one flip-flop (the flip-flop representing the current or "hot" state) is set at a time in a onehot FSM design.

• No. of flip-flops required = no. of states

Page 11: Effective coding styles

[email protected]

• The FSM coding style should be easily modified to change state encodings and FSM styles.

• The coding style should be compact.• The coding style should be easy to code and

understand.• The coding style should facilitate debugging.• The coding style should yield efficient synthesis

results.

FSM Coding Goals

Page 12: Effective coding styles

[email protected]

Two Always Block FSM Style (Good Style)

• One for sequential state register• Other for combinational next state and

combinational output logic.

Page 15: Effective coding styles

[email protected]

Onehot FSM Coding Style (Good Style)• Efficient (small and fast) onehot state machines can

be coded using an inverse case statement; a case statement where each case item is an expression that evaluates to true or false.

• Reconsider the fsm_4state design shown.• The key to understanding the changes is to realize

that the parameters no longer represent state encodings, they now represent an index into the state vector, and comparisons and assignments are now being made to single bits in either the state or next-state vectors.

• Notice how the case statement is now doing a 1-bit comparison against the onehot state bit.

Page 16: Effective coding styles

[email protected]

Onehot FSM Coding Style

• This is the only coding style where one should use full_case and parallel_case statements.

• The parallel case statement tells the synthesis tool to not build a priority encoder even though in theory, more than one of the state bits could be set (as engineers, we should know that this is a onehot FSM and that only one bit can be

set so no priority encoder is required).

Page 17: Effective coding styles

[email protected]

Onehot FSM Coding Style

Page 18: Effective coding styles

[email protected]

Registered FSM Outputs (Good Style)

• The Only Change one has to do isalways @(posedge clk or negedge rst_n)if (!rst_n) gnt <= 1'b0;else begingnt <= 1'b0;case (next)IDLE, BFREE: ; // default outputsBBUSY, BWAIT: gnt <= 1'b1;endcaseendendmodule

Page 19: Effective coding styles

[email protected]

Comparing RTL Coding Efforts

Page 20: Effective coding styles

[email protected]

Questions??

Page 21: Effective coding styles

[email protected]

References

• International Cadence User Group 2002• http://

www.csun.edu/edaasic/roosta/SME_Tech.pdf

Page 22: Effective coding styles

[email protected]

THANK YOU