[fpc-pascal] CASE

Eduardo nec556 at retena.com
Tue Nov 8 19:03:48 CET 2005


At 18:07 08/11/2005, you wrote:

>>Jump by offset label number? I don't understand it.
>>_______________________________________________
>>fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
>>http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>>
>
>Sorry Eduardo, am not knowledgeable of compiler internals.
>There is (?) an optimization in FPC that uses a jump table(?) 
>instead of scanning each label value of a case statement.  Hoping 
>that this is the case, as it seems to be with i386.  This would mean 
>faster execution of the case.  Yes?

Don't know how fpc ppc works internally. Surely this optimization is 
not done, it's uncommon, i think.

For now, the only optimization to the compiler output maybe use other 
crs for comparations and separate the branch from the comparation to 
prevent stalls. Here an example.

Original code

# [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

Modified code

# [735] case l3o3.FormType of
  // Select 3o3 processor
         lwz     r3,160(r1)     // r3, has the value to check
         cmplwi  cr0,r3,0
         cmplwi  cr2,r3,1        // cr1 is used for fpu condition and 
cannot be used for integer
         cmplwi  cr3,r3,2
         cmplwi  cr4,r3,3
         beq     cr0,L1051    // separate branch from comp (4 lines 
up) can make the branch be pre-calculated and executed in zero cycles
         cmplwi  cr5,r3,4
         beq     cr2,L1052
         cmplwi  cr0,r3,5
         beq     cr3,L1053
         cmplwi  cr2,r3,6
         beq     cr4,L1054

and so on...




More information about the fpc-pascal mailing list