Fixed up support for the gbz80 such that it will at least run (and fail badly) the...
[fw/sdcc] / doc / sdccman.html / node46.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2
3 <!--Converted with LaTeX2HTML 99.1 release (March 30, 1999)
4 original version by:  Nikos Drakos, CBLU, University of Leeds
5 * revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
6 * with significant contributions from:
7   Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
8 <HTML>
9 <HEAD>
10 <TITLE>5. TIPS</TITLE>
11 <META NAME="description" CONTENT="5. TIPS">
12 <META NAME="keywords" CONTENT="sdccman">
13 <META NAME="resource-type" CONTENT="document">
14 <META NAME="distribution" CONTENT="global">
15
16 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
17 <META NAME="Generator" CONTENT="LaTeX2HTML v99.1 release">
18 <META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
19
20 <LINK REL="STYLESHEET" HREF="sdccman.css">
21
22 <LINK REL="next" HREF="node48.html">
23 <LINK REL="previous" HREF="node38.html">
24 <LINK REL="up" HREF="sdccman.html">
25 <LINK REL="next" HREF="node47.html">
26 </HEAD>
27
28 <BODY >
29 <!--Navigation Panel-->
30 <A NAME="tex2html951"
31  HREF="node47.html">
32 <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A> 
33 <A NAME="tex2html945"
34  HREF="sdccman.html">
35 <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A> 
36 <A NAME="tex2html939"
37  HREF="node45.html">
38 <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A> 
39 <A NAME="tex2html947"
40  HREF="node1.html">
41 <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A> 
42 <A NAME="tex2html949"
43  HREF="node61.html">
44 <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A> 
45 <BR>
46 <B> Next:</B> <A NAME="tex2html952"
47  HREF="node47.html">5.1 Notes on MCS51</A>
48 <B> Up:</B> <A NAME="tex2html946"
49  HREF="sdccman.html">SDCC Compiler User Guide</A>
50 <B> Previous:</B> <A NAME="tex2html940"
51  HREF="node45.html">4.7 Cyclomatic Complexity</A>
52  &nbsp <B>  <A NAME="tex2html948"
53  HREF="node1.html">Contents</A></B> 
54  &nbsp <B>  <A NAME="tex2html950"
55  HREF="node61.html">Index</A></B> 
56 <BR>
57 <BR>
58 <!--End of Navigation Panel-->
59
60 <H1><A NAME="SECTION00060000000000000000">
61 5. TIPS</A>
62 </H1>
63
64 <P>
65 Here are a few guidelines that will help the compiler generate more
66 efficient code, some of the tips are specific to this compiler others
67 are generally good programming practice.
68
69 <P>
70
71 <UL>
72 <LI>Use the smallest data type to represent your data-value. If it is
73 known in advance that the value is going to be less than 256 then
74 use a 'char' instead of a 'short' or 'int'.</LI>
75 <LI>Use unsigned when it is known in advance that the value is not going
76 to be negative. This helps especially if you are doing division or
77 multiplication.</LI>
78 <LI>NEVER jump into a LOOP.</LI>
79 <LI>Declare the variables to be local whenever possible, especially loop
80 control variables (induction).</LI>
81 <LI>Since the compiler does not do implicit integral promotion, the programmer
82 should do an explicit cast when integral promotion is required.</LI>
83 <LI>Reducing the size of division, multiplication &amp; modulus operations
84 can reduce code size substantially. Take the following code for example.&nbsp;
85 <BR>&nbsp;
86 <BR>
87 <TT>foobar(unsigned int p1, unsigned char ch)</TT>&nbsp;
88 <BR>
89 <TT>{</TT>&nbsp;
90 <BR>
91  <TT>   unsigned char ch1 = p1 % ch ;</TT>&nbsp;
92 <BR>
93  <TT>   ....    </TT>&nbsp;
94 <BR>
95 <TT>}</TT>&nbsp;
96 <BR>
97
98 <BR>
99 For the modulus operation the variable ch will be promoted to unsigned
100 int first then the modulus operation will be performed (this will
101 lead to a call to support routine _muduint()), and the result will
102 be casted to an int. If the code is changed to 
103 <BR>&nbsp;
104 <BR>
105 <TT>foobar(unsigned int p1, unsigned char ch)</TT>&nbsp;
106 <BR>
107 <TT>{</TT>&nbsp;
108 <BR>
109  <TT>   unsigned char ch1 = (unsigned char)p1 % ch ;</TT>&nbsp;
110 <BR>
111  <TT>   ....    </TT>&nbsp;
112 <BR>
113 <TT>}</TT>&nbsp;
114 <BR>
115
116 <BR>
117 It would substantially reduce the code generated (future versions
118 of the compiler will be smart enough to detect such optimization oppurtunities).</LI>
119 </UL>
120
121 <P>
122 <BR><HR>
123 <!--Table of Child-Links-->
124 <A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A>
125
126 <UL>
127 <LI><A NAME="tex2html953"
128  HREF="node47.html">5.1 Notes on MCS51 memory layout</A>
129 </UL>
130 <!--End of Table of Child-Links-->
131 <HR>
132 <!--Navigation Panel-->
133 <A NAME="tex2html951"
134  HREF="node47.html">
135 <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next_motif.gif"></A> 
136 <A NAME="tex2html945"
137  HREF="sdccman.html">
138 <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up_motif.gif"></A> 
139 <A NAME="tex2html939"
140  HREF="node45.html">
141 <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="previous_motif.gif"></A> 
142 <A NAME="tex2html947"
143  HREF="node1.html">
144 <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents_motif.gif"></A> 
145 <A NAME="tex2html949"
146  HREF="node61.html">
147 <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index_motif.gif"></A> 
148 <BR>
149 <B> Next:</B> <A NAME="tex2html952"
150  HREF="node47.html">5.1 Notes on MCS51</A>
151 <B> Up:</B> <A NAME="tex2html946"
152  HREF="sdccman.html">SDCC Compiler User Guide</A>
153 <B> Previous:</B> <A NAME="tex2html940"
154  HREF="node45.html">4.7 Cyclomatic Complexity</A>
155  &nbsp <B>  <A NAME="tex2html948"
156  HREF="node1.html">Contents</A></B> 
157  &nbsp <B>  <A NAME="tex2html950"
158  HREF="node61.html">Index</A></B> 
159 <!--End of Navigation Panel-->
160 <ADDRESS>
161 <I>Johan Knol</I>
162 <BR><I>2001-07-13</I>
163 </ADDRESS>
164 </BODY>
165 </HTML>