Quantcast

Are math functions busted??.. (4.1.0 & 4.4.0)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Are math functions busted??.. (4.1.0 & 4.4.0)

Pavel Pavlov
I tried to compile x264 out of curiosity and when I finally built it I tried to run the code and got error message from x264 encoder saying that it was miscompiled.
After debugging the code I found out what was the source of error and what code was miscompiled.

Basically, log2 and log2f function return wrong results. So, I'm curios if it's a known issue and if there might be some other unpleasant surprises with some other math functions.

A simple test to verify wrong results:

#include <math.h>

#define log2f_correct(x) (logf(x) * 1.44269504088896340736f)

for(int lambda=0; lambda<5; ++lambda){
        for(int i=2010; i<2020; ++i){
                printf ("TEST1: lambda: %d, xxx => %f; log2f(i+1) => %f\n", lambda, lambda * (log2f(i+1)*2 + 0.718f + !!i) + .5f, log2f(i+1));
                printf("TEST2: lambda: %d, xxx => %f; log2f_correct (i+1) => %f\n", lambda, lambda * (log2f_correct (i+1)*2 + 0.718f + !!i) + .5f, log2f_correct(i+1));
        }
}

Results are always incorrect, here's a sample output:
[INFO ] [-2071554222] 18:28:17: x264: TEST2: lambda: 1, 2013 xxx => 24.168262; log2f_correct (i+1) => 10.975131
[INFO ] [-2071554222] 18:28:17: x264: TEST1: lambda: 1, 2013 xxx => 12.764759; log2f(i+1) => 5.273379




It has to be some sort of loop with expression, otherwise gcc will compute log2f at compile time and will produce correct output (that matches results of log2f_correct)

I verified it with both builds of cegcc and had identical errors.

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Cegcc-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/cegcc-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Are math functions busted??.. (4.1.0 & 4.4.0)

Pavel Pavlov
I'd like to do it, but I'd need some help as I don't have so much free personal time :)
I already tried it and it's not so trivial since I have no idea about most of the changes made to gcc/binutils and I don't know what I'd need to take into updated gcc. That's why I asked in my other email what svn version exactly was taken as baseline for current cegcc 4.4.0 so that I could make a diff and apply same changes to latest gcc to see it works or not. I think log2 is fixed in other versions of gcc; Android build at least doesn't have that log2 problem.



> -----Original Message-----
> From: Zack [mailto:[hidden email]]
> Sent: Saturday, July 10, 2010 23:19
> To: Pavel Pavlov
> Subject: Re: [Cegcc-devel] Are math functions busted??.. (4.1.0 & 4.4.0)
>
>   I only tried using log2. Perhaps a more comprehensive test is in order...
>
> I don't know why people would abandon Cegcc, unless perhaps they were
> using it for professional projects, and selling their products to phone users.
> Hobbyists like myself would not care so much what Microsoft does or when.
> But if they are using it for professional projects, why is log2 broken? It's a
> contradiction.
>
> It may be worth updating to the latest gcc. My question is, how much work is
> involved... and who will do it?
> -Zack
>
> >> -----Original Message-----
> >> From: Zack [mailto:[hidden email]]
> >> Sent: Saturday, July 10, 2010 23:08
> >> To: Pavel Pavlov
> >> Subject: Re: [Cegcc-devel] Are math functions busted??.. (4.1.0&
> >> 4.4.0)
> >>
> >>    I reported the log2 problem a couple months ago to this mailing
> >> list but no one responded.
> >> -Zack
> >
> > Hi Zack, did you have any similar problems with any other math functions?
> > It seems that people are not interested in cegcc since MS plans not to
> > support native development on their upcoming WinPhone7 (I doubt that
> > anyways)
> >
> >
> >>> I tried to compile x264 out of curiosity and when I finally built it
> >>> I tried to run
> >> the code and got error message from x264 encoder saying that it was
> >> miscompiled.
> >>> After debugging the code I found out what was the source of error
> >>> and
> >> what code was miscompiled.
> >>> Basically, log2 and log2f function return wrong results. So, I'm
> >>> curios if it's a
> >> known issue and if there might be some other unpleasant surprises
> >> with some other math functions.
> >>> A simple test to verify wrong results:
> >>>
> >>> #include<math.h>
> >>>
> >>> #define log2f_correct(x) (logf(x) * 1.44269504088896340736f)
> >>>
> >>> for(int lambda=0; lambda<5; ++lambda){
> >>> for(int i=2010; i<2020; ++i){
> >>> printf ("TEST1: lambda: %d, xxx =>   %f; log2f(i+1) =>   %f\n",
> >> lambda, lambda * (log2f(i+1)*2 + 0.718f + !!i) + .5f, log2f(i+1));
> >>> printf("TEST2: lambda: %d, xxx =>   %f; log2f_correct (i+1) =>
> >> %f\n", lambda, lambda * (log2f_correct (i+1)*2 + 0.718f + !!i) + .5f,
> >> log2f_correct(i+1));
> >>> }
> >>> }
> >>>
> >>> Results are always incorrect, here's a sample output:
> >>> [INFO ] [-2071554222] 18:28:17: x264: TEST2: lambda: 1, 2013 xxx =>
> >>> 24.168262; log2f_correct (i+1) =>   10.975131 [INFO ] [-2071554222]
> >>> 18:28:17: x264: TEST1: lambda: 1, 2013 xxx =>   12.764759; log2f(i+1)
> >>> =>   5.273379
> >>>
> >>>
> >>>
> >>>
> >>> It has to be some sort of loop with expression, otherwise gcc will
> >>> compute log2f at compile time and will produce correct output (that
> >>> matches results of log2f_correct)
> >>>
> >>> I verified it with both builds of cegcc and had identical errors.
> >>>
> >


------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Cegcc-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/cegcc-devel
Loading...