interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / bench / omc_efficiency / kernels / om2 / isort.om

66 lines · 1236 bytes Raw Blame History
1note isort: insertion sort of 20000 numbers from the generator of seed/rung4/tests/sort.om, in a
2note global array; prints sum a[i]*(i+1), the count of unsorted neighbours, a[0] and a[19999].
3note OMC-EFF-2: main writes the nanoseconds between its two monons readings (the computation, without
4note start-up and output) as one decimal line on stderr; stdout is unchanged.
5om2
6global obuf uchar 32
7global a ulong 20000
8fn putnum fd int v ulong to void
9put obuf 31 10
10p = ulong 31
11x = v
12while gt x 9
13p = sub p 1
14put obuf p uchar add rem x 10 48
15x = div x 10
16end
17p = sub p 1
18put obuf p uchar add x 48
19w = write fd obuf p sub 32 p
20end
21fn gen to void
22x = ulong 12345
23for i ulong 20000
24x = rem add mul x 1103515245 12345 2147483648
25put a i rem x 100000
26end
27end
28fn isort to void
29for j ulong 20000
30v = get a j
31k = j
32moving = true
33while and moving gt k 0
34p = get a sub k 1
35if gt p v
36put a k p
37k = sub k 1
38else
39moving = false
40end
41end
42put a k v
43end
44end
45fn main to int
46t0 = monons
47gen
48isort
49s = ulong 0
50for i ulong 20000
51s = add s mul get a i add i 1
52end
53bad = ulong 0
54for i ulong 19999
55if gt get a i get a add i 1
56bad = add bad 1
57end
58end
59t1 = monons
60putnum 2 ulong sub t1 t0
61putnum 1 s
62putnum 1 bad
63putnum 1 get a 0
64putnum 1 get a 19999
65ret 0
66end