public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: other/10184: unsigned long long arithmetics incorrect
@ 2003-03-21 15:21 bangerth
  0 siblings, 0 replies; 2+ messages in thread
From: bangerth @ 2003-03-21 15:21 UTC (permalink / raw)
  To: franord, gcc-bugs, gcc-prs, nobody

Synopsis: unsigned long long arithmetics incorrect

State-Changed-From-To: open->feedback
State-Changed-By: bangerth
State-Changed-When: Fri Mar 21 15:21:28 2003
State-Changed-Why:
    We need a complete, self-contained testcase to
    reproduce this. Please review
      http://gcc.gnu.org/bugs.html
    to see what is required.
    
    Also note that gcc2.96 is not an FSF released version.
    It is also rather old. Can you check whether the same
    problem still happens with a newer version, such as
    gcc 3.2.2?
    
    Thanks
      Wolfgang

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10184


^ permalink raw reply	[flat|nested] 2+ messages in thread

* other/10184: unsigned long long arithmetics incorrect
@ 2003-03-21 14:56 franord
  0 siblings, 0 replies; 2+ messages in thread
From: franord @ 2003-03-21 14:56 UTC (permalink / raw)
  To: gcc-gnats


>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          


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-03-21 15:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-21 15:21 other/10184: unsigned long long arithmetics incorrect bangerth
  -- strict thread matches above, loose matches on Subject: below --
2003-03-21 14:56 franord

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).