RISC-V ALU: Design, Implementation, and Testing

 Abstract

This documentation presents the design and testing of an Arithmetic Logic Unit (ALU) model for a RISC-V architecture. The ALU is capable of performing various arithmetic and logical operations while also providing flags such as Carry, Overflow, Zero, and Negative.


Introduction

The ALU is a fundamental component of any processor, responsible for executing arithmetic and logical operations on data. In this documentation, we focus on an ALU designed for a RISC-V architecture, which is a popular instruction set architecture used in many modern processors. The ALU model presented here is implemented in Verilog and includes support for flags to provide information about the result of operations.


ALU Model 



Logic Diagram 





Flags and Operations

The ALU supports the following operations:

OperationDescription
AdditionAdds two numbers together.
SubtractionSubtracts one number from another.
Bitwise ANDPerforms a bitwise AND operation.
Bitwise ORPerforms a bitwise OR operation.
Sign ExtensionExtends the sign of a number.

The flags provided by the ALU are:

FlagDescription
CarryIndicates if an arithmetic operation resulted in a carry out of the most significant bit.
OverflowIndicates if an arithmetic operation resulted in an overflow condition.
ZeroIndicates if the result of an operation is zero.
NegativeIndicates if the result of an operation is negative.

Truth Table 

ALU ControlOperationInput AInput BResultCarryOverflowZeroNegative
000AdditionABA + BCarryOverflowZeroNegative
001SubtractionABA - BCarryOverflowZeroNegative
010Bitwise ANDABA & BN/AN/AZeroNegative
011Bitwise ORABA | BN/AN/AZeroNegative
101Sign ExtensionAN/ASign ExtN/AN/AZero

Test Cases

The provided test bench verifies the functionality of the ALU model with the following test cases:

Test CaseOperationInputsExpected ResultExpected Flags
1AdditionA = 5, B = 38Carry = 0, Overflow = 0, Zero = 0, Negative = 0
2Addition (Overflow)A = 2147483647, B = 10-2147483639Carry = 1, Overflow = 1, Zero = 0, Negative = 1
3Bitwise ANDA = 10, B = 40Carry = 0, Overflow = 0, Zero = 1, Negative = 0
4Sign ExtensionA = 0xFFFFFFFF, B = 0x00000001-1Carry = 0, Overflow = 0, Zero = 0, Negative = 1
5Subtraction (Negative)A = 7, B = 10-3Carry = 0, Overflow = 0, Zero = 0, Negative = 1
6Addition (Carry)A = 0xFFFFFFFF, B = 10Carry = 1, Overflow = 0, Zero = 1, Negative = 0
7AdditionA = 5, B = 05Carry = 0, Overflow = 0, Zero = 0, Negative = 0
8SubtractionA = 5, B = 50Carry = 1, Overflow = 0, Zero = 1, Negative = 0

These test cases cover various scenarios including addition, subtraction, bitwise AND, and sign extension operations, along with different input values to verify the correctness of the ALU model. Test case practical results are provided below and are found to be in line with the expected results.


Waveform output



Scope

The ALU model presented here is designed to be used as a component within a larger RISC-V processor implementation. It provides the necessary arithmetic and logical functionality required for executing instructions in the processor.


Conclusion

In conclusion, the ALU model for a RISC-V architecture presented here demonstrates the essential arithmetic and logical operations required for processing instructions in a processor. By providing flags such as Carry, Overflow, Zero, and Negative, the ALU enhances the processor's capability to perform complex computations and handle different data types effectively. The comprehensive testing performed using the provided test bench validates the correctness and reliability of the ALU model, making it a valuable component in the development of RISC-V based processors.

Comments

Popular posts from this blog

FM Synthesis using two Oscillators

GSM Based Remote Load Switching