public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: franord@msn.com
To: gcc-gnats@gcc.gnu.org
Subject: other/10184: unsigned long long arithmetics incorrect
Date: Fri, 21 Mar 2003 14:56:00 -0000	[thread overview]
Message-ID: <20030321144619.6435.qmail@sources.redhat.com> (raw)


>Number:         10184
>Category:       other
>Synopsis:       unsigned long long arithmetics incorrect
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Mar 21 14:56:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     franord@msn.com
>Release:        gcc version 2.9-PentiumIII-010221 (2.96+) VxWorks 5.5
>Organization:
>Environment:

>Description:
When arithmetic on two unsigned long long variables (64-bit) are done, and the result is assigned to unsigned long (32-bit var), the arithmetic is only done on 32-bit. This happens even if trying to cast the result to unsigned long long. However, if first assigning the result to an unsigned long long variable, then assigning to unsigned long, correct code is generated.
>How-To-Repeat:

>Fix:
Work-around: Assign arithmetic result to a temporary 64-bit variable first, then cast to 32-bit.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="gcc unsigned long long error example.txt"
Content-Disposition: inline; filename="gcc unsigned long long error example.txt"

unsigned long long TscRef;	/* Reference value of TSC register, set on each timestamp count */

UINT32 sysTimestamp (void)
{
	unsigned long long TscVal;
	/* Fill 64-bit value into TscVal */
	pentiumTscGet64 (&TscVal);
	/* Various combinations of casts and no casts at all have been tried */
	return (UINT32) (unsigned long long) (TscVal - TscRef);
}

The following code is generated

    0060a830  55                       PUSH         EBP
    0060a831  89 e5                    MOV          EBP, ESP
    0060a833  83 ec 18                 SUB          ESP, 24
    0060a836  83 ec 0c                 SUB          ESP, 12
    0060a839  8d 45 f8                 LEA          EAX, [EBP-8]
    0060a83c  50                       PUSH         EAX
    0060a83d  e8 5e 29 01 00           CALL         pentiumTscGet64
    0060a842  83 c4 10                 ADD          ESP, 16
    0060a845  8b 55 f8                 MOV          EDX, [EBP-8]
; Here it is --> Only the lower 32 bits of the 64-bit variable is subtracted
    0060a848  2b 15 88 c7 6f 00        SUB          EDX, 0x006fc788
    0060a84e  89 d0                    MOV          EAX, EDX
    0060a850  eb 00                    JMP          sysTimestamp + 0x22
    0060a852  89 ec                    MOV          ESP, EBP
    0060a854  5d                       POP          EBP
    0060a855  c3                       RET          


             reply	other threads:[~2003-03-21 14:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-21 14:56 franord [this message]
2003-03-21 15:21 bangerth

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=20030321144619.6435.qmail@sources.redhat.com \
    --to=franord@msn.com \
    --cc=gcc-gnats@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).