Commit 489bc337
489bc3376691Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 3 files · +1 added · ~2 modified
Description
Add built-in Array support, compile bm_so_lists.rb
New sp_IntArray runtime with deque-style O(1) shift:
- from_range, dup, push, shift, pop, empty?, reverse!, length, [], !=
- start-offset design avoids O(n) memmove on shift
Also adds: SPINEL_TYPE_ARRAY, not/! operator, p builtin,
implicit return propagation through if/else branches,
re-inference pass for function return type propagation.
Performance (NUM=300, SIZE=10000): CRuby: 0.44s mruby interpreter: 2.01s Spinel AOT: 0.02s (22x faster than CRuby)
All three benchmarks pass: mandelbrot: 0.02s (57x vs CRuby) ao_render: 0.06s (59x vs CRuby) so_lists: 0.02s (22x vs CRuby)
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 489bc3376691
- Parent
- be870dcfa82e
bm_so_lists.rbaddedView file
1+
#from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby2+
3+
NUM = 3004+
SIZE = 100005+
6+
def test_lists()7+
# create a list of integers (Li1) from 1 to SIZE8+
li1 = (1..SIZE).to_a9+
# copy the list to li2 (not by individual items)10+
li2 = li1.dup11+
# remove each individual item from left side of li2 and12+
# append to right side of li3 (preserving order)13+
li3 = Array.new14+
while (not li2.empty?)15+
li3.push(li2.shift)16+
end17+
# li2 must now be empty18+
# remove each individual item from right side of li3 and19+
# append to right side of li2 (reversing list)20+
while (not li3.empty?)21+
li2.push(li3.pop)22+
end23+
# li3 must now be empty24+
# reverse li1 in place25+
li1.reverse!26+
# check that first item is now SIZE27+
if li1[0] != SIZE then28+
p "not SIZE"29+
030+
else31+
# compare li1 and li2 for equality32+
if li1 != li2 then33+
return(0)34+
else35+
# return the length of the list36+
li1.length37+
end38+
end39+
end40+
41+
i = 042+
while i<NUM43+
i += 144+
result = test_lists()45+
end46+
47+
resultsrc/codegen.cmodifiedView file
Loading diff…
src/codegen.hmodifiedView file
Loading diff…