sd:star_forth_test_suite
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| sd:star_forth_test_suite [2026/03/13 07:16] – appledog | sd:star_forth_test_suite [2026/03/14 13:20] (current) – appledog | ||
|---|---|---|---|
| Line 17: | Line 17: | ||
| | 1.0\\ 260313 | PASS | '': | | 1.0\\ 260313 | PASS | '': | ||
| | 1.0\\ 260313 | PASS | '': | | 1.0\\ 260313 | PASS | '': | ||
| + | | 1.0\\ 260314 | PASS | '': | ||
| + | |||
| + | Note that AS-IS, SD/FORTH 1.0 is not FORTH-79 compliant. That's fine, the following self-hosted words act as a sort of test suite, and also bring us up squarely into FORTH-79. | ||
| + | |||
| + | <codify forth> | ||
| + | : 1+ 1 + ; | ||
| + | : 1- 1 - ; | ||
| + | : 2+ 2 + ; | ||
| + | : 2- 2 - ; | ||
| + | : 0= 0 = ; | ||
| + | : 0< 0 < ; | ||
| + | : 0> 0 > ; | ||
| + | : NEGATE 0 SWAP - ; | ||
| + | : ABS DUP 0< IF NEGATE THEN ; | ||
| + | : NIP SWAP DROP ; | ||
| + | : TUCK SWAP OVER ; | ||
| + | : ?DUP DUP IF DUP THEN ; | ||
| + | : ROT >R SWAP R> SWAP ; | ||
| + | : 2DUP OVER OVER ; | ||
| + | : MAX 2DUP < IF SWAP THEN DROP ; | ||
| + | : MIN 2DUP > IF SWAP THEN DROP ; | ||
| + | : SPACE 32 EMIT ; | ||
| + | : SPACES 0 DO SPACE LOOP ; | ||
| + | : /MOD 2DUP MOD >R / R> SWAP ; | ||
| + | : +! DUP @ ROT + SWAP ! ; | ||
| + | : TYPE 0 DO DUP C@ EMIT 1 + LOOP DROP ; | ||
| + | : TYPE ( addr len -- ) 0 DO DUP C@ EMIT 1 + LOOP DROP ; | ||
| + | : MOVE CMOVE ; | ||
| + | </ | ||
| + | |||
| + | == FORTH-79 TESTS | ||
| + | You could also try this; if you see all PASS and then ABC and then A on the next line underneath the space beside the C, it works! | ||
| + | |||
| + | <codify Forth> | ||
| + | : TEST= = IF ." PASS " ELSE ." FAIL " THEN ; | ||
| + | |||
| + | ( Arithmetic ) | ||
| + | 5 1+ 6 TEST= | ||
| + | 5 1- 4 TEST= | ||
| + | 5 2+ 7 TEST= | ||
| + | 5 2- 3 TEST= | ||
| + | 5 NEGATE -5 TEST= | ||
| + | -7 NEGATE 7 TEST= | ||
| + | -5 ABS 5 TEST= | ||
| + | 5 ABS 5 TEST= | ||
| + | |||
| + | ( Comparisons ) | ||
| + | 0 0= 1 TEST= | ||
| + | 5 0= 0 TEST= | ||
| + | -1 0< 1 TEST= | ||
| + | 5 0< 0 TEST= | ||
| + | 5 0> 1 TEST= | ||
| + | -1 0> 0 TEST= | ||
| + | |||
| + | ( Stack ops ) | ||
| + | 1 2 NIP 2 TEST= | ||
| + | 1 2 TUCK 2 TEST= DROP DROP | ||
| + | 1 2 TUCK DROP 1 TEST= DROP | ||
| + | 1 2 TUCK DROP DROP 2 TEST= | ||
| + | 5 ?DUP + 10 TEST= | ||
| + | 0 ?DUP 0 TEST= | ||
| + | 1 2 3 ROT 1 TEST= DROP DROP | ||
| + | 3 4 2DUP + >R + R> + 14 TEST= | ||
| + | |||
| + | ( Math ) | ||
| + | 7 3 MAX 7 TEST= | ||
| + | 3 7 MAX 7 TEST= | ||
| + | 7 3 MIN 3 TEST= | ||
| + | 3 7 MIN 3 TEST= | ||
| + | 7 3 /MOD SWAP 1 TEST= | ||
| + | 7 3 /MOD 2 TEST= | ||
| + | DROP | ||
| + | |||
| + | ( Variable and +! ) | ||
| + | VARIABLE TV | ||
| + | 10 TV ! | ||
| + | 3 TV +! | ||
| + | TV @ 13 TEST= | ||
| + | |||
| + | ( SPACE and SPACES ) | ||
| + | 65 EMIT 66 EMIT 67 EMIT CR | ||
| + | 3 SPACES 65 EMIT CR | ||
| + | |||
| + | ( Bit Shifting Ops ) | ||
| + | 1 0 LSHIFT 1 TEST= | ||
| + | 1 1 LSHIFT 2 TEST= | ||
| + | 1 4 LSHIFT 16 TEST= | ||
| + | 1 8 LSHIFT 256 TEST= | ||
| + | $FF 4 LSHIFT $FF0 TEST= | ||
| + | 16 1 RSHIFT 8 TEST= | ||
| + | 256 8 RSHIFT 1 TEST= | ||
| + | $FF0 4 RSHIFT $FF TEST= | ||
| + | 1 1 RSHIFT 0 TEST= | ||
| + | </ | ||
| == Benchmarking | == Benchmarking | ||
| The SIMPLE and BENCH tests indicate SD/FORTH is: | The SIMPLE and BENCH tests indicate SD/FORTH is: | ||
| - | * 75x faster than BASIC (1,800 lines/sec) × ~5 ops/line ≈ 9,000 ops/sec) | + | * 75x faster than Stellar |
| * 5x to 7x faster than a real C64 running DurexForth (~25,000 words/sec) | * 5x to 7x faster than a real C64 running DurexForth (~25,000 words/sec) | ||
| * Comparable to a 4 MHz Z80 running Forth850 or an 8MHz Z80B running CamelForth. | * Comparable to a 4 MHz Z80 running Forth850 or an 8MHz Z80B running CamelForth. | ||
| - | However, this is an upper end. The following MUL and DIV heavy benchmarks operate a bit slower: | + | However, this is an upper end. The following MUL and DIV heavy benchmarks operate a bit slower. Here's a summary of the followinf programs: |
| + | |||
| + | | Benchmark | Words/Sec. | Notes | | ||
| + | | Bare Loop | 176,000 | Only dispatch overhead | | ||
| + | | Stackbench | 160,000 | Only stack operations | | ||
| + | | DUP * DROP | 136,000 | Multiply, Stack Ops | | ||
| + | | ADD only | 120,000 | Same as Mixed but no DIV or MUL | | ||
| + | | Mixed no DIV | 100,000 | Same as Mixed but no DIV | | ||
| + | | FizzBench | 97,000 | 3x MOD, branches | | ||
| + | | Mixed +-*/ | 90,000 | Division, Heavy Stack | | ||
| + | |||
| + | The estimate is that 70% overhead is dispatch. So with a touch of opt I think the system wants to run at 180,000 words/sec, but gets tinted down by various factors. Stack operations are cheap, then come other types of operation, then MUL, DIV and MOD are considered ' | ||
| + | |||
| + | === STACKBENCH | ||
| + | <codify Forth> | ||
| + | : STACKBENCH ( -- ) | ||
| + | 1 2 3 | ||
| + | 300000 0 DO | ||
| + | DUP DROP SWAP OVER DROP | ||
| + | LOOP | ||
| + | DROP DROP DROP ; | ||
| + | |||
| + | STACKBENCH | ||
| + | </ | ||
| === FIZZBENCH | === FIZZBENCH | ||
| - | <WRAP>< | + | <codify Forth> |
| - | : FIZZBENCH 0 100000 | + | : FIZZBUZZ 21 1 DO I 15 MOD 0 = IF ." FizzBuzz" |
| + | 0 = IF ." Fizz" ELSE I 5 MOD | ||
| + | 0 = IF ." Buzz" ELSE I . THEN THEN THEN CR LOOP ; | ||
| + | : FIZZBENCH 0 10000 0 | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| : FB10 10 0 DO FIZZBENCH LOOP . ." hits" CR ; | : FB10 10 0 DO FIZZBENCH LOOP . ." hits" CR ; | ||
| FB10 | FB10 | ||
| - | </code></WRAP> | + | </codify> |
| + | |||
| + | This executes in 18.5 seconds, indicating 97,000 words/sec. | ||
| === BENCH-ARITH | === BENCH-ARITH | ||
| - | : ARITH ( n -- n ) | + | <codify FORTH> |
| - | DUP 42 + | + | |
| - | DUP 7 - | + | DUP 42 + |
| - | DUP 3 * | + | DUP 7 - |
| - | DUP 2 / | + | DUP 3 * |
| - | DROP DROP DROP DROP ; | + | DUP 2 / |
| + | DROP DROP DROP DROP ; | ||
| + | |||
| + | : BENCH-ARITH ( -- ) | ||
| + | ." Arithmetic benchmark" | ||
| + | 100000 0 DO | ||
| + | I ARITH DROP | ||
| + | LOOP | ||
| + | ." Done" CR ; | ||
| + | |||
| + | BENCH-ARITH | ||
| + | </ | ||
| + | |||
| + | Same without DIV: | ||
| + | |||
| + | <codify Forth> | ||
| + | : ARITH3 ( n -- n ) | ||
| + | DUP 42 + | ||
| + | DUP 7 - | ||
| + | DUP 3 * | ||
| + | | ||
| - | : BENCH-ARITH | + | |
| - | ." | + | ." |
| - | 100000 0 DO | + | 100000 0 DO |
| - | I ARITH DROP | + | I ARITH3 |
| - | LOOP | + | LOOP |
| - | ." Done" CR ; | + | ." Done" CR ; |
| - | BENCH-ARITH | + | BENCH3 |
| + | </ | ||
sd/star_forth_test_suite.1773386186.txt.gz · Last modified: by appledog
