[fpc-pascal] CASE

Eduardo nec556 at retena.com
Tue Nov 8 17:39:58 CET 2005


At 04:42 08/11/2005, you wrote:
>May be having case statement problem.
>
>App has case statement with 146 sequential labels.
>They are in order, from a defined type.
>The assembler output is scanning each label, where it seems a jump 
>would be more efficient.

I don't understand well what you have:

case L3o3.Formtype of
1,2,3,....,146 : begin <somecode>
                 end;
or

case L3o3.FormType of
1 : begin <somecode1>
      end
2 : begin <somecode2>
      end

and so on.....

For the second case the assemmbler code seems ok to me, also L1051 
L1052 L1053 looks like are different destinations. For the first, 
well, it can be optimized "a bit" by hand, but note that it's 
difficult to do in "automatic mode" by a compiler.

lwz           r2,160(r1)        // Load in r2 the value to compare
subi         r3,r2,145  // Change 145 with the top value. Don't need 
to record in cr0, so subi is used instead of subi. (with point)
cmplwi     cr3,r3,0     // Change 0 with the low value. So if 145-r2 
is greater or equal 0, it's between them or is one of them
bge          cr3,L1051  // branch to L1051. Use bge+ cr3,L1051 if you 
are sure that branch will be taken often

Note that cr3, is a condition register field and can be used by the 
compiler for other pourposes. This code only works with integer 
values 0 < r2 < 65535, perhaps also works with chars. If you know 
that the condition is true (r2 is between 0 and 145 often), you can 
use the '+' format of the branch.

The code may not work, i'm writing it by memory.

>ppc 32, Darwin
>/usr/local/bin/ppcppc cape80.pas -Ci -Co -g -gl -O1 -vr -a -al 
>-FEbuild/cape80.build/cape80.build -ocape80
>
>Also tried -O2 and 3
>
>Result:
>
># [735] case l3o3.FormType of
>  // Select 3o3 processor
>         lwz     r2,160(r1)
>         cmplwi  cr0,r2,0
>         beq     cr0,L1051
>         cmplwi  cr0,r2,1
>         beq     cr0,L1052
>         cmplwi  cr0,r2,2
>         beq     cr0,L1053
>         cmplwi  cr0,r2,3
>         beq     cr0,L1054
>
>etc.
>
>Any hints?




More information about the fpc-pascal mailing list