Arithmetic for Computers – Significance Alexander Nelson March 5, 2021 University of Arkansas - Department of Computer Science and Computer Engineering
Arithmetic for Computers – Significance
Alexander Nelson
March 5, 2021
University of Arkansas - Department of Computer Science and Computer Engineering
Review of Computer Arithmetic
What have we learned so far:
We need circuits to perform binary arithmetic operations
• add, subtract, multiply, divide, and, or, etc.
We may need to perform operations on fewer bits
• Subword parallelism
We may need to perform this math on small or large numbers
• Floating point arithmetic
Specialized circuits perform these arithmetic operations
1
Review of Computer Arithmetic
Why does this matter?
2
Review of Computer Arithmetic
Why does this matter?
Keep the end goal in sight
A general purpose CPU (“central processing unit”) – Abstraction
3
Review of Computer Arithmetic
Five classic components of
a computer:
• Input• Output• Memory• Datapath• Control 1Computer Arithmetic in the “Combinational Logic” block
1By Lambtron - Own work, CC BY-SA 4.0,
https://commons.wikimedia.org/w/index.php?curid=37716438
4
Review of Computer Arithmetic
“Combinational Logic” receives a command to perform arithmetic
What kinds of arithmetic?
5
Review of Computer Arithmetic
Too many types to draw into schematics/overviews
Need an abstraction!
Arithmetic-Logic Unit (ALU) – Abstraction for all computer
arithmetic operations
Allow CPU designers to focus on individual parts
6
Arithmetic-Logic Unit
2
2By Lambtron - Own work, CC BY-SA 4.0,
https://commons.wikimedia.org/w/index.php?curid=36975996
7
Arithmetic-Logic Unit
Why does this work with MIPS?
8
Arithmetic-Logic Unit
Why does this work with MIPS?
Two operands, one result!
MIPS instruction types:
R-type – Rs = A, Rt = B, Rd = Y
I-type – Rs = A, Rt = B or Y, Imm = B or branch3
J-type – Imm = memory offset (jump3)
3Separate adder for computing addresses
9
Arithmetic-Logic Unit
What does the circuit of
the ALU look like?
Simple 4-bit ALU (74181
ALU)
75-logic gates, does 4-bit
add, sub, decrement,
AND, NAND, OR, NOR,
XOR, and shift
16-logical, 16-arithmetic
operations3
3CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=168473
10
Arithmetic-Logic Unit
Note – The 74181 is a 4-bit ALU, with no floating point,
multiplication, or division support
32-bit ALU w/ these support can be quite large
Using abstraction is the only way to allow integration of all parts!
11
Conclusion
What do I need to know about computer arithmetic?
Actual hardware implementation of arithmetic matters for
performance
Structure of the implementation (e.g. operands, result, status in,
status out) matter for design
In this class, (specifically in chapter 4) we focus on design
12
Conclusion
For design, the following conclusions are important:
• Small number of generic computation formats (e.g. R-type,I-type)
• Simple operations can have status codes that are important(e.g. Overflow)
• Complex computations require extra care (e.g. floating point,multiply, divide)
• Specialized computations require extra care (e.g. Multimedia,SIMD instructions)
Final remark – For integer arithmetic, simple operations dominate
the instructions in SPEC programs
These simple instructions will be used to design the CPU in the
remainder of the course.
13
Fallacies/Pitfalls
Pitfall 1 – Shifting right is not division for signed numbers!
srl – shift right logical – zero pads on the left, changing a negative
to a positive number
Even sra (shift right arithmetic) may not produce correct results
Pitfall 2 – Floating point addition not associative
Associative property – A + B + C = A + C + B
Floating point = approximation, meaning these may yield different
results
14
Fallacies/Pitfalls
Fallacy 1 – Parallel execution strategies that work for integer data
types also work for floating point
Related to Pitfall 2, parallel execution is not associative, so
distributing work must be handled with care.
Pitfall 3 – The MIPS instruction add immediate unsigned (addiu)
sign-extends its 16-bit immediate field
There is no subtract immediate, so this must have the ability to
represent negative numbers
Only used for addition where we don’t care about overflow
(immediate is sign extended)
15