Constant folding is related compiler optimizations used by many modern compilers. Constant folding is process of recognizing & evaluating a static expression at compile rather than computing them at runtime .
Questions tagged [constantfolding]
43 questions
1
vote
2 answers
Overflow during constant folding on a 16-bit target architecture
I'm using avr-gcc on a 16-bit target platform
I'd like to do something like this:
#define F_CPU 16000000
#define MIN_UPDATES_PER_REV 100
#define MAX_RPM 10000
#define UPDATE_PERIOD_cy ( F_CPU*60 / (MIN_UPDATES_PER_REV*MAX_RPM) )
As expected, I get…

fkoran
- 191
- 6
1
vote
0 answers
babel 6 and constants folding / propagation
Could someone suggest the right way to eliminate constants from the code in production mode? I've already tested babel-plugin-constant-folding and babel-plugin-dead-code-elimination but they both work only with babel 5, not with babel…

Vladislav Shabanov
- 11
- 2
1
vote
2 answers
Python constant folding with labels
I would like to do something that is similar to constant folding using Python.
Python has a convenient built function, eval(), so that constant only equations can be easily folded in by applying eval().
Example:
s = '4 + (5) * 2'
reduced_s =…

user2756376
- 117
- 9
1
vote
1 answer
mechanism for "undefined-ness" of modifying the value of a const
I have read, it is undefined in some C standards (perhaps 99?) what happens when a const is modified. But a student presented me with some code, which I modified.
I cannot see anything special about the address of the constant variable a. I…

Dov
- 8,000
- 8
- 46
- 75
1
vote
5 answers
Folding away assertions in C++ class?
So, in a non-class type of situation, I can do something like this:
int val_to_check = 0;
int some_func(int param) {
assert(val_to_check == 0);
return param*param+param;
}
int main() {
printf("Val: %i\n", some_func(rand()));
return…

gct
- 14,100
- 15
- 68
- 107
0
votes
1 answer
What is the expected behavior of C++ constant folding of integer expressions?
For example, let's say we have a function that replaces the two least significant decimal places of an int with 0:
int Remove2LSD(int x)
{
return x / 100 * 100;
}
If we pass 2052 we should expect a return of 2000, 2199 should return 2100.
It does…

Alex Riveron
- 389
- 1
- 10
0
votes
3 answers
Where is the description of Constant Folding in the Java Language Specification, Java SE 11 Edition (JLS SE 11)?
As far as I know, Java deals with constant variables §4.12.4 by constant folding in compile time. I've tried my best, but I couldn't find its description from JLS. Could anybody tell me where I could find official description of the constant folding…

Frank Mi
- 452
- 3
- 11
0
votes
2 answers
Deserialize JSON Map in a constant-foldable way C#
I need to pass a string representation of a map into my U-SQL program, and deserialize it into a C# Dictionary so I can then turn it to a U-SQL SqlMap. I need to do it in a constant-foldable way. My most recent…

Alex
- 139
- 1
- 7
0
votes
1 answer
Is there a way to fold an initializer list in C++17
Is there any way to do initializer list folding as opposed to using a parameter pack? My issue is that I have a heavily overloaded constructor, and I want to invoke different constructors based on whether I use {} or not. This seems to work fine…

lightxbulb
- 1,251
- 12
- 29
0
votes
1 answer
Preprocessor constant folding
I have a fundamental question regarding the C preprocessor constant evaluation and I would like some help in understanding if the preprocessor helps in optimizing the code in a situation like this. I understand that the preprocessor merely "replaces…

Sudeep Mohanty
- 41
- 9
0
votes
1 answer
Constant folding/propagation optimization with memory barriers
I have been reading for a while in order to understand better whats going on when multithread programming with a modern (multicore) CPU. However, while I was reading this, I noticed the code below in the "Explicit Compiler Barriers" section, which…

Deniz
- 858
- 10
- 31
0
votes
1 answer
Avoid switching on types to allow constant folding
I am trying to find a class hierarchy that permits to implement place holders for processor registers and operations on it. It should also allow for constants to be folded at run time. For sake of simplicity I'll only look at one operation, here…

ritter
- 7,447
- 7
- 51
- 84
0
votes
2 answers
Is __LINE__ constant-folded in this Perl one-liner?
In exploring an alternative answer to sarathi's current file line number question, I wrote this one-liner with the expectation that it would print the first line of all files provided:
$ perl -ne 'print "$ARGV : $_" if __LINE__ == 1;' *txt
This did…

Zaid
- 36,680
- 16
- 86
- 155