code wiki / (root) / nx_metabolism.nx

nx_metabolism.nx

buildroot/runtime/nx_metabolism.nx

7010 B176 linesdepth 2pulls 2 transitivereach 19 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_metabolism.nx -- per-call-site profiler + tier promotion. Biological analogue: cells consume more glucose at hot signaling pathways and grow mitochondria to compensate. Nishi metabolism tracks (hit_count, total_cycles, ram_peak) per call site and suggests a target tier for the existing nxc2 codegen layer to emit: interpreted bytecode -> AOT native -> SIMD-vectorized native -> GPU offload -> custom-silicon block. THIS IS THE OPTIMIZATION DECISION LAYER. nxc2 already has thirteen architecture backends compiled in (aarch64.c, armv7a.c, cortex_m.c, gcn.c, loongarch64.c, metal.c, mips64.c, ppc64le.c, ptx.c, riscv.c, riscv32.c, s390x.c, wasm.c, x86_64.c). What was missing is the NishiLang-side decision primitive that says WHICH backend to pick per call site. Metabolism is that primitive. Composes: nx_tier -- NX_TIER_MCU..NX_TIER_HPC target enum nx_budget -- ram_peak per site informs ceiling tuning nx_homeostasis -- repeated hot-site overshoot triggers tropism migration to higher tier nx_attention_class -- foreground sites get higher promotion bias (frame-budget pressure outranks build pressure) V1 ships a flat hash table keyed on site_id. Adaptive thresholds per tier; defaults derived from heuristics rather than learned. Gap list (V1 honest perf verdict): - no online learning (thresholds are static constants) - no decay (a one-time spike at startup never ages out) - no cross-site cost-amortization (each site decides alone) - no silicon target yet (NX_TIER_SOVEREIGN_CHIP returns same as HPC) genealogy_id: nishi_cardinal_2026-05-17_pathway_tropism + cardinal-21_resource_awareness lineage_id: substrate_metabolism_v1 nx_safety_envelope: intended_use: "Per-call-site profiling and target-tier promotion suggestions for the codegen layer" sil_target: SIL1

dependencies 2 imports · 8 importers

nx_syscalls.nx nx_tier.nx nx_metabolism.nx nx_ecosystem_compose_test.nx nx_homeostasis.nx nx_homeostasis_test.nx nx_metabolism_test.nx nx_pathway_test.nx nx_ribosome.nx nx_ribosome_test.nx nx_substrate_compose_test.nx

imports: nx_syscalls.nxnx_tier.nx

imported by: nx_ecosystem_compose_test.nxnx_homeostasis.nxnx_homeostasis_test.nxnx_metabolism_test.nxnx_pathway_test.nxnx_ribosome.nxnx_ribosome_test.nxnx_substrate_compose_test.nx

structs

58struct NxCallSite
69struct NxMetabolism

consts

49const NX_METAB_OK: nx_int = 0
50const NX_METAB_ERR_FULL: nx_int = 1 // site table at capacity
51const NX_METAB_ERR_BAD_SITE: nx_int = 2
75const NX_METAB_DEFAULT_CAPACITY: nx_size = 256
81const NX_METAB_PROMOTE_TO_NATIVE_AT: nx_size = 64
82const NX_METAB_PROMOTE_TO_VECTOR_AT: nx_size = 4096
83const NX_METAB_PROMOTE_TO_GPU_AT: nx_size = 65536
84const NX_METAB_PROMOTE_TO_SILICON_AT: nx_size = 1048576

functions

88func nx_metab_new(capacity: nx_size) -> *NxMetabolism
called by 4: mainmainmainmain calls 1: sys_mmap
103func _metab_lookup(m: *NxMetabolism, site_id: nx_int) -> *NxCallSite
119func nx_metab_record(m: *NxMetabolism,
called by 4: mainmainmainmain calls 1: _metab_lookup
150func nx_metab_suggest_target(m: *NxMetabolism, site_id: nx_int) -> nx_int
163func nx_metab_avg_cycles(m: *NxMetabolism, site_id: nx_int) -> nx_size
called by 2: mainmain calls 1: _metab_lookup
172func nx_metab_hit_count(m: *NxMetabolism, site_id: nx_int) -> nx_size
called by 2: mainmain calls 1: _metab_lookup