public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: bug in lrint [was: FW: Printing long int in C program under cygwin64]
Date: Wed, 07 Jun 2017 09:10:00 -0000	[thread overview]
Message-ID: <20170607091019.GA5971@calimero.vinschen.de> (raw)
In-Reply-To: <d252aaae-b298-6fc8-7e5b-8d8be9f27f21@redhat.com>

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

On May 24 07:33, Eric Blake wrote:
> On 05/24/2017 07:00 AM, Carl Fredrik Forsberg wrote:
> > type cast lrint(-1.0) = 4294967295
> 
> Now that's an interesting one - it may be that cygwin1.dll actually has
> buggy behavior in lrint().  In the source code, cygwin/math/lrint.c is
> dropping down to assembly; it could very well be that the assembly code
> is incorrectly truncating things at 32 bits (where it is just fine for
> 32-bit Cygwin, but wrong for 64-bit):
> 
> long lrint (double x)
> {
>   long retval = 0L;
> #if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) ||
> defined(__i386__)
>   __asm__ __volatile__ ("fistpl %0"  : "=m" (retval) : "t" (x) : "st");
> #elif defined(__arm__) || defined(_ARM_)
>     retval = __lrint_internal(x);
> #endif
>   return retval;
> }
> 
> But I'm not an assembly coding expert, so perhaps someone else will spot
> the fix faster.

I just applied a patch to fix this.  Using fistpl is fine and dandy for
Mingw because sizeof(long) == 4, but on 64 bit Cygwin this function
has to use fistpll to account for sizeof(long) == 8.


Thanks,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  parent reply	other threads:[~2017-06-07  9:10 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-24 12:18 FW: Printing long int in C program under cygwin64 Carl Fredrik Forsberg
2017-05-24 12:54 ` bug in lrint [was: FW: Printing long int in C program under cygwin64] Eric Blake
2017-05-24 16:53   ` Erik Bray
2017-05-24 16:57     ` Erik Bray
2017-05-24 17:40       ` Eric Blake
2017-05-24 21:19         ` Carl Fredrik Forsberg
2017-05-26 12:05         ` Erik Bray
2017-05-25  1:31   ` Steven Penny
2017-05-25  7:50     ` Steven Penny
2017-05-25 17:34       ` Brian Inglis
2017-05-25 19:25     ` Eric Blake
2017-05-26  1:53       ` Steven Penny
2017-05-26  5:01         ` Steven Penny
2017-06-07  9:10   ` Corinna Vinschen [this message]
2017-06-19 11:09 Carl Fredrik Forsberg
2017-06-20 11:22 ` Corinna Vinschen

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=20170607091019.GA5971@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --cc=cygwin@cygwin.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).