public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: Hans Petter Selasky <hselasky@c2i.net>
To: gcc-bugs@gcc.gnu.org
Subject: GCC has problems with 64-bit multiplication
Date: Thu, 08 Feb 2007 14:03:00 -0000	[thread overview]
Message-ID: <200702081502.51044.hselasky@c2i.net> (raw)

Test program:

#include <stdio.h>
#include <sys/types.h>      

int main() {

        int32_t a = 0x40000000;
        int16_t b = 0x4000;
        int64_t c = a * b;

        printf("0x%016llx\n", c);

        return 0;
}

%cc test.c
%./a.out
0x0000000000000000

%gcc --version
gcc (GCC) 3.4.6 [FreeBSD] 20060305
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Generated assembly code:

 8048514:       c7 45 fc 00 00 00 40    movl   $0x40000000,0xfffffffc(%ebp)
 804851b:       66 c7 45 fa 00 40       movw   $0x4000,0xfffffffa(%ebp)
 8048521:       0f bf 45 fa             movswl 0xfffffffa(%ebp),%eax
 8048525:       0f af 45 fc             imul   0xfffffffc(%ebp),%eax
XXX this instruction is probably the bug:
 8048529:       99                      cltd   
 804852a:       89 45 f0                mov    %eax,0xfffffff0(%ebp)
 804852d:       89 55 f4                mov    %edx,0xfffffff4(%ebp)
 8048530:       83 ec 04                sub    $0x4,%esp
 8048533:       ff 75 f4                pushl  0xfffffff4(%ebp)
 8048536:       ff 75 f0                pushl  0xfffffff0(%ebp)
 8048539:       68 cb 85 04 08          push   $0x80485cb
 804853e:       e8 49 fe ff ff          call   804838c <_init+0x24>
 8048543:       83 c4 10                add    $0x10,%esp

--HPS


             reply	other threads:[~2007-02-08 14:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-08 14:03 Hans Petter Selasky [this message]
2007-02-08 15:03 ` Graham Stott
2007-02-08 16:21   ` Hans Petter Selasky
2007-02-26 14:35   ` Hans Petter Selasky

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=200702081502.51044.hselasky@c2i.net \
    --to=hselasky@c2i.net \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).