OR-1 dataflow CPU sketch
at main 52 lines 2.0 kB view raw
1; OR1 Monitor Demo Program 2; 3; Computes (3 + 7) on PE0, writes the result (10) to SM cell 0, 4; then PE1 reads it back and checks if it equals 10 using SWEQ. 5; 6; This exercises: 7; - Seed token injection (const nodes) 8; - Dyadic matching (add waits for both operands) 9; - Cross-PE token routing (PE0 -> PE1) 10; - SM write and read with I-structure semantics 11; - Comparison / switch routing (sweq) 12; - Multiple PEs active across different ticks 13; 14; Expected execution flow: 15; t=0: const seeds arrive at c_three, c_seven, c_expected, c_read_trigger 16; t=0: c_three and c_seven match at adder -> executes ADD(3,7) = 10 17; t=0: adder emits result (10) to writer on PE0 18; t=0: writer is monadic (const addr), emits WRITE(cell=0, data=10) to SM0 19; t=0: SM0 writes cell 0 = 10 20; t=0: c_read_trigger fires reader on PE1 -> READ(cell=0) 21; t=0: SM0 satisfies read (cell already FULL) -> returns 10 to checker on PE1 22; t=0: c_expected (10) and SM read result (10) match at checker -> SWEQ 23; t=0: checker compares: 10 == 10 -> bool_out=true 24; 25; In the monitor you should see: 26; - PE0 cluster: c_three, c_seven, adder, writer all light up 27; - PE1 cluster: c_expected, c_read_trigger, reader, checker light up 28; - SM cell 0 transitions from EMPTY to FULL 29; - Token flow edges animate across PE boundary 30; - Half-match visible on adder/checker before second operand arrives 31 32@system pe=2, sm=1 33 34; PE0: compute 3 + 7 and write result to SM 35&c_three|pe0 <| const, 3 36&c_seven|pe0 <| const, 7 37&adder|pe0 <| add 38&writer|pe0 <| write, 0 39 40&c_three|pe0 |> &adder|pe0:L 41&c_seven|pe0 |> &adder|pe0:R 42&adder|pe0 |> &writer|pe0:L 43 44; PE1: read SM cell 0 and compare against expected value 45&c_expected|pe1 <| const, 10 46&c_read_trigger|pe1 <| const, 0 47&reader|pe1 <| read, 0 48&checker|pe1 <| sweq 49 50&c_read_trigger|pe1 |> &reader|pe1:L 51&reader|pe1 |> &checker|pe1:L 52&c_expected|pe1 |> &checker|pe1:R