code wiki / _hdl_build / nx_layered_backlog.nx

nx_layered_backlog.nx source

↩ module page · 53 lines · 2805 B

1// nx_layered_backlog.nx -- next moves must NOT be random (operator). The work is a LAYERED stack: 2// L8 = hardware / machine code (the base), up to L0 = the frontier output (the goal). A desired L0 3// output PUSHES its required work DOWN to L8 (decompose top-down); the team then BUILDS BACK UP 4// L8->L0 (execute bottom-up). The next move is therefore DETERMINISTIC, never ad-hoc: 5// - the BUILD FRONTIER = the deepest still-incomplete layer (highest layer number with a TODO). 6// - an item is BUILDABLE only when every layer BELOW it (more foundational, higher number) is 7// complete -- you cannot skip layers (no building L3 on an unfinished L5). 8// - all buildable items AT the frontier have no inter-layer dependency, so they run in PARALLEL. 9// So "what's next" is always: the parallel batch of buildable items at the deepest unfinished layer. 10// RACI: the CONDUCTOR reads this to dispatch; the RESEARCHER/CRITIC feed L0 desires that push the 11// backlog down; BUILDER/ENGINEER execute the frontier batch. license_tier: ORIGINAL 12 13import "nx_syscalls.nx" 14 15const BL_BASE_LAYER: i64 = 8 // machine code / hardware 16const BL_FRONTIER_LAYER: i64 = 0 // the desired output 17 18// every item at layer L is done? (vacuously true if no items at L) 19func bl_layer_done(n: i64, layer: *i64, done: *i64, L: i64) -> i64 { 20 var i: i64 = 0 21 while i < n { if layer[i] == L { if done[i] == 0 { return 0 } } i = i + 1 } 22 return 1 23} 24 25// the foundation under layer L (every more-foundational layer L+1..8) is complete? 26func bl_lower_complete(n: i64, layer: *i64, done: *i64, L: i64) -> i64 { 27 var k: i64 = L + 1 28 while k <= BL_BASE_LAYER { if bl_layer_done(n, layer, done, k) == 0 { return 0 } k = k + 1 } 29 return 1 30} 31 32// item i is buildable iff it is TODO and its foundation is complete (cannot skip layers). 33func bl_buildable(n: i64, layer: *i64, done: *i64, i: i64) -> i64 { 34 if done[i] == 1 { return 0 } 35 return bl_lower_complete(n, layer, done, layer[i]) 36} 37 38// the BUILD FRONTIER: the deepest (highest-numbered) layer that still has a TODO item; -1 if all done. 39func bl_frontier(n: i64, layer: *i64, done: *i64) -> i64 { 40 var best: i64 = 0 - 1; var i: i64 = 0 41 while i < n { if done[i] == 0 { if layer[i] > best { best = layer[i] } } i = i + 1 } 42 return best 43} 44 45// the PARALLEL BATCH of next moves: the buildable items at the frontier. Writes their indices to 46// out[], returns the count. This is the deterministic answer to "what do we build next". 47func bl_parallel_batch(n: i64, layer: *i64, done: *i64, out: *i64) -> i64 { 48 let f: i64 = bl_frontier(n, layer, done) 49 if f < 0 { return 0 } 50 var c: i64 = 0; var i: i64 = 0 51 while i < n { if layer[i] == f { if bl_buildable(n, layer, done, i) == 1 { out[c] = i; c = c + 1 } } i = i + 1 } 52 return c 53}