home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / arch / 8441 < prev    next >
Encoding:
Internet Message Format  |  1992-07-29  |  6.0 KB

  1. Path: sparky!uunet!darwin.sura.net!mips!cprice
  2. From: cprice@mips.com (Charlie Price)
  3. Newsgroups: comp.arch
  4. Subject: Re: Code Repositioning on MIPS Systems?
  5. Date: 30 Jul 1992 01:23:56 GMT
  6. Organization: MIPS Technology, Inc
  7. Lines: 156
  8. Message-ID: <l7eh5cINNpft@spim.mips.com>
  9. References: <32580130@hpcuhe.cup.hp.com>
  10. NNTP-Posting-Host: lloyd.mips.com
  11.  
  12. In article <32580130@hpcuhe.cup.hp.com> daryl@hpcuhe.cup.hp.com (Daryl Odnert) writes:
  13. >Could someone please send me or post a high level description of
  14. >the profile-based optimization capabilities of the MIPS compilers/linker.
  15. >
  16. >For example, I believe the MIPS system can support code repositioning
  17. >based on application profile measurements to reduce I-cache misses
  18. >and branch penalties.  Can someone verify this?  Any pointers to
  19. >published documentation on these optimizations would also be appreciated.
  20.  
  21. There is a function rearranger named cord.
  22. The idea is pretty simple: rearrange the functions in a program so
  23. that program hot spots thrash less in the Icache.
  24. To do this you make one or more runs of an application to find out
  25. where the program spends its time and you use this information to
  26. rearrange the program during a subsequent compilation.
  27.  
  28. Cord is normally invoked by the -cord option to cc or f77, but you
  29. can get to the program directly if you like.
  30. The manual page is included below for gory detail.
  31.  
  32.  
  33.  
  34.  
  35.  
  36. CORD(1-SysV)        RISC/os Reference Manual         CORD(1-SysV)
  37.  
  38.  
  39.  
  40. NAME
  41.      cord - rearrange procedures in an executable file to facili-
  42.      tate better cache mapping
  43.  
  44. SYNOPSIS
  45.      cord [-v] [-o outfile] [-f] [-c cachesize]    [-p maxphases]
  46.      obj_file reorder_file
  47.  
  48. DESCRIPTION
  49.      The cord command rearranges procedures in an exectable
  50.      object file to maximize efficiency    in a machine's cache.  By
  51.      rearranging the procedures    properly, we end up reducing the
  52.      instruction cache miss rates.  cord does not attempt to
  53.      determine the correct ordering, but is given a reorder file
  54.      containing    the desired procedure order.  The reorder file is
  55.      generated by the ftoc program, which in turn generates a
  56.      reorder file from a set of    profile    feedback files (see
  57.      prof(1)).
  58.  
  59.      Processed lines in    the reorder file are called procedure
  60.      lines.  Each procedure line must be on a separate source
  61.      line.  Each procedure line    must contain the source    name of
  62.      the file, followed    by a blank followed by a qualified pro-
  63.      cedure name.  Nested procedures must be qualified x.y where
  64.      x is the outer procedure.    A newline or blank can follow the
  65.      procedure name:
  66.  
  67.      foo.c bar (everything else    following is ignored)
  68.  
  69.  
  70.      Lines beginning with # are    comments, lines    beginning with $
  71.      are considered cord directive lines. The only directive
  72.      currently understood is $phase.  This directive will con-
  73.      sider the rest of the file    (until the end of file or next
  74.      $phase) as    a new phase of the program and will order the
  75.      procedures    accordingly.  A    procedure may appear in    more than
  76.      one phase,    resulting in more than one copy    of it in the
  77.      final binary.  First, cord    will try to relocate procedure
  78.      references    to a copy of the procedure belonging to    the
  79.      requesting    phase; otherwise it will relocate the references
  80.      to    a random copy.
  81.  
  82.      We    suggest    you use    the -cord option to a compiler driver
  83.      like cc(1)    rather than execute cord directly.  cord options
  84.      can be specified with -Wz,cordarg0,cordarg1,....  If you
  85.      have to run cord by hand, you may want to run it once with
  86.      the driver    using the -v flag on a simple program.    This will
  87.      enable you    to see the exact passes    and the    arguments
  88.      involved in using cord.
  89.  
  90.      Obj is an executable object file with its relocation infor-
  91.      mation intact. This can be    achieved by passing the    -r -z -d
  92.  
  93.  
  94.  
  95.              Printed 4/3/91               Page    1
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102. CORD(1-SysV)        RISC/os Reference Manual         CORD(1-SysV)
  103.  
  104.  
  105.  
  106.      options to    the linker, ld(1).  The    linker option -r main-
  107.      tains relocation information in the object    file, but will
  108.      not make it a ZMAGIC file (hence -z).  It also will not
  109.      allocate common variables (hence -d) as it    would without the
  110.      option.
  111.  
  112.      WARNING: Since cord works from an input list of procedures
  113.      generated from profile output, the    resulting binary is data
  114.      dependent.     In other words, it may    only preform well on the
  115.      same input    data that generated the    profile    information, and
  116.      may preform worse than the    original binary    on other data.
  117.      Furthermore, if the hot areas in the cache    don't fit well
  118.      into one cachepage, performance can degrade.
  119.  
  120.      The cord command accepts these options:
  121.  
  122.       -v   Print verbose information.  This    includes listing
  123.            those procedures    considered part    of other pro-
  124.            cedures and cannot be rearranged    (these are basi-
  125.            cally assembler procedures that may contain rela-
  126.            tive branches to    other procedures rather    than
  127.            relocatable ones).  The listing also lists those
  128.            procedures in the flipped area (if any) and a map-
  129.            ping of old location to new.
  130.  
  131.       -f   Flip the    first cachepage    size procedures.  The
  132.            assumption when cord was    written    was that pro-
  133.            cedures would be    reordered by procedure density
  134.            (cycles/byte).  This option ensures that    the den-
  135.            sest part of each page following    the first
  136.            cachepage would conflict    with the least-dense part
  137.            of the first cachepage.
  138.  
  139.       -c cachesize
  140.            Specify the cachesize (in bytes)    of the machine on
  141.            which you want to execute.  This    only affects the
  142.            -f option.  If not specified, 65536 is used.
  143.  
  144.       -o outputfile
  145.            Specifies the output file. If not specified, a.out
  146.            is used.
  147.  
  148.       -p phasemax
  149.            specifies the maximum number phases allowed. The
  150.            default is 20.
  151.  
  152. SEE ALSO
  153.      cc(1), ftoc(1), ld(1), prof(1).
  154.      RISCompiler and C Programmer's Guide
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  Page 2             Printed 4/3/91
  162.  
  163.  
  164.  
  165. -- 
  166. Charlie Price    cprice@mips.mips.com        (408) 720-1700
  167. MIPS Technology Inc. / 928 Arques Ave.  MS 1-03 / Sunnyvale, CA   94088-3650
  168.