
On Fri, 1 Jun 2012, John Maddock wrote:
* the example about using 0 vs 11 temporaries doesn't mention what happens to the boost package if we disable expression template. Does it use a single temporary (using rvalue-references) or plenty?
Plenty, haven't measured how many, but I'd expect it to be the same as for mpclass. I guess I should cover that.
I think you really want to investigate using rvalue references, in that case. Which reminds me: there is some overlap with boost/operators.hpp (I heard someone was rewriting it?), so the rvalue reference techniques could be the same, and the documentation could say something about the relation between the 2.
rvalue references and move semantics are already supported.
You have a move constructor, but I haven't seen anything like: number operator+(number&& a, number const&b){return move(a+=b);} which would bring the number of allocations down to 1 for types with a good move constructor (I may have missed it, I can't easily test anything these days). (returning a number&& is tempting, especially for types with a bad move constructor, but is not very safe)
Nod. Support for fused multiply-add is on my TODO list.
;-) My point was actually that FMA shouldn't have anything special. What makes it interesting in GMP is that malloc is replaced with alloca for the temporary. Otherwise, it is a plain mul and add. The same optimization could just as well have been done for addadd (a+b+c) instead. With expression templates, there should be enough information to do that for any combination, not just a+b*c. It may get quite complicated though, and not so useful for a backend like cpp_int. What happens when you try to mix numbers, say z+q where z is an integer and q a rational? I imagine that z is converted to a rational and the user can't provide an optimized version of the operation (maybe for a future version?). -- Marc Glisse