adapted ALU + minor fix in add-ports

This commit is contained in:
Louis Heredero 2025-04-19 17:16:09 +02:00
parent 4733f69b51
commit cd8784fcee
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
5 changed files with 50 additions and 71 deletions

Binary file not shown.

View File

@ -113,8 +113,7 @@
pos: (15, -3.5), pos: (15, -3.5),
size: (3, 1), size: (3, 1),
id: "Extender", id: "Extender",
fill: util.colors.green, fill: util.colors.green
debug: (bounds: true, ports: true)
) )
wire.wire( wire.wire(
"Extender.north", "Extender.north",
@ -126,12 +125,12 @@
bus: true bus: true
) )
/*
let mid = ("InstDataMgr.east", 50%, "RegFile.west") let mid = ("InstDataMgr.east", 50%, "RegFile.west")
wire.wire( wire.wire(
"InstDataMgr.Instr", "InstDataMgr.Instr",
(vertical: (), horizontal: mid), (vertical: (), horizontal: mid),
id: "wInstDataMgr-Bus" id: "wInstDataMgr-Bus",
name: ("Instr", none), name: ("Instr", none),
bus: true bus: true
) )
@ -144,7 +143,7 @@
wire.wire( wire.wire(
"RegFile.A1", "RegFile.A1",
(horizontal: mid, vertical: ()), (horizontal: mid, vertical: ()),
id: "wBus-RegFile-A1" id: "wBus-RegFile-A1",
name: (none, "RS1"), name: (none, "RS1"),
slice: (19, 15), slice: (19, 15),
reverse: true, reverse: true,
@ -153,7 +152,7 @@
wire.wire( wire.wire(
"RegFile.A3", "RegFile.A3",
(horizontal: mid, vertical: ()), (horizontal: mid, vertical: ()),
id: "wBus-RegFile-A3" id: "wBus-RegFile-A3",
name: (none, "RD"), name: (none, "RD"),
slice: (11, 7), slice: (11, 7),
reverse: true, reverse: true,
@ -162,7 +161,7 @@
wire.wire( wire.wire(
"Extender.in", "Extender.in",
(horizontal: mid, vertical: ()), (horizontal: mid, vertical: ()),
id: "wBus-Extender" id: "wBus-Extender",
slice: (31, 7), slice: (31, 7),
reverse: true, reverse: true,
bus: true bus: true
@ -179,11 +178,13 @@
wire.wire( wire.wire(
"RegFile.RD1", "RegFile.RD1",
"ALU.in1", "ALU.in1",
id: "wRegFile-ALU" id: "wRegFile-ALU",
name: ("A", "SrcA"), name: ("A", "SrcA"),
bus: true bus: true
) )
wire.stub("ALU.north", side: "north")
/*
element.block( element.block(
pos: ( pos: (
26, (align: "in", with: "ALU.out") 26, (align: "in", with: "ALU.out")

View File

@ -1,45 +1,40 @@
#import "@preview/cetz:0.3.2": draw #import "@preview/cetz:0.3.2": draw
#import "element.typ" #import "element.typ"
#import "ports.typ": add-port #import "ports.typ": add-port
#import "../util.typ"
#let draw-shape(elmt, bounds) = {
let tl = bounds.tl
let tr = bounds.tr
let bl = bounds.bl
let br = bounds.br
#let draw-shape(id, tl, tr, br, bl, fill, stroke) = {
let p0 = tl let p0 = tl
let p1 = (tr, 10%, br) let p1 = util.lerp(tr, 10%, br)
let p2 = (tr, 90%, br) let p2 = util.lerp(tr, 90%, br)
let p3 = bl let p3 = bl
let p4 = (tl, 55%, bl) let p4 = util.lerp(tl, 55%, bl)
let p5 = (tl, 50%, br) let p5 = util.lerp(tl, 50%, br)
let p6 = (tl, 45%, bl) let p6 = util.lerp(tl, 45%, bl)
let f1 = draw.group(name: id, { let bounds2 = element.complete-bounds(elmt, (
tl: p0,
draw.merge-path( tr: p1,
inset: 0.5em, br: p2,
fill: fill, bl: p3
stroke: stroke, ))
close: true,
draw.line(p0, p1, p2, p3, p4, p5, p6)
)
draw.anchor("north", (p0, 50%, p1))
draw.anchor("south", (p2, 50%, p3))
draw.anchor("west", (p0, 50%, p3))
draw.anchor("east", (p1, 50%, p2))
draw.anchor("north-west", p0)
draw.anchor("north-east", p1)
draw.anchor("south-east", p2)
draw.anchor("south-west", p3)
draw.anchor("name", (p5, 50%, (p1, 50%, p2)))
})
let f2 = add-port(id, "west", (id: "in1"), (p0, 50%, p6))
let f3 = add-port(id, "west", (id: "in2"), (p3, 50%, p4))
let f4 = add-port(id, "east", (id: "out"), (p1, 50%, p2))
let f = { let f = {
f1; f2; f3; f4 draw.line(
p0, p1, p2, p3, p4, p5, p6,
fill: elmt.fill,
stroke: elmt.stroke,
close: true
)
draw.anchor("name", (p5, 50%, (p1, 50%, p2)))
} }
return (f, tl, tr, br, bl) return (f, bounds2)
} }
/// Draws an ALU with two inputs /// Draws an ALU with two inputs
@ -47,18 +42,7 @@
/// #examples.alu /// #examples.alu
/// For parameters description, see #doc-ref("element.elmt") /// For parameters description, see #doc-ref("element.elmt")
#let alu( #let alu(
x: none, ..args
y: none,
w: none,
h: none,
name: none,
name-anchor: "center",
fill: none,
stroke: black + 1pt,
id: "",
debug: (
ports: false
)
) = { ) = {
let ports = ( let ports = (
west: ( west: (
@ -70,24 +54,18 @@
) )
) )
element.elmt( return element.elmt(
draw-shape: draw-shape, draw-shape: draw-shape,
x: x,
y: y,
w: w,
h: h,
name: name,
name-anchor: name-anchor,
ports: ports, ports: ports,
fill: fill, ports-pos: (
stroke: stroke, west: (
id: id, in1: l => l * 0.225,
auto-ports: false, in2: l => l * 0.775,
ports-y: (
in1: (h) => {h * 0.225},
in2: (h) => {h * 0.775},
out: (h) => {h * 0.5}
), ),
debug: debug east: (
out: l => l * 0.5
)
),
..args
) )
} }

View File

@ -10,7 +10,7 @@
} }
} }
} }
panic("Could not find port with id '" + str(id) + "'") panic("Could not find port with id '" + str(id) + "' in ports " + repr(ports))
} }
#let local-to-global(origin, u, v, points) = { #let local-to-global(origin, u, v, points) = {

View File

@ -142,7 +142,7 @@
pt0.at(1) - pt1.at(1) pt0.at(1) - pt1.at(1)
} }
for (i, port) in side-ports.enumerate() { for (i, port) in side-ports.enumerate() {
let offset = get-port-pos(elmt, bounds, side, port, i) let offset = get-port-pos(elmt, bounds, side, port.id, i)
let pos = (pt0, offset, pt1) let pos = (pt0, offset, pt1)
let offset-prev = if type(offset) == ratio { let offset-prev = if type(offset) == ratio {