[cfe-dev] Floating-point performance question

Stephen Canon scanon at apple.com
Fri Sep 6 09:09:24 PDT 2013


On Sep 6, 2013, at 8:31 AM, Hal Finkel <hfinkel at anl.gov> wrote:

> ----- Original Message -----
>> 
>> On 09/05/2013 04:44 PM, Richard Hadsell wrote:
>> 
>> 
>> Thanks for all the clues. Here is the stack trace:
>> feholdexcept,
>>  __ieee754_exp2,
>>  exp2,
>>  _ZN9cgi... Based on your various hints, I'm guessing that our code
>>  'pow (2.0, x)' is being optimized by Clang++ to 'exp2 (x)' and not
>>  by G++. We will try using exp2 explicitly and see what happens with
>>  the G++ version.
>> 
>> Perhaps we are running into a floating-point standards issue that our
>> old version of G++ is ignoring.
>> 
>> We'll continue investigating tomorrow.
>> 
>> We changed our code to use 'exp2 (x)' instead of 'pow (2.0, x)' and
>> verified that the G++ version now calls feholdexcept. We'll also run
>> our benchmarks again to compare Clang++ with G++ on our modified
>> code.
>> 
>> So, the question for Clang developers is: how can we avoid the
>> optimization that converts 'pow (2.0, x)' to 'exp2 (x)'?
> 
> This happens in Transforms/Utils/SimplifyLibCalls.cpp -- Maybe we should add a function to TargetLibraryInfo in order to mark exp2 as expensive on some platforms?

This is really a library bug — exp2(x) should be at least as fast as pow(2,x) with any sane implementation (in particular, the library writers can implement exp2 by calling pow(2,x), so there’s no excuse for it to be slower).  That said, it might be worth working around in the meantime.

– Steve



More information about the cfe-dev mailing list