home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / sgi / 12473 < prev    next >
Encoding:
Text File  |  1992-08-16  |  1.9 KB  |  66 lines

  1. Newsgroups: comp.sys.sgi
  2. Path: sparky!uunet!europa.asd.contel.com!darwin.sura.net!Sirius.dfn.de!chx400!bernina!hoesel
  3. From: hoesel@igc.ethz.ch (Frans van Hoesel)
  4. Subject: optimise ??? (C compiler generates sub-optimal code)
  5. Message-ID: <1992Aug16.171608.2333@bernina.ethz.ch>
  6. Sender: news@bernina.ethz.ch (USENET News System)
  7. Organization: University of Groningen, the Netherlands
  8. Date: Sun, 16 Aug 1992 17:16:08 GMT
  9. Lines: 55
  10.  
  11. The next piece of code generates non-optimized output, even with -O4.
  12.  
  13. static    int    array[100];
  14. void main(void) {
  15.     array[1] = 1;
  16.     array[4] = 1;
  17.     array[7] = 1;
  18.     array[23] = 1;
  19. }
  20.  
  21. the disassembled output is as follows:
  22. t.c:1  static    int    array[100];
  23. t.c:2  void main(void) {
  24. t.c:3      array[1] = 1;
  25.   [0x400200]    li      r14,1
  26.   [0x400204]    lui     r1,0x1000
  27.   [0x400208]    sw      r14,2900(r1)
  28. t.c:4      array[4] = 1;
  29.   [0x40020c]    lui     r1,0x1000
  30.   [0x400210]    li      r15,1
  31.   [0x400214]    sw      r15,2912(r1)
  32. t.c:5      array[7] = 1;
  33.   [0x400218]    lui     r1,0x1000
  34.   [0x40021c]    li      r24,1
  35.   [0x400220]    sw      r24,2924(r1)
  36. t.c:6      array[23] = 1;
  37.   [0x400224]    lui     r1,0x1000
  38.   [0x400228]    li      r25,1
  39.   [0x40022c]    sw      r25,2988(r1)
  40. t.c:7  }
  41.  
  42. whereas an optimised version would look something like:
  43.         li    r14,1
  44.         lui    r1,0x1000
  45.         sw    r14,2900(r1)
  46.         sw    r14,2912(r1)
  47.         sw    r14,2924(r1)
  48.         sw    r14,2988(r1)
  49.  
  50. Is there any way to let the compiler perform this rather simple opitmalization
  51. ? or do I have to switch back to good old assembler (even in 1992?)
  52.  
  53. I'm not a mips expert, so bear with me, please,
  54.  
  55. --frans
  56.  
  57. (don't tell me the really optimised version is simply : main () {;} )
  58.  
  59.  
  60.  
  61. -- 
  62. ===========================================================================
  63. ===  frans van hoesel               scientific research programmer      ===
  64. ===  hoesel@igc.ethz.ch             seeking a JOB in europa             ===
  65. ===========================================================================
  66.