m3 – risc-v alu design · truth table of the alu cu instrn opcode alu op operation funct7 funct3...

81
M3 – RISC-V ALU Design Appendix A.5

Upload: others

Post on 01-Aug-2021

15 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

M3 – RISC-V ALU Design

Appendix A.5

Page 2: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Module Outline

● Arithmetic and Logical Unit Design

Page 3: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Arithmetic Logic Unit

● Arithmetic operations● Logic operations● Comparison (Equal)

+ - * /==!=

& | ^

Arithmetic and Logic Unit

Control Signal

A

BOutput

Page 4: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU

● Start with the simplest operations.

Page 5: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU

● Start with the simplest operations.– AND, OR

– Control signal

Page 6: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU

● Start with the simplest operations.– AND, OR

– Control signal

● Incrementally add functionality and control

Page 7: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU

● Start with the simplest operations.– AND, OR

– Control signal

● Incrementally add functionality and control● Start with a 1-bit ALU

Page 8: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU

● Start with the simplest operations.– AND, OR

– Control signal

● Incrementally add functionality and control● Start with a 1-bit ALU● Modify design for a n-bit ALU

Page 9: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Basic ALU Design

AND, OR

Page 10: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Basic ALU Design

Include a Full AdderInclude a Full Adder

Page 11: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Full Adder

a

bSum

CarryOut

cin

S=( A⋅B⋅C i)+( A⋅B⋅C i)+(A⋅B⋅C i)+(A⋅B⋅C i)

Cout=(A+C i)⋅(B+C i)⋅(A+B)

Page 12: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Basic ALU Design

ADD, AND, OR

Page 13: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Basic ALU Design

ADD, AND, OR

1-bit ALU

CarryIn

Operation

a

b

Result

CarryOut

Page 14: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Basic 64b ALU

64 1-bit ALUs in Ripple Carry arrangement

Page 15: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Basic 1-bit ALU Design

Subtraction?Subtraction?ADD, AND, OR

Page 16: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Adder/Subtractor

+

0

S=a+b

Cout

a

b

Page 17: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Adder/Subtractor

+ -

0 1

S=a+b

Cout C

out

a

b

a

bS=a-b

Page 18: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Adder/Subtractor

+ -

0 1

S=a+b

Cout C

out

a

b

a

bS=a-b

-b = b + 1-b = b + 1

Page 19: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Adder/Subtractor

+ -

0 1

S=a+b

Cout C

out

a

b

a

bS=a-b

+/-+/-

cin

Cout

a

b

Cin== (0:1) ?

S=a+b : S=a-bb

Page 20: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU DesignA±B, AND, ORA±B, AND, OR

A–B: Binvert = 1; CarryIn = 1.A+B: Binvert = 0; CarryIn = 0.

A–B: Binvert = 1; CarryIn = 1.A+B: Binvert = 0; CarryIn = 0.

Page 21: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU DesignA±B, AND, ORA±B, AND, OR

NOR?NOR?A–B: Binvert = 1; CarryIn = 1.A+B: Binvert = 0; CarryIn = 0.

A–B: Binvert = 1; CarryIn = 1.A+B: Binvert = 0; CarryIn = 0.

Page 22: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

NAND, NOR

A NAND B = (A AND B)

= A OR B

A NAND B = (A AND B)

= A OR BA NOR B = (A OR B)

= A AND B

A NOR B = (A OR B)

= A AND B

Page 23: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU Design

a NAND b: Ainvert=1;Binvert=1;Op=1a NAND b: Ainvert=1;Binvert=1;Op=1

a NOR b: Ainvert=1;Binvert=1;Op=0a NOR b: Ainvert=1;Binvert=1;Op=0

Page 24: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU Design

A±B, AND, OR, NOR, NAND

Page 25: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU Design

SLT?SLT?

Page 26: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Set Less Than

● Set a status bit if (a < b)

Page 27: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Set Less Than

● Set a status bit if (a < b)● If (a<b); (a-b) is -ve● Calculate (a-b). Observe sign bit of the result

Page 28: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU Design

slt(a,b): Binvert=1; CarryIn=1; Operation=3;

MSB

Page 29: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU Design

A±B, AND, OR, NOR, NAND, SLT

Page 30: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU Design

Overflow?Overflow?A±B, AND, OR, NOR, NAND, SLT

Page 31: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU Design

A±B, AND, OR, NOR,SLT, Overflow detection

Page 32: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU Design

1-bit ALU

Ainvert

Binvert

CarryIn

Operation

a

b

Sum

Set

Overflow

CarryOut

Less

Page 33: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

64-bit ALU

Zero detection?Zero detection?

Page 34: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

64-bit ALU

Page 35: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU

Page 36: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU – Control Signals

Ainvert Binvert CarryIn Operation

AND

OR

ADD

SUB

NAND

NOR

SLT

Page 37: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU – Control Signals

Ainvert Binvert CarryIn Operation

AND 0 0 0 00

OR

ADD

SUB

NAND

NOR

SLT

Page 38: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU – Control Signals

Ainvert Binvert CarryIn Operation

AND 0 0 0 00

OR 0 0 0 01

ADD

SUB

NAND

NOR

SLT

Page 39: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU – Control Signals

Ainvert Binvert CarryIn Operation

AND 0 0 0 00

OR 0 0 0 01

ADD 0 0 0 10

SUB 0 1 1 10

NAND

NOR

SLT

Page 40: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU – Control Signals

Ainvert Binvert CarryIn Operation

AND 0 0 0 00

OR 0 0 0 01

ADD 0 0 0 10

SUB 0 1 1 10

NAND 1 1 0 01

NOR 1 1 0 00

SLT

Page 41: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU – Control Signals

Ainvert Binvert CarryIn Operation

AND 0 0 0 00

OR 0 0 0 01

ADD 0 0 0 10

SUB 0 1 1 10

NAND 1 1 0 01

NOR 1 1 0 00

SLT 0 1 1 11

Page 42: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU – Control Signals

Ainvert Binvert CarryIn Operation

AND 0 0 0 00

OR 0 0 0 01

ADD 0 0 0 10

SUB 0 1 1 10

NAND 1 1 0 01

NOR 1 1 0 00

SLT 0 1 1 11

Ignore the effect of CarryIn during NAND and NOR execution. Binvert == CarryIn.

Page 43: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU – Control Signals

ABOp

AND 0000

OR 0001

ADD 0010

SUB 0110

NAND 1101

NOR 1100

SLT 0111

Page 44: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU Control

+ - * /==!=

& | ^

Arithmetic and Logic Unit

Control Signal

A

BOutput

ALUCONTROL

ALUCONTROL

Instruction

Page 45: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU Control – AND Instruction

+ - * /==!=

& | ^

0000

A

B

A & B

ALUCONTROL

ALUCONTROL

AND

Page 46: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU Control – AND Instruction

+ - * /==!=

& | ^

0000

A

B

A & B

ALUCONTROL

ALUCONTROL

AND

What info to pass to ALU Controlto identify AND Operation?

What info to pass to ALU Controlto identify AND Operation?

Page 47: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Control Signals for Implementation

ABOp

AND 0000

OR 0001

ADD 0010

SUB 0110

Page 48: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Control Signals for Implementation

ABOp

AND 0000

OR 0001

ADD 0010

SUB 0110

From ISA ManualFrom ISA Manual

Page 49: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Control Signals for Implementation

ABOp

AND 0000

OR 0001

ADD 0010

SUB 0110

All are R-type InstructionsAll are R-type Instructions

Page 50: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Control Signals for Implementation

ABOp

AND 0000

OR 0001

ADD 0010

SUB 0110

All are R-type InstructionsAll are R-type Instructions

Which fields identify operation?Which fields identify operation?

Page 51: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Control Signals for Implementation

ABOp

AND 0000

OR 0001

ADD 0010

SUB 0110

All are R-type InstructionsAll are R-type Instructions

opcode, funct7, funct3 identify operationopcode, funct7, funct3 identify operation

Page 52: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Instructions using the ALU

Page 53: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Instructions using the ALU

● Arithmetic and Logic Instructions– add, sub, and, or

– R-type

Page 54: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Instructions using the ALU

● Memory transfer instructions– Effective address

calculation– ld, sd– I-type, S-type– Identified by opcode

● Arithmetic and Logic Instructions– add, sub, and, or

– R-type

Page 55: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Instructions using the ALU

● Memory transfer instructions– Effective address

calculation

– ld, sd

– I-type, S-type

– Identified by opcode

● Branch instructions (beq)– For Zero detection

– SB type

– Identified by opcode

● Arithmetic and Logic Instructions– add, sub, and, or

– R-type

Page 56: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Instructions using the ALU

● Arithmetic and Logic Instructions (R-type)● ld (I-type), sd (S-type)● beq (SB-type)

Page 57: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Instructions using the ALU

● Arithmetic and Logic Instructions (R-type)● ld (I-type), sd (S-type)● beq (SB-type)

Page 58: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU – Control Signals

ABOp

AND 0000

OR 0001

ADD 0010

SUB 0110

Which control signals forLD, SD, BEQ?

Which control signals forLD, SD, BEQ?

Page 59: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU – Control Signals

Input to ALU CU Output Control SignalsABOp

AND 0000

OR 0001

ADD, LD, SD 0010

SUB, BEQ 0110

Page 60: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Main and ALU Control Units

+ - * /==!=

& | ^

ABOp

A

BResult

ALUCONTROL

ALUCONTROL

MAINCONTROL UNIT

MAINCONTROL UNIT

32b instructionInstruction

Type

Page 61: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Control Unit – R-type

+ - * /==!=

& | ^

ABOp

A

BResult

ALUCONTROL

ALUCONTROL

MAINCONTROL UNIT

MAINCONTROL UNIT

32b instruction

Page 62: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Control Unit – R-type

+ - * /==!=

& | ^

ABOp

A

BResult

ALUCONTROL

ALUCONTROL

MAINCONTROL UNIT

MAINCONTROL UNIT

32b instruction

ALU, R-type !ALU, R-type !

Page 63: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Control Unit – R-type

+ - * /==!=

& | ^

ABOp

A

BResult

ALUCONTROL

ALUCONTROL

MAINCONTROL UNIT

MAINCONTROL UNIT

32b instruction

R-type,funct7,funct3

ALU, R-type !ALU, R-type !

Page 64: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Control Unit – LD, SD

+ - * /==!=

& | ^

ABOp

A

BResult

ALUCONTROL

ALUCONTROL

MAINCONTROL UNIT

MAINCONTROL UNIT

32b instruction

EAC,opcode

LD, SDLD, SD

Ignoring funct3Ignoring funct3

Page 65: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Control Unit – BEQ

+ - * /==!=

& | ^

ABOp

A

BResult

ALUCONTROL

ALUCONTROL

MAINCONTROL UNIT

MAINCONTROL UNIT

32b instruction

Branch,opcode

BEQBEQ

Page 66: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Main CU to ALU CU

● Type of Instruction– ALU (R-type), Effective Address Calculation, Branch

Instruction

● Opcode (to identify operation)– funct7, funct3 in case of R-type

Page 67: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Truth Table of the ALU CU

InstrnOpcode

ALUOp

Operation funct7 funct3 ALU Action ALU Control Input

LD

SD

BEQ

R-type

R-type

R-type

R-type

Page 68: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Truth Table of the ALU CU

InstrnOpcode

ALUOp

Operation funct7 funct3 ALU Action ALU Control Input

LD 00 Load doubleword

SD 00 Store doubleword

BEQ 01 Branch if equal

R-type 10 add

R-type 10 sub

R-type 10 and

R-type 10 or

Page 69: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Truth Table of the ALU CU

InstrnOpcode

ALUOp

Operation funct7 funct3 ALU Action ALU Control Input

LD 00 Load doubleword XXXXXXX XXX add 0010

SD 00 Store doubleword

BEQ 01 Branch if equal

R-type 10 add

R-type 10 sub

R-type 10 and

R-type 10 or

Page 70: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Truth Table of the ALU CU

InstrnOpcode

ALUOp

Operation funct7 funct3 ALU Action ALU Control Input

LD 00 Load doubleword XXXXXXX XXX add 0010

SD 00 Store doubleword XXXXXXX XXX add 0010

BEQ 01 Branch if equal

R-type 10 add

R-type 10 sub

R-type 10 and

R-type 10 or

Page 71: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Truth Table of the ALU CU

InstrnOpcode

ALUOp

Operation funct7 funct3 ALU Action ALU Control Input

LD 00 Load doubleword XXXXXXX XXX add 0010

SD 00 Store doubleword XXXXXXX XXX add 0010

BEQ 01 Branch if equal XXXXXXX XXX subtract 0110

R-type 10 add

R-type 10 sub

R-type 10 and

R-type 10 or

Page 72: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Truth Table of the ALU CU

InstrnOpcode

ALUOp

Operation funct7 funct3 ALU Action ALU Control Input

LD 00 Load doubleword XXXXXXX XXX add 0010

SD 00 Store doubleword XXXXXXX XXX add 0010

BEQ 01 Branch if equal XXXXXXX XXX subtract 0110

R-type 10 add 0000000 000 add 0010

R-type 10 sub

R-type 10 and

R-type 10 or

Page 73: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Truth Table of the ALU CU

InstrnOpcode

ALUOp

Operation funct7 funct3 ALU Action ALU Control Input

LD 00 Load doubleword XXXXXXX XXX add 0010

SD 00 Store doubleword XXXXXXX XXX add 0010

BEQ 01 Branch if equal XXXXXXX XXX subtract 0110

R-type 10 add 0000000 000 add 0010

R-type 10 sub 0100000 000 subtract 0110

R-type 10 and

R-type 10 or

Page 74: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Truth Table of the ALU CU

InstrnOpcode

ALUOp

Operation funct7 funct3 ALU Action ALU Control Input

LD 00 Load doubleword XXXXXXX XXX add 0010

SD 00 Store doubleword XXXXXXX XXX add 0010

BEQ 01 Branch if equal XXXXXXX XXX subtract 0110

R-type 10 add 0000000 000 add 0010

R-type 10 sub 0100000 000 subtract 0110

R-type 10 and 0000000 111 AND 0000

R-type 10 or

Page 75: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Truth Table of the ALU CU

InstrnOpcode

ALUOp

Operation funct7 funct3 ALU Action ALU Control Input

LD 00 Load doubleword XXXXXXX XXX add 0010

SD 00 Store doubleword XXXXXXX XXX add 0010

BEQ 01 Branch if equal XXXXXXX XXX subtract 0110

R-type 10 add 0000000 000 add 0010

R-type 10 sub 0100000 000 subtract 0110

R-type 10 and 0000000 111 AND 0000

R-type 10 or 0000000 110 OR 0001

Page 76: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Truth Table of the ALU CU

InstrnOpcode

ALUOp

Operation funct7 funct3 ALU Action ALU Control Input

LD 00 Load doubleword XXXXXXX XXX add 0010

SD 00 Store doubleword XXXXXXX XXX add 0010

BEQ 01 Branch if equal XXXXXXX XXX subtract 0110

R-type 10 add 0000000 000 add 0010

R-type 10 sub 0100000 000 subtract 0110

R-type 10 and 0000000 111 AND 0000

R-type 10 or 0000000 110 OR 0001

Control Unit identifiesclass of instruction

Control Unit identifiesclass of instruction

Inputs to the ALU CUInputs to the ALU CU Output of ALU CUOutput of ALU CU

Page 77: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Truth Table of the ALU CU

Page 78: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Truth Table of the ALU CU

Page 79: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Truth Table of the ALU CU

Page 80: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

ALU Control Unit

Page 81: M3 – RISC-V ALU Design · Truth Table of the ALU CU Instrn Opcode ALU Op Operation funct7 funct3 ALU Action ALU Control Input LD 00 Load doubleword XXXXXXX XXX add 0010 SD 00 Store

Module Outline

● Arithmetic and Logical Unit Design– ALU Design in HDL