CONSTANT FOLDING

  

Copyright © Philip M. Parker, INSEAD. Terms of Use.

CONSTANT FOLDING

Specialty Definition: CONSTANT FOLDING

DomainDefinition

Computing

Constant folding A compiler optimisation technique where constant subexpressions are evaluated at compile time. This is usually only applied to built-in numerical and boolean operators whereas partial evaluation is more general in that expressions involving user-defined functions may also be evaluated at compile time. (1997-02-20). Source: The Free On-line Dictionary of Computing.

Source: compiled by the editor from various references; see credits.

Top     

Specialty Definition: Constant folding

(From Wikipedia, the free Encyclopedia)

(See below for a dissenting article)

Constant folding is the optimization done by compilers in early stage of the compilation of a program. In C it is the optimization that makes it possible to have constant expressions in array-declarations, like:

#define WIDTH 320
#define HEIGHT 240

char buffer[WIDTH*HEIGHT];

Constant folding is similar to constant propagation, however constant folding must be done before the high-level language is translated to three-address-code to make code like above work. Constant propagation is done on the three-address-code (preferably on SSA form)

I would argue that the above is not quite correct. Although the above is an example of constant folding, the difference between constant folding and constant propagation is not the stage of the compiler during which they occur (both can occur at several stages), but actually what they do.

Constant folding is the process of simplifying expressions at compile-time which consist only of constants, which are usually simple literals like 2. An example is this:

 i = 320*200*32;

Most modern compilers would not generate two multiply instructions for this statement. Instead, they identify constructs like these, and compute their values at compile time, substituting them in, usually in the IR (intermediate representation) tree.

Constant folding and constant propagation can work together to effect many reductions of expressions by interleaving them repeatedly until no more changes are possible. Take this pseudocode for example:

 int x = 14;
 int y = 7 - x/2;

return y*(28/x+2);

If we execute constant propagation on this, we obtain

 int x = 14;
 int y = 7 - 14/2;

return y*(28/x+2);

If we execute constant folding on this, we get:

 int x = 14;
 int y = 0;

return y*(28/x+2);

If we execute constant propagation on this, we get:

 int x = 14;
 int y = 0;

return 0;

As noted by the previous author, sometimes constant folding must be done early so that expressions which can only contain constants, and not expressions, such as array initializers in C, can accept simple arithmetic expressions. However, this doesn't preclude doing it later again after constant propagation.

Source: adapted by the editor from Wikipedia, the free encyclopedia under a copyleft GNU Free Documentation License (GFDL) from the article "Constant folding."

Top     

Crosswords: CONSTANT FOLDING

Specialty definitions using "CONSTANT FOLDING": partial evaluationTree Transformation Language, Turbo C. (references)

Top     

Anagrams: CONSTANT FOLDING

Scrabble® Enable2K-Verified Anagrams

Words within the letters "a-c-d-f-g-i-l-n-n-n-o-o-s-t-t"

-4 letters: conflations.

-5 letters: anticodons, canoodling, cognations, confidants, conflating, conflation, contagions, flotations, inconstant, langostino, nonactions, olfactions.

Source: compiled by the editor from various references; see credits.

SCRABBLE® is a registered trademark. All intellectual property rights in and to the game are owned in the U.S.A and Canada by Hasbro Inc., and throughout the rest of the world by J.W. Spear & Sons Limited of Maidenhead, Berkshire, England, a subsidiary of Mattel Inc. Mattel and Spear are not affiliated with Hasbro.

Top     

Alternative Orthography: CONSTANT FOLDING


Hexadecimal (or equivalents, 770AD-1900s) (references)

43 4F 4E 53 54 41 4E 54      46 4F 4C 44 49 4E 47

Leonardo da Vinci (1452-1519; backwards) (references)

    

Binary Code (1918-1938, probably earlier) (references)

01000011 01001111 01001110 01010011 01010100 01000001 01001110 01010100 00100000 01000110 01001111 01001100 01000100 01001001 01001110 01000111

HTML Code (1990) (references)

&#67 &#79 &#78 &#83 &#84 &#65 &#78 &#84 &#32 &#70 &#79 &#76 &#68 &#73 &#78 &#71

ISO 10646 (1991-1993) (references)

0043 004F 004E 0053 0054 0041 004E 0054      0046 004F 004C 0044 0049 004E 0047

Encryption (beginner's substitution cypher): (references)

3749485354354854240494638434841

Top     



INDEX

1. Crosswords
2. Anagrams
3. Orthography
4. Bibliography


  

Copyright © Philip M. Parker, INSEAD. Terms of Use.