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 / tests / turing / ty_energy_fixture.om
| 1 | om2 |
| 2 | note SPDX-License-Identifier: Apache-2.0 |
| 3 | note Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 4 | note |
| 5 | note tests/turing/ty_energy_fixture.om -- synthetic meter windows for reducer tests. |
| 6 | note Replaces tests/turing/ty_energy_fixture.c. No hardware measurement claim. |
| 7 | |
| 8 | text t_s1 "{\"t_ns\":" |
| 9 | text t_s2 ",\"spbm_ok\":" |
| 10 | text t_s3 ",\"overflow\":[" |
| 11 | text t_s4 ",0,0],\"energy_uj\":[" |
| 12 | text t_s5 ",1000000,1000000]}" |
| 13 | text t_p1 "{\"ok\":1,\"result\":{\"tag\":\"" |
| 14 | text t_p2 "\",\"rz\":\"R1_plain\",\"cpus\":\"5\",\"pinned\":1,\"oracle_ok\":" |
| 15 | text t_p3 ",\"planned_ns\":1000000000,\"go_ns\":" |
| 16 | text t_p4 ",\"t0_ns\":" |
| 17 | text t_p5 ",\"t1_ns\":" |
| 18 | text t_p6 ",\"done_ns\":" |
| 19 | text t_p7 ",\"calls\":1,\"pmu_open\":1,\"pmu\":{\"ok\":1,\"sum\":{\"cpu_cycles\":100,\"inst_retired\":200,\"l2d_cache_refill\":5},\"pmu\":[{\"value\":[1,1,1,1,1,1],\"enabled\":[1000,1000,1000,1000,1000,1000],\"running\":[" |
| 20 | text t_p8 "]}]}}}" |
| 21 | text t_h1 "{\"run\":\"fixture\",\"config\":\"S1\",\"level\":\"" |
| 22 | text t_h2 "\",\"round\":1,\"trial\":1,\"planned_ns\":1000000000,\"tool_cpu\":0,\"meter_ok\":1,\"spec_a\":\"R1_plain:5\",\"spec_b\":\"R2c_crumb:15\",\"e0\":" |
| 23 | text t_h3 ",\"e1\":" |
| 24 | text t_h4 ",\"tel\":{\"t_ns\":[" |
| 25 | text t_h5 "],\"ok\":[1,1,1,1,1,1,1,1,1,1]},\"participants\":[" |
| 26 | text t_h6 "],\"s0\":{\"busy_jiffies\":[0],\"temp_mc\":[40000]},\"s1\":{\"busy_jiffies\":[0],\"temp_mc\":[40000]}}\n" |
| 27 | text t_comma "," |
| 28 | text t_idle "IDLE" |
| 29 | text t_sensor "sensor" |
| 30 | text t_wrap "wrap" |
| 31 | text t_ovf "overflow" |
| 32 | text t_oracle "oracle" |
| 33 | text t_mux "multiplexed" |
| 34 | |
| 35 | global g_out uchar 16384 |
| 36 | global g_ol ulong 1 |
| 37 | global g_a1 uchar 64 |
| 38 | global g_a2 uchar 64 |
| 39 | global g_a3 uchar 64 |
| 40 | global g_al ulong 4 |
| 41 | |
| 42 | fn ob c uchar to void |
| 43 | n = get g_ol 0 |
| 44 | if lt n 16384 |
| 45 | put g_out n c |
| 46 | put g_ol 0 add n 1 |
| 47 | end |
| 48 | end |
| 49 | |
| 50 | fn os s view uchar * to void |
| 51 | n = len s |
| 52 | for i ulong n |
| 53 | ob get s i |
| 54 | end |
| 55 | end |
| 56 | |
| 57 | fn ou v ulong to void |
| 58 | if eq v 0 |
| 59 | ob uchar 48 |
| 60 | ret |
| 61 | end |
| 62 | dig = new uchar 24 0 |
| 63 | n = ulong 0 |
| 64 | x = v |
| 65 | while gt x 0 |
| 66 | put dig n uchar add 48 rem x 10 |
| 67 | x = div x 10 |
| 68 | n = add n 1 |
| 69 | end |
| 70 | i = n |
| 71 | while gt i 0 |
| 72 | i = sub i 1 |
| 73 | ob get dig i |
| 74 | end |
| 75 | end |
| 76 | |
| 77 | fn a1_eq s view uchar * to bool |
| 78 | n = get g_al 1 |
| 79 | if ne n len s |
| 80 | ret false |
| 81 | end |
| 82 | for i ulong n |
| 83 | if ne get g_a1 i get s i |
| 84 | ret false |
| 85 | end |
| 86 | end |
| 87 | ret true |
| 88 | end |
| 89 | |
| 90 | fn a3_eq s view uchar * to bool |
| 91 | n = get g_al 3 |
| 92 | if ne n len s |
| 93 | ret false |
| 94 | end |
| 95 | for i ulong n |
| 96 | if ne get g_a3 i get s i |
| 97 | ret false |
| 98 | end |
| 99 | end |
| 100 | ret true |
| 101 | end |
| 102 | |
| 103 | fn parse_a2 to ulong |
| 104 | n = get g_al 2 |
| 105 | v = ulong 0 |
| 106 | for i ulong n |
| 107 | c = ulong get g_a2 i |
| 108 | if and ge c 48 le c 57 |
| 109 | v = add mul v 10 sub c 48 |
| 110 | else |
| 111 | break |
| 112 | end |
| 113 | end |
| 114 | ret v |
| 115 | end |
| 116 | |
| 117 | fn emit_edge t ulong en ulong ok ulong ovf ulong to void |
| 118 | os t_s1 |
| 119 | ou t |
| 120 | os t_s2 |
| 121 | ou ok |
| 122 | os t_s3 |
| 123 | ou ovf |
| 124 | os t_s4 |
| 125 | ou en |
| 126 | os t_s5 |
| 127 | end |
| 128 | |
| 129 | fn emit_part tag uchar st ulong orac ulong mux ulong to void |
| 130 | os t_p1 |
| 131 | ob tag |
| 132 | os t_p2 |
| 133 | ou orac |
| 134 | os t_p3 |
| 135 | ou st |
| 136 | os t_p4 |
| 137 | ou add st 1000000 |
| 138 | os t_p5 |
| 139 | ou add st 999000000 |
| 140 | os t_p6 |
| 141 | ou add st 999000001 |
| 142 | os t_p7 |
| 143 | rv = ulong 1000 |
| 144 | if ne mux 0 |
| 145 | rv = 0 |
| 146 | end |
| 147 | for j ulong 6 |
| 148 | if gt j 0 |
| 149 | os t_comma |
| 150 | end |
| 151 | ou rv |
| 152 | end |
| 153 | os t_p8 |
| 154 | end |
| 155 | |
| 156 | fn main to long |
| 157 | if ne argcnt 4 |
| 158 | ret 64 |
| 159 | end |
| 160 | l1 = argread 1 g_a1 0 64 |
| 161 | l2 = argread 2 g_a2 0 64 |
| 162 | l3 = argread 3 g_a3 0 64 |
| 163 | if or lt l1 0 or lt l2 0 lt l3 0 |
| 164 | ret 64 |
| 165 | end |
| 166 | put g_al 1 ulong l1 |
| 167 | put g_al 2 ulong l2 |
| 168 | put g_al 3 ulong l3 |
| 169 | st = parse_a2 |
| 170 | ok = ulong 1 |
| 171 | if a3_eq t_sensor |
| 172 | ok = 0 |
| 173 | end |
| 174 | end_e = ulong 1100000 |
| 175 | if a3_eq t_wrap |
| 176 | end_e = 999999 |
| 177 | end |
| 178 | ovf = ulong 0 |
| 179 | if a3_eq t_ovf |
| 180 | ovf = 1 |
| 181 | end |
| 182 | orac = ulong 1 |
| 183 | if a3_eq t_oracle |
| 184 | orac = 0 |
| 185 | end |
| 186 | mux = ulong 0 |
| 187 | if a3_eq t_mux |
| 188 | mux = 1 |
| 189 | end |
| 190 | os t_h1 |
| 191 | for i ulong get g_al 1 |
| 192 | ob get g_a1 i |
| 193 | end |
| 194 | os t_h2 |
| 195 | emit_edge st 1000000 ok 0 |
| 196 | os t_h3 |
| 197 | emit_edge add st 1000000000 end_e ok ovf |
| 198 | os t_h4 |
| 199 | for i ulong 10 |
| 200 | if gt i 0 |
| 201 | os t_comma |
| 202 | end |
| 203 | ou add st mul add i 1 100000000 |
| 204 | end |
| 205 | os t_h5 |
| 206 | if not a1_eq t_idle |
| 207 | for i ulong get g_al 1 |
| 208 | if gt i 0 |
| 209 | os t_comma |
| 210 | end |
| 211 | emit_part get g_a1 i st orac mux |
| 212 | end |
| 213 | end |
| 214 | os t_h6 |
| 215 | _w = write 1 g_out 0 get g_ol 0 |
| 216 | ret 0 |
| 217 | end |