[fpc-pascal] CASE

Paul Davidson pdavidson at coraxnetworks.com
Tue Nov 8 17:48:23 CET 2005


On Nov 8, 2005, at 11:39, Eduardo wrote:

> 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:
>
Not this

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

This :)

> 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.
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
>

Was under the impression that doing a jump, offset by label number, 
would be faster.  Specially for such long case statements.

P Davidson
http://CoraxNetworks.com




More information about the fpc-pascal mailing list