constantfolding

How can I disable constant folding in Perl?

十年热恋 提交于 2021-02-10 14:14:41
问题 Given a command like, perl -MO=Deparse -E'use constant FOO => 42; print FOO()' How can I disable constant folding such that print 42; Shows me print FOO(); Or the like. Ideally, I would like this to be a compiler option that works for all of Perl . You can see this talked about in this thread on the perl mailing list, [perl #97942] [PATCH] Add -DO option to disable optimizations and disable constant folding and the peephole optimizer when used.. I tried -DO and it didn't work. If that option

Is the difference between these two evals explained with constant folding?

被刻印的时光 ゝ 提交于 2021-02-09 11:10:41
问题 Given these two evals which only change Module::FOO() and FOO() . # Symbols imported, and used locally. eval qq[ package Foo$num; Module->import(); my \$result = Module::FOO() * Module::FOO(); ] or die $@; # Symbols imported, not used locally referencing parent symbol. eval qq[ package Foo$num; Module->import(); my \$result = FOO() * FOO(); ] or die $@; why would the top block take up substantially less space? The script and output are reproduced below, Script package Module { use v5.30; use

Is the difference between these two evals explained with constant folding?

家住魔仙堡 提交于 2021-02-09 11:09:33
问题 Given these two evals which only change Module::FOO() and FOO() . # Symbols imported, and used locally. eval qq[ package Foo$num; Module->import(); my \$result = Module::FOO() * Module::FOO(); ] or die $@; # Symbols imported, not used locally referencing parent symbol. eval qq[ package Foo$num; Module->import(); my \$result = FOO() * FOO(); ] or die $@; why would the top block take up substantially less space? The script and output are reproduced below, Script package Module { use v5.30; use

What are the specific rules for constant folding?

ぃ、小莉子 提交于 2020-12-08 07:55:43
问题 I just realized that CPython seems to treat constant expressions, which represent the same value, differently with respect to constant folding. For example: >>> import dis >>> dis.dis('2**66') 1 0 LOAD_CONST 0 (2) 2 LOAD_CONST 1 (66) 4 BINARY_POWER 6 RETURN_VALUE >>> dis.dis('4**33') 1 0 LOAD_CONST 2 (73786976294838206464) 2 RETURN_VALUE For the second example constant folding is applied while for the first it is not though both represent the same value. It doesn't seem to be related to the

What are the specific rules for constant folding?

瘦欲@ 提交于 2020-12-08 07:55:32
问题 I just realized that CPython seems to treat constant expressions, which represent the same value, differently with respect to constant folding. For example: >>> import dis >>> dis.dis('2**66') 1 0 LOAD_CONST 0 (2) 2 LOAD_CONST 1 (66) 4 BINARY_POWER 6 RETURN_VALUE >>> dis.dis('4**33') 1 0 LOAD_CONST 2 (73786976294838206464) 2 RETURN_VALUE For the second example constant folding is applied while for the first it is not though both represent the same value. It doesn't seem to be related to the

What are the specific rules for constant folding?

孤者浪人 提交于 2020-12-08 07:55:04
问题 I just realized that CPython seems to treat constant expressions, which represent the same value, differently with respect to constant folding. For example: >>> import dis >>> dis.dis('2**66') 1 0 LOAD_CONST 0 (2) 2 LOAD_CONST 1 (66) 4 BINARY_POWER 6 RETURN_VALUE >>> dis.dis('4**33') 1 0 LOAD_CONST 2 (73786976294838206464) 2 RETURN_VALUE For the second example constant folding is applied while for the first it is not though both represent the same value. It doesn't seem to be related to the

gcc complex constant folding

和自甴很熟 提交于 2019-12-30 08:26:10
问题 It seems that gcc has some limitation on complex constant folding. Here is an example: static inline unsigned int DJBHash(const char *str) { int i; unsigned int hash = 5381; for(i = 0; i < strlen(str); i++) { hash = ((hash << 5) + hash) + str[i]; } return hash; } int f(void) { return DJBHash("01234567890123456"); } When running with -O3 optimization level (gcc 4.8), it unfolds the loop in DJBHash nicely and calculates the hash value for that string during compile time. However, when making

Does Java Compiler include String Constant Folding?

大城市里の小女人 提交于 2019-12-28 06:59:05
问题 I found out that Java supports constant folding of primitive types, but what about String s? Example If I create the following source code out.write("" + "<markup>" + "<nested>" + "Easier to read if it is split into multiple lines" + "</nested>" + "</markup>" + ""); What goes into the compiled code? Combined Version? out.write("<markup><nested>Easier to read if it is split into multiple lines</nested></markup>"); Or the less efficient run-time concatenation version? out.write(new

Perl internals and Moose: constant-folding optimization

╄→尐↘猪︶ㄣ 提交于 2019-12-22 09:40:02
问题 I've been curious about constant-folding optimizations which Perl performs, but it occurred that when the code has Moose involved chances are that constant-folding won't be performed (please correct me if I am wrong). I have Moose code which contains the method as below: sub foo { my ($self) = shift; my $test_y = $self->pos->[1]; #... if ($self->is_map_val($self->pos->[0]+8, $test_y+32) || $self->is_map_val($self->pos->[0]+32-8, $test_y+32)) { { heavy_stuff(); } #... } and when I run perl -MO

C++ constant folding a loop for prime numbers

青春壹個敷衍的年華 提交于 2019-12-21 03:55:19
问题 Having had a look at previous questions 1, 2 , I was wondering if I can force the compiler to perform a constant folding for the following code which prints prime numbers. #include <iostream> using namespace std; inline bool is_prime(int n) { if(n<2) return false; for(int i=2;i*i<=n;i++) if(n%i==0) return false; return true; } int main() { for(int i=0;i<20;i++) if(is_prime(i)) cout<<i<<endl; return 0; } And I build it via: g++ -O3 -S main.cpp -o main.asm As the result are a few: 2,3,5,7,11,13