From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9356 invoked by alias); 14 May 2003 15:16: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 9342 invoked by uid 71); 14 May 2003 15:16:01 -0000 Date: Wed, 14 May 2003 15:16:00 -0000 Message-ID: <20030514151601.9341.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: "omar beo" Subject: Re: optimization/10772: Result differences between debug and optmize libs on linux; and with sol/nt on optimize mode Reply-To: "omar beo" X-SW-Source: 2003-05/txt/msg01651.txt.bz2 List-Id: The following reply was made to PR optimization/10772; it has been noted by GNATS. From: "omar beo" To: giovannibajo@libero.it, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org, omarbeo@hotmail.com, gcc-gnats@gcc.gnu.org Cc: Subject: Re: optimization/10772: Result differences between debug and optmize libs on linux; and with sol/nt on optimize mode Date: Wed, 14 May 2003 09:08:14 -0600 Hi, This problem could be related to the Rounding as many suggested, but how come I got different numbers between debug and optimize libs when I run on linux? Why this code generates the same numbers on NT and Unix, but not on linux? Unfortunately, I wasn’t able to create an identical test case to the one i'm currently testing, probably because this behavior only happened when you run a large application and not just a small test case. But i included a simalr test case with a similar behavior. Could you look at the assembly code generated on debug and optimize mode, and tell me if they are equivalent. Because they don't produce the same numbers . Thank you. Here the C++ code: double this->factor; int this->GetP() {} int object::GetPS() {} double this->factor; int this->GetP() {} int object::GetPS() { double aa = (double)this->GetP() * this->factor; int bb = (int) aa; return bb; } Here the Assembly code generated in linux in optimize mode (O3): =================== .LFE223: .Lfe223: .size _ZN17object9GetPSEv,.Lfe223-_ZN17object9GetPSEv .align 2 .p2align 4,,15 .globl _ZN17object13GetPSEv .type _ZN17object13GetPSEv,@function _ZN17object13GetPSEv: .LFB224: pushl %ebp .LCFI739: movl %esp, %ebp .LCFI740: subl $24, %esp .LCFI741: movl %ebx, -4(%ebp) .LCFI742: movl 8(%ebp), %ebx movl (%ebx), %eax movl %ebx, (%esp) call *220(%eax) pushl %eax fildl (%esp) addl $4, %esp fmull 116(%ebx) fnstcw -6(%ebp) movl -4(%ebp), %ebx movzwl -6(%ebp), %eax orw $3072, %ax movw %ax, -8(%ebp) fldcw -8(%ebp) fistpl -12(%ebp) fldcw -6(%ebp) movl -12(%ebp), %eax movl %ebp, %esp popl %ebp ret .LFE224: .Lfe224: .size _ZN17object13GetPSEv,.Lfe224-_ZN1object13GetPSEv7 .align 2 .p2align 4,,15 =================== Here the Assembly code generated in linux in optimize mode (O3): .LFE183: .Lfe183: .size _ZN17object9GetPSEv,.Lfe183-_ZN17object9GetPSEv .align 2 .globl _ZN17object13GetPSEv .type _ZN17object13GetPSEv,@function _ZN17object13GetPSEv: .LFB184: .loc 1 5737 0 .LBB414: pushl %ebp .LCFI554: movl %esp, %ebp .LCFI555: subl $24, %esp .LCFI556: .loc 1 5739 0 movl 8(%ebp), %eax movl (%eax), %edx addl $220, %edx movl 8(%ebp), %eax movl %eax, (%esp) movl (%edx), %eax call *%eax pushl %eax fildl (%esp) leal 4(%esp), %esp movl 8(%ebp), %eax fmull 116(%eax) fstpl -8(%ebp) .loc 1 5740 0 fldl -8(%ebp) fnstcw -14(%ebp) movzwl -14(%ebp), %eax orw $3072, %ax movw %ax, -16(%ebp) fldcw -16(%ebp) fistpl -12(%ebp) fldcw -14(%ebp) .loc 1 5741 0 movl -12(%ebp), %eax .LBE414: pushl %ebp .LCFI554: movl %esp, %ebp .loc 1 5742 0 leave ret .LFE184: .Lfe184: i was able to create a test case that shows the same behavior: ---- #include #include double tt = 0.000000005975; double afunction() { return (5.975e-9); } long getS() { return 3332; } long getP() { return 6665; } double getPSFactor() { return ( (double) getS() / (double) getP()); } int main(int argc, char* argv[]) { double temp = 1e12*afunction(); long var_1 = (long)temp; long var_2 = (long)(1e12*afunction()) ; long var_3 = (long)(1e12*5.975e-9) ; double temp1 = tt; long var_4 = (long)(1e12*temp1) ; long var_5 = (long) (1e12*tt+0.5) ; printf("var_1: %08d\n", var_1); printf("var_2: %08d\n", var_2); printf("var_3: %08d\n", var_3); printf("var_4: %08d\n", var_4); printf("var_5: %08d\n", var_5); return 0; } --- results using: linux: debug libs var_1: 00005975 var_2: 00005974 var_3: 00005975 var_4: 00005974 var_5: 00005975 linux opt libs: var_1: 00005975 var_2: 00005975 var_3: 00005975 var_4: 00005974 var_5: 00005975 sol/nt: var_1: 00005975 var_2: 00005975 var_3: 00005975 var_4: 00005975 var_5: 00005975 _________________________________________________________________ Help STOP SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail