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 / arith.om
| 1 | note arith: wrapping multiply-add hash h = h*31 + i and s = sum of ((i*i) xor (i >> 3)) rem 1000003, |
| 2 | note i = 0 .. 39999999, all ulong (unsigned wraps modulo 2^64). Prints h then s. |
| 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 | h = ulong 0 |
| 22 | s = ulong 0 |
| 23 | for i ulong 40000000 |
| 24 | h = add mul h 31 i |
| 25 | t = xor mul i i shr i 3 |
| 26 | s = add s rem t 1000003 |
| 27 | end |
| 28 | t1 = monons |
| 29 | putnum 2 ulong sub t1 t0 |
| 30 | putnum 1 h |
| 31 | putnum 1 s |
| 32 | ret 0 |
| 33 | end |