About optimization

From: Charles Melice <mail_at_forthcad.com>
Date: Wed, 26 Jan 2000 11:11:41 +0100

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

.
Received on Wed Jan 26 2000 - 11:11:41 PST


Subscribe to our e-mail list service. It's free for all SwiftForth and SwiftX users!

This archive was generated 09-Feb-2012. Archive updated nightly.