Re: C code .vs. Assembly code for Microcontrollers/DSPs ?

cdg@nullstone.com (Christopher Glaeser)
16 Mar 1996 00:01:10 -0500

          From comp.compilers

Related articles
[22 earlier articles]
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? rfg@monkeys.com (1996-03-14)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? sberg@camtronics.com (1996-03-14)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? bobduff@world.std.com (1996-03-14)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? bobduff@world.std.com (1996-03-14)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? john.r.strohm@BIX.com (1996-03-15)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? cdg@nullstone.com (1996-03-15)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? cdg@nullstone.com (1996-03-16)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? dan@watson.ibm.com (1996-03-16)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? stefan.monnier@lia.di.epfl.ch (Stefan Monnier) (1996-03-16)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? albaugh@agames.com (1996-03-16)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? preston@cs.rice.edu (1996-03-17)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? elvey@hal.com (1996-03-17)
Re: C code .vs. Assembly code for Microcontrollers/DSPs ? john.gilliver@gecm.com (1996-03-20)
[33 later articles]
| List of all articles for this month |
From: cdg@nullstone.com (Christopher Glaeser)
Newsgroups: comp.compilers
Date: 16 Mar 1996 00:01:10 -0500
Organization: Compilers Central
References: 96-03-006 96-03-091
Keywords: C, performance

> [Do people really not use const and static? -John]


1) const - Granted, const is useful in situations where you want to
inhibit stores and isolate potential errors at compile time. However,
using const as a replacement for constant macros has performance
penalties for many C compilers. In particular, many C compilers will
load the value of "one" in the example below, rather than use the
value "1".


#define ONE 1
                const int one = 1;


int f()
                {
                    x = ONE;
                    y = one;
                }


2) static - Static can cause significant performance problems for many
C compilers. In particular, few C compilers can keep static variables
in registers over a region of code. This is most notable when using
f2c to benchmark C compilers with FORTRAN benchmarks. Consider the
following code fragment.


            SUBROUTINE F()
            INTEGER I
            DO 10 I = 1, 100
  10 CONTINUE
            RETURN
            END


f2c gnerates the following output.


int f_()
{
static integer i;


for (i = 1; i <= 100; ++i) { }
                    return 0;
}


Benchmarks such as Livermore Loops run about three times slower when
these variables are delcared static (versus auto) for compilers that
can not keep static variables in registers.


Static inhibits many other optimizations as well. Consider:


x = a + b;
y = a + b;


Some compilers will eliminate the CSE if a and b are auto, but will
not eliminate the CSE if a or b are static.


Regards,
Christopher Glaeser cdg@nullstone.com
Nullstone Corporation http://www.nullstone.com
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.