; Load the old history for the associated static branch into ugpr1. ; Each entry in the branch history table is 4 bytes. The table is ; stored at BHT_Offset + gp, where gp is the program's global pointer. s4addq BHT_Index, gp, ugpr0 ; ugpr0 <- ((BHT_Index * 4) + gp) ldl ugpr1, BHT_Offset(ugpr0) ; ugpr1 <- memory[ugpr0 + BHT_Offset] ; Load the old PHT entry into ugpr3. Each entry in the ; PHT is 1 byte. The table is stored at PHT_Offset + gp. addq ugpr1, gp, ugpr2 ; ugpr2 <- (old_history [i.e., ugpr1] + gp) ldbs ugpr3, PHT_Offset(ugpr2) ; ugpr3 <- memory[ugpr2 + PHT_Offset] ; Calculate the new history and store it in ugpr1. cmple zero, Br_Dir, ugpr4 ; ugpr4 <- ((Br_Dir == 1) ? 1 : 0) s2addq ugpr1, ugpr4, ugpr1 ; shift current branch direction into the history zapnot ugpr1, #0x07, ugpr1 ; mask off unused bits ; Do part of the address calculation for the new PHT entry. ; Store this value in ugpr4. addq ugpr1, gp, ugpr4 ; ugpr4 <- (new_history [i.e., ugpr1] + gp) ; Update the old PHT entry. The value in the PHT entry ; ranges from -4 to 3, with negative values indicating that ; the branch should be predicted not taken. Br_Dir is 1 if ; the branch is taken, and -1 if the branch is not taken. ; The new PHT value is stored in ugpr3. addq ugpr3, Br_Dir, ugpr3 ; add either 1 or -1 to the PHT entry maxsb8 ugpr3, #3, ugpr3 ; if the value is greater than 3, set it to 3 minsb8 ugpr3, #-4, ugpr3 ; if the value is less than -4, set it to -4 ; Write the old PHT entry back into the PHT. stb ugpr3, PHT_Offset(ugpr2) ; memory[ugpr2 + PHT_Offset] <- ugpr3 ; Read the new PHT entry and store the prediction. ldbs ugpr3, PHT_Offset(ugpr4) ; ugpr3 <- memory[ugpr4 + PHT_Offset] st_pc ugpr3, Br_Addr ; write prediction cache ; Store the new history. stl ugpr1, BHT_Offset(ugpr0) ; store new BHT entry back into the table