Re: [Mingw-w64-public] Patch for finally fix fesetenv

2019-03-08 Thread Liu Hao
在 2019/3/8 15:10, Zidane Sama 写道:
> Something like this?
> 

Thanks. This testcase has been verified. I copied it into my commit
message and pushed my patch.


-- 
Best regards,
LH_Mouse



signature.asc
Description: OpenPGP digital signature
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] Patch for finally fix fesetenv

2019-03-07 Thread Zidane Sama
Something like this?

#include 
#include 

int main(void)
{
/* Compute 1.0/3.0 in default FPU mode */
volatile float somefloat = 1.0;
somefloat /= 3.0;

/* Output it in float and hex formats */
printf("%.9g\thex: %x\n", somefloat, *(int *));

fenv_t a, b;

fegetenv(); /* Save fpu env */

fesetround(FE_TOWARDZERO);  /* Set round mode */

fesetenv(); /* Restore fpu env (round mode must also be restored) */

fegetenv(); /* Get current fpu env */

/* Compute 1.0/3.0 after changing and restoring fpu env */
volatile float somefloat2 = 1.0;
somefloat2 /= 3.0;

/* Output it in float and hex formats */
printf("%.9g\thex: %x\n", somefloat2, *(int *));

/* Output FPU control words */
printf ("FPU control words: %x, %x\n", a.__control_word, b.__control_word);

return 0;
}


Output for incorrect work of fesetenv:
0.33343 hex: 3eab
0.33313 hex: 3eaa
FPU control words: 37f, f7f

For correct work output :
0.33343 hex: 3eab
0.33343 hex: 3eab
FPU control words: 37f, 37f

чт, 7 мар. 2019 г. в 21:50, Liu Hao :
>
> 在 2019/2/25 22:41, Liu Hao 写道:
> > 在 2019/2/25 19:27, Zidane Sama 写道:
> >> After this commit:
> >>
> >> [e98d80] (2.0 kB) by  Kai Tietz
> >> Add a fix for working fesetenv in libquadmath-library
> >>
> >> fesetenv was broken and do not sets new fpu state because it's now
> >> overwrites new env state by fnstenv.
> >>
> >> And this patch must fix it by store only mxcsr and load its afterwards:
> >>
> >> diff --git a/mingw-w64-crt/misc/fesetenv.c b/mingw-w64-crt/misc/fesetenv.c
> >> index f998017b..07035c66 100644
> >> --- a/mingw-w64-crt/misc/fesetenv.c
> >> +++ b/mingw-w64-crt/misc/fesetenv.c
> >> @@ -66,8 +66,7 @@ int fesetenv (const fenv_t * envp)
> >>  {
> >>fenv_t env = *envp;
> >>int _mxcsr;
> >> -  __asm__ ("fnstenv %0\n"
> >> -   "stmxcsr %1" : "=m" (*), "=m" (*&_mxcsr));
> >> +  __asm__ ("stmxcsr %0" : "=m" (*&_mxcsr));
> >>/*_mxcsr = ((int)envp->__unused0 << 16) | (int)envp->__unused1;
> >> *//* mxcsr low and high */
> >>env.__unused0 = 0x;
> >>env.__unused1 = 0x;
> >>
> >>
> >>
> >
> > This seems a good catch.
> >
> > However I think the `STMXCSR` instruction should follow
> > `__mingw_has_sse()`, although CPUs without SSE are rare. I propose
> > another patch to address this issue.
> >
> >
> >
>
> Ping?  Do you have any testcases related to this issue? Please notice
> that without any response we will not act on this.
>
>
> --
> Best regards,
> LH_Mouse
>


___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] Patch for finally fix fesetenv

2019-03-07 Thread Liu Hao
在 2019/2/25 22:41, Liu Hao 写道:
> 在 2019/2/25 19:27, Zidane Sama 写道:
>> After this commit:
>>
>> [e98d80] (2.0 kB) by  Kai Tietz
>> Add a fix for working fesetenv in libquadmath-library
>>
>> fesetenv was broken and do not sets new fpu state because it's now
>> overwrites new env state by fnstenv.
>>
>> And this patch must fix it by store only mxcsr and load its afterwards:
>>
>> diff --git a/mingw-w64-crt/misc/fesetenv.c b/mingw-w64-crt/misc/fesetenv.c
>> index f998017b..07035c66 100644
>> --- a/mingw-w64-crt/misc/fesetenv.c
>> +++ b/mingw-w64-crt/misc/fesetenv.c
>> @@ -66,8 +66,7 @@ int fesetenv (const fenv_t * envp)
>>  {
>>fenv_t env = *envp;
>>int _mxcsr;
>> -  __asm__ ("fnstenv %0\n"
>> -   "stmxcsr %1" : "=m" (*), "=m" (*&_mxcsr));
>> +  __asm__ ("stmxcsr %0" : "=m" (*&_mxcsr));
>>/*_mxcsr = ((int)envp->__unused0 << 16) | (int)envp->__unused1;
>> *//* mxcsr low and high */
>>env.__unused0 = 0x;
>>env.__unused1 = 0x;
>>
>>
>>
> 
> This seems a good catch.
> 
> However I think the `STMXCSR` instruction should follow
> `__mingw_has_sse()`, although CPUs without SSE are rare. I propose
> another patch to address this issue.
> 
> 
>

Ping?  Do you have any testcases related to this issue? Please notice
that without any response we will not act on this.


-- 
Best regards,
LH_Mouse



signature.asc
Description: OpenPGP digital signature
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] Patch for finally fix fesetenv

2019-02-25 Thread Liu Hao
在 2019/2/25 19:27, Zidane Sama 写道:
> After this commit:
> 
> [e98d80] (2.0 kB) by  Kai Tietz
> Add a fix for working fesetenv in libquadmath-library
> 
> fesetenv was broken and do not sets new fpu state because it's now
> overwrites new env state by fnstenv.
> 
> And this patch must fix it by store only mxcsr and load its afterwards:
> 
> diff --git a/mingw-w64-crt/misc/fesetenv.c b/mingw-w64-crt/misc/fesetenv.c
> index f998017b..07035c66 100644
> --- a/mingw-w64-crt/misc/fesetenv.c
> +++ b/mingw-w64-crt/misc/fesetenv.c
> @@ -66,8 +66,7 @@ int fesetenv (const fenv_t * envp)
>  {
>fenv_t env = *envp;
>int _mxcsr;
> -  __asm__ ("fnstenv %0\n"
> -   "stmxcsr %1" : "=m" (*), "=m" (*&_mxcsr));
> +  __asm__ ("stmxcsr %0" : "=m" (*&_mxcsr));
>/*_mxcsr = ((int)envp->__unused0 << 16) | (int)envp->__unused1;
> *//* mxcsr low and high */
>env.__unused0 = 0x;
>env.__unused1 = 0x;
> 
> 
> 

This seems a good catch.

However I think the `STMXCSR` instruction should follow
`__mingw_has_sse()`, although CPUs without SSE are rare. I propose
another patch to address this issue.

-- 
Best regards,
LH_Mouse
From 6237c1bb8f9a39ba523a6e633d67f0770c9bb692 Mon Sep 17 00:00:00 2001
From: Liu Hao 
Date: Mon, 25 Feb 2019 22:35:43 +0800
Subject: [PATCH] crt/misc/fesetenv.c: Do not clobber `env` with `FNSTENV`

... and do not involve `STMXCSR` unless SSE is supported.

Signed-off-by: Liu Hao 
---
 mingw-w64-crt/misc/fesetenv.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/mingw-w64-crt/misc/fesetenv.c b/mingw-w64-crt/misc/fesetenv.c
index f998017b..9b44fab6 100644
--- a/mingw-w64-crt/misc/fesetenv.c
+++ b/mingw-w64-crt/misc/fesetenv.c
@@ -65,16 +65,17 @@ int fesetenv (const fenv_t * envp)
   else
 {
   fenv_t env = *envp;
+  int has_sse = __mingw_has_sse ();
   int _mxcsr;
-  __asm__ ("fnstenv %0\n"
-   "stmxcsr %1" : "=m" (*), "=m" (*&_mxcsr));
   /*_mxcsr = ((int)envp->__unused0 << 16) | (int)envp->__unused1; *//* 
mxcsr low and high */
+  if (has_sse)
+__asm__ ("stmxcsr %0" : "=m" (*&_mxcsr));
   env.__unused0 = 0x;
   env.__unused1 = 0x;
   __asm__ volatile ("fldenv %0" : : "m" (env)
: "st", "st(1)", "st(2)", "st(3)", "st(4)",
"st(5)", "st(6)", "st(7)");
-  if (__mingw_has_sse ())
+  if (has_sse)
 __asm__ volatile ("ldmxcsr %0" : : "m" (*&_mxcsr));
 }
 
-- 
2.20.1

___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


[Mingw-w64-public] Patch for finally fix fesetenv

2019-02-25 Thread Zidane Sama
After this commit:

[e98d80] (2.0 kB) by  Kai Tietz
Add a fix for working fesetenv in libquadmath-library

fesetenv was broken and do not sets new fpu state because it's now
overwrites new env state by fnstenv.

And this patch must fix it by store only mxcsr and load its afterwards:

diff --git a/mingw-w64-crt/misc/fesetenv.c b/mingw-w64-crt/misc/fesetenv.c
index f998017b..07035c66 100644
--- a/mingw-w64-crt/misc/fesetenv.c
+++ b/mingw-w64-crt/misc/fesetenv.c
@@ -66,8 +66,7 @@ int fesetenv (const fenv_t * envp)
 {
   fenv_t env = *envp;
   int _mxcsr;
-  __asm__ ("fnstenv %0\n"
-   "stmxcsr %1" : "=m" (*), "=m" (*&_mxcsr));
+  __asm__ ("stmxcsr %0" : "=m" (*&_mxcsr));
   /*_mxcsr = ((int)envp->__unused0 << 16) | (int)envp->__unused1;
*//* mxcsr low and high */
   env.__unused0 = 0x;
   env.__unused1 = 0x;


___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public