Commit 08d4e87
Sessions F + G + H: divergent bands, harmony intrinsic, cross-fn calls
Three sessions shipped together because they share the dual-band
intrinsics surface and the cross-fn-call refactor in jit_module.
== Session F: phi_shadow(x) — divergent β
Tree-walk: pass-through (returns x unchanged). Tree-walk has no
β to manipulate; the value stays α-only.
Dual-band JIT: intercepted as intrinsic. Replaces the β lane of
the value's <2 x i64> carrier with `(phi_fold(α) * 1000) as i64`.
Implemented as a chain of LLVM ops in the lowerer:
sitofp i64 -> f64
fmul double, PHI
call @llvm.floor.f64
fsub double → fractional part [0, 1)
fmul double, 1000.0
fptosi double -> i64
insertelement <2 x i64> at lane 1
After phi_shadow, harmony() of the value diverges from 1000
(matched-band initial condition). Bands maintain their own
arithmetic paths through subsequent ops; they only re-converge
on another phi_shadow call.
5 tests: pass-through parity, IR-shape snapshot, α preservation
through subsequent arithmetic, end-to-end via Interpreter
dispatch hook.
== Session G: harmony(x) — runtime harmony reading
Tree-walk: returns 1000 (perfect). With no β, harmony is trivial.
Dual-band JIT: intercepted as intrinsic. Extracts α and β from
the value's vector and calls a new extern Rust helper:
#[no_mangle]
pub extern "C" fn omc_harmony(alpha: i64, beta: i64) -> i64 {
let h = HBit::harmony(alpha, beta);
(h * 1000.0).round() as i64
}
The fn is pre-declared in the LLVM module and bound via
add_global_mapping in JitContext::new. JIT'd code calls it at
~native speed.
3 tests:
- unshadowed harmony returns 1000 (matched bands)
- shadowed harmony < 1000 (bands diverge after phi_shadow)
- JIT'd OMC code branches on harmony to skip work — the
cost-cut primitive that @predict needs
The third test is architecturally significant: it's the first
JIT'd OMC fn that decides at runtime whether to do expensive
work based on harmony of its input. With harmony >= 500, the
fn returns the cheap path; otherwise the expensive path runs.
This is "@predict cuts cost" working in shipped code.
== Session H: cross-fn calls in dual-band JIT
Sessions C-G's lowerer rejected any Op::Call whose target name
wasn't the current fn (only self-recursion). jit_module is now
three-phase:
1. DECLARE every user fn in the module up-front (signature
only, empty body) so cross-fn references can be resolved.
2. LOWER each fn's body using prepare_existing instead of
prepare (which previously double-declared and would clash).
3. EXTRACT raw fn pointers via typed get_function.
Op::Call now resolves to:
- self.function for self-recursion (unchanged path)
- module.get_function("<name>_hbit") for cross-fn calls
- error if target not declared (caller fn gets erased; tree-
walk handles it)
A failed body-lowering replaces the partial fn with a single
"return 0" entry block instead of erasing it entirely — keeps
the symbol table valid for any other fn that referenced it.
4 tests:
- simple cross-fn call (caller calls helper)
- dispatch fn calling one of two helpers based on a comparison
- cross-fn call to a recursive fn (factorial called from
double_fact, factorial(10) = 3.6M, 2x = 7.26M)
- cascade fail: caller calling unsupported fn → both skipped,
pure fn nearby still JIT's normally
== Workspace state
Codegen: 31 tests pass (8 scalar + 5 dual-band parity + 1 IR
snapshot + 5 dispatch + 5 phi_shadow + 3 harmony + 4 cross-fn).
omnimcode-core: 149 unit tests pass.
OMC harmonic-lib: 18/18 pass.
Smoke test: tree-walk and JIT both produce correct output.
Bench (Session E): JIT 277x faster than tree-walk on
factorial(12), 206x on sum_to(100). Numbers held within noise.
== What's left for "@hbit cuts times/cost" parity with SL claims
The Sovereign Lattice hbit_full_demo claimed up to 80,000x
with @hbit + @Harmony + @predict + @avx512 + @unsafe. After
Sessions A-H we have:
- @hbit (dual-band) ✅
- @Harmony (harmony() builtin reads divergent bands) ✅
- @predict (harmony-gated branch elision) ✅
Still missing:
- @avx512 (<8 x i64> widening; needs array-processing OMC
fns to actually have work for the wider lanes — deferred
until codegen supports OMC arrays)
- @unsafe (fast-math, unroll; LLVM optimizer already runs
aggressive loop opts; explicit @unsafe pragma plumbing
is straightforward when there's a use case)
The 277x measured in Session E was @hbit alone. Adding @Harmony
and @predict to that bench would show the cost-cut on
high-harmony inputs (cheap branch wins) vs low-harmony inputs
(expensive branch runs). That bench is the natural follow-up.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 3ce40cc commit 08d4e87
6 files changed
Lines changed: 818 additions & 27 deletions
File tree
- omnimcode-codegen
- src
- tests
- omnimcode-core/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
47 | 51 | | |
48 | 52 | | |
49 | 53 | | |
| |||
86 | 90 | | |
87 | 91 | | |
88 | 92 | | |
| 93 | + | |
89 | 94 | | |
90 | 95 | | |
91 | 96 | | |
| |||
96 | 101 | | |
97 | 102 | | |
98 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
99 | 144 | | |
100 | 145 | | |
101 | 146 | | |
| |||
418 | 463 | | |
419 | 464 | | |
420 | 465 | | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
426 | 476 | | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
431 | 511 | | |
432 | 512 | | |
433 | 513 | | |
| |||
452 | 532 | | |
453 | 533 | | |
454 | 534 | | |
455 | | - | |
| 535 | + | |
456 | 536 | | |
457 | 537 | | |
458 | 538 | | |
| |||
484 | 564 | | |
485 | 565 | | |
486 | 566 | | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
487 | 702 | | |
488 | 703 | | |
489 | 704 | | |
| |||
0 commit comments