Branch and loop reorganization to prevent misdirects

How the Microprocessor Works Block Diagram: Microprocessors use various branch-prediction methods to keep from making mistakes when they encounter a conditional branch during instruction execution. There are, however, proven techniques to minimize branch misdirection and keep deeply pipelined processors fully utilized.

by Jeff Andrews, application engineer, Intel Corp.

Proven techniques and Intel tools enable developers to minimize branch mispredictions and keep deep-pipelined processors fully utilized.

Modern microprocessors are pipelined in order to get more instructions completed faster. This means that instructions do not wait for the previous ones to complete before their execution begins. A problem with this approach arises, however, due to conditional branches. If the microprocessor encounters a conditional branch and the result for the condition has not yet been calculated, how does it know whether to take the branch or not? This is where branch prediction comes in.

Branch prediction is what the processor uses to decide whether to take a conditional branch or not. Getting this information as accurately as possible is important, as an incorrect prediction (mispredict) will cause the microprocessor to throw out all the instructions that did not need to be executed and start over with the correct set of instructions. This process is particularly expensive with deeply pipelined processors.

This article introduces the various branch-prediction methods used by the microprocessor and provides some tips about how to avoid costly mispredicts. The paper assumes that the reader is familiar with programming in C and with IA32 assembly-language instructions.

Branch examples
A pipelined processor makes it possible to begin execution of instructions before their predecessors are completed by breaking the instruction execution up into stages. When a conditional branch is encountered, the microprocessor uses branch prediction to determine which direction the branch will take. The following are examples of C language commands that cause conditional branches.

The first type of construction considered here that causes conditional branches is if-else :

Subscribers who liked this article also read:
Deploying Oracle9i Real Application Clusters on Intel® architecture-based clusters
Information storage and retrieval lies at the heart of almost all core...
De-Mystifying Software Performance Optimization
by Paul Del Vecchio, senior performance analyst, Software and Soluti...
Consolidating the IT infrastructure: leveraging Oracle9i Real Application Clusters on Intel to build an 'Adaptive Architecture'
Intel Corp., Oracle Corp., and Cap Gemini Ernst & Young. Cap Gemi...

If you're interested in this topic, these articles may be helpful:

More WorkSharing with OpenMP
Abstract By Richard Gerber As you know, OpenMP* contains a very po...
Platform 2015 Software: Enabling Innovation in Parallelism for the Next Decade
Driven by steady advances in microprocessor design and manufacturing t...
For-loop threading methods
by Jeff Andrews, application engineer, Intel Corp. Explore differen...
Getting started with SSE/SSE2 for the Intel Pentium 4 Processor
Intel Corp. This paper teaches the programmer how to get started wi...
Practical C++ Programming, 2nd Edition
by Steve Oualline, O'Reilly Media Inc. C++ is a powerful, highly fl...

Related Jobs:

Help Desk JR Technician #R-261-05 - VA - Arlington - McDonald Bradley, Inc.
R-261-05 Help Desk JR Technician Sep 14, 2005 Arlington,Virgini...
Software Engineer #329679 - CA - Santa Clara - Formalized Design
Formalized Design looking for Software Engineer (RO) Formalized Design...
Help Desk Lead #R-256-05 - VA - Arlington - McDonald Bradley, Inc.
R-256-05 Help Desk Lead Sep 14, 2005 Arlington,Virginia Send J...
Help Desk JR Technician #R-263-05 - VA - Arlington - McDonald Bradley, Inc.
R-263-05 Help Desk JR Technician Sep 14, 2005 Arlington,Virginia ...
Help Desk (Entry It Specialist) #R-266-05 - VA - Herndon - McDonald Bradley, Inc.
R-266-05 Help Desk (Entry It Specialist) Sep 14, 2005 Arlington,Vir...
Help Desk (Junior IT Analyst) #R-258-05 - DC - Washington - McDonald Bradley, Inc.
R-258-05 Help Desk (Junior IT Analyst) Sep 14, 2005 Washington,Distr...
Help Desk (Junior IT Analyst) #R-257-05 - DC - Washington - McDonald Bradley, Inc.
R-257-05 Help Desk (Junior IT Analyst) Sep 14, 2005 Washington,Distr...
Software Engineer #N02641 - NJ - Totowa - BAE Systems
Description: Software Engineer with the ability to participate in var...
Firmware/BIOS Development Engineer - WA - Bellevue - General Software, Inc.
General Software is expanding its Technology Team with new Firmware an...
Help Desk JR Technician #R-262-05 - VA - Arlington - McDonald Bradley, Inc.
R-262-05 Help Desk JR Technician Sep 14, 2005 Arlington,Virginia ...