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 / isort.om

65 lines · 1227 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.
5global out uchar 32
6global a ulong 20000
7fn putnum fd int v ulong to void
8put out 31 10
9p = ulong 31
10x = v
11while gt x 9
12p = sub p 1
13put out p uchar add rem x 10 48
14x = div x 10
15end
16p = sub p 1
17put out p uchar add x 48
18w = write fd out p sub 32 p
19end
20fn gen to void
21x = ulong 12345
22for i ulong 20000
23x = rem add mul x 1103515245 12345 2147483648
24put a i rem x 100000
25end
26end
27fn isort to void
28for j ulong 20000
29v = get a j
30k = j
31moving = true
32while and moving gt k 0
33p = get a sub k 1
34if gt p v
35put a k p
36k = sub k 1
37else
38moving = false
39end
40end
41put a k v
42end
43end
44fn main to int
45t0 = monons
46gen
47isort
48s = ulong 0
49for i ulong 20000
50s = add s mul get a i add i 1
51end
52bad = ulong 0
53for i ulong 19999
54if gt get a i get a add i 1
55bad = add bad 1
56end
57end
58t1 = monons
59putnum 2 ulong sub t1 t0
60putnum 1 s
61putnum 1 bad
62putnum 1 get a 0
63putnum 1 get a 19999
64ret 0
65end