![]() |
||
| Home | SwiftForth Archive | SwiftX Archive | |

SF Talk wrote:
>
> Date: Wed, 26 Jan 2000 11:11:41 +0100
> From: "Charles Melice" <mail_at_forthcad.com>
> Subject: About optimization
>
> Using SEE, I see the code produced remain far too be optimal.
>
> : DUP* ( n -- n*n ) DUP * ; ok
>
> see dup*
>
> 45992B 4 # EBP SUB 83ED04
> 45992E EBX 0 [EBP] MOV 895D00
> 459931 0 [EBP] EAX MOV 8B4500
> 459934 EBX EAX MUL F7E3
> 459936 EAX EBX MOV 8BD8
> 459938 4 # EBP ADD 83C504
> 45993B RET
>
> Is it possible to optimize at the produced code level ? For instance:
>
> A. Create a minimal not optimized Forth system, that compile in real memory, and produce pseudo-token in a tempory memory.
>
> B. On end of definition, optimize the tempory memory, and replace the optimized code in real memory. Refresh DP.
>
> To optimize, use a small expert system, writed in ANS Forth. This system should be initialy empty. When porting a Forth-system, we
> enter specifics processor informations in the expert-optimizer:
>
> : DUP* ( n -- n*n ) DUP * ; ok -- the expert analis --
>
> 45992B 4 # EBP SUB SUB SP, 4
> 45992E EBX 0 [EBP] MOV MOV [SP], EBX
> 459931 0 [EBP] EAX MOV MOV EAX, [SP]
> 459934 EBX EAX MUL MUL EAX, EBX
> 459936 EAX EBX MOV MOV EBX, EAX
> 459938 4 # EBP ADD ADD SP, 4
> 45993B RET RET
>
> SUB SP, 4
Please, not in my code! I've seen too many systems "mysteriously" crash
when interrupted while the stack pointer was "temporarily" altered.
These are particularly hard bugs to find because they aren't
reproducible. It is small saving to declare a critical section in order
to optimize this way.
> MOV [SP], EBX
> MOV EAX, [SP]
> MUL EAX, EBX |
> MOV EBX, EAX | MUL EBX, EAX ; "MUL commutative"
> ADD SP, 4
> RET
>
> SUB SP, 4
> MOV [SP], EBX |
> MOV EAX, [SP] | MOV EAX, EBX ; "unnecessary [SP] transit"
> MUL EBX, EAX
> ADD SP, 4
> RET
>
> SUB SP, 4 | -
> MOV EAX, EBX | .
> MUL EBX, EAX | .
> ADD SP, 4 | - ; "unaffected stack-balance in the scope"
> RET
>
> MOV EAX, EBX
> MUL EBX, EAX
> RET
>
> And because the final result is small, why not to mark INLINABLE the resulting definition ?
>
> Just a probably common idea, but perhaps a too big project.
>
> Charles
>
Jerry
-- Engineering is the art of making what you want from things you can get. ----------------------------------------------------------------------- .Received on Wed Jan 26 2000 - 12:13:42 PST
This archive was generated by hypermail 2.2.0 : Thu Nov 20 2008 - 03:04:27 PST