|register variables in C. firstname.lastname@example.org (1992-04-22)|
|re: register variables in C email@example.com (1992-04-23)|
|From:||firstname.lastname@example.org (Tom Wicklund)|
|Keywords:||C, optimize, registers|
|Date:||Thu, 23 Apr 1992 18:23:25 GMT|
>From experience using a number of PC compilers, I found that having the
compiler automatically place most used variables in registers resulted in
a larger gain in performance than most other optimizations. This involved
Turbo C, which has two simple optimizations -- remembering when a simple
variable is in a register and automatically enregistering two local
variables. Those two optimizations along with fairly good code generation
(e.g. fairly full use of the instruction set) resulted in performance
comparable to compilers which used register coloring, common subexpression
elimination, etc. but didn't automatically put variables in registers.
Turbo C's simple algorithm chose the correct 2 variables in almost every
There are few cases where the programmer can do a better job than the
compiler, but most programmers add register keywords when initially
writing code and then don't update them as changes are made, so that the
manual decisions often become wrong with time.
It's probably best to let the compiler do the work and manually optimize
only in the code where performance really matters (since most programs
follow the general 80% of the time is spent in 20% of the code rule).
[The '86 series has such a small and irregular register set that I can
easily believe that graph coloring, which was designed for large and mostly
regular register sets, doesn't work well. -John]
Return to the
Search the comp.compilers archives again.