Monday, December 16, 2013

Address Subdivision

Address Subdivision



 










                                                                                                                             
·         32-bit byte address
·         A direct-mapped cache
·         The cache size is 2^n blocks, so n bits are used for the index
·         The block size is 2^m words (2^m+2 bytes), so m bits are used for the word within the block, and two bits are used for the byte part of the address

Accessing Cache

▪ Total number of bits needed for a cache
1)    size of tag field is

o   32-(n+m+2)
                 2) The total number of bits in a direct-mapped cache
o   2^n x (block size + tag size +valid field size)
             ▪ Total number of bits in cache is
-       2^n x (2^m x 32 +(32-n-m-2)+1) = 2^n x (2^m x 32+31-n-m)


             Example: Large Block Size
             ▪ 64 blocks ,16 bytes/block
o   To what block number does address 1200 map?
             ▪ Block Address= 1200/16 = 75
             ▪ Block number= 75 modulo 64=11

 

            Block Size Considerations
            ▪ Larger blocks should reduce miss rate
o   Due to spatial locality
▪ But in a fixed-sized cache
o   Larger blocks------->fewer of them

§  More competition-------->increased miss rate
o   Larger blocks------->pollution
 ▪ Larger miss penalty
o   Can override benefit of reduced miss rate
o   Early restart and critical-word-first can help

Cache Misses
▪ On cache hit, CPU proceed normally
▪ On cache miss
o   Stall the CPU pipeline
o   Fetch block from next level of hierachy
o   Instruction cache miss
-       Restart Instruction fetch
o   Data cache miss
-       Complete data access

             Write-Through
             ▪ On data-write hit, could just the block in cache
-       But then cache and memory would be inconsistent
             ▪ Write through: also update memory
             ▪ But makes writes take longer
-       e.g., if base CPI=1, 10% of instruction are stores, writes to memory takes 100 cycles
§   Effective CPI=1+0.1x100=11
 ▪ Solution: write buffer
-       Holds data waiting to be written to memory
-       CPU continues immediately
§  Only stalls on write if write buffer is already full

Write-Back
▪ Alternative: On data-write hit, just update the block in cache
-       keep track of whether each block is dirty
▪When a dirty block is replaced
-       Write it back to memory
-       Can use a write buffer to allow replacing block to read first

Write Allocation
▪ What should happen on a write miss?
▪ Alternatives for write-through
-       Allocate on miss: fetch the block
-       Write around: don’t fetch the block
o   Since programs often write a whole block before reading it(e.g., Initialization)
▪ For write-back
-       Usually fetch the block













Binary Operation

Binary Operation


Binary operation that only focus in addition, subtraction, multiplication and division. Binary number operation is different with the normal mathematic operation. Binary number only contains TWO number which are 0 or 1.


Binary Addition
In the mathematic operation, if 1+1=2 but in binary operation 1+1=10. This is because there are only 1 and 0 in this operation.

Example 1
Binary Rules
0+0=0
0+1=1
1+0=0
1+1=10
1+1+1=100
1+1+1+1=1000


Example 2
       
        1    1<--------------------this is call carried bit
        1    0   1 
+           1    1
         1   0   0   0

 



Binary Subtraction

Example 1
In the mathematic operation, if 12-9=3 that is because 2 borrow the left side digit to minus 3. It is also same with binary subtraction operation 100-1=11 also borrow from left side number.
Binary Rules
0-0=0
1-0=1
0-1=1
(This must borrow from next binary number)
1-1=0
10-1=1
100-1=11
1000-1=111

Example 2
       
            1   1    1<-------it can minus 1 when borrow from left side number
      1    0    1   0
-                      1   1
                  1   1   1

 



Binary Multiplication
Binary Multiplication is almost same with mathematic operation multiplication.

Example 1
Binary Rules
0x0=0
1x0=0
0x1=0
1x1=1
10x0=0
100x0=0
100x1=100

Example 2
       
            1   1    1
            x       1    1   0
                            0    }
        1   1   1   0    }  must use binary addition operation to solve
            1   1   1   0   0    }  this step
       1   0   1   1   1   0    }

 


Binary Division
The binary operation division only have a bit different with mathematic operation division. The different step is only when minus the number.
       
  1      1          
       1   1  / 1   0   1   1
 -      1   1            
      1   0   1
 -    1   1     
           1   0               This is remainder



 

Law of Boolean

Law of Boolean


 1.  Boolean expression is to manipulate them in the same way as normal algebraic expression are manipulated.
 2.  The rules is used to describe circuit whose state can be either, 1(true) or 0(false).
 3.  In order to fully understand this, the relation between the AND­ gate, OR gate and NOT gate operation should be appreciated.

Basic Laws of Boolean Algebra

AND Form
OR Form

Identity Law

A.1=A

A+0=A

Zero and One Law

A.0=0

A+1=1

Inverse Law

A.A'=0

A+A'=1

Idempotent Law

A.A=A

A+A=A

Commutative Law

A.B=B.A

A+B=B+A

Associative Law

A.(B.C)=(A.B).C

A+(B+C)=(A+B)+C

Distributive Law

A+(B.C)=(A+B).(A+C)

A.(B+C)=(A.B)+(A.C)

Absorption Law

A(A+B)=A
A+A.B=A
A+A'B=A+B

DeMorgan’s Law
(A.B)'=A'+B'
(A+B)'=A'.B'
Double
Complement Law
         
X''=X
  
X''=X

Example 1


 B(A+B)=AB+BB
                   =AB+B              B.B=B
                   =B(A+1)
                   =B                     A+1=1


Example 2

 
 (A+B’+C’)(A+B’C)
       =AA+AB’C+AB’+B’B’C+AC’+B’CC’
       =A(1+B’C+B’+C’)+B’C+B’CC’                        A.A=A
       =A(1+B’)+B’C+B’CC’                                      B’(C+C’)=B’(1)
       =A+B’C(1+C’)                                                 1+B’=1
       =A+B’C                                                            1+C’=1