]> git.sur5r.net Git - cc65/blobdiff - doc/coding.sgml
Added a sentence about unnamed labels
[cc65] / doc / coding.sgml
index 911b77422aae4605c276331eff83f157634784c9..fb49574300d8ac4d970fcf9ef6ecc78e0e8784a0 100644 (file)
@@ -109,11 +109,11 @@ if you don't help. Look at this example:
       i = i + OFFS + 3;
 </verb></tscreen>
 
-The expression is parsed from left to right, that means, the compiler sees
-'i', and puts it contents into the secondary register. Next is OFFS, which is
+The expression is parsed from left to right, that means, the compiler sees 'i',
+and puts it contents into the secondary register. Next is OFFS, which is 
 constant. The compiler emits code to add a constant to the secondary register.
-Same thing again for the constant 3. So the code produced contains a fetch of
-'i', two additions of constants, and a store (into 'i'). Unfortunately, the
+Same thing again for the constant 3. So the code produced contains a fetch 
+of 'i', two additions of constants, and a store (into 'i'). Unfortunately, the
 compiler does not see, that "OFFS + 3" is a constant for itself, since it does
 it's evaluation from left to right. There are some ways to help the compiler
 to recognize expression like this:
@@ -132,14 +132,6 @@ and reduce the code to one fetch, one addition and one store.
 </enum>
 
 
-<sect>Case labels in a switch statments are checked in source order<p>
-
-Labels that appear first in a switch statement are tested first. So, if your
-switch statement contains labels that are selected most of the time, put them
-first in your source code. This will speed up the code.
-
-
-
 <sect>Use the preincrement and predecrement operators<p>
 
 The compiler is not always smart enough to figure out, if the rvalue of an
@@ -242,7 +234,7 @@ The latter will work, but will create larger and slower code.
 
 
 
-<sect>When using the <tt/?:/ operator, cast values that are not ints<p>
+<sect>When using the ternary operator, cast values that are not ints<p>
 
 The result type of the <tt/?:/ operator is a long, if one of the second or
 third operands is a long. If the second operand has been evaluated and it was
@@ -316,12 +308,15 @@ easy to see, that - apart from the additional code that is needed to save and
 restore the values - you need to make heavy use of a variable to justify the
 overhead.
 
-An exception are pointers, especially char pointers. The optimizer has code to
-detect and transform the most common pointer operations if the pointer
-variable is a register variable. Declaring heavily used character pointers as
-register may give significant gains in speed and size.
+As a general rule: Use register variables only for pointers that are
+dereferenced several times in your function, or for heavily used induction
+variables in a loop (with several 100 accesses).
+
+When declaring register variables, try to keep them together, because this
+will allow the compiler to save and restore the old values in one chunk, and
+not in several.
 
-And remember: Register variables must be enabled with <tt/-Or/.
+And remember: Register variables must be enabled with <tt/-r/ or <tt/-Or/.
 
 
 
@@ -373,7 +368,7 @@ instead will give shorter and faster code.
 Since cc65 has the "wrong" calling order, the location of the fixed parameters
 in a variadic function (a function with a variable parameter list) depends on
 the number and size of variable arguments passed. Since this number and size
-is unknown at compiler time, the compiler will generate code to calculate the
+is unknown at compile time, the compiler will generate code to calculate the
 location on the stack when needed.
 
 Because of this additional code, accessing the fixed parameters in a variadic