omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / bench / omc_efficiency / kernels / branch.om
| 1 | note branch: Collatz steps to reach 1 for every start 1 .. 1000000; prints the total steps and the |
| 2 | note largest step count. Data-dependent branch in a bounded while. |
| 3 | note OMC-EFF-2: main writes the nanoseconds between its two monons readings (the computation, without |
| 4 | note start-up and output) as one decimal line on stderr; stdout is unchanged. |
| 5 | global out uchar 32 |
| 6 | fn putnum fd int v ulong to void |
| 7 | put out 31 10 |
| 8 | p = ulong 31 |
| 9 | x = v |
| 10 | while gt x 9 |
| 11 | p = sub p 1 |
| 12 | put out p uchar add rem x 10 48 |
| 13 | x = div x 10 |
| 14 | end |
| 15 | p = sub p 1 |
| 16 | put out p uchar add x 48 |
| 17 | w = write fd out p sub 32 p |
| 18 | end |
| 19 | fn main to int |
| 20 | t0 = monons |
| 21 | tot = ulong 0 |
| 22 | mx = ulong 0 |
| 23 | for n ulong 1000000 |
| 24 | x = add n 1 |
| 25 | k = ulong 0 |
| 26 | while ne x 1 |
| 27 | if eq and x 1 0 |
| 28 | x = shr x 1 |
| 29 | else |
| 30 | x = add mul x 3 1 |
| 31 | end |
| 32 | k = add k 1 |
| 33 | end |
| 34 | tot = add tot k |
| 35 | if gt k mx |
| 36 | mx = k |
| 37 | end |
| 38 | end |
| 39 | t1 = monons |
| 40 | putnum 2 ulong sub t1 t0 |
| 41 | putnum 1 tot |
| 42 | putnum 1 mx |
| 43 | ret 0 |
| 44 | end |