💾 Archived View for mirrors.apple2.org.za › archive › apple.cabi.net › FAQs.and.INFO › optimize.doc.… captured on 2023-01-29 at 04:29:40.

View Raw

More Information

-=-=-=-=-=-=-

    Finally, these programs have arrived.  The list of optimizable code
sequences brought to my attention has finally grown large enough that I
have expanded beyond just the control-point optmizations of previous
versions of jump.c.  Included in this file are the 3.0 version of Jump.c,
the 1.0 version of Loop.c, and the 1.2 version of Gen.c.  Each of these
programs does its own series of optimizations.
    Gen.c is a general optimizer.  It looks at increment statements, push
statements, variable references in memory, and a few others to decide if
redundant memory references are being made, unnecessary arithmetic is
being performed and the results thrown away, etc.  It makes a single pass
through the code.  It's pretty quick.  2 minutes is enough for it to optimize
even a 20-25K source file.  It's really spotty about how well it improves the
code, and unless you do a lot of post-incrementng on your variables, you're
unlikely to see a huge benefit from it.  However, the optimizations performed
by Loop.c can sometimes be improved by optimizations done here.
    Jump.c checks the control-transfer statements of a program to see when
they could be made more efficient.  Example.c, included here, shows how
to avoid many of these problems in C source code.  Re-coding all of the
control structures affected may not be the best choice, however.  The clarity
of the source code may be affected by these changes, or the programmer may just
not be willing to do it.  If the compiler were better, he wouldn't.. :)  This
program allows more freedom of expression while still keeping code production
good.  It's also fairly fast, though multi-pass.  This multi-pass-ness has
one major implication to placing it in your CC script:  The source file and
destination file of this program must be in the same directory.
    Loop.c checks the initialization statements of loops to see if they
can be optimized.  It's more effective when used on code containing for()
loops than while() loops.  However, it is a great way to waste CPU time.
To optimize the ~20K of assembly source produced by Andy Tefft's robots(1)
package took over an hour raw, and still over 50 minutes after Gen.c and
Jump.c had made their improvements beforehand.  The major reason that this
was not included in the Jump3.0 release was this computational time.  The
other programs in my test suite were not nearly so intense, but even Diff.c
and Syntax.c took about 10 minutes apeice.
    It is suggested that these three programs be run as a set:
    1) Gen.c, 2) Jump.c, 3) Loop.c, and 4) Gen.c in a final pass.
If you do not program using post-increment, then you could likely do about as
well with only the final 3 passes.
    As always, comments and bug reports are welcome, although I do not promise
any action upon them.

    Anthony J. Stuckey,
    Nov. 7, 1993.