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 / tools / reservoir / res_bench.om

2013 lines · 50170 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3note Gate 2 benchmark (bench-narma, bench-lorenz) and performance (perf) protocol.
4note Concatenated after reservoir.om, res_inflate.om, res_mat.om, res_common.om.
5
6const RB_NSEED_MAX ulong 16
7const RB_NM ulong 3
8const RB_NPW ulong 100
9const RB_N_TRAIN ulong 2000
10const RB_N_TEST ulong 1000
11const RB_WASHOUT ulong 100
12const RB_NDELAY ulong 12
13
14const RB_LZ_DISCARD ulong 200000
15const RB_LZ_POINTS ulong 200001
16const RB_LZ_SAMPLE ulong 100
17const RB_LZ_NS ulong 2001
18const RB_LZ_ROW0 ulong 200
19const RB_LZ_ROW1 ulong 1975
20const RB_LZ_NROW ulong 1776
21const RB_LZ_LAGS ulong 5
22
23const RB_PERF_WARM ulong 10000
24const RB_PERF_STEPS ulong 40000
25const RB_PERF_REPS ulong 5
26
27note Benchmark global storage (up to 16 seeds)
28note Per-run record: 332 uints = [0]=st, [1..2]=stopped(lo,hi), [3..132]=rc(130), [133..332]=ms(200) -> stride 336
29const RB_RUN_STRIDE ulong 336
30note Per-fit record: 10 ulongs = [0]=st, [1]=nf, [2]=lam, [3]=cv, [4..6]=test[0..2], [7..9]=train[0..2]
31const RB_FIT_STRIDE ulong 10
32
33global rb_n_runs uint 43008
34global rb_n_fits ulong 2880
35global rb_n_masks uint 1024
36global rb_n_nd uint 32
37global rb_n_nodes uint 64
38global rb_u0 f64 2000
39global rb_u1 f64 1000
40global rb_ny f64 12000
41global rb_nxr0 f64 *
42global rb_nxr1 f64 *
43global rb_nxb0 f64 *
44global rb_nxb1 f64 *
45global rb_cur_drv uint 64
46global rb_cur_mask uint 192
47
48global rb_l_runs uint 21504
49global rb_l_fits ulong 2880
50global rb_l_ic f64 96
51global rb_l_nodes uint 32
52global rb_lx0 f64 *
53global rb_lx1 f64 *
54global rb_lxl0 f64 *
55global rb_lxl1 f64 *
56global rb_lxs0 f64 *
57global rb_lxs1 f64 *
58global rb_lxb0 f64 *
59global rb_lxb1 f64 *
60global rb_ly f64 *
61
62global rb_lat ulong 200000
63
64note JSON strings
65text rb_s_run0 "{\"run\": \""
66text rb_s_run1 "\", \"status\": \""
67text rb_s_run2 "\", \"run_id\": "
68text rb_s_run3 ", \"config_id\": "
69text rb_s_run4 ", \"steps\": "
70text rb_s_run5 "\", \"stopped_at_step\": "
71text rb_s_fit0 "{\"model\": \""
72text rb_s_fit1 "\", \"task\": \""
73text rb_s_fit2 "\", \"features\": "
74text rb_s_fit3 ", \"status\": \""
75text rb_s_fit4 "\", \"lambda\": "
76text rb_s_fit5 ", \"cv_score\": "
77text rb_s_fit6 ", \"test_nrmse\": ["
78text rb_s_fit7 "], \"train_nrmse\": ["
79text rb_s_fit8 "]}"
80text rb_s_st0 "{\"seeds_ok\": "
81text rb_s_st1 ", \"mean\": "
82text rb_s_st2 ", \"sd\": "
83text rb_s_st3 ", \"min\": "
84text rb_s_st4 ", \"max\": "
85text rb_s_pr0 "{\"comparison\": \""
86text rb_s_pr1 "\", \"difference\": "
87text rb_s_pr2 ", \"first_wins\": "
88text rb_s_pr3 ", \"seeds_compared\": "
89text rb_s_comma ", "
90text rb_s_nl_c ",\n"
91
92text rb_nm0 "RC-connected"
93text rb_nm1 "RC-disconnected"
94text rb_nm2 "BL-linear"
95text rb_nm3 "BL-quadratic"
96text rb_nm4 "RC-connected-5 (post hoc)"
97text rb_nm5 "RC-disconnected-5 (post hoc)"
98text rb_nt0 "NARMA-2"
99text rb_nt1 "NARMA-5"
100text rb_nt2 "NARMA-10"
101text rb_nr0 "chain50 connected/train"
102text rb_nr1 "chain50 connected/test"
103text rb_nr2 "chain50 disconnected/train"
104text rb_nr3 "chain50 disconnected/test"
105text rb_nr4 "chain5 connected/train"
106text rb_nr5 "chain5 connected/test"
107text rb_nr6 "chain5 disconnected/train"
108text rb_nr7 "chain5 disconnected/test"
109
110text rb_lm0 "RC-connected-lin"
111text rb_lm1 "RC-connected-sq"
112text rb_lm2 "RC-disconnected-lin"
113text rb_lm3 "RC-disconnected-sq"
114text rb_lm4 "BL-linear"
115text rb_lm5 "BL-quadratic"
116text rb_lt0 "T0"
117text rb_lt1 "T1"
118text rb_lt2 "T25"
119text rb_lr0 "connected/train"
120text rb_lr1 "connected/test"
121text rb_lr2 "disconnected/train"
122text rb_lr3 "disconnected/test"
123
124text rb_bn_hdr "{\n \"schema\": \"omega-reservoir-bench-narma/1\",\n \"protocol\": \"RESERVOIR_REFERENCE.md section 10\",\n \"seeds\": "
125text rb_bn_s0 ",\n \"setup\": {\"train_inputs\": 2000, \"test_inputs\": 1000, \"washout\": 100, \"subpulses\": 3, \"subpulse_s\": 1e-3, \"current_hi_a\": 1e-10, \"delay_line\": 12, \"lambda_grid\": [1e-6, 1e2, 9], \"folds\": 5,\n \"networks\": [{\"name\": \"Length50 chain (declared)\", \"driven_nodes\": "
126text rb_bn_s1 ", \"nodes_connected\": "
127text rb_bn_s2 ", \"nodes_disconnected\": "
128text rb_bn_s3 "}, {\"name\": \"Length5 chain (post hoc, section 10.1)\", \"driven_nodes\": "
129text rb_bn_s4 "}],\n \"rc_squared_states\": \"NOT_RUN (50-node chain: 295 features > readout bound 256)\"},\n \"wall_s\": "
130text rb_bn_s5 ",\n \"per_seed\": ["
131text rb_bn_sd0 "\n {\"seed\": "
132text rb_bn_sd1 ", \"runs\": ["
133text rb_bn_sd2 "],\n \"mask_starts\": ["
134text rb_bn_sd3 "],\n \"fits\": ["
135text rb_bn_sd4 ",\n "
136text rb_bn_sum0 "\n ],\n \"summary\": ["
137text rb_bn_sum1 "\n {\"task\": \""
138text rb_bn_sum2 "\", \"test_nrmse\": {"
139text rb_bn_sum3 "},\n \"paired\": ["
140text rb_bn_end "\n ],\n \"significance\": \"none claimed (five seeds)\"\n}\n"
141
142text rb_bp0 "RC-connected - RC-disconnected"
143text rb_bp1 "RC-connected - best baseline (by CV score)"
144text rb_bp2 "RC-connected-5 - RC-disconnected-5 (post hoc)"
145text rb_bp3 "RC-connected-5 - best baseline (by CV score) (post hoc)"
146
147text rb_bl_hdr "{\n \"schema\": \"omega-reservoir-bench-lorenz/1\",\n \"protocol\": \"RESERVOIR_REFERENCE.md section 10\",\n \"seeds\": "
148text rb_bl_s0 ",\n \"setup\": {\"dt\": 1e-4, \"discard_s\": 20, \"record_s\": 20, \"sample_s\": 0.01, \"rows\": [200, 1975], \"horizons_samples\": [0, 1, 25], \"lags\": 5, \"lambda_grid\": [1e-6, 1e2, 9], \"folds\": 5, \"nodes_connected\": "
149text rb_bl_s1 ", \"nodes_disconnected\": "
150text rb_bl_s2 "},\n \"wall_s\": "
151text rb_bl_ic0 ", \"initial_state\": {\"train\": ["
152text rb_bl_ic1 "], \"test\": ["
153text rb_bl_ic2 "]}, \"runs\": ["
154text rb_bl_sum2 "\", \"test_nrmse_mean_over_xyz\": {"
155text rb_lp0 "RC-connected-lin - RC-disconnected-lin"
156text rb_lp1 "RC-connected-sq - RC-disconnected-sq"
157text rb_lp2 "RC-connected-lin - best baseline (by CV score)"
158text rb_lp3 "RC-connected-sq - best baseline (by CV score)"
159
160text rb_pf_hdr "{\n \"schema\": \"omega-reservoir-perf/1\",\n \"protocol\": \"RESERVOIR_REFERENCE.md section 10\",\n \"host\": {\"sysname\": \"Linux\", \"machine\": \"aarch64\"},\n \"compiler\": \"omega-om2-seeded\",\n \"timer\": {\"clock\": \"CLOCK_MONOTONIC\", \"mean_call_ns\": "
161text rb_pf_s0 ", \"included_in_latency\": true},\n \"struct_bytes\": {\"OmegaResConfig\": 21452, \"OmegaResState\": 3728, \"OmegaResWorkspace\": 14256, \"OmegaResTopology\": 2056, \"OmegaResReadout\": 8248, \"OmegaResReadoutWorkspace\": 538672},\n \"warmup_steps\": 10000, \"timed_steps\": 40000, \"repetitions\": 5,\n \"networks\": ["
162text rb_pf_n0 "chain5 NARMA (G2-N1)"
163text rb_pf_n1 "chain50 NARMA"
164text rb_pf_n2 "hex43 Lorenz"
165text rb_pf_j0 "\n {\"network\": \""
166text rb_pf_j1 "\", \"nodes\": "
167text rb_pf_j2 ", \"membranes\": "
168text rb_pf_j3 ", \"status\": \""
169text rb_pf_j4 "\", \"per_repetition\": ["
170text rb_pf_j5 "{\"p50_ns\": "
171text rb_pf_j6 ", \"p95_ns\": "
172text rb_pf_j7 ", \"p99_ns\": "
173text rb_pf_j8 ", \"max_ns\": "
174text rb_pf_j9 ", \"steps_per_s\": "
175text rb_pf_ja "], \"pooled\": {\"p50_ns\": "
176text rb_pf_jb "}, \"steps_per_s\": "
177text rb_pf_jc ", \"simulated_s_per_wall_s\": "
178text rb_pf_end "\n ],\n \"energy\": \"NOT_RUN (not instrumented; no efficiency claim)\"\n}\n"
179
180note ================================================================
181note Common benchmark helpers
182note ================================================================
183
184fn rb_stream seed int purpose ulong dst edit ulong 1 to void
185 put dst 0 or shl ulong bitcast uint seed 32 purpose
186end
187
188fn rb_grid_init g edit f64 9 to void
189 put g 0 1.0e-6f64
190 put g 1 1.0e-5f64
191 put g 2 1.0e-4f64
192 put g 3 1.0e-3f64
193 put g 4 1.0e-2f64
194 put g 5 1.0e-1f64
195 put g 6 1.0f64
196 put g 7 10.0f64
197 put g 8 100.0f64
198end
199
200fn rb_store_run dst_which uint slot ulong st int rc view uint 130 ms view uint 200 to void
201 base = mul slot RB_RUN_STRIDE
202 stp = rc_sim_get_step
203 if eq dst_which 0
204 put rb_n_runs base bitcast uint st
205 put rb_n_runs add base 1 uint and stp 0xffffffff
206 put rb_n_runs add base 2 uint shr stp 32
207 for i ulong 130 bound 130
208 put rb_n_runs add add base 3 i get rc i
209 end
210 for i ulong 200 bound 200
211 put rb_n_runs add add base 133 i get ms i
212 end
213 else
214 put rb_l_runs base bitcast uint st
215 put rb_l_runs add base 1 uint and stp 0xffffffff
216 put rb_l_runs add base 2 uint shr stp 32
217 for i ulong 130 bound 130
218 put rb_l_runs add add base 3 i get rc i
219 end
220 for i ulong 200 bound 200
221 put rb_l_runs add add base 133 i get ms i
222 end
223 end
224end
225
226fn rb_run_get which uint idx ulong to uint
227 if eq which 0
228 ret get rb_n_runs idx
229 end
230 ret get rb_l_runs idx
231end
232
233fn rb_run_json_ok which uint base ulong to void
234 rid = new uint 32 0
235 cid = new uint 32 0
236 for i ulong 32 bound 32
237 put rid i rb_run_get which add add base 101 i
238 put cid i rb_run_get which add add base 3 i
239 end
240 rc_puts rb_s_run2
241 rc_jhex_u32 view rid
242 rc_puts rb_s_run3
243 rc_jhex_u32 view cid
244 rc_puts rb_s_run4
245 slo = ulong rb_run_get which add base 99
246 shi = ulong rb_run_get which add base 100
247 rc_put_u64 or shl shi 32 slo
248end
249
250fn rb_run_json_ms which uint base ulong to void
251 ms = new uint 200 0
252 for i ulong 200 bound 200
253 put ms i rb_run_get which add add base 133 i
254 end
255 rc_mstats_json view ms
256end
257
258fn rb_run_json which uint slot ulong name view uchar * to void
259 base = mul slot RB_RUN_STRIDE
260 st = bitcast int rb_run_get which base
261 rc_puts rb_s_run0
262 rc_puts name
263 rc_puts rb_s_run1
264 rc_status_puts st
265 if eq st RES_OK
266 rb_run_json_ok which base
267 else
268 rc_puts rb_s_run5
269 slo = ulong rb_run_get which add base 1
270 shi = ulong rb_run_get which add base 2
271 rc_put_u64 or shl shi 32 slo
272 end
273 rb_run_json_ms which base
274 rc_putc uchar 125
275end
276
277fn rb_fit_refused which uint slot ulong st int nf ulong to void
278 base = mul slot RB_FIT_STRIDE
279 nanb = ulong 0x7ff8000000000000
280 if eq which 0
281 put rb_n_fits base ulong bitcast uint st
282 put rb_n_fits add base 1 nf
283 for i ulong 8 bound 8
284 put rb_n_fits add add base 2 i nanb
285 end
286 else
287 put rb_l_fits base ulong bitcast uint st
288 put rb_l_fits add base 1 nf
289 for i ulong 8 bound 8
290 put rb_l_fits add add base 2 i nanb
291 end
292 end
293end
294
295fn rb_fit_put which uint idx ulong val ulong to void
296 if eq which 0
297 put rb_n_fits idx val
298 else
299 put rb_l_fits idx val
300 end
301end
302
303fn rb_fit_store which uint slot ulong cvm view ulong 5 cv_res view ulong 3 to void
304 base = mul slot RB_FIT_STRIDE
305 st = bitcast int uint get cv_res 0
306 nanb = ulong 0x7ff8000000000000
307 rb_fit_put which base get cv_res 0
308 rb_fit_put which add base 1 get cvm 2
309 rb_fit_put which add base 2 get cv_res 1
310 rb_fit_put which add base 3 get cv_res 2
311 no = get cvm 3
312 for c ulong no bound 3
313 if eq st RES_OK
314 vte = bitcast ulong rc_nrmse_y_p 1 get cvm 1 no c
315 vtr = bitcast ulong rc_nrmse_y_p 0 get cvm 0 no c
316 rb_fit_put which add add base 4 c vte
317 rb_fit_put which add add base 7 c vtr
318 else
319 rb_fit_put which add add base 4 c nanb
320 rb_fit_put which add add base 7 c nanb
321 end
322 end
323end
324
325fn rb_fit_run which uint slot ulong ntr ulong nte ulong nf ulong no ulong to void
326 grid = new f64 9 0.0f64
327 rb_grid_init grid
328 cvm = new ulong 5 0
329 put cvm 0 ntr
330 put cvm 1 nte
331 put cvm 2 nf
332 put cvm 3 no
333 put cvm 4 5
334 cv_res = new ulong 3 0
335 rc_ridge_cv view cvm view grid cv_res
336 rb_fit_store which slot view cvm view cv_res
337end
338
339fn rb_fit_json_body which uint slot ulong no ulong to void
340 base = mul slot RB_FIT_STRIDE
341 f = new ulong 10 0
342 for i ulong 10 bound 10
343 if eq which 0
344 put f i get rb_n_fits add base i
345 else
346 put f i get rb_l_fits add base i
347 end
348 end
349 rc_puts rb_s_fit2
350 rc_put_u64 get f 1
351 rc_puts rb_s_fit3
352 rc_status_puts bitcast int uint get f 0
353 rc_puts rb_s_fit4
354 rc_put_f64 bitcast f64 get f 2 10
355 rc_puts rb_s_fit5
356 rc_put_f64 bitcast f64 get f 3 10
357 rc_puts rb_s_fit6
358 for c ulong no bound 3
359 if gt c 0
360 rc_puts rb_s_comma
361 end
362 rc_put_f64 bitcast f64 get f add 4 c 10
363 end
364 rc_puts rb_s_fit7
365 for c ulong no bound 3
366 if gt c 0
367 rc_puts rb_s_comma
368 end
369 rc_put_f64 bitcast f64 get f add 7 c 10
370 end
371 rc_puts rb_s_fit8
372end
373
374fn rb_stat_json vals view f64 16 n ulong to void
375 cnt = ulong 0
376 sum = 0.0f64
377 mn = bitcast f64 ulong 0x7ff0000000000000
378 mx = bitcast f64 ulong 0xfff0000000000000
379 for i ulong n bound 16
380 v = get vals i
381 if eq v v
382 sum = add sum v
383 if lt v mn
384 mn = v
385 end
386 if gt v mx
387 mx = v
388 end
389 cnt = add cnt 1
390 end
391 end
392 nanv = bitcast f64 ulong 0x7ff8000000000000
393 mean = nanv
394 sd = nanv
395 if gt cnt 0
396 mean = div sum f64 cnt
397 if gt cnt 1
398 q = 0.0f64
399 for i ulong n bound 16
400 v = get vals i
401 if eq v v
402 d = sub v mean
403 q = add q mul d d
404 end
405 end
406 sd = fsqrt div q f64 sub cnt 1
407 end
408 else
409 mn = nanv
410 mx = nanv
411 end
412 rc_puts rb_s_st0
413 rc_put_u64 cnt
414 rc_puts rb_s_st1
415 rc_put_f64 mean 10
416 rc_puts rb_s_st2
417 rc_put_f64 sd 10
418 rc_puts rb_s_st3
419 rc_put_f64 mn 10
420 rc_puts rb_s_st4
421 rc_put_f64 mx 10
422 rc_putc uchar 125
423end
424
425fn rb_paired_json name view uchar * a view f64 16 b view f64 16 n ulong to void
426 d = new f64 16 0.0f64
427 wins = ulong 0
428 both = ulong 0
429 for i ulong n bound 16
430 di = sub get a i get b i
431 put d i di
432 if eq di di
433 both = add both 1
434 if lt get a i get b i
435 wins = add wins 1
436 end
437 end
438 end
439 rc_puts rb_s_pr0
440 rc_puts name
441 rc_puts rb_s_pr1
442 rb_stat_json view d n
443 rc_puts rb_s_pr2
444 rc_put_u64 wins
445 rc_puts rb_s_pr3
446 rc_put_u64 both
447 rc_putc uchar 125
448end
449
450note ================================================================
451note bench-narma
452note ================================================================
453
454fn rb_narma_fill_knot base ulong sb ulong on f32 off f32 nd ulong to void
455 for d ulong nd bound 64
456 dv = ulong get rb_cur_drv d
457 mv = get rb_cur_mask add mul d RB_NM sb
458 if ne mv 0
459 put rc_tab add base dv on
460 else
461 put rc_tab add base dv off
462 end
463 end
464end
465
466fn rb_narma_fill_one_k sp ulong n ulong nd ulong nc ulong k ulong to void
467 j = div k 10
468 if ge j mul n RB_NM
469 j = sub mul n RB_NM 1
470 end
471 c = div j RB_NM
472 uc = 0.0f64
473 if eq sp 0
474 uc = get rb_u0 c
475 else
476 uc = get rb_u1 c
477 end
478 on = mul mul 2.0f64 uc 1.0e-10f64
479 rb_narma_fill_knot mul k nc rem j RB_NM f32 on f32 sub 1.0e-10f64 on nd
480end
481
482fn rb_narma_fill_tab sp ulong n ulong nd ulong nc ulong to ulong
483 kn = add mul mul n RB_NM 10 1
484 _e = enlarge rc_tab mul kn nc
485 for i ulong mul kn nc bound 4000000
486 put rc_tab i 0.0f32
487 end
488 for k ulong kn bound 70000
489 rb_narma_fill_one_k sp n nd nc k
490 end
491 ret kn
492end
493
494fn rb_narma_extract_d sp ulong cm1 ulong rbase ulong nc ulong d ulong to void
495 dv = ulong get rb_cur_drv d
496 for k ulong RB_NM bound 3
497 vidx = add mul add mul cm1 RB_NM k nc dv
498 val = get rc_vout vidx
499 dst = add rbase add mul d RB_NM k
500 if eq sp 0
501 put rb_nxr0 dst val
502 else
503 put rb_nxr1 dst val
504 end
505 end
506end
507
508fn rb_narma_extract_row sp ulong r ulong rbase ulong nc ulong nd ulong to void
509 cm1 = sub add RB_WASHOUT r 1
510 for d ulong nd bound 64
511 rb_narma_extract_d sp cm1 rbase nc d
512 end
513 if eq sp 0
514 put rb_nxr0 add rbase mul nd RB_NM get rb_u0 cm1
515 else
516 put rb_nxr1 add rbase mul nd RB_NM get rb_u1 cm1
517 end
518end
519
520fn rb_narma_extract_xr sp ulong nr ulong nfr ulong nc ulong nd ulong to void
521 if eq sp 0
522 _e = enlarge rb_nxr0 mul nr nfr
523 else
524 _e = enlarge rb_nxr1 mul nr nfr
525 end
526 for r ulong nr bound 2000
527 rb_narma_extract_row sp r mul r nfr nc nd
528 end
529end
530
531fn rb_narma_prep_sim sp ulong nd ulong nc ulong smeta edit uint 4 to void
532 n = RB_N_TRAIN
533 if eq sp 1
534 n = RB_N_TEST
535 end
536 nsteps = mul n RB_NM
537 _e = enlarge rc_steps nsteps
538 for j ulong nsteps bound 6000
539 put rc_steps j mul add j 1 RB_NPW
540 end
541 _e = enlarge rc_vout mul nsteps nc
542 kn = rb_narma_fill_tab sp n nd nc
543 put smeta 0 RES_INIT_N0
544 put smeta 1 0
545 put smeta 2 uint kn
546 put smeta 3 uint nsteps
547end
548
549note sinfo: [0]=si [1]=net [2]=m [3]=sp [4]=nd
550fn rb_narma_sim_one sinfo view ulong 5 t view uint 514 p view uint 265 to int
551 smeta = new uint 4 0
552 rb_narma_prep_sim get sinfo 3 get sinfo 4 ulong get t 0 smeta
553 rc = new uint 130 0
554 ms = new uint 200 0
555 st = rc_simulate_run t p view smeta rc ms
556 slot = add mul get sinfo 0 8 mul get sinfo 1 4
557 slot = add slot add mul get sinfo 2 2 get sinfo 3
558 rb_store_run 0 slot st view rc view ms
559 if eq st RES_OK
560 nr = sub RB_N_TRAIN RB_WASHOUT
561 if eq get sinfo 3 1
562 nr = sub RB_N_TEST RB_WASHOUT
563 end
564 rb_narma_extract_xr get sinfo 3 nr add mul get sinfo 4 RB_NM 1 ulong get t 0 get sinfo 4
565 end
566 ret st
567end
568
569fn rb_narma_load_y ord_i ulong to void
570 ntr = sub RB_N_TRAIN RB_WASHOUT
571 nte = sub RB_N_TEST RB_WASHOUT
572 _e = enlarge rc_ytr ntr
573 _e = enlarge rc_yte nte
574 b0 = add mul ord_i 4000 RB_WASHOUT
575 b1 = add add mul ord_i 4000 2000 RB_WASHOUT
576 for r ulong ntr bound 2000
577 put rc_ytr r get rb_ny add b0 r
578 end
579 for r ulong nte bound 1000
580 put rc_yte r get rb_ny add b1 r
581 end
582end
583
584fn rb_narma_fit_ok fbase ulong nfr ulong to void
585 ntr = sub RB_N_TRAIN RB_WASHOUT
586 nte = sub RB_N_TEST RB_WASHOUT
587 _e = enlarge rc_xtr mul ntr nfr
588 _e = enlarge rc_xte mul nte nfr
589 for i ulong mul ntr nfr bound 400000
590 put rc_xtr i get rb_nxr0 i
591 end
592 for i ulong mul nte nfr bound 200000
593 put rc_xte i get rb_nxr1 i
594 end
595 for o ulong 3 bound 3
596 rb_narma_load_y o
597 rb_fit_run 0 add fbase o ntr nte nfr 1
598 end
599end
600
601fn rb_narma_fit_net si ulong net ulong m ulong nfr ulong st0 int st1 int to void
602 mid = m
603 if eq net 1
604 mid = add 4 m
605 end
606 fbase = add mul si 18 mul mid 3
607 if or ne st0 RES_OK ne st1 RES_OK
608 es = st0
609 if eq es RES_OK
610 es = st1
611 end
612 for o ulong 3 bound 3
613 rb_fit_refused 0 add fbase o es nfr
614 end
615 ret
616 end
617 rb_narma_fit_ok fbase nfr
618end
619
620fn rb_narma_disc_fail si ulong net ulong nd ulong dst int to void
621 rc = new uint 130 0
622 ms = new uint 200 0
623 rb_store_run 0 add mul si 8 add mul net 4 2 dst view rc view ms
624 rb_store_run 0 add mul si 8 add mul net 4 3 dst view rc view ms
625 rb_narma_fit_net si net 1 add mul nd RB_NM 1 dst dst
626end
627
628fn rb_narma_run_disc si ulong net ulong conc view f32 64 nd ulong to void
629 td = new uint 514 0
630 pd = new uint 265 0
631 for d ulong nd bound 64
632 put rb_cur_drv d uint d
633 end
634 dst = rc_net_disconnected RES_REF_NARMA conc uint nd td pd
635 if ne dst RES_OK
636 put rb_n_nodes add mul si 4 add mul net 2 1 0
637 rb_narma_disc_fail si net nd dst
638 ret
639 end
640 put rb_n_nodes add mul si 4 add mul net 2 1 get td 0
641 sinfo = new ulong 5 0
642 put sinfo 0 si
643 put sinfo 1 net
644 put sinfo 2 1
645 put sinfo 3 0
646 put sinfo 4 nd
647 st0 = rb_narma_sim_one view sinfo view td view pd
648 put sinfo 3 1
649 st1 = rb_narma_sim_one view sinfo view td view pd
650 rb_narma_fit_net si net 1 add mul nd RB_NM 1 st0 st1
651end
652
653fn rb_narma_run_net si ulong net ulong to void
654 tc = new uint 514 0
655 pc = new uint 265 0
656 inp = new uint 3 0
657 gr = new uint 1 4
658 if eq net 0
659 _st = rc_net_topology RC_NET_CHAIN50 tc inp gr
660 else
661 _st = res_topology_chain 5 4 tc
662 end
663 _st = res_params_reference RES_REF_NARMA get tc 0 pc
664 conc = new f32 64 0.0f32
665 nd = ulong 0
666 for i ulong ulong get tc 0 bound 64
667 if ne uint i get gr 0
668 put rb_cur_drv nd uint i
669 put conc nd bitcast f32 get pc add RES_PAR_CONC i
670 nd = add nd 1
671 end
672 end
673 put rb_n_nd add mul si 2 net uint nd
674 put rb_n_nodes add mul si 4 mul net 2 get tc 0
675 sinfo = new ulong 5 0
676 put sinfo 0 si
677 put sinfo 1 net
678 put sinfo 2 0
679 put sinfo 3 0
680 put sinfo 4 nd
681 st0 = rb_narma_sim_one view sinfo view tc view pc
682 put sinfo 3 1
683 st1 = rb_narma_sim_one view sinfo view tc view pc
684 rb_narma_fit_net si net 0 add mul nd RB_NM 1 st0 st1
685 rb_narma_run_disc si net view conc nd
686end
687
688fn rb_narma_quad_p0 rb ulong ob ulong i ulong k_in ulong to ulong
689 k = k_in
690 ai = get rb_nxb0 add rb i
691 for j ulong sub RB_NDELAY i bound 12
692 aj = get rb_nxb0 add rb add i j
693 put rc_xtr add ob k mul ai aj
694 k = add k 1
695 end
696 ret k
697end
698
699fn rb_narma_quad_p1 rb ulong ob ulong i ulong k_in ulong to ulong
700 k = k_in
701 ai = get rb_nxb1 add rb i
702 for j ulong sub RB_NDELAY i bound 12
703 aj = get rb_nxb1 add rb add i j
704 put rc_xte add ob k mul ai aj
705 k = add k 1
706 end
707 ret k
708end
709
710fn rb_narma_quad_row which uint r ulong nfq ulong to void
711 rb = mul r RB_NDELAY
712 ob = mul r nfq
713 k = ulong 0
714 for i ulong RB_NDELAY bound 12
715 if eq which 0
716 put rc_xtr add ob k get rb_nxb0 add rb i
717 else
718 put rc_xte add ob k get rb_nxb1 add rb i
719 end
720 k = add k 1
721 end
722 for i ulong RB_NDELAY bound 12
723 if eq which 0
724 k = rb_narma_quad_p0 rb ob i k
725 else
726 k = rb_narma_quad_p1 rb ob i k
727 end
728 end
729end
730
731fn rb_narma_fill_delay which uint nr ulong to void
732 for r ulong nr bound 2000
733 base = mul r RB_NDELAY
734 c0 = sub add RB_WASHOUT r 1
735 for i ulong RB_NDELAY bound 12
736 if eq which 0
737 put rc_xtr add base i get rb_u0 sub c0 i
738 else
739 put rc_xte add base i get rb_u1 sub c0 i
740 end
741 end
742 end
743end
744
745fn rb_narma_baselines si ulong to void
746 ntr = sub RB_N_TRAIN RB_WASHOUT
747 nte = sub RB_N_TEST RB_WASHOUT
748 nfq = add RB_NDELAY div mul RB_NDELAY add RB_NDELAY 1 2
749 _e = enlarge rc_xtr mul ntr RB_NDELAY
750 _e = enlarge rc_xte mul nte RB_NDELAY
751 rb_narma_fill_delay 0 ntr
752 rb_narma_fill_delay 1 nte
753 for o ulong 3 bound 3
754 rb_narma_load_y o
755 rb_fit_run 0 add mul si 18 add 6 o ntr nte RB_NDELAY 1
756 end
757 _e = enlarge rb_nxb0 mul ntr RB_NDELAY
758 _e = enlarge rb_nxb1 mul nte RB_NDELAY
759 for i ulong mul ntr RB_NDELAY bound 30000
760 put rb_nxb0 i get rc_xtr i
761 end
762 for i ulong mul nte RB_NDELAY bound 15000
763 put rb_nxb1 i get rc_xte i
764 end
765 _e = enlarge rc_xtr mul ntr nfq
766 _e = enlarge rc_xte mul nte nfq
767 for r ulong ntr bound 2000
768 rb_narma_quad_row 0 r nfq
769 end
770 for r ulong nte bound 1000
771 rb_narma_quad_row 1 r nfq
772 end
773 for o ulong 3 bound 3
774 rb_narma_load_y o
775 rb_fit_run 0 add mul si 18 add 9 o ntr nte nfq 1
776 end
777end
778
779fn rb_narma_gen_targets to void
780 u0 = new f64 2000 0.0f64
781 u1 = new f64 1000 0.0f64
782 for i ulong 2000 bound 2000
783 put u0 i get rb_u0 i
784 end
785 for i ulong 1000 bound 1000
786 put u1 i get rb_u1 i
787 end
788 ords = new uint 3 0
789 put ords 0 2
790 put ords 1 5
791 put ords 2 10
792 y0 = new f64 2000 0.0f64
793 y1 = new f64 1000 0.0f64
794 for o ulong 3 bound 3
795 rc_narma_g view u0 2000 get ords o y0
796 rc_narma_g view u1 1000 get ords o y1
797 b0 = mul o 4000
798 b1 = add b0 2000
799 for i ulong 2000 bound 2000
800 put rb_ny add b0 i get y0 i
801 end
802 for i ulong 1000 bound 1000
803 put rb_ny add b1 i get y1 i
804 end
805 end
806end
807
808fn rb_narma_init_mask si ulong seed int to void
809 rm = new ulong 1 0
810 rb_stream seed 3 rm
811 db = new uint 4 0
812 put db 2 1
813 put db 3 1
814 for d ulong 64 bound 64
815 ms = rem rc_rng_next rm 4
816 put rb_n_masks add mul si 64 d uint ms
817 for k ulong RB_NM bound 3
818 v = get db rem add ms k 4
819 put rb_cur_mask add mul d RB_NM k v
820 end
821 end
822end
823
824fn rb_narma_seed si ulong seed int to void
825 r0 = new ulong 1 0
826 r1 = new ulong 1 0
827 rb_stream seed 1 r0
828 rb_stream seed 2 r1
829 for i ulong RB_N_TRAIN bound 2000
830 put rb_u0 i mul 0.5f64 rc_rng_unit r0
831 end
832 for i ulong RB_N_TEST bound 1000
833 put rb_u1 i mul 0.5f64 rc_rng_unit r1
834 end
835 rb_narma_init_mask si seed
836 rb_narma_gen_targets
837 rb_narma_run_net si 0
838 rb_narma_run_net si 1
839 rb_narma_baselines si
840end
841
842fn rb_narma_model_name m ulong to void
843 if eq m 0
844 rc_puts rb_nm0
845 ret
846 end
847 if eq m 1
848 rc_puts rb_nm1
849 ret
850 end
851 if eq m 2
852 rc_puts rb_nm2
853 ret
854 end
855 if eq m 3
856 rc_puts rb_nm3
857 ret
858 end
859 if eq m 4
860 rc_puts rb_nm4
861 ret
862 end
863 rc_puts rb_nm5
864end
865
866fn rb_narma_fit_emit si ulong m ulong t ulong to void
867 slot = add mul si 18 add mul m 3 t
868 rc_puts rb_s_fit0
869 rb_narma_model_name m
870 rc_puts rb_s_fit1
871 if eq t 0
872 rc_puts rb_nt0
873 else
874 if eq t 1
875 rc_puts rb_nt1
876 else
877 rc_puts rb_nt2
878 end
879 end
880 rb_fit_json_body 0 slot 1
881end
882
883fn rb_narma_emit_seed si ulong seed int to void
884 if gt si 0
885 rc_putc uchar 44
886 end
887 rc_puts rb_bn_sd0
888 rc_put_i64 long seed
889 rc_puts rb_bn_sd1
890 b = mul si 8
891 rb_run_json 0 b rb_nr0
892 rc_puts rb_s_comma
893 rb_run_json 0 add b 1 rb_nr1
894 rc_puts rb_s_comma
895 rb_run_json 0 add b 2 rb_nr2
896 rc_puts rb_s_comma
897 rb_run_json 0 add b 3 rb_nr3
898 rc_puts rb_s_comma
899 rb_run_json 0 add b 4 rb_nr4
900 rc_puts rb_s_comma
901 rb_run_json 0 add b 5 rb_nr5
902 rc_puts rb_s_comma
903 rb_run_json 0 add b 6 rb_nr6
904 rc_puts rb_s_comma
905 rb_run_json 0 add b 7 rb_nr7
906 rc_puts rb_bn_sd2
907 nd0 = ulong get rb_n_nd mul si 2
908 for d ulong nd0 bound 64
909 if gt d 0
910 rc_puts rb_s_comma
911 end
912 rc_put_u64 ulong get rb_n_masks add mul si 64 d
913 end
914 rc_puts rb_bn_sd3
915 for m ulong 6 bound 6
916 for t ulong 3 bound 3
917 if or gt m 0 gt t 0
918 rc_puts rb_bn_sd4
919 end
920 rb_narma_fit_emit si m t
921 end
922 end
923 rc_putc uchar 93
924 rc_putc uchar 125
925end
926
927fn rb_narma_fill_best_bl ns ulong t ulong bst edit f64 16 to void
928 for i ulong ns bound 16
929 sa = mul add mul i 18 add 6 t RB_FIT_STRIDE
930 sb = mul add mul i 18 add 9 t RB_FIT_STRIDE
931 sta = bitcast int uint get rb_n_fits sa
932 stb = bitcast int uint get rb_n_fits sb
933 cva = bitcast f64 get rb_n_fits add sa 3
934 cvb = bitcast f64 get rb_n_fits add sb 3
935 use_b = false
936 if eq stb RES_OK
937 if or ne sta RES_OK lt cvb cva
938 use_b = true
939 end
940 end
941 if use_b
942 put bst i bitcast f64 get rb_n_fits add sb 4
943 else
944 put bst i bitcast f64 get rb_n_fits add sa 4
945 end
946 end
947end
948
949fn rb_narma_collect_m ns ulong m ulong t ulong dst edit f64 16 to void
950 for i ulong ns bound 16
951 slot = add mul i 18 add mul m 3 t
952 put dst i bitcast f64 get rb_n_fits add mul slot RB_FIT_STRIDE 4
953 end
954end
955
956fn rb_narma_emit_summary ns ulong t ulong to void
957 if gt t 0
958 rc_putc uchar 44
959 end
960 rc_puts rb_bn_sum1
961 if eq t 0
962 rc_puts rb_nt0
963 else
964 if eq t 1
965 rc_puts rb_nt1
966 else
967 rc_puts rb_nt2
968 end
969 end
970 rc_puts rb_bn_sum2
971 v0 = new f64 16 0.0f64
972 v1 = new f64 16 0.0f64
973 v4 = new f64 16 0.0f64
974 v5 = new f64 16 0.0f64
975 bst = new f64 16 0.0f64
976 vm = new f64 16 0.0f64
977 for m ulong 6 bound 6
978 rb_narma_collect_m ns m t vm
979 if gt m 0
980 rc_puts rb_s_comma
981 end
982 rc_putc uchar 34
983 rb_narma_model_name m
984 rc_putc uchar 34
985 rc_putc uchar 58
986 rc_putc uchar 32
987 rb_stat_json view vm ns
988 end
989 rb_narma_collect_m ns 0 t v0
990 rb_narma_collect_m ns 1 t v1
991 rb_narma_collect_m ns 4 t v4
992 rb_narma_collect_m ns 5 t v5
993 rb_narma_fill_best_bl ns t bst
994 rc_puts rb_bn_sum3
995 rb_paired_json rb_bp0 view v0 view v1 ns
996 rc_puts rb_s_comma
997 rb_paired_json rb_bp1 view v0 view bst ns
998 rc_puts rb_s_comma
999 rb_paired_json rb_bp2 view v4 view v5 ns
1000 rc_puts rb_s_comma
1001 rb_paired_json rb_bp3 view v4 view bst ns
1002 rc_putc uchar 93
1003 rc_putc uchar 125
1004end
1005
1006fn rb_bench_narma seeds view int 16 ns ulong to int
1007 t0 = rc_now_s
1008 for i ulong ns bound 16
1009 rb_narma_seed i get seeds i
1010 end
1011 wall = sub rc_now_s t0
1012 rc_puts rb_bn_hdr
1013 rc_putc uchar 91
1014 for i ulong ns bound 16
1015 if gt i 0
1016 rc_puts rb_s_comma
1017 end
1018 rc_put_i64 long get seeds i
1019 end
1020 rc_putc uchar 93
1021 rc_puts rb_bn_s0
1022 rc_put_u64 ulong get rb_n_nd 0
1023 rc_puts rb_bn_s1
1024 rc_put_u64 ulong get rb_n_nodes 0
1025 rc_puts rb_bn_s2
1026 rc_put_u64 ulong get rb_n_nodes 1
1027 rc_puts rb_bn_s3
1028 rc_put_u64 ulong get rb_n_nd 1
1029 rc_puts rb_bn_s1
1030 rc_put_u64 ulong get rb_n_nodes 2
1031 rc_puts rb_bn_s2
1032 rc_put_u64 ulong get rb_n_nodes 3
1033 rc_puts rb_bn_s4
1034 rc_put_f64_1 wall
1035 rc_puts rb_bn_s5
1036 for i ulong ns bound 16
1037 rb_narma_emit_seed i get seeds i
1038 end
1039 rc_puts rb_bn_sum0
1040 for t ulong 3 bound 3
1041 rb_narma_emit_summary ns t
1042 end
1043 rc_puts rb_bn_end
1044 rc_flush
1045 ret 0
1046end
1047
1048note ================================================================
1049note bench-lorenz & perf
1050note ================================================================
1051
1052fn rb_lz_deriv s view f64 3 d edit f64 3 to void
1053 s0 = get s 0
1054 s1 = get s 1
1055 s2 = get s 2
1056 put d 0 mul 10.0f64 sub s1 s0
1057 put d 1 sub mul s0 sub 28.0f64 s2 s1
1058 put d 2 sub mul s0 s1 mul div 8.0f64 3.0f64 s2
1059end
1060
1061fn rb_lz_rk4 s edit f64 3 to void
1062 k1 = new f64 3 0.0f64
1063 k2 = new f64 3 0.0f64
1064 k3 = new f64 3 0.0f64
1065 k4 = new f64 3 0.0f64
1066 t = new f64 3 0.0f64
1067 rb_lz_deriv view s k1
1068 for i ulong 3 bound 3
1069 put t i add get s i mul mul 0.5f64 1.0e-4f64 get k1 i
1070 end
1071 rb_lz_deriv view t k2
1072 for i ulong 3 bound 3
1073 put t i add get s i mul mul 0.5f64 1.0e-4f64 get k2 i
1074 end
1075 rb_lz_deriv view t k3
1076 for i ulong 3 bound 3
1077 put t i add get s i mul 1.0e-4f64 get k3 i
1078 end
1079 rb_lz_deriv view t k4
1080 c6 = div 1.0e-4f64 6.0f64
1081 for i ulong 3 bound 3
1082 sv = add get k1 i get k4 i
1083 sv = add sv mul 2.0f64 add get k2 i get k3 i
1084 put s i add get s i mul c6 sv
1085 end
1086end
1087
1088fn rb_lz_current v f64 c ulong to f64
1089 if lt c 2
1090 ret div add mul v 1.05e-10f64 1.0e-9f64 10.0f64
1091 end
1092 ret div mul mul v 1.0e-10f64 2.05f64 10.0f64
1093end
1094
1095fn rb_lz_horizon h ulong to ulong
1096 if eq h 0
1097 ret 0
1098 end
1099 if eq h 1
1100 ret 1
1101 end
1102 ret 25
1103end
1104
1105fn rb_lz_init_state si ulong sp ulong seed int s edit f64 3 to void
1106 r = new ulong 1 0
1107 purp = ulong 4
1108 if ne sp 0
1109 purp = 5
1110 end
1111 rb_stream seed purp r
1112 put s 0 add -10.0f64 mul 20.0f64 rc_rng_unit r
1113 put s 1 add -10.0f64 mul 20.0f64 rc_rng_unit r
1114 put s 2 add 10.0f64 mul 30.0f64 rc_rng_unit r
1115 icb = add mul si 6 mul sp 3
1116 for c ulong 3 bound 3
1117 put rb_l_ic add icb c get s c
1118 end
1119end
1120
1121fn rb_lz_record_traj sp ulong s edit f64 3 to void
1122 if eq sp 0
1123 _e = enlarge rb_lx0 mul RB_LZ_POINTS 3
1124 for k ulong RB_LZ_POINTS bound 200001
1125 b = mul k 3
1126 put rb_lx0 b get s 0
1127 put rb_lx0 add b 1 get s 1
1128 put rb_lx0 add b 2 get s 2
1129 rb_lz_rk4 s
1130 end
1131 else
1132 _e = enlarge rb_lx1 mul RB_LZ_POINTS 3
1133 for k ulong RB_LZ_POINTS bound 200001
1134 b = mul k 3
1135 put rb_lx1 b get s 0
1136 put rb_lx1 add b 1 get s 1
1137 put rb_lx1 add b 2 get s 2
1138 rb_lz_rk4 s
1139 end
1140 end
1141end
1142
1143fn rb_lz_gen_traj si ulong sp ulong seed int to void
1144 s = new f64 3 0.0f64
1145 rb_lz_init_state si sp seed s
1146 for k ulong RB_LZ_DISCARD bound 200000
1147 rb_lz_rk4 s
1148 end
1149 rb_lz_record_traj sp s
1150end
1151
1152fn rb_lz_get_x sp ulong idx ulong to f64
1153 if eq sp 0
1154 ret get rb_lx0 idx
1155 end
1156 ret get rb_lx1 idx
1157end
1158
1159fn rb_lz_build_target_hs h ulong sp ulong to void
1160 hor = rb_lz_horizon h
1161 base = mul add mul h 2 sp mul RB_LZ_NROW 3
1162 for r ulong RB_LZ_NROW bound 1776
1163 idx = mul mul add add RB_LZ_ROW0 r hor RB_LZ_SAMPLE 3
1164 dst = add base mul r 3
1165 put rb_ly dst rb_lz_get_x sp idx
1166 put rb_ly add dst 1 rb_lz_get_x sp add idx 1
1167 put rb_ly add dst 2 rb_lz_get_x sp add idx 2
1168 end
1169end
1170
1171fn rb_lz_build_targets to void
1172 _e = enlarge rb_ly mul 6 mul RB_LZ_NROW 3
1173 for h ulong 3 bound 3
1174 rb_lz_build_target_hs h 0
1175 rb_lz_build_target_hs h 1
1176 end
1177end
1178
1179fn rb_lz_load_y h ulong to void
1180 _e = enlarge rc_ytr mul RB_LZ_NROW 3
1181 _e = enlarge rc_yte mul RB_LZ_NROW 3
1182 n3 = mul RB_LZ_NROW 3
1183 b0 = mul mul h 2 n3
1184 b1 = add b0 n3
1185 for i ulong n3 bound 6000
1186 put rc_ytr i get rb_ly add b0 i
1187 put rc_yte i get rb_ly add b1 i
1188 end
1189end
1190
1191fn rb_lz_fill_tab_k sp ulong k ulong nc ulong drv view uint 3 to void
1192 tbase = mul k nc
1193 xbase = mul k 3
1194 for c ulong 3 bound 3
1195 v = rb_lz_get_x sp add xbase c
1196 put rc_tab add tbase ulong get drv c f32 rb_lz_current v c
1197 end
1198end
1199
1200fn rb_lz_fill_tab sp ulong nc ulong drv view uint 3 to void
1201 total = mul RB_LZ_POINTS nc
1202 _e = enlarge rc_tab total
1203 for i ulong total bound 10000000
1204 put rc_tab i 0.0f32
1205 end
1206 for k ulong RB_LZ_POINTS bound 200001
1207 rb_lz_fill_tab_k sp k nc drv
1208 end
1209end
1210
1211fn rb_lz_extract_xl_m0 sp ulong r ulong nc ulong g uint nfl ulong to void
1212 f = ulong 0
1213 rbase = mul r nfl
1214 vbase = mul add RB_LZ_ROW0 r nc
1215 for i ulong nc bound 64
1216 if ne uint i g
1217 val = get rc_vout add vbase i
1218 if eq sp 0
1219 put rb_lxl0 add rbase f val
1220 else
1221 put rb_lxl1 add rbase f val
1222 end
1223 f = add f 1
1224 end
1225 end
1226end
1227
1228fn rb_lz_extract_xl_m1 sp ulong r ulong nc ulong to void
1229 rbase = mul r 3
1230 vbase = mul add RB_LZ_ROW0 r nc
1231 for i ulong 3 bound 3
1232 val = get rc_vout add vbase i
1233 if eq sp 0
1234 put rb_lxl0 add rbase i val
1235 else
1236 put rb_lxl1 add rbase i val
1237 end
1238 end
1239end
1240
1241fn rb_lz_extract_xl m ulong sp ulong nc ulong g uint nfl ulong to void
1242 if eq sp 0
1243 _e = enlarge rb_lxl0 mul RB_LZ_NROW nfl
1244 else
1245 _e = enlarge rb_lxl1 mul RB_LZ_NROW nfl
1246 end
1247 for r ulong RB_LZ_NROW bound 1776
1248 if eq m 0
1249 rb_lz_extract_xl_m0 sp r nc g nfl
1250 else
1251 rb_lz_extract_xl_m1 sp r nc
1252 end
1253 end
1254end
1255
1256fn rb_lz_build_xs_row sp ulong r ulong nfl ulong to void
1257 nf2 = mul nfl 2
1258 sb = mul r nfl
1259 db = mul r nf2
1260 for i ulong nfl bound 64
1261 if eq sp 0
1262 v = get rb_lxl0 add sb i
1263 put rb_lxs0 add db i v
1264 put rb_lxs0 add add db nfl i mul v v
1265 else
1266 v = get rb_lxl1 add sb i
1267 put rb_lxs1 add db i v
1268 put rb_lxs1 add add db nfl i mul v v
1269 end
1270 end
1271end
1272
1273fn rb_lz_build_xs sp ulong nfl ulong to void
1274 nf2 = mul nfl 2
1275 if eq sp 0
1276 _e = enlarge rb_lxs0 mul RB_LZ_NROW nf2
1277 else
1278 _e = enlarge rb_lxs1 mul RB_LZ_NROW nf2
1279 end
1280 for r ulong RB_LZ_NROW bound 1776
1281 rb_lz_build_xs_row sp r nfl
1282 end
1283end
1284
1285fn rb_lz_prep_sim sp ulong nc ulong drv view uint 3 smeta edit uint 4 to void
1286 _e = enlarge rc_steps RB_LZ_NS
1287 for j ulong RB_LZ_NS bound 2001
1288 put rc_steps j mul j mul RB_LZ_SAMPLE 10
1289 end
1290 _e = enlarge rc_vout mul RB_LZ_NS nc
1291 rb_lz_fill_tab sp nc drv
1292 put smeta 0 RES_INIT_CONST
1293 put smeta 1 bitcast uint 1.0f32
1294 put smeta 2 uint RB_LZ_POINTS
1295 put smeta 3 uint RB_LZ_NS
1296end
1297
1298fn rb_lz_sim_one si ulong m ulong sp ulong t view uint 514 p view uint 265 drv view uint 3 to int
1299 smeta = new uint 4 0
1300 rb_lz_prep_sim sp ulong get t 0 drv smeta
1301 rc = new uint 130 0
1302 ms = new uint 200 0
1303 st = rc_simulate_run t p view smeta rc ms
1304 slot = add mul si 4 add mul m 2 sp
1305 rb_store_run 1 slot st view rc view ms
1306 ret st
1307end
1308
1309fn rb_lz_load_x_res q ulong nf ulong to void
1310 tot = mul RB_LZ_NROW nf
1311 _e = enlarge rc_xtr tot
1312 _e = enlarge rc_xte tot
1313 for i ulong tot bound 200000
1314 if eq q 0
1315 put rc_xtr i get rb_lxl0 i
1316 put rc_xte i get rb_lxl1 i
1317 else
1318 put rc_xtr i get rb_lxs0 i
1319 put rc_xte i get rb_lxs1 i
1320 end
1321 end
1322end
1323
1324fn rb_lz_fit_res_q fbase ulong q ulong nf ulong ok bool es int to void
1325 if ok
1326 rb_lz_load_x_res q nf
1327 end
1328 for h ulong 3 bound 3
1329 slot = add fbase h
1330 if not ok
1331 rb_fit_refused 1 slot es nf
1332 else
1333 rb_lz_load_y h
1334 rb_fit_run 1 slot RB_LZ_NROW RB_LZ_NROW nf 3
1335 end
1336 end
1337end
1338
1339fn rb_lz_fit_res si ulong m ulong nfl ulong st0 int st1 int to void
1340 ok = and eq st0 RES_OK eq st1 RES_OK
1341 es = st0
1342 if eq es RES_OK
1343 es = st1
1344 end
1345 fb0 = add mul si 18 mul mul m 2 3
1346 rb_lz_fit_res_q fb0 0 nfl ok es
1347 rb_lz_fit_res_q add fb0 3 1 mul nfl 2 ok es
1348end
1349
1350fn rb_lz_run_conn si ulong tc view uint 514 pc view uint 265 inp view uint 3 g uint to void
1351 nc = ulong get tc 0
1352 nfl = sub nc 1
1353 st0 = rb_lz_sim_one si 0 0 tc pc inp
1354 if eq st0 RES_OK
1355 rb_lz_extract_xl 0 0 nc g nfl
1356 rb_lz_build_xs 0 nfl
1357 end
1358 st1 = rb_lz_sim_one si 0 1 tc pc inp
1359 if eq st1 RES_OK
1360 rb_lz_extract_xl 0 1 nc g nfl
1361 rb_lz_build_xs 1 nfl
1362 end
1363 rb_lz_fit_res si 0 nfl st0 st1
1364end
1365
1366fn rb_lz_disc_fail si ulong dst int to void
1367 rc = new uint 130 0
1368 ms = new uint 200 0
1369 rb_store_run 1 add mul si 4 2 dst view rc view ms
1370 rb_store_run 1 add mul si 4 3 dst view rc view ms
1371 rb_lz_fit_res si 1 3 dst dst
1372end
1373
1374fn rb_lz_run_disc si ulong conc view f32 64 to void
1375 td = new uint 514 0
1376 pd = new uint 265 0
1377 dst = rc_net_disconnected RES_REF_LORENZ conc 3 td pd
1378 if ne dst RES_OK
1379 put rb_l_nodes add mul si 2 1 0
1380 rb_lz_disc_fail si dst
1381 ret
1382 end
1383 put rb_l_nodes add mul si 2 1 get td 0
1384 drvd = new uint 3 0
1385 put drvd 1 1
1386 put drvd 2 2
1387 nc = ulong get td 0
1388 st0 = rb_lz_sim_one si 1 0 view td view pd view drvd
1389 if eq st0 RES_OK
1390 rb_lz_extract_xl 1 0 nc 0 3
1391 rb_lz_build_xs 0 3
1392 end
1393 st1 = rb_lz_sim_one si 1 1 view td view pd view drvd
1394 if eq st1 RES_OK
1395 rb_lz_extract_xl 1 1 nc 0 3
1396 rb_lz_build_xs 1 3
1397 end
1398 rb_lz_fit_res si 1 3 st0 st1
1399end
1400
1401fn rb_lz_fill_xb_row sp ulong r ulong to void
1402 rb = mul r 15
1403 for l ulong RB_LZ_LAGS bound 5
1404 xb = mul mul sub add RB_LZ_ROW0 r l RB_LZ_SAMPLE 3
1405 db = add rb mul l 3
1406 if eq sp 0
1407 put rb_lxb0 db rb_lz_get_x sp xb
1408 put rb_lxb0 add db 1 rb_lz_get_x sp add xb 1
1409 put rb_lxb0 add db 2 rb_lz_get_x sp add xb 2
1410 else
1411 put rb_lxb1 db rb_lz_get_x sp xb
1412 put rb_lxb1 add db 1 rb_lz_get_x sp add xb 1
1413 put rb_lxb1 add db 2 rb_lz_get_x sp add xb 2
1414 end
1415 end
1416end
1417
1418fn rb_lz_fill_xb sp ulong to void
1419 if eq sp 0
1420 _e = enlarge rb_lxb0 mul RB_LZ_NROW 15
1421 else
1422 _e = enlarge rb_lxb1 mul RB_LZ_NROW 15
1423 end
1424 for r ulong RB_LZ_NROW bound 1776
1425 rb_lz_fill_xb_row sp r
1426 end
1427end
1428
1429fn rb_lz_quad_pair which uint rb ulong ob ulong i ulong k_in ulong to ulong
1430 k = k_in
1431 ai = 0.0f64
1432 if eq which 0
1433 ai = get rb_lxb0 add rb i
1434 else
1435 ai = get rb_lxb1 add rb i
1436 end
1437 for j ulong sub 15 i bound 15
1438 if eq which 0
1439 aj = get rb_lxb0 add rb add i j
1440 put rc_xtr add ob k mul ai aj
1441 else
1442 aj = get rb_lxb1 add rb add i j
1443 put rc_xte add ob k mul ai aj
1444 end
1445 k = add k 1
1446 end
1447 ret k
1448end
1449
1450fn rb_lz_quad_row which uint r ulong nfq ulong to void
1451 rb = mul r 15
1452 ob = mul r nfq
1453 k = ulong 0
1454 for i ulong 15 bound 15
1455 if eq which 0
1456 put rc_xtr add ob k get rb_lxb0 add rb i
1457 else
1458 put rc_xte add ob k get rb_lxb1 add rb i
1459 end
1460 k = add k 1
1461 end
1462 for i ulong 15 bound 15
1463 k = rb_lz_quad_pair which rb ob i k
1464 end
1465end
1466
1467fn rb_lz_baselines si ulong to void
1468 rb_lz_fill_xb 0
1469 rb_lz_fill_xb 1
1470 nlin = mul RB_LZ_NROW 15
1471 _e = enlarge rc_xtr nlin
1472 _e = enlarge rc_xte nlin
1473 for i ulong nlin bound 30000
1474 put rc_xtr i get rb_lxb0 i
1475 put rc_xte i get rb_lxb1 i
1476 end
1477 for h ulong 3 bound 3
1478 rb_lz_load_y h
1479 rb_fit_run 1 add mul si 18 add 12 h RB_LZ_NROW RB_LZ_NROW 15 3
1480 end
1481 nfq = ulong 135
1482 _e = enlarge rc_xtr mul RB_LZ_NROW nfq
1483 _e = enlarge rc_xte mul RB_LZ_NROW nfq
1484 for r ulong RB_LZ_NROW bound 1776
1485 rb_lz_quad_row 0 r nfq
1486 rb_lz_quad_row 1 r nfq
1487 end
1488 for h ulong 3 bound 3
1489 rb_lz_load_y h
1490 rb_fit_run 1 add mul si 18 add 15 h RB_LZ_NROW RB_LZ_NROW nfq 3
1491 end
1492end
1493
1494fn rb_lorenz_seed si ulong seed int to void
1495 rb_lz_gen_traj si 0 seed
1496 rb_lz_gen_traj si 1 seed
1497 rb_lz_build_targets
1498 tc = new uint 514 0
1499 pc = new uint 265 0
1500 inp = new uint 3 0
1501 gr = new uint 1 0
1502 _st = rc_net_topology RC_NET_HEX43 tc inp gr
1503 _st = res_params_reference RES_REF_LORENZ get tc 0 pc
1504 conc = new f32 64 0.0f32
1505 for c ulong 3 bound 3
1506 put conc c bitcast f32 get pc add RES_PAR_CONC ulong get inp c
1507 end
1508 put rb_l_nodes mul si 2 get tc 0
1509 rb_lz_run_conn si view tc view pc view inp get gr 0
1510 rb_lz_run_disc si view conc
1511 rb_lz_baselines si
1512end
1513
1514fn rb_lz_model_name m ulong to void
1515 if eq m 0
1516 rc_puts rb_lm0
1517 ret
1518 end
1519 if eq m 1
1520 rc_puts rb_lm1
1521 ret
1522 end
1523 if eq m 2
1524 rc_puts rb_lm2
1525 ret
1526 end
1527 if eq m 3
1528 rc_puts rb_lm3
1529 ret
1530 end
1531 if eq m 4
1532 rc_puts rb_lm4
1533 ret
1534 end
1535 rc_puts rb_lm5
1536end
1537
1538fn rb_lz_task_name t ulong to void
1539 if eq t 0
1540 rc_puts rb_lt0
1541 ret
1542 end
1543 if eq t 1
1544 rc_puts rb_lt1
1545 ret
1546 end
1547 rc_puts rb_lt2
1548end
1549
1550fn rb_lz_fit_emit si ulong m ulong t ulong to void
1551 slot = add mul si 18 add mul m 3 t
1552 rc_puts rb_s_fit0
1553 rb_lz_model_name m
1554 rc_puts rb_s_fit1
1555 rb_lz_task_name t
1556 rb_fit_json_body 1 slot 3
1557end
1558
1559fn rb_lz_emit_seed si ulong seed int to void
1560 if gt si 0
1561 rc_putc uchar 44
1562 end
1563 rc_puts rb_bn_sd0
1564 rc_put_i64 long seed
1565 rc_puts rb_bl_ic0
1566 icb = mul si 6
1567 for c ulong 3 bound 3
1568 if gt c 0
1569 rc_puts rb_s_comma
1570 end
1571 rc_put_f64 get rb_l_ic add icb c 10
1572 end
1573 rc_puts rb_bl_ic1
1574 for c ulong 3 bound 3
1575 if gt c 0
1576 rc_puts rb_s_comma
1577 end
1578 rc_put_f64 get rb_l_ic add add icb 3 c 10
1579 end
1580 rc_puts rb_bl_ic2
1581 b = mul si 4
1582 rb_run_json 1 b rb_lr0
1583 rc_puts rb_s_comma
1584 rb_run_json 1 add b 1 rb_lr1
1585 rc_puts rb_s_comma
1586 rb_run_json 1 add b 2 rb_lr2
1587 rc_puts rb_s_comma
1588 rb_run_json 1 add b 3 rb_lr3
1589 rc_puts rb_bn_sd3
1590 for m ulong 6 bound 6
1591 for t ulong 3 bound 3
1592 if or gt m 0 gt t 0
1593 rc_puts rb_bn_sd4
1594 end
1595 rb_lz_fit_emit si m t
1596 end
1597 end
1598 rc_putc uchar 93
1599 rc_putc uchar 125
1600end
1601
1602fn rb_lz_fit_mean_slot slot ulong to f64
1603 base = mul slot RB_FIT_STRIDE
1604 s = 0.0f64
1605 for c ulong 3 bound 3
1606 s = add s bitcast f64 get rb_l_fits add add base 4 c
1607 end
1608 ret div s 3.0f64
1609end
1610
1611fn rb_lz_collect_m ns ulong m ulong t ulong dst edit f64 16 to void
1612 for i ulong ns bound 16
1613 slot = add mul i 18 add mul m 3 t
1614 put dst i rb_lz_fit_mean_slot slot
1615 end
1616end
1617
1618fn rb_lz_best_bl_one i ulong t ulong to f64
1619 sa_slot = add mul i 18 add 12 t
1620 sb_slot = add mul i 18 add 15 t
1621 sa = mul sa_slot RB_FIT_STRIDE
1622 sb = mul sb_slot RB_FIT_STRIDE
1623 if eq bitcast int uint get rb_l_fits sb RES_OK
1624 if ne bitcast int uint get rb_l_fits sa RES_OK
1625 ret rb_lz_fit_mean_slot sb_slot
1626 end
1627 if lt bitcast f64 get rb_l_fits add sb 3 bitcast f64 get rb_l_fits add sa 3
1628 ret rb_lz_fit_mean_slot sb_slot
1629 end
1630 end
1631 ret rb_lz_fit_mean_slot sa_slot
1632end
1633
1634fn rb_lz_fill_best_bl ns ulong t ulong bst edit f64 16 to void
1635 for i ulong ns bound 16
1636 put bst i rb_lz_best_bl_one i t
1637 end
1638end
1639
1640fn rb_lz_emit_summary ns ulong t ulong to void
1641 if gt t 0
1642 rc_putc uchar 44
1643 end
1644 rc_puts rb_bn_sum1
1645 rb_lz_task_name t
1646 rc_puts rb_bl_sum2
1647 v0 = new f64 16 0.0f64
1648 v1 = new f64 16 0.0f64
1649 v2 = new f64 16 0.0f64
1650 v3 = new f64 16 0.0f64
1651 bst = new f64 16 0.0f64
1652 vm = new f64 16 0.0f64
1653 for m ulong 6 bound 6
1654 rb_lz_collect_m ns m t vm
1655 if gt m 0
1656 rc_puts rb_s_comma
1657 end
1658 rc_putc uchar 34
1659 rb_lz_model_name m
1660 rc_putc uchar 34
1661 rc_putc uchar 58
1662 rc_putc uchar 32
1663 rb_stat_json view vm ns
1664 end
1665 rb_lz_collect_m ns 0 t v0
1666 rb_lz_collect_m ns 1 t v1
1667 rb_lz_collect_m ns 2 t v2
1668 rb_lz_collect_m ns 3 t v3
1669 rb_lz_fill_best_bl ns t bst
1670 rc_puts rb_bn_sum3
1671 rb_paired_json rb_lp0 view v0 view v2 ns
1672 rc_puts rb_s_comma
1673 rb_paired_json rb_lp1 view v1 view v3 ns
1674 rc_puts rb_s_comma
1675 rb_paired_json rb_lp2 view v0 view bst ns
1676 rc_puts rb_s_comma
1677 rb_paired_json rb_lp3 view v1 view bst ns
1678 rc_putc uchar 93
1679 rc_putc uchar 125
1680end
1681
1682fn rb_bench_lorenz seeds view int 16 ns ulong to int
1683 t0 = rc_now_s
1684 for i ulong ns bound 16
1685 rb_lorenz_seed i get seeds i
1686 end
1687 wall = sub rc_now_s t0
1688 rc_puts rb_bl_hdr
1689 rc_putc uchar 91
1690 for i ulong ns bound 16
1691 if gt i 0
1692 rc_puts rb_s_comma
1693 end
1694 rc_put_i64 long get seeds i
1695 end
1696 rc_putc uchar 93
1697 rc_puts rb_bl_s0
1698 rc_put_u64 ulong get rb_l_nodes 0
1699 rc_puts rb_bl_s1
1700 rc_put_u64 ulong get rb_l_nodes 1
1701 rc_puts rb_bl_s2
1702 rc_put_f64_1 wall
1703 rc_puts rb_bn_s5
1704 for i ulong ns bound 16
1705 rb_lz_emit_seed i get seeds i
1706 end
1707 rc_puts rb_bn_sum0
1708 for t ulong 3 bound 3
1709 rb_lz_emit_summary ns t
1710 end
1711 rc_puts rb_bn_end
1712 rc_flush
1713 ret 0
1714end
1715
1716fn rb_pct_u64 base ulong n ulong p f64 to ulong
1717 k = ulong add mul p f64 n 0.999999999f64
1718 if lt k 1
1719 k = 1
1720 end
1721 if gt k n
1722 k = n
1723 end
1724 ret get rb_lat add base sub k 1
1725end
1726
1727fn rb_perf_sort_ins base ulong gap ulong idx ulong to void
1728 tmp = get rb_lat add base idx
1729 j = idx
1730 done = false
1731 while not done bound 200000
1732 if ge j gap
1733 prev = get rb_lat add base sub j gap
1734 if gt prev tmp
1735 put rb_lat add base j prev
1736 j = sub j gap
1737 else
1738 done = true
1739 end
1740 else
1741 done = true
1742 end
1743 end
1744 put rb_lat add base j tmp
1745end
1746
1747fn rb_perf_sort_slice base ulong n ulong to void
1748 gap = div n 2
1749 while gt gap 0 bound 32
1750 for i ulong sub n gap bound 200000
1751 rb_perf_sort_ins base gap add gap i
1752 end
1753 gap = div gap 2
1754 end
1755end
1756
1757fn rb_perf_fill_narma_k base ulong nc ulong g uint i_node f64 r edit ulong 1 to void
1758 for i ulong nc bound 64
1759 if eq uint i g
1760 put rc_tab add base i 0.0f32
1761 else
1762 v = f32 mul i_node sub mul 2.0f64 rc_rng_unit r 1.0f64
1763 put rc_tab add base i v
1764 end
1765 end
1766end
1767
1768fn rb_perf_copy_prev base ulong pbase ulong nc ulong to void
1769 for i ulong nc bound 64
1770 put rc_tab add base i get rc_tab add pbase i
1771 end
1772end
1773
1774fn rb_perf_fill_lz_k base ulong inp view uint 3 s view f64 3 to void
1775 for c ulong 3 bound 3
1776 dst = add base ulong get inp c
1777 val = f32 rb_lz_current get s c c
1778 put rc_tab dst val
1779 end
1780end
1781
1782fn rb_perf_fill_tab ni ulong nc ulong g uint inp view uint 3 knots ulong to void
1783 _e = enlarge rc_tab mul knots nc
1784 for i ulong mul knots nc bound 2000000
1785 put rc_tab i 0.0f32
1786 end
1787 i_node = div 1.0e-10f64 f64 sub nc 1
1788 r = new ulong 1 0
1789 rb_stream 1 6 r
1790 s = new f64 3 0.0f64
1791 put s 0 1.0f64
1792 put s 1 1.0f64
1793 put s 2 20.0f64
1794 for k ulong knots bound 30000
1795 base = mul k nc
1796 if eq ni 2
1797 rb_perf_fill_lz_k base inp view s
1798 rb_lz_rk4 s
1799 else
1800 if eq rem k 10 0
1801 rb_perf_fill_narma_k base nc g i_node r
1802 else
1803 rb_perf_copy_prev base mul sub k 1 nc nc
1804 end
1805 end
1806 end
1807end
1808
1809fn rb_perf_warm nc ulong to int
1810 cfg = new uint 5363 0
1811 s = new uint 932 0
1812 ws = new uint 3564 0
1813 rc_load_sim cfg s ws
1814 pair = new f32 128 0.0f32
1815 last_k = ulong 0xffffffffffffffff
1816 for k ulong RB_PERF_WARM bound 10000
1817 k64 = div res_state_get_step view s 10
1818 if ne k64 last_k
1819 rc_load_pair nc k64 pair
1820 last_k = k64
1821 end
1822 st = res_step_pair view cfg view pair ws view s
1823 if ne st RES_OK
1824 ret st
1825 end
1826 res_copy_spare_to_state view ws s
1827 end
1828 rc_save_sim view s view ws
1829 ret RES_OK
1830end
1831
1832global rb_perf_meta ulong 3
1833
1834fn rb_perf_record_lat k ulong nw ulong prev ulong to void
1835 put rb_lat add get rb_perf_meta 0 k sub nw prev
1836end
1837
1838fn rb_perf_one_rep nc ulong to f64
1839 cfg = new uint 5363 0
1840 s = new uint 932 0
1841 ws = new uint 3564 0
1842 rc_load_sim cfg s ws
1843 pair = new f32 128 0.0f32
1844 put rb_perf_meta 1 ulong 0xffffffffffffffff
1845 put rb_perf_meta 2 rc_now_ns
1846 prev = get rb_perf_meta 2
1847 for k ulong RB_PERF_STEPS bound 40000
1848 k64 = div res_state_get_step view s 10
1849 if ne k64 get rb_perf_meta 1
1850 rc_load_pair nc k64 pair
1851 put rb_perf_meta 1 k64
1852 end
1853 st = res_step_pair view cfg view pair ws view s
1854 nw = rc_now_ns
1855 rb_perf_record_lat k nw prev
1856 prev = nw
1857 if ne st RES_OK
1858 ret neg f64 st
1859 end
1860 res_copy_spare_to_state view ws s
1861 end
1862 rc_save_sim view s view ws
1863 ret mul f64 sub prev get rb_perf_meta 2 1.0e-9f64
1864end
1865
1866fn rb_perf_measure nc ulong rwall edit f64 5 wall_out edit f64 1 to int
1867 st = rb_perf_warm nc
1868 if ne st RES_OK
1869 ret st
1870 end
1871 w0 = rc_now_ns
1872 for rep ulong RB_PERF_REPS bound 5
1873 put rb_perf_meta 0 mul rep RB_PERF_STEPS
1874 rw = rb_perf_one_rep nc
1875 if lt rw 0.0f64
1876 ret int neg rw
1877 end
1878 put rwall rep rw
1879 end
1880 put wall_out 0 mul f64 sub rc_now_ns w0 1.0e-9f64
1881 ret RES_OK
1882end
1883
1884fn rb_perf_emit_ok rwall view f64 5 wall f64 to void
1885 rc_puts rb_pf_j4
1886 for rep ulong RB_PERF_REPS bound 5
1887 if gt rep 0
1888 rc_puts rb_s_comma
1889 end
1890 b = mul rep RB_PERF_STEPS
1891 rb_perf_sort_slice b RB_PERF_STEPS
1892 rc_puts rb_pf_j5
1893 rc_put_u64 rb_pct_u64 b RB_PERF_STEPS 0.50f64
1894 rc_puts rb_pf_j6
1895 rc_put_u64 rb_pct_u64 b RB_PERF_STEPS 0.95f64
1896 rc_puts rb_pf_j7
1897 rc_put_u64 rb_pct_u64 b RB_PERF_STEPS 0.99f64
1898 rc_puts rb_pf_j8
1899 rc_put_u64 get rb_lat add b sub RB_PERF_STEPS 1
1900 rc_puts rb_pf_j9
1901 rc_put_f64_1 div f64 RB_PERF_STEPS get rwall rep
1902 rc_putc uchar 125
1903 end
1904 nl = mul RB_PERF_STEPS RB_PERF_REPS
1905 rb_perf_sort_slice 0 nl
1906 sps = div f64 nl wall
1907 rc_puts rb_pf_ja
1908 rc_put_u64 rb_pct_u64 0 nl 0.50f64
1909 rc_puts rb_pf_j6
1910 rc_put_u64 rb_pct_u64 0 nl 0.95f64
1911 rc_puts rb_pf_j7
1912 rc_put_u64 rb_pct_u64 0 nl 0.99f64
1913 rc_puts rb_pf_j8
1914 rc_put_u64 get rb_lat sub nl 1
1915 rc_puts rb_pf_jb
1916 rc_put_f64_1 sps
1917 rc_puts rb_pf_jc
1918 rc_put_f64 mul sps 1.0e-5f64 6
1919 rc_putc uchar 125
1920end
1921
1922fn rb_perf_setup ni ulong info edit uint 2 to int
1923 t = new uint 514 0
1924 p = new uint 265 0
1925 inp = new uint 3 0
1926 gr = new uint 1 4
1927 st = RES_OK
1928 if eq ni 0
1929 st = res_topology_chain 5 4 t
1930 if eq st RES_OK
1931 st = res_params_reference RES_REF_NARMA get t 0 p
1932 end
1933 else
1934 if eq ni 1
1935 st = rc_net_topology RC_NET_CHAIN50 t inp gr
1936 if eq st RES_OK
1937 st = res_params_reference RES_REF_NARMA get t 0 p
1938 end
1939 else
1940 st = rc_net_topology RC_NET_HEX43 t inp gr
1941 if eq st RES_OK
1942 st = res_params_reference RES_REF_LORENZ get t 0 p
1943 end
1944 end
1945 end
1946 put info 0 get t 0
1947 put info 1 get t 1
1948 rb_perf_fill_tab ni ulong get t 0 get gr 0 view inp 21001
1949 if eq st RES_OK
1950 if eq ni 2
1951 st = rc_sim_init_globals view t view p RES_INIT_CONST 1.0f32
1952 else
1953 st = rc_sim_init_globals view t view p RES_INIT_N0 0.0f32
1954 end
1955 end
1956 ret st
1957end
1958
1959fn rb_perf_run_net ni ulong to int
1960 info = new uint 2 0
1961 st = rb_perf_setup ni info
1962 rwall = new f64 5 0.0f64
1963 wall_b = new f64 1 0.0f64
1964 if eq st RES_OK
1965 st = rb_perf_measure ulong get info 0 rwall wall_b
1966 end
1967 if gt ni 0
1968 rc_putc uchar 44
1969 end
1970 rc_puts rb_pf_j0
1971 if eq ni 0
1972 rc_puts rb_pf_n0
1973 else
1974 if eq ni 1
1975 rc_puts rb_pf_n1
1976 else
1977 rc_puts rb_pf_n2
1978 end
1979 end
1980 rc_puts rb_pf_j1
1981 rc_put_u64 ulong get info 0
1982 rc_puts rb_pf_j2
1983 rc_put_u64 ulong get info 1
1984 rc_puts rb_pf_j3
1985 rc_status_puts st
1986 if eq st RES_OK
1987 rb_perf_emit_ok view rwall get wall_b 0
1988 ret 0
1989 end
1990 rc_putc uchar 34
1991 rc_putc uchar 125
1992 ret 1
1993end
1994
1995fn rb_perf to int
1996 tc0 = rc_now_ns
1997 for i ulong 100000 bound 100000
1998 _t = rc_now_ns
1999 end
2000 tns = div f64 sub rc_now_ns tc0 100000.0f64
2001 rc_puts rb_pf_hdr
2002 rc_put_f64_1 tns
2003 rc_puts rb_pf_s0
2004 rc = int 0
2005 for ni ulong 3 bound 3
2006 if ne rb_perf_run_net ni 0
2007 rc = 1
2008 end
2009 end
2010 rc_puts rb_pf_end
2011 rc_flush
2012 ret rc
2013end