omega-helix
This project has not described itself yet.
Brought by drakestapleton
omega-helix / native / univ / interchange.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note native/univ/interchange.om: Pure-Omega Universal Weight Interchange (ollm-interchange), Phase 3. |
| 3 | note Built by `TARGET=interchange sh scripts/build.sh` after net/json.om, net/jsonw.om, univ/umath.om, |
| 4 | note univ/uarena.om and univ/uckpt.om. No float library, no C, no Python: every byte is read and written here. |
| 5 | note |
| 6 | note Commands (argv[1]): |
| 7 | note import-hf CONFIG.json MODEL.safetensors OUT.ck [T B TOTAL LRMICRO] |
| 8 | note model_type llama | mistral | qwen2 | qwen3 | gemma | helix; dtypes F32 BF16 F16 F64. |
| 9 | note HF linear weights [out][in] are transposed into Helix [in][out] row-major (y = x . W). |
| 10 | note Flags: llama/mistral/qwen2 1|2|16, qwen3 1|2|8|16 (each +4 when untied), gemma 1|4|16|64 with |
| 11 | note wte = embed * sqrt(D), lmh = embed and every gemma RMSNorm gain stored as 1 + w; helix from |
| 12 | note helix_arch_flags + helix_loop_lp/lc/np. Defaults T = min(max_position_embeddings, 256) (WPE models: |
| 13 | note T = rows of model.embed_positions.weight), B 1, TOTAL 1000, LRMICRO 100, seed 0, step 0, m = v = 0. |
| 14 | note stdout `I V T D H HKV F L P FLAGS`. |
| 15 | note export-hf IN.ck OUT_DIR [f32|bf16] -> OUT_DIR/config.json (jsonw.om) + OUT_DIR/model.safetensors. |
| 16 | note OUT_DIR must exist (the a64macos target has no makedir host word; exit 70 otherwise). |
| 17 | note stdout `XH NTENSORS SAFETENSORS_BYTES`. |
| 18 | note export-gguf IN.ck OUT.gguf -> GGUF v3 (magic 1179993927), 20 KV pairs, F32 tensors, 32-byte |
| 19 | note aligned data; llama arch Q/K rows permuted as convert_hf_to_gguf. stdout `XG NTENSORS FILE_BYTES`. |
| 20 | note upgrade LEGACY.ck OUT.ck -> OLLMCK01/02/03 to OLLMCK04 (gpt flags 0, HKV = H, eps 1e-5, |
| 21 | note loop from CK03, p/m/v bit-exact). stdout `U VER P`. |
| 22 | note Architecture rule for both exports (loop NP <= 1 for every named family): RoPE+SwiGLU+QKnorm = qwen3, |
| 23 | note RoPE+SwiGLU = llama, RoPE+GeGLU+untied with wte == lmh*sqrt(D) bit for bit = gemma, else helix. |
| 24 | note Exit codes: 2 usage, 70 I/O, 80 config JSON malformed, 81 config field missing/invalid or model_type |
| 25 | note unsupported, 82 unsupported feature (rope_scaling, head_dim != D/H, activation, nonzero bias, sliding |
| 26 | note window < T), 83 safetensors header malformed (size, JSON, entry, byte size, overlap, hole, trailing, |
| 27 | note duplicate), 84 tensor missing/unknown or dtype unsupported, 85 shape mismatch, 86 NaN/Inf weight, |
| 28 | note 87 truncated safetensors, 88 geometry refused; CK loads 10..15 exactly as uckpt.om. |
| 29 | |
| 30 | const IXOB ulong 1048576 |
| 31 | const IXBIG ulong 9223372036854775807 |
| 32 | |
| 33 | note ixc config slots: 0 model_type (1 llama 2 qwen2 3 qwen3 4 mistral 5 gemma 6 helix 99 other) |
| 34 | note 1 V 2 D 3 H 4 HKV 5 F 6 L 7 max_pos 8 head_dim 9 eps bits 10 eps set 11 theta bits 12 theta set |
| 35 | note 13 tie (0 absent 1 false 2 true) 14 rope_scaling set 15 sliding_window 16 use_sliding_window |
| 36 | note 17 hidden_act 18 hidden_activation (0 none 1 silu 2 gelu-tanh 3 other 4 gelu-erf 5 relu) |
| 37 | note 19 helix flags 20 helix flags set 21 LP 22 LC 23 NP |
| 38 | global ixc ulong 64 |
| 39 | note ixs state: 0 extents 1 safetensors fd 2 data base 3 data bytes 4 table slots 5 name length |
| 40 | note 6 out fill 7 out file pos 8 out fd 9 path length 10 export tensors 11 T given 12 T arg |
| 41 | note 13 extent capacity 14 suffix pos 15 B 16 TOTAL 17 LRMICRO |
| 42 | global ixs ulong 32 |
| 43 | global ixt ulong * |
| 44 | global ixe ulong * |
| 45 | global ixl ulong * |
| 46 | note ixq one export tensor: 0 code 1 layer 2 ndims 3 rows 4 cols 5 helix base 6 kind 7 heads |
| 47 | global ixq ulong 8 |
| 48 | note ixent one safetensors entry: 0 dtype 1 ndims 2 d0 3 d1 4 begin 5 end 6 numel 7 seen mask |
| 49 | global ixent ulong 8 |
| 50 | note ixld tensor load: 0 dtype 1 base 2 mode 3 rows 4 cols |
| 51 | global ixld ulong 8 |
| 52 | note ixm export mode: 0 arch (1 llama 3 qwen3 5 gemma 6 helix) 1 bf16 2 permute q/k 3 gguf |
| 53 | global ixm ulong 4 |
| 54 | global ixf f64 4 |
| 55 | global ixnm uchar 1100 |
| 56 | global ixpath uchar 4400 |
| 57 | global ixob uchar 1048576 |
| 58 | |
| 59 | const OLLMBF01_MAG ulong 3544410157319212111 |
| 60 | note bfi: 0=V 1=D 2=H 3=HKV 4=HD 5=F 6=L 7=fl 8=th_milli 9=eps_bits 10=max_pos 11=P |
| 61 | note 12=payload_bytes 13=qdim 14=kvd 15=n_shards 16=gem 17=untied 18=wfnv 19=thash 20=hfnv |
| 62 | note 21=out_pl 22=sh_sl_cnt 23=dir_len 24=pad_bytes |
| 63 | global bfi ulong 32 |
| 64 | global bfo ulong * |
| 65 | global bfsl ulong * |
| 66 | global bfsh uchar 65536 |
| 67 | global bfshn ulong 256 |
| 68 | global bfdir uchar 4096 |
| 69 | |
| 70 | text ix_c_imp "import-hf" |
| 71 | text ix_c_impbf "import-hf-bf16" |
| 72 | text ix_c_infobf "info-bf16" |
| 73 | text ix_c_exh "export-hf" |
| 74 | text ix_c_exg "export-gguf" |
| 75 | text ix_c_upg "upgrade" |
| 76 | text ix_s_f32 "f32" |
| 77 | text ix_s_bf16 "bf16" |
| 78 | text ixp_idx "model.safetensors.index.json" |
| 79 | text ixp_st1 "model.safetensors" |
| 80 | text ixp_cfg1 "config.json" |
| 81 | text ixk_wm "weight_map" |
| 82 | |
| 83 | text ixk_mt "model_type" |
| 84 | text ixk_vs "vocab_size" |
| 85 | text ixk_hs "hidden_size" |
| 86 | text ixk_nh "num_attention_heads" |
| 87 | text ixk_kv "num_key_value_heads" |
| 88 | text ixk_is "intermediate_size" |
| 89 | text ixk_nl "num_hidden_layers" |
| 90 | text ixk_mp "max_position_embeddings" |
| 91 | text ixk_hd "head_dim" |
| 92 | text ixk_eps "rms_norm_eps" |
| 93 | text ixk_th "rope_theta" |
| 94 | text ixk_tie "tie_word_embeddings" |
| 95 | text ixk_rs "rope_scaling" |
| 96 | text ixk_sw "sliding_window" |
| 97 | text ixk_usw "use_sliding_window" |
| 98 | text ixk_act "hidden_act" |
| 99 | text ixk_acn "hidden_activation" |
| 100 | text ixk_hf "helix_arch_flags" |
| 101 | text ixk_lp "helix_loop_lp" |
| 102 | text ixk_lc "helix_loop_lc" |
| 103 | text ixk_np "helix_loop_np" |
| 104 | text ixk_arch "architectures" |
| 105 | text ixk_td "torch_dtype" |
| 106 | text ixk_ab "attention_bias" |
| 107 | |
| 108 | text ixv_llama "llama" |
| 109 | text ixv_qwen2 "qwen2" |
| 110 | text ixv_qwen3 "qwen3" |
| 111 | text ixv_mistral "mistral" |
| 112 | text ixv_gemma "gemma" |
| 113 | text ixv_helix "helix" |
| 114 | text ixv_silu "silu" |
| 115 | text ixv_gtanh "gelu_pytorch_tanh" |
| 116 | text ixv_gnew "gelu_new" |
| 117 | text ixv_gelu "gelu" |
| 118 | text ixv_relu "relu" |
| 119 | text ixv_allama "LlamaForCausalLM" |
| 120 | text ixv_aqwen3 "Qwen3ForCausalLM" |
| 121 | text ixv_agemma "GemmaForCausalLM" |
| 122 | text ixv_ahelix "HelixForCausalLM" |
| 123 | text ixv_fp32 "float32" |
| 124 | text ixv_bf16 "bfloat16" |
| 125 | |
| 126 | text ixs_meta "__metadata__" |
| 127 | text ixs_fmt "format" |
| 128 | text ixs_pt "pt" |
| 129 | text ixs_dtype "dtype" |
| 130 | text ixs_shape "shape" |
| 131 | text ixs_doff "data_offsets" |
| 132 | text ixs_F32 "F32" |
| 133 | text ixs_BF16 "BF16" |
| 134 | text ixs_F16 "F16" |
| 135 | text ixs_F64 "F64" |
| 136 | |
| 137 | text ixn_emb "model.embed_tokens.weight" |
| 138 | text ixn_pos "model.embed_positions.weight" |
| 139 | text ixn_norm "model.norm.weight" |
| 140 | text ixn_lmh "lm_head.weight" |
| 141 | text ixn_lay "model.layers." |
| 142 | text ixn_inv "rotary_emb.inv_freq" |
| 143 | text ixr_0 "input_layernorm.weight" |
| 144 | text ixr_1 "self_attn.q_proj.weight" |
| 145 | text ixr_2 "self_attn.k_proj.weight" |
| 146 | text ixr_3 "self_attn.v_proj.weight" |
| 147 | text ixr_4 "self_attn.o_proj.weight" |
| 148 | text ixr_5 "self_attn.q_norm.weight" |
| 149 | text ixr_6 "self_attn.k_norm.weight" |
| 150 | text ixr_7 "post_attention_layernorm.weight" |
| 151 | text ixr_8 "mlp.gate_proj.weight" |
| 152 | text ixr_9 "mlp.up_proj.weight" |
| 153 | text ixr_10 "mlp.down_proj.weight" |
| 154 | text ixr_11 "self_attn.q_proj.bias" |
| 155 | text ixr_12 "self_attn.k_proj.bias" |
| 156 | text ixr_13 "self_attn.v_proj.bias" |
| 157 | text ixr_14 "self_attn.o_proj.bias" |
| 158 | text ixr_15 "mlp.gate_proj.bias" |
| 159 | text ixr_16 "mlp.up_proj.bias" |
| 160 | text ixr_17 "mlp.down_proj.bias" |
| 161 | |
| 162 | text ixg_temb "token_embd.weight" |
| 163 | text ixg_tpos "position_embd.weight" |
| 164 | text ixg_tnorm "output_norm.weight" |
| 165 | text ixg_tout "output.weight" |
| 166 | text ixg_blk "blk." |
| 167 | text ixg_r0 ".attn_norm.weight" |
| 168 | text ixg_r1 ".attn_q.weight" |
| 169 | text ixg_r2 ".attn_k.weight" |
| 170 | text ixg_r3 ".attn_v.weight" |
| 171 | text ixg_r4 ".attn_output.weight" |
| 172 | text ixg_r5 ".attn_q_norm.weight" |
| 173 | text ixg_r6 ".attn_k_norm.weight" |
| 174 | text ixg_r7 ".ffn_norm.weight" |
| 175 | text ixg_r8 ".ffn_gate.weight" |
| 176 | text ixg_r9 ".ffn_up.weight" |
| 177 | text ixg_r10 ".ffn_down.weight" |
| 178 | text ixg_arch "general.architecture" |
| 179 | text ixg_name "general.name" |
| 180 | text ixg_namev "omega-helix" |
| 181 | text ixg_align "general.alignment" |
| 182 | text ixg_ftype "general.file_type" |
| 183 | text ixg_vs ".vocab_size" |
| 184 | text ixg_ctx ".context_length" |
| 185 | text ixg_emb ".embedding_length" |
| 186 | text ixg_blkc ".block_count" |
| 187 | text ixg_ffn ".feed_forward_length" |
| 188 | text ixg_hc ".attention.head_count" |
| 189 | text ixg_hkv ".attention.head_count_kv" |
| 190 | text ixg_kl ".attention.key_length" |
| 191 | text ixg_vl ".attention.value_length" |
| 192 | text ixg_eps ".attention.layer_norm_rms_epsilon" |
| 193 | text ixg_fb ".rope.freq_base" |
| 194 | text ixg_rd ".rope.dimension_count" |
| 195 | text ixg_hfl "helix.arch_flags" |
| 196 | text ixg_hlp "helix.loop.lp" |
| 197 | text ixg_hlc "helix.loop.lc" |
| 198 | text ixg_hnp "helix.loop.np" |
| 199 | |
| 200 | text ixp_cfg "/config.json" |
| 201 | text ixp_st "/model.safetensors" |
| 202 | |
| 203 | note ======== small helpers ======== |
| 204 | |
| 205 | fn ix_arg_eq ai ulong s view uchar * to bool |
| 206 | r = argread ai uarg 0 4096 |
| 207 | if ne r long len s |
| 208 | ret false |
| 209 | end |
| 210 | for i ulong len s |
| 211 | if ne get uarg i get s i |
| 212 | ret false |
| 213 | end |
| 214 | end |
| 215 | ret true |
| 216 | end |
| 217 | |
| 218 | fn ix_bad v f64 to bool |
| 219 | ret ne sub v v 0.0 |
| 220 | end |
| 221 | |
| 222 | fn ix_p10 k ulong to f64 |
| 223 | r = 1.0f64 |
| 224 | for i ulong k bound 400 |
| 225 | r = mul r 10.0 |
| 226 | end |
| 227 | ret r |
| 228 | end |
| 229 | |
| 230 | note m * 10^ex: one correctly rounded operation when m < 2^53 and |ex| <= 22 (both operands exact) |
| 231 | fn ix_scale m ulong ex long to f64 |
| 232 | if eq m 0 |
| 233 | ret 0.0f64 |
| 234 | end |
| 235 | v = f64 m |
| 236 | x = ex |
| 237 | if lt m 9007199254740992 |
| 238 | if and ge x -22 le x 22 |
| 239 | if ge x 0 |
| 240 | ret mul v ix_p10 ulong x |
| 241 | end |
| 242 | ret div v ix_p10 ulong neg x |
| 243 | end |
| 244 | end |
| 245 | while gt x 22 bound 100000 |
| 246 | v = mul v 1.0e22 |
| 247 | x = sub x 22 |
| 248 | end |
| 249 | while lt x -22 bound 100000 |
| 250 | v = div v 1.0e22 |
| 251 | x = add x 22 |
| 252 | end |
| 253 | if ge x 0 |
| 254 | ret mul v ix_p10 ulong x |
| 255 | end |
| 256 | ret div v ix_p10 ulong neg x |
| 257 | end |
| 258 | |
| 259 | fn ix_nexp src view uchar * p ulong e ulong to long |
| 260 | q = p |
| 261 | ng = false |
| 262 | if lt q e |
| 263 | c = get src q |
| 264 | if eq c 45 |
| 265 | ng = true |
| 266 | q = add q 1 |
| 267 | else |
| 268 | if eq c 43 |
| 269 | q = add q 1 |
| 270 | end |
| 271 | end |
| 272 | end |
| 273 | x = long 0 |
| 274 | while lt q e bound 1000000 |
| 275 | d = long sub get src q 48 |
| 276 | if lt x 100000 |
| 277 | x = add mul x 10 d |
| 278 | end |
| 279 | q = add q 1 |
| 280 | end |
| 281 | if ng |
| 282 | ret neg x |
| 283 | end |
| 284 | ret x |
| 285 | end |
| 286 | |
| 287 | note a JSON number lexeme src[off .. off + n) as f64 (19 significant digits, then ix_scale) |
| 288 | fn ix_numf src view uchar * off ulong n ulong to f64 |
| 289 | e = add off n |
| 290 | p = off |
| 291 | ng = false |
| 292 | if eq get src p 45 |
| 293 | ng = true |
| 294 | p = add p 1 |
| 295 | end |
| 296 | m = ulong 0 |
| 297 | nd = ulong 0 |
| 298 | ex = long 0 |
| 299 | fr = false |
| 300 | while lt p e bound 1000000 |
| 301 | c = get src p |
| 302 | if or eq c 101 eq c 69 |
| 303 | ex = add ex ix_nexp src add p 1 e |
| 304 | break |
| 305 | end |
| 306 | if eq c 46 |
| 307 | fr = true |
| 308 | else |
| 309 | if lt nd 19 |
| 310 | m = add mul m 10 ulong sub c 48 |
| 311 | if gt m 0 |
| 312 | nd = add nd 1 |
| 313 | end |
| 314 | if fr |
| 315 | ex = sub ex 1 |
| 316 | end |
| 317 | else |
| 318 | if not fr |
| 319 | ex = add ex 1 |
| 320 | end |
| 321 | end |
| 322 | end |
| 323 | p = add p 1 |
| 324 | end |
| 325 | v = ix_scale m ex |
| 326 | if ng |
| 327 | ret neg v |
| 328 | end |
| 329 | ret v |
| 330 | end |
| 331 | |
| 332 | fn ix_e10 a f64 to long |
| 333 | k = long 0 |
| 334 | x = a |
| 335 | while ge x 10.0 bound 400 |
| 336 | x = div x 10.0 |
| 337 | k = add k 1 |
| 338 | end |
| 339 | while lt x 1.0 bound 400 |
| 340 | x = mul x 10.0 |
| 341 | k = sub k 1 |
| 342 | end |
| 343 | ret k |
| 344 | end |
| 345 | |
| 346 | fn ix_cand a f64 sc long to ulong |
| 347 | x = a |
| 348 | if ge sc 0 |
| 349 | x = mul a ix_p10 ulong sc |
| 350 | else |
| 351 | x = div a ix_p10 ulong neg sc |
| 352 | end |
| 353 | ret ulong add x 0.5 |
| 354 | end |
| 355 | |
| 356 | fn ix_lexu lex edit uchar * w ulong v ulong to ulong |
| 357 | tmp = new uchar 24 0 |
| 358 | k = ulong 0 |
| 359 | x = v |
| 360 | while true bound 21 |
| 361 | put tmp k uchar add rem x 10 48 |
| 362 | k = add k 1 |
| 363 | x = div x 10 |
| 364 | if eq x 0 |
| 365 | break |
| 366 | end |
| 367 | end |
| 368 | q = w |
| 369 | while gt k 0 bound 21 |
| 370 | k = sub k 1 |
| 371 | put lex q get tmp k |
| 372 | q = add q 1 |
| 373 | end |
| 374 | ret q |
| 375 | end |
| 376 | |
| 377 | note shortest decimal (<= 17 digits) that ix_numf reads back to the same f64 bits |
| 378 | fn ix_fmt lex edit uchar * v f64 to ulong |
| 379 | if eq v 0.0 |
| 380 | put lex 0 48 |
| 381 | ret 1 |
| 382 | end |
| 383 | a = fabs v |
| 384 | k = ix_e10 a |
| 385 | want = bitcast ulong a |
| 386 | mm = ulong 0 |
| 387 | sc = long 0 |
| 388 | for p ulong 17 |
| 389 | sc = sub long p k |
| 390 | mm = ix_cand a sc |
| 391 | if eq bitcast ulong ix_scale mm neg sc want |
| 392 | break |
| 393 | end |
| 394 | end |
| 395 | w = ulong 0 |
| 396 | if lt v 0.0 |
| 397 | put lex 0 45 |
| 398 | w = 1 |
| 399 | end |
| 400 | w = ix_lexu lex w mm |
| 401 | if ne sc 0 |
| 402 | put lex w 101 |
| 403 | w = add w 1 |
| 404 | if gt sc 0 |
| 405 | put lex w 45 |
| 406 | w = add w 1 |
| 407 | w = ix_lexu lex w ulong sc |
| 408 | else |
| 409 | w = ix_lexu lex w ulong neg sc |
| 410 | end |
| 411 | end |
| 412 | ret w |
| 413 | end |
| 414 | |
| 415 | fn ix_wf64 ob edit uchar * v f64 to void |
| 416 | lex = new uchar 64 0 |
| 417 | n = ix_fmt lex v |
| 418 | js_wnumb ob lex 0 n |
| 419 | end |
| 420 | |
| 421 | note f64 -> bf16 bits, one round-to-nearest-even of the f64 value (no double rounding through f32) |
| 422 | fn ix_bf16 v f64 to ulong |
| 423 | f = f32 v |
| 424 | b = ulong bitcast uint f |
| 425 | hi = shr b 16 |
| 426 | lo = and b 65535 |
| 427 | if and eq lo 32768 ne f64 f v |
| 428 | if gt fabs f64 f fabs v |
| 429 | ret hi |
| 430 | end |
| 431 | ret and add hi 1 65535 |
| 432 | end |
| 433 | ret and shr add b add 32767 and hi 1 16 65535 |
| 434 | end |
| 435 | |
| 436 | note ======== name buffer ======== |
| 437 | |
| 438 | fn ixn_reset to void |
| 439 | put ixs 5 0 |
| 440 | end |
| 441 | |
| 442 | fn ixn_c c ulong to void |
| 443 | n = get ixs 5 |
| 444 | if ge n 1024 |
| 445 | exit 70 |
| 446 | end |
| 447 | put ixnm n uchar and c 255 |
| 448 | put ixs 5 add n 1 |
| 449 | end |
| 450 | |
| 451 | fn ixn_t t view uchar * to void |
| 452 | for i ulong len t |
| 453 | ixn_c ulong get t i |
| 454 | end |
| 455 | end |
| 456 | |
| 457 | fn ixn_dec v ulong to void |
| 458 | tmp = new uchar 24 0 |
| 459 | k = ulong 0 |
| 460 | x = v |
| 461 | while true bound 21 |
| 462 | put tmp k uchar add rem x 10 48 |
| 463 | k = add k 1 |
| 464 | x = div x 10 |
| 465 | if eq x 0 |
| 466 | break |
| 467 | end |
| 468 | end |
| 469 | while gt k 0 bound 21 |
| 470 | k = sub k 1 |
| 471 | ixn_c ulong get tmp k |
| 472 | end |
| 473 | end |
| 474 | |
| 475 | fn ixn_at off ulong t view uchar * to bool |
| 476 | if ne get ixs 5 add off len t |
| 477 | ret false |
| 478 | end |
| 479 | for i ulong len t |
| 480 | if ne get ixnm add off i get t i |
| 481 | ret false |
| 482 | end |
| 483 | end |
| 484 | ret true |
| 485 | end |
| 486 | |
| 487 | fn ixn_eq t view uchar * to bool |
| 488 | ret ixn_at 0 t |
| 489 | end |
| 490 | |
| 491 | fn ixn_pre t view uchar * to bool |
| 492 | if gt len t get ixs 5 |
| 493 | ret false |
| 494 | end |
| 495 | for i ulong len t |
| 496 | if ne get ixnm i get t i |
| 497 | ret false |
| 498 | end |
| 499 | end |
| 500 | ret true |
| 501 | end |
| 502 | |
| 503 | fn ixn_suf t view uchar * to bool |
| 504 | n = get ixs 5 |
| 505 | if gt len t n |
| 506 | ret false |
| 507 | end |
| 508 | ret ixn_at sub n len t t |
| 509 | end |
| 510 | |
| 511 | fn ixn_arch to void |
| 512 | a = get ixm 0 |
| 513 | if eq a 1 |
| 514 | ixn_t ixv_llama |
| 515 | ret |
| 516 | end |
| 517 | if eq a 3 |
| 518 | ixn_t ixv_qwen3 |
| 519 | ret |
| 520 | end |
| 521 | if eq a 5 |
| 522 | ixn_t ixv_gemma |
| 523 | ret |
| 524 | end |
| 525 | ixn_t ixv_helix |
| 526 | end |
| 527 | |
| 528 | note ======== buffered writer (ixob -> ixs 8 fd) and paths ======== |
| 529 | |
| 530 | fn ix_path_arg ai ulong to void |
| 531 | n = uargp ai |
| 532 | for i ulong n |
| 533 | put ixpath i get uarg i |
| 534 | end |
| 535 | put ixs 9 n |
| 536 | end |
| 537 | |
| 538 | fn ix_path_t t view uchar * to void |
| 539 | n = get ixs 9 |
| 540 | if gt add n len t 4300 |
| 541 | exit 2 |
| 542 | end |
| 543 | for i ulong len t |
| 544 | put ixpath add n i get t i |
| 545 | end |
| 546 | put ixs 9 add n len t |
| 547 | end |
| 548 | |
| 549 | fn ixw_open to void |
| 550 | fd = int fopen ixpath 0 get ixs 9 577 420 |
| 551 | if lt fd 0 |
| 552 | exit 70 |
| 553 | end |
| 554 | put ixs 8 ulong fd |
| 555 | put ixs 6 0 |
| 556 | put ixs 7 0 |
| 557 | end |
| 558 | |
| 559 | fn ixw_flush to void |
| 560 | n = get ixs 6 |
| 561 | fd = int get ixs 8 |
| 562 | pos = get ixs 7 |
| 563 | p = ulong 0 |
| 564 | while lt p n bound 1000000 |
| 565 | w = pwrite fd ixob p sub n p long add pos p |
| 566 | if le w 0 |
| 567 | exit 70 |
| 568 | end |
| 569 | p = add p ulong w |
| 570 | end |
| 571 | put ixs 7 add pos n |
| 572 | put ixs 6 0 |
| 573 | end |
| 574 | |
| 575 | fn ixw_b c ulong to void |
| 576 | n = get ixs 6 |
| 577 | if ge n IXOB |
| 578 | ixw_flush |
| 579 | n = 0 |
| 580 | end |
| 581 | put ixob n uchar and c 255 |
| 582 | put ixs 6 add n 1 |
| 583 | end |
| 584 | |
| 585 | fn ixw_u16 v ulong to void |
| 586 | ixw_b and v 255 |
| 587 | ixw_b and shr v 8 255 |
| 588 | end |
| 589 | |
| 590 | fn ixw_u32 v ulong to void |
| 591 | for k ulong 4 |
| 592 | ixw_b and shr v mul k 8 255 |
| 593 | end |
| 594 | end |
| 595 | |
| 596 | fn ixw_u64 v ulong to void |
| 597 | for k ulong 8 |
| 598 | ixw_b and shr v mul k 8 255 |
| 599 | end |
| 600 | end |
| 601 | |
| 602 | fn ixw_pos to ulong |
| 603 | ret add get ixs 7 get ixs 6 |
| 604 | end |
| 605 | |
| 606 | fn ixw_nm to void |
| 607 | n = get ixs 5 |
| 608 | ixw_u64 n |
| 609 | for i ulong n |
| 610 | ixw_b ulong get ixnm i |
| 611 | end |
| 612 | end |
| 613 | |
| 614 | fn ixw_close to ulong |
| 615 | ixw_flush |
| 616 | fd = int get ixs 8 |
| 617 | if ne fsync fd 0 |
| 618 | exit 70 |
| 619 | end |
| 620 | if ne fclose fd 0 |
| 621 | exit 70 |
| 622 | end |
| 623 | ret get ixs 7 |
| 624 | end |
| 625 | |
| 626 | note ======== OLLMCK04 load without activation buffers ======== |
| 627 | |
| 628 | fn ix_geom to bool |
| 629 | if not ugeom_check |
| 630 | ret false |
| 631 | end |
| 632 | ret ugeom_params |
| 633 | end |
| 634 | |
| 635 | fn ix_alloc3 to void |
| 636 | p = get ug 10 |
| 637 | r = enlarge up p |
| 638 | if ne r 0 |
| 639 | exit 70 |
| 640 | end |
| 641 | r = enlarge um p |
| 642 | if ne r 0 |
| 643 | exit 70 |
| 644 | end |
| 645 | r = enlarge uv p |
| 646 | if ne r 0 |
| 647 | exit 70 |
| 648 | end |
| 649 | end |
| 650 | |
| 651 | fn ix_zero_mv to void |
| 652 | p = get ug 10 |
| 653 | i = ulong 0 |
| 654 | while lt i p bound IXBIG |
| 655 | put um i 0.0 |
| 656 | put uv i 0.0 |
| 657 | i = add i 1 |
| 658 | end |
| 659 | end |
| 660 | |
| 661 | fn ix_ck_hdr ai ulong to ulong |
| 662 | sz = uofsz ai |
| 663 | if lt sz UCKHDR |
| 664 | exit 10 |
| 665 | end |
| 666 | if ne uoprd ai 0 0 UCKHDR UCKHDR |
| 667 | exit 10 |
| 668 | end |
| 669 | if ne uopw_get8 0 UMAGIC_CK4 |
| 670 | exit 11 |
| 671 | end |
| 672 | for i ulong 8 |
| 673 | put ug i uopw_get8 add 8 mul i 8 |
| 674 | end |
| 675 | put ug 20 uopw_get8 72 |
| 676 | put ug 21 uopw_get8 80 |
| 677 | put ug 22 uopw_get8 88 |
| 678 | put ug 23 uopw_get8 96 |
| 679 | for j ulong 8 |
| 680 | put ug add 12 j uopw_get8 add 112 mul j 8 |
| 681 | end |
| 682 | pf = uopw_get8 104 |
| 683 | fnv = uopw_get8 200 |
| 684 | if not ix_geom |
| 685 | exit 12 |
| 686 | end |
| 687 | p = get ug 10 |
| 688 | if ne p pf |
| 689 | exit 13 |
| 690 | end |
| 691 | want = add UCKHDR mul 24 p |
| 692 | if lt sz want |
| 693 | exit 10 |
| 694 | end |
| 695 | if gt sz want |
| 696 | exit 15 |
| 697 | end |
| 698 | ret fnv |
| 699 | end |
| 700 | |
| 701 | fn ix_ck_load ai ulong to void |
| 702 | fnv = ix_ck_hdr ai |
| 703 | ix_alloc3 |
| 704 | put uck_st 0 14695981039346656037 |
| 705 | put uck_st 1 UCKHDR |
| 706 | for k ulong 3 |
| 707 | uck_load_pool ai k |
| 708 | end |
| 709 | if ne get uck_st 0 fnv |
| 710 | exit 14 |
| 711 | end |
| 712 | end |
| 713 | |
| 714 | fn ix_finite to void |
| 715 | p = get ug 10 |
| 716 | i = ulong 0 |
| 717 | while lt i p bound IXBIG |
| 718 | if ix_bad get up i |
| 719 | exit 86 |
| 720 | end |
| 721 | i = add i 1 |
| 722 | end |
| 723 | end |
| 724 | |
| 725 | note ======== config.json reader ======== |
| 726 | |
| 727 | fn ix_slurp ai ulong src edit uchar * code ulong to ulong |
| 728 | pl = uargp ai |
| 729 | fd = int fopen uarg 0 pl 0 0 |
| 730 | if lt fd 0 |
| 731 | exit 70 |
| 732 | end |
| 733 | sz = fseek fd 0 2 |
| 734 | if lt sz 0 |
| 735 | exit 70 |
| 736 | end |
| 737 | n = ulong sz |
| 738 | if or eq n 0 gt n len src |
| 739 | c = fclose fd |
| 740 | exit int code |
| 741 | end |
| 742 | got = ulong 0 |
| 743 | while lt got n bound 1000000 |
| 744 | r = pread fd src got sub n got long got |
| 745 | if le r 0 |
| 746 | exit 70 |
| 747 | end |
| 748 | got = add got ulong r |
| 749 | end |
| 750 | if ne fclose fd 0 |
| 751 | exit 70 |
| 752 | end |
| 753 | ret n |
| 754 | end |
| 755 | |
| 756 | fn ixj_u src view uchar * tape view uint * v ulong to ulong |
| 757 | if ne js_type tape v jsnum |
| 758 | exit 81 |
| 759 | end |
| 760 | o = js_off tape v |
| 761 | if not js_isu src o |
| 762 | exit 81 |
| 763 | end |
| 764 | ret js_tou src o |
| 765 | end |
| 766 | |
| 767 | fn ix_stu src view uchar * tape view uint * v ulong to ulong |
| 768 | if ne js_type tape v jsnum |
| 769 | exit 83 |
| 770 | end |
| 771 | o = js_off tape v |
| 772 | if not js_isu src o |
| 773 | exit 83 |
| 774 | end |
| 775 | ret js_tou src o |
| 776 | end |
| 777 | |
| 778 | fn ixj_f src view uchar * tape view uint * v ulong to f64 |
| 779 | if ne js_type tape v jsnum |
| 780 | exit 81 |
| 781 | end |
| 782 | ret ix_numf src js_off tape v js_span tape v |
| 783 | end |
| 784 | |
| 785 | fn ixj_b src view uchar * tape view uint * v ulong to ulong |
| 786 | t = js_type tape v |
| 787 | if eq t jstrue |
| 788 | ret 2 |
| 789 | end |
| 790 | if eq t jsfalse |
| 791 | ret 1 |
| 792 | end |
| 793 | exit 81 |
| 794 | end |
| 795 | |
| 796 | fn ix_cfg_mt src view uchar * tape view uint * v ulong to ulong |
| 797 | if ne js_type tape v jsstr |
| 798 | exit 81 |
| 799 | end |
| 800 | o = js_off tape v |
| 801 | if js_streq src o ixv_llama |
| 802 | ret 1 |
| 803 | end |
| 804 | if js_streq src o ixv_qwen2 |
| 805 | ret 2 |
| 806 | end |
| 807 | if js_streq src o ixv_qwen3 |
| 808 | ret 3 |
| 809 | end |
| 810 | if js_streq src o ixv_mistral |
| 811 | ret 4 |
| 812 | end |
| 813 | if js_streq src o ixv_gemma |
| 814 | ret 5 |
| 815 | end |
| 816 | if js_streq src o ixv_helix |
| 817 | ret 6 |
| 818 | end |
| 819 | ret 99 |
| 820 | end |
| 821 | |
| 822 | fn ix_cfg_act src view uchar * tape view uint * v ulong to ulong |
| 823 | t = js_type tape v |
| 824 | if eq t jsnull |
| 825 | ret 0 |
| 826 | end |
| 827 | if ne t jsstr |
| 828 | exit 81 |
| 829 | end |
| 830 | o = js_off tape v |
| 831 | if js_streq src o ixv_silu |
| 832 | ret 1 |
| 833 | end |
| 834 | if or js_streq src o ixv_gtanh js_streq src o ixv_gnew |
| 835 | ret 2 |
| 836 | end |
| 837 | if js_streq src o ixv_gelu |
| 838 | ret 4 |
| 839 | end |
| 840 | if js_streq src o ixv_relu |
| 841 | ret 5 |
| 842 | end |
| 843 | ret 3 |
| 844 | end |
| 845 | |
| 846 | fn ix_cfg_m1 src view uchar * tape view uint * ko ulong v ulong to bool |
| 847 | if js_streq src ko ixk_mt |
| 848 | put ixc 0 ix_cfg_mt src tape v |
| 849 | ret true |
| 850 | end |
| 851 | if js_streq src ko ixk_vs |
| 852 | put ixc 1 ixj_u src tape v |
| 853 | ret true |
| 854 | end |
| 855 | if js_streq src ko ixk_hs |
| 856 | put ixc 2 ixj_u src tape v |
| 857 | ret true |
| 858 | end |
| 859 | if js_streq src ko ixk_nh |
| 860 | put ixc 3 ixj_u src tape v |
| 861 | ret true |
| 862 | end |
| 863 | if js_streq src ko ixk_kv |
| 864 | put ixc 4 ixj_u src tape v |
| 865 | ret true |
| 866 | end |
| 867 | if js_streq src ko ixk_is |
| 868 | put ixc 5 ixj_u src tape v |
| 869 | ret true |
| 870 | end |
| 871 | if js_streq src ko ixk_nl |
| 872 | put ixc 6 ixj_u src tape v |
| 873 | ret true |
| 874 | end |
| 875 | if js_streq src ko ixk_mp |
| 876 | put ixc 7 ixj_u src tape v |
| 877 | ret true |
| 878 | end |
| 879 | if js_streq src ko ixk_hd |
| 880 | put ixc 8 ixj_u src tape v |
| 881 | ret true |
| 882 | end |
| 883 | ret false |
| 884 | end |
| 885 | |
| 886 | fn ix_cfg_m2 src view uchar * tape view uint * ko ulong v ulong to bool |
| 887 | if js_streq src ko ixk_eps |
| 888 | put ixc 9 bitcast ulong ixj_f src tape v |
| 889 | put ixc 10 1 |
| 890 | ret true |
| 891 | end |
| 892 | if js_streq src ko ixk_th |
| 893 | put ixc 11 bitcast ulong ixj_f src tape v |
| 894 | put ixc 12 1 |
| 895 | ret true |
| 896 | end |
| 897 | if js_streq src ko ixk_tie |
| 898 | put ixc 13 ixj_b src tape v |
| 899 | ret true |
| 900 | end |
| 901 | if js_streq src ko ixk_rs |
| 902 | if ne js_type tape v jsnull |
| 903 | put ixc 14 1 |
| 904 | end |
| 905 | ret true |
| 906 | end |
| 907 | if js_streq src ko ixk_sw |
| 908 | if ne js_type tape v jsnull |
| 909 | put ixc 15 ixj_u src tape v |
| 910 | end |
| 911 | ret true |
| 912 | end |
| 913 | if js_streq src ko ixk_usw |
| 914 | put ixc 16 sub ixj_b src tape v 1 |
| 915 | ret true |
| 916 | end |
| 917 | if js_streq src ko ixk_act |
| 918 | put ixc 17 ix_cfg_act src tape v |
| 919 | ret true |
| 920 | end |
| 921 | if js_streq src ko ixk_acn |
| 922 | put ixc 18 ix_cfg_act src tape v |
| 923 | ret true |
| 924 | end |
| 925 | ret false |
| 926 | end |
| 927 | |
| 928 | fn ix_cfg_m3 src view uchar * tape view uint * ko ulong v ulong to void |
| 929 | if js_streq src ko ixk_hf |
| 930 | put ixc 19 ixj_u src tape v |
| 931 | put ixc 20 1 |
| 932 | ret |
| 933 | end |
| 934 | if js_streq src ko ixk_lp |
| 935 | put ixc 21 ixj_u src tape v |
| 936 | ret |
| 937 | end |
| 938 | if js_streq src ko ixk_lc |
| 939 | put ixc 22 ixj_u src tape v |
| 940 | ret |
| 941 | end |
| 942 | if js_streq src ko ixk_np |
| 943 | put ixc 23 ixj_u src tape v |
| 944 | end |
| 945 | end |
| 946 | |
| 947 | fn ix_cfg_member src view uchar * tape view uint * k ulong to void |
| 948 | ko = js_off tape k |
| 949 | v = add k 1 |
| 950 | if ix_cfg_m1 src tape ko v |
| 951 | ret |
| 952 | end |
| 953 | if ix_cfg_m2 src tape ko v |
| 954 | ret |
| 955 | end |
| 956 | ix_cfg_m3 src tape ko v |
| 957 | end |
| 958 | |
| 959 | fn ix_cfg ai ulong to void |
| 960 | src = new uchar 262144 0 |
| 961 | tape = new uint 65536 0 |
| 962 | n = ix_slurp ai src 80 |
| 963 | if lt js_init tape 262144 64 0 |
| 964 | exit 80 |
| 965 | end |
| 966 | if le js_parse src tape n 0 |
| 967 | exit 80 |
| 968 | end |
| 969 | if ne js_type tape 0 jsobj |
| 970 | exit 80 |
| 971 | end |
| 972 | k = js_first tape 0 |
| 973 | while ne k jsnone bound 1000000 |
| 974 | ix_cfg_member src tape k |
| 975 | k = js_mnext tape k |
| 976 | end |
| 977 | end |
| 978 | |
| 979 | fn ix_cfg_flags mt ulong to ulong |
| 980 | if or eq mt 1 or eq mt 2 eq mt 4 |
| 981 | if gt get ixc 17 1 |
| 982 | exit 82 |
| 983 | end |
| 984 | ret 19 |
| 985 | end |
| 986 | if eq mt 3 |
| 987 | if gt get ixc 17 1 |
| 988 | exit 82 |
| 989 | end |
| 990 | ret 27 |
| 991 | end |
| 992 | if eq mt 5 |
| 993 | a = get ixc 18 |
| 994 | if and ne a 0 ne a 2 |
| 995 | exit 82 |
| 996 | end |
| 997 | if eq get ixc 13 1 |
| 998 | exit 82 |
| 999 | end |
| 1000 | ret 85 |
| 1001 | end |
| 1002 | if eq get ixc 20 0 |
| 1003 | exit 81 |
| 1004 | end |
| 1005 | ret get ixc 19 |
| 1006 | end |
| 1007 | |
| 1008 | fn ix_cfg_check to void |
| 1009 | mt = get ixc 0 |
| 1010 | if or eq mt 0 eq mt 99 |
| 1011 | exit 81 |
| 1012 | end |
| 1013 | for i ulong 6 |
| 1014 | if and ne i 3 eq get ixc add 1 i 0 |
| 1015 | exit 81 |
| 1016 | end |
| 1017 | end |
| 1018 | if lt get ixc 1 2 |
| 1019 | exit 81 |
| 1020 | end |
| 1021 | if gt get ixc 6 100000 |
| 1022 | exit 81 |
| 1023 | end |
| 1024 | h = get ixc 3 |
| 1025 | hkv = get ixc 4 |
| 1026 | if eq hkv 0 |
| 1027 | hkv = h |
| 1028 | end |
| 1029 | hd = get ixc 8 |
| 1030 | if and ne hd 0 ne mul hd h get ixc 2 |
| 1031 | exit 82 |
| 1032 | end |
| 1033 | if ne get ixc 14 0 |
| 1034 | exit 82 |
| 1035 | end |
| 1036 | fl = ix_cfg_flags mt |
| 1037 | if and ne mt 5 ne mt 6 |
| 1038 | if ne get ixc 13 2 |
| 1039 | fl = or fl 4 |
| 1040 | end |
| 1041 | end |
| 1042 | if eq mt 6 |
| 1043 | tie = get ixc 13 |
| 1044 | if ne tie 0 |
| 1045 | if ne eq tie 2 eq and fl 4 0 |
| 1046 | exit 81 |
| 1047 | end |
| 1048 | end |
| 1049 | end |
| 1050 | put ug 0 get ixc 1 |
| 1051 | put ug 2 get ixc 2 |
| 1052 | put ug 3 h |
| 1053 | put ug 4 hkv |
| 1054 | put ug 5 get ixc 5 |
| 1055 | put ug 6 get ixc 6 |
| 1056 | put ug 7 get ixs 15 |
| 1057 | put ug 12 fl |
| 1058 | ix_cfg_scal fl |
| 1059 | end |
| 1060 | |
| 1061 | fn ix_cfg_scal fl ulong to void |
| 1062 | eps = 1.0e-6f64 |
| 1063 | if ne get ixc 10 0 |
| 1064 | eps = bitcast f64 get ixc 9 |
| 1065 | end |
| 1066 | if or ix_bad eps le eps 0.0 |
| 1067 | exit 81 |
| 1068 | end |
| 1069 | put ug 14 bitcast ulong eps |
| 1070 | th = 10000.0f64 |
| 1071 | if ne get ixc 12 0 |
| 1072 | th = bitcast f64 get ixc 11 |
| 1073 | end |
| 1074 | mi = mul th 1000.0 |
| 1075 | if or ix_bad mi or le mi 0.0 ge mi 1.0e18 |
| 1076 | exit 81 |
| 1077 | end |
| 1078 | if ne mi f64 ulong mi |
| 1079 | exit 81 |
| 1080 | end |
| 1081 | put ug 13 ulong mi |
| 1082 | wd = 0.0f64 |
| 1083 | if ne and fl 16 0 |
| 1084 | wd = 0.1f64 |
| 1085 | end |
| 1086 | put ug 15 bitcast ulong wd |
| 1087 | put ug 16 100 |
| 1088 | put ug 17 0 |
| 1089 | put ug 18 0 |
| 1090 | put ug 19 0 |
| 1091 | if eq get ixc 0 6 |
| 1092 | put ug 17 get ixc 21 |
| 1093 | put ug 18 get ixc 22 |
| 1094 | put ug 19 get ixc 23 |
| 1095 | end |
| 1096 | put ug 20 0 |
| 1097 | put ug 21 0 |
| 1098 | put ug 22 get ixs 16 |
| 1099 | put ug 23 bitcast ulong div f64 get ixs 17 1000000.0 |
| 1100 | end |
| 1101 | |
| 1102 | note ======== safetensors header reader ======== |
| 1103 | |
| 1104 | fn ix_st_open ai ulong to ulong |
| 1105 | pl = uargp ai |
| 1106 | fd = int fopen uarg 0 pl 0 0 |
| 1107 | if lt fd 0 |
| 1108 | exit 70 |
| 1109 | end |
| 1110 | put ixs 1 ulong fd |
| 1111 | sz = fseek fd 0 2 |
| 1112 | if lt sz 8 |
| 1113 | exit 87 |
| 1114 | end |
| 1115 | hb = new uchar 8 0 |
| 1116 | if ne pread fd hb 0 8 0 8 |
| 1117 | exit 87 |
| 1118 | end |
| 1119 | n = ulong 0 |
| 1120 | for k ulong 8 |
| 1121 | n = or n shl ulong get hb k mul k 8 |
| 1122 | end |
| 1123 | if or lt n 2 gt n 983040 |
| 1124 | exit 83 |
| 1125 | end |
| 1126 | if gt add 8 n ulong sz |
| 1127 | exit 87 |
| 1128 | end |
| 1129 | put ixs 2 add 8 n |
| 1130 | put ixs 3 sub ulong sz add 8 n |
| 1131 | ret n |
| 1132 | end |
| 1133 | |
| 1134 | fn ix_st_read src edit uchar * n ulong to void |
| 1135 | fd = int get ixs 1 |
| 1136 | got = ulong 0 |
| 1137 | while lt got n bound 1000000 |
| 1138 | r = pread fd src got sub n got long add 8 got |
| 1139 | if le r 0 |
| 1140 | exit 87 |
| 1141 | end |
| 1142 | got = add got ulong r |
| 1143 | end |
| 1144 | end |
| 1145 | |
| 1146 | fn ix_key src view uchar * tape view uint * k ulong to void |
| 1147 | nb = new uchar 1100 0 |
| 1148 | r = js_sget src js_off tape k nb |
| 1149 | if or lt r 0 gt r 1024 |
| 1150 | exit 83 |
| 1151 | end |
| 1152 | n = ulong r |
| 1153 | for i ulong n |
| 1154 | put ixnm i get nb i |
| 1155 | end |
| 1156 | put ixs 5 n |
| 1157 | end |
| 1158 | |
| 1159 | fn ix_dtype src view uchar * o ulong to ulong |
| 1160 | if js_streq src o ixs_F32 |
| 1161 | ret 1 |
| 1162 | end |
| 1163 | if js_streq src o ixs_BF16 |
| 1164 | ret 2 |
| 1165 | end |
| 1166 | if js_streq src o ixs_F16 |
| 1167 | ret 3 |
| 1168 | end |
| 1169 | if js_streq src o ixs_F64 |
| 1170 | ret 4 |
| 1171 | end |
| 1172 | exit 84 |
| 1173 | end |
| 1174 | |
| 1175 | fn ix_dsz dt ulong to ulong |
| 1176 | if eq dt 1 |
| 1177 | ret 4 |
| 1178 | end |
| 1179 | if eq dt 4 |
| 1180 | ret 8 |
| 1181 | end |
| 1182 | ret 2 |
| 1183 | end |
| 1184 | |
| 1185 | fn ix_st_shape src view uchar * tape view uint * v ulong to void |
| 1186 | if ne js_type tape v jsarr |
| 1187 | exit 83 |
| 1188 | end |
| 1189 | nd = js_nkids tape v |
| 1190 | if gt nd 8 |
| 1191 | exit 83 |
| 1192 | end |
| 1193 | put ixent 1 nd |
| 1194 | put ixent 2 0 |
| 1195 | put ixent 3 0 |
| 1196 | nm = ulong 1 |
| 1197 | i = ulong 0 |
| 1198 | e = js_first tape v |
| 1199 | while ne e jsnone bound 9 |
| 1200 | d = ix_stu src tape e |
| 1201 | if gt d 1099511627776 |
| 1202 | exit 83 |
| 1203 | end |
| 1204 | if and ne d 0 gt nm div 4611686018427387904 d |
| 1205 | exit 83 |
| 1206 | end |
| 1207 | nm = mul nm d |
| 1208 | if lt i 2 |
| 1209 | put ixent add 2 i d |
| 1210 | end |
| 1211 | i = add i 1 |
| 1212 | e = js_enext tape e |
| 1213 | end |
| 1214 | put ixent 6 nm |
| 1215 | end |
| 1216 | |
| 1217 | fn ix_st_doff src view uchar * tape view uint * v ulong to void |
| 1218 | if ne js_type tape v jsarr |
| 1219 | exit 83 |
| 1220 | end |
| 1221 | if ne js_nkids tape v 2 |
| 1222 | exit 83 |
| 1223 | end |
| 1224 | e = js_first tape v |
| 1225 | b = ix_stu src tape e |
| 1226 | f = ix_stu src tape js_enext tape e |
| 1227 | if gt b f |
| 1228 | exit 83 |
| 1229 | end |
| 1230 | put ixent 4 b |
| 1231 | put ixent 5 f |
| 1232 | end |
| 1233 | |
| 1234 | fn ix_seen bit ulong to void |
| 1235 | s = get ixent 7 |
| 1236 | if ne and s bit 0 |
| 1237 | exit 83 |
| 1238 | end |
| 1239 | put ixent 7 or s bit |
| 1240 | end |
| 1241 | |
| 1242 | fn ix_st_field src view uchar * tape view uint * m ulong to void |
| 1243 | ko = js_off tape m |
| 1244 | v = add m 1 |
| 1245 | if js_streq src ko ixs_dtype |
| 1246 | ix_seen 1 |
| 1247 | if ne js_type tape v jsstr |
| 1248 | exit 83 |
| 1249 | end |
| 1250 | put ixent 0 ix_dtype src js_off tape v |
| 1251 | ret |
| 1252 | end |
| 1253 | if js_streq src ko ixs_shape |
| 1254 | ix_seen 2 |
| 1255 | ix_st_shape src tape v |
| 1256 | ret |
| 1257 | end |
| 1258 | if js_streq src ko ixs_doff |
| 1259 | ix_seen 4 |
| 1260 | ix_st_doff src tape v |
| 1261 | ret |
| 1262 | end |
| 1263 | exit 83 |
| 1264 | end |
| 1265 | |
| 1266 | fn ix_st_entry src view uchar * tape view uint * v ulong to void |
| 1267 | for i ulong 8 |
| 1268 | put ixent i 0 |
| 1269 | end |
| 1270 | if ne js_nkids tape v 3 |
| 1271 | exit 83 |
| 1272 | end |
| 1273 | m = js_first tape v |
| 1274 | while ne m jsnone bound 4 |
| 1275 | ix_st_field src tape m |
| 1276 | m = js_mnext tape m |
| 1277 | end |
| 1278 | if ne get ixent 7 7 |
| 1279 | exit 83 |
| 1280 | end |
| 1281 | if gt get ixent 6 div 4611686018427387904 ix_dsz get ixent 0 |
| 1282 | exit 83 |
| 1283 | end |
| 1284 | nb = mul get ixent 6 ix_dsz get ixent 0 |
| 1285 | if ne sub get ixent 5 get ixent 4 nb |
| 1286 | exit 83 |
| 1287 | end |
| 1288 | end |
| 1289 | |
| 1290 | fn ix_ext_add to void |
| 1291 | c = get ixs 0 |
| 1292 | if ge c get ixs 13 |
| 1293 | exit 83 |
| 1294 | end |
| 1295 | put ixe mul c 2 get ixent 4 |
| 1296 | put ixe add mul c 2 1 get ixent 5 |
| 1297 | put ixs 0 add c 1 |
| 1298 | end |
| 1299 | |
| 1300 | fn ix_role o ulong to ulong |
| 1301 | if ixn_at o ixr_0 |
| 1302 | ret 0 |
| 1303 | end |
| 1304 | if ixn_at o ixr_1 |
| 1305 | ret 1 |
| 1306 | end |
| 1307 | if ixn_at o ixr_2 |
| 1308 | ret 2 |
| 1309 | end |
| 1310 | if ixn_at o ixr_3 |
| 1311 | ret 3 |
| 1312 | end |
| 1313 | if ixn_at o ixr_4 |
| 1314 | ret 4 |
| 1315 | end |
| 1316 | if ixn_at o ixr_5 |
| 1317 | ret 5 |
| 1318 | end |
| 1319 | if ixn_at o ixr_6 |
| 1320 | ret 6 |
| 1321 | end |
| 1322 | if ixn_at o ixr_7 |
| 1323 | ret 7 |
| 1324 | end |
| 1325 | if ixn_at o ixr_8 |
| 1326 | ret 8 |
| 1327 | end |
| 1328 | if ixn_at o ixr_9 |
| 1329 | ret 9 |
| 1330 | end |
| 1331 | if ixn_at o ixr_10 |
| 1332 | ret 10 |
| 1333 | end |
| 1334 | ret ix_role_b o |
| 1335 | end |
| 1336 | |
| 1337 | fn ix_role_b o ulong to ulong |
| 1338 | if ixn_at o ixr_11 |
| 1339 | ret 11 |
| 1340 | end |
| 1341 | if ixn_at o ixr_12 |
| 1342 | ret 12 |
| 1343 | end |
| 1344 | if ixn_at o ixr_13 |
| 1345 | ret 13 |
| 1346 | end |
| 1347 | if ixn_at o ixr_14 |
| 1348 | ret 14 |
| 1349 | end |
| 1350 | if ixn_at o ixr_15 |
| 1351 | ret 15 |
| 1352 | end |
| 1353 | if ixn_at o ixr_16 |
| 1354 | ret 16 |
| 1355 | end |
| 1356 | if ixn_at o ixr_17 |
| 1357 | ret 17 |
| 1358 | end |
| 1359 | ret 99 |
| 1360 | end |
| 1361 | |
| 1362 | note slot of the name in ixnm: 0 embed 1 positions 2 final norm 3 lm_head, 8 + 24 l + role; 9999 ignored; |
| 1363 | note 9998 unknown |
| 1364 | fn ix_slot to ulong |
| 1365 | if ixn_eq ixn_emb |
| 1366 | ret 0 |
| 1367 | end |
| 1368 | if ixn_eq ixn_pos |
| 1369 | ret 1 |
| 1370 | end |
| 1371 | if ixn_eq ixn_norm |
| 1372 | ret 2 |
| 1373 | end |
| 1374 | if ixn_eq ixn_lmh |
| 1375 | ret 3 |
| 1376 | end |
| 1377 | if ixn_suf ixn_inv |
| 1378 | ret 9999 |
| 1379 | end |
| 1380 | if not ixn_pre ixn_lay |
| 1381 | ret 9998 |
| 1382 | end |
| 1383 | n = get ixs 5 |
| 1384 | p = len ixn_lay |
| 1385 | l = ulong 0 |
| 1386 | nd = ulong 0 |
| 1387 | while lt p n bound 1100 |
| 1388 | c = ulong get ixnm p |
| 1389 | if or lt c 48 gt c 57 |
| 1390 | break |
| 1391 | end |
| 1392 | if lt nd 7 |
| 1393 | l = add mul l 10 sub c 48 |
| 1394 | end |
| 1395 | nd = add nd 1 |
| 1396 | p = add p 1 |
| 1397 | end |
| 1398 | if or eq nd 0 gt nd 6 |
| 1399 | ret 9998 |
| 1400 | end |
| 1401 | if or ge l get ug 6 ge p n |
| 1402 | ret 9998 |
| 1403 | end |
| 1404 | if ne get ixnm p 46 |
| 1405 | ret 9998 |
| 1406 | end |
| 1407 | r = ix_role add p 1 |
| 1408 | if eq r 99 |
| 1409 | ret 9998 |
| 1410 | end |
| 1411 | ret add 8 add mul l 24 r |
| 1412 | end |
| 1413 | |
| 1414 | fn ix_slot_put sl ulong to void |
| 1415 | b = mul sl 8 |
| 1416 | if ne get ixt b 0 |
| 1417 | exit 83 |
| 1418 | end |
| 1419 | put ixt b 1 |
| 1420 | for i ulong 4 |
| 1421 | put ixt add b add 1 i get ixent i |
| 1422 | end |
| 1423 | put ixt add b 5 get ixent 4 |
| 1424 | put ixt add b 6 get ixent 5 |
| 1425 | end |
| 1426 | |
| 1427 | fn ix_st_member src view uchar * tape view uint * k ulong to void |
| 1428 | ix_key src tape k |
| 1429 | v = add k 1 |
| 1430 | if ixn_eq ixs_meta |
| 1431 | if ne js_type tape v jsobj |
| 1432 | exit 83 |
| 1433 | end |
| 1434 | ret |
| 1435 | end |
| 1436 | if ne js_type tape v jsobj |
| 1437 | exit 83 |
| 1438 | end |
| 1439 | ix_st_entry src tape v |
| 1440 | ix_ext_add |
| 1441 | sl = ix_slot |
| 1442 | if eq sl 9999 |
| 1443 | ret |
| 1444 | end |
| 1445 | if ge sl 9998 |
| 1446 | exit 84 |
| 1447 | end |
| 1448 | ix_slot_put sl |
| 1449 | end |
| 1450 | |
| 1451 | fn ix_st ai ulong to void |
| 1452 | src = new uchar 983040 0 |
| 1453 | tape = new uint 524288 0 |
| 1454 | hn = ix_st_open ai |
| 1455 | ix_st_read src hn |
| 1456 | if lt js_init tape 983040 64 0 |
| 1457 | exit 83 |
| 1458 | end |
| 1459 | if le js_parse src tape hn 0 |
| 1460 | exit 83 |
| 1461 | end |
| 1462 | if ne js_type tape 0 jsobj |
| 1463 | exit 83 |
| 1464 | end |
| 1465 | nk = js_nkids tape 0 |
| 1466 | r = enlarge ixe mul add nk 1 2 |
| 1467 | if ne r 0 |
| 1468 | exit 70 |
| 1469 | end |
| 1470 | put ixs 13 nk |
| 1471 | k = js_first tape 0 |
| 1472 | while ne k jsnone bound 1000000 |
| 1473 | ix_st_member src tape k |
| 1474 | k = js_mnext tape k |
| 1475 | end |
| 1476 | end |
| 1477 | |
| 1478 | fn ix_tab_alloc to void |
| 1479 | n = add 8 mul get ug 6 24 |
| 1480 | put ixs 4 n |
| 1481 | r = enlarge ixt mul n 8 |
| 1482 | if ne r 0 |
| 1483 | exit 70 |
| 1484 | end |
| 1485 | for i ulong mul n 8 bound IXBIG |
| 1486 | put ixt i 0 |
| 1487 | end |
| 1488 | end |
| 1489 | |
| 1490 | fn ix_overlap i ulong n ulong to bool |
| 1491 | b = get ixe mul i 2 |
| 1492 | e = get ixe add mul i 2 1 |
| 1493 | if eq b e |
| 1494 | ret false |
| 1495 | end |
| 1496 | j = add i 1 |
| 1497 | while lt j n bound IXBIG |
| 1498 | b2 = get ixe mul j 2 |
| 1499 | e2 = get ixe add mul j 2 1 |
| 1500 | if and ne b2 e2 and lt b e2 lt b2 e |
| 1501 | ret true |
| 1502 | end |
| 1503 | j = add j 1 |
| 1504 | end |
| 1505 | ret false |
| 1506 | end |
| 1507 | |
| 1508 | fn ix_cover to void |
| 1509 | n = get ixs 0 |
| 1510 | ds = get ixs 3 |
| 1511 | sm = ulong 0 |
| 1512 | for i ulong n bound IXBIG |
| 1513 | e = get ixe add mul i 2 1 |
| 1514 | if gt e ds |
| 1515 | exit 87 |
| 1516 | end |
| 1517 | sm = add sm sub e get ixe mul i 2 |
| 1518 | end |
| 1519 | if ne sm ds |
| 1520 | exit 83 |
| 1521 | end |
| 1522 | for i2 ulong n bound IXBIG |
| 1523 | if ix_overlap i2 n |
| 1524 | exit 83 |
| 1525 | end |
| 1526 | end |
| 1527 | end |
| 1528 | |
| 1529 | note ======== import: shape checks and conversion ======== |
| 1530 | |
| 1531 | fn ix_has sl ulong to bool |
| 1532 | ret ne get ixt mul sl 8 0 |
| 1533 | end |
| 1534 | |
| 1535 | fn ix_dim sl ulong k ulong to ulong |
| 1536 | ret get ixt add mul sl 8 k |
| 1537 | end |
| 1538 | |
| 1539 | fn ix_req1 sl ulong n ulong to void |
| 1540 | if not ix_has sl |
| 1541 | exit 84 |
| 1542 | end |
| 1543 | if or ne ix_dim sl 2 1 ne ix_dim sl 3 n |
| 1544 | exit 85 |
| 1545 | end |
| 1546 | end |
| 1547 | |
| 1548 | fn ix_req2 sl ulong r ulong c ulong to void |
| 1549 | if not ix_has sl |
| 1550 | exit 84 |
| 1551 | end |
| 1552 | if ne ix_dim sl 2 2 |
| 1553 | exit 85 |
| 1554 | end |
| 1555 | if or ne ix_dim sl 3 r ne ix_dim sl 4 c |
| 1556 | exit 85 |
| 1557 | end |
| 1558 | end |
| 1559 | |
| 1560 | fn ix_forbid sl ulong to void |
| 1561 | if ix_has sl |
| 1562 | exit 84 |
| 1563 | end |
| 1564 | end |
| 1565 | |
| 1566 | fn ix_bias sl ulong n ulong to void |
| 1567 | if ix_has sl |
| 1568 | if or ne ix_dim sl 2 1 ne ix_dim sl 3 n |
| 1569 | exit 85 |
| 1570 | end |
| 1571 | end |
| 1572 | end |
| 1573 | |
| 1574 | fn ix_set_t to void |
| 1575 | fl = get ug 12 |
| 1576 | t = ulong 256 |
| 1577 | mp = get ixc 7 |
| 1578 | if and ne mp 0 lt mp 256 |
| 1579 | t = mp |
| 1580 | end |
| 1581 | if ne get ixs 11 0 |
| 1582 | t = get ixs 12 |
| 1583 | end |
| 1584 | if eq and fl 1 0 |
| 1585 | if not ix_has 1 |
| 1586 | exit 84 |
| 1587 | end |
| 1588 | r = ix_dim 1 3 |
| 1589 | if and ne get ixs 11 0 ne r t |
| 1590 | exit 85 |
| 1591 | end |
| 1592 | t = r |
| 1593 | end |
| 1594 | if eq t 0 |
| 1595 | exit 88 |
| 1596 | end |
| 1597 | put ug 1 t |
| 1598 | sw = get ixc 15 |
| 1599 | mt = get ixc 0 |
| 1600 | if and ne sw 0 lt sw t |
| 1601 | if or eq mt 4 and eq mt 2 eq get ixc 16 1 |
| 1602 | exit 82 |
| 1603 | end |
| 1604 | end |
| 1605 | end |
| 1606 | |
| 1607 | fn ix_need_l l ulong to void |
| 1608 | d = get ug 2 |
| 1609 | kvd = mul get ug 4 div d get ug 3 |
| 1610 | f = get ug 5 |
| 1611 | fl = get ug 12 |
| 1612 | b = add 8 mul l 24 |
| 1613 | ix_req1 b d |
| 1614 | ix_req2 add b 1 d d |
| 1615 | ix_req2 add b 2 kvd d |
| 1616 | ix_req2 add b 3 kvd d |
| 1617 | ix_req2 add b 4 d d |
| 1618 | if ne and fl 8 0 |
| 1619 | ix_req1 add b 5 div d get ug 3 |
| 1620 | ix_req1 add b 6 div d get ug 3 |
| 1621 | else |
| 1622 | ix_forbid add b 5 |
| 1623 | ix_forbid add b 6 |
| 1624 | end |
| 1625 | ix_req1 add b 7 d |
| 1626 | if ne and fl 66 0 |
| 1627 | ix_req2 add b 8 f d |
| 1628 | else |
| 1629 | ix_forbid add b 8 |
| 1630 | end |
| 1631 | ix_req2 add b 9 f d |
| 1632 | ix_req2 add b 10 d f |
| 1633 | ix_bias add b 11 d |
| 1634 | ix_bias add b 12 kvd |
| 1635 | ix_bias add b 13 kvd |
| 1636 | ix_bias add b 14 d |
| 1637 | ix_bias add b 15 f |
| 1638 | ix_bias add b 16 f |
| 1639 | ix_bias add b 17 d |
| 1640 | end |
| 1641 | |
| 1642 | fn ix_need to void |
| 1643 | v = get ug 0 |
| 1644 | d = get ug 2 |
| 1645 | h = get ug 3 |
| 1646 | hkv = get ug 4 |
| 1647 | if or eq h 0 ne rem d h 0 |
| 1648 | exit 88 |
| 1649 | end |
| 1650 | if or eq hkv 0 or gt hkv h ne rem h hkv 0 |
| 1651 | exit 88 |
| 1652 | end |
| 1653 | fl = get ug 12 |
| 1654 | ix_req2 0 v d |
| 1655 | if eq and fl 1 0 |
| 1656 | ix_req2 1 get ug 1 d |
| 1657 | else |
| 1658 | ix_forbid 1 |
| 1659 | end |
| 1660 | ix_req1 2 d |
| 1661 | if and ne and fl 4 0 ne get ixc 0 5 |
| 1662 | ix_req2 3 v d |
| 1663 | end |
| 1664 | for l ulong get ug 6 bound IXBIG |
| 1665 | ix_need_l l |
| 1666 | end |
| 1667 | end |
| 1668 | |
| 1669 | fn ix_dec j ulong dt ulong to f64 |
| 1670 | if eq dt 1 |
| 1671 | b = mul j 4 |
| 1672 | u = ulong get uopw b |
| 1673 | u = or u shl ulong get uopw add b 1 8 |
| 1674 | u = or u shl ulong get uopw add b 2 16 |
| 1675 | u = or u shl ulong get uopw add b 3 24 |
| 1676 | ret f64 bitcast f32 uint u |
| 1677 | end |
| 1678 | if eq dt 4 |
| 1679 | ret bitcast f64 uopw_get8 mul j 8 |
| 1680 | end |
| 1681 | b2 = mul j 2 |
| 1682 | h = or ulong get uopw b2 shl ulong get uopw add b2 1 8 |
| 1683 | if eq dt 2 |
| 1684 | ret ubf16_to_f64 h |
| 1685 | end |
| 1686 | ret uf16_to_f64 h |
| 1687 | end |
| 1688 | |
| 1689 | fn ix_store k ulong v f64 to void |
| 1690 | md = get ixld 2 |
| 1691 | base = get ixld 1 |
| 1692 | if eq md 0 |
| 1693 | put up add base k v |
| 1694 | ret |
| 1695 | end |
| 1696 | if eq md 1 |
| 1697 | c = get ixld 4 |
| 1698 | r = get ixld 3 |
| 1699 | o = div k c |
| 1700 | i = rem k c |
| 1701 | put up add base add mul i r o v |
| 1702 | ret |
| 1703 | end |
| 1704 | if eq md 2 |
| 1705 | put up add base k add v 1.0 |
| 1706 | ret |
| 1707 | end |
| 1708 | if eq md 3 |
| 1709 | put up add base k mul v get ixf 0 |
| 1710 | ret |
| 1711 | end |
| 1712 | if ne v 0.0 |
| 1713 | exit 82 |
| 1714 | end |
| 1715 | end |
| 1716 | |
| 1717 | fn ix_conv k0 ulong m ulong to void |
| 1718 | dt = get ixld 0 |
| 1719 | for j ulong m bound IXBIG |
| 1720 | v = ix_dec j dt |
| 1721 | if ix_bad v |
| 1722 | exit 86 |
| 1723 | end |
| 1724 | ix_store add k0 j v |
| 1725 | end |
| 1726 | end |
| 1727 | |
| 1728 | fn ix_pread pos ulong n ulong to void |
| 1729 | fd = int get ixs 1 |
| 1730 | got = ulong 0 |
| 1731 | while lt got n bound 1000000 |
| 1732 | r = pread fd uopw got sub n got long add pos got |
| 1733 | if le r 0 |
| 1734 | exit 87 |
| 1735 | end |
| 1736 | got = add got ulong r |
| 1737 | end |
| 1738 | end |
| 1739 | |
| 1740 | fn ix_load sl ulong base ulong md ulong to void |
| 1741 | b = mul sl 8 |
| 1742 | put ixld 0 get ixt add b 1 |
| 1743 | put ixld 1 base |
| 1744 | put ixld 2 md |
| 1745 | put ixld 3 get ixt add b 3 |
| 1746 | put ixld 4 get ixt add b 4 |
| 1747 | put ixld 5 get ixt add b 5 |
| 1748 | put ixld 6 get ixt add b 6 |
| 1749 | ix_load_run |
| 1750 | end |
| 1751 | |
| 1752 | fn ix_load_run to void |
| 1753 | ds = ix_dsz get ixld 0 |
| 1754 | pos = add get ixs 2 get ixld 5 |
| 1755 | n = div sub get ixld 6 get ixld 5 ds |
| 1756 | cn = div IXOB ds |
| 1757 | k = ulong 0 |
| 1758 | while lt k n bound IXBIG |
| 1759 | m = sub n k |
| 1760 | if gt m cn |
| 1761 | m = cn |
| 1762 | end |
| 1763 | ix_pread add pos mul k ds mul m ds |
| 1764 | ix_conv k m |
| 1765 | k = add k m |
| 1766 | end |
| 1767 | end |
| 1768 | |
| 1769 | fn ix_fill_l l ulong gn ulong to void |
| 1770 | fl = get ug 12 |
| 1771 | b = add 8 mul l 24 |
| 1772 | ix_load b up_g1 l gn |
| 1773 | ix_load add b 1 up_wq l 1 |
| 1774 | ix_load add b 2 up_wk l 1 |
| 1775 | ix_load add b 3 up_wv l 1 |
| 1776 | ix_load add b 4 up_wo l 1 |
| 1777 | if ne and fl 8 0 |
| 1778 | ix_load add b 5 up_qn l 0 |
| 1779 | ix_load add b 6 up_kn l 0 |
| 1780 | end |
| 1781 | ix_load add b 7 up_g2 l gn |
| 1782 | if ne and fl 66 0 |
| 1783 | ix_load add b 8 up_w1 l 1 |
| 1784 | ix_load add b 9 up_wup l 1 |
| 1785 | else |
| 1786 | ix_load add b 9 up_w1 l 1 |
| 1787 | end |
| 1788 | ix_load add b 10 up_w2 l 1 |
| 1789 | for r ulong 7 |
| 1790 | if ix_has add b add 11 r |
| 1791 | ix_load add b add 11 r 0 5 |
| 1792 | end |
| 1793 | end |
| 1794 | end |
| 1795 | |
| 1796 | fn ix_fill to void |
| 1797 | fl = get ug 12 |
| 1798 | gem = eq get ixc 0 5 |
| 1799 | gn = ulong 0 |
| 1800 | put ixf 0 fsqrt f64 get ug 2 |
| 1801 | if gem |
| 1802 | gn = 2 |
| 1803 | ix_load 0 0 3 |
| 1804 | ix_load 0 get ug 36 0 |
| 1805 | else |
| 1806 | ix_load 0 0 0 |
| 1807 | if ne and fl 4 0 |
| 1808 | ix_load 3 get ug 36 0 |
| 1809 | end |
| 1810 | end |
| 1811 | if eq and fl 1 0 |
| 1812 | ix_load 1 get ug 32 0 |
| 1813 | end |
| 1814 | ix_load 2 get ug 35 gn |
| 1815 | for l ulong get ug 6 bound IXBIG |
| 1816 | ix_fill_l l gn |
| 1817 | end |
| 1818 | end |
| 1819 | |
| 1820 | fn ix_cmd_import to void |
| 1821 | na = ulong argcnt |
| 1822 | if and ne na 5 ne na 9 |
| 1823 | exit 2 |
| 1824 | end |
| 1825 | put ixs 11 0 |
| 1826 | put ixs 15 1 |
| 1827 | put ixs 16 1000 |
| 1828 | put ixs 17 100 |
| 1829 | if eq na 9 |
| 1830 | put ixs 11 1 |
| 1831 | put ixs 12 uargu 5 |
| 1832 | put ixs 15 uargu 6 |
| 1833 | put ixs 16 uargu 7 |
| 1834 | put ixs 17 uargu 8 |
| 1835 | end |
| 1836 | ix_cfg 2 |
| 1837 | ix_cfg_check |
| 1838 | ix_tab_alloc |
| 1839 | ix_st 3 |
| 1840 | ix_cover |
| 1841 | ix_set_t |
| 1842 | ix_need |
| 1843 | if not ix_geom |
| 1844 | exit 88 |
| 1845 | end |
| 1846 | ix_alloc3 |
| 1847 | ix_zero_mv |
| 1848 | ix_fill |
| 1849 | c = fclose int get ixs 1 |
| 1850 | uck_save 4 |
| 1851 | uputc 73 |
| 1852 | for i ulong 7 |
| 1853 | uputc 32 |
| 1854 | uputu get ug i |
| 1855 | end |
| 1856 | uputc 32 |
| 1857 | uputu get ug 10 |
| 1858 | uputc 32 |
| 1859 | uputu get ug 12 |
| 1860 | uputc 10 |
| 1861 | uflush |
| 1862 | end |
| 1863 | |
| 1864 | note ======== export: architecture, tensor list, values ======== |
| 1865 | |
| 1866 | fn ix_gemma_ok to bool |
| 1867 | n = mul get ug 0 get ug 2 |
| 1868 | lm = get ug 36 |
| 1869 | sq = fsqrt f64 get ug 2 |
| 1870 | i = ulong 0 |
| 1871 | while lt i n bound IXBIG |
| 1872 | a = get up i |
| 1873 | b = get up add lm i |
| 1874 | if ne bitcast ulong a bitcast ulong mul b sq |
| 1875 | ret false |
| 1876 | end |
| 1877 | i = add i 1 |
| 1878 | end |
| 1879 | ret true |
| 1880 | end |
| 1881 | |
| 1882 | fn ix_arch to ulong |
| 1883 | fl = get ug 12 |
| 1884 | if gt get ug 19 1 |
| 1885 | ret 6 |
| 1886 | end |
| 1887 | if eq and fl 1 0 |
| 1888 | ret 6 |
| 1889 | end |
| 1890 | if ne and fl 2 0 |
| 1891 | if ne and fl 8 0 |
| 1892 | ret 3 |
| 1893 | end |
| 1894 | ret 1 |
| 1895 | end |
| 1896 | if and ne and fl 64 0 eq and fl 8 0 |
| 1897 | if ne and fl 4 0 |
| 1898 | if ix_gemma_ok |
| 1899 | ret 5 |
| 1900 | end |
| 1901 | end |
| 1902 | end |
| 1903 | ret 6 |
| 1904 | end |
| 1905 | |
| 1906 | fn ix_la n ulong code ulong l ulong to ulong |
| 1907 | put ixl mul n 2 code |
| 1908 | put ixl add mul n 2 1 l |
| 1909 | ret add n 1 |
| 1910 | end |
| 1911 | |
| 1912 | fn ix_list_l n ulong l ulong to ulong |
| 1913 | fl = get ug 12 |
| 1914 | k = n |
| 1915 | for r ulong 5 |
| 1916 | k = ix_la k add 8 r l |
| 1917 | end |
| 1918 | if ne and fl 8 0 |
| 1919 | k = ix_la k 13 l |
| 1920 | k = ix_la k 14 l |
| 1921 | end |
| 1922 | k = ix_la k 15 l |
| 1923 | if ne and fl 66 0 |
| 1924 | k = ix_la k 16 l |
| 1925 | end |
| 1926 | k = ix_la k 17 l |
| 1927 | k = ix_la k 18 l |
| 1928 | ret k |
| 1929 | end |
| 1930 | |
| 1931 | fn ix_list to void |
| 1932 | fl = get ug 12 |
| 1933 | cap = add 8 mul get ug 6 12 |
| 1934 | r = enlarge ixl mul cap 2 |
| 1935 | if ne r 0 |
| 1936 | exit 70 |
| 1937 | end |
| 1938 | n = ix_la 0 0 0 |
| 1939 | if eq and fl 1 0 |
| 1940 | n = ix_la n 1 0 |
| 1941 | end |
| 1942 | for l ulong get ug 6 bound IXBIG |
| 1943 | n = ix_list_l n l |
| 1944 | end |
| 1945 | n = ix_la n 2 0 |
| 1946 | if and ne and fl 4 0 ne get ixm 0 5 |
| 1947 | n = ix_la n 3 0 |
| 1948 | end |
| 1949 | put ixs 10 n |
| 1950 | end |
| 1951 | |
| 1952 | fn ix_q nd ulong rows ulong cols ulong base ulong kind ulong to void |
| 1953 | put ixq 2 nd |
| 1954 | put ixq 3 rows |
| 1955 | put ixq 4 cols |
| 1956 | put ixq 5 base |
| 1957 | put ixq 6 kind |
| 1958 | end |
| 1959 | |
| 1960 | fn ix_ti_g code ulong gn ulong to void |
| 1961 | v = get ug 0 |
| 1962 | d = get ug 2 |
| 1963 | if eq code 0 |
| 1964 | if eq get ixm 0 5 |
| 1965 | ix_q 2 v d get ug 36 0 |
| 1966 | else |
| 1967 | ix_q 2 v d 0 0 |
| 1968 | end |
| 1969 | ret |
| 1970 | end |
| 1971 | if eq code 1 |
| 1972 | ix_q 2 get ug 1 d get ug 32 0 |
| 1973 | ret |
| 1974 | end |
| 1975 | if eq code 2 |
| 1976 | ix_q 1 d 1 get ug 35 gn |
| 1977 | ret |
| 1978 | end |
| 1979 | ix_q 2 v d get ug 36 0 |
| 1980 | end |
| 1981 | |
| 1982 | fn ix_pk heads ulong to ulong |
| 1983 | put ixq 7 heads |
| 1984 | if ne get ixm 2 0 |
| 1985 | ret 4 |
| 1986 | end |
| 1987 | ret 1 |
| 1988 | end |
| 1989 | |
| 1990 | fn ix_ti_l r ulong l ulong gn ulong to void |
| 1991 | d = get ug 2 |
| 1992 | e = get ug 8 |
| 1993 | kvd = get ug 9 |
| 1994 | f = get ug 5 |
| 1995 | if eq r 0 |
| 1996 | ix_q 1 d 1 up_g1 l gn |
| 1997 | ret |
| 1998 | end |
| 1999 | if eq r 1 |
| 2000 | ix_q 2 d d up_wq l ix_pk get ug 3 |
| 2001 | ret |
| 2002 | end |
| 2003 | if eq r 2 |
| 2004 | ix_q 2 kvd d up_wk l ix_pk get ug 4 |
| 2005 | ret |
| 2006 | end |
| 2007 | if eq r 3 |
| 2008 | ix_q 2 kvd d up_wv l 1 |
| 2009 | ret |
| 2010 | end |
| 2011 | if eq r 4 |
| 2012 | ix_q 2 d d up_wo l 1 |
| 2013 | ret |
| 2014 | end |
| 2015 | if eq r 5 |
| 2016 | ix_q 1 e 1 up_qn l 0 |
| 2017 | ret |
| 2018 | end |
| 2019 | if eq r 6 |
| 2020 | ix_q 1 e 1 up_kn l 0 |
| 2021 | ret |
| 2022 | end |
| 2023 | if eq r 7 |
| 2024 | ix_q 1 d 1 up_g2 l gn |
| 2025 | ret |
| 2026 | end |
| 2027 | if eq r 8 |
| 2028 | ix_q 2 f d up_w1 l 1 |
| 2029 | ret |
| 2030 | end |
| 2031 | if eq r 9 |
| 2032 | if ne and get ug 12 66 0 |
| 2033 | ix_q 2 f d up_wup l 1 |
| 2034 | else |
| 2035 | ix_q 2 f d up_w1 l 1 |
| 2036 | end |
| 2037 | ret |
| 2038 | end |
| 2039 | ix_q 2 d f up_w2 l 1 |
| 2040 | end |
| 2041 | |
| 2042 | fn ix_ti k ulong to void |
| 2043 | code = get ixl mul k 2 |
| 2044 | l = get ixl add mul k 2 1 |
| 2045 | put ixq 0 code |
| 2046 | put ixq 1 l |
| 2047 | gn = ulong 0 |
| 2048 | if and eq get ixm 0 5 eq get ixm 3 0 |
| 2049 | gn = 2 |
| 2050 | end |
| 2051 | if lt code 8 |
| 2052 | ix_ti_g code gn |
| 2053 | ret |
| 2054 | end |
| 2055 | ix_ti_l sub code 8 l gn |
| 2056 | end |
| 2057 | |
| 2058 | fn ix_perm r ulong to ulong |
| 2059 | e = get ug 8 |
| 2060 | h = div r e |
| 2061 | j = rem r e |
| 2062 | ret add mul h e add mul rem j 2 div e 2 div j 2 |
| 2063 | end |
| 2064 | |
| 2065 | fn ix_val r ulong c ulong to f64 |
| 2066 | kind = get ixq 6 |
| 2067 | base = get ixq 5 |
| 2068 | if eq kind 0 |
| 2069 | i0 = add base add mul r get ixq 4 c |
| 2070 | ret get up i0 |
| 2071 | end |
| 2072 | if eq kind 2 |
| 2073 | i2 = add base add mul r get ixq 4 c |
| 2074 | ret sub get up i2 1.0 |
| 2075 | end |
| 2076 | rr = r |
| 2077 | if eq kind 4 |
| 2078 | rr = ix_perm r |
| 2079 | end |
| 2080 | i1 = add base add mul c get ixq 3 rr |
| 2081 | ret get up i1 |
| 2082 | end |
| 2083 | |
| 2084 | fn ix_hfname to void |
| 2085 | code = get ixq 0 |
| 2086 | ixn_reset |
| 2087 | if eq code 0 |
| 2088 | ixn_t ixn_emb |
| 2089 | ret |
| 2090 | end |
| 2091 | if eq code 1 |
| 2092 | ixn_t ixn_pos |
| 2093 | ret |
| 2094 | end |
| 2095 | if eq code 2 |
| 2096 | ixn_t ixn_norm |
| 2097 | ret |
| 2098 | end |
| 2099 | if eq code 3 |
| 2100 | ixn_t ixn_lmh |
| 2101 | ret |
| 2102 | end |
| 2103 | ixn_t ixn_lay |
| 2104 | ixn_dec get ixq 1 |
| 2105 | ixn_c 46 |
| 2106 | r = sub code 8 |
| 2107 | if eq r 0 |
| 2108 | ixn_t ixr_0 |
| 2109 | end |
| 2110 | if eq r 1 |
| 2111 | ixn_t ixr_1 |
| 2112 | end |
| 2113 | if eq r 2 |
| 2114 | ixn_t ixr_2 |
| 2115 | end |
| 2116 | if eq r 3 |
| 2117 | ixn_t ixr_3 |
| 2118 | end |
| 2119 | if eq r 4 |
| 2120 | ixn_t ixr_4 |
| 2121 | end |
| 2122 | if eq r 5 |
| 2123 | ixn_t ixr_5 |
| 2124 | end |
| 2125 | if eq r 6 |
| 2126 | ixn_t ixr_6 |
| 2127 | end |
| 2128 | if eq r 7 |
| 2129 | ixn_t ixr_7 |
| 2130 | end |
| 2131 | if eq r 8 |
| 2132 | ixn_t ixr_8 |
| 2133 | end |
| 2134 | if eq r 9 |
| 2135 | ixn_t ixr_9 |
| 2136 | end |
| 2137 | if eq r 10 |
| 2138 | ixn_t ixr_10 |
| 2139 | end |
| 2140 | end |
| 2141 | |
| 2142 | fn ix_ggname to void |
| 2143 | code = get ixq 0 |
| 2144 | ixn_reset |
| 2145 | if eq code 0 |
| 2146 | ixn_t ixg_temb |
| 2147 | ret |
| 2148 | end |
| 2149 | if eq code 1 |
| 2150 | ixn_t ixg_tpos |
| 2151 | ret |
| 2152 | end |
| 2153 | if eq code 2 |
| 2154 | ixn_t ixg_tnorm |
| 2155 | ret |
| 2156 | end |
| 2157 | if eq code 3 |
| 2158 | ixn_t ixg_tout |
| 2159 | ret |
| 2160 | end |
| 2161 | ixn_t ixg_blk |
| 2162 | ixn_dec get ixq 1 |
| 2163 | r = sub code 8 |
| 2164 | if eq r 0 |
| 2165 | ixn_t ixg_r0 |
| 2166 | end |
| 2167 | if eq r 1 |
| 2168 | ixn_t ixg_r1 |
| 2169 | end |
| 2170 | if eq r 2 |
| 2171 | ixn_t ixg_r2 |
| 2172 | end |
| 2173 | if eq r 3 |
| 2174 | ixn_t ixg_r3 |
| 2175 | end |
| 2176 | if eq r 4 |
| 2177 | ixn_t ixg_r4 |
| 2178 | end |
| 2179 | if eq r 5 |
| 2180 | ixn_t ixg_r5 |
| 2181 | end |
| 2182 | if eq r 6 |
| 2183 | ixn_t ixg_r6 |
| 2184 | end |
| 2185 | if eq r 7 |
| 2186 | ixn_t ixg_r7 |
| 2187 | end |
| 2188 | if eq r 8 |
| 2189 | ixn_t ixg_r8 |
| 2190 | end |
| 2191 | if eq r 9 |
| 2192 | ixn_t ixg_r9 |
| 2193 | end |
| 2194 | if eq r 10 |
| 2195 | ixn_t ixg_r10 |
| 2196 | end |
| 2197 | end |
| 2198 | |
| 2199 | fn ix_wrow r ulong to void |
| 2200 | c = get ixq 4 |
| 2201 | bf = ne get ixm 1 0 |
| 2202 | for j ulong c bound IXBIG |
| 2203 | v = ix_val r j |
| 2204 | if bf |
| 2205 | ixw_u16 ix_bf16 v |
| 2206 | else |
| 2207 | ixw_u32 ulong bitcast uint f32 v |
| 2208 | end |
| 2209 | end |
| 2210 | end |
| 2211 | |
| 2212 | fn ix_wtensor to void |
| 2213 | rows = get ixq 3 |
| 2214 | for r ulong rows bound IXBIG |
| 2215 | ix_wrow r |
| 2216 | end |
| 2217 | end |
| 2218 | |
| 2219 | fn ix_esz to ulong |
| 2220 | if ne get ixm 1 0 |
| 2221 | ret 2 |
| 2222 | end |
| 2223 | ret 4 |
| 2224 | end |
| 2225 | |
| 2226 | note ======== export-hf ======== |
| 2227 | |
| 2228 | fn ixj_ks ob edit uchar * k view uchar * s view uchar * to void |
| 2229 | js_wsbuf ob k 0 len k |
| 2230 | js_wsbuf ob s 0 len s |
| 2231 | end |
| 2232 | |
| 2233 | fn ixj_ku ob edit uchar * k view uchar * v ulong to void |
| 2234 | js_wsbuf ob k 0 len k |
| 2235 | js_wulong ob v |
| 2236 | end |
| 2237 | |
| 2238 | fn ix_wobuf ob view uchar * n ulong to void |
| 2239 | for i ulong n bound IXBIG |
| 2240 | ixw_b ulong get ob add jswh i |
| 2241 | end |
| 2242 | end |
| 2243 | |
| 2244 | fn ix_cfgw_arch ob edit uchar * to void |
| 2245 | a = get ixm 0 |
| 2246 | js_wsbuf ob ixk_arch 0 len ixk_arch |
| 2247 | js_warr ob |
| 2248 | if eq a 1 |
| 2249 | js_wsbuf ob ixv_allama 0 len ixv_allama |
| 2250 | end |
| 2251 | if eq a 3 |
| 2252 | js_wsbuf ob ixv_aqwen3 0 len ixv_aqwen3 |
| 2253 | end |
| 2254 | if eq a 5 |
| 2255 | js_wsbuf ob ixv_agemma 0 len ixv_agemma |
| 2256 | end |
| 2257 | if eq a 6 |
| 2258 | js_wsbuf ob ixv_ahelix 0 len ixv_ahelix |
| 2259 | end |
| 2260 | js_warre ob |
| 2261 | if eq a 1 |
| 2262 | ixj_ks ob ixk_mt ixv_llama |
| 2263 | end |
| 2264 | if eq a 3 |
| 2265 | ixj_ks ob ixk_mt ixv_qwen3 |
| 2266 | end |
| 2267 | if eq a 5 |
| 2268 | ixj_ks ob ixk_mt ixv_gemma |
| 2269 | end |
| 2270 | if eq a 6 |
| 2271 | ixj_ks ob ixk_mt ixv_helix |
| 2272 | end |
| 2273 | end |
| 2274 | |
| 2275 | fn ix_cfgw_act ob edit uchar * to void |
| 2276 | fl = get ug 12 |
| 2277 | if ne and fl 2 0 |
| 2278 | ixj_ks ob ixk_act ixv_silu |
| 2279 | ret |
| 2280 | end |
| 2281 | if ne and fl 96 0 |
| 2282 | ixj_ks ob ixk_act ixv_gtanh |
| 2283 | if eq get ixm 0 5 |
| 2284 | ixj_ks ob ixk_acn ixv_gtanh |
| 2285 | end |
| 2286 | ret |
| 2287 | end |
| 2288 | ixj_ks ob ixk_act ixv_relu |
| 2289 | end |
| 2290 | |
| 2291 | fn ix_cfgw_num ob edit uchar * to void |
| 2292 | js_wsbuf ob ixk_eps 0 len ixk_eps |
| 2293 | ix_wf64 ob bitcast f64 get ug 14 |
| 2294 | js_wsbuf ob ixk_th 0 len ixk_th |
| 2295 | mi = get ug 13 |
| 2296 | if eq rem mi 1000 0 |
| 2297 | js_wulong ob div mi 1000 |
| 2298 | else |
| 2299 | ix_wf64 ob div f64 mi 1000.0 |
| 2300 | end |
| 2301 | js_wsbuf ob ixk_tie 0 len ixk_tie |
| 2302 | js_wbool ob or eq get ixm 0 5 eq and get ug 12 4 0 |
| 2303 | end |
| 2304 | |
| 2305 | fn ix_cfgw to void |
| 2306 | ob = new uchar 65536 0 |
| 2307 | if lt js_winit ob 0 |
| 2308 | exit 70 |
| 2309 | end |
| 2310 | js_wobj ob |
| 2311 | ix_cfgw_arch ob |
| 2312 | ixj_ku ob ixk_vs get ug 0 |
| 2313 | ixj_ku ob ixk_hs get ug 2 |
| 2314 | ixj_ku ob ixk_is get ug 5 |
| 2315 | ixj_ku ob ixk_nl get ug 6 |
| 2316 | ixj_ku ob ixk_nh get ug 3 |
| 2317 | ixj_ku ob ixk_kv get ug 4 |
| 2318 | ixj_ku ob ixk_hd get ug 8 |
| 2319 | ixj_ku ob ixk_mp get ug 1 |
| 2320 | ix_cfgw_num ob |
| 2321 | ix_cfgw_act ob |
| 2322 | js_wsbuf ob ixk_ab 0 len ixk_ab |
| 2323 | js_wbool ob false |
| 2324 | js_wsbuf ob ixk_rs 0 len ixk_rs |
| 2325 | js_wnull ob |
| 2326 | if ne get ixm 1 0 |
| 2327 | ixj_ks ob ixk_td ixv_bf16 |
| 2328 | else |
| 2329 | ixj_ks ob ixk_td ixv_fp32 |
| 2330 | end |
| 2331 | ixj_ku ob ixk_hf get ug 12 |
| 2332 | ixj_ku ob ixk_lp get ug 17 |
| 2333 | ixj_ku ob ixk_lc get ug 18 |
| 2334 | ixj_ku ob ixk_np get ug 19 |
| 2335 | js_wobje ob |
| 2336 | n = js_wdone ob |
| 2337 | if le n 0 |
| 2338 | exit 70 |
| 2339 | end |
| 2340 | ix_path_arg 3 |
| 2341 | ix_path_t ixp_cfg |
| 2342 | ixw_open |
| 2343 | ix_wobuf ob ulong n |
| 2344 | c = ixw_close |
| 2345 | end |
| 2346 | |
| 2347 | fn ix_sth_key ob edit uchar * to void |
| 2348 | js_wsbeg ob |
| 2349 | n = get ixs 5 |
| 2350 | for i ulong n |
| 2351 | js_wsb ob get ixnm i |
| 2352 | end |
| 2353 | js_wsend ob |
| 2354 | end |
| 2355 | |
| 2356 | fn ix_sth_one ob edit uchar * k ulong off ulong to ulong |
| 2357 | ix_ti k |
| 2358 | ix_hfname |
| 2359 | ix_sth_key ob |
| 2360 | js_wobj ob |
| 2361 | if ne get ixm 1 0 |
| 2362 | ixj_ks ob ixs_dtype ixs_BF16 |
| 2363 | else |
| 2364 | ixj_ks ob ixs_dtype ixs_F32 |
| 2365 | end |
| 2366 | js_wsbuf ob ixs_shape 0 len ixs_shape |
| 2367 | js_warr ob |
| 2368 | js_wulong ob get ixq 3 |
| 2369 | if eq get ixq 2 2 |
| 2370 | js_wulong ob get ixq 4 |
| 2371 | end |
| 2372 | js_warre ob |
| 2373 | nb = mul mul get ixq 3 get ixq 4 ix_esz |
| 2374 | js_wsbuf ob ixs_doff 0 len ixs_doff |
| 2375 | js_warr ob |
| 2376 | js_wulong ob off |
| 2377 | js_wulong ob add off nb |
| 2378 | js_warre ob |
| 2379 | js_wobje ob |
| 2380 | ret add off nb |
| 2381 | end |
| 2382 | |
| 2383 | fn ix_sth to void |
| 2384 | ob = new uchar 2097152 0 |
| 2385 | if lt js_winit ob 0 |
| 2386 | exit 70 |
| 2387 | end |
| 2388 | js_wobj ob |
| 2389 | js_wsbuf ob ixs_meta 0 len ixs_meta |
| 2390 | js_wobj ob |
| 2391 | ixj_ks ob ixs_fmt ixs_pt |
| 2392 | js_wobje ob |
| 2393 | off = ulong 0 |
| 2394 | for k ulong get ixs 10 bound IXBIG |
| 2395 | off = ix_sth_one ob k off |
| 2396 | end |
| 2397 | js_wobje ob |
| 2398 | r = js_wdone ob |
| 2399 | if le r 0 |
| 2400 | exit 70 |
| 2401 | end |
| 2402 | n = ulong r |
| 2403 | pad = rem sub 8 rem add 8 n 8 8 |
| 2404 | ixw_u64 add n pad |
| 2405 | ix_wobuf ob n |
| 2406 | for i ulong pad |
| 2407 | ixw_b 32 |
| 2408 | end |
| 2409 | end |
| 2410 | |
| 2411 | fn ix_cmd_exh to void |
| 2412 | na = ulong argcnt |
| 2413 | if and ne na 4 ne na 5 |
| 2414 | exit 2 |
| 2415 | end |
| 2416 | put ixm 1 0 |
| 2417 | if eq na 5 |
| 2418 | if ix_arg_eq 4 ix_s_bf16 |
| 2419 | put ixm 1 1 |
| 2420 | else |
| 2421 | if not ix_arg_eq 4 ix_s_f32 |
| 2422 | exit 2 |
| 2423 | end |
| 2424 | end |
| 2425 | end |
| 2426 | ix_ck_load 2 |
| 2427 | ix_finite |
| 2428 | put ixm 0 ix_arch |
| 2429 | put ixm 2 0 |
| 2430 | put ixm 3 0 |
| 2431 | ix_list |
| 2432 | ix_cfgw |
| 2433 | ix_path_arg 3 |
| 2434 | ix_path_t ixp_st |
| 2435 | ixw_open |
| 2436 | ix_sth |
| 2437 | for k ulong get ixs 10 bound IXBIG |
| 2438 | ix_ti k |
| 2439 | ix_wtensor |
| 2440 | end |
| 2441 | tot = ixw_close |
| 2442 | uputc 88 |
| 2443 | uputc 72 |
| 2444 | uputc 32 |
| 2445 | uputu get ixs 10 |
| 2446 | uputc 32 |
| 2447 | uputu tot |
| 2448 | uputc 10 |
| 2449 | uflush |
| 2450 | end |
| 2451 | |
| 2452 | note ======== export-gguf ======== |
| 2453 | |
| 2454 | fn ix_kv_u key view uchar * v ulong to void |
| 2455 | ixn_reset |
| 2456 | ixn_t key |
| 2457 | ixw_nm |
| 2458 | ixw_u32 4 |
| 2459 | ixw_u32 v |
| 2460 | end |
| 2461 | |
| 2462 | fn ix_kv_au suf view uchar * v ulong to void |
| 2463 | ixn_reset |
| 2464 | ixn_arch |
| 2465 | ixn_t suf |
| 2466 | ixw_nm |
| 2467 | ixw_u32 4 |
| 2468 | ixw_u32 v |
| 2469 | end |
| 2470 | |
| 2471 | fn ix_kv_af suf view uchar * v f64 to void |
| 2472 | ixn_reset |
| 2473 | ixn_arch |
| 2474 | ixn_t suf |
| 2475 | ixw_nm |
| 2476 | ixw_u32 6 |
| 2477 | ixw_u32 ulong bitcast uint f32 v |
| 2478 | end |
| 2479 | |
| 2480 | fn ix_gkv to void |
| 2481 | ixn_reset |
| 2482 | ixn_t ixg_arch |
| 2483 | ixw_nm |
| 2484 | ixw_u32 8 |
| 2485 | ixn_reset |
| 2486 | ixn_arch |
| 2487 | ixw_nm |
| 2488 | ixn_reset |
| 2489 | ixn_t ixg_name |
| 2490 | ixw_nm |
| 2491 | ixw_u32 8 |
| 2492 | ixn_reset |
| 2493 | ixn_t ixg_namev |
| 2494 | ixw_nm |
| 2495 | ix_kv_u ixg_align 32 |
| 2496 | ix_kv_u ixg_ftype 0 |
| 2497 | ix_kv_au ixg_vs get ug 0 |
| 2498 | ix_kv_au ixg_ctx get ug 1 |
| 2499 | ix_kv_au ixg_emb get ug 2 |
| 2500 | ix_kv_au ixg_blkc get ug 6 |
| 2501 | ix_kv_au ixg_ffn get ug 5 |
| 2502 | ix_kv_au ixg_hc get ug 3 |
| 2503 | ix_kv_au ixg_hkv get ug 4 |
| 2504 | ix_kv_au ixg_kl get ug 8 |
| 2505 | ix_kv_au ixg_vl get ug 8 |
| 2506 | ix_kv_af ixg_eps bitcast f64 get ug 14 |
| 2507 | ix_kv_af ixg_fb div f64 get ug 13 1000.0 |
| 2508 | ix_kv_au ixg_rd get ug 8 |
| 2509 | ix_kv_u ixg_hfl get ug 12 |
| 2510 | ix_kv_u ixg_hlp get ug 17 |
| 2511 | ix_kv_u ixg_hlc get ug 18 |
| 2512 | ix_kv_u ixg_hnp get ug 19 |
| 2513 | end |
| 2514 | |
| 2515 | fn ix_al32 x ulong to ulong |
| 2516 | ret and add x 31 18446744073709551584 |
| 2517 | end |
| 2518 | |
| 2519 | fn ix_ginfo to void |
| 2520 | off = ulong 0 |
| 2521 | for k ulong get ixs 10 bound IXBIG |
| 2522 | ix_ti k |
| 2523 | ix_ggname |
| 2524 | ixw_nm |
| 2525 | nd = get ixq 2 |
| 2526 | ixw_u32 nd |
| 2527 | if eq nd 2 |
| 2528 | ixw_u64 get ixq 4 |
| 2529 | end |
| 2530 | ixw_u64 get ixq 3 |
| 2531 | ixw_u32 0 |
| 2532 | ixw_u64 off |
| 2533 | off = ix_al32 add off mul mul get ixq 3 get ixq 4 4 |
| 2534 | end |
| 2535 | end |
| 2536 | |
| 2537 | fn ix_gpad to void |
| 2538 | while ne and ixw_pos 31 0 bound 32 |
| 2539 | ixw_b 0 |
| 2540 | end |
| 2541 | end |
| 2542 | |
| 2543 | fn ix_cmd_exg to void |
| 2544 | if ne ulong argcnt 4 |
| 2545 | exit 2 |
| 2546 | end |
| 2547 | ix_ck_load 2 |
| 2548 | ix_finite |
| 2549 | put ixm 0 ix_arch |
| 2550 | put ixm 1 0 |
| 2551 | put ixm 2 0 |
| 2552 | put ixm 3 1 |
| 2553 | if eq get ixm 0 1 |
| 2554 | put ixm 2 1 |
| 2555 | end |
| 2556 | ix_list |
| 2557 | ix_path_arg 3 |
| 2558 | ixw_open |
| 2559 | ixw_u32 1179993927 |
| 2560 | ixw_u32 3 |
| 2561 | ixw_u64 get ixs 10 |
| 2562 | ixw_u64 20 |
| 2563 | ix_gkv |
| 2564 | ix_ginfo |
| 2565 | for k ulong get ixs 10 bound IXBIG |
| 2566 | ix_gpad |
| 2567 | ix_ti k |
| 2568 | ix_wtensor |
| 2569 | end |
| 2570 | tot = ixw_close |
| 2571 | uputc 88 |
| 2572 | uputc 71 |
| 2573 | uputc 32 |
| 2574 | uputu get ixs 10 |
| 2575 | uputc 32 |
| 2576 | uputu tot |
| 2577 | uputc 10 |
| 2578 | uflush |
| 2579 | end |
| 2580 | |
| 2581 | note ======== upgrade OLLMCK01/02/03 -> OLLMCK04 ======== |
| 2582 | |
| 2583 | fn ix_lmag mg ulong to ulong |
| 2584 | if eq mg 3544415659172318287 |
| 2585 | ret 112 |
| 2586 | end |
| 2587 | if eq mg 3616473253210246223 |
| 2588 | ret 120 |
| 2589 | end |
| 2590 | if eq mg 3688530847248174159 |
| 2591 | ret 144 |
| 2592 | end |
| 2593 | exit 11 |
| 2594 | end |
| 2595 | |
| 2596 | fn ix_upg_hdr sz ulong hl ulong to void |
| 2597 | for i ulong 4 |
| 2598 | put ug i uopw_get8 add 8 mul i 8 |
| 2599 | end |
| 2600 | put ug 4 get ug 3 |
| 2601 | put ug 5 uopw_get8 40 |
| 2602 | put ug 6 uopw_get8 48 |
| 2603 | put ug 7 uopw_get8 56 |
| 2604 | put ug 20 uopw_get8 64 |
| 2605 | put ug 21 uopw_get8 72 |
| 2606 | put ug 22 uopw_get8 80 |
| 2607 | put ug 23 uopw_get8 88 |
| 2608 | put ug 12 0 |
| 2609 | put ug 13 10000000 |
| 2610 | put ug 14 bitcast ulong 1.0e-5f64 |
| 2611 | put ug 15 0 |
| 2612 | put ug 16 100 |
| 2613 | put ug 17 0 |
| 2614 | put ug 18 0 |
| 2615 | put ug 19 0 |
| 2616 | if eq hl 144 |
| 2617 | put ug 17 uopw_get8 112 |
| 2618 | put ug 18 uopw_get8 120 |
| 2619 | put ug 19 uopw_get8 128 |
| 2620 | if lt get ug 19 2 |
| 2621 | exit 12 |
| 2622 | end |
| 2623 | end |
| 2624 | if ge hl 120 |
| 2625 | g = uopw_get8 104 |
| 2626 | b = get ug 7 |
| 2627 | if or eq g 0 or gt g b ne rem b g 0 |
| 2628 | exit 12 |
| 2629 | end |
| 2630 | end |
| 2631 | end |
| 2632 | |
| 2633 | fn ix_lver hl ulong to ulong |
| 2634 | if eq hl 112 |
| 2635 | ret 1 |
| 2636 | end |
| 2637 | if eq hl 120 |
| 2638 | ret 2 |
| 2639 | end |
| 2640 | ret 3 |
| 2641 | end |
| 2642 | |
| 2643 | fn ix_cmd_upg to void |
| 2644 | if ne ulong argcnt 4 |
| 2645 | exit 2 |
| 2646 | end |
| 2647 | sz = uofsz 2 |
| 2648 | if lt sz 112 |
| 2649 | exit 10 |
| 2650 | end |
| 2651 | hn = uoprd 2 0 0 144 |
| 2652 | hl = ix_lmag uopw_get8 0 |
| 2653 | if lt sz hl |
| 2654 | exit 10 |
| 2655 | end |
| 2656 | ix_upg_hdr sz hl |
| 2657 | pf = uopw_get8 96 |
| 2658 | fnv = uopw_get8 sub hl 8 |
| 2659 | if not ix_geom |
| 2660 | exit 12 |
| 2661 | end |
| 2662 | p = get ug 10 |
| 2663 | if ne p pf |
| 2664 | exit 13 |
| 2665 | end |
| 2666 | want = add hl mul 24 p |
| 2667 | if lt sz want |
| 2668 | exit 10 |
| 2669 | end |
| 2670 | if gt sz want |
| 2671 | exit 15 |
| 2672 | end |
| 2673 | ix_alloc3 |
| 2674 | put uck_st 0 14695981039346656037 |
| 2675 | put uck_st 1 hl |
| 2676 | for k ulong 3 |
| 2677 | uck_load_pool 2 k |
| 2678 | end |
| 2679 | if ne get uck_st 0 fnv |
| 2680 | exit 14 |
| 2681 | end |
| 2682 | uck_save 3 |
| 2683 | uputc 85 |
| 2684 | uputc 32 |
| 2685 | uputu ix_lver hl |
| 2686 | uputc 32 |
| 2687 | uputu p |
| 2688 | uputc 10 |
| 2689 | uflush |
| 2690 | end |
| 2691 | |
| 2692 | note ======== import-hf-bf16 / info-bf16 (OLLMBF01 sharded BF16 frozen trunk) ======== |
| 2693 | |
| 2694 | fn bf_al256 x ulong to ulong |
| 2695 | ret mul div add x 255 256 256 |
| 2696 | end |
| 2697 | |
| 2698 | fn bf_set_dir ai ulong to void |
| 2699 | r = argread ai bfdir 0 4000 |
| 2700 | if or le r 0 gt r 4000 |
| 2701 | exit 2 |
| 2702 | end |
| 2703 | n = ulong r |
| 2704 | while gt n 1 bound 4001 |
| 2705 | if ne get bfdir sub n 1 47 |
| 2706 | break |
| 2707 | end |
| 2708 | n = sub n 1 |
| 2709 | end |
| 2710 | put bfi 23 n |
| 2711 | end |
| 2712 | |
| 2713 | fn bf_build_path nm view uchar * nl ulong to ulong |
| 2714 | dl = get bfi 23 |
| 2715 | if gt add dl add nl 2 4350 |
| 2716 | exit 70 |
| 2717 | end |
| 2718 | for i ulong dl |
| 2719 | put ixpath i get bfdir i |
| 2720 | end |
| 2721 | p = dl |
| 2722 | if ne get bfdir sub dl 1 47 |
| 2723 | put ixpath p 47 |
| 2724 | p = add p 1 |
| 2725 | end |
| 2726 | for j ulong nl |
| 2727 | put ixpath add p j get nm j |
| 2728 | end |
| 2729 | put ixs 9 add p nl |
| 2730 | ret add p nl |
| 2731 | end |
| 2732 | |
| 2733 | fn bf_build_shpath si ulong to ulong |
| 2734 | dl = get bfi 23 |
| 2735 | nl = get bfshn si |
| 2736 | if gt add dl add nl 2 4350 |
| 2737 | exit 70 |
| 2738 | end |
| 2739 | for i ulong dl |
| 2740 | put ixpath i get bfdir i |
| 2741 | end |
| 2742 | p = dl |
| 2743 | if ne get bfdir sub dl 1 47 |
| 2744 | put ixpath p 47 |
| 2745 | p = add p 1 |
| 2746 | end |
| 2747 | base = mul si 256 |
| 2748 | for j ulong nl |
| 2749 | put ixpath add p j get bfsh add base j |
| 2750 | end |
| 2751 | put ixs 9 add p nl |
| 2752 | ret add p nl |
| 2753 | end |
| 2754 | |
| 2755 | fn bf_slurp_path src edit uchar * code ulong to ulong |
| 2756 | pl = get ixs 9 |
| 2757 | fd = int fopen ixpath 0 pl 0 0 |
| 2758 | if lt fd 0 |
| 2759 | exit 70 |
| 2760 | end |
| 2761 | sz = fseek fd 0 2 |
| 2762 | if lt sz 0 |
| 2763 | c0 = fclose fd |
| 2764 | exit 70 |
| 2765 | end |
| 2766 | n = ulong sz |
| 2767 | if or eq n 0 gt n len src |
| 2768 | c1 = fclose fd |
| 2769 | exit int code |
| 2770 | end |
| 2771 | got = ulong 0 |
| 2772 | while lt got n bound 1000000 |
| 2773 | r = pread fd src got sub n got long got |
| 2774 | if le r 0 |
| 2775 | c2 = fclose fd |
| 2776 | exit 70 |
| 2777 | end |
| 2778 | got = add got ulong r |
| 2779 | end |
| 2780 | if ne fclose fd 0 |
| 2781 | exit 70 |
| 2782 | end |
| 2783 | ret n |
| 2784 | end |
| 2785 | |
| 2786 | fn bf_cfg_dir to void |
| 2787 | p = bf_build_path ixp_cfg1 len ixp_cfg1 |
| 2788 | src = new uchar 262144 0 |
| 2789 | tape = new uint 65536 0 |
| 2790 | n = bf_slurp_path src 80 |
| 2791 | if lt js_init tape 262144 64 0 |
| 2792 | exit 80 |
| 2793 | end |
| 2794 | if le js_parse src tape n 0 |
| 2795 | exit 80 |
| 2796 | end |
| 2797 | if ne js_type tape 0 jsobj |
| 2798 | exit 80 |
| 2799 | end |
| 2800 | k = js_first tape 0 |
| 2801 | while ne k jsnone bound 1000000 |
| 2802 | ix_cfg_member src tape k |
| 2803 | k = js_mnext tape k |
| 2804 | end |
| 2805 | end |
| 2806 | |
| 2807 | fn bf_cfg_check_scal fl ulong to void |
| 2808 | eps = 1.0e-6f64 |
| 2809 | if ne get ixc 10 0 |
| 2810 | eps = bitcast f64 get ixc 9 |
| 2811 | end |
| 2812 | if or ix_bad eps le eps 0.0 |
| 2813 | exit 81 |
| 2814 | end |
| 2815 | put bfi 9 bitcast ulong eps |
| 2816 | th = 10000.0f64 |
| 2817 | if ne get ixc 12 0 |
| 2818 | th = bitcast f64 get ixc 11 |
| 2819 | end |
| 2820 | mi = mul th 1000.0 |
| 2821 | if or ix_bad mi or le mi 0.0 ge mi 1.0e18 |
| 2822 | exit 81 |
| 2823 | end |
| 2824 | if ne mi f64 ulong mi |
| 2825 | exit 81 |
| 2826 | end |
| 2827 | put bfi 8 ulong mi |
| 2828 | put bfi 10 get ixc 7 |
| 2829 | if eq get bfi 10 0 |
| 2830 | put bfi 10 256 |
| 2831 | end |
| 2832 | end |
| 2833 | |
| 2834 | fn bf_cfg_check to void |
| 2835 | mt = get ixc 0 |
| 2836 | if or eq mt 0 eq mt 99 |
| 2837 | exit 81 |
| 2838 | end |
| 2839 | for i ulong 6 |
| 2840 | if and ne i 3 eq get ixc add 1 i 0 |
| 2841 | exit 81 |
| 2842 | end |
| 2843 | end |
| 2844 | if lt get ixc 1 2 |
| 2845 | exit 81 |
| 2846 | end |
| 2847 | if gt get ixc 6 100000 |
| 2848 | exit 81 |
| 2849 | end |
| 2850 | h = get ixc 3 |
| 2851 | hkv = get ixc 4 |
| 2852 | if eq hkv 0 |
| 2853 | hkv = h |
| 2854 | end |
| 2855 | if or eq hkv 0 or gt hkv h ne rem h hkv 0 |
| 2856 | exit 88 |
| 2857 | end |
| 2858 | hd = get ixc 8 |
| 2859 | if eq hd 0 |
| 2860 | if ne rem get ixc 2 h 0 |
| 2861 | exit 88 |
| 2862 | end |
| 2863 | hd = div get ixc 2 h |
| 2864 | else |
| 2865 | if or eq hd 0 ne rem hd 2 0 |
| 2866 | exit 88 |
| 2867 | end |
| 2868 | end |
| 2869 | if ne get ixc 14 0 |
| 2870 | exit 82 |
| 2871 | end |
| 2872 | fl = ix_cfg_flags mt |
| 2873 | if and ne mt 5 ne mt 6 |
| 2874 | if ne get ixc 13 2 |
| 2875 | fl = or fl 4 |
| 2876 | end |
| 2877 | end |
| 2878 | if eq mt 6 |
| 2879 | tie = get ixc 13 |
| 2880 | if ne tie 0 |
| 2881 | if ne eq tie 2 eq and fl 4 0 |
| 2882 | exit 81 |
| 2883 | end |
| 2884 | end |
| 2885 | end |
| 2886 | put bfi 0 get ixc 1 |
| 2887 | put bfi 1 get ixc 2 |
| 2888 | put bfi 2 h |
| 2889 | put bfi 3 hkv |
| 2890 | put bfi 4 hd |
| 2891 | put bfi 5 get ixc 5 |
| 2892 | put bfi 6 get ixc 6 |
| 2893 | put bfi 7 fl |
| 2894 | put bfi 13 mul h hd |
| 2895 | put bfi 14 mul hkv hd |
| 2896 | put bfi 16 0 |
| 2897 | if eq mt 5 |
| 2898 | put bfi 16 1 |
| 2899 | end |
| 2900 | put bfi 17 0 |
| 2901 | if and ne and fl 4 0 ne mt 5 |
| 2902 | put bfi 17 1 |
| 2903 | end |
| 2904 | put ug 0 get bfi 0 |
| 2905 | put ug 2 get bfi 1 |
| 2906 | put ug 3 h |
| 2907 | put ug 4 hkv |
| 2908 | put ug 5 get bfi 5 |
| 2909 | put ug 6 get bfi 6 |
| 2910 | put ug 8 hd |
| 2911 | put ug 9 get bfi 14 |
| 2912 | put ug 12 fl |
| 2913 | bf_cfg_check_scal fl |
| 2914 | end |
| 2915 | |
| 2916 | fn bf_plan_add sl ulong nb ulong nsc ulong off ulong to ulong |
| 2917 | put bfo mul sl 2 off |
| 2918 | put bfo add mul sl 2 1 nb |
| 2919 | put bfi 11 add get bfi 11 nsc |
| 2920 | ret add off bf_al256 nb |
| 2921 | end |
| 2922 | |
| 2923 | fn bf_plan_lay l ulong off ulong to ulong |
| 2924 | d = get bfi 1 |
| 2925 | qd = get bfi 13 |
| 2926 | kvd = get bfi 14 |
| 2927 | f = get bfi 5 |
| 2928 | fl = get bfi 7 |
| 2929 | b = add 8 mul l 24 |
| 2930 | p = bf_plan_add b mul d 4 d off |
| 2931 | p = bf_plan_add add b 1 mul mul qd d 2 mul qd d p |
| 2932 | p = bf_plan_add add b 2 mul mul kvd d 2 mul kvd d p |
| 2933 | p = bf_plan_add add b 3 mul mul kvd d 2 mul kvd d p |
| 2934 | p = bf_plan_add add b 4 mul mul d qd 2 mul d qd p |
| 2935 | if ne and fl 8 0 |
| 2936 | hd = get bfi 4 |
| 2937 | p = bf_plan_add add b 5 mul hd 4 hd p |
| 2938 | p = bf_plan_add add b 6 mul hd 4 hd p |
| 2939 | end |
| 2940 | p = bf_plan_add add b 7 mul d 4 d p |
| 2941 | if ne and fl 66 0 |
| 2942 | p = bf_plan_add add b 8 mul mul f d 2 mul f d p |
| 2943 | end |
| 2944 | p = bf_plan_add add b 9 mul mul f d 2 mul f d p |
| 2945 | p = bf_plan_add add b 10 mul mul d f 2 mul d f p |
| 2946 | ret p |
| 2947 | end |
| 2948 | |
| 2949 | fn bf_plan to void |
| 2950 | nsl = add 8 mul get bfi 6 24 |
| 2951 | r = enlarge bfo mul nsl 2 |
| 2952 | if ne r 0 |
| 2953 | exit 70 |
| 2954 | end |
| 2955 | r2 = enlarge bfsl nsl |
| 2956 | if ne r2 0 |
| 2957 | exit 70 |
| 2958 | end |
| 2959 | r3 = enlarge ixt mul nsl 8 |
| 2960 | if ne r3 0 |
| 2961 | exit 70 |
| 2962 | end |
| 2963 | put ixs 4 nsl |
| 2964 | for i ulong mul nsl 2 bound IXBIG |
| 2965 | put bfo i 0 |
| 2966 | end |
| 2967 | for j ulong mul nsl 8 bound IXBIG |
| 2968 | put ixt j 0 |
| 2969 | end |
| 2970 | put bfi 11 0 |
| 2971 | v = get bfi 0 |
| 2972 | d = get bfi 1 |
| 2973 | off = bf_plan_add 0 mul mul v d 2 mul v d 0 |
| 2974 | for l ulong get bfi 6 bound IXBIG |
| 2975 | off = bf_plan_lay l off |
| 2976 | end |
| 2977 | off = bf_plan_add 2 mul d 4 d off |
| 2978 | if ne get bfi 17 0 |
| 2979 | off = bf_plan_add 3 mul mul v d 2 mul v d off |
| 2980 | end |
| 2981 | put bfi 12 off |
| 2982 | end |
| 2983 | |
| 2984 | fn bf_add_shard nl ulong to void |
| 2985 | if or eq nl 0 gt nl 255 |
| 2986 | exit 83 |
| 2987 | end |
| 2988 | for i ulong nl |
| 2989 | if eq get ixnm i 47 |
| 2990 | exit 83 |
| 2991 | end |
| 2992 | if and lt add i 1 nl and eq get ixnm i 46 eq get ixnm add i 1 46 |
| 2993 | exit 83 |
| 2994 | end |
| 2995 | end |
| 2996 | ns = get bfi 15 |
| 2997 | for s ulong ns |
| 2998 | if eq get bfshn s nl |
| 2999 | base = mul s 256 |
| 3000 | same = true |
| 3001 | for k ulong nl |
| 3002 | if ne get bfsh add base k get ixnm k |
| 3003 | same = false |
| 3004 | break |
| 3005 | end |
| 3006 | end |
| 3007 | if same |
| 3008 | ret |
| 3009 | end |
| 3010 | end |
| 3011 | end |
| 3012 | if ge ns 256 |
| 3013 | exit 83 |
| 3014 | end |
| 3015 | dst = mul ns 256 |
| 3016 | for j ulong nl |
| 3017 | put bfsh add dst j get ixnm j |
| 3018 | end |
| 3019 | put bfshn ns nl |
| 3020 | put bfi 15 add ns 1 |
| 3021 | end |
| 3022 | |
| 3023 | fn bf_shard_wm src view uchar * tape view uint * v ulong to void |
| 3024 | if ne js_type tape v jsobj |
| 3025 | exit 83 |
| 3026 | end |
| 3027 | m = js_first tape v |
| 3028 | nb = new uchar 1100 0 |
| 3029 | while ne m jsnone bound 1000000 |
| 3030 | mv = add m 1 |
| 3031 | if ne js_type tape mv jsstr |
| 3032 | exit 83 |
| 3033 | end |
| 3034 | r = js_sget src js_off tape mv nb |
| 3035 | if or le r 0 gt r 255 |
| 3036 | exit 83 |
| 3037 | end |
| 3038 | n = ulong r |
| 3039 | for i ulong n |
| 3040 | put ixnm i get nb i |
| 3041 | end |
| 3042 | bf_add_shard n |
| 3043 | m = js_mnext tape m |
| 3044 | end |
| 3045 | end |
| 3046 | |
| 3047 | fn bf_shard_list to void |
| 3048 | put bfi 15 0 |
| 3049 | p = bf_build_path ixp_idx len ixp_idx |
| 3050 | fd = int fopen ixpath 0 p 0 0 |
| 3051 | if lt fd 0 |
| 3052 | for i ulong len ixp_st1 |
| 3053 | put bfsh i get ixp_st1 i |
| 3054 | end |
| 3055 | put bfshn 0 len ixp_st1 |
| 3056 | put bfi 15 1 |
| 3057 | ret |
| 3058 | end |
| 3059 | c0 = fclose fd |
| 3060 | src = new uchar 983040 0 |
| 3061 | tape = new uint 524288 0 |
| 3062 | n = bf_slurp_path src 83 |
| 3063 | if lt js_init tape 983040 64 0 |
| 3064 | exit 83 |
| 3065 | end |
| 3066 | if le js_parse src tape n 0 |
| 3067 | exit 83 |
| 3068 | end |
| 3069 | if ne js_type tape 0 jsobj |
| 3070 | exit 83 |
| 3071 | end |
| 3072 | k = js_first tape 0 |
| 3073 | found = false |
| 3074 | while ne k jsnone bound 1000000 |
| 3075 | if js_streq src js_off tape k ixk_wm |
| 3076 | bf_shard_wm src tape add k 1 |
| 3077 | found = true |
| 3078 | break |
| 3079 | end |
| 3080 | k = js_mnext tape k |
| 3081 | end |
| 3082 | if or not found eq get bfi 15 0 |
| 3083 | exit 83 |
| 3084 | end |
| 3085 | end |
| 3086 | |
| 3087 | fn bf_st_open_sh si ulong to ulong |
| 3088 | pl = bf_build_shpath si |
| 3089 | fd = int fopen ixpath 0 pl 0 0 |
| 3090 | if lt fd 0 |
| 3091 | exit 70 |
| 3092 | end |
| 3093 | put ixs 1 ulong fd |
| 3094 | sz = fseek fd 0 2 |
| 3095 | if lt sz 8 |
| 3096 | c0 = fclose fd |
| 3097 | exit 87 |
| 3098 | end |
| 3099 | hb = new uchar 8 0 |
| 3100 | if ne pread fd hb 0 8 0 8 |
| 3101 | c1 = fclose fd |
| 3102 | exit 87 |
| 3103 | end |
| 3104 | n = ulong 0 |
| 3105 | for k ulong 8 |
| 3106 | n = or n shl ulong get hb k mul k 8 |
| 3107 | end |
| 3108 | if or lt n 2 gt n 983040 |
| 3109 | c2 = fclose fd |
| 3110 | exit 83 |
| 3111 | end |
| 3112 | if gt add 8 n ulong sz |
| 3113 | c3 = fclose fd |
| 3114 | exit 87 |
| 3115 | end |
| 3116 | put ixs 2 add 8 n |
| 3117 | put ixs 3 sub ulong sz add 8 n |
| 3118 | ret n |
| 3119 | end |
| 3120 | |
| 3121 | fn bf_st_member src view uchar * tape view uint * k ulong to void |
| 3122 | ix_key src tape k |
| 3123 | v = add k 1 |
| 3124 | if ixn_eq ixs_meta |
| 3125 | if ne js_type tape v jsobj |
| 3126 | exit 83 |
| 3127 | end |
| 3128 | ret |
| 3129 | end |
| 3130 | if ne js_type tape v jsobj |
| 3131 | exit 83 |
| 3132 | end |
| 3133 | ix_st_entry src tape v |
| 3134 | ix_ext_add |
| 3135 | sl = ix_slot |
| 3136 | if eq sl 9999 |
| 3137 | ret |
| 3138 | end |
| 3139 | if ge sl 9998 |
| 3140 | exit 84 |
| 3141 | end |
| 3142 | ix_slot_put sl |
| 3143 | cnt = get bfi 22 |
| 3144 | put bfsl cnt sl |
| 3145 | put bfi 22 add cnt 1 |
| 3146 | end |
| 3147 | |
| 3148 | fn bf_check_l_slot b ulong r ulong to void |
| 3149 | d = get bfi 1 |
| 3150 | qd = get bfi 13 |
| 3151 | kvd = get bfi 14 |
| 3152 | f = get bfi 5 |
| 3153 | if eq r 0 |
| 3154 | ix_req1 b d |
| 3155 | ret |
| 3156 | end |
| 3157 | if eq r 1 |
| 3158 | ix_req2 add b 1 qd d |
| 3159 | ret |
| 3160 | end |
| 3161 | if eq r 2 |
| 3162 | ix_req2 add b 2 kvd d |
| 3163 | ret |
| 3164 | end |
| 3165 | if eq r 3 |
| 3166 | ix_req2 add b 3 kvd d |
| 3167 | ret |
| 3168 | end |
| 3169 | if eq r 4 |
| 3170 | ix_req2 add b 4 d qd |
| 3171 | ret |
| 3172 | end |
| 3173 | if eq r 5 |
| 3174 | ix_req1 add b 5 get bfi 4 |
| 3175 | ret |
| 3176 | end |
| 3177 | if eq r 6 |
| 3178 | ix_req1 add b 6 get bfi 4 |
| 3179 | ret |
| 3180 | end |
| 3181 | if eq r 7 |
| 3182 | ix_req1 add b 7 d |
| 3183 | ret |
| 3184 | end |
| 3185 | if eq r 8 |
| 3186 | ix_req2 add b 8 f d |
| 3187 | ret |
| 3188 | end |
| 3189 | if eq r 9 |
| 3190 | ix_req2 add b 9 f d |
| 3191 | ret |
| 3192 | end |
| 3193 | if eq r 10 |
| 3194 | ix_req2 add b 10 d f |
| 3195 | ret |
| 3196 | end |
| 3197 | if or eq r 11 eq r 14 |
| 3198 | ix_bias add b r d |
| 3199 | ret |
| 3200 | end |
| 3201 | if or eq r 12 eq r 13 |
| 3202 | ix_bias add b r kvd |
| 3203 | ret |
| 3204 | end |
| 3205 | if or eq r 15 eq r 16 |
| 3206 | ix_bias add b r f |
| 3207 | ret |
| 3208 | end |
| 3209 | ix_bias add b 17 d |
| 3210 | end |
| 3211 | |
| 3212 | fn bf_check_slot sl ulong to void |
| 3213 | v = get bfi 0 |
| 3214 | d = get bfi 1 |
| 3215 | if eq sl 0 |
| 3216 | ix_req2 0 v d |
| 3217 | ret |
| 3218 | end |
| 3219 | if eq sl 1 |
| 3220 | exit 84 |
| 3221 | end |
| 3222 | if eq sl 2 |
| 3223 | ix_req1 2 d |
| 3224 | ret |
| 3225 | end |
| 3226 | if eq sl 3 |
| 3227 | if eq get bfi 17 0 |
| 3228 | exit 84 |
| 3229 | end |
| 3230 | ix_req2 3 v d |
| 3231 | ret |
| 3232 | end |
| 3233 | s8 = sub sl 8 |
| 3234 | l = div s8 24 |
| 3235 | r = rem s8 24 |
| 3236 | b = add 8 mul l 24 |
| 3237 | fl = get bfi 7 |
| 3238 | if and or eq r 5 eq r 6 eq and fl 8 0 |
| 3239 | exit 84 |
| 3240 | end |
| 3241 | if and eq r 8 eq and fl 66 0 |
| 3242 | exit 84 |
| 3243 | end |
| 3244 | bf_check_l_slot b r |
| 3245 | end |
| 3246 | |
| 3247 | fn bf_pw_ixob fd int n ulong fpos ulong to void |
| 3248 | p = ulong 0 |
| 3249 | while lt p n bound 1000000 |
| 3250 | w = pwrite fd ixob p sub n p long add fpos p |
| 3251 | if le w 0 |
| 3252 | exit 70 |
| 3253 | end |
| 3254 | p = add p ulong w |
| 3255 | end |
| 3256 | end |
| 3257 | |
| 3258 | fn bf_pw_uopw fd int n ulong fpos ulong to void |
| 3259 | p = ulong 0 |
| 3260 | while lt p n bound 1000000 |
| 3261 | w = pwrite fd uopw p sub n p long add fpos p |
| 3262 | if le w 0 |
| 3263 | exit 70 |
| 3264 | end |
| 3265 | p = add p ulong w |
| 3266 | end |
| 3267 | end |
| 3268 | |
| 3269 | fn bf_check_bf16_chunk m ulong to void |
| 3270 | for j ulong m bound IXBIG |
| 3271 | b2 = mul j 2 |
| 3272 | h = or ulong get uopw b2 shl ulong get uopw add b2 1 8 |
| 3273 | if eq and h 32640 32640 |
| 3274 | exit 86 |
| 3275 | end |
| 3276 | end |
| 3277 | end |
| 3278 | |
| 3279 | fn bf_put_u16 j ulong u ulong to void |
| 3280 | o = mul j 2 |
| 3281 | put ixob o uchar and u 255 |
| 3282 | put ixob add o 1 uchar and shr u 8 255 |
| 3283 | end |
| 3284 | |
| 3285 | fn bf_put_f32 j ulong v f64 to void |
| 3286 | b32 = ulong bitcast uint f32 v |
| 3287 | o = mul j 4 |
| 3288 | for k ulong 4 |
| 3289 | sh = mul k 8 |
| 3290 | put ixob add o k uchar and shr b32 sh 255 |
| 3291 | end |
| 3292 | end |
| 3293 | |
| 3294 | fn bf_conv_one j ulong v f64 md ulong to void |
| 3295 | if eq md 0 |
| 3296 | bf_put_u16 j ix_bf16 v |
| 3297 | ret |
| 3298 | end |
| 3299 | if eq md 3 |
| 3300 | bf_put_u16 j ix_bf16 mul v get ixf 0 |
| 3301 | ret |
| 3302 | end |
| 3303 | if eq md 1 |
| 3304 | bf_put_f32 j v |
| 3305 | ret |
| 3306 | end |
| 3307 | if eq md 2 |
| 3308 | bf_put_f32 j add v 1.0 |
| 3309 | ret |
| 3310 | end |
| 3311 | if ne v 0.0 |
| 3312 | exit 82 |
| 3313 | end |
| 3314 | end |
| 3315 | |
| 3316 | fn bf_conv_chunk m ulong dt ulong md ulong to void |
| 3317 | for j ulong m bound IXBIG |
| 3318 | v = ix_dec j dt |
| 3319 | if ix_bad v |
| 3320 | exit 86 |
| 3321 | end |
| 3322 | bf_conv_one j v md |
| 3323 | end |
| 3324 | end |
| 3325 | |
| 3326 | fn bf_pad_slot dst_off ulong nb ulong to void |
| 3327 | al = bf_al256 nb |
| 3328 | if eq al nb |
| 3329 | ret |
| 3330 | end |
| 3331 | pad = sub al nb |
| 3332 | for i ulong pad |
| 3333 | put ixob i 0 |
| 3334 | end |
| 3335 | bf_pw_ixob get ucfd 0 pad add dst_off nb |
| 3336 | end |
| 3337 | |
| 3338 | fn bf_chunk_lim ds ulong md ulong to ulong |
| 3339 | cn = div IXOB ds |
| 3340 | if eq md 4 |
| 3341 | ret cn |
| 3342 | end |
| 3343 | lim = div IXOB 2 |
| 3344 | if or eq md 1 eq md 2 |
| 3345 | lim = div IXOB 4 |
| 3346 | end |
| 3347 | if gt cn lim |
| 3348 | ret lim |
| 3349 | end |
| 3350 | ret cn |
| 3351 | end |
| 3352 | |
| 3353 | fn bf_stream_one dt ulong md ulong m ulong out_p ulong to ulong |
| 3354 | if and eq dt 2 eq md 0 |
| 3355 | bf_check_bf16_chunk m |
| 3356 | nb = mul m 2 |
| 3357 | bf_pw_uopw get ucfd 0 nb out_p |
| 3358 | ret add out_p nb |
| 3359 | end |
| 3360 | bf_conv_chunk m dt md |
| 3361 | if eq md 4 |
| 3362 | ret out_p |
| 3363 | end |
| 3364 | esz = ulong 2 |
| 3365 | if or eq md 1 eq md 2 |
| 3366 | esz = 4 |
| 3367 | end |
| 3368 | nb2 = mul m esz |
| 3369 | bf_pw_ixob get ucfd 0 nb2 out_p |
| 3370 | ret add out_p nb2 |
| 3371 | end |
| 3372 | |
| 3373 | fn bf_stream_slot sl ulong md ulong to void |
| 3374 | b = mul sl 8 |
| 3375 | dt = get ixt add b 1 |
| 3376 | ds = ix_dsz dt |
| 3377 | pos = add get ixs 2 get ixt add b 5 |
| 3378 | n = div sub get ixt add b 6 get ixt add b 5 ds |
| 3379 | cn = bf_chunk_lim ds md |
| 3380 | dst0 = add 256 get bfo mul sl 2 |
| 3381 | out_p = dst0 |
| 3382 | k = ulong 0 |
| 3383 | while lt k n bound IXBIG |
| 3384 | m = sub n k |
| 3385 | if gt m cn |
| 3386 | m = cn |
| 3387 | end |
| 3388 | ix_pread add pos mul k ds mul m ds |
| 3389 | out_p = bf_stream_one dt md m out_p |
| 3390 | k = add k m |
| 3391 | end |
| 3392 | if ne md 4 |
| 3393 | bf_pad_slot dst0 sub out_p dst0 |
| 3394 | end |
| 3395 | end |
| 3396 | |
| 3397 | fn bf_slot_mode sl ulong to ulong |
| 3398 | gem = get bfi 16 |
| 3399 | if eq sl 0 |
| 3400 | if ne gem 0 |
| 3401 | ret 3 |
| 3402 | end |
| 3403 | ret 0 |
| 3404 | end |
| 3405 | if eq sl 2 |
| 3406 | if ne gem 0 |
| 3407 | ret 2 |
| 3408 | end |
| 3409 | ret 1 |
| 3410 | end |
| 3411 | if eq sl 3 |
| 3412 | ret 0 |
| 3413 | end |
| 3414 | r = rem sub sl 8 24 |
| 3415 | if or eq r 0 or eq r 5 or eq r 6 eq r 7 |
| 3416 | if and ne gem 0 or eq r 0 eq r 7 |
| 3417 | ret 2 |
| 3418 | end |
| 3419 | ret 1 |
| 3420 | end |
| 3421 | if ge r 11 |
| 3422 | ret 4 |
| 3423 | end |
| 3424 | ret 0 |
| 3425 | end |
| 3426 | |
| 3427 | fn bf_proc_shard si ulong to void |
| 3428 | put ixs 0 0 |
| 3429 | put bfi 22 0 |
| 3430 | src = new uchar 983040 0 |
| 3431 | tape = new uint 524288 0 |
| 3432 | hn = bf_st_open_sh si |
| 3433 | ix_st_read src hn |
| 3434 | if lt js_init tape 983040 64 0 |
| 3435 | exit 83 |
| 3436 | end |
| 3437 | if le js_parse src tape hn 0 |
| 3438 | exit 83 |
| 3439 | end |
| 3440 | if ne js_type tape 0 jsobj |
| 3441 | exit 83 |
| 3442 | end |
| 3443 | nk = js_nkids tape 0 |
| 3444 | r = enlarge ixe mul add nk 1 2 |
| 3445 | if ne r 0 |
| 3446 | exit 70 |
| 3447 | end |
| 3448 | put ixs 13 nk |
| 3449 | k = js_first tape 0 |
| 3450 | while ne k jsnone bound 1000000 |
| 3451 | bf_st_member src tape k |
| 3452 | k = js_mnext tape k |
| 3453 | end |
| 3454 | ix_cover |
| 3455 | cnt = get bfi 22 |
| 3456 | for i ulong cnt bound IXBIG |
| 3457 | sl = get bfsl i |
| 3458 | bf_check_slot sl |
| 3459 | bf_stream_slot sl bf_slot_mode sl |
| 3460 | end |
| 3461 | c0 = fclose int get ixs 1 |
| 3462 | end |
| 3463 | |
| 3464 | fn bf_need to void |
| 3465 | fl = get bfi 7 |
| 3466 | if not ix_has 0 |
| 3467 | exit 84 |
| 3468 | end |
| 3469 | if ix_has 1 |
| 3470 | exit 84 |
| 3471 | end |
| 3472 | if not ix_has 2 |
| 3473 | exit 84 |
| 3474 | end |
| 3475 | if ne get bfi 17 0 |
| 3476 | if not ix_has 3 |
| 3477 | exit 84 |
| 3478 | end |
| 3479 | else |
| 3480 | if ix_has 3 |
| 3481 | exit 84 |
| 3482 | end |
| 3483 | end |
| 3484 | for l ulong get bfi 6 bound IXBIG |
| 3485 | b = add 8 mul l 24 |
| 3486 | for r ulong 5 |
| 3487 | if not ix_has add b r |
| 3488 | exit 84 |
| 3489 | end |
| 3490 | end |
| 3491 | if ne and fl 8 0 |
| 3492 | if or not ix_has add b 5 not ix_has add b 6 |
| 3493 | exit 84 |
| 3494 | end |
| 3495 | else |
| 3496 | if or ix_has add b 5 ix_has add b 6 |
| 3497 | exit 84 |
| 3498 | end |
| 3499 | end |
| 3500 | if not ix_has add b 7 |
| 3501 | exit 84 |
| 3502 | end |
| 3503 | if ne and fl 66 0 |
| 3504 | if not ix_has add b 8 |
| 3505 | exit 84 |
| 3506 | end |
| 3507 | else |
| 3508 | if ix_has add b 8 |
| 3509 | exit 84 |
| 3510 | end |
| 3511 | end |
| 3512 | if or not ix_has add b 9 not ix_has add b 10 |
| 3513 | exit 84 |
| 3514 | end |
| 3515 | end |
| 3516 | end |
| 3517 | |
| 3518 | fn bf_fnv_ixob n ulong to ulong |
| 3519 | h = ulong 14695981039346656037 |
| 3520 | for i ulong n |
| 3521 | h = mul xor h ulong get ixob i 1099511628211 |
| 3522 | end |
| 3523 | ret h |
| 3524 | end |
| 3525 | |
| 3526 | fn bf_fnv_words h ulong nw ulong to ulong |
| 3527 | x = h |
| 3528 | for i ulong nw bound IXBIG |
| 3529 | b = mul i 8 |
| 3530 | w = ulong 0 |
| 3531 | for k ulong 8 |
| 3532 | w = or w shl ulong get ixob add b k mul k 8 |
| 3533 | end |
| 3534 | x = mul xor x w 1099511628211 |
| 3535 | end |
| 3536 | ret x |
| 3537 | end |
| 3538 | |
| 3539 | fn bf_hash_fd fd int pay_bytes ulong to ulong |
| 3540 | if ne rem pay_bytes 8 0 |
| 3541 | exit 60 |
| 3542 | end |
| 3543 | h = ulong 14695981039346656037 |
| 3544 | pos = ulong 256 |
| 3545 | remb = pay_bytes |
| 3546 | while gt remb 0 bound IXBIG |
| 3547 | cn = remb |
| 3548 | if gt cn IXOB |
| 3549 | cn = IXOB |
| 3550 | end |
| 3551 | got = ulong 0 |
| 3552 | while lt got cn bound 1000000 |
| 3553 | r = pread fd ixob got sub cn got long add pos got |
| 3554 | if le r 0 |
| 3555 | exit 70 |
| 3556 | end |
| 3557 | got = add got ulong r |
| 3558 | end |
| 3559 | h = bf_fnv_words h div cn 8 |
| 3560 | pos = add pos cn |
| 3561 | remb = sub remb cn |
| 3562 | end |
| 3563 | ret h |
| 3564 | end |
| 3565 | |
| 3566 | fn bf_put8 o ulong v ulong to void |
| 3567 | for k ulong 8 |
| 3568 | put ixob add o k uchar and shr v mul k 8 255 |
| 3569 | end |
| 3570 | end |
| 3571 | |
| 3572 | fn bf_get8 o ulong to ulong |
| 3573 | v = ulong 0 |
| 3574 | for k ulong 8 |
| 3575 | v = or v shl ulong get ixob add o k mul k 8 |
| 3576 | end |
| 3577 | ret v |
| 3578 | end |
| 3579 | |
| 3580 | fn bf_write_hdr wfnv ulong to void |
| 3581 | for i ulong 256 |
| 3582 | put ixob i 0 |
| 3583 | end |
| 3584 | bf_put8 0 OLLMBF01_MAG |
| 3585 | bf_put8 8 1 |
| 3586 | bf_put8 16 get bfi 0 |
| 3587 | bf_put8 24 get bfi 1 |
| 3588 | bf_put8 32 get bfi 2 |
| 3589 | bf_put8 40 get bfi 3 |
| 3590 | bf_put8 48 get bfi 4 |
| 3591 | bf_put8 56 get bfi 5 |
| 3592 | bf_put8 64 get bfi 6 |
| 3593 | bf_put8 72 get bfi 7 |
| 3594 | bf_put8 80 get bfi 8 |
| 3595 | bf_put8 88 get bfi 9 |
| 3596 | bf_put8 96 get bfi 10 |
| 3597 | bf_put8 104 get bfi 11 |
| 3598 | bf_put8 112 get bfi 12 |
| 3599 | bf_put8 120 wfnv |
| 3600 | th = bf_fnv_ixob 128 |
| 3601 | put bfi 19 th |
| 3602 | bf_put8 128 th |
| 3603 | hf = bf_fnv_ixob 248 |
| 3604 | put bfi 20 hf |
| 3605 | bf_put8 248 hf |
| 3606 | end |
| 3607 | |
| 3608 | fn bf_puthex v ulong to void |
| 3609 | for i ulong 16 |
| 3610 | h = and shr v mul sub 15 i 4 15 |
| 3611 | if lt h 10 |
| 3612 | uputc add h 48 |
| 3613 | else |
| 3614 | uputc add h 87 |
| 3615 | end |
| 3616 | end |
| 3617 | end |
| 3618 | |
| 3619 | fn bf_print_meta tag ulong to void |
| 3620 | if eq tag 73 |
| 3621 | uputc 73 |
| 3622 | end |
| 3623 | uputc 66 |
| 3624 | uputc 70 |
| 3625 | uputc 49 |
| 3626 | uputc 32 |
| 3627 | uputu get bfi 0 |
| 3628 | uputc 32 |
| 3629 | uputu get bfi 1 |
| 3630 | uputc 32 |
| 3631 | uputu get bfi 2 |
| 3632 | uputc 32 |
| 3633 | uputu get bfi 3 |
| 3634 | uputc 32 |
| 3635 | uputu get bfi 4 |
| 3636 | uputc 32 |
| 3637 | uputu get bfi 5 |
| 3638 | uputc 32 |
| 3639 | uputu get bfi 6 |
| 3640 | uputc 32 |
| 3641 | uputu get bfi 11 |
| 3642 | uputc 32 |
| 3643 | uputu get bfi 7 |
| 3644 | uputc 32 |
| 3645 | bf_puthex get bfi 19 |
| 3646 | uputc 32 |
| 3647 | uputu get bfi 12 |
| 3648 | uputc 10 |
| 3649 | uflush |
| 3650 | end |
| 3651 | |
| 3652 | fn ix_cmd_impbf to void |
| 3653 | if ne ulong argcnt 4 |
| 3654 | exit 2 |
| 3655 | end |
| 3656 | bf_set_dir 2 |
| 3657 | bf_cfg_dir |
| 3658 | bf_cfg_check |
| 3659 | bf_plan |
| 3660 | bf_shard_list |
| 3661 | ucopen_tmp 3 |
| 3662 | put ixf 0 fsqrt f64 get bfi 1 |
| 3663 | ns = get bfi 15 |
| 3664 | for s ulong ns |
| 3665 | bf_proc_shard s |
| 3666 | end |
| 3667 | bf_need |
| 3668 | fd0 = get ucfd 0 |
| 3669 | if ne fsync fd0 0 |
| 3670 | exit 70 |
| 3671 | end |
| 3672 | if ne fclose fd0 0 |
| 3673 | exit 70 |
| 3674 | end |
| 3675 | pl = uargp 3 |
| 3676 | fd_r = int fopen upath 0 add pl 4 0 0 |
| 3677 | if lt fd_r 0 |
| 3678 | exit 70 |
| 3679 | end |
| 3680 | wfnv = bf_hash_fd fd_r get bfi 12 |
| 3681 | put bfi 18 wfnv |
| 3682 | c0 = fclose fd_r |
| 3683 | bf_write_hdr wfnv |
| 3684 | fd_w = int fopen upath 0 add pl 4 2 0 |
| 3685 | if lt fd_w 0 |
| 3686 | exit 70 |
| 3687 | end |
| 3688 | bf_pw_ixob fd_w 256 0 |
| 3689 | if ne fsync fd_w 0 |
| 3690 | exit 70 |
| 3691 | end |
| 3692 | if ne fclose fd_w 0 |
| 3693 | exit 70 |
| 3694 | end |
| 3695 | ucrename pl |
| 3696 | bf_print_meta 73 |
| 3697 | end |
| 3698 | |
| 3699 | fn ix_cmd_infobf to void |
| 3700 | if ne ulong argcnt 3 |
| 3701 | exit 2 |
| 3702 | end |
| 3703 | sz = uofsz 2 |
| 3704 | if lt sz 256 |
| 3705 | exit 60 |
| 3706 | end |
| 3707 | pl = uargp 2 |
| 3708 | fd = int fopen uarg 0 pl 0 0 |
| 3709 | if lt fd 0 |
| 3710 | exit 70 |
| 3711 | end |
| 3712 | if ne pread fd ixob 0 256 0 256 |
| 3713 | c0 = fclose fd |
| 3714 | exit 60 |
| 3715 | end |
| 3716 | if ne bf_get8 0 OLLMBF01_MAG |
| 3717 | c1 = fclose fd |
| 3718 | exit 60 |
| 3719 | end |
| 3720 | if ne bf_get8 8 1 |
| 3721 | c2 = fclose fd |
| 3722 | exit 60 |
| 3723 | end |
| 3724 | if ne bf_fnv_ixob 248 bf_get8 248 |
| 3725 | c3 = fclose fd |
| 3726 | exit 61 |
| 3727 | end |
| 3728 | th = bf_get8 128 |
| 3729 | if ne bf_fnv_ixob 128 th |
| 3730 | c4 = fclose fd |
| 3731 | exit 61 |
| 3732 | end |
| 3733 | pb = bf_get8 112 |
| 3734 | if ne sub sz 256 pb |
| 3735 | c5 = fclose fd |
| 3736 | exit 60 |
| 3737 | end |
| 3738 | wfnv = bf_get8 120 |
| 3739 | put bfi 0 bf_get8 16 |
| 3740 | put bfi 1 bf_get8 24 |
| 3741 | put bfi 2 bf_get8 32 |
| 3742 | put bfi 3 bf_get8 40 |
| 3743 | put bfi 4 bf_get8 48 |
| 3744 | put bfi 5 bf_get8 56 |
| 3745 | put bfi 6 bf_get8 64 |
| 3746 | put bfi 7 bf_get8 72 |
| 3747 | put bfi 11 bf_get8 104 |
| 3748 | put bfi 12 pb |
| 3749 | put bfi 19 th |
| 3750 | if ne bf_hash_fd fd pb wfnv |
| 3751 | c6 = fclose fd |
| 3752 | exit 61 |
| 3753 | end |
| 3754 | c7 = fclose fd |
| 3755 | bf_print_meta 66 |
| 3756 | end |
| 3757 | |
| 3758 | fn main to int |
| 3759 | if lt ulong argcnt 2 |
| 3760 | exit 2 |
| 3761 | end |
| 3762 | if ix_arg_eq 1 ix_c_imp |
| 3763 | ix_cmd_import |
| 3764 | ret 0 |
| 3765 | end |
| 3766 | if ix_arg_eq 1 ix_c_impbf |
| 3767 | ix_cmd_impbf |
| 3768 | ret 0 |
| 3769 | end |
| 3770 | if ix_arg_eq 1 ix_c_infobf |
| 3771 | ix_cmd_infobf |
| 3772 | ret 0 |
| 3773 | end |
| 3774 | if ix_arg_eq 1 ix_c_exh |
| 3775 | ix_cmd_exh |
| 3776 | ret 0 |
| 3777 | end |
| 3778 | if ix_arg_eq 1 ix_c_exg |
| 3779 | ix_cmd_exg |
| 3780 | ret 0 |
| 3781 | end |
| 3782 | if ix_arg_eq 1 ix_c_upg |
| 3783 | ix_cmd_upg |
| 3784 | ret 0 |
| 3785 | end |
| 3786 | exit 2 |
| 3787 | end |