Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-10-24 Thread Cong Hou
I have updated the patch according to your suggestion, and have committed the patch as the bootstrapping and make check both get passed. Thank you for your patient help on this patch! I learned a lot from it. thanks, Cong On Wed, Oct 23, 2013 at 1:13 PM, Joseph S. Myers wrote: > On Mon, 7 Oct

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-10-23 Thread Joseph S. Myers
On Mon, 7 Oct 2013, Cong Hou wrote: > + if (type != newtype) > +break; That comparison would wrongly treat as different cases where the types differ only in one being a typedef, having qualifiers, etc. - or if in future GCC implemented proposed TS 18661-3, cases where they differ in e.g.

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-10-17 Thread Cong Hou
Ping? thanks, Cong On Mon, Oct 7, 2013 at 10:15 AM, Cong Hou wrote: > You are right. I am not an expert on numerical analysis, but I tested > your case and it proves the number 4 conversion is not safe. > > Now we have four conversions which are safe once the precision > requirement is satisfi

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-10-07 Thread Cong Hou
You are right. I am not an expert on numerical analysis, but I tested your case and it proves the number 4 conversion is not safe. Now we have four conversions which are safe once the precision requirement is satisfied. I added a condition if (type != newtype) to remove the unsafe one, as in this

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-10-03 Thread Joseph S. Myers
On Fri, 6 Sep 2013, Cong Hou wrote: > 4: (float) sqrtl ((long double) double_val) -> (float) sqrt (double_val) I don't believe this case is in fact safe even if precision (long double) >= precision (double) * 2 + 2 (when your patch would allow it). The result that precision (double) * 2 + 2 i

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-10-03 Thread Cong Hou
Ping... thanks, Cong On Fri, Sep 20, 2013 at 9:49 AM, Cong Hou wrote: > Any comment or more suggestions on this patch? > > > thanks, > Cong > > On Mon, Sep 9, 2013 at 7:28 PM, Cong Hou wrote: >> On Mon, Sep 9, 2013 at 6:26 PM, Xinliang David Li wrote: >>> On Fri, Sep 6, 2013 at 3:24 PM, Cong

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-09-20 Thread Cong Hou
Any comment or more suggestions on this patch? thanks, Cong On Mon, Sep 9, 2013 at 7:28 PM, Cong Hou wrote: > On Mon, Sep 9, 2013 at 6:26 PM, Xinliang David Li wrote: >> On Fri, Sep 6, 2013 at 3:24 PM, Cong Hou wrote: >>> First, thank you for your detailed comments again! Then I deeply >>> ap

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-09-09 Thread Cong Hou
On Mon, Sep 9, 2013 at 6:26 PM, Xinliang David Li wrote: > On Fri, Sep 6, 2013 at 3:24 PM, Cong Hou wrote: >> First, thank you for your detailed comments again! Then I deeply >> apologize for not explaining my patch properly and responding to your >> previous comment. I didn't understand thorough

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-09-09 Thread Xinliang David Li
On Fri, Sep 6, 2013 at 3:24 PM, Cong Hou wrote: > First, thank you for your detailed comments again! Then I deeply > apologize for not explaining my patch properly and responding to your > previous comment. I didn't understand thoroughly the problem before > submitting the patch. > > Previously I

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-09-06 Thread Cong Hou
First, thank you for your detailed comments again! Then I deeply apologize for not explaining my patch properly and responding to your previous comment. I didn't understand thoroughly the problem before submitting the patch. Previously I only considered the following three conversions for sqrt():

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-09-04 Thread Joseph S. Myers
On Wed, 4 Sep 2013, Xinliang David Li wrote: > > This patch submission still fails to pay attention to various of my > > comments. > > > > If you can provide inlined comments in the patch, that will be more > useful and productive. I have explained things several times in this thread already. I

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-09-04 Thread Cong Hou
Updated patch according to your comment (tabs are not pasted here). Cong Index: gcc/convert.c === --- gcc/convert.c (revision 201891) +++ gcc/convert.c (working copy) @@ -135,16 +135,40 @@ convert_to_real (tree type, tree expr) C

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-09-04 Thread Joseph S. Myers
On Wed, 4 Sep 2013, Cong Hou wrote: > I have made a new patch according to your comments. I found several > references saying that the precision 2p+2 is OK for the sqrt > conversion (one here: > http://www.cs.berkeley.edu/~fateman/generic/algorithms.pdf). The new > patch is pasted as below. This

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-09-04 Thread Cong Hou
I have made a new patch according to your comments. I found several references saying that the precision 2p+2 is OK for the sqrt conversion (one here: http://www.cs.berkeley.edu/~fateman/generic/algorithms.pdf). The new patch is pasted as below. Thank you for all the suggestions, Joseph! Cong

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-09-04 Thread Xinliang David Li
On Wed, Sep 4, 2013 at 1:59 PM, Joseph S. Myers wrote: > On Wed, 4 Sep 2013, Cong Hou wrote: > >> I have made a new patch according to your comments. I found several >> references saying that the precision 2p+2 is OK for the sqrt >> conversion (one here: >> http://www.cs.berkeley.edu/~fateman/gene

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-09-04 Thread Xinliang David Li
On Wed, Sep 4, 2013 at 1:53 PM, Cong Hou wrote: > I have made a new patch according to your comments. I found several > references saying that the precision 2p+2 is OK for the sqrt > conversion (one here: > http://www.cs.berkeley.edu/~fateman/generic/algorithms.pdf). The new > patch is pasted as b

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-09-03 Thread Bernhard Reutner-Fischer
On 4 September 2013 00:17:00 Cong Hou wrote: Could you please tell me how to check the precision of long double in GCC on different platforms? I did not follow your discussion but.. http://uclibc.org/~aldot/precision_check.f Or something along those lines in your favourite language. HTH.. Th

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-09-03 Thread Joseph S. Myers
On Tue, 3 Sep 2013, Cong Hou wrote: > Could you please tell me how to check the precision of long double in > GCC on different platforms? REAL_MODE_FORMAT (TYPE_MODE (long_double_type_node))->p (but you should be referring to the relevant types - "type", the type being converted to, "itype", th

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-09-03 Thread Xinliang David Li
>From Joseph: "The conversion is not safe for sqrt if the two types are double and long double and long double is x86 extended, for example." This is not reflected in the patch. David On Tue, Sep 3, 2013 at 2:27 PM, Joseph S. Myers wrote: > On Tue, 3 Sep 2013, Cong Hou wrote: > >> + CASE_MAT

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-09-03 Thread Joseph S. Myers
On Tue, 3 Sep 2013, Cong Hou wrote: > + CASE_MATHFN (SQRT) > +/* sqrtl(double) cannot be safely converted to sqrt(double). */ > +if (fcode == BUILT_IN_SQRTL && > +(TYPE_MODE (type) == TYPE_MODE (double_type_node)) && > +!flag_unsafe_math_opt

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-09-03 Thread Cong Hou
Could you please tell me how to check the precision of long double in GCC on different platforms? Thank you! Cong On Tue, Sep 3, 2013 at 2:43 PM, Joseph S. Myers wrote: > On Tue, 3 Sep 2013, Xinliang David Li wrote: > >> >From Joseph: >> >> "The >> conversion is not safe for sqrt if the two ty

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-09-03 Thread Joseph S. Myers
On Tue, 3 Sep 2013, Xinliang David Li wrote: > >From Joseph: > > "The > conversion is not safe for sqrt if the two types are double and long > double and long double is x86 extended, for example." > > This is not reflected in the patch. No, the problem is that it tries to reflect it but hardcod

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-09-03 Thread Cong Hou
I have fixed my test code and replaced those aliasing violations with unions. Now the test result shows logb() is safe for the conversions. The conclusion is, logb() and fabs() are always safe for the converion, and sqrt() is unsafe for the conversion from sqrtl(double) to sqrt(double). Other math

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-08-31 Thread Joseph S. Myers
On Sat, 31 Aug 2013, Cong Hou wrote: > > I don't see why it would be unsafe for logb - can you give an example > > (exact float input value as hex float, and the values you believe logb > > should return for float and double). > > > > Please try the following code (you will get different results

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-08-30 Thread Joseph S. Myers
On Fri, 30 Aug 2013, Cong Hou wrote: > I have done a simple experiment and found that it may only be safe to do > this conversion for fabs() and sqrt(). For fabs() it is easy to see the > safety. For sqrt(), I tried many random floating point values on two > versions and did not see a difference.

Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-08-23 Thread Joseph S. Myers
On Tue, 20 Aug 2013, Cong Hou wrote: > When a sin() (cos(), log(), etc.) function is called on a value of > float type and the returned double value is converted to another value > of float type, GCC converts this function call into a float version > (sinf()) in the optimization mode. This avoids

[PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.

2013-08-20 Thread Cong Hou
When a sin() (cos(), log(), etc.) function is called on a value of float type and the returned double value is converted to another value of float type, GCC converts this function call into a float version (sinf()) in the optimization mode. This avoids two type conversions and the float version fun