patternMinor
Is it standard for VMs to run *= computationallyHeavyFunction() if the left hand side is 0?
Viewed 0 times
lefthandthesidestandardvmsforcomputationallyheavyfunctionrun
Problem
What is the standard way for VMs to deal with 0 *= computationallyHeavyFunction()? Given that once the VM sees that left hand factor is 0, it would know that the result of
Edit: After answer, I think I misphrased the question. I'll rephrase a bit and replace
computationallyHeavyFunction() would not matter, is it standard for VMs to still compute computationallyHeavyFunction() or do they tend to omit that computation and just evaluate as 0?Edit: After answer, I think I misphrased the question. I'll rephrase a bit and replace
computationallyHeavyFunction() that has unknown factors. If VMs see 0 * (1-1/veryLargeNumber)^anotherVeryLargeNumber, do they tend to not compute right factor? Assuming they rely on squaring algorithm, quite computation heavy with O(log2(anotherVeryLargeNumber)).Solution
Optimizing
A VM that is optimized for numerical or symbolic calculations and that has access to enough type information to know that
0 * f(…) is correct only if f has no side effect and its result is known to be finite. If f has side effects, they must be executed even if the result does not matter. If f might return a result such as NaN or infinity then the result of the calculation might be NaN and not 0.A VM that is optimized for numerical or symbolic calculations and that has access to enough type information to know that
f has no side effects and has a finite result would presumably optimize the call away. Any other type of VM would not do this optimization.Context
StackExchange Computer Science Q#117594, answer score: 5
Revisions (0)
No revisions yet.