Commit c8aedee0 authored by anton's avatar anton

added ekey etc.

updated performance in docs
parent 624d6bee
......@@ -25,11 +25,14 @@ siev bubble matrix fib machine and configuration
11.81 14.39 13.61 15.07 IBM/Cyrix-6x86 133MHz (P166+) 512K PB cache; gcc-2.7.2.1 -DFORCE_REG -DDIRECT_THREADED; gforth-0.3.0; ELF
12.08 11.90 11.06 12.09 Cyrix-6x86MX 166MHz (PR200) 512K PB Cache; gcc-2.7.2.1 -DFORCE_REG -DDIRECT_THREADED; gforth-0.3.0; ELF
29.89 35.42 26.96 34.59 i486 66MHz 256K cache; gcc-2.6.3 -DFORCE_REG -DDIRECT_THREADED; gforth-0.1beta; a.out
26.19 29.92 23.80 30.18 i486 66MHz 256K cache; gcc-2.95.1 -DFORCE_REG; gforth-0.4.9; ELF
39.50 45.91 36.73 44.90 i486 50MHz 256K cache; gcc-2.7.0 -DFORCE_REG -DDIRECT_THREADED; gforth-0.1beta
42.82 46.74 38.69 48.30 i486 50MHz 256K cache; gcc-2.7.0 -DFORCE_REG; gforth-0.1beta
2.14 3.11 3.20 3.96 21264 (Compaq XP 1000) 500MHz 4M cache; egcs-1.0.3+gas; gforth-0.4.0
2.03 2.91 3.45 4.39 21264 (Compaq XP 1000) 500MHz 4M cache; gcc-2.95.1 -mcpu=21164a -DFORCE_REG; gforth-0.4.9
3.09 3.24 2.39 3.42 21164A (Alpha,164LX) 600MHz 2M cache; gcc-2.7.2.1+gas; gforth-0.3.0
2.74 2.95 2.20 3.45 21164a (Alpha,164LX) 600MHz 2M cache; gcc-2.95.1 -mcpu=21164a -DFORCE_REG; gforth-0.4.9
3.7 3.8 2.8 4.1 21164A (Alpha,PC164) 500MHz 2M cache; gcc-2.7.2.1+as (Digital Unix); gforth-0.3.0
7.0 7.6 6.2 7.7 21064A (Alpha,Cabriolet) 300MHz 2M cache; gcc-2.7.2; gforth-0.2.0
......
......@@ -8751,9 +8751,6 @@ The following ANS Forth words are not currently supported by Gforth
(@pxref{ANS conformance}):
@code{EDITOR}
@code{EKEY}
@code{EKEY>CHAR}
@code{EKEY?}
@code{EMIT?}
@code{FORGET}
......@@ -8901,7 +8898,7 @@ ANS Forth System
@item providing the Exception word set
@item providing the Exception Extensions word set
@item providing the Facility word set
@item providing @code{MS} and @code{TIME&DATE} from the Facility Extensions word set
@item providing @code{EKEY}, @code{EKEY>CHAR}, @code{EKEY?}, @code{MS} and @code{TIME&DATE} from the Facility Extensions word set
@item providing the File Access word set
@item providing the File Access Extensions word set
@item providing the Floating-Point word set
......@@ -9653,7 +9650,12 @@ undefined OS errors produce a message with a strange number; e.g.,
@item encoding of keyboard events (@code{EKEY}):
@cindex keyboard events, encoding in @code{EKEY}
@cindex @code{EKEY}, encoding of keyboard events
Not yet implemented.
Keys corresponding to ASCII characters are encoded as ASCII characters.
Other keys are encoded with the constants \code{k-left}, \code{k-right},
\code{k-up}, \code{k-down}, \code{k-home}, \code{k-end}, \code{k1},
\code{k2}, \code{k3}, \code{k4}, \code{k5}, \code{k6}, \code{k7},
\code{k8}, \code{k9}, \code{k10}, \code{k11}, \code{k12}.
@item duration of a system clock tick:
@cindex duration of a system clock tick
......@@ -11168,7 +11170,11 @@ registers as well as a human, even with explicit register declarations;
e.g., Bernd Beuster wrote a Forth system fragment in assembly language
and hand-tuned it for the 486; this system is 1.19 times faster on the
Sieve benchmark on a 486DX2/66 than Gforth compiled with
@code{gcc-2.6.3} with @code{-DFORCE_REG}.
@code{gcc-2.6.3} with @code{-DFORCE_REG}. The situation has improved
with gcc-2.95 and gforth-0.4.9; now the most important virtual machine
registers fit in real registers (and we can even afford to use the TOS
optimization), resulting in a speedup of 1.14 on the sieve over the
earlier results.
@cindex Win32Forth performance
@cindex NT Forth performance
......@@ -11176,9 +11182,9 @@ Sieve benchmark on a 486DX2/66 than Gforth compiled with
@cindex ThisForth performance
@cindex PFE performance
@cindex TILE performance
However, this potential advantage of assembly language implementations
The potential advantage of assembly language implementations
is not necessarily realized in complete Forth systems: We compared
Gforth (direct threaded, compiled with @code{gcc-2.6.3} and
Gforth-0.4.9 (direct threaded, compiled with @code{gcc-2.95.1} and
@code{-DFORCE_REG}) with Win32Forth 1.2093, LMI's NT Forth (Beta, May
1994) and Eforth (with and without peephole (aka pinhole) optimization
of the threaded code); all these systems were written in assembly
......@@ -11194,7 +11200,7 @@ O'Heskin kindly provided the results for Win32Forth and NT Forth on a
Hendrix ported Eforth to Linux, then extended it to run the benchmarks,
added the peephole optimizer, ran the benchmarks and reported the
results.
We used four small benchmarks: the ubiquitous Sieve; bubble-sorting and
matrix multiplication come from the Stanford integer benchmarks and have
been translated into Forth by Martin Fraeman; we used the versions
......@@ -11205,12 +11211,12 @@ scaled by the time taken by Gforth (in other words, it shows the speedup
factor that Gforth achieved over the other systems).
@example
relative Win32- NT eforth This-
relative Win32- NT eforth This-
time Gforth Forth Forth eforth +opt PFE Forth TILE
sieve 1.00 1.39 1.14 1.39 0.85 1.58 3.18 8.58
bubble 1.00 1.31 1.41 1.48 0.88 1.50 3.88
matmul 1.00 1.47 1.35 1.46 0.74 1.58 4.09
fib 1.00 1.52 1.34 1.22 0.86 1.74 2.99 4.30
sieve 1.00 1.58 1.30 1.58 0.97 1.80 3.63 9.79
bubble 1.00 1.55 1.67 1.75 1.04 1.78 4.59
matmul 1.00 1.67 1.53 1.66 0.84 1.79 4.63
fib 1.00 1.75 1.53 1.40 0.99 1.99 3.43 4.93
@end example
You may be quite surprised by the good performance of Gforth when
......@@ -11222,10 +11228,10 @@ but costly method for relocating the Forth image: like @code{cforth}, it
computes the actual addresses at run time, resulting in two address
computations per @code{NEXT} (@pxref{Image File Background}).
Only Eforth with the peephole optimizer has a performance that is
comparable to Gforth. The speedups achieved with peephole optimization
of threaded code are quite remarkable. Adding a peephole optimizer to
Gforth should cause similar speedups.
Only Eforth with the peephole optimizer performs comparable to
Gforth. The speedups achieved with peephole optimization of threaded
code are quite remarkable. Adding a peephole optimizer to Gforth should
cause similar speedups.
The speedup of Gforth over PFE, ThisForth and TILE can be easily
explained with the self-imposed restriction of the latter systems to
......@@ -11239,19 +11245,20 @@ The performance of Gforth on 386 architecture processors varies widely
with the version of @code{gcc} used. E.g., @code{gcc-2.5.8} failed to
allocate any of the virtual machine registers into real machine
registers by itself and would not work correctly with explicit register
declarations, giving a 1.3 times slower engine (on a 486DX2/66 running
declarations, giving a 1.5 times slower engine (on a 486DX2/66 running
the Sieve) than the one measured above.
Note that there have been several releases of Win32Forth since the
release presented here, so the results presented above may have little
predictive value for the performance of Win32Forth today.
predictive value for the performance of Win32Forth today (results for
the current release on an i486DX2/66 are welcome).
@cindex @file{Benchres}
In @cite{Translating Forth to Efficient C} by M. Anton Ertl and Martin
Maierhofer (presented at EuroForth '95), an indirect threaded version of
Gforth is compared with Win32Forth, NT Forth, PFE, and ThisForth; that
version of Gforth is 2%@minus{}8% slower on a 486 than the direct
threaded version used here. The paper available at
version of Gforth is slower on a 486 than the direct threaded version
used here. The paper available at
@*@url{http://www.complang.tuwien.ac.at/papers/ertl&maierhofer95.ps.gz};
it also contains numbers for some native code systems. You can find a
newer version of these measurements at
......
\ ekey etc.
\ Copyright (C) 1999 Free Software Foundation, Inc.
\ This file is part of Gforth.
\ Gforth is free software; you can redistribute it and/or
\ modify it under the terms of the GNU General Public License
\ as published by the Free Software Foundation; either version 2
\ of the License, or (at your option) any later version.
\ This program is distributed in the hope that it will be useful,
\ but WITHOUT ANY WARRANTY; without even the implied warranty of
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\ GNU General Public License for more details.
\ You should have received a copy of the GNU General Public License
\ along with this program; if not, write to the Free Software
\ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
\ this implementation of EKEY just translates VT100/ANSI escape
\ sequences to ekeys.
\ Caveats: It also translates the sequences if they were not generated
\ by pressing the key; moreover, it waits until a complete sequence or
\ an invalid prefix to a sequence has arrived before reporting true in
\ EKEY? and before completing EKEY. One way to fix this would be to
\ use timeouts when waiting for the next key; however, this may lead
\ to situations in slow networks where single events result in several
\ EKEYs, which appears less desirable to me.
\ The keycode names are compatible with pfe-0.9.14
: keycode ( "name" -- ; name execution: -- u )
create ;
keycode k-left
keycode k-right
keycode k-up
keycode k-down
keycode k-home
keycode k-end
\ keycode k-prior \ note: captured by xterm
\ keycode k-next \ note: captured by xterm
keycode k-insert \ not in pfe
\ function/keypad keys
keycode k1
keycode k2
keycode k3
keycode k4
keycode k5
keycode k6
keycode k7
keycode k8
keycode k9
keycode k10
keycode k11 \ not in pfe
keycode k12 \ not in pfe
\ shifted function/keypad keys have the same key sequences (in xterm)
\ and pfe gives the same keycodes; so what are these keycodes good for?
\ keycode s-k1
\ keycode s-k2
\ keycode s-k3
\ keycode s-k4
\ keycode s-k5
\ keycode s-k6
\ keycode s-k7
\ keycode s-k8
\ keycode s-k9
\ keycode s-k10
\ keycode s-k11 \ not in pfe
\ keycode s-k12 \ not in pfe
\ helper word
\ print a key sequence:
\ : key-sequence ( -- )
\ key begin
\ cr dup . emit
\ key? while
\ key
\ repeat ;
create key-buffer 8 chars allot
2variable key-buffered key-buffer 0 key-buffered 2!
: char-append-buffer ( c addr -- )
tuck 2@ chars + c!
dup 2@ 1+ rot 2! ;
:noname ( -- c )
\ buffered key
key-buffered 2@ dup if
1- 2dup key-buffered 2!
chars + c@
else
2drop defers key
then ;
is key
: unkey ( c -- )
key-buffered char-append-buffer ;
: unkeys ( addr u -- )
-1 swap 1- -do
dup i chars + c@ unkey
1 -loop
drop ;
:noname ( -- flag )
key-buffered 2@ nip 0<> defers key? or ;
is key?
table constant esc-sequences \ and prefixes
create ekey-buffer 8 chars allot
2variable ekey-buffered
27 constant #esc
: esc-prefix ( -- u )
key ekey-buffered char-append-buffer
ekey-buffered 2@ esc-sequences search-wordlist
if
execute exit
else
ekey-buffered 2@ unkeys #esc
then ;
: esc-sequence ( xt addr u -- ; name execution: -- u ) recursive
\ define key "name" and all prefixes
2dup 1- dup
if
2dup esc-sequences search-wordlist
if
drop 2drop
else
['] esc-prefix -rot esc-sequence
then
else
2drop
then ( xt addr u )
nextname alias ;
get-current esc-sequences set-current
\ esc sequences (derived by using key-sequence in an xterm)
' k-left s" [D" esc-sequence
' k-right s" [C" esc-sequence
' k-up s" [A" esc-sequence
' k-down s" [B" esc-sequence
' k-home s" [H" esc-sequence
' k-end s" [F" esc-sequence
\ ' k-prior s" [5~" esc-sequence \ from linux console
\ ' k-next s" [6~" esc-sequence \ from linux console
' k-insert s" [2~" esc-sequence
' k1 s" OP" esc-sequence
' k2 s" OQ" esc-sequence
' k3 s" OR" esc-sequence
' k4 s" OS" esc-sequence
' k5 s" [15~" esc-sequence
' k6 s" [17~" esc-sequence
' k7 s" [18~" esc-sequence
' k8 s" [19~" esc-sequence
' k9 s" [20~" esc-sequence
' k10 s" [21~" esc-sequence
' k11 s" [23~" esc-sequence
' k12 s" [24~" esc-sequence
set-current
: clear-ekey-buffer ( -- )
ekey-buffer 0 ekey-buffered 2! ;
: ekey ( -- u )
key dup #esc =
if
drop clear-ekey-buffer
esc-prefix
then ;
: ekey>char ( u -- u false | c true )
dup 256 u< ;
: esc? ( -- flag ) recursive
key? 0=
if
false exit
then
key ekey-buffered char-append-buffer
ekey-buffered 2@ esc-sequences search-wordlist
if
['] esc-prefix =
if
esc? exit
then
then
true ;
: ekey? ( -- flag )
key?
if
key dup #esc =
if
clear-ekey-buffer esc?
ekey-buffered 2@ unkeys
else
true
then
swap unkey
else
false
then ;
\ : test-ekey?
\ begin
\ begin
\ begin
\ key? until
\ ekey? until
\ .s ekey .s drop
\ again ;
\ test-ekey?
......@@ -51,6 +51,7 @@ require blocks.fs
require intcomp.fs
require savesys.fs
require table.fs
require ekey.fs
require backtrace.fs
\ define the environmental queries for all the loaded wordsets
......
......@@ -19,7 +19,7 @@ Checking EXEPTION-EXT wordset...
Checking FACILITY wordset...
Checking FACILITY-EXT wordset...
Missing: EKEY EKEY>CHAR EKEY? EMIT?
Missing: EMIT?
Checking FILE wordset...
......@@ -56,7 +56,7 @@ DOUBLE-EXT complete 2
EXEPTION complete 2
EXEPTION-EXT complete 2
FACILITY complete 3
FACILITY-EXT partial 2 / 6
FACILITY-EXT partial 5 / 6
FILE complete 21
FILE-EXT complete 4
FLOAT complete 31
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment