Re: [fpc-pascal] CASE

2005-11-08 Thread Eduardo

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 
end;
or

case L3o3.FormType of
1 : begin 
 end
2 : begin 
 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?


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] CASE

2005-11-08 Thread Paul Davidson


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 
end;
or



This :)


case L3o3.FormType of
1 : begin 
 end
2 : begin 
 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@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

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] CASE

2005-11-08 Thread Eduardo



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.


This :)


case L3o3.FormType of
1 : begin 
 end
2 : begin 
 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.


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


Jump by offset label number? I don't understand it. 


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] CASE

2005-11-08 Thread Paul Davidson


Jump by offset label number? I don't understand it.
___
fpc-pascal maillist  -  fpc-pascal@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?


P Davidson
http://CoraxNetworks.com

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] CASE

2005-11-08 Thread Peter Vreman

At 04:42 8-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.


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?


Use 2.1.1


Peter

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] CASE

2005-11-08 Thread Paul Davidson


On Nov 8, 2005, at 12:11, Peter Vreman wrote:



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


Use 2.1.1


Peter

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal




version 2.1.1 [2005/11/08] for powerpc
Same result, Peter :|

P Davidson
http://CoraxNetworks.com

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] CASE

2005-11-08 Thread Eduardo

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


Jump by offset label number? I don't understand it.
___
fpc-pascal maillist  -  fpc-pascal@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...

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] CASE

2005-11-08 Thread Eduardo

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

Any hints?


Use 2.1.1


Peter


version 2.1.1 [2005/11/08] for powerpc
Same result, Peter :|

P Davidson


Perhaps this code can do the trick, but don't know if is easily 
integrable in fpc ppc codegenerator, you can adapt it a bit if you want


** IN r3 Value to check r29 branch lookup table r5 top/end r6 
low/begin r4 where to branch


SecuentialCase: lwzr3,VALUE // VALUE from TOC or BSS or other.
 subi   r29,r29,4  // Adjust 
value for access
  caseloop: lwzu  r4,4(r29)  // in address 
pointed by r29 begins the jump look-up table (L1051,L1052)
 mtctr r4// Move 
address in r4 to CTR special register. CTR has now the destiny address

 lwzr5,TOP // last value
 lwzr6,LOW// low value
 cmplwi   cr2,r3,r6   // compare if 
value with r6
 bcctr 12,10// BO = 12 
Branch if condition True. BI = 10 Condition flag Equal of cr2.

 addi   r6,r6,1  // r6 := r6 +1
 cmplwi   cr3,r5,r6   // is r6 > r5 ?
 blecr3,caseloop // Branch to 
caseloop if FALSE

 otherwise statement or branch to it

** OUT r29, r6 originals values are destroyed.  


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] CASE

2005-11-08 Thread Peter Vreman




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


Use 2.1.1


version 2.1.1 [2005/11/08] for powerpc
Same result, Peter :|


The 2.1.1 compiler contains code to generate jumptables for ppc, see 
powerpc/nppcset.pas. You'll have to debug the compiler to see why it 
doesn't use them.



Peter

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Compiling for DOS

2005-11-08 Thread Felipe Monteiro de Carvalho
Hello,

I am trying to compile a very simple app (hello world kind) for DOS or
even for the Windows 98 rescue disk.

My first attempts ended up with a "This program cannot be run in DOS mode".

On the FP IDE I see many targets, but I don´t know witch one to
compile against. I see a few possible targets:

* GO32 V2 DOS extender
* Win32 for i386
* WDOSX DOS extender
* Watcom compatible DOS extenders

Witch one should I compile against?? Win32 doesn´t work and GO32
claims it can´t find system unit.

Should I recompile FPC for GO32 in order to use it? What is the
difference between it and WDOX or Watcom??

One might wonder what the reason for compiling to DOS is? I happen to
have an 486 running ibm-dos in my house and I´d like to use my own
program to test the ISA Card I recently created, instead of the DEBUG
program.

thanks,
--
Felipe Monteiro de Carvalho
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Compiling for DOS

2005-11-08 Thread Tomas Hajny
Date sent:  Tue, 8 Nov 2005 20:16:47 -0200
From:   Felipe Monteiro de Carvalho <[EMAIL PROTECTED]>
To: FPC-Pascal users discussions 

Subject:[fpc-pascal] Compiling for DOS
Send reply to:  FPC-Pascal users discussions 





Hello,

> I am trying to compile a very simple app (hello world kind) for DOS or
> even for the Windows 98 rescue disk.
>
> My first attempts ended up with a "This program cannot be run in DOS
> mode".
>
> On the FP IDE I see many targets, but I don´t know witch one to
> compile against. I see a few possible targets:
>
> * GO32 V2 DOS extender
> * Win32 for i386
> * WDOSX DOS extender
> * Watcom compatible DOS extenders
>
> Witch one should I compile against?? Win32 doesn´t work and GO32
> claims it can´t find system unit.
>
> Should I recompile FPC for GO32 in order to use it? What is the
> difference between it and WDOX or Watcom??
>
> One might wonder what the reason for compiling to DOS is? I happen to
> have an 486 running ibm-dos in my house and I´d like to use my own
> program to test the ISA Card I recently created, instead of the DEBUG
> program.

Your best choice probably is GO32v2. However, as for any other
target, you need RTL compiled for the given target, the appropriate
binutils (as and ld) and the right configuration. If you can compile
on a Win 9x/ME machine (or even machine with plain DOS), the easiest
solution (not requiring you to play with configuration, proper setup
of directories, etc.) is to download the old 1.0.10 version, make
sure you don't have any other FPC version (Win32) in PATH and use
that one. Alternatively you could overwrite that one with a 2.0.x
snapshot (for GO32v2 target). There are other options too, but these
might be more complex (I believe some of them were discussed in our
GO32v2 forum).

If you encounter any difficulties, just ask.

Hopefully a DOS (GO32v2) version of FPC 2.x gets released with one of
the next releases.

Tomas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] CASE

2005-11-08 Thread Anton Tichawa

Paul Davidson wrote:



On Nov 8, 2005, at 12:11, Peter Vreman wrote:



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



Use 2.1.1


Peter

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal




version 2.1.1 [2005/11/08] for powerpc
Same result, Peter :|

P Davidson
http://CoraxNetworks.com

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


You could use an array of procedures. It's members are initialized once,

var my_table: array [0 .. 146] of procedure;

my_table[0] := @my_proc_0;
my_tyble[1] := @my_proc_1;
...

and the 'case' statement is simply replaced with

begin
 ..
 my_table[x];
 ..
end;

which is fast, because it performs no compare, but loads the procedure 
address from the array, indexed with x.


Anton.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] CASE

2005-11-08 Thread Marco van de Voort
> >>># [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?
> >>
> >>Use 2.1.1
> >
> >version 2.1.1 [2005/11/08] for powerpc
> >Same result, Peter :|
> 
> The 2.1.1 compiler contains code to generate jumptables for ppc, see 
> powerpc/nppcset.pas. You'll have to debug the compiler to see why it 
> doesn't use them.

Haven't really debugged, but there is an cs_optimize in aktmodeswitches
somewhere near where this code is called.

Paul: do you enable some -O parameter? Play with it etc.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal