This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] fix PR 37850


On Mon, Mar 9, 2009 at 7:05 PM, Nathan Froyd <froydnj@codesourcery.com> wrote:
> The complex multiplication routines in libgcc2.c compute the real and
> imaginary components of the result--x and y, respectively--and then
> combine them via:
>
> ?return x + I * y;
>
> Doing so causes problems when libgcc is compiled without optimization,
> as the above expression causes gcc to emit a call to the appropriate
> complex multiplication routine...leading to infinite recursion. ?The
> above formulation also leads to problems with NaNs, infinities, and
> negative zeros.
>
> The patch below implements Richard's suggestion from the PR comments to
> avoid these problems. ?The division routines also use the formulation
> above; I've taken the liberty of modifying it as well, since the
> new formulation should be faster and more correct.
>
> Tested on x86_64-unknown-linux-gnu. ?Hand-verified that compiling
> __mulMODE3 with no optimization no longer emit a call to itself. ?OK to
> commit?

Ok.

Thanks,
Richard.

> -Nathan
>
> 2009-03-09 ?Richard Guenther ?<rguenther@suse.de>
> ? ? ? ? ? ?Nathan Froyd ?<froydnj@codesourcery.com>
>
> ? ? ? ?PR middle-end/37850
> ? ? ? ?* libgcc2.c (__mulMODE3): Use explicit assignments to form the
> ? ? ? ?result.
> ? ? ? ?(__divMODE3): Likewise.
>
> Index: libgcc2.c
> ===================================================================
> --- libgcc2.c ? (revision 144728)
> +++ libgcc2.c ? (working copy)
> @@ -1831,6 +1831,7 @@ CTYPE
> ?CONCAT3(__mul,MODE,3) (MTYPE a, MTYPE b, MTYPE c, MTYPE d)
> ?{
> ? MTYPE ac, bd, ad, bc, x, y;
> + ?CTYPE res;
>
> ? ac = a * c;
> ? bd = b * d;
> @@ -1887,7 +1888,9 @@ CONCAT3(__mul,MODE,3) (MTYPE a, MTYPE b,
> ? ? ? ?}
> ? ? }
>
> - ?return x + I * y;
> + ?__real__ res = x;
> + ?__imag__ res = y;
> + ?return res;
> ?}
> ?#endif /* complex multiply */
>
> @@ -1898,6 +1901,7 @@ CTYPE
> ?CONCAT3(__div,MODE,3) (MTYPE a, MTYPE b, MTYPE c, MTYPE d)
> ?{
> ? MTYPE denom, ratio, x, y;
> + ?CTYPE res;
>
> ? /* ??? We can get better behavior from logarithmic scaling instead of
> ? ? ?the division. ?But that would mean starting to link libgcc against
> @@ -1943,7 +1947,9 @@ CONCAT3(__div,MODE,3) (MTYPE a, MTYPE b,
> ? ? ? ?}
> ? ? }
>
> - ?return x + I * y;
> + ?__real__ res = x;
> + ?__imag__ res = y;
> + ?return res;
> ?}
> ?#endif /* complex divide */
>
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]