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 / inference_cost / io.om

131 lines · 1939 bytes Raw Blame History
1note bench/inference_cost/io.om -- stdin argument reader and decimal writer.
2note driver.sh builds an Omega candidate's unit as: the line "om2 diag", the candidate,
3note this unit, then a generated fn main that calls the candidate once per case of
4note inputs.txt. Exit 90..93 are harness I/O failures.
5global bxin uchar 65536
6global bxst ulong 2
7global bxob uchar 24
8
9fn bench_load to void
10p = ulong 0
11note every pass adds at least one byte to the 65536-byte buffer or leaves the loop
12while lt p 65536 bound 65537
13k = read 0 bxin p sub 65536 p
14if lt k 0
15exit 90
16end
17if eq k 0
18break
19end
20p = add p ulong k
21end
22if ge p 65536
23exit 91
24end
25put bxst 0 0
26put bxst 1 p
27end
28
29fn bench_ws to void
30p = get bxst 0
31n = get bxst 1
32while lt p n bound 65537
33c = get bxin p
34if gt c 32
35break
36end
37p = add p 1
38end
39put bxst 0 p
40end
41
42fn bench_skip to void
43bench_ws
44p = get bxst 0
45n = get bxst 1
46while lt p n bound 65537
47c = get bxin p
48if le c 32
49break
50end
51p = add p 1
52end
53put bxst 0 p
54end
55
56fn bench_arg to long
57bench_ws
58p = get bxst 0
59n = get bxst 1
60sg = long 1
61if lt p n
62if eq get bxin p 45
63sg = long -1
64p = add p 1
65end
66end
67v = long 0
68d = ulong 0
69note at most 20 digits fit a long-sized decimal; more is refused below by the checked mul
70while lt p n bound 65537
71c = get bxin p
72if lt c 48
73break
74end
75if gt c 57
76break
77end
78v = add mul v 10 long sub c 48
79p = add p 1
80d = add d 1
81end
82if eq d 0
83exit 92
84end
85put bxst 0 p
86ret mul v sg
87end
88
89fn bench_cases to ulong
90bench_skip
91bench_skip
92bench_skip
93v = bench_arg
94if lt v 0
95exit 92
96end
97ret ulong v
98end
99
100fn bench_putu x ulong to void
101v = x
102i = ulong 23
103put bxob i 10
104note a ulong has at most 20 decimal digits
105for j ulong 21
106i = sub i 1
107put bxob i uchar add rem v 10 48
108v = div v 10
109if eq v 0
110break
111end
112end
113n = sub 24 i
114w = write 1 bxob i n
115if ne w long n
116exit 93
117end
118end
119
120fn bench_puti x long to void
121if lt x 0
122put bxob 0 45
123w = write 1 bxob 0 1
124if ne w 1
125exit 93
126end
127bench_putu ulong neg x
128else
129bench_putu ulong x
130end
131end