# Study of Register Value Branch Predictor Based on CNN
## 3 Background
### Training and Predicting Process  
The first step in training a neural network branch predictor is to create datasets. One option is using an architecture runtime simulator. It can run the program without too much additional processing, process the branch instructions, and train the neural network. At this point, the data that make up the datasets are given by the simulator runtime. This approach has the benefit that it is easy to add the information used for training, but the disadvantage is the high overhead of the simulator and the slow speed of training. Another option is the trace-driven simulator, whose input trace file can be extracted by specific tools during the program runtime or generated by an architecture simulator. The trace-driven simulator runs faster than the runtime simulator, but the disadvantage of using trace files is that the trace file has to be regenerated if additional content is needed. We use a trace-based simulation program to conduct our experiments because it runs faster. We run the program to train only one branch and one model at one time. The program reads the trace file with the organizational structure described below and runs from the beginning until the last branch has completed training and then proceeds with the validation and test step. When training, the program reading trace stops when it encounters the branch being trained. After that, the program expands the values of the 18 registers to the length required by the current training model and puts them into the model calculation to obtain a prediction. The program compares it with the actual result and then completes the backpropagation computation. That is how simulation the program works. Our experiment uses Pintool to collect the information to generate trace files. Pintool can be used to perform program analysis on user space applications, and by calling the API it provides, it can record the data, such as jump direction and address and register values, which are needed for the research. The data we need to run the experiments are shown in Table 1.  
The type of registers in the table was chosen as a 32-bit unsigned integer, with the reasons explained below. We attached Pintool to the benchmarks program to collect all the data in Table 1. Each time the benchmark program executes a branch instruction, Pintool will save the information into a file; thus, we can obtain the original trace file. Trace files record 200 million instructions for each benchmark. The dataset for training the neural network consists of a training set, validation set, and test set, and Table 2 shows the programs chosen for each set of this experiment. In order to find the H2P branch in each trace, our experiment uses the trace file generated by the method described above and runs through the TAGE-SC-L branch predictor \begin{table}
\begin{tabular}{c c c} \hline \hline
**Name** & **Type** & **Content** \\ \hline pc & uint64\_t & Current instruction address \\ target\_pc & uint64\_t & Target address \\ direction & uint8\_t & Jump direction \\ type & uint8\_t & Branch type \\ regs & uint32\_t[] & Array of 18 register values \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Trace file content structure. \begin{table}
\begin{tabular}{c c} \hline \hline
**Sets** & **Inputs** \\ \hline Training Set & Alberta Inputs [21] \\ Validation Set & SPEC2017 training size \\ Test Set & SPEC2017 ref size \\ \hline \hline \end{tabular}
\end{table} 
Table 2: The input of each set for training and testing the neural predictor. provided by the 5 th Championship Branch Prediction competition to filter out the top five branch with the highest MPKI, saving the addresses of these branches. The next step is to convert the original trace file into an HDF5 file read by the actual training program. The whole HDF5 file consists of the following data parts: the first one is the data structure described in Table 1, and the training program uses the pc value, jump direction and register value.