public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Richard Henderson <rth@twiddle.net>
To: sellcey@cavium.com, Szabolcs Nagy <szabolcs.nagy@arm.com>,
	Joseph Myers <joseph@codesourcery.com>,
	Wilco Dijkstra <Wilco.Dijkstra@arm.com>
Cc: nd@arm.com, "Ellcey, Steve" <Steve.Ellcey@cavium.com>,
	"libc-alpha@sourceware.org" <libc-alpha@sourceware.org>
Subject: Re: [PATCH 3/4] Add ILP32 support to aarch64
Date: Mon, 28 Aug 2017 14:53:00 -0000	[thread overview]
Message-ID: <d2ded737-80dd-aa78-4a3b-0262c77cbed5@twiddle.net> (raw)
In-Reply-To: <1502215837.3962.127.camel@cavium.com>

[-- Attachment #1: Type: text/plain, Size: 1097 bytes --]

On 08/08/2017 11:10 AM, Steve Ellcey wrote:
> @@ -44,6 +66,32 @@ __CONCATX(__,FUNC) (ITYPE x)
>  {
>    OTYPE result;
>    ITYPE temp;
> +
> +#if IREG_SIZE == 64 && OREG_SIZE == 32
> +  if (__builtin_fabs (x) > INT32_MAX)
> +    {
> +      /* Converting large values to a 32 bit int may cause the frintx/fcvtza
> +	 sequence to set both FE_INVALID and FE_INEXACT.  To avoid this
> +         we save and restore the FE and only set one or the other.  */
> +
> +      fenv_t env;
> +      int feflags;
> +
> +      libc_feholdexcept (&env);
> +      asm ( "frintx" "\t%" IREGS "1, %" IREGS "2\n\t"
> +	    "fcvtzs" "\t%" OREGS "0, %" IREGS "1"
> +	    : "=r" (result), "=w" (temp) : "w" (x) );
> +      feflags = libc_fetestexcept (FE_INVALID | FE_INEXACT);
> +      libc_fesetenv (&env);
> +
> +      if (feflags & FE_INVALID)
> +	feraiseexcept (FE_INVALID);
> +      else if (feflags & FE_INEXACT)
> +	feraiseexcept (FE_INEXACT);
> +
> +      return result;
> +  }
> +#endif

Surely it is simply better to do the conversion in one step, getting the proper
flags set the first time.  Like so.


r~

[-- Attachment #2: zz --]
[-- Type: text/plain, Size: 1166 bytes --]

diff --git a/sysdeps/aarch64/fpu/s_lrint.c b/sysdeps/aarch64/fpu/s_lrint.c
index 8c61a039bf..a6ac070fa6 100644
--- a/sysdeps/aarch64/fpu/s_lrint.c
+++ b/sysdeps/aarch64/fpu/s_lrint.c
@@ -17,6 +17,7 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <math.h>
+#include <get-rounding-mode.h>
 
 #ifndef FUNC
 # define FUNC lrint
@@ -43,10 +44,25 @@ OTYPE
 __CONCATX(__,FUNC) (ITYPE x)
 {
   OTYPE result;
-  ITYPE temp;
-  asm ( "frintx" "\t%" IREGS "1, %" IREGS "2\n\t"
-        "fcvtzs" "\t%" OREGS "0, %" IREGS "1"
-        : "=r" (result), "=w" (temp) : "w" (x) );
+  switch (get_rounding_mode ())
+    {
+    case FE_TONEAREST:
+      asm volatile ("fcvtns" "\t%" OREGS "0, %" IREGS "1"
+		    : "=r" (result) : "w" (x));
+      break;
+    case FE_UPWARD:
+      asm volatile ("fcvtps" "\t%" OREGS "0, %" IREGS "1"
+		    : "=r" (result) : "w" (x));
+      break;
+    case FE_DOWNWARD:
+      asm volatile ("fcvtms" "\t%" OREGS "0, %" IREGS "1"
+		    : "=r" (result) : "w" (x));
+      break;
+    default:
+    case FE_TOWARDZERO:
+      asm volatile ("fcvtzs" "\t%" OREGS "0, %" IREGS "1"
+		    : "=r" (result) : "w" (x));
+    }
   return result;
 }
 

  reply	other threads:[~2017-08-28 14:53 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-03 22:33 Wilco Dijkstra
2017-08-04  0:12 ` Joseph Myers
2017-08-04 23:15   ` Steve Ellcey
2017-08-08 15:02     ` Szabolcs Nagy
2017-08-08 15:23       ` Szabolcs Nagy
2017-08-08 17:22       ` Joseph Myers
2017-08-08 18:10       ` Steve Ellcey
2017-08-28 14:53         ` Richard Henderson [this message]
2017-08-29 10:33           ` Szabolcs Nagy
  -- strict thread matches above, loose matches on Subject: below --
2017-08-03 15:36 Steve Ellcey
2017-08-03 17:47 ` Joseph Myers
2017-08-03 18:22   ` Steve Ellcey
2017-08-03 19:48     ` Joseph Myers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d2ded737-80dd-aa78-4a3b-0262c77cbed5@twiddle.net \
    --to=rth@twiddle.net \
    --cc=Steve.Ellcey@cavium.com \
    --cc=Wilco.Dijkstra@arm.com \
    --cc=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    --cc=nd@arm.com \
    --cc=sellcey@cavium.com \
    --cc=szabolcs.nagy@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).