[SLOF] [PATCH] Fix output word

Segher Boessenkool segher at kernel.crashing.org
Wed Sep 27 19:07:03 AEST 2017


Hi all,

On Wed, Sep 27, 2017 at 09:25:04AM +0200, Thomas Huth wrote:
> On 26.09.2017 13:28, Laurent Vivier wrote:
> > diff --git a/slof/fs/term-io.fs b/slof/fs/term-io.fs
> > index 52ce12a..a0b0f4b 100644
> > --- a/slof/fs/term-io.fs
> > +++ b/slof/fs/term-io.fs
> > @@ -40,6 +40,20 @@
> >  
> >  1 BUFFER: (term-io-char-buf)
> >  
> > +: term-io-emit ( char -- )
> > +    s" stdout" get-chosen IF
> > +        decode-int nip nip dup 0= IF 0 EXIT THEN
> > +	swap (term-io-char-buf) c!
> > +	>r (term-io-char-buf) 1 s" write" r@ $call-method
> > +	drop
> > +	r> drop
> > +    ELSE
> > +        [ ' emit behavior compile, ]
> > +    THEN
> > +;

First some trivialities...  Things are easier to read if you use
early-return instead of big IF...ELSE...THEN blocks.  R> DROP is a
red flag usually.  So something like

: term-io-emit ( char -- )
   s" stdout" get-chosen 0= IF [ ' emit behavior compile, ] THEN
   decode-int nip nip dup 0= IF 0 EXIT THEN
   swap (term-io-char-buf) c!
   >r (term-io-char-buf) 1 s" write" r> $call-method drop ;

> 3) Speed ... This rather code is called for every character that we
>    print out. While it likely does not really matter for input, the
>    output of text was always a rather critical thing in SLOF.

Is it?  I always found the output devices to be *much* slower than the
code, heh.  Or everything was so fast it did not matter.

But there are two big problems with the current architecture:

1) You should not use get-chosen.  Only SLOF itself is allowed to
modify anything in /chosen (directly), so the "output" word can just
scribble the "stdout" ihandle into some variable it can access much
faster.  Better yet, it can store some xt from the chosen stdout
package (the "write" one, for example).

2) EMIT in a loop is much slower than TYPE on some devices (say, if
you do some hypervisor call for output, or on a network device or
similar where you send a packet per character this way instead of the
whole string at once).  So you shouldn't use EMIT so much...  If speed
is still bad after 1), replace (simplified :-) )

: emit  ... ;
: type  bounds ?DO i c@ emit LOOP ;

with

: type  ... ;
CVARIABLE emit-buf
: emit  emit-buf c!  emit-buf 1 type ;


Segher


More information about the SLOF mailing list