interplane.Get Omega
Read in your language

omega-helix

This project has not described itself yet.

Brought by drakestapleton

branch main Branches Tags History

omega-helix / native / univ / uarena.om

552 lines · 8365 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note native/univ/uarena.om: Dynamic zero-cap memory arenas, OLLMCK04 geometry, RoPE table builder,
3note and streaming u8/u16/u32 token reader. Works identically on Linux AArch64 and macOS Apple Silicon.
4
5const UCH ulong 500000
6const UOPWCAP ulong 1048576
7
8global up f64 *
9global ugd f64 *
10global um f64 *
11global uv f64 *
12global ua f64 *
13global upa f64 *
14global ucos f64 *
15global usin f64 *
16global ukvc f64 *
17global uvvc f64 *
18global ubx ulong *
19global uby ulong *
20global ulos f64 *
21global utmp f64 *
22global ukv_toks ulong *
23
24global uarg uchar 4100
25global upath uchar 4100
26global upk uchar 8220
27global uck uchar 524288
28global uopw uchar 1048576
29global ucfd int 1
30
31fn ucn n ulong to ulong
32if eq n 0
33ret 0
34end
35ret div add n sub UCH 1 UCH
36end
37
38fn uce q ulong n ulong to ulong
39e = mul add q 1 UCH
40if gt e n
41ret n
42end
43ret e
44end
45
46fn uargp i ulong to ulong
47r = argread i uarg 0 4096
48if or le r 0 gt r 4096
49exit 2
50end
51ret ulong r
52end
53
54fn uargu i ulong to ulong
55n = uargp i
56if gt n 19
57exit 2
58end
59v = ulong 0
60for k ulong n
61c = ulong get uarg k
62if or lt c 48 gt c 57
63exit 2
64end
65v = add mul v 10 sub c 48
66end
67ret v
68end
69
70fn uofsz ai ulong to ulong
71n = uargp ai
72fd = int fopen uarg 0 n 0 0
73if lt fd 0
74exit 70
75end
76sz = fseek fd 0 2
77if lt sz 0
78exit 70
79end
80if ne fclose fd 0
81exit 70
82end
83ret ulong sz
84end
85
86fn uoprd ai ulong pos ulong off ulong n ulong to ulong
87plen = uargp ai
88fd = int fopen uarg 0 plen 0 0
89if lt fd 0
90exit 70
91end
92got = ulong 0
93while lt got n bound 999999
94r = pread fd uopw add off got sub n got long add pos got
95if lt r 0
96c = fclose fd
97exit 70
98end
99if eq r 0
100break
101end
102got = add got ulong r
103end
104if ne fclose fd 0
105exit 70
106end
107ret got
108end
109
110fn ugeom_check to bool
111for i ulong 8
112if eq get ug i 0
113ret false
114end
115end
116if lt get ug 0 2
117ret false
118end
119d = get ug 2
120h = get ug 3
121hkv = get ug 4
122if ne rem d h 0
123ret false
124end
125if or gt hkv h ne rem h hkv 0
126ret false
127end
128e = div d h
129put ug 8 e
130put ug 9 mul hkv e
131fl = get ug 12
132if and ne and fl 2 0 ne and fl 64 0
133ret false
134end
135if and ne and fl 66 0 ne and fl 32 0
136ret false
137end
138if and ne and fl 1 0 ne rem e 2 0
139ret false
140end
141put ug 28 0
142put ug 29 0
143put ug 30 0
144put ug 31 0
145if ne and fl 1 0
146put ug 28 1
147end
148if ne and fl 66 0
149put ug 29 1
150end
151if ne and fl 4 0
152put ug 30 1
153end
154if ne and fl 8 0
155put ug 31 1
156end
157ret true
158end
159
160fn ugeom_params to bool
161ll = get ug 6
162np = get ug 19
163if gt np 1
164lc = get ug 18
165if or eq lc 0 gt add get ug 17 lc ll
166ret false
167end
168put ug 11 add ll mul lc sub np 1
169else
170put ug 11 ll
171end
172d = get ug 2
173kvd = get ug 9
174f = get ug 5
175wpe = mul get ug 0 d
176put ug 32 wpe
177lay0 = wpe
178if eq get ug 28 0
179lay0 = add lay0 mul get ug 1 d
180end
181put ug 33 lay0
182o = add add d mul d d mul 2 mul d kvd
183o = add o mul d d
184put ug 54 o
185if eq get ug 31 1
186o = add o get ug 8
187put ug 55 o
188o = add o get ug 8
189else
190put ug 55 o
191end
192put ug 56 o
193o = add o d
194put ug 57 o
195o = add o mul d f
196put ug 58 o
197if eq get ug 29 1
198o = add o mul d f
199end
200put ug 59 o
201o = add o mul f d
202put ug 34 o
203gf = add lay0 mul ll o
204put ug 35 gf
205lmh = add gf d
206put ug 36 lmh
207if eq get ug 30 1
208put ug 10 add lmh mul get ug 0 d
209else
210put ug 10 lmh
211end
212put ug 24 get ug 1
213tw = ulong 1
214if gt get ug 0 256
215tw = 2
216end
217if gt get ug 0 65535
218tw = 4
219end
220put ug 25 tw
221ret true
222end
223
224fn ugeom_acts to void
225t = get ug 1
226td = mul t get ug 2
227tkv = mul t get ug 9
228tf = mul t get ug 5
229a = add add mul 6 td mul 2 tkv add mul 2 t mul 3 tf
230if eq get ug 31 1
231a = add a add add mul t get ug 3 mul t get ug 4 add td tkv
232end
233put ug 37 a
234put ug 38 mul mul get ug 3 t t
235o = mul get ug 11 a
236put ug 39 o
237o = add o td
238put ug 40 o
239o = add o t
240put ug 41 o
241o = add o td
242put ug 42 o
243o = add o mul t get ug 0
244put ug 43 o
245o = add o td
246put ug 44 o
247o = add o td
248put ug 45 o
249o = add o td
250put ug 46 o
251o = add o tkv
252put ug 47 o
253o = add o tkv
254put ug 48 o
255o = add o td
256put ug 49 o
257o = add o td
258put ug 50 o
259o = add o tf
260put ug 51 o
261o = add o tf
262put ug 52 o
263end
264
265fn ugeom_alloc to void
266p = get ug 10
267r = enlarge up p
268if ne r 0
269exit 70
270end
271r = enlarge ugd p
272if ne r 0
273exit 70
274end
275r = enlarge um p
276if ne r 0
277exit 70
278end
279r = enlarge uv p
280if ne r 0
281exit 70
282end
283r = enlarge ua get ug 52
284if ne r 0
285exit 70
286end
287r = enlarge upa mul get ug 11 get ug 38
288if ne r 0
289exit 70
290end
291bt = mul get ug 7 get ug 1
292r = enlarge ubx bt
293if ne r 0
294exit 70
295end
296r = enlarge uby bt
297if ne r 0
298exit 70
299end
300r = enlarge ulos get ug 7
301if ne r 0
302exit 70
303end
304ts = get ug 0
305if gt get ug 1 ts
306ts = get ug 1
307end
308if gt get ug 2 ts
309ts = get ug 2
310end
311if gt get ug 5 ts
312ts = get ug 5
313end
314r = enlarge utmp add ts 256
315if ne r 0
316exit 70
317end
318kvsz = mul get ug 11 mul get ug 1 get ug 9
319r = enlarge ukvc kvsz
320if ne r 0
321exit 70
322end
323r = enlarge uvvc kvsz
324if ne r 0
325exit 70
326end
327end
328
329fn urobe_col i ulong lth f64 to void
330t = get ug 1
331he = div get ug 8 2
332freq = ufexp mul neg lth div f64 mul 2 i f64 get ug 8
333for pos ulong t
334ang = mul f64 pos freq
335idx = add mul pos he i
336put ucos idx ufcos ang
337put usin idx ufsin ang
338end
339end
340
341fn urobe_init to void
342sz = mul get ug 1 div get ug 8 2
343r = enlarge ucos sz
344if ne r 0
345exit 70
346end
347r = enlarge usin sz
348if ne r 0
349exit 70
350end
351th = div f64 get ug 13 1000.0
352if le th 0.0
353th = 10000.0
354end
355lth = uflog th
356for i ulong div get ug 8 2
357urobe_col i lth
358end
359end
360
361fn ugeom to bool
362if not ugeom_check
363ret false
364end
365if not ugeom_params
366ret false
367end
368ugeom_acts
369ugeom_alloc
370if eq get ug 28 1
371urobe_init
372end
373ret true
374end
375
376fn ulp l ulong to ulong
377np = get ug 19
378if le np 1
379ret l
380end
381lp = get ug 17
382if lt l lp
383ret l
384end
385lc = get ug 18
386j = sub l lp
387if lt j mul lc np
388ret add lp rem j lc
389end
390ret sub l mul lc sub np 1
391end
392
393fn up_lay l ulong to ulong
394ret add get ug 33 mul l get ug 34
395end
396fn up_g1 l ulong to ulong
397ret up_lay l
398end
399fn up_wq l ulong to ulong
400ret add up_lay l get ug 2
401end
402fn up_wk l ulong to ulong
403d = get ug 2
404ret add up_wq l mul d d
405end
406fn up_wv l ulong to ulong
407ret add up_wk l mul get ug 2 get ug 9
408end
409fn up_wo l ulong to ulong
410ret add up_wv l mul get ug 2 get ug 9
411end
412fn up_qn l ulong to ulong
413ret add up_lay l get ug 54
414end
415fn up_kn l ulong to ulong
416ret add up_lay l get ug 55
417end
418fn up_g2 l ulong to ulong
419ret add up_lay l get ug 56
420end
421fn up_w1 l ulong to ulong
422ret add up_lay l get ug 57
423end
424fn up_wup l ulong to ulong
425ret add up_lay l get ug 58
426end
427fn up_w2 l ulong to ulong
428ret add up_lay l get ug 59
429end
430
431fn ua_base l ulong to ulong
432ret mul l get ug 37
433end
434fn ua_hin l ulong to ulong
435ret ua_base l
436end
437fn ua_a l ulong to ulong
438ret add ua_base l mul get ug 1 get ug 2
439end
440fn ua_q l ulong to ulong
441ret add ua_a l mul get ug 1 get ug 2
442end
443fn ua_k l ulong to ulong
444ret add ua_q l mul get ug 1 get ug 2
445end
446fn ua_v l ulong to ulong
447ret add ua_k l mul get ug 1 get ug 9
448end
449fn ua_o l ulong to ulong
450ret add ua_v l mul get ug 1 get ug 9
451end
452fn ua_hmid l ulong to ulong
453ret add ua_o l mul get ug 1 get ug 2
454end
455fn ua_bn l ulong to ulong
456ret add ua_hmid l mul get ug 1 get ug 2
457end
458fn ua_s1 l ulong to ulong
459ret add ua_bn l mul get ug 1 get ug 2
460end
461fn ua_s2 l ulong to ulong
462ret add ua_s1 l get ug 1
463end
464fn ua_f1 l ulong to ulong
465ret add ua_s2 l get ug 1
466end
467fn ua_f2 l ulong to ulong
468ret add ua_f1 l mul get ug 1 get ug 5
469end
470fn ua_f3 l ulong to ulong
471ret add ua_f2 l mul get ug 1 get ug 5
472end
473fn ua_qns l ulong to ulong
474ret add ua_f3 l mul get ug 1 get ug 5
475end
476fn ua_kns l ulong to ulong
477ret add ua_qns l mul get ug 1 get ug 3
478end
479fn ua_qpre l ulong to ulong
480ret add ua_kns l mul get ug 1 get ug 4
481end
482fn ua_kpre l ulong to ulong
483ret add ua_qpre l mul get ug 1 get ug 2
484end
485
486fn udopen ai ulong to void
487w = get ug 25
488nb = uofsz ai
489if ne rem nb w 0
490exit 21
491end
492n = div nb w
493if le n get ug 1
494exit 20
495end
496put ug 26 ai
497put ug 27 n
498end
499
500fn udtk k ulong to ulong
501w = get ug 25
502if eq w 1
503ret ulong get uopw k
504end
505if eq w 2
506lo = ulong get uopw mul k 2
507hi = ulong get uopw add mul k 2 1
508ret or shl hi 8 lo
509end
510b = mul k 4
511v = ulong get uopw b
512v = or v shl ulong get uopw add b 1 8
513v = or v shl ulong get uopw add b 2 16
514v = or v shl ulong get uopw add b 3 24
515ret v
516end
517
518fn udrow o ulong n ulong to void
519w = get ug 25
520nb = mul n w
521if gt nb UOPWCAP
522exit 21
523end
524r = uoprd get ug 26 mul o w 0 nb
525m = div r w
526v = get ug 0
527for k ulong m
528if ge udtk k v
529exit 25
530end
531end
532end
533
534fn ubrow b ulong o ulong to void
535t = get ug 1
536udrow o add t 1
537for j ulong t
538put ubx add mul b t j udtk j
539put uby add mul b t j udtk add j 1
540end
541end
542
543fn ubatch s ulong to void
544bb = get ug 7
545t = get ug 1
546n = get ug 27
547sd = get ug 20
548for b ulong bb
549o = rem usmx xor sd mul add mul s bb b 11400714819323198485 sub n t
550ubrow b o
551end
552end