Compare commits

..

No commits in common. "0a108fdc73cf338c762680a1849949d09cfa29e8" and "3e9272255c21392c3c120f6360e49f5a2a1c6427" have entirely different histories.

7 changed files with 175 additions and 120 deletions

Binary file not shown.

View File

@ -2,7 +2,6 @@
#import "@preview/cetz:0.3.4": draw #import "@preview/cetz:0.3.4": draw
#set text(font: "Source Sans 3") #set text(font: "Source Sans 3")
#set page(width: auto, height: auto, margin: .5cm)
#circuit({ #circuit({
element.block( element.block(
@ -38,6 +37,7 @@
) )
wire.stub("AdrSrc-MP.north", side: "north", name: "AdrSrc") wire.stub("AdrSrc-MP.north", side: "north", name: "AdrSrc")
/*
element.block( element.block(
pos: ( pos: (
6, (align: "A", with: "AdrSrc-MP.out") 6, (align: "A", with: "AdrSrc-MP.out")
@ -126,12 +126,11 @@
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,12 +161,12 @@
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
) )
element.alu( element.alu(
pos: ( pos: (
22, (align: "in1", with: "RegFile.RD1") 22, (align: "in1", with: "RegFile.RD1")
@ -179,11 +178,10 @@
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: (
@ -202,7 +200,7 @@
wire.wire( wire.wire(
"ALU.out", "ALU.out",
"OutBuf.in", "OutBuf.in",
id: "wALU-OutBuf", id: "wALU-OutBuf"
name: "ALUResult", name: "ALUResult",
bus: true bus: true
) )
@ -216,12 +214,12 @@
fill: util.colors.orange, fill: util.colors.orange,
entries: 3 entries: 3
) )
wire.stub("Res-MP.north", side: "north", name: "ResultSrc") wire.stub("Res-MP.north", name: "ResultSrc")
wire.stub("Res-MP.in2") wire.stub("Res-MP.in2")
wire.wire( wire.wire(
"OutBuf.out", "OutBuf.out",
"Res-MP.in0", "Res-MP.in0",
id: "wOutBuf-ResMP", id: "wOutBuf-ResMP"
name: "ALUOut", name: "ALUOut",
bus: true bus: true
) )
@ -229,7 +227,7 @@
wire.wire( wire.wire(
"Extender.out", "Extender.out",
"ALU.in2", "ALU.in2",
id: "wExt-ALU", id: "wExt-ALU"
name: ("ImmExt", "SrcB"), name: ("ImmExt", "SrcB"),
bus: true, bus: true,
style: "zigzag", style: "zigzag",
@ -239,7 +237,7 @@
wire.wire( wire.wire(
"InstDataMgr.RD", "InstDataMgr.RD",
"Res-MP.in1", "Res-MP.in1",
id: "wInstDataMgr-ResMP", id: "wInstDataMgr-ResMP"
style: "dodge", style: "dodge",
dodge-y: -4, dodge-y: -4,
dodge-sides: ("east", "west"), dodge-sides: ("east", "west"),
@ -250,7 +248,7 @@
wire.wire( wire.wire(
"Res-MP.out", "Res-MP.out",
"AdrSrc-MP.in1", "AdrSrc-MP.in1",
id: "wResMP-AdrSrc", id: "wResMP-AdrSrc"
style: "dodge", style: "dodge",
dodge-y: -5, dodge-y: -5,
dodge-sides: ("east", "west"), dodge-sides: ("east", "west"),
@ -261,7 +259,7 @@
wire.wire( wire.wire(
"Res-MP.out", "Res-MP.out",
"RegFile.WD3", "RegFile.WD3",
id: "wResMP-RegFile", id: "wResMP-RegFile"
style: "dodge", style: "dodge",
dodge-y: -5, dodge-y: -5,
dodge-sides: ("east", "west"), dodge-sides: ("east", "west"),
@ -272,7 +270,7 @@
wire.wire( wire.wire(
"Res-MP.out", "Res-MP.out",
"PCBuf.PCNext", "PCBuf.PCNext",
id: "wResMP-PCBuf", id: "wResMP-PCBuf"
style: "dodge", style: "dodge",
dodge-y: -5, dodge-y: -5,
dodge-sides: ("east", "west"), dodge-sides: ("east", "west"),
@ -283,4 +281,5 @@
wire.intersection("wResMP-RegFile.dodge-end", radius: .2) wire.intersection("wResMP-RegFile.dodge-end", radius: .2)
wire.intersection("wResMP-AdrSrc.dodge-end", radius: .2) wire.intersection("wResMP-AdrSrc.dodge-end", radius: .2)
*/
}) })

View File

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

View File

@ -10,7 +10,7 @@
} }
} }
} }
panic("Could not find port with id '" + str(id) + "' in ports " + repr(ports)) panic("Could not find port with id '" + str(id) + "'")
} }
#let local-to-global(origin, u, v, points) = { #let local-to-global(origin, u, v, points) = {
@ -157,9 +157,9 @@
let props2 = props let props2 = props
if side in elmt.ports-margins { if side in elmt.ports-margins {
let (pt0, pt1) = props let (pt0, pt1) = props
let margins = elmt.ports-margins.at(side) let margins = ports-margins.at(side)
let a = util.lerp(pt0, margins.at(0), pt1) a = (pt0, margins.at(0), pt1)
let b = util.lerp(pt0, 100% - margins.at(1), pt1) b = (pt0, 100% - margins.at(1), pt1)
props2 = (a, b) props2 = (a, b)
} }
bounds.ports.insert(side, props2) bounds.ports.insert(side, props2)
@ -209,15 +209,6 @@
) )
func func
draw.anchor("north", bounds.t)
draw.anchor("south", bounds.b)
draw.anchor("west", bounds.l)
draw.anchor("east", bounds.r)
draw.anchor("north-west", bounds.tl)
draw.anchor("north-east", bounds.tr)
draw.anchor("south-east", bounds.br)
draw.anchor("south-west", bounds.bl)
if elmt.name != none { if elmt.name != none {
draw.content( draw.content(
(name: elmt.id, anchor: elmt.name-anchor), (name: elmt.id, anchor: elmt.name-anchor),
@ -228,14 +219,6 @@
} }
add-ports(elmt, bounds) add-ports(elmt, bounds)
if elmt.debug.bounds {
draw.line(
bounds.tl, bounds.tr, bounds.br, bounds.bl,
stroke: red,
close: true
)
}
}) })
/// Draws an element /// Draws an element
@ -280,7 +263,6 @@
id: auto, id: auto,
ports-pos: auto, ports-pos: auto,
debug: ( debug: (
bounds: false,
ports: false ports: false
), ),
extra: (:) extra: (:)
@ -305,6 +287,7 @@
ports.at(key) = side-ports ports.at(key) = side-ports
} }
return (( return ((
cls: cls, cls: cls,
id: id, id: id,

View File

@ -1,25 +1,41 @@
#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 draw-shape(id, tl, tr, br, bl, fill, stroke, h-ratio: 75%, align-out: true) = {
let ratio = elmt.l-ratio / 100% let (x, y) = bl
let tl2 = util.lerp(bounds.bl, elmt.l-ratio, bounds.tl) let (width, height) = (tr.at(0) - x, tr.at(1) - y)
let bounds2 = element.complete-bounds(elmt, (
tl: tl2,
tr: bounds.tr,
br: bounds.br,
bl: bounds.bl,
))
let f = draw.line( let ratio = h-ratio / 100%
bounds2.tl, bounds2.tr, bounds2.br, bounds2.bl,
fill: elmt.fill, tl = (x, y + height * ratio)
stroke: elmt.stroke, let tr2 = (x + width, y + height * ratio)
close: true let br = (x + width, y)
)
return (f, bounds2) if align-out {
(tr, tr2) = (tr2, tr)
} else {
(tr, tr2) = (tr, tr)
}
let f = draw.group(name: id, {
draw.merge-path(
inset: 0.5em,
fill: fill,
stroke: stroke,
close: true,
draw.line(tl, tr2, br, bl)
)
draw.anchor("north", (tl, 50%, tr2))
draw.anchor("south", (bl, 50%, br))
draw.anchor("west", (tl, 50%, bl))
draw.anchor("east", (tr2, 50%, br))
draw.anchor("north-west", tl)
draw.anchor("north-east", tr2)
draw.anchor("south-east", br)
draw.anchor("south-west", bl)
})
return (f, tl, tr, br, bl)
} }
/// Draws a bit extender /// Draws a bit extender
@ -29,28 +45,54 @@
/// - h-ratio (ratio): The height ratio of the left side relative to the full height /// - h-ratio (ratio): The height ratio of the left side relative to the full height
/// - align-out (bool): If true, the output and input ports are aligned, otherwise, the output port is centered on the right side /// - align-out (bool): If true, the output and input ports are aligned, otherwise, the output port is centered on the right side
#let extender( #let extender(
l-ratio: 75%, x: none,
y: none,
w: none,
h: none,
name: none,
name-anchor: "center",
fill: none,
stroke: black + 1pt,
id: "",
h-ratio: 75%,
align-out: true, align-out: true,
..args debug: (
ports: false
)
) = { ) = {
let ports = ( let ports = (
west: ((id: "in"),), west: (
east: ((id: "out"),) (id: "in"),
),
east: (
(id: "out"),
)
) )
let out-pct = if align-out {l-ratio / 2} else {50%} let out-pct = if align-out {h-ratio / 2} else {50%}
let ports-pos = ( let ports-y = (
"east": (l, i) => {l - l * (out-pct / 100%)} "in": (h) => {h - h * (h-ratio / 200%)},
"out": (h) => {h - h * (out-pct / 100%)}
) )
return element.elmt( element.elmt(
cls: "extender", draw-shape: draw-shape.with(h-ratio: h-ratio, align-out: align-out),
draw-shape: draw-shape, x: x,
y: y,
w: w,
h: h,
name: name,
name-anchor: name-anchor,
ports: ports, ports: ports,
ports-pos: ports-pos, auto-ports: false,
extra: ( ports-y: ports-y,
l-ratio: l-ratio, fill: fill,
align-out: align-out stroke: stroke,
), id: id,
..args debug: debug
) )
let in-pos = (rel: (0, h * (h-ratio / 200%)), to: id+".south-west")
let out-pos = (id+".south-east", out-pct, id+".north-east")
add-port(id, "west", ports.west.first(), in-pos)
add-port(id, "east", ports.east.first(), out-pos)
} }

View File

@ -13,12 +13,23 @@
tr: tr2, tr: tr2,
br: br2, br: br2,
)) ))
let f = draw.line( let f = {
bounds2.tl, bounds2.tr, bounds2.br, bounds2.bl, draw.merge-path(
close: true, inset: 0.5em,
fill: elmt.fill, fill: elmt.fill,
stroke: elmt.stroke stroke: elmt.stroke,
) close: true,
draw.line(bounds2.tl, bounds2.tr, bounds2.br, bounds2.bl)
)
draw.anchor("north", bounds2.t)
draw.anchor("south", bounds2.b)
draw.anchor("west", bounds2.l)
draw.anchor("east", bounds2.r)
draw.anchor("north-west", bounds2.tl)
draw.anchor("north-east", bounds2.tr)
draw.anchor("south-east", bounds2.br)
draw.anchor("south-west", bounds2.bl)
}
return (f, bounds2) return (f, bounds2)
} }

View File

@ -9,9 +9,7 @@
} }
} }
} }
panic( panic("Unknown port " + port + " on element " + elmt.id)
"Unknown port '" + port + "' on element '" + elmt.id + "', could not automatically determine side"
)
} }
#let get-port-idx(elmt, port, side: auto) = { #let get-port-idx(elmt, port, side: auto) = {
@ -127,7 +125,7 @@
elmt, elmt,
bounds bounds
) = { ) = {
let debug = elmt.debug.at("ports", default: false) let debug = elmt.debug.ports
if type(elmt.ports) != dictionary { if type(elmt.ports) != dictionary {
return return
@ -144,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.id, i) let offset = get-port-pos(elmt, bounds, side, port, 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 {