home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / superopt-2.5-src.tgz / tar.out / fsf / superopt / README < prev    next >
Text File  |  1996-09-28  |  7KB  |  195 lines

  1.  
  2.             GNU SUPEROPTIMIZER
  3.  
  4. The superoptimizer is a function sequence generator that uses an exhaustive
  5. generate-and-test approach to finding the shortest instruction sequence for
  6. a given function.  You have to tell the superoptimizer which function and
  7. which CPU you want to generate code for, and how many instructions you can
  8. accept.
  9.  
  10. The superoptimizer can't generate very long sequences, unless you have a
  11. very fast computer or very much spare time.  The time complexity of the used
  12. algorithm is approximately
  13.  
  14.          2n
  15.     O(m n  )
  16.  
  17. where m is the number of available instructions on the architecture and n is
  18. the shortest sequence for the goal function.  The practical sequence length
  19. limit depends on the target architecture and goal function arity; In most
  20. cases it is about 5, but for a rich instruction set as the HPPA it is just
  21. 4.  The longest sequence ever generated was for the MC68020 and 7
  22. instructions long.  It took several weeks to generate it...
  23.  
  24. The superoptimizer can't guarantee that it finds the best possible
  25. instruction sequences for all possible goal functions.  For example, it
  26. doesn't even try to include immediate constants (other that -1, 0, +1, and
  27. the smallest negative and biggest positive numbers) in the sequences.
  28.  
  29. Other reasons why not optimal sequences might be found is that not all
  30. instructions are included, not even in their register-only form.  Also, some
  31. instructions included might not be correctly simulated.  If you encounter
  32. any of these problems, please report them to the address below.
  33.  
  34. WARNING!  The generated sequences might be incorrect with a very small
  35. probability.  Always make sure a sequence is correct before using it.  So
  36. far, I have never encountered any incorrect sequences.  If you find one,
  37. please let me know about it!
  38.  
  39. Having said this, note that the superoptimizer practically always finds
  40. optimal and correct sequences for functions that depend on registers only.
  41.  
  42.  
  43.             USAGE INSTRUCTIONS
  44.  
  45. The superoptimizer supports these CPUs: SPARC v7, Motorola 68000, 68020, and
  46. 88000, IBM POWER and PowerPC, AMD 29000, Intel x86 and 960 1.0 and 1.1,
  47. Pyramid, DEC Alpha, HP PA-RISC, and Hitachi SH.  SGI Mips is not supported,
  48. since it doesn't have instructions whose use in non-obvious.  Some new
  49. instructions, like the Intel P6 and Sparc v9 conditional moves are not
  50. supported.
  51.  
  52. You need an ANSI C compiler, for example GCC, to compile the superoptimizer.
  53. Type
  54.  
  55.     make CPU=-D<cpuname> superopt
  56.  
  57. where <cpuname> is one of SPARC, MC68000, MC68020, M88000, POWER, POWERPC,
  58. AM29K, I386, I960 (for i960 1.0), I960B (for I960B 1.1), PYR, ALPHA, HPPA,
  59. or SH.  The compilation might take a long time and use up a lot of memory,
  60. especially for HPPA.
  61.  
  62. You can also build all superoptimizers by typing:
  63.  
  64.     make all
  65.  
  66. This will create superopt-sparc, superopt-power, etc.
  67.  
  68. There are also install targets, use `make install' to install a single
  69. superoptimizer and `make install-all' to install all of them.
  70.  
  71. To run the superoptimizer, type
  72.  
  73.     superopt -f<goal-function> | -all  [-assembly] [-max-cost n]
  74.        [-shifts] [-extracts] [-no-carry-insns] [-extra-cost n]
  75.  
  76. and wait until the found instructions sequences are printed.  For example,
  77.  
  78.     superopt -flts0 -as
  79.  
  80. will print all sequences computing the statement
  81.  
  82.     { r = (signed_word) v0 < 0; }.
  83.  
  84. See below for some examples of possible goal functions.
  85.  
  86. By default, the superoptimizer doesn't try all immediate shift counts.  To
  87. enable all shift counts, pass -shifts as a command line option.  To enable
  88. all bit field extracts, use -extracts.
  89.  
  90.             OPTIONS
  91.  
  92. The `-f' option has always to be defined to tell the superoptimizer for
  93. which function it should try to to find an instruction sequence.  See below
  94. for possible function names.
  95.  
  96. Option names may be abbreviated.
  97.  
  98. -assembly
  99.     Output assembly suitable to feed the assembler instead of pseudo-
  100.     code suitable for humans.
  101.  
  102. -max-cost n
  103.     Limit the `cost' of the instruction sequence to n.  May be used to
  104.     stop the search if no instruction sequence of that length or
  105.     shorter is found.  By default this is 4.
  106.  
  107. -extra-cost n
  108.     Search for sequences n more expensive than the cheapest found
  109.     sequence.  Default is 0 meaning that only the cheapest sequence(s)
  110.     are printed.
  111.  
  112. -no-carry-insns
  113.     Don't use instructions that use the carry flag.  This might be
  114.     desirable on RISCs to simplify instruction scheduling.
  115.  
  116. -shifts
  117.     Include all shift counts supported by the target architecture in
  118.     the search.  This slows down the search considerably.
  119.  
  120. -extracts
  121.     Include all bit field extracts supported by the target architecture
  122.     in the search.  This slows down the search considerably.
  123.  
  124. -f<goal-function-name>
  125.     
  126.     where <goal-function-name> is one of eq, ne, les, ges, lts, gts,
  127.     leu, geu, ltu, gtu, eq0, ne0, les0, ges0, lts0, gts0, neq, nne,
  128.     nles, nges, nlts, ngts, nleu, ngeu, nltu, ngtu, neq0, nne0, nles0,
  129.     nges0, nlts0, ngts0, maxs, mins, maxu, minu, sgn, abs, nabs, gray,
  130.     or gray2, etc, etc.
  131.  
  132.     eq, ne, les, etc, computes the C expression "a == b", "a != b", "a
  133.     <= b", etc, where the operation codes ending in `s' indicates
  134.     signed comparison; `u` indicates unsigned comparison.
  135.  
  136.     eq0,... computes "a == 0", ...
  137.  
  138.     The `n' before the names means that the corresponding function
  139.     value is negated, e.g. nlt is the C expression "-(a < b)".
  140.  
  141.     maxs, mins, maxu, minu are binary (i.e. two argument) signed
  142.     respectively unsigned max and min.
  143.  
  144.     sgn is the unary sign function; -1 for negative, 0 for zero, and +1
  145.     for positive arguments.
  146.  
  147.     abs and nabs are absolute value and negative absolute value,
  148.     respectively.
  149.  
  150.     For a complete list of goal function and their definitions, look in
  151.     the file goal.def.  You can easily add your own goal functions to
  152.     that file.  After having added a new function, you have to recompile
  153.     the superoptimizer.
  154.  
  155.  
  156.         READING SUPEROPTIMIZER OUTPUT
  157.  
  158. The superoptimizer by default outputs sequences in high-level language like
  159. syntax.  For example, this is the output for M88000/abs:
  160.  
  161. 1:    r1:=arith_shift_right(r0,0x1f)
  162.     r2:=add_co(r1,r0)
  163.     r3:=xor(r2,r1)
  164. 2:    r1:=arith_shift_right(r0,0x1f)
  165.     r2:=add(r1,r0)
  166.     r3:=xor(r2,r1)
  167. 3:    r1:=arith_shift_right(r0,0x1f)
  168.     r2:=xor(r1,r0)
  169.     r3:=adc_co(r2,r1)
  170.  
  171. r1:=arith_shift_right(r0,0x1f) means "shift r0 right 31 steps
  172. arithmetically and put the result in r1".  add_co is "add and set carry".
  173. adc_co is the subtraction instruction found on most RISCs, i.e. "add with
  174. complement and set carry".  This may seem dumb, but there is an important
  175. difference in the way carry is set after an addition-with-complement and a
  176. subtraction.  The suffixes "_ci" and "_cio" means respectively that carry
  177. is input but not affected, and that carry is both input and generated.
  178.  
  179. The interesting value is always the value computed by the last instruction.
  180.  
  181.  
  182.         *********************************
  183.  
  184. Please send comments, improvements and new ports to tege@gnu.ai.mit.edu.
  185.  
  186. The GNU superoptimizer was written by Torbjorn Granlund (currently with
  187. Cygnus Support).  Tom Wood (at the time with Data General, now at Motorola)
  188. made major improvements, like the clean way to describe goal functions and
  189. internal instructions.  The original superoptimizer idea is due to Henry
  190. Massalin.
  191.  
  192. The GNU superoptimizer and it's application for tuning GCC are described in
  193. the proceedings of the ACM SIGPLAN conference on Programming Language
  194. Design an Implementation (PLDI), 1992.
  195.