Chapter 03 RISC V
Chapter 03 RISC V
Edition
The Hardware/Software Interface
Chapter 3
Arithmetic for Computers
§3.1 Introduction
Arithmetic for Computers
Operations on integers
Addition and subtraction
Multiplication and division
Dealing with overflow
Floating-point real numbers
Representation and operations
Length of product is
the sum of operand
lengths
Initially 0
Can be pipelined
Several multiplication performed in parallel
Chapter 3 — Arithmetic for Computers — 9
RISC-V Multiplication
Four multiply instructions:
mul: multiply
Gives the lower 64 bits of the product
mulh: multiply high
Gives the upper 64 bits of the product, assuming the
operands are signed
mulhu: multiply high unsigned
Gives the upper 64 bits of the product, assuming the
operands are unsigned
mulhsu: multiply high signed/unsigned
Gives the upper 64 bits of the product, assuming one
operand is signed and the other unsigned
Use mulh result to check for 64-bit overflow
Chapter 3 — Arithmetic for Computers — 10
§3.4 Division
Division
Check for 0 divisor
Long division approach
quotient If divisor ≤ dividend bits
dividend 1 bit in quotient, subtract
1001 Otherwise
1000 1001010 0 bit in quotient, bring down next
-1000 dividend bit
divisor
10 Restoring division
101 Do the subtract, and if remainder
1010 goes < 0, add divisor back
-1000 Signed division
remainder 10
Divide using absolute values
Adjust sign of quotient and remainder
n-bit operands yield n-bit as required
quotient and remainder
Initially dividend
Step 1
Step 2
Step 3
Step 4
Optional variations
I: integer operand
P: pop operand from stack
R: reverse operand order
But not all combinations allowed