All Topics  
Speculative execution

 

   Email Print
   Bookmark   Link






 

Speculative execution



 
 
In computer science
Computer science

Computer science is the study of the theoretical foundations of information and computation, and of practical techniques for their implementation and application in computer systems....
, speculative execution is the execution of code, the result of which may not be needed. In the context of functional programming
Functional programming

In computer science, functional programming is a programming paradigm that treats computation as the evaluation of function s and avoids program state and immutable object data....
, the term "speculative evaluation" is used instead.

rally, statements and definitions in a program can be divided into three types:

The first group does not benefit from speculative execution because its members need to run anyway.

The second group can be quietly discarded much like lazy evaluation
Lazy evaluation

In computer programming, lazy evaluation is the technique of delaying a computation until such time as the result of the computation is known to be needed....
 would discard its members.

The third group is the target of speculative evaluation, as its members can be run concurrently with the mandatory computations until they are needed or shown to be of the second group; this concurrency means that speculative execution can be parallelized.

ulative execution is a performance optimization
Optimization (computer science)

In computing, optimization is the process of modifying a system to make some aspect of it work more efficiently or use fewer resources. For instance, a computer program may be optimized so that it executes more rapidly, or is capable of operating with less Computer data storage or other resources, or draw less power....
.






Discussion
Ask a question about 'Speculative execution'
Start a new discussion about 'Speculative execution'
Answer questions from other users
Full Discussion Forum



Encyclopedia


In computer science
Computer science

Computer science is the study of the theoretical foundations of information and computation, and of practical techniques for their implementation and application in computer systems....
, speculative execution is the execution of code, the result of which may not be needed. In the context of functional programming
Functional programming

In computer science, functional programming is a programming paradigm that treats computation as the evaluation of function s and avoids program state and immutable object data....
, the term "speculative evaluation" is used instead.

Types

Generally, statements and definitions in a program can be divided into three types:
  • things which must be run and are mandatory
  • things which do not need to be run because they are irrelevant
  • statements which cannot be proven to be in either of the first two groups


The first group does not benefit from speculative execution because its members need to run anyway.

The second group can be quietly discarded much like lazy evaluation
Lazy evaluation

In computer programming, lazy evaluation is the technique of delaying a computation until such time as the result of the computation is known to be needed....
 would discard its members.

The third group is the target of speculative evaluation, as its members can be run concurrently with the mandatory computations until they are needed or shown to be of the second group; this concurrency means that speculative execution can be parallelized.

Function

Speculative execution is a performance optimization
Optimization (computer science)

In computing, optimization is the process of modifying a system to make some aspect of it work more efficiently or use fewer resources. For instance, a computer program may be optimized so that it executes more rapidly, or is capable of operating with less Computer data storage or other resources, or draw less power....
. It is only useful when early execution consumes less time and space than later execution would, and the savings are enough to compensate, in the long run, for the possible wasted effort of computing a value which is never used.

Modern pipelined
Instruction pipeline

File:5 Stage Pipeline.svgAn instruction pipeline is a technique used in the design of computers and other digital electronic devices to increase their instruction throughput ....
 microprocessor
Microprocessor

A microprocessor incorporates most or all of the functions of a central processing unit on a single integrated circuit . The first microprocessors emerged in the early 1970s and were used for electronic calculators, using Binary-coded decimal arithmetic on 4-bit Word ....
s use speculative execution to reduce the cost of conditional branch instructions. When a conditional branch instruction is encountered, the processor guesses which way the branch is most likely to go (this is called branch prediction
Branch predictor

In computer architecture, a branch predictor is the part of a central processing unit that determines whether a conditional branch in the instruction flow of a program is likely to be taken or not....
), and immediately starts executing instructions from that point. If the guess later proves to be incorrect, all computation past the branch point is discarded. The early execution is relatively cheap because the pipeline stages involved would otherwise lie dormant until the next instruction was known. However, wasted instructions consume CPU cycles that could have otherwise delivered performance, and on a laptop, those cycles consume batteries. There is always a penalty for a mispredicted branch. Many microprocessors (such as the Intel Pentium II and successors) have a conditional move instruction. This is an operation to move data, usually, between a register and memory, if a condition is met. There is no branching any more, and the misprediction penalty is less.

Eager Execution

Though it is seldom referred to as such, eager execution is also a form of speculative execution (although the situation is complicated by the presence of side effects). Early execution is often cheaper because values needed for the computation are likely to be available on the stack
Stack (data structure)

In computer science, a stack is an abstract data type and data structure based on the principle of LIFO . Stacks are used extensively at every level of a modern computer system....
 and need not be stored and later retrieved from the heap. It can also be substantially more expensive, for instance in the case of generating the list of integers from 1 to 1,000,000. Programmers writing code in a strict programming language
Strict programming language

A strict programming language is one in which only strict functions may be defined by the user. A non-strict programming language is one that allows the user to define non-strict functions, and hence may allow lazy evaluation....
 avoid these cases by using explicit laziness
Lazy evaluation

In computer programming, lazy evaluation is the technique of delaying a computation until such time as the result of the computation is known to be needed....
 or by circumlocution (which can become very elaborate).

Lazy Evaluation

Lazy evaluation
Lazy evaluation

In computer programming, lazy evaluation is the technique of delaying a computation until such time as the result of the computation is known to be needed....
 does not speculate. The incorporation of speculative execution into implementations of the Haskell programming language
Haskell (programming language)

Haskell is a standardized, purely functional programming language with non-strict programming language, named after logician Haskell Curry. The goals of the language are described as:...
 is a current research topic. Eager Haskell
Eager Haskell

Eager Haskell is an implementation of the Haskell programming language that uses eager evaluation.Sources and External Links ...
 is designed around the idea of speculative execution. Recent versions of GHC
Glasgow Haskell Compiler

The Glorious Glasgow Haskell Compilation System, more commonly known as the Glasgow Haskell Compiler or GHC, is an open source Machine language compiler for the functional programming Computer programming Programming language Haskell ....
 support a kind of speculative execution called optimistic execution.

External links