
Show HN: A weekend replication of STOKE, a stochastic superoptimiser - bollu
https://github.com/bollu/blaze/blob/master/notebooks/tutorial.ipynb
======
pcwalton
I used STOKE to generate some SIMD code for PNG decoding once. Fun stuff!

I generally found it most useful to have STOKE generate the code, then reverse
engineer what it did and rewrite equivalent code by hand in a higher-level
language like C or Rust. The nondeterminism of the process and
unmaintainability of the resulting code makes it hard to justify shipping
STOKE as-is. But I did find it useful as a tool to give me general
optimization ideas. Sometimes it finds clever things you would never have
thought of on your own.

------
azhenley
Any chance you can give us a summary since GitHub is currently down?

~~~
lemcoe9
A weekend replication of STOKE, a stochastic superoptimiser

A super optimizer is a type of compiler that takes a program and finds the
optimal sequence of instructions that perform the same task as the original
program.

A stochastic thing X is a thing X that uses randomness.

STOKE is a superoptimizer that finds optimal instruction sequences to perform
a particular task by using numerical techniques which rely on randomness
(markov-chain-monte-carlo/MCMC) to explore the space of "all possible
programs".

Here, we re-implement STOKE for a tiny stack machine language whose
instruction set is Push, Add, Mul, and And. Sample output

 __* original: (nparams: 0 | [IPush 2,IPush 3,IAdd]) __* [IPush 5] | score:
2.5 // constant folding: 2 + 3 -> 5

 __* original: (nparams: 1 | [IPush 2,IMul]) __* [IDup,IAdd] | score: 2.25 //
strength reduction: 2 * x -> x + x

 __* original: (nparams: 1 | progInsts = [IDup,IAnd]) __* [] | score: 3.0 //
strength folding: x & x == x

That is, we automatically disover those program transformations by randomly
trying different programs (in a somewhat smart way).

