[x264-devel] configure: test for log2f fails, external reference folded out
Dirk Fieldhouse
fieldhouse at gmx.net
Tue Oct 16 11:04:40 CEST 2018
On 16/10/18 07:04, BugMaster wrote:
> On Tue, 16 Oct 2018 00:04:41 +0100, Dirk Fieldhouse wrote:
>> On 15/10/18 19:55, BugMaster wrote:
>>> ...
>>> So log2f exists at compile time for constant evolution but not at
>>> runtime for variables? It is weird system/environment. Or is this only
>>> due use of uClibc instead of glibc (and gcc still use glibc during
>>> constant evolution)?
>
>> Exactly. This uClibc's libmath doesn't have log2f(), but perhaps this
>> gcc was built with the equivalent of HAVE_LOGF=0, causing its internal
>> log2f() to be defined through logf(). Or perhaps it does enough static
>> analysis to determine that log2f(2) is never used and so discards it. Or
>> both?
Obvs I meant libm above, not libmath.
>>> Anyway for even more obstacle to compiler to optimize it out we can
>>> also add volatile to variable declaration.
>>>
>>> Check that it works as expected with attached patch.
>
>> Supporting the 2nd hypothesis above, it's not enough just to mention
>> log2f(x). You actually have to assign it as in my original proposal
>> above, so the proposed patch doesn't quite work even with the "volatile"
>> qualifier. I've made the trivial mod in the attached.
>
> Hm. So use of function result is obligatory condition to not remove it
> call? And what about simple 'return log2f(2);' (attached patch)?
> Or would it replace it with constant?
It would and does. Maybe it's just ambitious constant folding after all.
This fragment does correctly detects the lack of log2f() in libm --
maybe it's the simplest to do so:
volatile float x = 2; return log2f(x);
According to man gcc, the option -frounding-math "disables constant
folding of floating-point expressions at compile time", but this option
doesn't make the fragment 'return log2f(2);' work. It does however make
'return log2f(X);' where X is a float constant other than 2, work; so
gcc knows that logn(n)==1 even without folding.
regards
/df
--
London SW6
UK
More information about the x264-devel
mailing list