[v2] sparc: Force calculation that raises exception

Message ID 20240115145345.3389246-1-cederman@gaisler.com
State Superseded
Headers

Commit Message

Daniel Cederman Jan. 15, 2024, 2:53 p.m. UTC
  Use the math_force_eval() macro to force the calculation to complete and
raise the exception.

With this change the math/test-fenv test pass.

Signed-off-by: Daniel Cederman <cederman@gaisler.com>
---
 sysdeps/sparc/fpu/fraiseexcpt.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
  

Comments

Adhemerval Zanella Netto Jan. 16, 2024, 1:57 p.m. UTC | #1
On 15/01/24 11:53, Daniel Cederman wrote:
> Use the math_force_eval() macro to force the calculation to complete and
> raise the exception.
> 
> With this change the math/test-fenv test pass.
> 
> Signed-off-by: Daniel Cederman <cederman@gaisler.com>
> ---
>  sysdeps/sparc/fpu/fraiseexcpt.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/sysdeps/sparc/fpu/fraiseexcpt.c b/sysdeps/sparc/fpu/fraiseexcpt.c
> index 26a7720ec9..87c8f9a4dc 100644
> --- a/sysdeps/sparc/fpu/fraiseexcpt.c
> +++ b/sysdeps/sparc/fpu/fraiseexcpt.c

You need to include '<math-barriers.h>' (I am getting building failure
without it).

> @@ -42,7 +42,7 @@ __feraiseexcept (int excepts)
>        /* One example of an invalid operation is 0/0.  */
>        __asm ("" : "=e" (d) : "0" (c.zero));
>        d /= c.zero;
> -      __asm __volatile ("" : : "e" (d));
> +      math_force_eval (d);
>      }
>  
>    /* Next: division by zero.  */
> @@ -50,7 +50,7 @@ __feraiseexcept (int excepts)
>      {
>        __asm ("" : "=e" (d) : "0" (c.one));
>        d /= c.zero;
> -      __asm __volatile ("" : : "e" (d));
> +      math_force_eval (d);
>      }
>  
>    /* Next: overflow.  */
> @@ -58,7 +58,7 @@ __feraiseexcept (int excepts)
>      {
>        __asm ("" : "=e" (d) : "0" (c.max));
>        d *= d;
> -      __asm __volatile ("" : : "e" (d));
> +      math_force_eval (d);
>      }
>  
>    /* Next: underflow.  */
> @@ -66,7 +66,7 @@ __feraiseexcept (int excepts)
>      {
>        __asm ("" : "=e" (d) : "0" (c.min));
>        d *= d;
> -      __asm __volatile ("" : : "e" (d));
> +      math_force_eval (d);
>      }
>  
>    /* Last: inexact.  */
> @@ -74,7 +74,7 @@ __feraiseexcept (int excepts)
>      {
>        __asm ("" : "=e" (d) : "0" (c.one));
>        d /= c.pi;
> -      __asm __volatile ("" : : "e" (d));
> +      math_force_eval (d);
>      }
>  
>    /* Success.  */
  
Daniel Cederman Jan. 16, 2024, 3:16 p.m. UTC | #2
On 2024-01-16 14:57, Adhemerval Zanella Netto wrote:
> 
> 
> On 15/01/24 11:53, Daniel Cederman wrote:
>> Use the math_force_eval() macro to force the calculation to complete and
>> raise the exception.
>>
>> With this change the math/test-fenv test pass.
>>
>> Signed-off-by: Daniel Cederman <cederman@gaisler.com>
>> ---
>>   sysdeps/sparc/fpu/fraiseexcpt.c | 10 +++++-----
>>   1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/sysdeps/sparc/fpu/fraiseexcpt.c b/sysdeps/sparc/fpu/fraiseexcpt.c
>> index 26a7720ec9..87c8f9a4dc 100644
>> --- a/sysdeps/sparc/fpu/fraiseexcpt.c
>> +++ b/sysdeps/sparc/fpu/fraiseexcpt.c
> 
> You need to include '<math-barriers.h>' (I am getting building failure
> without it).
> 

Sorry about that, I will post an updated version with this fixed.

Thank you for reviewing the patches! Can I ask you to also take a look
at the "sparc: Do not test preservation of NaN payloads for LEON" patch?
The FPU used by LEON does not support propagating NaN payloads 
(documented in Section 51.2.7 in 
https://www.gaisler.com/products/grlib/grip.pdf)
  

Patch

diff --git a/sysdeps/sparc/fpu/fraiseexcpt.c b/sysdeps/sparc/fpu/fraiseexcpt.c
index 26a7720ec9..87c8f9a4dc 100644
--- a/sysdeps/sparc/fpu/fraiseexcpt.c
+++ b/sysdeps/sparc/fpu/fraiseexcpt.c
@@ -42,7 +42,7 @@  __feraiseexcept (int excepts)
       /* One example of an invalid operation is 0/0.  */
       __asm ("" : "=e" (d) : "0" (c.zero));
       d /= c.zero;
-      __asm __volatile ("" : : "e" (d));
+      math_force_eval (d);
     }
 
   /* Next: division by zero.  */
@@ -50,7 +50,7 @@  __feraiseexcept (int excepts)
     {
       __asm ("" : "=e" (d) : "0" (c.one));
       d /= c.zero;
-      __asm __volatile ("" : : "e" (d));
+      math_force_eval (d);
     }
 
   /* Next: overflow.  */
@@ -58,7 +58,7 @@  __feraiseexcept (int excepts)
     {
       __asm ("" : "=e" (d) : "0" (c.max));
       d *= d;
-      __asm __volatile ("" : : "e" (d));
+      math_force_eval (d);
     }
 
   /* Next: underflow.  */
@@ -66,7 +66,7 @@  __feraiseexcept (int excepts)
     {
       __asm ("" : "=e" (d) : "0" (c.min));
       d *= d;
-      __asm __volatile ("" : : "e" (d));
+      math_force_eval (d);
     }
 
   /* Last: inexact.  */
@@ -74,7 +74,7 @@  __feraiseexcept (int excepts)
     {
       __asm ("" : "=e" (d) : "0" (c.one));
       d /= c.pi;
-      __asm __volatile ("" : : "e" (d));
+      math_force_eval (d);
     }
 
   /* Success.  */