Sunday, May 25, 2008

Benchmarking Retro

Retro now has a small, but working, set of benchmarks. This is in the svn repo and can be found in bin/bench. To use the benchmarks, you'll need a console build of Ngaro, a Retro image, a Unix-like host system, and Perl.

  cd bin/bench
./make-image
./run-bench

The timings for each test will be displayed when the test completes. There are currently three tests:
  • Recursive FIB
  • Countdown Loop
  • Call/Return (nesting) Pairs
I expect to see this grow into a more complete set of benchmarks in the future. For now, this should suffice for basic performance testing.

Initial results:

Host: ZenWalk 5 (Linux)
GCC: 4.1.2
CPU: Pentium 4 2.8GHz (1 core)
RAM: 1.5gb

Switched VM:
Recursive FIB (39)... 225.540318 seconds
Countdown Loop (1,000,000)... 13.616979 seconds
Nest/Unnest (256 million pairs)... 36.356847 seconds

Threaded VM:
Recursive FIB (39)... 212.555673 seconds
Countdown Loop (1,000,000)... 13.995988 seconds
Nest/Unnest (256 million pairs)... 33.026269 seconds

Updated Documentation

I have finished the initial updates to Retro's documentation. This is an ongoing process, in which I have been merging all of my notes and separate pieces of documentation into a single, cohesive reference.

Many sections have been expanded, and some new areas were added. I think it's a definite step forward and invite everyone to Check it out.

Saturday, May 24, 2008

Loading text files into an image

While Retro has no direct access to the host system, it is possible to load text files into an image and then save the results, or use it interactively. The process assumes that you are running on some form of Unix. It's pretty simple:

./build
cd bin
cat filename | ./ngaro forth.image

Or, for interactive mode:

cat filename - | ./ngaro forth.image

There is a limiting factor. The standard Retro image only recognizes space as valid whitespace, so any use of tabs or newlines will cause problems. This can be fixed by starting your code with the following line. This should be one single line. Be sure to include a space at the end of the line:

: fix dup 10 =if drop 32 then dup 13 =if drop 32 then
dup 9 =if drop 32 then ; ' fix is (remap-keys)

If you want, this can be disabled later by doing:

devector remap-keys

If you aren't going to drop to an interactive prompt, end with bye. Be sure to save your state if you want any changes to be present when you next load your Retro image.

Friday, May 23, 2008

Threaded Execution in the Ngaro VM

Thanks to Matthias Schirm there's a new implementation of Ngaro. It's written in C, and supports the text console devices. His implementation uses threaded execution, which is faster. He is working on further performance improvements. (This will likely become the default console build later this summer.) At present it does not work with the SDL-backed I/O; I will try to figure out why later on.

I've not done any significant benchmarking, but he did provide some numbers:
  : test dup for dup . CR 1 – next ; 1000000 test bye
ngaro (old):
  real  [s] 35,47
user [s] 8,27
sys [s] 1,07
ngaro (new):
 real: [s]  35,13
user [s] 7,46
sys [s] 1,34

  : fib dup 1 >if dup 1 RECURSE swap 2 RECURSE + EXIT then drop 1 ; 39 fib bye

ngaro (old):
 real  [s]  131,23
user [s] 131,21
sys [s] 0,03

ngaro (new):
 real  [s]  77,95
user [s] 77,67
sys [s] 0,04

This is a clear improvement and should continue to get better. I've begun to work on a small benchmark package; once done it'll be easier to test performance tweaks.

Sunday, May 11, 2008

Retro on Windows

Retro has been supported on Windows for a few weeks now. My access to Windows has been very limited, but I finally have a working XP install on my main development box.

I'll be revising the Windows Build Instructions later today, to help clarify a few points and point out the exact files I'm using. In addition, I've built a new installable package for Retro 10. This is a standard MSI package, so should install on XP and Vista machines without problems. It includes all necessary dependencies. I expect to replace the binary package on retroforth.org with this later this week.

Saturday, May 10, 2008

Release 2008.05.10

This is a pretty small release. I've been very busy (and a bit sick), so haven't had time to do much.
  • The video refresh port is now set properly after outputting a character
  • Ngaro JS now supports the video refresh port
  • Ngaro JS now stores the video output apart from the form output textarea
  • Strings are now rendered after all characters are drawn to the video buffer rather than character by character
  • update (enable/disable screen redraws) was added
  • redraw (redraw the screen if update is on) is now in the dictionary
  • Graphics module now does video updates after drawing shapes
  • Removed the FFI from Toka.
As shown, most of my time has been spent in enabling proper use of the video refresh support provided by Ngaro. This allows a noticeable performance increase in bits that are text heavy (try words) by delaying renders until the output is finished. It's also helpful with graphics, allowing filled shapes to be rendered more quickly.

I also removed the FFI functionality from Toka for this release. The FFI words are not used by the cross-compiler, and serves only to slow down the build of Toka and increase the number of dependencies. (This only affects the copy of Toka included in the Retro package; the full Toka still has FFI).

Sunday, May 4, 2008

Retro on Mobile Devices

I have scaled down the UI elements in Ngaro JS and am now able to run Retro on some mobile devices.

I have confirmation that it works properly on (platform, browser):
  • Windows Mobile 5 (Minimo)
  • Apple iPhone (Mobile Safari)
You can check out Retro Mobile online, or download the files to copy to your device for offline use.

Links:

Saturday, May 3, 2008

Release 2008.05.03

This release primarily focuses on the build system, but does bring some minor updates to Retro, the modules, and Ngaro.

The build system:
  • Refactored, now has separate functions for each step of the build system
  • The clean script has been merged in
  • Accepts various command line options allowing more control over the build
  • Basic help (pass --help) to see
  • Several bugs were fixed in fix-image
  • Memory usage of fix-image was reduced
  • image2js.toka is now commented
For the modules:
  • COUNT and R@ were added to forth94 and forth83.
Retro:
  • for / next loops have been added
And as finally, Ngaro:
  • Added a Clear Display button.
Nothing too impressive, but the updated build script will be easier for me to maintain and extend in the future.

Loops

I've implemented simple for/next loops now. The code below can be entered into a running Retro instance, then you can save the image to get them. (They will also be in the release due later today).

macro: for here 5 , ;
macro: next 6 , 27 , 25 , 8 , , ;

For those who are curious, this involves two compiler macros, which inline raw machine code into the words using the macros. As an example:

: foo 10 for 98 emit next ;

This will compile to:

foo:
lit 10

foo.1: ( 'for' )
push

lit 98

call emit

pop ( 'next' )

1-
0;
jump foo.1

;

There is a limitation that should be mentioned: when the loop counter reaches zero, the word will exit. Factor loops out if this is a problem for you.