lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] Optimized integral power [Was: MinGW-w64 anomaly?]


From: Greg Chicares
Subject: [lmi] Optimized integral power [Was: MinGW-w64 anomaly?]
Date: Thu, 22 Dec 2016 02:36:49 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.4.0

On 2016-12-21 02:09, Greg Chicares wrote:
> On 2016-12-20 16:24, Vadim Zeitlin wrote:
>> On Tue, 20 Dec 2016 02:41:20 +0000 Greg Chicares <address@hidden> wrote:
[...]
>> GC> Having committed this, I'm not sure it's really preferable to
>> GC> the code between #if 0 ... #endif, especially if the newer code
>> GC> works with fewer compilers.
>> 
>>  I think it's preferable if only because we've seen that the compiler will
>> unroll the loop inside std::pow() efficiently while it's unlikely to do it
>> for the loop in the old perform_pow().
> 
> Funny, I thought you'd say the opposite: that calculating integral
> powers of "integers" manually is certain to do what we want, whereas
> relying on an optional optimization in pow() (especially in light of
> Howard Hinnant's example showing how it can be harmful) is dubious.
> 
> We could of course copy sgi's 'power()' source into lmi. It uses the
> "Russian peasant algorithm", with only O(log n) multiplications:
>   https://www.sgi.com/tech/stl/power.html#1
> and it's particularly efficient for a base of ten (which, despite
> the striving for generality, is the only base we actually use)
> because there are only two 1's in ten's binary representation.
> 
> I think I'll do that for the #if 0 ... #endif block, and then see
> which alternative we like better. BTW, g++ already has a version of
> this sgi extension, under GPL3, in include/c++/ext/numeric , but
> other compilers may not, so I'll use the sgi original:
>   https://www.sgi.com/tech/stl/stl_numeric.h

Please take a look at commit 569b775d3ffc4afc526a83cb1a769f6d604101a8
and let me know if you see any reason to keep the std::pow() alternative,
now in a #if 0 ... #endif block. I'm inclined to remove it soon.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]