166 lines
5.3 KiB
HTML
166 lines
5.3 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
|
|
|
<!--Converted with LaTeX2HTML 99.1 release (March 30, 1999)
|
|
original version by: Nikos Drakos, CBLU, University of Leeds
|
|
* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan
|
|
* with significant contributions from:
|
|
Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>5. TIPS</TITLE>
|
|
<META NAME="description" CONTENT="5. TIPS">
|
|
<META NAME="keywords" CONTENT="sdccman">
|
|
<META NAME="resource-type" CONTENT="document">
|
|
<META NAME="distribution" CONTENT="global">
|
|
|
|
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
|
|
<META NAME="Generator" CONTENT="LaTeX2HTML v99.1 release">
|
|
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
|
|
|
|
<LINK REL="STYLESHEET" HREF="sdccman.css">
|
|
|
|
<LINK REL="next" HREF="node48.html">
|
|
<LINK REL="previous" HREF="node38.html">
|
|
<LINK REL="up" HREF="sdccman.html">
|
|
<LINK REL="next" HREF="node47.html">
|
|
</HEAD>
|
|
|
|
<BODY >
|
|
<!--Navigation Panel-->
|
|
<A NAME="tex2html951"
|
|
HREF="node47.html">
|
|
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A>
|
|
<A NAME="tex2html945"
|
|
HREF="sdccman.html">
|
|
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A>
|
|
<A NAME="tex2html939"
|
|
HREF="node45.html">
|
|
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A>
|
|
<A NAME="tex2html947"
|
|
HREF="node1.html">
|
|
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A>
|
|
<A NAME="tex2html949"
|
|
HREF="node61.html">
|
|
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A>
|
|
<BR>
|
|
<B> Next:</B> <A NAME="tex2html952"
|
|
HREF="node47.html">5.1 Notes on MCS51</A>
|
|
<B> Up:</B> <A NAME="tex2html946"
|
|
HREF="sdccman.html">SDCC Compiler User Guide</A>
|
|
<B> Previous:</B> <A NAME="tex2html940"
|
|
HREF="node45.html">4.7 Cyclomatic Complexity</A>
|
|
  <B> <A NAME="tex2html948"
|
|
HREF="node1.html">Contents</A></B>
|
|
  <B> <A NAME="tex2html950"
|
|
HREF="node61.html">Index</A></B>
|
|
<BR>
|
|
<BR>
|
|
<!--End of Navigation Panel-->
|
|
|
|
<H1><A NAME="SECTION00060000000000000000">
|
|
5. TIPS</A>
|
|
</H1>
|
|
|
|
<P>
|
|
Here are a few guidelines that will help the compiler generate more
|
|
efficient code, some of the tips are specific to this compiler others
|
|
are generally good programming practice.
|
|
|
|
<P>
|
|
|
|
<UL>
|
|
<LI>Use the smallest data type to represent your data-value. If it is
|
|
known in advance that the value is going to be less than 256 then
|
|
use a 'char' instead of a 'short' or 'int'.</LI>
|
|
<LI>Use unsigned when it is known in advance that the value is not going
|
|
to be negative. This helps especially if you are doing division or
|
|
multiplication.</LI>
|
|
<LI>NEVER jump into a LOOP.</LI>
|
|
<LI>Declare the variables to be local whenever possible, especially loop
|
|
control variables (induction).</LI>
|
|
<LI>Since the compiler does not do implicit integral promotion, the programmer
|
|
should do an explicit cast when integral promotion is required.</LI>
|
|
<LI>Reducing the size of division, multiplication & modulus operations
|
|
can reduce code size substantially. Take the following code for example.
|
|
<BR>
|
|
<BR>
|
|
<TT>foobar(unsigned int p1, unsigned char ch)</TT>
|
|
<BR>
|
|
<TT>{</TT>
|
|
<BR>
|
|
<TT> unsigned char ch1 = p1 % ch ;</TT>
|
|
<BR>
|
|
<TT> .... </TT>
|
|
<BR>
|
|
<TT>}</TT>
|
|
<BR>
|
|
|
|
<BR>
|
|
For the modulus operation the variable ch will be promoted to unsigned
|
|
int first then the modulus operation will be performed (this will
|
|
lead to a call to support routine _muduint()), and the result will
|
|
be casted to an int. If the code is changed to
|
|
<BR>
|
|
<BR>
|
|
<TT>foobar(unsigned int p1, unsigned char ch)</TT>
|
|
<BR>
|
|
<TT>{</TT>
|
|
<BR>
|
|
<TT> unsigned char ch1 = (unsigned char)p1 % ch ;</TT>
|
|
<BR>
|
|
<TT> .... </TT>
|
|
<BR>
|
|
<TT>}</TT>
|
|
<BR>
|
|
|
|
<BR>
|
|
It would substantially reduce the code generated (future versions
|
|
of the compiler will be smart enough to detect such optimization oppurtunities).</LI>
|
|
</UL>
|
|
|
|
<P>
|
|
<BR><HR>
|
|
<!--Table of Child-Links-->
|
|
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A>
|
|
|
|
<UL>
|
|
<LI><A NAME="tex2html953"
|
|
HREF="node47.html">5.1 Notes on MCS51 memory layout</A>
|
|
</UL>
|
|
<!--End of Table of Child-Links-->
|
|
<HR>
|
|
<!--Navigation Panel-->
|
|
<A NAME="tex2html951"
|
|
HREF="node47.html">
|
|
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A>
|
|
<A NAME="tex2html945"
|
|
HREF="sdccman.html">
|
|
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A>
|
|
<A NAME="tex2html939"
|
|
HREF="node45.html">
|
|
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A>
|
|
<A NAME="tex2html947"
|
|
HREF="node1.html">
|
|
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A>
|
|
<A NAME="tex2html949"
|
|
HREF="node61.html">
|
|
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A>
|
|
<BR>
|
|
<B> Next:</B> <A NAME="tex2html952"
|
|
HREF="node47.html">5.1 Notes on MCS51</A>
|
|
<B> Up:</B> <A NAME="tex2html946"
|
|
HREF="sdccman.html">SDCC Compiler User Guide</A>
|
|
<B> Previous:</B> <A NAME="tex2html940"
|
|
HREF="node45.html">4.7 Cyclomatic Complexity</A>
|
|
  <B> <A NAME="tex2html948"
|
|
HREF="node1.html">Contents</A></B>
|
|
  <B> <A NAME="tex2html950"
|
|
HREF="node61.html">Index</A></B>
|
|
<!--End of Navigation Panel-->
|
|
<ADDRESS>
|
|
<I>Johan Knol</I>
|
|
<BR><I>2001-07-13</I>
|
|
</ADDRESS>
|
|
</BODY>
|
|
</HTML>
|