home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.sgi
- Path: sparky!uunet!europa.asd.contel.com!darwin.sura.net!Sirius.dfn.de!chx400!bernina!hoesel
- From: hoesel@igc.ethz.ch (Frans van Hoesel)
- Subject: optimise ??? (C compiler generates sub-optimal code)
- Message-ID: <1992Aug16.171608.2333@bernina.ethz.ch>
- Sender: news@bernina.ethz.ch (USENET News System)
- Organization: University of Groningen, the Netherlands
- Date: Sun, 16 Aug 1992 17:16:08 GMT
- Lines: 55
-
- The next piece of code generates non-optimized output, even with -O4.
-
- static int array[100];
- void main(void) {
- array[1] = 1;
- array[4] = 1;
- array[7] = 1;
- array[23] = 1;
- }
-
- the disassembled output is as follows:
- t.c:1 static int array[100];
- t.c:2 void main(void) {
- t.c:3 array[1] = 1;
- [0x400200] li r14,1
- [0x400204] lui r1,0x1000
- [0x400208] sw r14,2900(r1)
- t.c:4 array[4] = 1;
- [0x40020c] lui r1,0x1000
- [0x400210] li r15,1
- [0x400214] sw r15,2912(r1)
- t.c:5 array[7] = 1;
- [0x400218] lui r1,0x1000
- [0x40021c] li r24,1
- [0x400220] sw r24,2924(r1)
- t.c:6 array[23] = 1;
- [0x400224] lui r1,0x1000
- [0x400228] li r25,1
- [0x40022c] sw r25,2988(r1)
- t.c:7 }
-
- whereas an optimised version would look something like:
- li r14,1
- lui r1,0x1000
- sw r14,2900(r1)
- sw r14,2912(r1)
- sw r14,2924(r1)
- sw r14,2988(r1)
-
- Is there any way to let the compiler perform this rather simple opitmalization
- ? or do I have to switch back to good old assembler (even in 1992?)
-
- I'm not a mips expert, so bear with me, please,
-
- --frans
-
- (don't tell me the really optimised version is simply : main () {;} )
-
-
-
- --
- ===========================================================================
- === frans van hoesel scientific research programmer ===
- === hoesel@igc.ethz.ch seeking a JOB in europa ===
- ===========================================================================
-