4 ms·
I wonder how often actual code uses these patterns. Is there anyone who would write (-x)/(-y) instead of x/y? Also, some of these patterns claim to eliminate s
by brianberns 11y ago
I wonder how often actual code uses these patterns. Is there anyone who would write (-x)/(-y) instead of x/y?
Also, some of these patterns claim to eliminate something, but they actually just move it around. For example, -(x/y) -> (-x)/y doesn't eliminate negation, so it's not clear to me that the latter form is faster than the former.
- Ono-Sendai 11y agoIt doesn't really matter if someone would write such code by hand. Code can be transformed into that pattern by compiler transformations such as inlining, CSE, constant folding etc..
- hyperpape 11y agoI believe these are mostly either a) the result of prior optimizations/inlining b) in generated code. This is often true of optimizations in general.
- dgoldstein 11y agoRe moving the negation: it could be faster if x is available a few cycles before y in a superscalar architecture as you could save a cycle by negating x while in parallel computing y.