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 / seed / ng / front / runs / branch-s.om
| 1 | note branch-s: kernels/branch.om with starts 1 .. 10000 (was 1000000), for ngrun in gate-front-ir. |
| 2 | note branch: Collatz steps to reach 1 for every start; prints the total steps and the |
| 3 | note largest step count. Data-dependent branch in a bounded while. |
| 4 | note OMC-EFF-2: main writes the nanoseconds between its two monons readings (the computation, without |
| 5 | note start-up and output) as one decimal line on stderr; stdout is unchanged. |
| 6 | global out uchar 32 |
| 7 | fn putnum fd int v ulong to void |
| 8 | put out 31 10 |
| 9 | p = ulong 31 |
| 10 | x = v |
| 11 | while gt x 9 |
| 12 | p = sub p 1 |
| 13 | put out p uchar add rem x 10 48 |
| 14 | x = div x 10 |
| 15 | end |
| 16 | p = sub p 1 |
| 17 | put out p uchar add x 48 |
| 18 | w = write fd out p sub 32 p |
| 19 | end |
| 20 | fn main to int |
| 21 | t0 = monons |
| 22 | tot = ulong 0 |
| 23 | mx = ulong 0 |
| 24 | for n ulong 10000 |
| 25 | x = add n 1 |
| 26 | k = ulong 0 |
| 27 | while ne x 1 |
| 28 | if eq and x 1 0 |
| 29 | x = shr x 1 |
| 30 | else |
| 31 | x = add mul x 3 1 |
| 32 | end |
| 33 | k = add k 1 |
| 34 | end |
| 35 | tot = add tot k |
| 36 | if gt k mx |
| 37 | mx = k |
| 38 | end |
| 39 | end |
| 40 | t1 = monons |
| 41 | putnum 2 ulong sub t1 t0 |
| 42 | putnum 1 tot |
| 43 | putnum 1 mx |
| 44 | ret 0 |
| 45 | end |