class Memory(Elaboratable):
def __init__(self, regwid, addrw):
- depth = (1<<addrw) / (regwid/8)
+ self.ddepth = regwid/8
+ depth = (1<<addrw) / self.ddepth
self.adr = Signal(addrw)
self.dat_r = Signal(regwid)
self.dat_w = Signal(regwid)
m.submodules.rdport = rdport = self.mem.read_port()
m.submodules.wrport = wrport = self.mem.write_port()
m.d.comb += [
- rdport.addr.eq(self.adr[2:]),
+ rdport.addr.eq(self.adr[self.ddepth:]), # ignore low bits
self.dat_r.eq(rdport.data),
wrport.addr.eq(self.adr),
wrport.data.eq(self.dat_w),
return m
+class MemSim:
+ def __init__(self, regwid, addrw):
+ self.regwid = regwid
+ self.ddepth = regwid//8
+ depth = (1<<addrw) // self.ddepth
+ self.mem = list(range(0, depth))
+
+ def ld(self, addr):
+ return self.mem[addr>>self.ddepth]
+
+ def st(self, addr, data):
+ self.mem[addr>>self.ddepth] = data & ((1<<self.regwid)-1)
+
+
class CompUnitsBase(Elaboratable):
""" Computation Unit Base class.
# inputs
self.oper_i = Signal(opwid, reset_less=True)
+ self.imm_i = Signal(rwid, reset_less=True)
# Int ALUs
add = ALU(rwid)
units = []
for alu in [add, sub, mul, shf]:
- units.append(ComputationUnitNoDelay(rwid, 2, alu))
+ aluopwid = 3 # extra bit for immediate mode
+ units.append(ComputationUnitNoDelay(rwid, aluopwid, alu))
CompUnitsBase.__init__(self, rwid, units)
m = CompUnitsBase.elaborate(self, platform)
comb = m.d.comb
- # hand the same operation to all units
+ # hand the same operation to all units, only lower 2 bits though
for alu in self.units:
- comb += alu.oper_i.eq(self.oper_i)
- #comb += self.units[0].oper_i.eq(Const(0, 2)) # op=add
- #comb += self.units[1].oper_i.eq(Const(1, 2)) # op=sub
- #comb += self.units[2].oper_i.eq(Const(2, 2)) # op=mul
- #comb += self.units[3].oper_i.eq(Const(3, 2)) # op=shf
+ comb += alu.oper_i[0:3].eq(self.oper_i)
+ comb += alu.imm_i.eq(self.imm_i)
return m
# hand the same operation to all units
for alu in self.units:
comb += alu.oper_i.eq(self.oper_i)
- #comb += self.br1.oper_i.eq(Const(4, 3)) # op=bgt
return m
self.brissue = IssueUnitGroup(1)
# and these
self.alu_oper_i = Signal(4, reset_less=True)
+ self.alu_imm_i = Signal(rwid, reset_less=True)
self.br_oper_i = Signal(4, reset_less=True)
# inputs
# Int ALUs and Comp Units
n_int_alus = 5
- cua = CompUnitALUs(self.rwid, 2)
+ cua = CompUnitALUs(self.rwid, 3)
cub = CompUnitBR(self.rwid, 2)
m.submodules.cu = cu = CompUnitsBase(self.rwid, [cua, cub])
bgt = cub.bgt # get at the branch computation unit
m.submodules.bshadow = bshadow = ShadowMatrix(n_intfus, 1, False)
# record previous instruction to cast shadow on current instruction
- fn_issue_prev = Signal(n_intfus)
prev_shadow = Signal(n_intfus)
# Branch Speculation recorder. tracks the success/fail state as
# take these to outside (issue needs them)
comb += cua.oper_i.eq(self.alu_oper_i)
+ comb += cua.imm_i.eq(self.alu_imm_i)
comb += cub.oper_i.eq(self.br_oper_i)
# TODO: issueunit.f (FP)
for i in range(n_intfus):
comb += shadows.s_good_i[i][0:n_intfus].eq(go_wr_o[0:n_intfus])
- # work out the current-activated busy unit (by recording the old one)
- with m.If(fn_issue_o): # only update prev bit if instruction issued
- sync += fn_issue_prev.eq(fn_issue_o)
-
# *previous* instruction shadows *current* instruction, and, obviously,
# if the previous is completed (!busy) don't cast the shadow!
comb += prev_shadow.eq(~fn_issue_o & cu.busy_o)
def ports(self):
return list(self)
+
class IssueToScoreboard(Elaboratable):
def __init__(self, qlen, n_in, n_out, rwid, opwid, n_regs):
# "resetting" done above (insn_i=0) could be re-ASSERTed.
with m.If(iq.qlen_o != 0):
# get the operands and operation
+ imm = iq.data_o[0].imm_i
dest = iq.data_o[0].dest_i
src1 = iq.data_o[0].src1_i
src2 = iq.data_o[0].src2_i
op = iq.data_o[0].oper_i
+ opi = iq.data_o[0].opim_i # immediate set
# set the src/dest regs
comb += sc.int_dest_i.eq(dest)
comb += wait_issue_br.eq(1)
with m.Else(): # alu
comb += sc.aluissue.insn_i.eq(1)
- comb += sc.alu_oper_i.eq(op & 0x3)
+ comb += sc.alu_oper_i.eq(Cat(op[0:2], opi))
+ comb += sc.alu_imm_i.eq(imm)
comb += wait_issue_alu.eq(1)
# XXX TODO
def ports(self):
return list(self)
+
IADD = 0
ISUB = 1
IMUL = 2
self.rwidth = rwidth
self.regs = [0] * nregs
- def op(self, op, src1, src2, dest):
+ def op(self, op, op_imm, imm, src1, src2, dest):
maxbits = (1 << self.rwidth) - 1
src1 = self.regs[src1] & maxbits
- src2 = self.regs[src2] & maxbits
+ if op_imm:
+ src2 = imm
+ else:
+ src2 = self.regs[src2] & maxbits
if op == IADD:
val = src1 + src2
elif op == ISUB:
yield from self.dump(dut)
assert False
-def instr_q(dut, op, src1, src2, dest, branch_success, branch_fail):
- instrs = [{'oper_i': op, 'dest_i': dest, 'src1_i': src1, 'src2_i': src2}]
+def instr_q(dut, op, op_imm, imm, src1, src2, dest,
+ branch_success, branch_fail):
+ instrs = [{'oper_i': op, 'dest_i': dest, 'imm_i': imm, 'opim_i': op_imm,
+ 'src1_i': src1, 'src2_i': src2}]
sendlen = 1
for idx in range(sendlen):
yield dut.p_add_i.eq(0)
-def int_instr(dut, op, src1, src2, dest, branch_success, branch_fail):
+def int_instr(dut, op, imm, src1, src2, dest, branch_success, branch_fail):
yield from disable_issue(dut)
yield dut.int_dest_i.eq(dest)
yield dut.int_src1_i.eq(src1)
else:
yield dut.aluissue.insn_i.eq(1)
yield dut.alu_oper_i.eq(Const(op & 0x3, 2))
+ yield dut.alu_imm_i.eq(imm)
dut_issue = dut.aluissue
yield dut.reg_enable_i.eq(1)
for i in range(n_ops):
src1 = randint(1, dut.n_regs-1)
src2 = randint(1, dut.n_regs-1)
+ imm = randint(1, (1<<dut.rwid)-1)
dest = randint(1, dut.n_regs-1)
op = randint(0, max_opnums)
+ opi = 0 if randint(0, 3) else 1 # set true if random is nonzero
if shadowing:
- insts.append((src1, src2, dest, op, (0, 0)))
+ insts.append((src1, src2, dest, op, opi, imm, (0, 0)))
else:
- insts.append((src1, src2, dest, op))
+ insts.append((src1, src2, dest, op, opi, imm))
return insts
# create some instructions (some random, some regression tests)
instrs = []
- if True:
+ if False:
instrs = create_random_ops(dut, 15, True, 3)
+ if True:
+ instrs.append( (1, 2, 2, 1, 1, 20, (0, 0)) )
+
if False:
instrs.append( (7, 3, 2, 4, (0, 0)) )
instrs.append( (7, 6, 6, 2, (0, 0)) )
instrs.append((4, 2, 1, 2, (1, 0)))
if False:
- instrs.append( (4, 3, 5, 1, (0, 0)) )
- instrs.append( (5, 2, 3, 1, (0, 0)) )
- instrs.append( (7, 1, 5, 2, (0, 0)) )
- instrs.append( (5, 6, 6, 4, (0, 0)) )
- instrs.append( (7, 5, 2, 2, (1, 0)) )
- instrs.append( (1, 7, 5, 0, (0, 1)) )
- instrs.append( (1, 6, 1, 2, (1, 0)) )
- instrs.append( (1, 6, 7, 3, (0, 0)) )
- instrs.append( (6, 7, 7, 0, (0, 0)) )
+ instrs.append( (4, 3, 5, 1, 0, (0, 0)) )
+ instrs.append( (5, 2, 3, 1, 0, (0, 0)) )
+ instrs.append( (7, 1, 5, 2, 0, (0, 0)) )
+ instrs.append( (5, 6, 6, 4, 0, (0, 0)) )
+ instrs.append( (7, 5, 2, 2, 0, (1, 0)) )
+ instrs.append( (1, 7, 5, 0, 0, (0, 1)) )
+ instrs.append( (1, 6, 1, 2, 0, (1, 0)) )
+ instrs.append( (1, 6, 7, 3, 0, (0, 0)) )
+ instrs.append( (6, 7, 7, 0, 0, (0, 0)) )
# issue instruction(s), wait for issue to be free before proceeding
- for i, (src1, src2, dest, op, (br_ok, br_fail)) in enumerate(instrs):
+ for i, instr in enumerate(instrs):
+ src1, src2, dest, op, opi, imm, (br_ok, br_fail) = instr
- print ("instr %d: (%d, %d, %d, %d)" % (i, src1, src2, dest, op))
- alusim.op(op, src1, src2, dest)
- yield from instr_q(dut, op, src1, src2, dest, br_ok, br_fail)
+ print ("instr %d: (%d, %d, %d, %d, %d, %d)" % \
+ (i, src1, src2, dest, op, opi, imm))
+ alusim.op(op, opi, imm, src1, src2, dest)
+ yield from instr_q(dut, op, opi, imm, src1, src2, dest,
+ br_ok, br_fail)
# wait for all instructions to stop before checking
while True:
def test_scoreboard():
dut = IssueToScoreboard(2, 1, 1, 16, 8, 8)
alusim = RegSim(16, 8)
+ memsim = MemSim(16, 16)
vl = rtlil.convert(dut, ports=dut.ports())
with open("test_scoreboard6600.il", "w") as f:
f.write(vl)