optimize method ? 
Author Message
 optimize method ?

Where can find the information of   optimize  method  about forth code ?
Thanks .


Sat, 07 Feb 2004 01:08:19 GMT  
 optimize method ?

Quote:

> Where can find the information of optimize method about forth code ?

There is no single optimization method for Forth.

Traditional threaded Forth systems were optimized by using
a simple built in assembler to CODE the words that take
up most of the time when the application is profiled.
Usually optimizing the application was optimizing a
few words from their threaded Forth versions into
assembler versions with exactly the same functionality.

There are simple pin-hole optimizing compilers for
Forth which make certain improvements in compiled
code.  For instance, + can check to see if constants
and literals are being added and it can do this at
compile time instead of compiling code to do it
at runtime.


might compile to the equivalent of


and compiling DROP after DUP might simply remove
the DROP.

Some Forth optimizers inline some things in native
machine code and compile subroutine calls for other
instructions.  Some have rules for how certain
opcodes can be combined, or how some sequences can
be replaced with better sequences of opcodes.  

More sophisticated optimizing native code compilers
do more.  There is really no upper limit to what
can be done and one of the next steps is judicious
register allocation.  There are PD versions that have
documentation and source code and there are commercial
versions available with or without source.

Since there is no single standard way of doing it,
you will have to check the specifics of Forth
code optimizers.  You can download versions of
VFX and SwiftForth for instance and compile some
code and examine it to see just what optimization
tricks were done.  You will also find some links
to papers about different optimization techniques
that various people are using.



Sat, 07 Feb 2004 02:46:25 GMT  
 optimize method ?

Quote:


> > Where can find the information of optimize method about forth code ?

> There is no single optimization method for Forth.

> Traditional threaded Forth systems were optimized by using
> a simple built in assembler to CODE the words that take
> up most of the time when the application is profiled.
> Usually optimizing the application was optimizing a
> few words from their threaded Forth versions into
> assembler versions with exactly the same functionality.

I have no experience in writing optimized Forth compiler (but
actually try to understand some mechanism). so I ask
about the benefits of native optimzed code, compared to
the method which you have mentioned above.

as I think, the most performance boost will be archived
by a well thought design (optimized problem). some years
ago (in the old i386sx days) I have written a larger C
program with a function which has consumed 99% of CPU time.
as the function would be called very often I have done
two improvements

1. cached the answer by the caller and therefor reduced
   the number of calls to this slow function
2. optimzed the slow function only be recoding it for
   better performance (instead of using assembler)

after these two steps no more optimizing was needed anymore.

--
Andreas Klimas



Sat, 07 Feb 2004 17:59:15 GMT  
 optimize method ?

Quote:

> Since there is no single standard way of doing it,
> you will have to check the specifics of Forth
> code optimizers.  You can download versions of
> VFX and SwiftForth for instance and compile some
> code and examine it to see just what optimization
> tricks were done.

SwiftForth does very tricky optimizations which
leads to very fast code. it's easy to figure out
what optimiziation is going on (define a word
and have a look to the produced code by see <word>).

--
Andreas Klimas



Sat, 07 Feb 2004 18:22:12 GMT  
 optimize method ?

Quote:


> > Where can find the information of optimize method about forth code ?

> Some Forth optimizers inline some things in native
> machine code and compile subroutine calls for other
> instructions.  Some have rules for how certain
> opcodes can be combined, or how some sequences can
> be replaced with better sequences of opcodes.  

  My optimizer works so. It replace the last fragment of a code.
Buffer of the references on a code is exists for distinguish
a code from operands. This the most correct way. It provides
independence of a optimization from a compilation.
It permits to program as if the optimization was not.

Quote:
> More sophisticated optimizing native code compilers
> do more.  There is really no upper limit to what
> can be done and one of the next steps is judicious
> register allocation.

  My optimize method is quite enough. It is necessary only
to use more abstraction rule for code replacement. Forth
can compile the most effective code.

Quote:
> There are PD versions that have
> documentation and source code and there are commercial
> versions available with or without source.

  My optimizer with source code.
 Last UpSPF4M6.rar in http://maksimov435.rtc.neva.ru/
 I do not know other.

Quote:
> You can download versions of
> VFX and SwiftForth for instance and compile some
> code and examine it to see just what optimization
> tricks were done.

 As I have realized, VFX use a special stack during compilation.
For many words instead of compilation the special program is
working with these stack. This way imposes the specific
requirements to management of compilation.Compilation of new
words is not optimized. I think, SwiftForth is too.


Sat, 07 Feb 2004 21:41:11 GMT  
 optimize method ?


Quote:
>I have no experience in writing optimized Forth compiler (but
>actually try to understand some mechanism). so I ask
>about the benefits of native optimzed code, compared to
>the method which you have mentioned above.

In smaller scale embedded systems, the rule of 90% of time
in 10% of the code is usually true. In larger systems, there
exist much more distributed algorithms/processes for which
overall execution speed is important. Many TCP/IP
implementations are an example of this. In such cases,
using an optimising compiler permits you to use a high
level language for all of the code. In our PowerNet
stack, the only routines which is usually coded are
the Internet checksum and an aligned block move.

Stephen
--

MicroProcessor Engineering Ltd - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
web: http://www.mpeltd.demon.co.uk - free VFX Forth downloads



Sat, 07 Feb 2004 21:10:12 GMT  
 optimize method ?

Quote:

> 1. cached the answer by the caller and therefor reduced
>    the number of calls to this slow function
> 2. optimzed the slow function only be recoding it for
>    better performance (instead of using assembler)

> after these two steps no more optimizing was needed anymore.

I talked about traditional optimization to by using
a few CODEd words, and the various optimizing techniques
used inside of various optimzing compilers.

I didn't talk about optimizations by the programmer
in the design.  Those are of course where the biggest
benefits are usually found.  Substituting a better
algorithm, removing redundant things and making
a clean design are all things that can get more
dramatic results than what the optimzing compilers
do under the hood.

I learned a few tricks from Chuck over the years.  He
tends to try to push things back in time from
runtime to compile time, from compile time to edit
time, from edit time to design time.   The more
optimization that takes place earlier in time the
more dramatic the results.

In the old days my coding tricks were quite
limited to things like precomputed data and
code tables but one picks up more optimization
tricks along the way.



Sat, 07 Feb 2004 13:46:42 GMT  
 optimize method ?
One optimization technique that bears harping on is the one that Linus
Torvalds always harps on, optimize for the common case. My example will be
in C, but one of the beauties of the technique is that it is utterly
language-independant. The same thing works in unix shell, Perl, assembly,
whatever, proportional to the performance of the language in question.
Another beauty of optimizing for the common case is it frequently requires
human understanding of the problem, and can't be done for you by a
compiler or other automaton, thus keeping us all employed. It can also
simplify code.

The benchmark on Bagley's shootout page that resembles the unix wc word
counting utility is fastest, from what Bagley shows, in C. His top C
program is very clever. It does two adds in one using the high and low
halves of an int to count words and lines (or words and characters or
whatever) separately in the same add. By using a simpler algorithm, but
wrapping it with an early-out test on char > 32 (most non-whitespace, the
common case) I beat his #1 by about 20% on almost-normal text like the 386
docs, and it just so happens to beat Bagley's #1 by closer to 100% on his
test input file, which favors my common case. Here's mine...

.........................................................................
/* wc32.c

I early-out by hand on >32, which is more or less extraneous code from a
compiler's point of view, since compilers don't speak English.

There's probably a win to be had by saying whitespace < 33, which makes
more sense to me as well.

                                        Rick Hohensee   July 2001
                                        www.clienux.com
*/

#include <stdio.h>
#include <unistd.h>
char buff[4096];

main() {
unsigned int  bytes=0, words=0, lines=0, red=0, was_ink=0;
unsigned char * here, *end;
char c;
while (red = read (0, buff, 4096) ) {
        end = buff + red ;
        here = buff ;
        bytes+=red;
        while ( here < end)

                {
                c = *here;
                if ( c > 32 )
                        { was_ink ++ ;
                        here++;
                                continue ;
                        }
                if ( c == ' ' || c == '\n' || c == '\t' )
                        {
                        if (was_ink) words++ ;
                        was_ink=0 ;
                        if ( c == '\n' )        lines++ ;
                        here++;
                                continue;
                        }
                else    {
                        was_ink ++ ;
                        here++;
                                continue ;
                        }
                }
        }
printf("%d %d %d\n", lines, words, bytes);

Quote:
}

..........................................................................

The first test is totally extraneous from the point of view of a strict
derscription of the algorithm. The win for whitespace=(<33) is another 10%
or so. The code path for the common case is 9 instructions when the above
is compiled gcc -O3.

wc has been around for eons, and simpler code with a simple optimization
beats all the older versions, AFAIK.

Rick Hohensee
                                                www.clienux.com



Sun, 08 Feb 2004 00:21:55 GMT  
 optimize method ?

Quote:

> Where can find the information of   optimize  method  about forth code ?
> Thanks .

I have written a modification of the Win32Forth assembler
(it can be done for any assembler) that will translate simple
arithmetic expressions to highly optimized (floating point)
code sequences for the Pentium and related chips. It is available
on

        http://www.*-*-*.com/ .{*filter*}ia.edu/classes/551.jvn.fall01/

Look under "Forth system and example programs". It is flagged
as NEW.

--
Julian V. Noble
Professor of Physics

Galileo's Commandment:

   "Science knows only one commandment: contribute to science."
   -- Bertolt Brecht, "Galileo".



Sun, 08 Feb 2004 09:04:37 GMT  
 optimize method ?


Quote:
> As I have realized, VFX use a special stack during compilation.
>For many words instead of compilation the special program is
>working with these stack. This way imposes the specific
>requirements to management of compilation.
> Compilation of new words is not optimized.

I don't understand this sentence. New words *are* optimised.

Stephen
--

MicroProcessor Engineering Ltd - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
web: http://www.mpeltd.demon.co.uk - free VFX Forth downloads



Sun, 08 Feb 2004 06:06:39 GMT  
 optimize method ?

Quote:



> > As I have realized, VFX use a special stack during compilation.
> >For many words instead of compilation the special program is
> >working with these stack. This way imposes the specific
> >requirements to management of compilation.
> > Compilation of new words is not optimized.
> I don't understand this sentence. New words *are* optimised.

Maybe you should explain that/if VFX does some form of inlining,
and/or/that/if stackdiagrams are auto-constructed for user words.

-marcel



Sun, 08 Feb 2004 16:01:08 GMT  
 optimize method ?


Quote:



>> > As I have realized, VFX use a special stack during compilation.
>> >For many words instead of compilation the special program is
>> >working with these stack. This way imposes the specific
>> >requirements to management of compilation.

>> > Compilation of new words is not optimized.
>> I don't understand this sentence. New words *are* optimised.
>Maybe you should explain that/if VFX does some form of inlining,
>and/or/that/if stackdiagrams are auto-constructed for user words.

VFX Forth for Windows has four options:
  VFX code generator
  source inliner
  binary inliner
  call
Providing that initial compilation of a new word satisfies
certain conditions and the source inliner is turned on, the
new word is considered for source inlining when referenced.
If it satisfies these conditions, the reference to the new
word does not compile a call, but effectively re-runs the
source code for that word. ALL compilation through the
VFX code generator uses the compilation stack(s).

Thus, short definitions are usually automatically inlined
at the source level.

Stephen

--

MicroProcessor Engineering Ltd - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
web: http://www.mpeltd.demon.co.uk - free VFX Forth downloads



Sun, 08 Feb 2004 18:06:12 GMT  
 optimize method ?

Quote:



> > As I have realized, VFX use a special stack during compilation.
> >For many words instead of compilation the special program is
> >working with these stack. This way imposes the specific
> >requirements to management of compilation.

> > Compilation of new words is not optimized.
> I don't understand this sentence. New words *are* optimised.

  Example:
: XX 5 + ;
: YY 4 + ;
: ZZ XX YY ;

\ VFX

SEE SS

SS
( 00499118    83C305 )                ADD     EBX, 05
( 0049911B    83C304 )                ADD     EBX, 04
( 0049911E    C3 )                    NEXT,

 INLINE is made. But optimizer does not know what
to do with XX YY.

\ SPF4

SEE SS

55C330 8D4009           LEA     EAX , 9 [EAX]
55C333 C3               RET     NEAR
END-CODE

Optimizer works at a level of a machine code

 In some cases, INLINE in VFX is made with error.


: ZZ SWAP XX ;

SEE ZZ
( 0049930C    8B5B05 )                MOV     EBX, [EBX+05]
( 0049930F    C3 )                    NEXT,


About a error in local variable I have informed in

  The programming in machine codes is not allowable

: JMP> 0xE9 C, ' HERE CELL+ - , ; IMMEDIATE

: TST SWAP JMP> # ;



Sun, 08 Feb 2004 19:40:10 GMT  
 optimize method ?

Quote:
> Optimizer works at a level of a machine code

Ah, you're typing in definitions at the command line, right?  That caught me
for a while, too.  The source inliner does not work with such definitions,
because the source code for definitions is not stored in a file.  Put it in
a file, load it with INCLUDE, and then try disassembling your words.

(This is noted in the release notes, BTW.)

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



Mon, 09 Feb 2004 22:50:09 GMT  
 optimize method ?

Quote:

> > Optimizer works at a level of a machine code

> Ah, you're typing in definitions at the command line, right?  That caught me
> for a while, too.  The source inliner does not work with such definitions,
> because the source code for definitions is not stored in a file.  Put it in
> a file, load it with INCLUDE, and then try disassembling your words.

> (This is noted in the release notes, BTW.)

Whence loading goes has not significance.
It is possible to load with listing production.

spf4.exe ~mak/listing1.f S" tst.f" INCLUDED_L BYE

 The  tst.f file should not INCLUDE contain.
 If you will see that program was optimized not ideally
 then you write listing you like to see.
 And I'm inform that is necessary to add in optimizer
 for this purpose.



Tue, 10 Feb 2004 16:07:24 GMT  
 
 [ 18 post ]  Go to page: [1] [2]

 Relevant Pages 

1. class methods and optimizing

2. Optimizing programmer vs optimizing compiler (was: Re: Assembly vs c/c++)

3. accessing a instance method from a class method

4. How do I call a method from another method within the same class

5. Class methods vs Instance methods

6. Class method vs instance method???

7. Class method vs instance method???

8. Class methods in ab???.clw files and derived methods

9. "methods" method

10. same method as class and instance methods?

11. Getting method! for free from method

12. Kernet methods and IO methods

 

 
Powered by phpBB® Forum Software