Back Next
Primary memory is directly addressable by CPU and electronic.
  Register: 
    internal to CPU.
    addressed by name (native operand).
    very fast access.
    expensive.
    very small quantity.
    preset quantity.

  Main memory:
    external to CPU.
    addressed by numeric values on address bus.
    slower than CPU.
    less expensive.
    large quantities.
    quantities vary.

Cache - A compromise between registers and main memory.
  May be external or internal to CPU

  Addressed like main memory (from user's point of view)

  Some versions as fast as CPU registers

  Cost between main memory and registers.

  Small quantity 16K-256K (still much more than registers)
  
Caching principles
  A cache is a small block of high speed memory that acts like 
    addressable primary memory, usually 16K - 256K.

  Caching works by providing enough high speed memory to handle the
    current data and code.

  This works because of the principle of locality.
    Spacial - all memory of current interest is closely grouped together.

    Temporal - for a given block of memory, a program will spend an
      extended period of time on that block.


Locality example
  int I, total, num[100]
  for I = 0 to 99
  do
    total = num[i]
  done

  Spacial - the num array is usually implemented as a set of adjacent
    memory cells and the set of values composing the instruction sequence
    are also stored together.

  Temporal - the small set of instructions composing the loop are
    repeated 100 times as is access to the variables I and total.


Implementation of locality
  Main memory is parsed into cache sized blocks called segments.

  Main memory and cache are broken up into smaller blocks called lines.

  When a byte of information is first accessed in main memory, it and 
    all the adjacent bytes making up the "line" are copied or cached 
    into a line of the cache.

  This transfer is referred to as a miss.

  Any additional access to fetched byte or other adjacent bytes in "line"
    occurs in the cached line rather than in main memory.

  This access referred to as a hit.

Table example


Granularity of cache - how small is the line of the cache.
  Line arrangement
    Total cache may be 64K in size

    Locality often occurs at a much finer level 16-64 bytes.

    Cache broken up into lines of that size.

    All data in a line is local to itself.

    However, adjacent lines may have data from completely different
      blocks of memory.