Search code examples
simulatorcpu-architecturebranch-prediction

Confused by simplescalr preditor


now I am learning simplescalar source code. But I am confused by the predictor module. It is about bimod predictor. Here is the initialization :

case BPred2bit: 
  if (!l1size || (l1size & (l1size-1)) != 0) 
      fatal("2bit table size, `%d', must be non-zero and a power of two",  
      l1size); 
  pred_dir->config.bimod.size = l1size; 
  if (!(pred_dir->config.bimod.table = 
    calloc(l1size, sizeof(unsigned char)))) 
    fatal("cannot allocate 2bit storage"); 
  /* initialize counters to weakly this-or-that */ 
  flipflop = 1; 
  for (cnt = 0; cnt < l1size; cnt++) 
  { 
    pred_dir->config.bimod.table[cnt] = flipflop; 
    flipflop = 3 - flipflop; 
  } 
  break; 

Here we use the PHT table:

case BPred2bit:
  p = &pred_dir->config.bimod.table[BIMOD_HASH(pred_dir, baddr)];
  break;

But what to my suprise is the PHT tale NEVER be updated!!!. I find the code nowhere, neither in the pred_update() funtion!!!. Can you tell me the reason? What mechanism dose simplescalar use?


Solution

  • But it is updated. In bpred_update() you find this code

      if (dir_update_ptr->pdir1)
        {
          if (taken)
        {
          if (*dir_update_ptr->pdir1 < 3)
            ++*dir_update_ptr->pdir1;
        }
          else
        { /* not taken */
          if (*dir_update_ptr->pdir1 > 0)
            --*dir_update_ptr->pdir1;
        }
        }
    

    An entry of the table is either incremented or decremented depending on the outcome of the branch. That particular entry comes from the second code segment in your question. It's just a pointer to a 2-bit counter.