On 01/25/2018 10:10 PM, Richard B. Kreckel wrote:
On another related note: there's a flag that tells you if an expression is expanded (status_flag::expanded), which presumably exists so that expand() repeated twice would be a quick no-op. There's no such flag for normal() though, and I'd argue it's much more needed there than in expand(). With such a flag you could pretty much put normal() all over the place without fearing for wasted computation: performance-minded code would have already normal()ized whatever it's passing into is_zero() and the like, so no performance penalty there, and more careless code would get the benefit of always obtaining correct results even when it forgot to normal()ize it's expressions.
This sounds very reasonable. Would you like to try your hand at a patch?
I've been testing the attached patch for a bit, but I do not see as big of a performance gain on my workload as I hoped for. This is because normalizing an already normal expression is already much, much faster than normalizing it in the first place, so this optimization is nice, but not as big of a deal. I haven't covered all the places status_flag::normal could be exploited though, so don't commit it just yet.