diff options
author | Kevin B Kenny <kennykb@acm.org> | 2010-09-21 19:32:26 (GMT) |
---|---|---|
committer | Kevin B Kenny <kennykb@acm.org> | 2010-09-21 19:32:26 (GMT) |
commit | 53ebe37f0445f1a132bd20729d41894c6470622a (patch) | |
tree | 8432e95e8f3951b0e719713a4234c3ec27728bfb /tests/assemble1.bench | |
parent | d24e3a2febe9142596afe7c394f7bbc27b193eb6 (diff) | |
download | tcl-53ebe37f0445f1a132bd20729d41894c6470622a.zip tcl-53ebe37f0445f1a132bd20729d41894c6470622a.tar.gz tcl-53ebe37f0445f1a132bd20729d41894c6470622a.tar.bz2 |
initial commit of Ozgur Dogan Ugurlu's (SF user:dogeen) assembler for the Tcl bytecode language
Diffstat (limited to 'tests/assemble1.bench')
-rw-r--r-- | tests/assemble1.bench | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/assemble1.bench b/tests/assemble1.bench new file mode 100644 index 0000000..4f4dbce --- /dev/null +++ b/tests/assemble1.bench @@ -0,0 +1,60 @@ +proc ulam1 {n} { + set max $n + while {$n != 1} { + if {$n > $max} { + set max $n + } + if {$n % 2} { + set n [expr {3 * $n + 1}] + } else { + set n [expr {$n / 2}] + } + } + return $max +} +set i 0 +puts [time {ulam1 [incr i]} 10000] + +regsub -all {\#[^\n]*} { + {load n} # max + {dup} # max n + {jump start} # max n + + {label loop} # max n + {over 1} # max n max + {over 1} # max n max n + {ge} # man n max>=n + {jumpTrue skip} # max n + + {reverse 2} # n max + {pop} # n + {dup} # n n + + {label skip} # max n + {dup} # max n n + {push 2} # max n n 2 + {mod} # max n n%2 + {jumpTrue odd} # max n + + {push 2} # max n 2 + {div} # max n/2 -> max n + {jump start} # max n + + {label odd} # max n + {push 3} # max n 3 + {mult} # max 3*n + {push 1} # max 3*n 1 + {add} # max 3*n+1 + + {label start} # max n + {dup} # max n n + {push 1} # max n n 1 + {neq} # max n n>1 + {jumpTrue loop} # max n + + {pop} # max + +} {} code +proc ulam2 n [list tcl::unsupported::assemble $code] +set i 0 +puts [time {ulam2 [incr i]} 10000] |