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

| Domain | Definition |
Computing | Constant folding |
Source: compiled by the editor from various references; see credits. | |
(From Wikipedia, the free Encyclopedia)
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 240Constant 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)char buffer[WIDTH*HEIGHT];
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;If we execute constant propagation on this, we obtainreturn y*(28/x+2);
int x = 14; int y = 7 - 14/2;If we execute constant folding on this, we get:return y*(28/x+2);
int x = 14; int y = 0;If we execute constant propagation on this, we get:return y*(28/x+2);
int x = 14; int y = 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.return 0;
Source: adapted by the editor from Wikipedia, the free encyclopedia under a copyleft GNU Free Documentation License (GFDL) from the article "Constant folding."
Crosswords: CONSTANT FOLDING |
| Specialty definitions using "CONSTANT FOLDING": partial evaluation ♦ Tree Transformation Language, Turbo C. (references) |
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. | |
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)C O N S T A N T   F O L D I N G |
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 |
| 1. Crosswords 2. Anagrams 3. Orthography 4. Bibliography |
Copyright © Philip M. Parker, INSEAD. Terms of Use.