April 10 2001

H3sm in x86 assembly is now exhibiting nascent interpreter-like behavior.
dpdump, x (like Forth . but hex only) and a few other words can be invoked
interactively before she segfaults or otherwise fails. "words" works if
you compile it in. This means that H3sm 1.5 is roughly at the size it
needs to be at. The existing code is thus reflective of what a fully
working all-assembly 80386+ implementation might consist of resource-wise.
1.5 is the same threads as 1.4, but with all-assembly primitives, and some
reformatting to accomodate the change.

There are 78 primitives in H3sm 1.5, and they take up about 3.5k of space
in the file, including thier dictionary headers. That means it takes
roughly 2.5k of core machine code to implement an all-assembly H3sm. The
whole thing is assembly of course, but threads aren't really machine code
in the sense of really being hand-coded asm. This is significantly better
than I was able to do in GNU C, where the same primitives are much larger.
 
The pyte-related words are large for a Forth-like language, but the code
is somewhat repetitious, which eases implementation slightly. The H3sm 1.5
pyte words are optimized somewhat. Most of them test for Size=cellsize and
do the fast native cellsize version of themselves if possible before
reverting to traversing a pyte piecemeal if necessary, and they then do as
many chunks as possible as system cell size ints, doing only the leftover
byte and 2-byte portions as such. In most cases, that is. max and min are
still ugly cheats. max and min are currently unsigned, which required
changing a thread or two. Size operator words have been modified to assert
Size=cellsize=4 if Size is set to 0. The maximum pyte size is 255 bytes,
not 256.

Host calls are a form of primitive, but aren't in the 78 count. At this
writing there are only four Linux syscalls in 1.5, which are
basically the minimum to get the thing up. They aren't real big. The call
to Linux read is 42 bytes including the header.  H3sm read always requests
a 2k read. A complete set of Linux syscalls would be roughly 8k.

The threads portion of the dictionary is next in the file physically, and
the named data threads such as ARGV, toklen, dp and so on are all in a
clump. Much of the size of the stored executable file is initially zeros
in this clump of data words and in a non-dictionary allocation for the
pyte and pointer stacks. H3sm 1.5 stripped, no external linking, is 27k.
Getting uninitialized data out of the dictionary is doable, and may be
doable without an added degree of indirection at runtime, but 27k static
is plenty good for now.

Above the mostly empty data threads physically is 7k of thread verbs
constituting the interpreter and threader. 1.5 is subroutine-threaded.
Every "xt" in a thread includes a call instruction, which is the byte 0xe8
in this case. That's roughly the same size as the previous VMST scheme in
C.

Words that don't involve pytes should inline trivially and beneficially.
Many are one instruction and a return. Words using the return stack might
benefit from distinct inlined and threaded versions, since in subroutine
threading they have to do some juggling of thier own return address that
they don't have to do if inlined. Pyte words aren't worth inlining without
pretending to know what Size is at runtime. An optimizing compiler could
be devised that keeps track of Size, similar to a typed-data language
batch compiler, but this is far beyond my scope of interest. There are
definitely performance gains to be had there. The tradeoffs to obtain them
have extra issues in a Forth-like language, and would hopefully be
irrelevant to H3sm hardware.

Host-completeness on x86 requires some kind of "port" IO facility, which
doesn't exist in H3sm yet. It appears that a !port and @port could be
rigged up to cover most useful variants. These would necessarily be
primitives. 

There are about 6 unused primitives in the current 78. dshift, which is
down-significance bitshift a pyte, is unused, for example. 

"words" compiled directly into 1.4 and 1.5, runs about 30% faster in 1.5.
That's using emit for each character of output, so that's a LOT of IO.
Looking at the code, 1.5 would almost have to be several times faster than
1.4 for anything CPU-bound. 

The 1.blivvit version I put up on my ftp host a few days ago is reflective
of the above metrics, but with lots more bugs. I'm going to hold off
posting what I have at the moment in the hope that it reaches full
functionality soon.


Rick Hohensee
www.clienux.com


:;H3Sm | fmt
0-terminate  words  ->C  'p&  '&code  '&  '  (O)  tab  to2  to1  to:
token  threader  this  snug  step  spaces  ;  resolve  refill  .name
.chars  .$  .string  .r  .p  p2+s  p2dup  postpone  \  (  open  negate
name  link  interpret  input  include  hide  hexnumber  H3m  <-code
finish  delimit  dpdump  dump  cr  :  blank  beep  ?word  ?char  ?byte$=
?$=  ?pending  ?threader  ?hexnumber  asciinybble  allot  &p  &pliteral
&word  &$  &literal  &  tb  toklen  thispointer  Source  rcfile  latest
hexdigits  ENVP  epa  dp  digits  buffer  block  ARGV  <<<THREADS  write
open_  read  quit  <<<SYSCALLS  zero  xor  x  ushift  2pdrop  true  ->p
->link  ->code  ->r  !  s->p  s->r  setSize  swap  r->s  r->p  <-r  r-1
rpcopy  rdrop  pup  pswap  p!  p->s  p->r  p->  p-1  p-c  p+c  p+1  p+s
p+  pover  plus  pliteral  pdup  p@  pdrop  or  one  onbits  over  not
-?r  nip  move  maskbyte  -  min  max  literal  ?positive  ?=  ?()=  H3sm
halve  gap  getSize  flag  @+  @  false  emit  doHNC  double  dshift
dup  drop  cells  bcellsd  bbytesd  bytes  bump  align  aint  and  address
:; cLIeNUX /dev/tty1  14:46:43   /.so/H3sm/1.shasm
:;

