Professional Documents
Culture Documents
Five phases
IF (instruction fetch)
ID(instruction decode)
EXE
MEM
WB(write back)
1st phase:
2nd phase:
it only decodes the instruction which was previously fetched from (IF
phase) and sees where its (R,I,J) format
two control lines MEM read MEM write
output of ID phase if I-type will go two sign extend (16 bit ---> 32 bit)
will be explained later
3rd phase:
4th phase:
5th phase:
Sign extend:
3 formats only
The src field is constant in all 3 formats
Memory is used in only 2 instructions (lw and sw)
Pipelining hazards:
1. Data hazard : ex x= y +z, k= x +y if x wasnt calculated therefore the
result in could be wrong
Sol: stalling or forwarding
Forwarding: dont wait till answer is written in register we can read it from
latch
2. Structural hazard: HW cant support a particular combination of
instructions to be executed in the same cycle example : branching to an
address while this address is being written to at exact time
Sol: stall or using 2 memories
Some hazards dont occur that often, so the cost may outweigh the
benefit
May complicate the HW which isnt used that often therefore may
impact the performance
3. Control hazard:
A control hazard occur because CPU doesnt know soon enough
Whether or not the conditional branch will be taken
The target of transfer of control
Sol:
Can determine or predict this info earlier (predict not taken) 2 bit
predictor
Can delay the exe. Of branch until the calc. is done(stall)
Chapter 5 memory:
Concepts:
1. Memory hierarchies & principle of locality
2. Basic cache organization
3. Virtual memory
Memory hierarchies:
Form faster to slower: Register, cache, RAM, hard disk
The pipelining need a range of one word per cycle a few word cycle
depending on the CPU organization. The Rate at which data is
provided is called (Bandwidth)
Memory hierarchy:
Goal:
Concept of locality:
3. Set associative: A memory block can be placed in any cache line within
single set
most comely. Y3ni 3andy el cache mat2asm sets w el set el wa7da feha
kaza cache line therefore el queues 2alat than direct mapped w search
time a7san men el fully associative
dah kan rule bat3 set associative idk for what excatly bs el doctor kan
2alo
(Block address) % (number of sets in cache)
An example on memory problems from page 390:
Note: 4 kiB = 1024 words from page 389.
Rules:
Block size = 2^m
The cache size = 2^n blocks
Number of blocks= cache data capacity/ words per block
Tag size= bit address (n+m+2)
Total number of bits in direct mapped cache is = 2^n * (block size
+tag size+ valid field size)
How many total bits are required for a direct mapped cache with 16 KiB
of data and 4 words blocks, assuming a 32- bit address?
Sol:
Number of blocks = 16 KiB/ 4 words = 4096/ 4 = 2^10 blocks
Cache size =2^n blocks n=10
Since block size = 2^m and block size = 4 words = 2^2 words m=2
Block size in bits = 4*32 bits
Tag size = 32-(10-2-2) =18 bits
Total number of bits = 2^10 * ( [4* 32] + 18 + 1) = 2^10 x147 bits =
127 Kibibits
There are more examples in book for different types of examples
please check them