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 / dagsim / dagsim_cli.om

1012 lines · 21019 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note tools/dagsim/dagsim_cli.om -- Pure seeded OM-2 CLI for the offline resource-DAG evaluator (omega-mv#583).
3note Composed after tools/dagsim/dagsim.om:
4note cat tools/dagsim/dagsim.om tools/dagsim/dagsim_cli.om | seed/out/omc > dagsim
5
6global cli_arg uchar 4096
7global cli_cmd uchar 32
8global cli_cmd_len ulong 1
9global cli_files uchar 16384
10global cli_flens ulong 64
11global cli_nfiles ulong 1
12global cli_changed uchar 256
13global cli_changed_len ulong 1
14global cli_asof long 1
15global cli_has_model ulong 1
16
17global cli_nom_sc ulong 8192
18global cli_nom_rsn uchar 256
19global cli_nom_rsn_len ulong 1
20
21note Pareto row tables (up to 64 rows)
22global pr_status ulong 64
23global pr_t ulong 64
24global pr_lo ulong 64
25global pr_hi ulong 64
26global pr_peak ulong 64
27global pr_e ulong 64
28global pr_emeas ulong 64
29global pr_esyn ulong 64
30global pr_front ulong 64
31global pr_rsn uchar 16384
32global pr_rsn_len ulong 64
33
34note Sensitivity tables (up to 32 resources)
35global sn_cf ulong 32
36global sn_width ulong 32
37global sn_score ulong 32
38global sn_idx ulong 32
39
40text cli_usage "usage: dagsim eval FILE | pareto FILE... | diff BASE TRANSFORMED [--asof YYYY-MM-DD] [--model BLOB] [--changed a,b]\n"
41text cli_need_asof "dagsim: --asof YYYY-MM-DD is required so the run is reproducible (calibration validity is checked against it)\n"
42text cli_bad_asof "bad --asof\n"
43text cli_keval "eval"
44text cli_kpareto "pareto"
45text cli_kdiff "diff"
46text cli_fasof "--asof"
47text cli_fmodel "--model"
48text cli_fchanged "--changed"
49
50text cj_perr1 "{\"schema\": \"oev1\", \"tool\": \"dagsim\", \"file\": "
51text cj_perr2 ", \"status\": \"PARSE_ERROR\", \"reason\": "
52text cj_perr3 "}\n"
53
54text cj_h1 "{\n \"schema\": \"oev1\", \"tool\": \"dagsim\", \"file\": "
55text cj_h2 ",\n \"machine\": "
56text cj_h3 ", \"build_sha\": "
57text cj_h4 ",\n \"calibration\": {\"id\": "
58text cj_h5 ", \"taken_day\": "
59text cj_h6 ", \"valid_days\": "
60text cj_h7 ", \"load1\": "
61text cj_h8 ", \"src\": "
62text cj_h9 "},\n \"asof_day\": "
63text cj_h10 ",\n \"status\": "
64text cj_h11 ", \"reason\": "
65text cj_h12 ",\n \"provenance\": ["
66text cj_h13 "], \"synthetic\": "
67text cj_h14 ", \"offline\": true, \"gpu_executed\": false"
68text cj_end_ref "\n}\n"
69
70text cj_mk1 ",\n \"makespan_ns\": {\"nominal\": "
71text cj_mk2 ", \"lo\": "
72text cj_mk3 ", \"hi\": "
73text cj_mk4 ", \"interval_known\": "
74text cj_true "true"
75text cj_false "false"
76text cj_null "null"
77text cj_comma ", "
78text cj_colon ": "
79text cj_rbrace "}"
80
81text cj_bd1 "},\n \"bounds_ns\": {\"critical_path\": "
82text cj_bd2 ", \"max\": "
83text cj_bd3 ", \"resources\": {"
84text cj_bd4 "}, \"makespan_ge_bounds\": "
85
86text cj_ops1 "},\n \"ops\": ["
87text cj_op_a "\n {\"id\": "
88text cj_op_a2 ",\n {\"id\": "
89text cj_op_s ", \"start_ns\": "
90text cj_op_e ", \"end_ns\": "
91text cj_op_f ", \"floor_ns\": "
92text cj_op_c ", \"contention_ns\": "
93text cj_op_p ", \"prov\": "
94text cj_op_r ", \"src\": "
95
96text cj_cp1 "\n ],\n \"critical_path\": ["
97text cj_pk1 "],\n \"peak_live_bytes\": {"
98text cj_pk2 ": {\"bytes\": "
99text cj_pk3 ", \"at_ns\": "
100text cj_pk4 ", \"cap\": "
101
102text cj_at1 "},\n \"attribution_ns\": {"
103text cj_en1 "},\n \"energy\": {\"status\": "
104text cj_en2 ", \"joules\": "
105text cj_en3 ", \"instrument\": "
106text cj_en4 ", \"boundary\": "
107text cj_en5 ", \"ranking_valid\": "
108
109text cj_co1 "},\n \"conservation\": {\"n_ops\": "
110text cj_co2 ", \"total_bytes\": "
111text cj_co3 ", \"total_busy_ns\": "
112text cj_co4 ", \"total_launch_ns\": "
113text cj_co5 ", \"instrument_overhead_ns\": null}"
114
115text cj_sn1 ",\n \"sensitivities\": ["
116text cj_sn_a "\n {\"resource\": "
117text cj_sn_a2 ",\n {\"resource\": "
118text cj_sn_k ", \"kind\": "
119text cj_sn_m ", \"makespan_if_doubled_ns\": "
120text cj_sn_d ", \"delta_ns\": "
121text cj_sn_w ", \"interval_width_frac\": "
122text cj_sn_s ", \"decision_score\": "
123text cj_sn_n ", \"next_experiment\": "
124
125text cj_tail1 "\n ],\n \"unresolved_residual_ns\": "
126text cj_tail2 ",\n \"note\": \"loaded-box calibration (load1 above); bounds are floors, not predictions; no performance claim from this simulation alone\"\n}\n"
127
128text cj_df1 "{\"tool\": \"dagsim diff\", \"baseline\": "
129text cj_df2 ", \"transformed\": "
130text cj_df3 ", \"status\": "
131text cj_df4 ", \"reason\": "
132text cj_df5 ", \"kept\": "
133text cj_df6 ", \"added\": "
134text cj_df7 ", \"removed\": "
135text cj_df8 ", \"double_counted\": "
136text cj_df9 ", \"required_removed\": "
137text cj_df10 ", \"removed_ns\": {"
138text cj_df11 "}, \"changed\": "
139text cj_df12 "}\n"
140
141text cp_hdr1 "# dagsim pareto: objectives = seconds, peak bytes"
142text cp_hdr_j ", joules"
143text cp_hdr2 ". Energy "
144text cp_hdr_em "measured on every row and part of the dominance test"
145text cp_hdr_en "not measured on every row: shown, never ranked"
146text cp_hdr3 ".\n# file status seconds lo_s hi_s peak_bytes energy front\n"
147text cp_yes "yes"
148text cp_no "no"
149text cp_ref "refused"
150text cp_unm "UNMEASURED"
151text cp_syn "syn "
152text cp_j " J"
153text cp_dash "-"
154text cp_cmt " # "
155
156fn cli_arg_eq s view uchar * n ulong to bool
157if ne n len s
158ret false
159end
160for i ulong n bound 4096
161if ne get cli_arg i get s i
162ret false
163end
164end
165ret true
166end
167
168fn cli_cmd_eq s view uchar * to bool
169n = get cli_cmd_len 0
170if ne n len s
171ret false
172end
173for i ulong n bound 32
174if ne get cli_cmd i get s i
175ret false
176end
177end
178ret true
179end
180
181fn cli_out_fmt_name mode ulong idx ulong to void
182fa = new ulong 16 0
183sn = new uchar 256 0
184put fa 0 idx
185n = dag_fmt mode edit fa edit sn
186ds_out_jstr_buf view sn n
187end
188
189fn cli_out_next_exp rk ulong prov ulong to void
190fa = new ulong 16 0
191sn = new uchar 256 0
192put fa 0 rk
193put fa 1 prov
194nl = dag_fmt 12 edit fa edit sn
195ds_out_jstr_buf view sn nl
196end
197
198fn cli_out_energy_status em ulong es ulong to void
199fa = new ulong 16 0
200sn = new uchar 256 0
201put fa 0 em
202put fa 1 es
203nl = dag_fmt 10 edit fa edit sn
204ds_out_jstr_buf view sn nl
205end
206
207fn cli_out_nom_rsn_jstr to void
208esc = new uchar 6 0
209ds_out_ch uchar 34
210n = get cli_nom_rsn_len 0
211for i ulong n bound 256
212k = dag_jstr get cli_nom_rsn i edit esc
213for j ulong k bound 6
214ds_out_ch get esc j
215end
216end
217ds_out_ch uchar 34
218end
219
220fn cli_out_changed_jstr to void
221esc = new uchar 6 0
222ds_out_ch uchar 34
223n = get cli_changed_len 0
224for i ulong n bound 256
225k = dag_jstr get cli_changed i edit esc
226for j ulong k bound 6
227ds_out_ch get esc j
228end
229end
230ds_out_ch uchar 34
231end
232
233fn cli_out_file_jstr fi ulong to void
234fl = get cli_flens fi
235fb = mul fi 256
236esc = new uchar 6 0
237ds_out_ch uchar 34
238for i ulong fl bound 256
239k = dag_jstr get cli_files add fb i edit esc
240for j ulong k bound 6
241ds_out_ch get esc j
242end
243end
244ds_out_ch uchar 34
245end
246
247fn cli_out_pad count ulong to void
248for i ulong count bound 64
249ds_out_ch uchar 32
250end
251end
252
253fn cli_emit_ops to void
254ds_out_text cj_ops1
255n_ops = get ds_pm 12
256for i ulong n_ops bound 256
257if eq i 0
258ds_out_text cj_op_a
259else
260ds_out_text cj_op_a2
261end
262sp = add 448 mul i 26
263ds_out_jstr_slice_txt 0 get ds_pm sp get ds_pm add sp 1
264ds_out_text cj_op_s
265ds_out_jnum bitcast f64 get cli_nom_sc add 4512 i
266ds_out_text cj_op_e
267ds_out_jnum bitcast f64 get cli_nom_sc add 4768 i
268ds_out_text cj_op_f
269ds_out_jnum bitcast f64 get cli_nom_sc add 5280 i
270ds_out_text cj_op_c
271ds_out_jnum bitcast f64 get cli_nom_sc add 5536 i
272ds_out_text cj_op_p
273kind = get ds_pm add sp 2
274hast = get ds_pm add sp 8
275pv = get ds_pm add sp 7
276if and eq kind 3 eq hast 0
277pv = ulong 2
278end
279cli_out_fmt_name 1 pv
280ds_out_text cj_op_r
281ds_out_jstr_slice_txt 0 get ds_pm add sp 17 get ds_pm add sp 18
282ds_out_text cj_rbrace
283ds_out_flush 1
284end
285end
286
287fn cli_sens_width sp ulong to f64
288rk = get ds_pm add sp 2
289capv = bitcast f64 get ds_pm add sp 4
290w = f64 0.0f64
291if and eq rk 2 gt capv 0.0f64
292w = div sub bitcast f64 get ds_pm add sp 6 bitcast f64 get ds_pm add sp 5 capv
293end
294if eq get ds_pm add sp 7 4
295w = f64 1.0f64
296end
297ret w
298end
299
300fn cli_sens_compute n_res ulong mk f64 asof long hasm ulong qbits ulong to void
301for i ulong n_res bound 32
302cf = ds_counterfactual_idx long i asof hasm qbits
303put sn_cf i bitcast ulong cf
304w = cli_sens_width add 64 mul i 12
305put sn_width i bitcast ulong w
306sc = f64 0.0f64
307if ge cf 0.0f64
308wf = w
309if le wf 0.0f64
310wf = f64 0.05f64
311end
312sc = mul fabs sub mk cf wf
313end
314put sn_score i bitcast ulong sc
315put sn_idx i i
316end
317end
318
319fn cli_sens_sort n_res ulong to void
320for a ulong n_res bound 32
321if gt a 0
322k = get sn_idx a
323b = a
324while gt b 0 bound 32
325prev = get sn_idx sub b 1
326if not lt bitcast f64 get sn_score prev bitcast f64 get sn_score k
327break
328end
329put sn_idx b prev
330b = sub b 1
331end
332put sn_idx b k
333end
334end
335end
336
337fn cli_emit_sens_one a ulong mk f64 to void
338i = get sn_idx a
339sp = add 64 mul i 12
340if eq a 0
341ds_out_text cj_sn_a
342else
343ds_out_text cj_sn_a2
344end
345ds_out_jstr_slice_txt 0 get ds_pm sp get ds_pm add sp 1
346ds_out_text cj_sn_k
347cli_out_fmt_name 3 get ds_pm add sp 2
348cf = bitcast f64 get sn_cf i
349ds_out_text cj_sn_m
350if ge cf 0.0f64
351ds_out_jnum cf
352else
353ds_out_text cj_null
354end
355ds_out_text cj_sn_d
356if ge cf 0.0f64
357ds_out_jnum sub mk cf
358else
359ds_out_text cj_null
360end
361ds_out_text cj_sn_w
362ds_out_jnum bitcast f64 get sn_width i
363ds_out_text cj_sn_s
364ds_out_jnum bitcast f64 get sn_score i
365ds_out_text cj_sn_n
366cli_out_next_exp get ds_pm add sp 2 get ds_pm add sp 7
367ds_out_text cj_rbrace
368ds_out_flush 1
369end
370
371fn cli_emit_sens n_res ulong mk f64 asof long hasm ulong qbits ulong to void
372cli_sens_compute n_res mk asof hasm qbits
373cli_sens_sort n_res
374ds_out_text cj_sn1
375for a ulong n_res bound 32
376cli_emit_sens_one a mk
377end
378end
379
380fn cli_emit_eval_hdr fi ulong st ulong to void
381ds_out_text cj_h1
382cli_out_file_jstr fi
383ds_out_text cj_h2
384ds_out_jstr_slice_txt 0 get ds_pm 17 get ds_pm 18
385ds_out_text cj_h3
386ds_out_jstr_slice_txt 0 get ds_pm 23 get ds_pm 24
387ds_out_text cj_h4
388if ne get ds_pm 3 0
389ds_out_jstr_slice_txt 0 get ds_pm 27 get ds_pm 28
390else
391ds_out_ch uchar 34
392ds_out_ch uchar 34
393end
394ds_out_text cj_h5
395ds_out_i64 dr_i get ds_pm 4
396ds_out_text cj_h6
397ds_out_i64 dr_i get ds_pm 5
398ds_out_text cj_h7
399ds_out_jnum bitcast f64 get ds_pm 6
400ds_out_text cj_h8
401ds_out_jstr_slice_txt 0 get ds_pm 29 get ds_pm 30
402ds_out_text cj_h9
403ds_out_i64 get cli_asof 0
404ds_out_text cj_h10
405cli_out_fmt_name 0 st
406ds_out_text cj_h11
407cli_out_nom_rsn_jstr
408ds_out_text cj_h12
409pmask = get cli_nom_sc 11
410first = ulong 1
411for p ulong 5
412if ne and pmask shl ulong 1 p 0
413if eq first 0
414ds_out_text cj_comma
415end
416first = ulong 0
417cli_out_fmt_name 1 p
418end
419end
420ds_out_text cj_h13
421ds_out_u64 get cli_nom_sc 26
422ds_out_text cj_h14
423end
424
425fn cli_emit_bounds mk f64 lo f64 hi f64 to void
426ds_out_text cj_mk1
427ds_out_jnum mk
428ds_out_text cj_mk2
429ds_out_jnum lo
430ds_out_text cj_mk3
431ds_out_jnum hi
432ds_out_text cj_mk4
433if and gt lo 0.0f64 gt hi 0.0f64
434ds_out_text cj_true
435else
436ds_out_text cj_false
437end
438ds_out_text cj_bd1
439ds_out_jnum bitcast f64 get cli_nom_sc 20
440ds_out_text cj_bd2
441bnd = bitcast f64 get cli_nom_sc 19
442ds_out_jnum bnd
443ds_out_text cj_bd3
444n_res = get ds_pm 11
445for i ulong n_res bound 32
446if gt i 0
447ds_out_text cj_comma
448end
449sp = add 64 mul i 12
450ds_out_jstr_slice_txt 0 get ds_pm sp get ds_pm add sp 1
451ds_out_text cj_colon
452ds_out_jnum bitcast f64 get cli_nom_sc add 5792 i
453end
454ds_out_text cj_bd4
455if ge add mk 0.000001f64 bnd
456ds_out_text cj_true
457else
458ds_out_text cj_false
459end
460ds_out_flush 1
461end
462
463fn cli_emit_cp_peak to void
464ds_out_text cj_cp1
465nc = get cli_nom_sc 21
466for i ulong nc bound 256
467if gt i 0
468ds_out_text cj_comma
469end
470oi = get cli_nom_sc add 6080 i
471sp = add 448 mul oi 26
472ds_out_jstr_slice_txt 0 get ds_pm sp get ds_pm add sp 1
473end
474ds_out_text cj_pk1
475n_res = get ds_pm 11
476first = ulong 1
477for i ulong n_res bound 32
478sp = add 64 mul i 12
479if eq get ds_pm add sp 2 3
480if eq first 0
481ds_out_text cj_comma
482end
483first = ulong 0
484ds_out_jstr_slice_txt 0 get ds_pm sp get ds_pm add sp 1
485ds_out_text cj_pk2
486ds_out_jnum bitcast f64 get cli_nom_sc add 6344 i
487ds_out_text cj_pk3
488ds_out_jnum bitcast f64 get cli_nom_sc add 6376 i
489ds_out_text cj_pk4
490ds_out_jnum bitcast f64 get ds_pm add sp 4
491ds_out_text cj_rbrace
492end
493end
494ds_out_flush 1
495end
496
497fn cli_emit_attr_energy_cons to void
498ds_out_text cj_at1
499for i ulong 7
500if gt i 0
501ds_out_text cj_comma
502end
503cli_out_fmt_name 4 i
504ds_out_text cj_colon
505ds_out_jnum bitcast f64 get cli_nom_sc add 5824 i
506end
507ds_out_text cj_en1
508em = get cli_nom_sc 22
509es = get cli_nom_sc 23
510cli_out_energy_status em es
511ds_out_text cj_en2
512if or ne em 0 ne es 0
513ds_out_jnum bitcast f64 get cli_nom_sc 24
514else
515ds_out_text cj_null
516end
517ds_out_text cj_en3
518ds_out_jstr_slice_txt 0 get ds_pm 33 get ds_pm 34
519ds_out_text cj_en4
520ds_out_jstr_slice_txt 0 get ds_pm 35 get ds_pm 36
521ds_out_text cj_en5
522if ne em 0
523ds_out_text cj_true
524else
525ds_out_text cj_false
526end
527ds_out_text cj_co1
528ds_out_u64 get ds_pm 12
529ds_out_text cj_co2
530ds_out_jnum bitcast f64 get cli_nom_sc 15
531ds_out_text cj_co3
532ds_out_jnum bitcast f64 get cli_nom_sc 16
533ds_out_text cj_co4
534ds_out_jnum bitcast f64 get cli_nom_sc 17
535ds_out_text cj_co5
536ds_out_flush 1
537end
538
539fn cli_emit_eval_body lo f64 hi f64 to void
540mk = bitcast f64 get cli_nom_sc 3
541cli_emit_bounds mk lo hi
542cli_emit_ops
543cli_emit_cp_peak
544cli_emit_attr_energy_cons
545cli_emit_sens get ds_pm 11 mk get cli_asof 0 get cli_has_model 0 bitcast ulong 0.9f64
546ds_out_text cj_tail1
547ds_out_jnum bitcast f64 get cli_nom_sc 5830
548ds_out_text cj_tail2
549ds_out_flush 1
550end
551
552fn cli_cmd_eval to int
553flen = get cli_flens 0
554pbuf = new uchar 256 0
555for i ulong flen bound 256
556put pbuf i get cli_files i
557end
558prc = ds_read_file_side 0 view pbuf flen
559ds_out_reset
560if ne prc 0
561ds_out_text cj_perr1
562cli_out_file_jstr 0
563ds_out_text cj_perr2
564ds_out_jstr_err
565ds_out_text cj_perr3
566ds_out_flush 1
567ret 1
568end
569asof = get cli_asof 0
570hasm = get cli_has_model 0
571qbits = bitcast ulong 0.9f64
572rc = ds_eval_current 0 asof hasm qbits
573for i ulong 8192
574put cli_nom_sc i get ds_sc i
575end
576rlen = get ds_reason_len 0
577put cli_nom_rsn_len 0 rlen
578for i ulong rlen bound 256
579put cli_nom_rsn i get ds_reason i
580end
581cli_emit_eval_hdr 0 rc
582if ne rc 0
583ds_out_text cj_end_ref
584ds_out_flush 1
585ret 1
586end
587lo = f64 0.0f64
588hi = f64 0.0f64
589rc_lo = ds_eval_current 1 asof hasm qbits
590if eq rc_lo 0
591lo = bitcast f64 get ds_sc 3
592end
593rc_hi = ds_eval_current -1 asof hasm qbits
594if eq rc_hi 0
595hi = bitcast f64 get ds_sc 3
596end
597cli_emit_eval_body lo hi
598ret 0
599end
600
601fn cli_pareto_load k ulong to ulong
602fl = get cli_flens k
603fb = mul k 256
604pbuf = new uchar 256 0
605for i ulong fl bound 256
606put pbuf i get cli_files add fb i
607end
608prc = ds_read_file_side 0 view pbuf fl
609if ne prc 0
610put pr_status k 9
611rl = ulong 0
612while lt rl 255 bound 256
613c = get ds_err rl
614if eq c 0
615break
616end
617put pr_rsn add fb rl c
618rl = add rl 1
619end
620put pr_rsn_len k rl
621ret 1
622end
623ret 0
624end
625
626fn cli_pareto_max_peak to f64
627peak = f64 0.0f64
628n_res = get ds_pm 11
629for i ulong n_res bound 32
630sp = add 64 mul i 12
631if eq get ds_pm add sp 2 3
632pv = bitcast f64 get ds_sc add 6344 i
633if gt pv peak
634peak = pv
635end
636end
637end
638ret peak
639end
640
641fn cli_pareto_eval_one k ulong to ulong
642if ne cli_pareto_load k 0
643ret 0
644end
645asof = get cli_asof 0
646hasm = get cli_has_model 0
647qbits = bitcast ulong 0.9f64
648rc = ds_eval_current 0 asof hasm qbits
649put pr_status k rc
650fb = mul k 256
651rl = get ds_reason_len 0
652put pr_rsn_len k rl
653for i ulong rl bound 256
654put pr_rsn add fb i get ds_reason i
655end
656if ne rc 0
657ret 0
658end
659put pr_t k get ds_sc 3
660put pr_peak k bitcast ulong cli_pareto_max_peak
661put pr_e k get ds_sc 24
662put pr_emeas k get ds_sc 22
663put pr_esyn k get ds_sc 23
664rc_lo = ds_eval_current 1 asof hasm qbits
665if eq rc_lo 0
666put pr_lo k get ds_sc 3
667else
668put pr_lo k 0
669end
670rc_hi = ds_eval_current -1 asof hasm qbits
671if eq rc_hi 0
672put pr_hi k get ds_sc 3
673else
674put pr_hi k 0
675end
676if eq get pr_emeas k 0
677ret 0
678end
679ret 1
680end
681
682fn cli_pareto_dom a ulong b ulong all_e ulong to bool
683ta = bitcast f64 get pr_t a
684tb = bitcast f64 get pr_t b
685pa = bitcast f64 get pr_peak a
686pb = bitcast f64 get pr_peak b
687leq = and le tb ta le pb pa
688str = or lt tb ta lt pb pa
689if ne all_e 0
690ea = bitcast f64 get pr_e a
691eb = bitcast f64 get pr_e b
692leq = and leq le eb ea
693str = or str lt eb ea
694end
695ret and leq str
696end
697
698fn cli_pareto_print_row k ulong to void
699fa = new ulong 16 0
700sn = new uchar 256 0
701ds_out_ch uchar 32
702ds_out_ch uchar 32
703fl = get cli_flens k
704fb = mul k 256
705for i ulong fl bound 256
706ds_out_ch get cli_files add fb i
707end
708if lt fl 36
709cli_out_pad sub 36 fl
710end
711ds_out_ch uchar 32
712st = get pr_status k
713put fa 0 st
714sl = dag_fmt 0 edit fa edit sn
715for i ulong sl bound 64
716ds_out_ch get sn i
717end
718if lt sl 24
719cli_out_pad sub 24 sl
720end
721ds_out_ch uchar 32
722if eq st 0
723ds_out_fixed mul bitcast f64 get pr_t k 1.0e-9f64 6
724ds_out_ch uchar 32
725ds_out_fixed mul bitcast f64 get pr_lo k 1.0e-9f64 6
726ds_out_ch uchar 32
727ds_out_fixed mul bitcast f64 get pr_hi k 1.0e-9f64 6
728ds_out_ch uchar 32
729ds_out_fixed bitcast f64 get pr_peak k 0
730ds_out_ch uchar 32
731if ne get pr_emeas k 0
732ds_out_fixed bitcast f64 get pr_e k 3
733ds_out_text cp_j
734else
735if ne get pr_esyn k 0
736ds_out_text cp_syn
737ds_out_fixed bitcast f64 get pr_e k 3
738ds_out_text cp_j
739else
740ds_out_text cp_unm
741end
742end
743ds_out_ch uchar 32
744if ne get pr_front k 0
745ds_out_text cp_yes
746else
747ds_out_text cp_no
748end
749else
750ds_out_text cp_dash
751ds_out_ch uchar 32
752ds_out_text cp_dash
753ds_out_ch uchar 32
754ds_out_text cp_dash
755ds_out_ch uchar 32
756ds_out_text cp_dash
757ds_out_ch uchar 32
758ds_out_text cp_dash
759ds_out_ch uchar 32
760ds_out_text cp_ref
761ds_out_text cp_cmt
762rl = get pr_rsn_len k
763for i ulong rl bound 256
764ds_out_ch get pr_rsn add fb i
765end
766end
767ds_out_ch uchar 10
768ds_out_flush 1
769end
770
771fn cli_cmd_pareto to int
772nf = get cli_nfiles 0
773all_e = ulong 1
774for k ulong nf bound 64
775ok_e = cli_pareto_eval_one k
776if eq ok_e 0
777all_e = ulong 0
778end
779end
780for a ulong nf bound 64
781if eq get pr_status a 0
782put pr_front a 1
783for b ulong nf bound 64
784if and ne a b eq get pr_status b 0
785if cli_pareto_dom a b all_e
786put pr_front a 0
787break
788end
789end
790end
791end
792end
793ds_out_reset
794ds_out_text cp_hdr1
795if ne all_e 0
796ds_out_text cp_hdr_j
797end
798ds_out_text cp_hdr2
799if ne all_e 0
800ds_out_text cp_hdr_em
801else
802ds_out_text cp_hdr_en
803end
804ds_out_text cp_hdr3
805ds_out_flush 1
806for k ulong nf bound 64
807cli_pareto_print_row k
808end
809ret 0
810end
811
812fn cli_cmd_diff to int
813f0 = new uchar 256 0
814f1 = new uchar 256 0
815cb = new uchar 256 0
816l0 = get cli_flens 0
817l1 = get cli_flens 1
818for i ulong l0 bound 256
819put f0 i get cli_files i
820end
821for i ulong l1 bound 256
822put f1 i get cli_files add 256 i
823end
824if ne ds_read_file_side 0 view f0 l0 0
825ds_out_reset
826ds_out_jstr_err
827ds_out_ch uchar 10
828ds_out_flush 2
829ret 1
830end
831if ne ds_read_file_side 1 view f1 l1 0
832ds_out_reset
833ds_out_jstr_err
834ds_out_ch uchar 10
835ds_out_flush 2
836ret 1
837end
838ds_pack_side 0
839ds_pack_side 1
840clen = get cli_changed_len 0
841if gt clen 0
842for i ulong clen bound 256
843put cb i get cli_changed i
844end
845ds_mark_changed view cb clen
846end
847for i ulong 64
848put ds_ra i 0
849end
850rc = ds_run_diff
851ds_out_reset
852ds_out_text cj_df1
853cli_out_file_jstr 0
854ds_out_text cj_df2
855cli_out_file_jstr 1
856ds_out_text cj_df3
857cli_out_fmt_name 0 rc
858ds_out_text cj_df4
859ds_out_ch uchar 34
860ds_out_ch uchar 34
861ds_out_text cj_df5
862ds_out_u64 get ds_ra 11
863ds_out_text cj_df6
864ds_out_u64 get ds_ra 10
865ds_out_text cj_df7
866ds_out_u64 get ds_ra 12
867ds_out_text cj_df8
868ds_out_u64 get ds_ra 13
869ds_out_text cj_df9
870ds_out_u64 get ds_ra 14
871ds_out_text cj_df10
872for i ulong 7
873if gt i 0
874ds_out_text cj_comma
875end
876cli_out_fmt_name 2 add i 1
877ds_out_text cj_colon
878ds_out_jnum bitcast f64 get ds_ra add 33 i
879end
880ds_out_text cj_df11
881cli_out_changed_jstr
882ds_out_text cj_df12
883ds_out_flush 1
884if eq rc 0
885ret 0
886end
887ret 1
888end
889
890fn cli_parse_asof_arg n2 ulong to long
891dbuf = new uchar 256 0
892lim = n2
893if gt lim 255
894lim = ulong 255
895end
896for k ulong lim bound 256
897put dbuf k get cli_arg k
898end
899ret ds_day_from_slice view dbuf lim
900end
901
902fn cli_parse_args ac ulong to int
903i = ulong 2
904while lt i ac bound 256
905n = argread i cli_arg 0 4096
906if lt n 0
907ret 2
908end
909un = ulong n
910if cli_arg_eq cli_fasof un
911if ge add i 1 ac
912ret 2
913end
914i = add i 1
915n2 = argread i cli_arg 0 4096
916if le n2 0
917ret 2
918end
919d = cli_parse_asof_arg ulong n2
920if lt d 0
921w = write 2 cli_bad_asof 0 len cli_bad_asof
922ret 2
923end
924put cli_asof 0 d
925i = add i 1
926continue
927end
928if cli_arg_eq cli_fchanged un
929if ge add i 1 ac
930ret 2
931end
932i = add i 1
933n2 = argread i cli_arg 0 4096
934if lt n2 0
935ret 2
936end
937lim = ulong n2
938if gt lim 255
939lim = ulong 255
940end
941for k ulong lim bound 256
942put cli_changed k get cli_arg k
943end
944put cli_changed_len 0 lim
945i = add i 1
946continue
947end
948if cli_arg_eq cli_fmodel un
949if ge add i 1 ac
950ret 2
951end
952i = add i 2
953continue
954end
955nf = get cli_nfiles 0
956if lt nf 64
957lim = un
958if gt lim 255
959lim = ulong 255
960end
961fb = mul nf 256
962for k ulong lim bound 256
963put cli_files add fb k get cli_arg k
964end
965put cli_flens nf lim
966put cli_nfiles 0 add nf 1
967end
968i = add i 1
969end
970ret 0
971end
972
973fn main to int
974ac = argcnt
975if lt ac 3
976w = write 2 cli_usage 0 len cli_usage
977ret 2
978end
979n1 = argread 1 cli_arg 0 4096
980if le n1 0
981w = write 2 cli_usage 0 len cli_usage
982ret 2
983end
984cl = ulong n1
985if gt cl 31
986cl = ulong 31
987end
988for i ulong cl bound 32
989put cli_cmd i get cli_arg i
990end
991put cli_cmd_len 0 cl
992prc = cli_parse_args ulong ac
993if ne prc 0
994ret prc
995end
996if eq get cli_asof 0 0
997w = write 2 cli_need_asof 0 len cli_need_asof
998ret 2
999end
1000nf = get cli_nfiles 0
1001if and cli_cmd_eq cli_keval eq nf 1
1002ret cli_cmd_eval
1003end
1004if and cli_cmd_eq cli_kpareto ge nf 1
1005ret cli_cmd_pareto
1006end
1007if and cli_cmd_eq cli_kdiff eq nf 2
1008ret cli_cmd_diff
1009end
1010w = write 2 cli_usage 0 len cli_usage
1011ret 2
1012end