interplane.Get Omega
Read in your language

aien-train

AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.

Brought by drakestapleton

branch main Branches Tags History

aien-train / native / omegallm / bpe.om

997 lines · 19003 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note omegallm bpe.om (aien-train#52, CONTRACT-V1 sections 2, 7 and 8): the byte-pair tokenizer.
3note Text is read as a stream through the opw window of data.om (opstart, opshift) and cut into
4note chunks (2.1). bpefit counts chunk types, then merges with a hashed pair table, per-pair lists
5note of the types that hold the pair and a lazy max-heap keyed count << 24 | (4095 - a) << 12 |
6note (4095 - b): the largest key is the largest count, then the smallest a, then the smallest b.
7note A pair's count only falls once its newest token exists, so a popped key whose count is still
8note current is the true maximum; a stale one is pushed again with its current count (if any).
9note Encode applies, per chunk, the present merge of lowest rank until none is left. That equals
10note merges 0, 1, ... in order (2.4): merge k's pair never reappears after merge k, since a later
11note merge only makes pairs that hold its own new token. Chunk types cache their tokens.
12note Exits: 2 usage (bpefit V outside 257..4096); 21 a capacity below, an odd token file, or
13note MAXBYTES with no byte 0 inside; 25 a token >= V; 26 a bad merges file; 27 V above the file's
14note V, or V <= 256; 28 no pair left to merge; 70 I/O.
15note Interface for the model units (section 8): obload, obtlen, obtput, obprompt and obtk.
16note Capacities: 524288 chunk types, 4194304 pool symbols (2 per byte of type), 900000 pairs,
17note 4194304 type-in-pair list nodes.
18const BQTCAP ulong 524288
19const BQHMSK ulong 1048575
20const BQSCAP ulong 4194304
21const BQPCAP ulong 900000
22const BQPMSK ulong 1048575
23const BQNCAP ulong 4194304
24const BQLCAP ulong 1099511627776
25global obtk ulong 4096
26global obo uchar 4096
27global obon ulong 1
28global obm uchar 15384
29global bqma ushort 4096
30global bqmb ushort 4096
31global bqln ulong 4096
32global bqrk uint 8192
33global bqrt ushort 8192
34global bqv ulong 2
35global bqcl uchar 256
36global bqtm ushort 128
37global bqsk ushort 4100
38global bqst ulong 16
39global bqhs uint 1048576
40global bqto uint 524288
41global bqtl uchar 524288
42global bqtn uchar 524288
43global bqtc ulong 524288
44global bqts uint 524288
45global bqsy ushort 4194304
46global bqpk uint 1048576
47global bqpc ulong 1048576
48global bqph uint 1048576
49global bqpl uint 1048576
50global bqnl uint 1048576
51global bqnt uint 4194304
52global bqnx uint 4194304
53global bqhp ulong 1048576
54
55note bqst: 0 types, 1 pool symbols used, 2 chunks, 3 bytes read, 4 tokens, 5 pairs, 6 new pairs
56note of this merge (bqnl), 7 list nodes, 8 heap entries.
57
58note class table: bqcl[c] = 1 when A(c) (section 2)
59fn bpcls to void
60for c ulong 256
61v = uchar 0
62if or or and ge c 48 le c 57 and ge c 65 le c 90 or and ge c 97 le c 122 ge c 128
63v = uchar 1
64end
65put bqcl c v
66end
67end
68
69note length of the chunk at opw[i] (section 2.1, pieces of at most 64) in a text ending at n > i
70fn bpclen i ulong n ulong to ulong
71c = ulong get opw i
72j = add i 1
73if eq get bqcl c 0
74if ne c 32
75ret 1
76end
77if ge j n
78ret 1
79end
80if eq get bqcl get opw j 0
81ret 1
82end
83j = add j 1
84end
85e = add i 64
86if lt n e
87e = n
88end
89while lt j e bound 64
90if eq get bqcl get opw j 0
91break
92end
93j = add j 1
94end
95ret sub j i
96end
97
98note as bpclen, over the argument bytes oarg (obprompt)
99fn bpclena i ulong n ulong to ulong
100c = ulong get oarg i
101j = add i 1
102if eq get bqcl c 0
103if ne c 32
104ret 1
105end
106if ge j n
107ret 1
108end
109if eq get bqcl get oarg j 0
110ret 1
111end
112j = add j 1
113end
114e = add i 64
115if lt n e
116e = n
117end
118while lt j e bound 64
119if eq get bqcl get oarg j 0
120break
121end
122j = add j 1
123end
124ret sub j i
125end
126
127note FNV-1a 64 of opw[i .. i + l)
128fn bphash i ulong l ulong to ulong
129h = ulong 14695981039346656037
130for k ulong l
131h = mul xor h ulong get opw add i k 1099511628211
132end
133ret h
134end
135
136note does type y hold the bytes opw[i .. i + l)?
137fn bpsame y ulong i ulong l ulong to bool
138if ne ulong get bqtl y l
139ret false
140end
141o = ulong get bqto y
142for k ulong l
143if ne ulong get bqsy add o k ulong get opw add i k
144ret false
145end
146end
147ret true
148end
149
150note new type in empty slot s for opw[i .. i + l): its bytes become symbols at bqsy[o], 2 l pool
151note symbols are reserved (encode stores the tokens after the bytes); BQTCAP when full
152fn bpins s ulong i ulong l ulong to ulong
153nt = get bqst 0
154o = get bqst 1
155if ge nt BQTCAP
156ret BQTCAP
157end
158if gt add o mul 2 l BQSCAP
159ret BQTCAP
160end
161put bqhs s uint add nt 1
162put bqto nt uint o
163put bqtl nt uchar l
164put bqtn nt uchar l
165put bqtc nt 0
166put bqts nt 0
167for k ulong l
168put bqsy add o k ushort get opw add i k
169end
170put bqst 0 add nt 1
171put bqst 1 add o l
172ret nt
173end
174
175note type id of the chunk opw[i .. i + l), added when absent; BQTCAP when absent and full
176fn bpfind i ulong l ulong to ulong
177s = and bphash i l BQHMSK
178for q ulong 524289
179y = ulong get bqhs s
180if eq y 0
181ret bpins s i l
182end
183y = sub y 1
184if bpsame y i l
185ret y
186end
187s = and add s 1 BQHMSK
188end
189ret BQTCAP
190end
191
192note fit: count one chunk
193fn bpcount i ulong l ulong to void
194y = bpfind i l
195if eq y BQTCAP
196exit 21
197end
198put bqtc y add get bqtc y 1
199put bqst 2 add get bqst 2 1
200end
201
202note append token t to output 0 as u16 LE
203fn bpwtok t ulong to void
204owbyte 0 and t 255
205owbyte 0 shr t 8
206end
207
208note rank of pair (a, b): its merge token, or 65535 when it is not a merge below V
209fn bprank a ulong b ulong to ulong
210key = add mul a 4096 b
211s = shr mul add key 1 ulong 11400714819323198485 51
212for q ulong 8192
213k = ulong get bqrk s
214if eq k 0
215ret 65535
216end
217if eq k add key 1
218ret ulong get bqrt s
219end
220s = and add s 1 8191
221end
222ret 65535
223end
224
225note replace in bqtm[0 .. m) every (a, b) of merge token t, left to right without overlap
226fn bprepl m ulong t ulong to ulong
227a = get bqma t
228b = get bqmb t
229w = ulong 0
230j = ulong 0
231while lt j m bound 128
232x = get bqtm j
233z = ushort 65535
234if lt add j 1 m
235z = get bqtm add j 1
236end
237if and eq x a eq z b
238put bqtm w ushort t
239j = add j 2
240else
241put bqtm w x
242j = add j 1
243end
244w = add w 1
245end
246ret w
247end
248
249note encode bqtm[0 .. n) (bytes) in place (section 2.4); returns the token count
250fn bpenct n ulong to ulong
251m = n
252dn = false
253while and not dn gt m 1 bound 64
254best = ulong 65535
255for j ulong sub m 1
256r = bprank ulong get bqtm j ulong get bqtm add j 1
257if lt r best
258best = r
259end
260end
261if eq best 65535
262dn = true
263else
264m = bprepl m best
265end
266end
267ret m
268end
269
270note encode: one chunk opw[i .. i + l) to output 0, through the type cache when it has room
271fn bpenc1 i ulong l ulong to void
272put bqst 2 add get bqst 2 1
273y = bpfind i l
274if eq y BQTCAP
275for k ulong l
276put bqtm k ushort get opw add i k
277end
278m = bpenct l
279for k ulong m
280bpwtok ulong get bqtm k
281end
282put bqst 4 add get bqst 4 m
283else
284o = add ulong get bqto y l
285if eq get bqtc y 0
286for k ulong l
287put bqtm k ushort get opw add i k
288end
289mt = bpenct l
290for k ulong mt
291put bqsy add o k get bqtm k
292end
293put bqtn y uchar mt
294put bqtc y 1
295put bqst 1 add get bqst 1 mt
296end
297m = ulong get bqtn y
298for k ulong m
299bpwtok ulong get bqsy add o k
300end
301put bqst 4 add get bqst 4 m
302end
303end
304
305note the chunks of the first lim bytes of argument ai (all of it when shorter) through bpcount
306note (mode 0) or bpenc1 (mode 1, output 0 opened on argument bo once the text is open); bqst 3 =
307note bytes read. A chunk needs at most 65 bytes past its start, so the window moves to the
308note current chunk when fewer are left and the file goes on.
309note window position of i after a refill: when fewer than need bytes are left from opw[i] and the
310note file goes on, opw[i ..] moves to the front (0); else i
311fn bprefil ai ulong i ulong need ulong to ulong
312if gt add i need get opst 1
313if eq get opst 2 0
314opshift ai i
315ret 0
316end
317end
318ret i
319end
320
321fn bpscan ai ulong lim ulong mode ulong bo ulong to void
322opstart ai
323if eq mode 1
324owopen 0 bo
325end
326i = ulong 0
327dn = false
328while not dn bound 999999
329q = ulong 0
330while and not dn lt q 999999 bound 999999
331q = add q 1
332i = bprefil ai i 65
333wn = get opst 1
334wb = get opst 0
335n = wn
336if lt sub lim wb n
337n = sub lim wb
338end
339if ge i n
340dn = true
341put bqst 3 add wb i
342else
343l = bpclen i n
344if eq mode 0
345bpcount i l
346else
347bpenc1 i l
348end
349i = add i l
350end
351end
352end
353end
354
355note fitbytes for MAXBYTES m: just after the last byte 0 among the first m bytes of argument ai;
356note exit 21 when there is none
357fn bpcut ai ulong m ulong to ulong
358opstart ai
359last = ulong 0
360dn = false
361while not dn bound 999999
362wb = get opst 0
363wn = get opst 1
364e = wn
365if lt sub m wb e
366e = sub m wb
367end
368j = ulong 0
369for o ulong 3
370lj = mul add o 1 999999
371if gt lj e
372lj = e
373end
374while lt j lj bound 999999
375if eq get opw j 0
376last = add add wb j 1
377end
378j = add j 1
379end
380end
381if or lt e wn ne get opst 2 0
382dn = true
383else
384opshift ai wn
385end
386end
387if eq last 0
388exit 21
389end
390ret last
391end
392
393note pair table slot of key a 4096 + b, made (count 0, no list) when absent; new slots are listed
394note in bqnl; exit 21 past BQPCAP pairs
395fn bppslot key ulong to ulong
396s = shr mul add key 1 ulong 11400714819323198485 44
397for q ulong 1048577
398k = ulong get bqpk s
399if eq k 0
400nf = get bqst 5
401if ge nf BQPCAP
402exit 21
403end
404put bqpk s uint add key 1
405put bqpc s 0
406put bqph s 0
407put bqpl s 0
408put bqst 5 add nf 1
409nn = get bqst 6
410put bqnl nn uint s
411put bqst 6 add nn 1
412ret s
413end
414if eq k add key 1
415ret s
416end
417s = and add s 1 BQPMSK
418end
419ret s
420end
421
422note list type y under pair slot s (once per type in a row); exit 21 past BQNCAP nodes
423fn bpnode s ulong y ulong to void
424if ne ulong get bqpl s add y 1
425put bqpl s uint add y 1
426nn = get bqst 7
427if ge nn BQNCAP
428exit 21
429end
430put bqnt nn uint y
431put bqnx nn get bqph s
432put bqph s uint add nn 1
433put bqst 7 add nn 1
434end
435end
436
437fn bpkey c ulong a ulong b ulong to ulong
438ret or or shl c 24 shl sub 4095 a 12 sub 4095 b
439end
440
441fn bphpush x ulong to void
442i = get bqst 8
443put bqst 8 add i 1
444dn = false
445while and not dn gt i 0 bound 64
446p = div sub i 1 2
447v = get bqhp p
448if ge v x
449dn = true
450else
451put bqhp i v
452i = p
453end
454end
455put bqhp i x
456end
457
458note pop the heap's largest key (the heap is not empty)
459fn bphpop to ulong
460top = get bqhp 0
461n = sub get bqst 8 1
462put bqst 8 n
463x = get bqhp n
464i = ulong 0
465dn = false
466while not dn bound 64
467l = add mul i 2 1
468if ge l n
469dn = true
470else
471c = l
472r = add l 1
473if lt r n
474if gt get bqhp r get bqhp l
475c = r
476end
477end
478v = get bqhp c
479if ge x v
480dn = true
481else
482put bqhp i v
483i = c
484end
485end
486end
487if gt n 0
488put bqhp i x
489end
490ret top
491end
492
493note bqpc[s] += c and -= c, one big array per function (error 12 at this pin otherwise)
494fn bppcadd s ulong c ulong to void
495put bqpc s add get bqpc s c
496end
497fn bppcsub s ulong c ulong to void
498put bqpc s sub get bqpc s c
499end
500
501note count the pairs of type y and list y under them
502fn bpinty y ulong to void
503o = ulong get bqto y
504c = get bqtc y
505for j ulong sub ulong get bqtn y 1
506x = ulong get bqsy add o j
507z = ulong get bqsy add add o j 1
508s = bppslot add mul x 4096 z
509bppcadd s c
510bpnode s y
511end
512end
513
514note count the pairs of every type, list the types under them, heap every pair
515fn bpinit to void
516nt = get bqst 0
517for y ulong nt
518bpinty y
519end
520for s ulong 1048576
521k = ulong get bqpk s
522if ne k 0
523c = get bqpc s
524if gt c 0
525k = sub k 1
526bphpush bpkey c div k 4096 and k 4095
527end
528end
529end
530end
531
532note the pair to merge: the slot of the heap's largest current key; exit 28 when none is left.
533note Each pair has at most one heap entry, and one pop sequence meets a pair at most twice.
534fn bpsel to ulong
535for o ulong 3
536while gt get bqst 8 0 bound 999999
537x = bphpop
538c = shr x 24
539a = sub 4095 and shr x 12 4095
540b = sub 4095 and x 4095
541s = bppslot add mul a 4096 b
542cc = get bqpc s
543if eq cc c
544ret s
545end
546if gt cc 0
547bphpush bpkey cc a b
548end
549end
550end
551exit 28
552end
553
554fn bphas o ulong n ulong a ulong b ulong to bool
555for j ulong sub n 1
556x = ulong get bqsy add o j
557z = ulong get bqsy add add o j 1
558if and eq x a eq z b
559ret true
560end
561end
562ret false
563end
564
565note take count c of every pair in bqsy[o .. o + n)
566fn bpsub o ulong n ulong c ulong to void
567for j ulong sub n 1
568x = ulong get bqsy add o j
569z = ulong get bqsy add add o j 1
570s = bppslot add mul x 4096 z
571bppcsub s c
572end
573end
574
575note replace (a, b) by t in bqsy[o .. o + n), left to right without overlap; returns the length
576fn bprpool o ulong n ulong a ulong b ulong t ulong to ulong
577w = ulong 0
578j = ulong 0
579while lt j n bound 128
580x = ulong get bqsy add o j
581z = ulong 65535
582if lt add j 1 n
583z = ulong get bqsy add add o j 1
584end
585if and eq x a eq z b
586put bqsy add o w ushort t
587j = add j 2
588else
589put bqsy add o w ushort x
590j = add j 1
591end
592w = add w 1
593end
594ret w
595end
596
597note add count c of every pair in bqsy[o .. o + m) of type y; list y under the pairs holding t
598fn bpadd o ulong m ulong c ulong y ulong t ulong to void
599for j ulong sub m 1
600x = ulong get bqsy add o j
601z = ulong get bqsy add add o j 1
602s = bppslot add mul x 4096 z
603bppcadd s c
604if or eq x t eq z t
605bpnode s y
606end
607end
608end
609
610note apply merge (a, b) -> t to type y, moving its pair counts
611fn bpmtype y ulong a ulong b ulong t ulong to void
612o = ulong get bqto y
613n = ulong get bqtn y
614if bphas o n a b
615c = get bqtc y
616bpsub o n c
617m = bprpool o n a b t
618put bqtn y uchar m
619bpadd o m c y t
620end
621end
622
623note merge t over every type listed under pair slot s (each type once: stamp t - 255)
624fn bpwalk s ulong a ulong b ulong t ulong to void
625nd = ulong get bqph s
626st = uint sub t 255
627for o ulong 5
628while gt nd 0 bound 999999
629y = ulong get bqnt sub nd 1
630nd = ulong get bqnx sub nd 1
631if ne get bqts y st
632put bqts y st
633bpmtype y a b t
634end
635end
636end
637end
638
639note merges 0 .. v - 257 into bqma/bqmb and obm[24 ..)
640fn bpmerge v ulong to void
641for k ulong sub v 256
642s = bpsel
643key = sub ulong get bqpk s 1
644a = div key 4096
645b = and key 4095
646t = add 256 k
647put bqma t ushort a
648put bqmb t ushort b
649p = add 24 mul 4 k
650put obm p uchar and a 255
651put obm add p 1 uchar shr a 8
652put obm add p 2 uchar and b 255
653put obm add p 3 uchar shr b 8
654put bqst 6 0
655bpwalk s a b t
656bpnewp
657end
658end
659
660note heap every pair slot made by this merge (bqnl[0 .. bqst 6)) that has a count
661fn bpnewp to void
662nw = get bqst 6
663for i ulong nw
664q = ulong get bqnl i
665c = get bqpc q
666if gt c 0
667kq = sub ulong get bqpk q 1
668bphpush bpkey c div kq 4096 and kq 4095
669end
670end
671end
672
673note obm[p .. p + 8) = v as u64 LE
674fn bpu64 p ulong v ulong to void
675for k ulong 8
676put obm add p k uchar and shr v mul k 8 255
677end
678end
679
680note FNV-1a 64 of obm[24 .. e)
681fn bpfnvm e ulong to ulong
682h = ulong 14695981039346656037
683for k ulong sub e 24
684h = mul xor h ulong get obm add 24 k 1099511628211
685end
686ret h
687end
688
689note u16 LE at opw[p]
690fn bprd16 p ulong to ulong
691lo = ulong get opw p
692hi = ulong get opw add p 1
693ret or lo shl hi 8
694end
695
696note u64 LE at opw[p]
697fn bprd64 p ulong to ulong
698v = ulong 0
699for k ulong 8
700v = or v shl ulong get opw add p k mul k 8
701end
702ret v
703end
704
705note read and check the merges file of argument ai (section 2.3; refusals 26) into bqma/bqmb;
706note returns its V. Uses opw.
707fn bpload ai ulong to ulong
708n = oprd ai 0 0 15385
709if or lt n 24 gt n 15384
710exit 26
711end
712if ne bprd64 0 3550332126946413647
713exit 26
714end
715vm = bprd64 8
716if or lt vm 257 gt vm 4096
717exit 26
718end
719if ne n add 24 mul 4 sub vm 256
720exit 26
721end
722h = ulong 14695981039346656037
723for k ulong sub n 24
724h = mul xor h ulong get opw add 24 k 1099511628211
725end
726if ne h bprd64 16
727exit 26
728end
729for k ulong sub vm 256
730p = add 24 mul 4 k
731a = bprd16 p
732b = bprd16 add p 2
733lk = add 256 k
734if or ge a lk ge b lk
735exit 26
736end
737t = add 256 k
738put bqma t ushort a
739put bqmb t ushort b
740end
741put bqv 1 vm
742ret vm
743end
744
745note use the first v - 256 merges: decoded lengths (held at 2^40) and the rank table
746fn bpsetv v ulong to void
747for t ulong 256
748put bqln t 1
749end
750for k ulong sub v 256
751t = add 256 k
752ma = ulong get bqma t
753mb = ulong get bqmb t
754la = get bqln ma
755s = add la get bqln mb
756if gt s BQLCAP
757s = BQLCAP
758end
759put bqln t s
760end
761for s ulong 8192
762put bqrk s 0
763end
764for k ulong sub v 256
765t = add 256 k
766ma = ulong get bqma t
767mb = ulong get bqmb t
768key = add mul ma 4096 mb
769s = shr mul add key 1 ulong 11400714819323198485 51
770dn = false
771while not dn bound 8192
772if eq get bqrk s 0
773put bqrk s uint add key 1
774put bqrt s ushort t
775dn = true
776else
777s = and add s 1 8191
778end
779end
780end
781put bqv 0 v
782end
783
784note write the decoded bytes of token t to stdout (mode 0), to output 0 (mode 1) or to the capture
785note buffer obo (mode 2, serve.om; bytes past obo's 4096 are dropped, so callers check obtlen first)
786fn bpexp t ulong mode ulong to void
787put bqsk 0 ushort t
788sp = ulong 1
789while gt sp 0 bound 999999
790q = ulong 0
791while and gt sp 0 lt q 999999 bound 999999
792q = add q 1
793sp = sub sp 1
794x = ulong get bqsk sp
795if lt x 256
796if eq mode 0
797oputc x
798else
799if eq mode 1
800owbyte 0 x
801else
802n = get obon 0
803if lt n 4096
804put obo n uchar x
805put obon 0 add n 1
806end
807end
808end
809else
810put bqsk sp get bqmb x
811put bqsk add sp 1 get bqma x
812sp = add sp 2
813end
814end
815end
816end
817
818note decode token t to output 0 and add its length to bqst 4
819fn bpdec1 t ulong to void
820bpexp t 1
821put bqst 4 add get bqst 4 get bqln t
822end
823
824note token file argument ai: mode 0 checks it (exit 21 odd length, then 25 a token >= v) and
825note returns its token count; mode 1 decodes it to output 0 (bqst 4 = bytes)
826fn bpdscan ai ulong v ulong mode ulong to ulong
827opstart ai
828i = ulong 0
829nt = ulong 0
830bad = false
831odd = false
832dn = false
833while not dn bound 999999
834q = ulong 0
835while and not dn lt q 999999 bound 999999
836q = add q 1
837i = bprefil ai i 2
838wn = get opst 1
839if gt add i 2 wn
840dn = true
841if lt i wn
842odd = true
843end
844else
845t = bprd16 i
846if ge t v
847bad = true
848end
849if eq mode 1
850bpdec1 t
851end
852nt = add nt 1
853i = add i 2
854end
855end
856end
857if odd
858exit 21
859end
860if bad
861exit 25
862end
863ret nt
864end
865
866note print C a b c (C = 77 M, 75 K, 68 D)
867fn bpline c ulong a ulong b ulong d ulong to void
868oputc c
869oputc 32
870oputu a
871oputc 32
872oputu b
873if ne c 75
874if ne c 68
875oputc 32
876oputu d
877end
878end
879oputc 10
880oflush
881end
882
883note section 8: load merges argument ai for vocabulary v (26, 27)
884fn obload ai ulong v ulong to void
885vm = bpload ai
886if or le v 256 gt v vm
887exit 27
888end
889bpsetv v
890bpcls
891end
892
893fn obtlen t ulong to ulong
894ret get bqln t
895end
896
897fn obtput t ulong to void
898bpexp t 0
899end
900
901note the decoded bytes of token t into obo[0 .. obon[0]) (serve.om)
902fn obtcap t ulong to void
903put obon 0 0
904bpexp t 2
905end
906
907note section 8: encode argument ai (at most 4000 bytes, CONTRACT 7.2; longer exit 2) into obtk;
908note returns the token count
909fn obprompt ai ulong to ulong
910n = oargp ai
911if gt n 4000
912exit 2
913end
914ret obpenc n
915end
916
917note encode oarg[0 .. n), n <= 4000, into obtk; returns the token count (obprompt, serve.om)
918fn obpenc n ulong to ulong
919i = ulong 0
920m = ulong 0
921while lt i n bound 4097
922l = bpclena i n
923for k ulong l
924put bqtm k ushort get oarg add i k
925end
926c = bpenct l
927for k ulong c
928put obtk add m k ulong get bqtm k
929end
930m = add m c
931i = add i l
932end
933ret m
934end
935
936note bpefit TEXT MERGES V [MAXBYTES]
937fn cmdbpfit to void
938na = oargc
939if or lt na 5 gt na 6
940exit 2
941end
942v = oargu 4
943if or lt v 257 gt v 4096
944exit 2
945end
946lim = ulong 18446744073709551615
947if eq na 6
948lim = bpcut 2 oargu 5
949end
950bpcls
951bpscan 2 lim 0 0
952bpinit
953bpmerge v
954nb = add 24 mul 4 sub v 256
955bpu64 0 3550332126946413647
956bpu64 8 v
957bpu64 16 bpfnvm nb
958obmsave 3 nb
959oputc 77
960oputc 32
961oputu v
962oputc 32
963oputu get bqst 0
964oputc 32
965oputu get bqst 2
966oputc 32
967oputu get bqst 3
968oputc 10
969oflush
970end
971
972note bpeenc MERGES V TEXT TOKS
973fn cmdbpenc to void
974if ne oargc 6
975exit 2
976end
977v = oargu 3
978obload 2 v
979bpscan 4 ulong 18446744073709551615 1 5
980owclose 0
981bpline 75 get bqst 3 get bqst 4 0
982end
983
984note bpedec MERGES TOKS OUT (V = the file's V)
985fn cmdbpdec to void
986if ne oargc 5
987exit 2
988end
989vm = bpload 2
990bpsetv vm
991nt = bpdscan 3 vm 0
992owopen 0 4
993put bqst 4 0
994nd = bpdscan 3 vm 1
995owclose 0
996bpline 68 nt get bqst 4 0
997end