Prediction?

Harabecw

Senior member
Apr 28, 2003
605
0
0
How does a CPU "predict" what it should do?
Why does it do it?
what exactly is a "miss"? when the CPU predicts something but ends up needing to do something else?

To make it clear...do both the P4's and AthlonXP's do it?

Thanks for your time
 

sgtroyer

Member
Feb 14, 2000
94
0
0
I'm not qualified to explain how branch prediction works, but I can tell you why. All modern processors that I know of perform branch prediction, some better than others. The reason is pipelining. Pipelining involves breaking a complicated instruction up into separate chunks so that more than one instruction can be worked on at a time.

A pipeline is like an assembly line. Instead of working on one car at a time, and not starting the second car until the first is completely finished, you work on many cars simultaneously. While the first car is being painted, the second one is being welded, or whatever. The time to finish one car is the same, but the throughput of cars per hour is much higher.

So how does this relate to branch prediction? Suppose you add A + B to get C. Then you branch if C = D. Because of the pipeline, the processor will start the branch instruction before the addition is finished. It doesn't know the answer, but it needs to make a decision. So it guesses. It chooses one alternative, and keeps working on it. When the first instruction is done, it checks to see if it guessed right. If so, everything proceeds as normal. If not, however, the processor must back up and start over again. In modern processors, with very deep pipelines, this can be a serious performance hit. So accurate branch prediction is very important, and a good processor is right most of the time.

I'd recommend any of the Hennessy and Patterson Computer Architecture books for much more extensive information on this. A good starting point is "Computer Organization and Design: The Hardware Software Interface"
 

wviperw

Senior member
Aug 5, 2000
824
0
76
/me trys to recall CompOrg class...

A computer predicts pretty much just like we do. It makes predictions based on the facts it has on hand. It can predict "never taken" (ignore a choice with this set of conditions), "always taken" (automatically choose a choice with this set of conditons), predict by opcode, and predict by history (look at frequency tables).

I guess a "miss" would be what you said. Let's say the computer decides to branch from A to B because based on A's history, there is a 90% chance this is what the decision will be. However, if what actually happens is that the decision is C, then A has to branch to C, it is a "miss", and you use precious time.

(I knew I should have listened better in class )
 

frostgiant

Senior member
Jun 19, 2000
258
0
0
Not sure how the x86 does it, though I know it is complex.

Some embedded CPUs are much more simple. Their guess is that a branch will not be taken and cache the instruction after the branch. Thus, on a CPU like this, it is in your best interest to program for the most likely case not to branch.

I think I read in some ASM manual that the P4 lets you specify which way a branch is more likely to go... But I am not sure.
 

Lynx516

Senior member
Apr 20, 2003
272
0
0
x86 CPUs and most highend CPUs use what is know as a branch table to help in branch prediction. In this table it records whether a branch is either strongly taken,lightly taken,lightly not taken or strongly not taken and then makes disisions based on that.

Less complex CPUs such as the ARM 7 CPU use a technique that says that if the branch links backwards (i.e. a loop) it always takes it while if it links forwards it doesnt.

When it misses all the work it has done is useless and it has to flush all the useless code out of the pipeline which costs alot of cycles.

FrostGiant it is very very unliky if the P4 has something to say if a branch is more likly to be taken because branchprediction was not invented when x86 was introduced and hence if it is not in x86 then it is unliukly the P4 supports it. (SSE is a different thing all together so no comments about it :frown
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |