0% found this document useful (0 votes)
183 views

Rubyenrails 2008

Project EaRing: A Meta-Literal Machine Zed A. Shaw. VMs are slow, because they're virtual, so everyone gets to announce A VM these days. EaRing is literal, so it is as fast as your CPU so it's fast.

Uploaded by

anon-419057
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
183 views

Rubyenrails 2008

Project EaRing: A Meta-Literal Machine Zed A. Shaw. VMs are slow, because they're virtual, so everyone gets to announce A VM these days. EaRing is literal, so it is as fast as your CPU so it's fast.

Uploaded by

anon-419057
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 217

Project EaRing:

A Meta-Literal Machine

Zed A. Shaw
[email protected]

June 9, 2008

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 1/1
Introduction Announcing EeRing

A Meta-Literal Machine

Everyone gets to announce a VM these days

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 2/1
Introduction Announcing EeRing

A Meta-Literal Machine

Everyone gets to announce a VM these days


Their VMs are slow, because they’re virtual

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 2/1
Introduction Announcing EeRing

A Meta-Literal Machine

Everyone gets to announce a VM these days


Their VMs are slow, because they’re virtual
EaRing is literal, so it is as fast as your CPU

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 2/1
Introduction Announcing EeRing

A Meta-Literal Machine

Everyone gets to announce a VM these days


Their VMs are slow, because they’re virtual
EaRing is literal, so it is as fast as your CPU
EaRing sounds like Erlang so it’s fast

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 2/1
Introduction Announcing EeRing

A Meta-Literal Machine

Everyone gets to announce a VM these days


Their VMs are slow, because they’re virtual
EaRing is literal, so it is as fast as your CPU
EaRing sounds like Erlang so it’s fast
Just like anything with memcache is fast

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 2/1
Introduction Announcing EeRing

A Meta-Literal Machine

Everyone gets to announce a VM these days


Their VMs are slow, because they’re virtual
EaRing is literal, so it is as fast as your CPU
EaRing sounds like Erlang so it’s fast
Just like anything with memcache is fast
Or, anything with "cloud" computing

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 2/1
Introduction Announcing EeRing

A Meta-Literal Machine

Everyone gets to announce a VM these days


Their VMs are slow, because they’re virtual
EaRing is literal, so it is as fast as your CPU
EaRing sounds like Erlang so it’s fast
Just like anything with memcache is fast
Or, anything with "cloud" computing
So EaRing will be fast, fast, fast!

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 2/1
Introduction Announcing EeRing

What Is A Literal Machine?

A VM is a big while-loop

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 3/1
Introduction Announcing EeRing

What Is A Literal Machine?

A VM is a big while-loop
Reading bytes

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 3/1
Introduction Announcing EeRing

What Is A Literal Machine?

A VM is a big while-loop
Reading bytes
And then running another language

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 3/1
Introduction Announcing EeRing

What Is A Literal Machine?

A VM is a big while-loop
Reading bytes
And then running another language
Like C, or Ruby, or C-Ruby, or Scheme

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 3/1
Introduction Announcing EeRing

What Is A Literal Machine?

A VM is a big while-loop
Reading bytes
And then running another language
Like C, or Ruby, or C-Ruby, or Scheme
Or, Assembler

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 3/1
Introduction Announcing EeRing

A Literal Machine...

Makes the real byte codes

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 4/1
Introduction Announcing EeRing

A Literal Machine...

Makes the real byte codes


You might call it an "assembler"

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 4/1
Introduction Announcing EeRing

A Literal Machine...

Makes the real byte codes


You might call it an "assembler"
They are pretty handy

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 4/1
Introduction Announcing EeRing

A Literal Machine...

Makes the real byte codes


You might call it an "assembler"
They are pretty handy
For, you know, making fast code

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 4/1
Introduction Announcing EeRing

EaRing Is Meta

Meta is awesome

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 5/1
Introduction Announcing EeRing

EaRing Is Meta

Meta is awesome
It lets people do amazing things

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 5/1
Introduction Announcing EeRing

EaRing Is Meta

Meta is awesome
It lets people do amazing things
Where would Rails 50k lines of code be...

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 5/1
Introduction Announcing EeRing

EaRing Is Meta

Meta is awesome
It lets people do amazing things
Where would Rails 50k lines of code be...
Without Meta Meta Meta!

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 5/1
Introduction Announcing EeRing

EaRing Is Meta

Meta is awesome
It lets people do amazing things
Where would Rails 50k lines of code be...
Without Meta Meta Meta!
(Probably 20k still)

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 5/1
Introduction Announcing EeRing

EaRing Took Me Two Weeks!

I am a god

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 6/1
Introduction Announcing EeRing

EaRing Took Me Two Weeks!

I am a god
Just like Avi and Gemstone

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 6/1
Introduction Announcing EeRing

EaRing Took Me Two Weeks!

I am a god
Just like Avi and Gemstone
I totally didn’t cheat either

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 6/1
Introduction Announcing EeRing

EaRing Took Me Two Weeks!

I am a god
Just like Avi and Gemstone
I totally didn’t cheat either
Just like Avi and Gemstone

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 6/1
Introduction Announcing EeRing

EaRing Is For You

With EaRing, Even you can announce a new Ruby VM in


a few short weeks.

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 7/1
Introduction Announcing EeRing

EaRing Is For You

With EaRing, Even you can announce a new Ruby VM in a few


short weeks.
Just take what I show you here today,

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 7/1
Introduction Announcing EeRing

EaRing Is For You

With EaRing, Even you can announce a new Ruby VM in a few


short weeks.
Just take what I show you here today,
add any Ruby parser you can find,

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 7/1
Introduction Announcing EeRing

EaRing Is For You

With EaRing, Even you can announce a new Ruby VM in a few


short weeks.
Just take what I show you here today,
add any Ruby parser you can find,
and PRESTO, you are a player baby.

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 7/1
Introduction Announcing EeRing

EaRing

The Perfect Accessory To Every Ruby On Rails


Company(tm)

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 8/1
Presenting EaRing The Fastest Dynamic Assembler

What Is EaRing Really?

Simple

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 9/1
Presenting EaRing The Fastest Dynamic Assembler

What Is EaRing Really?

Simple
A parser for a simple assembly language

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 9/1
Presenting EaRing The Fastest Dynamic Assembler

What Is EaRing Really?

Simple
A parser for a simple assembly language
That generates machine code dynamically

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 9/1
Presenting EaRing The Fastest Dynamic Assembler

What Is EaRing Really?

Simple
A parser for a simple assembly language
That generates machine code dynamically
Giving you dynamic access to functions

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 9/1
Presenting EaRing The Fastest Dynamic Assembler

What Is EaRing Really?

Simple
A parser for a simple assembly language
That generates machine code dynamically
Giving you dynamic access to functions
Doing this on multiple CPUs (x86-32, x86-64, PPC,
SPARC)

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 9/1
Presenting EaRing The Fastest Dynamic Assembler

What Is EaRing Really?

Simple
A parser for a simple assembly language
That generates machine code dynamically
Giving you dynamic access to functions
Doing this on multiple CPUs (x86-32, x86-64, PPC, SPARC)
From the same source

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 9/1
Presenting EaRing The Fastest Dynamic Assembler

Fibonacci Demo

The Best Benchmark Ever

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 10 / 1


Presenting EaRing The Fastest Dynamic Assembler

Fibonacci Demo

The Best Benchmark Ever


There’s No Way To Make It Faster

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 10 / 1


Presenting EaRing The Fastest Dynamic Assembler

Fibonacci Demo

The Best Benchmark Ever


There’s No Way To Make It Faster
Every new VM announce uses it

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 10 / 1


Presenting EaRing The Fastest Dynamic Assembler

Fibonacci Demo

The Best Benchmark Ever


There’s No Way To Make It Faster
Every new VM announce uses it
Mine will blow the doors off

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 10 / 1


Presenting EaRing The Fastest Dynamic Assembler

Basic Iterative Fib In EaRing

This is so fast!

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 11 / 1


Presenting EaRing The Fastest Dynamic Assembler

Basic Iterative Fib In EaRing

This is so fast!
Only 1 slide of code!

Zed A. Shaw ([email protected]) Project EaRing:A Meta-Literal Machine June 9, 2008 11 / 1


Presenting EaRing The Fastest Dynamic Assembler

function fibit(in : ulong) : ulong


getarg.ul(R2, in)
movi.ul(R1, 1)
blti.ul(exit:, R2, 2)
subi.ul(R2, R2, 1)
movi.ul(R0, 1)
loop:
subi.ul(R2, R2, 1)
addr.ul(V0, R0, R1)
movr.ul(R0, R1)
addi.ul(R1, V0, 1)
bnei.ul(loop:, R2, 0)
exit:
movr.ul(RET, R1)
ret
end

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 12 / 1


Presenting EaRing The Fastest Dynamic Assembler

The Main Method

Notice the import. That’s dynamic!

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 12 / 1


Presenting EaRing The Fastest Dynamic Assembler

%import("includes/fibit.asm", "fibit")

function main() : ulong


prepare(1)
movi.ul(R0, 93)

pusharg.ul(R0)
finish(fibit.fibit)
retval.ul(R0)

movr.ul(RET, R0)
ret
end

Zed A. Shaw ([email protected]) Code: includes/fibit_main.asm - June 9, 2008 13 / 1


Presenting EaRing The Fastest Dynamic Assembler

Timing To Parse And Run?

Actually too fast to measure.

Zed A. Shaw ([email protected]) Code: includes/fibit_main.asm - June 9, 2008 13 / 1


Presenting EaRing The Fastest Dynamic Assembler

Timing To Parse And Run?

Actually too fast to measure.


About 0.005 seconds on most machines.

Zed A. Shaw ([email protected]) Code: includes/fibit_main.asm - June 9, 2008 13 / 1


Presenting EaRing The Fastest Dynamic Assembler

$ time ./earing includes/fibit_main.asm main


EaRing. Copyright 2008 Zed A. Shaw.
Done compiling includes/fibit_main.asm. Enter ? to get th
main >> 2587060292317343101

real 0m0.005s
user 0m0.000s
sys 0m0.003s

Zed A. Shaw ([email protected]) Code: screens/fibit_main.txt - June 9, 2008 14 / 1


Presenting EaRing The Fastest Dynamic Assembler

Dynamic REPL

Yes, EaRing has a REPL

Zed A. Shaw ([email protected]) Code: screens/fibit_main.txt - June 9, 2008 14 / 1


Presenting EaRing The Fastest Dynamic Assembler

Dynamic REPL

Yes, EaRing has a REPL


It makes learning ASM pretty fun

Zed A. Shaw ([email protected]) Code: screens/fibit_main.txt - June 9, 2008 14 / 1


Presenting EaRing The Fastest Dynamic Assembler

EaRing. Copyright 2008 Zed A. Shaw.


Done compiling simpler.asm. Enter ? to get the function l
>>> main
>> -0.839072
>>> ?
data_sharing_test: 57 bytes of code, 0 params defined
fibit_huge_loop: 68 bytes of code, 0 params defined
fibit: 77 bytes of code, 1 params defined
incrementer: 32 bytes of code, 0 params defined
main: 163 bytes of code, 0 params defined
make_test1_test2: 56 bytes of code, 0 params defined
nfibs: 117 bytes of code, 1 params defined
print_fibit10: 52 bytes of code, 0 params defined
print_nfibs10: 52 bytes of code, 0 params defined
print_reflect: 52 bytes of code, 0 params defined
puts_sample: 98 bytes of code, 0 params defined
ram_test: 83 bytes of code, 0 params defined
Zed A. Shaw ([email protected]) Code: screens/simpler_screen.txt - June 9, 2008 14 / 1
Presenting EaRing The Fastest Dynamic Assembler

reflect: 18 bytes of code, 1 params defined


test2: 21 bytes of code, 0 params defined
test1: 29 bytes of code, 0 params defined
>>> test1
>> 100
>>> test2
>> 100
>>>

Zed A. Shaw ([email protected]) Code: screens/simpler_screen.txt - June 9, 2008 15 / 1


Presenting EaRing The Fastest Dynamic Assembler

How Fast Is It?!

Let’s do 5 million fib 93 calls!

Zed A. Shaw ([email protected]) Code: screens/simpler_screen.txt - June 9, 2008 15 / 1


Presenting EaRing The Fastest Dynamic Assembler

%import("includes/fibit.asm", "fibit")

function main() : ulong


movi.ui(V1, 5000000)

again:
prepare(1)
movi.ul(R0, 93)
pusharg.ul(R0)
finish(fibit.fibit)
retval.ul(R0)

# decrement and repeat


subi.ui(V1, V1, 1)
bgti.ui(again:, V1, 0)

# grab the last value as a check


Zed A. Shaw ([email protected]) Code: includes/fibit_huge.asm - June 9, 2008 15 / 1
Presenting EaRing The Fastest Dynamic Assembler

movr.ul(RET, R0)
ret
end

Zed A. Shaw ([email protected]) Code: includes/fibit_huge.asm - June 9, 2008 16 / 1


Presenting EaRing The Fastest Dynamic Assembler

Timing To Parse And Run?

Remember, this is 5.000.000 function calls

Zed A. Shaw ([email protected]) Code: includes/fibit_huge.asm - June 9, 2008 16 / 1


Presenting EaRing The Fastest Dynamic Assembler

Timing To Parse And Run?

Remember, this is 5.000.000 function calls


To a Fibonacci sequence up to 93

Zed A. Shaw ([email protected]) Code: includes/fibit_huge.asm - June 9, 2008 16 / 1


Presenting EaRing The Fastest Dynamic Assembler

Timing To Parse And Run?

Remember, this is 5.000.000 function calls


To a Fibonacci sequence up to 93
About 1.8 seconds on my laptop

Zed A. Shaw ([email protected]) Code: includes/fibit_huge.asm - June 9, 2008 16 / 1


Presenting EaRing The Fastest Dynamic Assembler

$ time ./earing includes/fibit_huge.asm main


EaRing. Copyright 2008 Zed A. Shaw.
Done compiling includes/fibit_huge.asm. Enter ? to get th
main >> 2587060292317343101

real 0m1.755s
user 0m1.747s
sys 0m0.003s

Zed A. Shaw ([email protected]) Code: screens/fibit_huge.txt - June 9, 2008 17 / 1


Presenting EaRing The Fastest Dynamic Assembler

More Features!

Fully dynamic functions.

Zed A. Shaw ([email protected]) Code: screens/fibit_huge.txt - June 9, 2008 17 / 1


Presenting EaRing The Fastest Dynamic Assembler

More Features!

Fully dynamic functions.


Thread safe (hopefully) and library capable.

Zed A. Shaw ([email protected]) Code: screens/fibit_huge.txt - June 9, 2008 17 / 1


Presenting EaRing The Fastest Dynamic Assembler

More Features!

Fully dynamic functions.


Thread safe (hopefully) and library capable.
Can even access .so libraries!

Zed A. Shaw ([email protected]) Code: screens/fibit_huge.txt - June 9, 2008 17 / 1


Presenting EaRing The Fastest Dynamic Assembler

%library("/lib/libc.so.6", "libc")

function puts_sample() : int


MY_NAME = "Zed A. Shaw"

movi.p(R0, MY_NAME)
prepare(1)
pusharg.p(R0)
finish(libc.puts)

ret
end

Zed A. Shaw ([email protected]) Code: includes/puts_sample.asm - June 9, 2008 18 / 1


Presenting EaRing The Fastest Dynamic Assembler

The Results Of Puts

Yep, does what you think.

Zed A. Shaw ([email protected]) Code: includes/puts_sample.asm - June 9, 2008 18 / 1


Presenting EaRing The Fastest Dynamic Assembler

EaRing. Copyright 2008 Zed A. Shaw.


Done compiling includes/puts_sample.asm. Enter ? to get t
puts_sample Zed A. Shaw
>> 12

Zed A. Shaw ([email protected]) Code: screens/puts_sample.txt - June 9, 2008 19 / 1


Presenting EaRing The Fastest Dynamic Assembler

More Features!

You want more?!

Zed A. Shaw ([email protected]) Code: screens/puts_sample.txt - June 9, 2008 19 / 1


Presenting EaRing The Fastest Dynamic Assembler

More Features!

You want more?!


Dynamic constants!

Zed A. Shaw ([email protected]) Code: screens/puts_sample.txt - June 9, 2008 19 / 1


Presenting EaRing The Fastest Dynamic Assembler

More Features!

You want more?!


Dynamic constants!
Reference Constants in other functions!

Zed A. Shaw ([email protected]) Code: screens/puts_sample.txt - June 9, 2008 19 / 1


Presenting EaRing The Fastest Dynamic Assembler

%library("/lib/libc.so.6", "libc")

SOME_STUFF = "Hello!"

function i_have_constants() : void


A_NAME = "Hi There"
ret
end

function puts_other() : int


movi.p(R0, self.i_have_constants.A_NAME)
prepare(1)
pusharg.p(R0)
finish(libc.puts)

movi.p(R0, SOME_STUFF)
prepare(1)
Zed A. Shaw ([email protected]) Code: includes/constants.asm - June 9, 2008 19 / 1
Presenting EaRing The Fastest Dynamic Assembler

pusharg.p(R0)
finish(libc.puts)

ret
end

Zed A. Shaw ([email protected]) Code: includes/constants.asm - June 9, 2008 20 / 1


Presenting EaRing The Fastest Dynamic Assembler

MORE FEATURES?!

Functions Are Also Dynamic Constants!

Zed A. Shaw ([email protected]) Code: includes/constants.asm - June 9, 2008 20 / 1


Presenting EaRing The Fastest Dynamic Assembler

MORE FEATURES?!

Functions Are Also Dynamic Constants!


ONE FUNCTION CAN ALTER ANOTHER!

Zed A. Shaw ([email protected]) Code: includes/constants.asm - June 9, 2008 20 / 1


Presenting EaRing The Fastest Dynamic Assembler

function test1() : int


movi.i(R1, 10000)
movi.i(R0, 20)

mulr.i(RET, R1, R0)


ret
end

function test2(): int


movi.i(RET, 100)
ret
end

function make_test1_test2() : int


movi.ui(R1, 0)

next:
Zed A. Shaw ([email protected]) Code: includes/func_swap.asm - June 9, 2008 20 / 1
Presenting EaRing The Fastest Dynamic Assembler

ldxi.c(R0, R1, self.test2)


stxi.c(self.test1, R1, R0)
addi.ui(R1, R1, 1)
blti.ui(next:, R1, 21)

calli(self.test1)

ret
end

Zed A. Shaw ([email protected]) Code: includes/func_swap.asm - June 9, 2008 21 / 1


Presenting EaRing The Fastest Dynamic Assembler

Oh That’s Evil

But does it work?

Zed A. Shaw ([email protected]) Code: includes/func_swap.asm - June 9, 2008 21 / 1


Presenting EaRing The Fastest Dynamic Assembler

Oh That’s Evil

But does it work?


Of course!

Zed A. Shaw ([email protected]) Code: includes/func_swap.asm - June 9, 2008 21 / 1


Presenting EaRing The Fastest Dynamic Assembler

EaRing. Copyright 2008 Zed A. Shaw.


Done compiling includes/func_swap.asm. Enter ? to get the
>>> ?
make_test1_test2: 56 bytes of code, 0 params defined
test2: 21 bytes of code, 0 params defined
test1: 29 bytes of code, 0 params defined
>>> test1
>> 200000
>>> test2
>> 100
>>> make_test1_test2
>> 100
>>>

Zed A. Shaw ([email protected]) Code: screens/func_swap.txt - June 9, 2008 22 / 1


Presenting EaRing The Fastest Dynamic Assembler

What About Garbage Collection?

Collection? Garbage?

Zed A. Shaw ([email protected]) Code: screens/func_swap.txt - June 9, 2008 22 / 1


Presenting EaRing The Fastest Dynamic Assembler

What About Garbage Collection?

Collection? Garbage?
This is assembler baby.

Zed A. Shaw ([email protected]) Code: screens/func_swap.txt - June 9, 2008 22 / 1


Presenting EaRing The Fastest Dynamic Assembler

What About Garbage Collection?

Collection? Garbage?
This is assembler baby.
You do your own GC.

Zed A. Shaw ([email protected]) Code: screens/func_swap.txt - June 9, 2008 22 / 1


Presenting EaRing The Fastest Dynamic Assembler

%library("/lib/libc.so.6", "libc")

function ram_test() : void


movi.ui(R0, 1024)
prepare(1)
pusharg.ui(R0)
finish(libc.malloc)
movr.ui(R0, RET)

prepare(1)
pusharg.ui(R0)
finish(libc.free)

ret
end

Zed A. Shaw ([email protected]) Code: includes/memory.asm - June 9, 2008 23 / 1


Presenting EaRing The Fastest Dynamic Assembler

Any Dynamic Library Dynamically

You want GC? You got GC.

Zed A. Shaw ([email protected]) Code: includes/memory.asm - June 9, 2008 23 / 1


Presenting EaRing The Fastest Dynamic Assembler

Any Dynamic Library Dynamically

You want GC? You got GC.


You want threads? You got threads.

Zed A. Shaw ([email protected]) Code: includes/memory.asm - June 9, 2008 23 / 1


Presenting EaRing The Fastest Dynamic Assembler

Any Dynamic Library Dynamically

You want GC? You got GC.


You want threads? You got threads.
You want printf?

Zed A. Shaw ([email protected]) Code: includes/memory.asm - June 9, 2008 23 / 1


Presenting EaRing The Fastest Dynamic Assembler

Any Dynamic Library Dynamically

You want GC? You got GC.


You want threads? You got threads.
You want printf?
Sorry, uh, printf is weird.

Zed A. Shaw ([email protected]) Code: includes/memory.asm - June 9, 2008 23 / 1


Presenting EaRing The Fastest Dynamic Assembler

MORE FEATURES?!

Actual Real Very Nice Error Messages

Zed A. Shaw ([email protected]) Code: includes/memory.asm - June 9, 2008 24 / 1


Presenting EaRing The Fastest Dynamic Assembler

MORE FEATURES?!

Actual Real Very Nice Error Messages


With, Line numbers even!

Zed A. Shaw ([email protected]) Code: includes/memory.asm - June 9, 2008 24 / 1


Presenting EaRing The Fastest Dynamic Assembler

MORE FEATURES?!

Actual Real Very Nice Error Messages


With, Line numbers even!
Already Better Than MRI

Zed A. Shaw ([email protected]) Code: includes/memory.asm - June 9, 2008 24 / 1


Presenting EaRing The Fastest Dynamic Assembler

function badoptype : v
movi.blah(R0,R1)
end

function badfunctype : not


movi.ui(R0,1)
end

function unterminated : v

function recovers : v
end

function badtokens : i
movi.ui($$,$$)
end

Zed A. Shaw ([email protected]) Code: includes/error.asm - June 9, 2008 25 / 1


Presenting EaRing The Fastest Dynamic Assembler

Error Reporting Is Sweet

When I run that, it will make you cry.

Zed A. Shaw ([email protected]) Code: includes/error.asm - June 9, 2008 25 / 1


Implementation How’d He Do That?

error.asm:1: error at COLON token in


[ FUNCTION IDENT | COLON ] unexpected ’:’
error.asm:1: error at TYPE token in
[ | TYPE ] unexpected ’v’
error.asm:2: error at OP token in
[ statements | OP ] unexpected ’movi’
error.asm:5: error at COLON token in
[ statements FUNCTION IDENT | COLON ] unexpected ’:’
error.asm:9: error at COLON token in
[ statements FUNCTION IDENT | COLON ] unexpected ’:’
error.asm:12: error at COLON token in
[ statements FUNCTION IDENT | COLON ] unexpected ’:’
error.asm:16: error at COLON token in
[ statements FUNCTION IDENT | COLON ] unexpected ’:’
error.asm:17: invalid character ’$’

Zed A. Shaw ([email protected]) Code: screens/error.txt - June 9, 2008 26 / 1


Implementation How’d He Do That?

It Wasn’t That Hard

When I say, "two weeks", I’m not bragging.

Zed A. Shaw ([email protected]) Code: screens/error.txt - June 9, 2008 26 / 1


Implementation How’d He Do That?

It Wasn’t That Hard

When I say, "two weeks", I’m not bragging.


I’m saying you could do it too.

Zed A. Shaw ([email protected]) Code: screens/error.txt - June 9, 2008 26 / 1


Implementation How’d He Do That?

It Wasn’t That Hard

When I say, "two weeks", I’m not bragging.


I’m saying you could do it too.
If you take the code I wrote (not generated)

Zed A. Shaw ([email protected]) Code: screens/error.txt - June 9, 2008 26 / 1


Implementation How’d He Do That?

It Wasn’t That Hard

When I say, "two weeks", I’m not bragging.


I’m saying you could do it too.
If you take the code I wrote (not generated)
2001 lines of text.

Zed A. Shaw ([email protected]) Code: screens/error.txt - June 9, 2008 26 / 1


Implementation How’d He Do That?

329 src/data.c
164 src/directives.c
111 src/earing.c
36 src/error.c
216 src/module.c
79 src/naming.c
184 src/ops.c
14 src/repl.c
75 src/util.c

166 src/data.h
10 src/directives.h
9 src/error.h
20 src/grammar.h
10 src/lexer.h
20 src/naming.h
145 src/ops.h
Zed A. Shaw ([email protected]) Code: screens/code_size.txt - June 9, 2008 26 / 1
Implementation How’d He Do That?

9 src/repl.h
14 src/tokenize.h
9 src/util.h

150 src/grammar.y
231 src/lexer.rl
Total: 2001

Zed A. Shaw ([email protected]) Code: screens/code_size.txt - June 9, 2008 27 / 1


Implementation How’d He Do That?

Now Leverage Existing Libraries

sglib for data structures I needed.

Zed A. Shaw ([email protected]) Code: screens/code_size.txt - June 9, 2008 27 / 1


Implementation How’d He Do That?

Now Leverage Existing Libraries

sglib for data structures I needed.


GNU lightning for generating the machine code.

Zed A. Shaw ([email protected]) Code: screens/code_size.txt - June 9, 2008 27 / 1


Implementation How’d He Do That?

Now Leverage Existing Libraries

sglib for data structures I needed.


GNU lightning for generating the machine code.
Lemon Parser for making the parser. Here’s a sample.

Zed A. Shaw ([email protected]) Code: screens/code_size.txt - June 9, 2008 27 / 1


Implementation How’d He Do That?

module ::= statements.


parameters ::= LPAREN args RPAREN.
parameters ::=.
args ::= args COMMA expr.
args ::= expr.
args ::=.
operation ::= OP DOT TYPE parameters.
operation ::= OP parameters.
expr ::= HEX.
expr ::= FLOAT. expr ::= INT.
expr ::= STR. expr ::= CHR.
expr ::= REG. expr ::= LABEL.
function ::= FUNCTION function_decl block END.
function_decl ::= IDENT LPAREN function_params
RPAREN COLON TYPE.

Zed A. Shaw ([email protected]) Code: includes/grammar.y - June 9, 2008 28 / 1


Implementation How’d He Do That?

Ragel For Lexer

Ragel is an awesome tool making this pretty easy.

Zed A. Shaw ([email protected]) Code: includes/grammar.y - June 9, 2008 28 / 1


Implementation How’d He Do That?

Ragel For Lexer

Ragel is an awesome tool making this pretty easy.


Does a lot more work than most lexers.

Zed A. Shaw ([email protected]) Code: includes/grammar.y - June 9, 2008 28 / 1


Implementation How’d He Do That?

Then A Bit Of Magic

Ternary Search Trees

Zed A. Shaw ([email protected]) Code: includes/grammar.y - June 9, 2008 29 / 1


Implementation How’d He Do That?

Then A Bit Of Magic

Ternary Search Trees


My Favorite Data Structure

Zed A. Shaw ([email protected]) Code: includes/grammar.y - June 9, 2008 29 / 1


Implementation How’d He Do That?

Then A Bit Of Magic

Ternary Search Trees


My Favorite Data Structure
Nearly impossible to explain

Zed A. Shaw ([email protected]) Code: includes/grammar.y - June 9, 2008 29 / 1


Implementation How’d He Do That?

Then A Bit Of Magic

Ternary Search Trees


My Favorite Data Structure
Nearly impossible to explain
Fast as hell for looking up strings

Zed A. Shaw ([email protected]) Code: includes/grammar.y - June 9, 2008 29 / 1


Implementation How’d He Do That?

void *Naming_search(tnode *root, const char *s, int len)


{
tnode *p = root;
int i = 0;

while(i < len && p) {


if (s[i] < p->splitchar) {
p = p->low;
} else if (s[i] == p->splitchar) {
i++;
if(i < len) p = p->equal;
} else {
p = p->high;
}
}

if(p) {
Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 29 / 1
Implementation How’d He Do That?

return p->value;
} else {
return NULL;
}
}

tnode *Naming_insert(tnode *p, const char *s, int len, vo


{
if (p == NULL) {
p = (tnode *) calloc(1,sizeof(tnode));
p->splitchar = *s;
}

if (*s < p->splitchar) {


p->low = Naming_insert(p->low, s, len, value);
} else if (*s == p->splitchar) {
if (len > 1) {
Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 29 / 1
Implementation How’d He Do That?

// not done yet, keep going but one less


p->equal = Naming_insert(p->equal, s+1, len -
} else {
p->value = value;
}
} else {
p->high = Naming_insert(p->high, s, len, value);
}

return p;
}

void Naming_traverse(tnode *p, Naming_traverse_cb cb, void


{
if (!p) return;
if(p->low) Naming_traverse(p->low, cb, data);

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 29 / 1


Implementation How’d He Do That?

if (p->equal) {
Naming_traverse(p->equal, cb, data);
}

if(p->high) Naming_traverse(p->high, cb, data);

if(p->value) cb(p->value, data);


}

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 30 / 1


Implementation How’d He Do That?

Naming And TSTs

Trading space for speed

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 30 / 1


Implementation How’d He Do That?

Naming And TSTs

Trading space for speed


Don’t scale up to giant strings

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 30 / 1


Implementation How’d He Do That?

Naming And TSTs

Trading space for speed


Don’t scale up to giant strings
But super fast for small strings

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 30 / 1


Implementation How’d He Do That?

Naming And TSTs

Trading space for speed


Don’t scale up to giant strings
But super fast for small strings
Especially language identifiers

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 30 / 1


Implementation How’d He Do That?

Naming And TSTs

Trading space for speed


Don’t scale up to giant strings
But super fast for small strings
Especially language identifiers
Works like a Hashmap with extra features

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 30 / 1


Implementation How’d He Do That?

TST Extra Features

Can do a partial match (like begins with, ends with)

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 31 / 1


Implementation How’d He Do That?

TST Extra Features

Can do a partial match (like begins with, ends with)


Can do most Regex over it

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 31 / 1


Implementation How’d He Do That?

TST Extra Features

Can do a partial match (like begins with, ends with)


Can do most Regex over it
Faster to not find a member

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 31 / 1


Implementation How’d He Do That?

TST Extra Features

Can do a partial match (like begins with, ends with)


Can do most Regex over it
Faster to not find a member
Can do probable matches.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 31 / 1


Implementation How’d He Do That?

TST Extra Features

Can do a partial match (like begins with, ends with)


Can do most Regex over it
Faster to not find a member
Can do probable matches.
Can’t find ’idint’ but there is ’ident’.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 31 / 1


Implementation How’d He Do That?

TST Extra Features

Can do a partial match (like begins with, ends with)


Can do most Regex over it
Faster to not find a member
Can do probable matches.
Can’t find ’idint’ but there is ’ident’.
All great things when writing a parser

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 31 / 1


Implementation How’d He Do That?

Now, Put It All Together

An assembler,

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 32 / 1


Implementation How’d He Do That?

Now, Put It All Together

An assembler,
That parses a real-ish language,

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 32 / 1


Implementation How’d He Do That?

Now, Put It All Together

An assembler,
That parses a real-ish language,
With error messages and fast parsing,

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 32 / 1


Implementation How’d He Do That?

Now, Put It All Together

An assembler,
That parses a real-ish language,
With error messages and fast parsing,
Which can generate actual machine code,

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 32 / 1


Implementation How’d He Do That?

Now, Put It All Together

An assembler,
That parses a real-ish language,
With error messages and fast parsing,
Which can generate actual machine code,
With introspection, dynamic libraries, imports,

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 32 / 1


Implementation How’d He Do That?

Now, Put It All Together

An assembler,
That parses a real-ish language,
With error messages and fast parsing,
Which can generate actual machine code,
With introspection, dynamic libraries, imports,
Yet you can modify and manipulate the results,

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 32 / 1


Implementation How’d He Do That?

Now, Put It All Together

An assembler,
That parses a real-ish language,
With error messages and fast parsing,
Which can generate actual machine code,
With introspection, dynamic libraries, imports,
Yet you can modify and manipulate the results,
And, on multiple CPUs from one source.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 32 / 1


Implementation How’d He Do That?

100 Days For MagLev?!

Two Weeks! I win!

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 33 / 1


Implementation How’d He Do That?

100 Days For MagLev?!

Two Weeks! I win!


Yeah yeah, they got an Object Database.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 33 / 1


Implementation How’d He Do That?

100 Days For MagLev?!

Two Weeks! I win!


Yeah yeah, they got an Object Database.
Those have been real successful.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 33 / 1


The Sales Pitch Why You Should Buy EaRing

Why You Should Buy EaRing

Buy?! What The FUCK I DEMAND OPEN SOURCE.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 34 / 1


The Sales Pitch Why You Should Buy EaRing

Fine, It’s Open Source Then

Sales Job Done!

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 35 / 1


The Sales Pitch Why You Should Buy EaRing

Disclaimer

Zed A. Shaw and the EaRing project are not responsible


for any limitations, effects, or implications of using said
software not limited to but including hair loss, nuclear
reactor failures, performance limitations, difficult
debugging, infection of the right eye, deterioration of
small intestines, or sudden rapid blindness.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 36 / 1


The Sales Pitch Why You Should Buy EaRing

The Bonus To You

EaRing will be the perfect accessory to any Ruby


company.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 37 / 1


The Sales Pitch Why You Should Buy EaRing

The Bonus To You

EaRing will be the perfect accessory to any Ruby company.


To be top in the Ruby world, you need a VM.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 37 / 1


The Sales Pitch Why You Should Buy EaRing

The Bonus To You

EaRing will be the perfect accessory to any Ruby company.


To be top in the Ruby world, you need a VM.
Without one, you’re just a "Rails Shop". That’s lame.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 37 / 1


The Sales Pitch Why You Should Buy EaRing

The Bonus To You

EaRing will be the perfect accessory to any Ruby company.


To be top in the Ruby world, you need a VM.
Without one, you’re just a "Rails Shop". That’s lame.
With EaRing, you have 50% of what you need to make a
Ruby VM good enough to present.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 37 / 1


The Sales Pitch Why You Should Buy EaRing

Imagine The Press Releases!

The Blogosphere will be blowing you harder than a 2


dollar whore with a bag of cash and no teeth.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 38 / 1


The Sales Pitch Why You Should Buy EaRing

Imagine The Press Releases!

The Blogosphere will be blowing you harder than a 2 dollar


whore with a bag of cash and no teeth.
Imagine, all those Ruby programmers who blog so much,
all the time, rather than, you know, writing good code.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 38 / 1


The Sales Pitch Why You Should Buy EaRing

Imagine The Press Releases!

The Blogosphere will be blowing you harder than a 2 dollar


whore with a bag of cash and no teeth.
Imagine, all those Ruby programmers who blog so much, all the
time, rather than, you know, writing good code.
How influential will their pretty 5 paragraph posts about
your VM be to the world?

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 38 / 1


The Sales Pitch Why You Should Buy EaRing

Imagine The Press Releases!

The Blogosphere will be blowing you harder than a 2 dollar


whore with a bag of cash and no teeth.
Imagine, all those Ruby programmers who blog so much, all the
time, rather than, you know, writing good code.
How influential will their pretty 5 paragraph posts about your
VM be to the world?
They’re Ruby blogs! Your grandma will know! Senators
will know! The WORLD will know!

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 38 / 1


The Sales Pitch Why You Should Buy EaRing

Resurrect Failing Platforms

Got a VM that only 10 companies pay for like Gemstone?

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 39 / 1


The Sales Pitch Why You Should Buy EaRing

Resurrect Failing Platforms

Got a VM that only 10 companies pay for like Gemstone?


Got a platform that is dying faster than Darfur like Sun?

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 39 / 1


The Sales Pitch Why You Should Buy EaRing

Resurrect Failing Platforms

Got a VM that only 10 companies pay for like Gemstone?


Got a platform that is dying faster than Darfur like Sun?
Got a reputation for raping children like Microsoft?

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 39 / 1


The Sales Pitch Why You Should Buy EaRing

Resurrect Failing Platforms

Got a VM that only 10 companies pay for like Gemstone?


Got a platform that is dying faster than Darfur like Sun?
Got a reputation for raping children like Microsoft?
EaRing will let you resurrect your failing platform, to the
applause of millions!

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 39 / 1


The Sales Pitch Why You Should Buy EaRing

Resurrect Failing Platforms

Got a VM that only 10 companies pay for like Gemstone?


Got a platform that is dying faster than Darfur like Sun?
Got a reputation for raping children like Microsoft?
EaRing will let you resurrect your failing platform, to the
applause of millions!
No, billions!

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 39 / 1


The Sales Pitch Why You Should Buy EaRing

Be A Good Guy

You’re helping open source!

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 40 / 1


The Sales Pitch Why You Should Buy EaRing

Be A Good Guy

You’re helping open source!


How could that possibly go wrong?

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 40 / 1


The Sales Pitch Why You Should Buy EaRing

Be A Good Guy

You’re helping open source!


How could that possibly go wrong?
Sun and Microsoft have great histories with open source.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 40 / 1


The Sales Pitch Why You Should Buy EaRing

Be A Good Guy

You’re helping open source!


How could that possibly go wrong?
Sun and Microsoft have great histories with open source.
Open source projects like NetBSD, JetSpeed, JBoss, and
Apache have never been taken over and exploited by big
companies.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 40 / 1


The Sales Pitch Why You Should Buy EaRing

Be A Good Guy

You’re helping open source!


How could that possibly go wrong?
Sun and Microsoft have great histories with open source.
Open source projects like NetBSD, JetSpeed, JBoss, and Apache
have never been taken over and exploited by big companies.
Nothing will ever go wrong with this setup.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 40 / 1


The Sales Pitch Why You Should Buy EaRing

Be A Good Guy

You’re helping open source!


How could that possibly go wrong?
Sun and Microsoft have great histories with open source.
Open source projects like NetBSD, JetSpeed, JBoss, and Apache
have never been taken over and exploited by big companies.
Nothing will ever go wrong with this setup.
If you help with EaRing, even you could be one of the
great benefactors of the open source world.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 40 / 1


The Sales Pitch Why You Should Buy EaRing

Be A Good Guy

You’re helping open source!


How could that possibly go wrong?
Sun and Microsoft have great histories with open source.
Open source projects like NetBSD, JetSpeed, JBoss, and Apache
have never been taken over and exploited by big companies.
Nothing will ever go wrong with this setup.
If you help with EaRing, even you could be one of the great
benefactors of the open source world.
I promise that EaRing will always be free and open.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 40 / 1


The Sales Pitch Why You Should Buy EaRing

Be A Good Guy

You’re helping open source!


How could that possibly go wrong?
Sun and Microsoft have great histories with open source.
Open source projects like NetBSD, JetSpeed, JBoss, and Apache
have never been taken over and exploited by big companies.
Nothing will ever go wrong with this setup.
If you help with EaRing, even you could be one of the great
benefactors of the open source world.
I promise that EaRing will always be free and open.
That’s been so successful for me in the past.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 40 / 1


In All Seriousness Some Sober Reflections

Amdahl’s Law

1/((1-f)+(f/p))

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 41 / 1


In All Seriousness Some Sober Reflections

Amdahl’s Law

1/((1-f)+(f/p))
Anyone know what this is?

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 41 / 1


In All Seriousness Some Sober Reflections

Amdahl’s Law

1/((1-f)+(f/p))
Anyone know what this is?
It’s mathematics for, "You’re Fucked".

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 41 / 1


In All Seriousness Some Sober Reflections

Amdahl’s Law

1/((1-f)+(f/p))
Anyone know what this is?
It’s mathematics for, "You’re Fucked".
f == Fraction of a program you can parallelize.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 41 / 1


In All Seriousness Some Sober Reflections

Amdahl’s Law

1/((1-f)+(f/p))
Anyone know what this is?
It’s mathematics for, "You’re Fucked".
f == Fraction of a program you can parallelize.
p == Number of CPUs you can run it on in parallel.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 41 / 1


In All Seriousness Some Sober Reflections

Amdahl’s Law And Programmers

Imagine that programmers aren’t very good.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 42 / 1


In All Seriousness Some Sober Reflections

Amdahl’s Law And Programmers

Imagine that programmers aren’t very good.


I know, it’s a stretch.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 42 / 1


In All Seriousness Some Sober Reflections

Amdahl’s Law And Programmers

Imagine that programmers aren’t very good.


I know, it’s a stretch.
Now, imagine that there’s a range of values for f
depending on how good they can parallelize.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 42 / 1


In All Seriousness Some Sober Reflections

Amdahl’s Law And Programmers

Imagine that programmers aren’t very good.


I know, it’s a stretch.
Now, imagine that there’s a range of values for f depending on
how good they can parallelize.
f now becomes a normal curve with a mean and standard
deviations determining the quality of parallel processing
implementation.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 42 / 1


In All Seriousness Some Sober Reflections

Amdahl’s Law And Programmers

Imagine that programmers aren’t very good.


I know, it’s a stretch.
Now, imagine that there’s a range of values for f depending on
how good they can parallelize.
f now becomes a normal curve with a mean and standard
deviations determining the quality of parallel processing
implementation.
p becomes a fixed input of CPUs.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 42 / 1


In All Seriousness Some Sober Reflections

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 43 / 1


In All Seriousness Some Sober Reflections

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 44 / 1


In All Seriousness Some Sober Reflections

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 45 / 1


In All Seriousness Some Sober Reflections

Last Graph Was Bullshit

It is weirdly true, but that graph doesn’t mean anything.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 46 / 1


In All Seriousness Some Sober Reflections

The Message Is There

Throw as many cores as you want at the problem.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 47 / 1


In All Seriousness Some Sober Reflections

The Message Is There

Throw as many cores as you want at the problem.


The real limiter is programmer ability

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 47 / 1


In All Seriousness Some Sober Reflections

The Message Is There

Throw as many cores as you want at the problem.


The real limiter is programmer ability
And a more complex Prolog like Erlang isn’t helping.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 47 / 1


In All Seriousness Some Sober Reflections

The Message Is There

Throw as many cores as you want at the problem.


The real limiter is programmer ability
And a more complex Prolog like Erlang isn’t helping.
Instead, the platform should make this easier.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 47 / 1


In All Seriousness Some Sober Reflections

It’s A Multiplier

Let’s look at that graph again though.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 48 / 1


In All Seriousness Some Sober Reflections

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 49 / 1


In All Seriousness Some Sober Reflections

It’s A Multiplier

One thing the pimps of parallel don’t tell you

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 50 / 1


In All Seriousness Some Sober Reflections

It’s A Multiplier

One thing the pimps of parallel don’t tell you


You can also make your code faster

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 50 / 1


In All Seriousness Some Sober Reflections

It’s A Multiplier

One thing the pimps of parallel don’t tell you


You can also make your code faster
By...

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 50 / 1


In All Seriousness Some Sober Reflections

It’s A Multiplier

One thing the pimps of parallel don’t tell you


You can also make your code faster
By...
Just making it fucking faster.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 50 / 1


In All Seriousness Some Sober Reflections

Imagine A World

Where you aren’t working with a Virtual Machine

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 51 / 1


In All Seriousness Some Sober Reflections

Imagine A World

Where you aren’t working with a Virtual Machine


Instead, the OS and CPU supports dynamic languages
easily

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 51 / 1


In All Seriousness Some Sober Reflections

Imagine A World

Where you aren’t working with a Virtual Machine


Instead, the OS and CPU supports dynamic languages easily
Where you can use something like EaRing to
sort-of-compile, sort-of-interpret

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 51 / 1


In All Seriousness Some Sober Reflections

Imagine A World

Where you aren’t working with a Virtual Machine


Instead, the OS and CPU supports dynamic languages easily
Where you can use something like EaRing to sort-of-compile,
sort-of-interpret
I’m not saying EaRing is the answer.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 51 / 1


In All Seriousness Some Sober Reflections

Imagine A World

Where you aren’t working with a Virtual Machine


Instead, the OS and CPU supports dynamic languages easily
Where you can use something like EaRing to sort-of-compile,
sort-of-interpret
I’m not saying EaRing is the answer.
But Amdahl’s law says putting slow languages on more
CPUs is only so helpful.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 51 / 1


In All Seriousness Some Sober Reflections

Fibonacci

Notice I wrote a fast Fibonacci sequence.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 52 / 1


In All Seriousness Some Sober Reflections

Fibonacci

Notice I wrote a fast Fibonacci sequence.


It wasn’t too hard, here it is again.

Zed A. Shaw ([email protected]) Code: includes/naming.c - June 9, 2008 52 / 1


In All Seriousness Some Sober Reflections

function fibit(in : ulong) : ulong


getarg.ul(R2, in)
movi.ul(R1, 1)
blti.ul(exit:, R2, 2)
subi.ul(R2, R2, 1)
movi.ul(R0, 1)
loop:
subi.ul(R2, R2, 1)
addr.ul(V0, R0, R1)
movr.ul(R0, R1)
addi.ul(R1, V0, 1)
bnei.ul(loop:, R2, 0)
exit:
movr.ul(RET, R1)
ret
end

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 53 / 1


In All Seriousness Some Sober Reflections

Fibonacci Should Be Banished

It is too easy to game a measurement like this.

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 53 / 1


In All Seriousness Some Sober Reflections

Fibonacci Should Be Banished

It is too easy to game a measurement like this.


I just used a fast goto loop.

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 53 / 1


In All Seriousness Some Sober Reflections

Fibonacci Should Be Banished

It is too easy to game a measurement like this.


I just used a fast goto loop.
You can even do tricks like static calculation and tables.

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 53 / 1


In All Seriousness Some Sober Reflections

Fibonacci Should Be Banished

It is too easy to game a measurement like this.


I just used a fast goto loop.
You can even do tricks like static calculation and tables.
It shows only a minor type of computation, one that’s
not particularly useful.

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 53 / 1


Conclusion In Conclusion – You’re Screwed

In Conclusion – You’re Screwed

Amdahl’s Law Says So.

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 54 / 1


Conclusion In Conclusion – You’re Screwed

In Conclusion – You’re Screwed

Amdahl’s Law Says So.


6x with the best programmers on about 200 CPUs

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 54 / 1


Conclusion In Conclusion – You’re Screwed

In Conclusion – You’re Screwed

Amdahl’s Law Says So.


6x with the best programmers on about 200 CPUs
Sounds like a great way to sell CPUs

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 54 / 1


Conclusion In Conclusion – You’re Screwed

In Conclusion – You’re Screwed

Amdahl’s Law Says So.


6x with the best programmers on about 200 CPUs
Sounds like a great way to sell CPUs
Parallel don’t matter nearly as much as Sun wants you to
think

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 54 / 1


Conclusion In Conclusion – You’re Screwed

In Conclusion – You’re Screwed

Amdahl’s Law Says So.


6x with the best programmers on about 200 CPUs
Sounds like a great way to sell CPUs
Parallel don’t matter nearly as much as Sun wants you to think
They are just trying to route around Moore’s Law

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 54 / 1


Conclusion In Conclusion – You’re Screwed

In Conclusion – You’re Screwed

Amdahl’s Law Says So.


6x with the best programmers on about 200 CPUs
Sounds like a great way to sell CPUs
Parallel don’t matter nearly as much as Sun wants you to think
They are just trying to route around Moore’s Law
And blaming you for it

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 54 / 1


Conclusion In Conclusion – You’re Screwed

In Conclusion – You’re Screwed

Amdahl’s Law Says So.


6x with the best programmers on about 200 CPUs
Sounds like a great way to sell CPUs
Parallel don’t matter nearly as much as Sun wants you to think
They are just trying to route around Moore’s Law
And blaming you for it
But who built things this way in the first place?

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 54 / 1


Conclusion In Conclusion – You’re Screwed

What We Need

We need CPUs that run modern languages

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 55 / 1


Conclusion In Conclusion – You’re Screwed

What We Need

We need CPUs that run modern languages


Operating systems that run modern CPUs

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 55 / 1


Conclusion In Conclusion – You’re Screwed

What We Need

We need CPUs that run modern languages


Operating systems that run modern CPUs
And languages that aren’t fucking interpreted

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 55 / 1


Conclusion In Conclusion – You’re Screwed

What We Need

We need CPUs that run modern languages


Operating systems that run modern CPUs
And languages that aren’t fucking interpreted
The way Ruby is.

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 55 / 1


Conclusion In Conclusion – You’re Screwed

And...

EaRing Is Going To Change The World.

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 56 / 1


Conclusion In Conclusion – You’re Screwed

And...

EaRing Is Going To Change The World.


One insult at a time.

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 56 / 1


Conclusion In Conclusion – You’re Screwed

Tools Used

GNU Lightning

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 57 / 1


Conclusion In Conclusion – You’re Screwed

Tools Used

GNU Lightning
Ragel Super Lexer

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 57 / 1


Conclusion In Conclusion – You’re Screwed

Tools Used

GNU Lightning
Ragel Super Lexer
Lemon Parser Generator

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 57 / 1


Conclusion In Conclusion – You’re Screwed

Tools Used

GNU Lightning
Ragel Super Lexer
Lemon Parser Generator
Valgrind

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 57 / 1


Conclusion In Conclusion – You’re Screwed

Tools Used

GNU Lightning
Ragel Super Lexer
Lemon Parser Generator
Valgrind
Vim

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 57 / 1


Conclusion In Conclusion – You’re Screwed

Getting The Presentation

I’ll have the whole Bazaar repository online later today.

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 58 / 1


Conclusion In Conclusion – You’re Screwed

Getting The Presentation

I’ll have the whole Bazaar repository online later today.


bzr pull
http://zedshaw.com/repository/rubyenrails2008

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 58 / 1


Conclusion In Conclusion – You’re Screwed

Getting The Presentation

I’ll have the whole Bazaar repository online later today.


bzr pull
http://zedshaw.com/repository/rubyenrails2008
See all my mistakes and get all the code.

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 58 / 1


Conclusion In Conclusion – You’re Screwed

Getting The Presentation

I’ll have the whole Bazaar repository online later today.


bzr pull
http://zedshaw.com/repository/rubyenrails2008
See all my mistakes and get all the code.
Vellum: http://zedshaw.com/projects/vellum/

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 58 / 1


Conclusion In Conclusion – You’re Screwed

Getting The Presentation

I’ll have the whole Bazaar repository online later today.


bzr pull
http://zedshaw.com/repository/rubyenrails2008
See all my mistakes and get all the code.
Vellum: http://zedshaw.com/projects/vellum/
EaRing: bzr pull http://zedshaw.com/repository/earing

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 58 / 1


Conclusion In Conclusion – You’re Screwed

Questions?

About Anything

Zed A. Shaw ([email protected]) Code: includes/fibit.asm - June 9, 2008 59 / 1

You might also like