Professional Documents
Culture Documents
Combinational ALU
Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology
January 9, 2012
http://csg.csail.mit.edu/SNU
L1-1
January 9, 2012
http://csg.csail.mit.edu/SNU
L01-2
http://csg.csail.mit.edu/SNU
L01-3
How to add and compare two numbers Must have a place to keep the program and data Must know how to fetch instructions and data Must know how to sequence instructions:
Fetch a[i], Fetch b[i], add, store results in c[i], increment i,
Computer Architecture is learning about how programs execute and designing hardware to execute them efficiently
January 9, 2012
http://csg.csail.mit.edu/SNU
L1-4
Examples: Intels IA-32, ARM, ARM-Thumb, PowerPC In this class we will use SMIPS, a subset of MIPS ISA
Implementations are deeply affected by the technology issues; we will assume a simple and abstract model of technology based on Silicon
January 9, 2012
http://csg.csail.mit.edu/SNU
L1-5
Each architecture and each part of it would be defined as executable code in Bluespec
By this Friday you will have designed several different computers on which you will be able to execute your C programs
January 9, 2012
http://csg.csail.mit.edu/SNU
L1-6
ALU resides inside the CPU and carried out all the arithmetic and logical functions
A B
- Add, Sub, ... - And, Or, Xor, Not, ... - GT, LT, EQ, Zero, ...
ALU
Result Comp?
January 9, 2012
http://csg.csail.mit.edu/SNU
L1-8
January 9, 2012
http://csg.csail.mit.edu/SNU
L1-9
January 9, 2012
Types
Every expression and variable in a Bluespec program has a type; sometimes it is specified explicitly and sometimes it is deduced by the compiler A type is a grouping of values:
Integer: 1, 2, 3, Bool: True, False Bit: 0,1 A pair of Integers: Tuple2#(Integer, Integer) A function fname from Integers to Integers: function Integer fname (Integer arg)
Thus we say an expression has a type, belongs to a type The type of each expression is unique
January 9, 2012
http://csg.csail.mit.edu/SNU
L1-11
http://csg.csail.mit.edu/SNU
L1-12
c[0]
fa
fa
c[2]
s[0]
January 9, 2012
s[1]
L1-13
http://csg.csail.mit.edu/SNU
let syntax
The let syntax: avoids having to write down types explicitly
let cs0 = fa(x[0], y[0], c[0]); Bits#(2) cs0 = fa(x[0], y[0], c[0]);
The same
January 9, 2012
http://csg.csail.mit.edu/SNU
L1-14
Parameterized types: #
A type declaration itself can be parameterized the parameters are indicated by using the syntax #
For example Bit#(n) represents n bits and can be instantiated by specifying a value of n Bit#(1), Bit#(32), Bit#(8),
January 9, 2012
http://csg.csail.mit.edu/SNU
L1-15
http://csg.csail.mit.edu/SNU
L1-16
valueOf(w) versus w
Each expression has a type and a value and these come from two entirely disjoint worlds n in Bit#(n) resides in the types world Sometimes we need to use values from the types world into actual computation. The function valueOf allows us to do that
January 9, 2012
http://csg.csail.mit.edu/SNU
L1-17
We define a few special operators in the types space for such operations
January 9, 2012
http://csg.csail.mit.edu/SNU
L1-18
January 9, 2012
http://csg.csail.mit.edu/SNU
L1-19
January 9, 2012
http://csg.csail.mit.edu/SNU
L1-20
http://csg.csail.mit.edu/SNU
L1-21
00ab Fixed size shift operation is cheap in hardware just wire the circuit appropriately Rotate, sign-extended shifts all are equally easy
January 9, 2012
http://csg.csail.mit.edu/SNU
L1-22
We need a Mux to select the appropriate wires: if s is one the Mux will select the wires on the left otherwise it would select wires on the right
(s==0)?{a,b,c,d}:{0,0,a,b};
January 9, 2012
s
http://csg.csail.mit.edu/SNU L1-23
A B
S0
B
S A B
AND
A 2-way multiplexer
S
C D
S0
S1
(s==0)?A:B
January 9, 2012
http://csg.csail.mit.edu/SNU
00
The whole structure can be expressed an a bunch of nested conditional expressions You will write a Blusepec program to produce a variable size shifter in Lab 1 this afternoon
January 9, 2012
http://csg.csail.mit.edu/SNU
L1-25
Combinational ALU
function Bit#(width) combALU(Bit#(width) a, Bit#(width) b, OP op); case op matches NOT: return ~a; Once we have AND: return a&b; implemented the OR: return a|b; primitive operations like addN, >>, the ALU can SHL: return a<<b; be implemented simply SHR: return a>>b; by introducing a Mux ADD: return addN(a,b); controlled by op to SUB: return a-b; select the appropriate MUL: return combMulN(a,b); circuit endcase slightly stylized code endfunction Other operations may be needed
January 9, 2012
http://csg.csail.mit.edu/SNU
L1-26
Conditional operations
Generate one-bit result which is used for branching
Eq (a,b) : (a == b); Neq(a,b) : (a != b); Le(a) : signedLE(a, 0); Lt(a) : signedLT(a, 0); Ge(a) : signedGE(a, 0); Gt(a) : signedGT(a, 0);
Straightforward to implement; can be combined with the ALU with an extra bit of output
January 9, 2012
http://csg.csail.mit.edu/SNU
L1-27
EQ
0
mux
comb MulN
add
op
mux
http://csg.csail.mit.edu/SNU
L1-28