From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14076 invoked by alias); 21 Mar 2003 14:56:01 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 14057 invoked by uid 71); 21 Mar 2003 14:56:01 -0000 Resent-Date: 21 Mar 2003 14:56:01 -0000 Resent-Message-ID: <20030321145601.14056.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, franord@msn.com Received: (qmail 6436 invoked by uid 48); 21 Mar 2003 14:46:19 -0000 Message-Id: <20030321144619.6435.qmail@sources.redhat.com> Date: Fri, 21 Mar 2003 14:56:00 -0000 From: franord@msn.com Reply-To: franord@msn.com To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: other/10184: unsigned long long arithmetics incorrect X-SW-Source: 2003-03/txt/msg01397.txt.bz2 List-Id: >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