kowalski@svax.cs.cornell.edu (Jeffrey Kowalski) (12/15/89)
Boy, I hope I'm wrong... I just spent 4 hours in SADE tracking THIS one down... Look at the program I've attached. I compile it with the flags shown - basically the FP coprocessor stuff & it generates bad code! I'm not sure why. This is clearly un-good. Can anyone suggest a solution. Is there a patch to MPW C? I'm using 3.0 right now on a IIcx. The original code is MUCH hairier. This is pretty stripped down, but still has the same effect. I realize that non-tool printf-ing is a no-no, but take them out and look at the code - it's still absolutely screwed up. If you solve this one, I've got a REALLY hard 881 addressing problem for you, but I'll save that for the brave in my next posting. Well, experts? Code follows (foo.c) ----------------------- /********************************** # The commands # (notice no \n escapers -- removed for posting) ;C -mc68020 -mc68881 -elems881 -mbg full -b3 -m -w -s "foo" foo.c -o foo.c.o ;Link -t APPL -c 'YIKE' -mf -srt -d foo.c.o "{MPW}Libraries:CLibraries:"CLib881.o "{MPW}Libraries:CLibraries:"CRuntime.o "{MPW}Libraries:Libraries:"Interface.o "{MPW}Libraries:CLibraries:"StdCLib.o "{MPW}Libraries:CLibraries:"CInterface.o -o "foo" ;foo **********************************/ #include <Types.h> struct extRect { extended left, right, bottom, top; }; void foo (dc) register struct extRect *dc; { register extended smaller, www, hhh; www = (dc->right - dc->left); hhh = (dc->top - dc->bottom); printf("%f %f\n", www, hhh); smaller = (www < hhh) ? www : hhh; printf("%f %f\n", www, hhh); } main() { struct extRect fee; Debugger(); fee.left = 11.0; fee.right= 22.0; fee.bottom = 3.0; fee.top = 4.0; foo(&fee); } /********************************** Generates the following (I removed the data stuff) foo +0002 002F7ACE DC.W $0000,$2F0B | 0000 2F0B +0006 002F7AD2 FMOVEM FP5-FP7,-(A7) | F227 E0E0 +000A 002F7AD6 MOVEA.L $0008(A6),A3 | 266E 0008 +000E 002F7ADA FMOVE.X $000C(A3),FP0 | F22B 4800 000C +0014 002F7AE0 FSUB.X (A3),FP0 | F213 4828 +0018 002F7AE4 FMOVE FP0,FP6 | F200 0300 +001C 002F7AE8 FMOVE.X $0024(A3),FP0 | F22B 4800 0024 +0022 002F7AEE FSUB.X $0018(A3),FP0 | F22B 4828 0018 +0028 002F7AF4 FMOVE FP0,FP7 | F200 0380 +002C 002F7AF8 FMOVE.X FP7,-(A7) | F227 6B80 +0030 002F7AFC FMOVE.X FP6,-(A7) | F227 6B00 +0034 002F7B00 PEA *+$004E ; 002F7B4E | 487A 004C +0038 002F7B04 JSR $021A(A5) | 4EAD 021A +003C 002F7B08 FMOVE FP6,FP0 | F200 1800 +0040 002F7B0C FCMP FP7,FP0 | F200 1C38 +0044 002F7B10 FBNLT foo+004A ; 002F7B16 | F29B 0004 +0048 002F7B14 BRA.S foo+004E ; 002F7B1A | 6004 +004A 002F7B16 FMOVE FP7,FP6 | F200 1F00 +004E 002F7B1A FMOVE FP6,FP5 | F200 1A80 +0052 002F7B1E FMOVEM FP6,-(A7) | F227 E040 +0056 002F7B22 FMOVE.X FP7,-(A7) | F227 6B80 +005A 002F7B26 FMOVE.X FP6,-(A7) | F227 6B00 +005E 002F7B2A PEA *+$0024 ; 002F7B4E | 487A 0022 +0062 002F7B2E JSR $021A(A5) | 4EAD 021A +0066 002F7B32 LEA $001C(A7),A7 | 4FEF 001C +006A 002F7B36 FMOVEM (A7)+,FP6 | F21F D002 +006E 002F7B3A LEA $001C(A7),A7 | 4FEF 001C +0072 002F7B3E FMOVEM (A7)+,FP5-FP7 | F21F D007 +0076 002F7B42 MOVEA.L (A7)+,A3 | 265F +0078 002F7B44 UNLK A6 | 4E5E +007A 002F7B46 RTS | 4E75 main +0000 002F7B56 LINK A6,#$FFD0 | 4E56 FFD0 +0004 002F7B5A _Debugger ; A9FF | A9FF +0006 002F7B5C *LEA *+$0070,A0 ; 002F7BCC | 41FA 006E +000A 002F7B60 LEA -$0030(A6),A1 | 43EE FFD0 +000E 002F7B64 MOVE.L (A0)+,(A1)+ | 22D8 +0010 002F7B66 MOVE.L (A0)+,(A1)+ | 22D8 +0012 002F7B68 MOVE.L (A0)+,(A1)+ | 22D8 +0014 002F7B6A LEA *+$0056,A0 ; 002F7BC0 | 41FA 0054 +0018 002F7B6E LEA -$0024(A6),A1 | 43EE FFDC +001C 002F7B72 MOVE.L (A0)+,(A1)+ | 22D8 +001E 002F7B74 MOVE.L (A0)+,(A1)+ | 22D8 +0020 002F7B76 MOVE.L (A0)+,(A1)+ | 22D8 +0022 002F7B78 LEA *+$003C,A0 ; 002F7BB4 | 41FA 003A +0026 002F7B7C LEA -$0018(A6),A1 | 43EE FFE8 +002A 002F7B80 MOVE.L (A0)+,(A1)+ | 22D8 +002C 002F7B82 MOVE.L (A0)+,(A1)+ | 22D8 **********************************/ /********************************** Outputs & Analysis (the standard warning dialog from MPW non-tool, then...) 11.000000 1.000000 1.000000 1.000000 Which is clearly in error. Why? Because the instruction at foo+004A moves FP7 to FP6 which effectively assigns www to hhh! Not good. So, what's the fix? (You do not get points for wise answers like "Use LSC" or "Don't compile for 881") **********************************/