Boost logo

Boost :

Subject: Re: [boost] Looking for some "real world" extended precision integer arithmetic tests
From: John Maddock (boost.regex_at_[hidden])
Date: 2012-01-26 05:20:25


>> I was thinking of those approaches. It makes sense to change my code
>>appropriately as it will also enable usage of mpz_class as you noticed
>>above. As a separate benchmark it would be good to have
>>time comparison of fixed_int code working with and without expression
>>template type.
>
> I'm a little confused why we need expression templates for fixed int.
> Does the fixed int dynamically allocate? If not, what do
>the expression templates accomplish? For stack allocation of fixed int
>values I wouldn't expect reuse of memory
>to be much of a performance win. Can you clarify for me, John?

Good question.

The short answer is the expression templates are there because they're part
of the overall frontend framework (aside: it might be worthwhile providing a
simpler non-expression-template frontend for debugging purposes, but that's
another issue).

Whether they're of any benefit in this case (and no it doesn't dynamically
allocate) is open to question. Except that:

* Reducing temporaries should reduce the amount of array copying going on,
and
* The expression template do *sometimes* reduce the number of arithmetic ops
taking place - by applying the rules of arithmetic they can sometime
simplify the expressions, a banal example would be something like:

a = a+b+c;

which gets transformed to:

a+= b;
a+=c;

Probably doesn't make much difference, and I'm sure there are counter
examples where it hurts, but it'll be interesting to see how things shake
out in practice...

John.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk