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 / isort.om
| 1 | note isort: insertion sort of 20000 numbers from the generator of seed/rung4/tests/sort.om, in a |
| 2 | note global array; prints sum a[i]*(i+1), the count of unsorted neighbours, a[0] and a[19999]. |
| 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 | global a ulong 20000 |
| 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 gen to void |
| 21 | x = ulong 12345 |
| 22 | for i ulong 20000 |
| 23 | x = rem add mul x 1103515245 12345 2147483648 |
| 24 | put a i rem x 100000 |
| 25 | end |
| 26 | end |
| 27 | fn isort to void |
| 28 | for j ulong 20000 |
| 29 | v = get a j |
| 30 | k = j |
| 31 | moving = true |
| 32 | while and moving gt k 0 |
| 33 | p = get a sub k 1 |
| 34 | if gt p v |
| 35 | put a k p |
| 36 | k = sub k 1 |
| 37 | else |
| 38 | moving = false |
| 39 | end |
| 40 | end |
| 41 | put a k v |
| 42 | end |
| 43 | end |
| 44 | fn main to int |
| 45 | t0 = monons |
| 46 | gen |
| 47 | isort |
| 48 | s = ulong 0 |
| 49 | for i ulong 20000 |
| 50 | s = add s mul get a i add i 1 |
| 51 | end |
| 52 | bad = ulong 0 |
| 53 | for i ulong 19999 |
| 54 | if gt get a i get a add i 1 |
| 55 | bad = add bad 1 |
| 56 | end |
| 57 | end |
| 58 | t1 = monons |
| 59 | putnum 2 ulong sub t1 t0 |
| 60 | putnum 1 s |
| 61 | putnum 1 bad |
| 62 | putnum 1 get a 0 |
| 63 | putnum 1 get a 19999 |
| 64 | ret 0 |
| 65 | end |