aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2025-08-09 17:35:26 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2025-08-09 17:35:26 +0300
commit489beadf61d05f40dd4ac40e4e5290502f7ad078 (patch)
tree58241d94c3376aae6b081c6fe16288aa0f4d8593 /src
parent1853f5d6594bc371e4d8e631c24acd011a620915 (diff)
downloadgran-489beadf61d05f40dd4ac40e4e5290502f7ad078.tar.gz
gran-489beadf61d05f40dd4ac40e4e5290502f7ad078.zip
format
Diffstat (limited to 'src')
-rw-r--r--src/bfly/fat_bfly.c33
-rw-r--r--src/bus/simple_bus.c3
-rw-r--r--src/common.c4
-rw-r--r--src/cpu/riscv/simple_riscv64.c44
-rw-r--r--src/ideal_noc.c14
-rw-r--r--src/mem/ideal_alloc.c12
-rw-r--r--src/mem/simple_mem.c3
-rw-r--r--src/mesh/node2d.c3
-rw-r--r--src/mesh/node3d.c10
-rw-r--r--src/source.mk2
-rw-r--r--src/torus3d/node.c69
-rw-r--r--src/uart/simple_uart.c3
12 files changed, 109 insertions, 91 deletions
diff --git a/src/bfly/fat_bfly.c b/src/bfly/fat_bfly.c
index 39ad657..90ed876 100644
--- a/src/bfly/fat_bfly.c
+++ b/src/bfly/fat_bfly.c
@@ -30,11 +30,6 @@
* in this version so I'm sticking with this for now at least.
*/
-struct reg {
- struct packet pkt;
- bool busy;
-};
-
struct fat_node {
/* parent in tree */
struct fat_node *up;
@@ -57,7 +52,8 @@ struct fat_bfly {
};
/* left selects which input bank to use and idx which index within it */
-static stat node_receive(struct fat_node *node, struct packet pkt, size_t idx, bool left)
+static stat node_receive(struct fat_node *node, struct packet pkt, size_t idx,
+ bool left)
{
struct reg *rs = left ? node->left : node->right;
if (rs[idx].busy)
@@ -71,8 +67,7 @@ static stat node_receive(struct fat_node *node, struct packet pkt, size_t idx, b
static stat node_clock(struct fat_node *node, size_t count, size_t height)
{
/* can't go higher than the top layer */
- if (node->up)
- for (size_t i = 0; i < count; ++i) {
+ if (node->up) for (size_t i = 0; i < count; ++i) {
if (!node->out[i].busy)
continue;
@@ -182,7 +177,8 @@ static stat fat_bfly_clock(struct fat_bfly *bfly)
return OK;
}
-static stat fat_bfly_receive(struct fat_bfly *bfly, struct component *from, struct packet pkt)
+static stat fat_bfly_receive(struct fat_bfly *bfly, struct component *from,
+ struct packet pkt)
{
uint32_t elem;
addr_fat_bfly(pkt.from, &elem, NULL);
@@ -245,10 +241,18 @@ struct component *create_fat_bfly(uint32_t elems)
for (size_t j = 0; j < count; ++j) {
/* j / 2 since there are always twice as few nodes per layer */
- bfly->layer[i][j].up = i == 0 ? NULL : &bfly->layer[i - 1][j / 2];
- bfly->layer[i][j].left = calloc(elems / count, sizeof(struct reg));
- bfly->layer[i][j].right = calloc(elems / count, sizeof(struct reg));
- bfly->layer[i][j].out = calloc(2 * elems / count, sizeof(struct reg));
+ bfly->layer[i][j].up = i == 0
+ ? NULL
+ : &bfly->layer[i - 1][j / 2];
+
+ bfly->layer[i][j].left = calloc(elems / count,
+ sizeof(struct reg));
+
+ bfly->layer[i][j].right = calloc(elems / count,
+ sizeof(struct reg));
+
+ bfly->layer[i][j].out = calloc(2 * elems / count,
+ sizeof(struct reg));
assert(bfly->layer[i][j].left);
assert(bfly->layer[i][j].right);
assert(bfly->layer[i][j].out);
@@ -261,7 +265,8 @@ struct component *create_fat_bfly(uint32_t elems)
return (struct component *)bfly;
}
-stat fat_bfly_connect(struct component *bfly, struct component *component, uint32_t elem)
+stat fat_bfly_connect(struct component *bfly, struct component *component,
+ uint32_t elem)
{
struct fat_bfly *b = (struct fat_bfly *)bfly;
assert(elem < b->elems);
diff --git a/src/bus/simple_bus.c b/src/bus/simple_bus.c
index e1e9a88..1b245eb 100644
--- a/src/bus/simple_bus.c
+++ b/src/bus/simple_bus.c
@@ -47,7 +47,8 @@ static stat simple_bus_clock(struct simple_bus *bus)
return OK;
}
-static stat simple_bus_receive(struct simple_bus *bus, struct component *from, struct packet pkt)
+static stat simple_bus_receive(struct simple_bus *bus, struct component *from,
+ struct packet pkt)
{
if (bus->busy)
return EBUSY;
diff --git a/src/common.c b/src/common.c
index 41bd145..4208d50 100644
--- a/src/common.c
+++ b/src/common.c
@@ -23,8 +23,8 @@ stat copy_reg(struct reg *r, struct reg *s)
}
void propagate(struct reg *out,
- size_t count, struct reg *in[static count],
- bool (*sel)(struct reg *r, void *data), void *data)
+ size_t count, struct reg *in[static count],
+ bool (*sel)(struct reg *r, void *data), void *data)
{
struct reg *r = NULL;
for (size_t i = 0; i < count; ++i) {
diff --git a/src/cpu/riscv/simple_riscv64.c b/src/cpu/riscv/simple_riscv64.c
index 80ee7c1..b2bdff6 100644
--- a/src/cpu/riscv/simple_riscv64.c
+++ b/src/cpu/riscv/simple_riscv64.c
@@ -299,9 +299,9 @@ static stat op(struct simple_riscv64 *cpu, union rv_insn insn)
#define JTYPE_IMM(insn) \
EXTEND_IMM20((insn.jtype.imm3 << 20) \
- | (insn.jtype.imm2 << 1) \
- | (insn.jtype.imm1 << 11) \
- | (insn.jtype.imm0 << 12))
+ | (insn.jtype.imm2 << 1) \
+ | (insn.jtype.imm1 << 11) \
+ | (insn.jtype.imm0 << 12))
static stat jal(struct simple_riscv64 *cpu, union rv_insn insn)
{
@@ -322,9 +322,9 @@ static stat jalr(struct simple_riscv64 *cpu, union rv_insn insn)
#define BTYPE_IMM(insn) \
EXTEND_IMM12((insn.btype.imm3 << 12) \
- | (insn.btype.imm2 << 5) \
- | (insn.btype.imm1 << 1) \
- | (insn.btype.imm0 << 11))
+ | (insn.btype.imm2 << 5) \
+ | (insn.btype.imm1 << 1) \
+ | (insn.btype.imm0 << 11))
static stat branch(struct simple_riscv64 *cpu, union rv_insn insn)
{
@@ -418,10 +418,10 @@ static stat load(struct simple_riscv64 *cpu, union rv_insn insn)
}
struct packet pkt = create_packet(cpu->rcv,
- addr,
- size,
- NULL,
- PACKET_READ);
+ addr,
+ size,
+ NULL,
+ PACKET_READ);
cpu->dls = (struct ldst){pkt, LDST_SENT, insn.itype.rd, u};
stat ret = SEND(cpu, cpu->dmem, pkt);
@@ -436,7 +436,7 @@ static stat load(struct simple_riscv64 *cpu, union rv_insn insn)
#define STYPE_IMM(insn) \
EXTEND_IMM12((insn.stype.imm1 << 5) \
- | (insn.stype.imm0))
+ | (insn.stype.imm0))
static stat store(struct simple_riscv64 *cpu, union rv_insn insn)
{
@@ -461,7 +461,8 @@ static stat store(struct simple_riscv64 *cpu, union rv_insn insn)
return ENOSUCH;
}
- struct packet pkt = create_packet(cpu->rcv, addr, size, &src, PACKET_WRITE);
+ struct packet pkt = create_packet(cpu->rcv, addr, size, &src,
+ PACKET_WRITE);
cpu->dls = (struct ldst){pkt, LDST_SENT, 0, false};
stat ret = SEND(cpu, cpu->dmem, pkt);
if (ret == EBUSY) {
@@ -527,7 +528,8 @@ static uint32_t finalize_ils(struct simple_riscv64 *cpu)
return packet_convu32(&cpu->ils.pkt);
}
-static stat simple_riscv64_receive(struct simple_riscv64 *cpu, struct component *from, struct packet pkt)
+static stat simple_riscv64_receive(struct simple_riscv64 *cpu,
+ struct component *from, struct packet pkt)
{
(void)from;
@@ -661,10 +663,10 @@ static stat simple_riscv64_clock(struct simple_riscv64 *cpu)
if (cpu->ils.state == LDST_IDLE) {
cpu->ils.pkt = create_packet(cpu->rcv + 64,
- cpu->pc,
- sizeof(uint32_t),
- NULL,
- PACKET_READ);
+ cpu->pc,
+ sizeof(uint32_t),
+ NULL,
+ PACKET_READ);
cpu->ils.state = LDST_BLOCKED;
}
@@ -701,10 +703,10 @@ struct component *create_simple_riscv64(uint64_t rcv, uint64_t start_pc,
/* fetch new instruction at start */
new->ils.state = LDST_BLOCKED;
new->ils.pkt = create_packet(new->rcv + 64,
- new->pc,
- sizeof(uint32_t),
- NULL,
- PACKET_READ);
+ new->pc,
+ sizeof(uint32_t),
+ NULL,
+ PACKET_READ);
return (struct component *)new;
}
diff --git a/src/ideal_noc.c b/src/ideal_noc.c
index d2816d6..57afba3 100644
--- a/src/ideal_noc.c
+++ b/src/ideal_noc.c
@@ -1,10 +1,5 @@
#include <gran/ideal_noc.h>
-struct reg {
- struct packet pkt;
- bool busy;
-};
-
struct noc {
struct component component;
uint32_t elems;
@@ -17,7 +12,8 @@ struct noc {
struct component **lower; /* countedby[elems] */
};
-static stat ideal_noc_receive(struct noc *n, struct component *from, struct packet pkt)
+static stat ideal_noc_receive(struct noc *n, struct component *from,
+ struct packet pkt)
{
(void)from; /* unused */
uint32_t elem;
@@ -86,7 +82,8 @@ static void ideal_noc_destroy(struct noc *n)
free(n);
}
-stat ideal_noc_connect(struct component *node, struct component *component, uint32_t elem)
+stat ideal_noc_connect(struct component *node, struct component *component,
+ uint32_t elem)
{
struct noc *n = (struct noc *)node;
assert(elem < n->elems);
@@ -114,7 +111,8 @@ struct component *create_ideal_noc(uint32_t elems, size_t latency)
return NULL;
}
- n->lower = (struct component **)calloc(elems, sizeof(struct component *));
+ n->lower = (struct component **)calloc(elems,
+ sizeof(struct component *));
if (!n->lower) {
free(n->out);
free(n->in);
diff --git a/src/mem/ideal_alloc.c b/src/mem/ideal_alloc.c
index 0396123..8840a17 100644
--- a/src/mem/ideal_alloc.c
+++ b/src/mem/ideal_alloc.c
@@ -1,12 +1,6 @@
#include <stdlib.h>
#include <gran/mem/ideal_alloc.h>
-/** @todo almost everyone has the same def for reg, should maybe make common */
-struct reg {
- struct packet pkt;
- bool busy;
-};
-
struct region {
uint64_t start, end;
};
@@ -69,7 +63,8 @@ static void alloc_destroy(struct alloc *a)
free(a);
}
-static stat alloc_receive(struct alloc *a, struct component *from, struct packet pkt)
+static stat alloc_receive(struct alloc *a, struct component *from,
+ struct packet pkt)
{
(void)from; /* unused */
if (a->in.busy)
@@ -80,7 +75,8 @@ static stat alloc_receive(struct alloc *a, struct component *from, struct packet
return OK;
}
-static stat alloc_resp(struct alloc *a, enum alloc_if_ret resp, uint64_t start, uint64_t end)
+static stat alloc_resp(struct alloc *a, enum alloc_if_ret resp, uint64_t start,
+ uint64_t end)
{
a->in.busy = false;
diff --git a/src/mem/simple_mem.c b/src/mem/simple_mem.c
index 77d8319..48a4631 100644
--- a/src/mem/simple_mem.c
+++ b/src/mem/simple_mem.c
@@ -31,7 +31,8 @@ static stat simple_mem_clock(struct simple_mem *mem)
return OK;
}
-static stat simple_mem_receive(struct simple_mem *mem, struct component *from, struct packet pkt)
+static stat simple_mem_receive(struct simple_mem *mem, struct component *from,
+ struct packet pkt)
{
if (mem->busy)
return EBUSY;
diff --git a/src/mesh/node2d.c b/src/mesh/node2d.c
index 569bd68..7bfe02a 100644
--- a/src/mesh/node2d.c
+++ b/src/mesh/node2d.c
@@ -126,7 +126,8 @@ static stat node2d_clock(struct node2d *n)
propagate(&south_out(n), 4, south, south_sel, &helper);
propagate(&west_out(n), 4, west, west_sel, &helper);
- struct reg *all[] = {r, &north_in(n), &east_in(n), &south_in(n), &west_in(n)};
+ struct reg *all[] = {r, &north_in(n), &east_in(n), &south_in(n),
+ &west_in(n)};
for (int i = 0; i < n->elems; ++i) {
helper.elem = i;
propagate(&n->out[i], 5, all, elem_sel, &helper);
diff --git a/src/mesh/node3d.c b/src/mesh/node3d.c
index 8c6d776..5bd6ee9 100644
--- a/src/mesh/node3d.c
+++ b/src/mesh/node3d.c
@@ -112,7 +112,8 @@ static bool elem_sel(struct reg *r, void *data)
uint8_t x = 0, y = 0, z = 0, elem = 0;
struct sel_helper *helper = data;
addr_mesh3d(r->pkt.to, &x, &y, &z, &elem, NULL);
- return x == helper->x && y == helper->y && z == helper->z && elem == helper->elem;
+ return x == helper->x && y == helper->y && z == helper->z &&
+ elem == helper->elem;
}
static stat node3d_clock(struct node3d *n)
@@ -163,7 +164,7 @@ static stat node3d_clock(struct node3d *n)
propagate(&down_out(n), 6, down, down_sel, &helper);
struct reg *all[] = {r, &north_in(n), &east_in(n), &south_in(n),
- &west_in(n), &up_in(n), &down_in(n)};
+ &west_in(n), &up_in(n), &down_in(n)};
for (int i = 0; i < n->elems; ++i) {
helper.elem = i;
@@ -190,7 +191,8 @@ static stat node3d_receive(struct node3d *n, struct component *from,
return OK;
}
-struct component *create_mesh_node3d(uint8_t x, uint8_t y, uint8_t z, uint8_t elems)
+struct component *create_mesh_node3d(uint8_t x, uint8_t y, uint8_t z,
+ uint8_t elems)
{
struct node3d *n = calloc(1, sizeof(struct node3d));
if (!n)
@@ -225,7 +227,7 @@ struct component *create_mesh_node3d(uint8_t x, uint8_t y, uint8_t z, uint8_t el
}
stat mesh_node3d_connect(struct component *c, struct component *e,
- uint8_t elem)
+ uint8_t elem)
{
struct node3d *n = (struct node3d *)c;
if (elem >= n->elems)
diff --git a/src/source.mk b/src/source.mk
index f6e8ba9..7ec3b9e 100644
--- a/src/source.mk
+++ b/src/source.mk
@@ -1,4 +1,4 @@
include src/*/source.mk
-SOURCES += src/root.c src/clock_domain.c src/ideal_noc.c
+SOURCES += src/root.c src/clock_domain.c src/ideal_noc.c src/common.c
MAIN_SRC += src/main.c
diff --git a/src/torus3d/node.c b/src/torus3d/node.c
index 4111c48..11f15e8 100644
--- a/src/torus3d/node.c
+++ b/src/torus3d/node.c
@@ -1,10 +1,5 @@
#include <gran/torus3d/node.h>
-struct reg {
- struct packet pkt;
- bool busy;
-};
-
struct port {
struct reg r[2];
};
@@ -14,8 +9,8 @@ struct torus3d_node {
uint8_t x, y, z /*, w for 4D but that might be a bit overkill*/;
struct component *x_next, *y_next, *z_next,
- *x_prev, *y_prev, *z_prev,
- *child;
+ *x_prev, *y_prev, *z_prev,
+ *child;
struct port port_x, port_y, port_z;
@@ -24,7 +19,8 @@ struct torus3d_node {
bool prio;
};
-static stat port_receive(struct torus3d_node *torus3d, struct port *port, struct reg *reg)
+static stat port_receive(struct torus3d_node *torus3d, struct port *port,
+ struct reg *reg)
{
if (!reg->busy)
return OK;
@@ -44,10 +40,10 @@ static stat port_receive(struct torus3d_node *torus3d, struct port *port, struct
return OK;
printf("(%d, %d, %d) to (%d, %d, %d) via (%d, %d, %d) c %d\n",
- sx, sy, sz,
- dx, dy, dz,
- torus3d->x, torus3d->y, torus3d->z,
- chan);
+ sx, sy, sz,
+ dx, dy, dz,
+ torus3d->x, torus3d->y, torus3d->z,
+ chan);
port->r[chan].pkt = reg->pkt;
port->r[chan].busy = true;
@@ -74,7 +70,9 @@ enum match {
NZ = (1 << 5),
};
-static void maybe_route_reg(struct torus3d_node *torus3d, struct reg *reg, enum match m, uint64_t *oldest, struct packet **pkt, bool **busy)
+static void maybe_route_reg(struct torus3d_node *torus3d, struct reg *reg,
+ enum match m, uint64_t *oldest, struct packet **pkt,
+ bool **busy)
{
if (!reg->busy)
return;
@@ -107,24 +105,36 @@ static void maybe_route_reg(struct torus3d_node *torus3d, struct reg *reg, enum
}
}
-static stat route(struct torus3d_node *torus3d, struct component *next, enum match m)
+static stat route(struct torus3d_node *torus3d, struct component *next,
+ enum match m)
{
bool prio = torus3d->prio;
uint64_t oldest = -1; struct packet *pkt = NULL; bool *busy = NULL;
/* prioritise current priority port */
- maybe_route_reg(torus3d, &torus3d->port_x.r[prio], m, &oldest, &pkt, &busy);
- maybe_route_reg(torus3d, &torus3d->port_y.r[prio], m, &oldest, &pkt, &busy);
- maybe_route_reg(torus3d, &torus3d->port_z.r[prio], m, &oldest, &pkt, &busy);
+ maybe_route_reg(torus3d, &torus3d->port_x.r[prio], m,
+ &oldest, &pkt, &busy);
+
+ maybe_route_reg(torus3d, &torus3d->port_y.r[prio], m,
+ &oldest, &pkt, &busy);
+
+ maybe_route_reg(torus3d, &torus3d->port_z.r[prio], m,
+ &oldest, &pkt, &busy);
/* if no suitable match found, check other ports as well */
if (pkt == NULL) {
- maybe_route_reg(torus3d, &torus3d->port_x.r[!prio], m, &oldest, &pkt, &busy);
- maybe_route_reg(torus3d, &torus3d->port_y.r[!prio], m, &oldest, &pkt, &busy);
- maybe_route_reg(torus3d, &torus3d->port_z.r[!prio], m, &oldest, &pkt, &busy);
+ maybe_route_reg(torus3d, &torus3d->port_x.r[!prio], m,
+ &oldest, &pkt, &busy);
+
+ maybe_route_reg(torus3d, &torus3d->port_y.r[!prio], m,
+ &oldest, &pkt, &busy);
+
+ maybe_route_reg(torus3d, &torus3d->port_z.r[!prio], m,
+ &oldest, &pkt, &busy);
}
- maybe_route_reg(torus3d, &torus3d->child_in, m, &oldest, &pkt, &busy);
+ maybe_route_reg(torus3d, &torus3d->child_in, m,
+ &oldest, &pkt, &busy);
/* no suitable match */
if (pkt == NULL)
@@ -169,7 +179,8 @@ static stat torus3d_clock(struct torus3d_node *torus3d)
return OK;
}
-static stat torus3d_receive(struct torus3d_node *torus3d, struct component *from, struct packet pkt)
+static stat torus3d_receive(struct torus3d_node *torus3d,
+ struct component *from, struct packet pkt)
{
if (from == torus3d->child)
return reg_receive(&torus3d->child_in, pkt);
@@ -202,13 +213,13 @@ struct component *create_torus3d_node(uint8_t x, uint8_t y, uint8_t z)
}
stat torus3d_node_connect(struct component *node,
- struct component *x_in,
- struct component *y_in,
- struct component *z_in,
- struct component *child,
- struct component *x_out,
- struct component *y_out,
- struct component *z_out)
+ struct component *x_in,
+ struct component *y_in,
+ struct component *z_in,
+ struct component *child,
+ struct component *x_out,
+ struct component *y_out,
+ struct component *z_out)
{
struct torus3d_node *n = (struct torus3d_node *)node;
n->x_prev = x_in;
diff --git a/src/uart/simple_uart.c b/src/uart/simple_uart.c
index e640ae1..91bbbbd 100644
--- a/src/uart/simple_uart.c
+++ b/src/uart/simple_uart.c
@@ -22,7 +22,8 @@ static stat simple_uart_clock(struct simple_uart *uart)
return OK;
}
-static stat simple_uart_receive(struct simple_uart *uart, struct component *from, struct packet pkt)
+static stat simple_uart_receive(struct simple_uart *uart,
+ struct component *from, struct packet pkt)
{
if (uart->busy)
return EBUSY;