0

I can’t get help to disambiguate a problem. It involves sorting an array of 11 numbers and filling in a table of values to calculate the state of a branch prediction state machine. The problem is that the table has 16 rows and the input array only has 11 numbers. Do I loop back to the beginning to complete the table? I cannot ever get the answer, and the 2-state machine and MIPS like assembly seem uncomplicated.

The algorithm is if a number is odd take one branch, otherwise take the other branch.

Is there a convention or rule on how to fill out 16 rows of branches with 11 items? I have even tried padding empty spaces with zeros(the input is positive integers).

I also have tried stopping on 11 and writing that state as the answer.

This is the same or very similar machine.

https://upload.wikimedia.org/wikipedia/commons/thumb/c/c8/Branch_prediction_2bit_saturating_counter-dia.svg/800px-Branch_prediction_2bit_saturating_counter-dia.svg.png

The table has the following columns: input value, Boolean column for even/odd truthiness, branch predicted, branch.

bentaisan
  • 1,056
  • 3
  • 12
  • 29
  • 1
    A branch predictor will have predictions for each branch in the machine code (or fewer if two alias the same entry), not one per data element that you're looping over. Also, comparison-based sorting algorithms need to branch more than N times to sort N elements. (The lower bound being O(N log N)). Unless the code can figure out exactly where to place each element the first time you look at it, it has to look at each element multiple times, and each "look" normally involves running a branch instruction. Or are you not fully sorting, just dividing into even/odd so loop once over the input? – Peter Cordes Sep 07 '21 at 00:48
  • You didn't say what the rows of your table are supposed to represent. It could be state of the predictor for a single branch after multiple steps of some algorithm, or it could be the state of the CPUs array of predictors, only some of which will actually map to the branches in the code being executed. – Peter Cordes Sep 07 '21 at 00:50
  • *Is there a convention or rule on how to fill out 16 rows of branches with 11 items?* Not in real-world programming or CPU design. Maybe there is in the textbook you're using, but we have no info on the exact phrasing of your problem or table. – Peter Cordes Sep 07 '21 at 00:54
  • 1
    Seems like the obvious thing would be to leave the later rows blank, or to assume a 2nd run on the same input array with the predictor already primed from the first run. – Peter Cordes Sep 07 '21 at 01:24

0 Answers0