Message-Id: <199605191410.AA04794@sun17.thp.Uni-Koeln.DE> From: brenig AT thp DOT Uni-Koeln DOT DE (Wolfram Brenig) Date: Sun, 19 May 1996 16:10:54 +0200 To: djgpp AT delorie DOT com Subject: V2.x and -On (2nd) To any of those friendly DJGPP gurus this may be of a concern: On Wed, 15 May 1996 I submitted a Q to regarding SIGFPE's I get with V2.x and lengthy algebraic exprs. compiled using the -On switch. As is obvious from the the code attached below (following '======' ) using DJGPP-V2.x and the -On switch things are even much worse. Setting: #define PRIFCT printf // #define PRIFCT // in this small program, which just evals. a few simple expressions, and compiling with: gcc -O foo.cc -lm everything seems to be ok. with the program producing some completely harmless output: z111= -1.625e+00 z112= 3.188e+00 z11= -2.750e-01 z12= 4.875e+00 z13= 1.000e+00 z1= -3.644e+03 z21= -6.250e-02 z22= 2.625e+00 z2= -1.433e+02 z3= -8.206e+01 z4= -4.573e+04 z5= 2.039e+01 z6= 3.221e+00 z7= 2.243e-01 z8= 3.221e+00 z9= 4.624e+01 F= -5.701e+00 However, simply commenting away the various printf statements by setting: // #define PRIFCT printf #define PRIFCT // and, again, compiling with: gcc -O foo.cc -lm the program crashes with: Exiting due to signal SIGFPE Floating Point exception at eip=000016be eax=3ff00000 ebx=00000000 ecx=0005304c edx=3fe00000 esi=3fe00000 edi=0000dac0 ebp=0004da98 esp=0004da40 cs=00a7 ds=00af es=00af fs=008f gs=00bf ss=00af Call frame traceback EIPs: 0x000016be _main+286 0x00003dd3 ___crt1_startup+115 Now, doing all the same as above however, with the -On switch *removed*, i.e. gcc foo.cc -lm, there is *no* problem with *both* versions of the program. WHAT IS WRONG HERE !?!? B.t.w.: 1) I performed the whole procedure with * V1.x * : No problems. 2) I did all of it on a SUN workstation using SOLARIS' CC compiler: No problems. 3) Like suggested by one of the answers to my previous mail I enabled the strength-reduce opt. in the lib specs: still the same problem with V2.x 4) The time stamps of those distribution file I use in my setup and do the compilation with is: SPECS 693 24.12.95 3:47 CPP EXE 115712 22.02.96 3:49 CC1PLUS EXE 1360896 05.02.96 2:10 AS EXE 247296 05.02.96 2:08 LD EXE 230400 05.02.96 2:09 STUBIFY EXE 53760 31.01.96 5:41 5) My machine is just a one of those simple garden-variety 486-PCs, 16MB Ram, and the usual stuff .... Any help is most appreciated. I am *not* subscribing to the djgpp mailing list so please mail your comments to: brenig AT thp DOT uni-koeln DOT de Thanks :-) ! ==================Here is that program======================= #include #include #define QDR(x) ((x)*(x)) #define CUB(x) ((x)*(x)*(x)) #define PRIFCT printf //#define PRIFCT // int main() { double t=5.,d0=1.,a=2.,b=1.,c=-.6,be=.5,ga=2,nu=.66,T=.5; double tm1=T-1,emt=1-T,th2=QDR(T); double th4=QDR(th2),tm1h2=QDR(tm1),atm1h2=QDR(a*tm1); double pa=pow(emt,ga),pe=pow(T,be),ex=exp(a/T); double F,z111=0,z112=0,z11=0,z12=0,z13=0,z1=0,z21=0,z22=0,z2=0,z3=0, z4=0,z5=0,z6=0,z7=0,z8=0,z9=0; z111=(a*tm1-T*(be*tm1+ga*T+emt)); PRIFCT("z111=%12.3e\n",z111); z112=(atm1h2-a*T*tm1*(be*tm1+3*ga*T-2*tm1)+ga*CUB(T)* (be*tm1+T*(2*ga-1))); PRIFCT("z112=%12.3e\n",z112); z11=(b*c*z112*pa+be*T*tm1*z111); PRIFCT("z11=%12.3e\n",z11); z12=(2*atm1h2-2*a*T*tm1*(2*ga*T+emt)+ga*th4*(2*ga-1)); PRIFCT("z12=%12.3e\n",z12); z13=(2*be*tm1+ga*T+emt); PRIFCT("z13=%12.3e\n",z13); z1=(be*c*th2*tm1*z13*pow(T,2*be)+ex*z11*pe-b*z12*QDR(ex)*pa); PRIFCT("z1=%12.3e\n",z1); z21=(QDR(be*tm1)+be*tm1*(2*ga*T+emt)+ga*th2*(ga-1)); PRIFCT("z21=%12.3e\n",z21); z22=(atm1h2-2*a*T*tm1*(ga*T+emt)+ga*th4*(ga-1)); PRIFCT("z22=%12.3e\n",z22); z2=(c*th2*z21*pe-z22*ex); PRIFCT("z2=%12.3e\n",z2); z3=(c*T*(be*tm1+ga*T)*pe+(a*tm1-ga*th2)*ex); PRIFCT("z3=%12.3e\n",z3); z4=2*(c*pe-ex)*QDR(be*T*tm1*pe-b*(a*tm1-ga*th2)*ex*pa); PRIFCT("z4=%12.3e\n",z4); z5=(be*T*tm1*pe-b*(a*tm1-ga*th2)*ex*pa); PRIFCT("z5=%12.3e\n",z5); z6=(th4*QDR(pe+b*ex*pa)*tm1h2); PRIFCT("z6=%12.3e\n",z6); z7=(th4*(pe+b*ex*pa)*tm1h2); PRIFCT("z7=%12.3e\n",z7); z8=(th4*QDR(pe+b*ex*pa)*tm1h2); PRIFCT("z8=%12.3e\n",z8); z9=(th4*CUB(pe+b*ex*pa)*tm1h2); PRIFCT("z9=%12.3e\n",z9); F=b*pa*(z1/z6-z2/z7+z5*z3/z8-z4/z9); printf("F=%12.3e\n",F); return 1; }