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 / gpu / nvidia / om / codegen / bw_hazard.om

895 lines · 16617 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note Static scoreboard hazard checker over encoded sm_121 bytes; successor of omega_bw_hazard.c at omega-mv 60b5d81e,
3note except ATOMG with size field 2 or 3, whose Rd and Rb are two registers here (hz_atn) and one in that C
4note (gpu/nvidia/checks/README.md, bwhz).
5note hz_chk checks c[0..lc) (lc a nonzero multiple of 16, at most 32768: 2048 instructions) into the wire m.
6note Decode record, 24 ulong: 0 op, 1 guard, 2 stall, 3 yield, 4 wbar, 5 rbar, 6 wait, 7 var, 8 late,
7note 9 nr, 10 nw, 11..15 reads, 16 write, 17 flow (0 next, 1 exit, 2 bra), 18 target (long bits), 19 name id.
8note Operand: reg | n << 8 | uniform << 16. Name id 0 is no name; 1..37 number the opcode name strings the C decode sets.
9note Check wire m, ulong: 0 insns, 1 reachable, 2 count, 3 bad_pc (long bits); finding i < 256 at 8 + 3i:
10note pc, src_pc, kind | reg << 8 | uniform << 16 | release << 24. State at 1024: w 512, r 512,
11note hints 512 (wpc | rpc << 32): 1 + the smallest pc of a producer (wpc) or queued late reader (rpc) merged into
12note the entry since it was last empty, 0 when it is empty; the join keeps the smaller, so src_pc does not depend
13note on the order the walk visits successors. Records at 2560, then seen n, queued n, work n, IN states n x 1536.
14note m is ulong 3203584 = 2560 + 1563 * 2048; the unit zeroes the used part. A walk longer than 999999 pops traps 4.
15note Barrier 6 does not exist on sm_121 (0..5, 7 = none): hz_dec1 refuses it in either field, as the C does, so
16note every shift amount below is at most 63.
17note Portable two's-complement reinterpretation; the bridge lowers no integer-to-integer bitcast.
18fn hz_u2l x ulong to long
19if lt x ulong 9223372036854775808
20ret long x
21end
22ret sub long -1 long xor x ulong 18446744073709551615
23end
24fn hz_l2u v long to ulong
25if ge v long 0
26ret ulong v
27end
28ret xor ulong sub long -1 v ulong 18446744073709551615
29end
30fn hz_u2i x ulong to long
31if lt x ulong 2147483648
32ret long x
33end
34ret sub long x 4294967296
35end
36fn hz_rd32 c view uchar 16 o ulong to ulong
37a = ulong get c o
38a = or a shl ulong get c add o 1 8
39a = or a shl ulong get c add o 2 16
40ret or a shl ulong get c add o 3 24
41end
42fn hz_size w2 ulong to long
43s = and shr w2 9 7
44if le s 4
45ret long 1
46end
47if eq s 5
48ret long 2
49end
50if eq s 6
51ret long 4
52end
53ret long -1
54end
55fn hz_r d edit ulong 24 o ulong reg ulong n long u ulong to void
56if eq reg 255
57ret
58end
59if le n 0
60ret
61end
62k = get d add o 9
63if ge k 5
64ret
65end
66put d add add o 11 k or or reg shl ulong n 8 shl u 16
67put d add o 9 add k 1
68end
69fn hz_w d edit ulong 24 o ulong reg ulong n long u ulong to void
70if eq reg 255
71ret
72end
73if le n 0
74ret
75end
76if ge get d add o 10 1
77ret
78end
79put d add o 16 or or reg shl ulong n 8 shl u 16
80put d add o 10 1
81end
82fn hz_nm d edit ulong 24 o ulong id ulong var ulong late ulong to void
83put d add o 19 id
84put d add o 7 var
85put d add o 8 late
86end
87fn hz_atn w2 ulong to long
88if or eq and shr w2 9 7 2 eq and shr w2 9 7 3
89ret 2
90end
91ret 1
92end
93fn hz_mem c view uchar 16 d edit ulong 24 o ulong op ulong to bool
94w0 = hz_rd32 c 0
95w2 = hz_rd32 c 8
96rd = and shr w0 16 255
97ra = shr w0 24
98rb = and hz_rd32 c 4 255
99rc = and w2 255
100an = long 1
101if ne and w2 256 0
102an = long 2
103end
104de = ne and w2 134217728 0
105if eq op 2433
106hz_nm d o 33 0 0
107n = hz_size w2
108if lt n 0
109ret false
110end
111hz_w d o rd n 0
112hz_r d o ra an 0
113if de
114hz_r d o rb 1 1
115end
116hz_nm d o 33 1 1
117ret true
118end
119if eq op 2438
120hz_nm d o 34 0 0
121n = hz_size w2
122if lt n 0
123ret false
124end
125hz_r d o ra an 0
126hz_r d o rb n 0
127if de
128hz_r d o rc 1 1
129end
130hz_nm d o 34 0 1
131ret true
132end
133if eq op 2472
134hz_w d o rd hz_atn w2 0
135hz_r d o ra an 0
136hz_r d o rb hz_atn w2 0
137if de
138hz_r d o rc 1 1
139end
140hz_nm d o 35 1 1
141ret true
142end
143ret hz_mem2 c d o op
144end
145fn hz_mem2 c view uchar 16 d edit ulong 24 o ulong op ulong to bool
146w0 = hz_rd32 c 0
147w2 = hz_rd32 c 8
148rd = and shr w0 16 255
149ra = shr w0 24
150rb = and hz_rd32 c 4 255
151rc = and w2 255
152de = ne and w2 134217728 0
153if eq op 2436
154hz_nm d o 36 0 0
155n = hz_size w2
156if lt n 0
157ret false
158end
159hz_w d o rd n 0
160hz_r d o ra 1 0
161if de
162hz_r d o rb 1 1
163end
164hz_nm d o 36 1 1
165ret true
166end
167if or eq op 904 eq op 2440
168hz_nm d o 37 0 0
169n = hz_size w2
170if lt n 0
171ret false
172end
173hz_r d o ra 1 0
174hz_r d o rb n 0
175if de
176hz_r d o rc 1 1
177end
178hz_nm d o 37 0 1
179ret true
180end
181if eq op 2946
182hz_nm d o 11 0 0
183n = hz_size w2
184if lt n 0
185ret false
186end
187hz_w d o rd n 0
188hz_r d o ra 1 0
189hz_nm d o 11 1 1
190ret true
191end
192if eq op 1964
193hz_nm d o 12 0 0
194n = hz_size w2
195if lt n 0
196ret false
197end
198hz_w d o rd n 1
199hz_r d o ra 1 1
200hz_nm d o 12 1 1
201ret true
202end
203ret false
204end
205fn hz_wab c view uchar 16 d edit ulong 24 o ulong id ulong to void
206w0 = hz_rd32 c 0
207hz_w d o and shr w0 16 255 1 0
208hz_r d o shr w0 24 1 0
209hz_r d o and hz_rd32 c 4 255 1 0
210hz_r d o and hz_rd32 c 8 255 1 0
211hz_nm d o id 0 0
212end
213fn hz_ab c view uchar 16 d edit ulong 24 o ulong id ulong to void
214w0 = hz_rd32 c 0
215hz_w d o and shr w0 16 255 1 0
216hz_r d o shr w0 24 1 0
217hz_r d o and hz_rd32 c 4 255 1 0
218hz_nm d o id 0 0
219end
220fn hz_ac c view uchar 16 d edit ulong 24 o ulong id ulong to void
221w0 = hz_rd32 c 0
222hz_w d o and shr w0 16 255 1 0
223hz_r d o shr w0 24 1 0
224hz_r d o and hz_rd32 c 8 255 1 0
225hz_nm d o id 0 0
226end
227fn hz_mma c view uchar 16 d edit ulong 24 o ulong id ulong to void
228w0 = hz_rd32 c 0
229hz_w d o and shr w0 16 255 4 0
230hz_r d o shr w0 24 4 0
231hz_r d o and hz_rd32 c 4 255 2 0
232hz_r d o and hz_rd32 c 8 255 4 0
233hz_nm d o id 0 0
234end
235fn hz_bra d edit ulong 24 o ulong w0 ulong w1 ulong to void
236s = shr w1 2
237if ne and w1 2147483648 0
238s = or s 3221225472
239end
240u = and shl s 6 4294967295
241u = or u and shr w0 18 63
242t = add hz_u2i u 1
243if gt t 2147483647
244t = sub t 4294967296
245end
246put d add o 17 2
247put d add o 18 hz_l2u t
248hz_nm d o 6 0 0
249end
250fn hz_alu c view uchar 16 d edit ulong 24 o ulong op ulong to bool
251w0 = hz_rd32 c 0
252w1 = hz_rd32 c 4
253w2 = hz_rd32 c 8
254rd = and shr w0 16 255
255ra = shr w0 24
256rb = and w1 255
257if eq op 2328
258hz_nm d o 1 0 0
259ret true
260end
261if eq op 2845
262hz_nm d o 2 0 0
263ret true
264end
265if eq op 2450
266hz_nm d o 3 0 0
267ret true
268end
269if eq op 2447
270hz_r d o ra 1 0
271hz_nm d o 4 0 1
272ret true
273end
274if eq op 2381
275put d add o 17 1
276hz_nm d o 5 0 0
277ret true
278end
279if eq op 2375
280hz_bra d o w0 w1
281ret true
282end
283if eq op 2373
284hz_nm d o 7 0 0
285ret true
286end
287if eq op 2369
288hz_nm d o 8 0 0
289ret true
290end
291if eq op 514
292hz_w d o rd 1 0
293hz_r d o rb 1 0
294hz_nm d o 9 0 0
295ret true
296end
297if eq op 2050
298hz_w d o rd 1 0
299hz_nm d o 9 0 0
300ret true
301end
302if eq op 2329
303hz_w d o rd 1 0
304hz_nm d o 10 1 0
305ret true
306end
307if or eq op 548 eq op 528
308if eq op 548
309hz_wab c d o 13
310else
311hz_wab c d o 17
312end
313ret true
314end
315if eq op 2084
316hz_ac c d o 13
317ret true
318end
319if eq op 3108
320hz_w d o rd 1 0
321hz_r d o ra 1 0
322hz_r d o rb 1 1
323hz_r d o and w2 255 1 0
324hz_nm d o 13 0 0
325ret true
326end
327if eq op 2085
328hz_w d o rd 2 0
329hz_r d o ra 1 0
330hz_r d o and w2 255 2 0
331hz_nm d o 14 0 0
332ret true
333end
334if eq op 551
335hz_wab c d o 15
336ret true
337end
338if eq op 524
339hz_r d o ra 1 0
340hz_r d o rb 1 0
341hz_nm d o 16 0 0
342ret true
343end
344if eq op 2060
345hz_r d o ra 1 0
346hz_nm d o 16 0 0
347ret true
348end
349if eq op 3084
350hz_r d o ra 1 0
351hz_r d o rb 1 1
352hz_nm d o 16 0 0
353ret true
354end
355if eq op 572
356hz_mma c d o 18
357ret true
358end
359if eq op 634
360hz_mma c d o 19
361ret true
362end
363if eq op 2073
364hz_ac c d o 20
365ret true
366end
367if eq op 537
368hz_wab c d o 20
369ret true
370end
371if eq op 2066
372hz_ac c d o 21
373ret true
374end
375if eq op 530
376hz_wab c d o 21
377ret true
378end
379ret hz_flt c d o op
380end
381fn hz_flt c view uchar 16 d edit ulong 24 o ulong op ulong to bool
382w0 = hz_rd32 c 0
383w1 = hz_rd32 c 4
384w2 = hz_rd32 c 8
385rd = and shr w0 16 255
386ra = shr w0 24
387rb = and w1 255
388if eq op 545
389hz_ab c d o 22
390ret true
391end
392if eq op 544
393hz_ab c d o 23
394ret true
395end
396if eq op 547
397hz_wab c d o 24
398ret true
399end
400if eq op 523
401hz_r d o ra 1 0
402hz_r d o rb 1 0
403hz_nm d o 25 0 0
404ret true
405end
406if eq op 520
407hz_ab c d o 26
408ret true
409end
410if eq op 521
411hz_ab c d o 27
412ret true
413end
414if eq op 574
415hz_ab c d o 28
416ret true
417end
418if eq op 581
419hz_w d o rd 1 0
420hz_r d o rb 1 0
421hz_nm d o 29 0 0
422ret true
423end
424if or eq op 773 eq op 776
425hz_w d o rd 1 0
426hz_r d o rb 1 0
427if eq op 773
428hz_nm d o 30 1 0
429else
430hz_nm d o 31 1 0
431end
432ret true
433end
434if eq op 3977
435hz_w d o rd 1 0
436hz_r d o ra 1 0
437hz_nm d o 32 1 0
438ret true
439end
440ret false
441end
442fn hz_dec1 c view uchar 16 d edit ulong 24 to long
443o = ulong 0
444for i ulong 24
445put d add o i 0
446end
447w0 = hz_rd32 c 0
448w3 = hz_rd32 c 12
449op = and w0 4095
450put d o op
451put d add o 1 and shr w0 12 15
452put d add o 2 and shr w3 9 15
453put d add o 3 and shr w3 13 1
454put d add o 4 and shr w3 14 7
455put d add o 5 and shr w3 17 7
456if or eq get d add o 4 6 eq get d add o 5 6
457ret long -1
458end
459put d add o 6 and shr w3 20 63
460if hz_alu c d o op
461ret long 0
462end
463if hz_mem c d o op
464ret long 0
465end
466ret long -1
467end
468fn hz_kill wt ulong to ulong
469k = ulong 0
470for m ulong 64
471if and gt m 0 ne and m wt 0
472k = or k shl ulong 1 m
473end
474end
475ret k
476end
477fn hz_note m edit ulong 3203584 pc ulong p ulong kix ulong pend ulong to void
478src = sub and get m p 4294967295 1
479if eq and kix 255 2
480src = sub shr get m p 32 1
481end
482key = hz_key kix
483if hz_dup m pc key
484ret
485end
486cnt = get m 2
487if lt cnt 256
488f = add 8 mul cnt 3
489put m f pc
490put m add f 1 src
491put m add f 2 or key shl hz_low pend 24
492end
493put m 2 add cnt 1
494end
495fn hz_dup m edit ulong 3203584 pc ulong key ulong to bool
496lim = get m 2
497if gt lim 256
498lim = 256
499end
500for i ulong lim
501f = add 8 mul i 3
502if eq get m f pc
503if eq and get m add f 2 16777215 key
504ret true
505end
506end
507end
508ret false
509end
510fn hz_low p ulong to ulong
511for b ulong 64
512if ne and shr p b 1 0
513ret b
514end
515end
516ret 0
517end
518fn hz_key kix ulong to ulong
519ix = shr kix 8
520uni = ulong 0
521if ge ix 256
522uni = 1
523end
524ret or or and kix 255 shl and ix 255 8 shl uni 16
525end
526fn hz_ix op ulong q ulong to ulong
527reg = and op 255
528u = and shr op 16 1
529ret add mul u 256 and add reg q 255
530end
531fn hz_raw m edit ulong 3203584 op ulong sb ulong pc ulong rep bool to void
532for q ulong and shr op 8 255
533i = hz_ix op q
534if ne and i 255 255
535hz_raw1 m add sb i i pc rep
536end
537end
538end
539fn hz_raw1 m edit ulong 3203584 x ulong i ulong pc ulong rep bool to void
540w = get m x
541if ne w 0
542if rep
543hz_note m pc add x 1024 or 1 shl i 8 w
544end
545put m x 0
546put m add x 1024 and get m add x 1024 18446744069414584320
547end
548end
549fn hz_wfl m edit ulong 3203584 dr ulong rep bool to ulong
550wb = get m add dr 4
551fl = ulong 0
552if rep
553fl = 1
554end
555if or ne wb 7 ne get m add dr 7 0
556fl = or fl 2
557end
558if ne wb 7
559fl = or fl shl shl ulong 1 wb 8
560end
561ret fl
562end
563fn hz_wop m edit ulong 3203584 dr ulong sb ulong pc ulong rep bool to void
564fl = hz_wfl m dr rep
565op = get m add dr 16
566for q ulong and shr op 8 255
567i = hz_ix op q
568if ne and i 255 255
569hz_wop1 m add sb i i pc fl
570end
571end
572end
573fn hz_wop1 m edit ulong 3203584 x ulong i ulong pc ulong fl ulong to void
574p = add x 1024
575r = get m add x 512
576if ne r 0
577if ne and fl 1 0
578hz_note m pc p or 2 shl i 8 r
579end
580put m add x 512 0
581put m p and get m p 4294967295
582end
583w = get m x
584if ne w 0
585if ne and fl 1 0
586hz_note m pc p or 3 shl i 8 w
587end
588put m x 0
589put m p and get m p 18446744069414584320
590end
591if ne and fl 2 0
592put m x or get m x shl ulong 1 shr fl 8
593put m p or and get m p 18446744069414584320 add pc 1
594end
595end
596fn hz_late m edit ulong 3203584 op ulong sb ulong pc ulong bit ulong to void
597for q ulong and shr op 8 255
598i = hz_ix op q
599if ne and i 255 255
600hz_late1 m add sb i pc bit
601end
602end
603end
604fn hz_late1 m edit ulong 3203584 x ulong pc ulong bit ulong to void
605y = add x 512
606r = get m y
607put m y or r bit
608p = add x 1024
609h = get m p
610t = hz_ltag r shr h 32 pc
611put m p or and h 4294967295 shl t 32
612end
613note The pc tag rules of the C (step and join), each on plain numbers so gpu/nvidia/checks/bwhz can run them.
614fn hz_pmin a ulong b ulong to ulong
615if eq a 0
616ret b
617end
618if eq b 0
619ret a
620end
621if lt a b
622ret a
623end
624ret b
625end
626note late reader at pc queued on an entry with mask r and tag rt: pmin(rt, pc + 1) if r, else pc + 1
627fn hz_ltag r ulong rt ulong pc ulong to ulong
628t = add pc 1
629if ne r 0
630t = hz_pmin rt t
631end
632ret t
633end
634note join of a source entry with mask sv and tag st into tag dt: pmin(dt, st) if sv, else dt
635fn hz_jtag dt ulong sv ulong st ulong to ulong
636if ne sv 0
637ret hz_pmin dt st
638end
639ret dt
640end
641note an entry whose mask v a wait left empty drops its tag t
642fn hz_wtag v ulong t ulong to ulong
643if eq v 0
644ret 0
645end
646ret t
647end
648fn hz_lbit m edit ulong 3203584 dr ulong to ulong
649rb = get m add dr 5
650wb = get m add dr 4
651lt8 = get m add dr 8
652if and eq lt8 0 eq rb 7
653ret 0
654end
655mm = ulong 0
656if ne rb 7
657mm = shl ulong 1 rb
658end
659if ne wb 7
660mm = or mm shl ulong 1 wb
661end
662ret shl ulong 1 mm
663end
664fn hz_wait m edit ulong 3203584 dr ulong sb ulong to void
665wt = get m add dr 6
666if ne wt 0
667k = xor hz_kill wt 18446744073709551615
668for i ulong 512
669x = add sb i
670w = and get m x k
671put m x w
672r = and get m add x 512 k
673put m add x 512 r
674p = add x 1024
675h = get m p
676wt = hz_wtag w and h 4294967295
677rt = hz_wtag r shr h 32
678put m p or wt shl rt 32
679end
680end
681end
682fn hz_step m edit ulong 3203584 dr ulong sb ulong pc ulong rep bool to void
683hz_wait m dr sb
684nr = get m add dr 9
685for j ulong nr
686op = get m add add dr 11 j
687hz_raw m op sb pc rep
688end
689nw = get m add dr 10
690if ne nw 0
691hz_wop m dr sb pc rep
692end
693bit = hz_lbit m dr
694if ne bit 0
695for j ulong nr
696op = get m add add dr 11 j
697hz_late m op sb pc bit
698end
699end
700end
701fn hz_join m edit ulong 3203584 dst ulong src ulong to bool
702ch = false
703for i ulong 512
704a = hz_j1 m add dst i add src i 0
705b = hz_j1 m add dst i add src i 1
706if or a b
707ch = true
708end
709end
710ret ch
711end
712fn hz_j1 m edit ulong 3203584 d ulong s ulong sel ulong to bool
713o = mul sel 512
714sh = mul sel 32
715x = get m add d o
716sv = get m add s o
717y = or x sv
718h = get m add d 1024
719dt = and shr h sh 4294967295
720st = get m add s 1024
721st = and shr st sh 4294967295
722t = hz_jtag dt sv st
723if and eq x y eq t dt
724ret false
725end
726put m add d o y
727k = shl ulong 4294967295 sh
728k = xor k 18446744073709551615
729h = and h k
730h = or h shl t sh
731put m add d 1024 h
732ret true
733end
734fn hz_copy m edit ulong 3203584 dst ulong src ulong to void
735for i ulong 1536
736v = get m add src i
737put m add dst i v
738end
739end
740fn hz_zero m edit ulong 3203584 n ulong to void
741for b ulong add div n 65536 1
742for i ulong 65536
743x = add mul b 65536 i
744if ge x n
745ret
746end
747put m x 0
748end
749end
750end
751fn hz_se n ulong to ulong
752ret add 2560 mul n 24
753end
754fn hz_in n ulong to ulong
755ret add hz_se n mul n 3
756end
757fn hz_push m edit ulong 3203584 n ulong s long top ulong to long
758if or lt s 0 ge s long n
759ret long -1
760end
761t = ulong s
762qu = add hz_se n n
763if eq get m add qu t 0
764put m add qu t 1
765put m add add qu n top t
766ret long add top 1
767end
768ret long top
769end
770fn hz_dpc c view uchar 32768 m edit ulong 3203584 pc ulong to long
771ins = new uchar 16 0
772rec = new ulong 24 0
773for i ulong 16
774put ins i get c add mul pc 16 i
775end
776r = hz_dec1 ins rec
777dr = add 2560 mul pc 24
778for i ulong 24
779put m add dr i get rec i
780end
781ret r
782end
783fn hz_reach c view uchar 32768 m edit ulong 3203584 n ulong to long
784qu = add hz_se n n
785wk = add qu n
786put m wk 0
787put m qu 1
788top = ulong 1
789while gt top 0 bound 999999
790top = sub top 1
791pc = get m add wk top
792if ne hz_dpc c m pc 0
793put m 3 pc
794ret long -1
795end
796put m add hz_se n pc 1
797t = hz_rsuc m n pc top
798if lt t 0
799put m 3 pc
800ret long -1
801end
802top = ulong t
803end
804ret long 0
805end
806fn hz_rsuc m edit ulong 3203584 n ulong pc ulong top ulong to long
807dr = add 2560 mul pc 24
808fl = get m add dr 17
809gd = get m add dr 1
810t = long top
811if or eq fl 0 ne gd 7
812t = hz_push m n add long pc 1 top
813if lt t 0
814ret t
815end
816end
817if eq fl 2
818tg = hz_u2l get m add dr 18
819t = hz_push m n add long pc tg ulong t
820end
821ret t
822end
823fn hz_tgt m edit ulong 3203584 pc ulong to ulong
824tg = hz_u2l get m add add 2560 mul pc 24 18
825ret ulong add long pc tg
826end
827fn hz_edge m edit ulong 3203584 n ulong t ulong top ulong to ulong
828se = hz_se n
829qu = add se n
830ch = hz_join m add hz_in n mul t 1536 1024
831sv = get m add se t
832qv = get m add qu t
833if and or ch eq sv 1 eq qv 0
834put m add qu t 1
835put m add add qu n top t
836ret add top 1
837end
838ret top
839end
840fn hz_fix m edit ulong 3203584 n ulong to void
841se = hz_se n
842qu = add se n
843wk = add qu n
844put m wk 0
845put m qu 1
846top = ulong 1
847while gt top 0 bound 999999
848top = sub top 1
849pc = get m add wk top
850put m add qu pc 0
851put m add se pc 2
852hz_copy m 1024 add hz_in n mul pc 1536
853dr = add 2560 mul pc 24
854hz_step m dr 1024 pc false
855fl = get m add dr 17
856gd = get m add dr 1
857if or eq fl 0 ne gd 7
858top = hz_edge m n add pc 1 top
859end
860if eq fl 2
861top = hz_edge m n hz_tgt m pc top
862end
863end
864end
865fn hz_chk c view uchar 32768 lc ulong m edit ulong 3203584 to long
866put m 3 18446744073709551615
867if or or eq lc 0 gt lc 32768 ne rem lc 16 0
868ret long -1
869end
870n = div lc 16
871need = add hz_in n mul n 1536
872hz_zero m need
873put m 3 18446744073709551615
874put m 0 n
875if ne hz_reach c m n 0
876ret long -1
877end
878se = hz_se n
879s = ulong 0
880for i ulong n
881if ne get m add se i 0
882s = add s 1
883end
884put m add add se n i 0
885end
886put m 1 s
887hz_fix m n
888for pc ulong n
889if ne get m add se pc 0
890hz_copy m 1024 add hz_in n mul pc 1536
891hz_step m add 2560 mul pc 24 1024 pc true
892end
893end
894ret long 0
895end