feat(v4.0.0): nodes that talk -- ports, a node born empty, and the fabric
MESH.md step 1, in the engine, which knows nothing of StarForth or of any kernel. - node: V4_PORTS ports (8), a build parameter; "any port" and the port the last such read came from; a read blocks until the neighbour writes, as a write blocks until the neighbour reads; v4_node_born: empty, P at "any port" - exec: a fetch from a port -- @ @b @+ @p, or of an instruction word when P is a port -- waits for a word; a node executes what arrives at a port without advancing P; a blocked node goes on from the slot it stopped at - fabric: the nodes there are and the table of how their ports are wired, both changed while the nodes run; devices on a port; asleep and awake; a step is every unblocked node executing one instruction word, then every write with a reader waiting being handed over - DECOMPOSITION.md section 6: four named ports withdrawn for V4_PORTS numbered ones and wiring as data, as ruled Verified: tests/test_fabric.c, 53 checks at both widths: two nodes exchange words; an empty node is filled through its port by a device, and by another node, and runs what it was sent; a word is passed on by a node in between; a waiting node executes nothing; the wiring is changed while they run; a node is put to sleep, woken and removed while looping; a node is born while others run; the fabric is given more room. make -C v4 test and make -C v4 sanitize pass. The single-node products are unchanged: hosted-check on three ISAs, and clean qemu with STARFORTH_V4=1 on amd64, aarch64 and riscv64 with lines typed at each prompt (logs/20261006-074907, -075150, -075532). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
2c5427d9c1
commit
9af442f793
+68
-19
@@ -36,6 +36,14 @@
|
||||
#include "v4/stack.h"
|
||||
|
||||
/* Words of node memory. Overridable at build time. */
|
||||
/* How many ports a node has. A build parameter, as the cell width and the
|
||||
* node's memory are: the geometry the nodes are wired in is data, and a node
|
||||
* has as many ports as the geometry in use needs (docs/v4.0.0/MESH.md 4.1). */
|
||||
#ifndef V4_PORTS
|
||||
#define V4_PORTS 8u
|
||||
#endif
|
||||
#define V4_PORT_ANY V4_PORTS /* not a port: "whichever port has a neighbour writing" */
|
||||
|
||||
#ifndef V4_NODE_WORDS
|
||||
#define V4_NODE_WORDS 1024u
|
||||
#endif
|
||||
@@ -91,9 +99,16 @@ typedef struct {
|
||||
/* The port (DECOMPOSITION.md section 6): a write to it blocks the node
|
||||
* until its neighbour has taken what was written. See
|
||||
* v4_node_port_attach below. */
|
||||
v4_cell port; /* its word address, or -1: no port */
|
||||
int asking; /* non-zero: blocked, having written `request` */
|
||||
v4_cell port; /* word address of port 0, or -1: no ports */
|
||||
int asking; /* non-zero: blocked, having written `request` to port `ask_port` */
|
||||
v4_cell request; /* what it wrote */
|
||||
unsigned ask_port; /* to which port */
|
||||
int reading; /* non-zero: blocked, wanting a word from port `read_port` */
|
||||
unsigned read_port; /* a port, or V4_PORT_ANY */
|
||||
int given; /* non-zero: `given_value` has come from port `given_port` and not been taken yet */
|
||||
v4_cell given_value;
|
||||
unsigned given_port;
|
||||
unsigned last_from; /* the port the last read from "any" took its word from */
|
||||
|
||||
/* DSTACK-DEPTH and RSTACK-DEPTH (D-16). See v4_node_stack_regs_attach. */
|
||||
v4_cell dstack_reg; /* its word address, or -1 */
|
||||
@@ -156,28 +171,62 @@ void v4_node_store(v4_node *n, v4_cell addr, v4_cell value);
|
||||
* Passing -1 detaches. The address is the caller's choice. */
|
||||
void v4_node_console_attach(v4_node *n, v4_cell addr);
|
||||
|
||||
/* THE PORT. A node reaches its neighbour through a port, and a port is an
|
||||
* address (DECOMPOSITION.md section 6): "a write blocks until the neighbour
|
||||
* reads. This is the GA144 model. No instruction is added."
|
||||
/* THE PORTS. A node reaches its neighbours through its ports, and a port is
|
||||
* an address (DECOMPOSITION.md section 6): "a read from a port blocks until
|
||||
* the neighbour writes; a write blocks until the neighbour reads. This is
|
||||
* the GA144 model. No instruction is added." docs/v4.0.0/MESH.md 4.1.
|
||||
*
|
||||
* After v4_node_port_attach(n, addr), a store to word address `addr` does
|
||||
* not write memory: the node keeps the value in n->request, sets n->asking
|
||||
* and is blocked. A blocked node executes nothing -- v4_exec_step_word
|
||||
* returns 0 and changes nothing -- until its neighbour calls
|
||||
* v4_node_port_served(n). It then goes on from the opcode after the store,
|
||||
* in the same instruction word if there are any left.
|
||||
* After v4_node_port_attach(n, base) the node's V4_PORTS ports are the word
|
||||
* addresses base .. base + V4_PORTS - 1. Two more follow them:
|
||||
* base + V4_PORTS "any port": a read here takes from whichever port
|
||||
* has a neighbour writing
|
||||
* base + V4_PORTS + 1 which port the last read from "any" came from
|
||||
* (read only)
|
||||
* None of them is memory while the ports are attached.
|
||||
*
|
||||
* This is how a node asks its kernel for something (docs/v4.0.0/ENGINE.md
|
||||
* 3.3): the neighbour on the port is the kernel, what is written is the
|
||||
* number of the request, and the arguments and results are on the node's
|
||||
* data stack, which the kernel may use while the node is blocked. Only the
|
||||
* write is here. Nothing reads from a port yet, and a fetch from the
|
||||
* address is a fetch from memory.
|
||||
* A WRITE. A store to a port does not write memory: the node keeps the
|
||||
* value in n->request and the port in n->ask_port, sets n->asking and is
|
||||
* blocked. When its neighbour has taken the value -- v4_node_port_served --
|
||||
* it goes on from the opcode after the store, in the same instruction word
|
||||
* if there are any left.
|
||||
*
|
||||
* A node has no port until one is attached: v4_node_reset detaches it. */
|
||||
void v4_node_port_attach(v4_node *n, v4_cell addr);
|
||||
* A READ. A fetch from a port -- @ @b @+, the literal fetch @p, or the
|
||||
* fetch of an instruction word when P is a port -- does not happen until
|
||||
* there is a word to fetch. The node sets n->reading and n->read_port and
|
||||
* is blocked, the opcode not yet executed. When its neighbour writes --
|
||||
* v4_node_port_give -- the fetch is made, and it gets that word. When P is
|
||||
* a port it is not advanced by a fetch: the node goes on executing what
|
||||
* arrives there, as an F18 node does.
|
||||
*
|
||||
* A blocked node executes nothing: v4_exec_step_word returns 0 and changes
|
||||
* nothing. Who the neighbour is, and whether there is one, is not the
|
||||
* node's to know (fabric.h). A store to "any port" or to the "which port"
|
||||
* address is an address fault.
|
||||
*
|
||||
* A node has no ports until they are attached: v4_node_reset detaches them. */
|
||||
void v4_node_port_attach(v4_node *n, v4_cell base);
|
||||
|
||||
/* The neighbour has taken what the node wrote. */
|
||||
void v4_node_port_served(v4_node *n);
|
||||
|
||||
/* The neighbour on `port` writes `value`: the node, blocked reading that
|
||||
* port or "any", is unblocked and will fetch it. */
|
||||
void v4_node_port_give(v4_node *n, unsigned port, v4_cell value);
|
||||
|
||||
/* Which port `addr` is: 0 .. V4_PORTS - 1, V4_PORT_ANY, V4_PORTS + 1 for the
|
||||
* "which port" address, or -1 if it is none of them. */
|
||||
int v4_node_port_index(const v4_node *n, v4_cell addr);
|
||||
|
||||
/* 1 if a fetch from `addr` can be made now: it is not a port, or the word
|
||||
* has been given. 0 if it is a port with nothing given: the node is then
|
||||
* blocked reading it, and the fetch must not be made. */
|
||||
int v4_node_read_ready(v4_node *n, v4_cell addr);
|
||||
|
||||
/* A NODE NEWLY BORN (docs/v4.0.0/MESH.md 4.2). Reset, its ports attached at
|
||||
* `base`, and P at "any port": it is blocked reading its ports, and will
|
||||
* execute what a neighbour sends it. Nothing else is in it. */
|
||||
void v4_node_born(v4_node *n, v4_cell base);
|
||||
|
||||
/* CONSOLE-RX and CONSOLE-STATUS, the console's receive side, on the
|
||||
* single-node model.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user