class DIVInputData(IntegerData):
- regspec = [('INT', 'ra', '0:63'), # RA
- ('INT', 'rb', '0:63'), # RB/immediate
- ('XER', 'xer_so', '32'),] # XER bit 32: SO
+ regspec = [('INT', 'ra', '0:63'), # RA
+ ('INT', 'rb', '0:63'), # RB/immediate
+ ('XER', 'xer_so', '32'), ] # XER bit 32: SO
+
def __init__(self, pspec):
super().__init__(pspec, False)
# convenience
class DivMulOutputData(IntegerData):
regspec = [('INT', 'o', '0:63'),
('CR', 'cr_a', '0:3'),
- ('XER', 'xer_ov', '33,44'), # bit0: ov, bit1: ov32
+ ('XER', 'xer_ov', '33,44'), # bit0: ov, bit1: ov32
('XER', 'xer_so', '32')]
+
def __init__(self, pspec):
super().__init__(pspec, True)
# convenience
self.cr0 = self.cr_a
-
class DIVPipeSpec(CommonPipeSpec):
regspec = (DIVInputData.regspec, DivMulOutputData.regspec)
opsubsetkls = CompLogicalOpSubset
from soc.fu.div.pipe_data import DIVPipeSpec
import random
+
def log_rand(n, min_val=1):
logrange = random.randint(1, n)
- return random.randint(min_val, (1<<logrange)-1)
+ return random.randint(min_val, (1 << logrange)-1)
+
def get_cu_inputs(dec2, sim):
"""naming (res) must conform to DIVFunctionUnit input regspec
"""
res = {}
- yield from ALUHelpers.get_sim_int_ra(res, sim, dec2) # RA
- yield from ALUHelpers.get_sim_int_rb(res, sim, dec2) # RB
- yield from ALUHelpers.get_sim_xer_so(res, sim, dec2) # XER.so
+ yield from ALUHelpers.get_sim_int_ra(res, sim, dec2) # RA
+ yield from ALUHelpers.get_sim_int_rb(res, sim, dec2) # RB
+ yield from ALUHelpers.get_sim_xer_so(res, sim, dec2) # XER.so
- print ("alu get_cu_inputs", res)
+ print("alu get_cu_inputs", res)
return res
-
def set_alu_inputs(alu, dec2, sim):
# TODO: see https://bugs.libre-soc.org/show_bug.cgi?id=305#c43
# detect the immediate here (with m.If(self.i.ctx.op.imm_data.imm_ok))
lst = ["divw. 3, 1, 2"]
initial_regs = [0] * 32
initial_regs[1] = 0x80000000
- initial_regs[2] = 0xffffffffffffffff # top bits don't seem to matter
+ initial_regs[2] = 0xffffffffffffffff # top bits don't seem to matter
self.run_tst_program(Program(lst, bigendian), initial_regs)
def tst_divw_overflow3(self):
sim = Simulator(m)
sim.add_clock(1e-6)
+
def process():
for test in self.test_data:
print(test.name)
program = test.program
self.subTest(test.name)
sim = ISA(pdecode2, test.regs, test.sprs, test.cr,
- test.mem, test.msr,
- bigendian=bigendian)
+ test.mem, test.msr,
+ bigendian=bigendian)
gen = program.generate_instructions()
instructions = list(zip(gen, program.assembly.splitlines()))
yield Settle()
so = 1 if sim.spr['XER'][XER_bits['SO']] else 0
ov = 1 if sim.spr['XER'][XER_bits['OV']] else 0
ov32 = 1 if sim.spr['XER'][XER_bits['OV32']] else 0
- print ("before: so/ov/32", so, ov, ov32)
+ print("before: so/ov/32", so, ov, ov32)
# ask the decoder to decode this binary data (endian'd)
yield pdecode2.dec.bigendian.eq(bigendian) # little / big?
dive_abs_ov32 = yield do.i.dive_abs_ov32
div_by_zero = yield do.i.div_by_zero
quotient_neg = yield do.quotient_neg
- print ("32bit", hex(is_32bit))
- print ("signed", hex(is_signed))
- print ("quotient_root", hex(quotient_root))
- print ("quotient_65", hex(quotient_65))
- print ("div_by_zero", hex(div_by_zero))
- print ("dive_abs_ov32", hex(dive_abs_ov32))
- print ("quotient_neg", hex(quotient_neg))
- print ("")
+ print("32bit", hex(is_32bit))
+ print("signed", hex(is_signed))
+ print("quotient_root", hex(quotient_root))
+ print("quotient_65", hex(quotient_65))
+ print("div_by_zero", hex(div_by_zero))
+ print("dive_abs_ov32", hex(dive_abs_ov32))
+ print("quotient_neg", hex(quotient_neg))
+ print("")
yield
yield from self.check_alu_outputs(alu, pdecode2, sim, code)
sim.add_sync_process(process)
with sim.write_vcd("div_simulator.vcd", "div_simulator.gtkw",
- traces=[]):
+ traces=[]):
sim.run()
def check_alu_outputs(self, alu, dec2, sim, code):
cridx_ok = yield dec2.e.write_cr.ok
cridx = yield dec2.e.write_cr.data
- print ("check extra output", repr(code), cridx_ok, cridx)
+ print("check extra output", repr(code), cridx_ok, cridx)
if rc:
self.assertEqual(cridx, 0, code)
yield from ALUHelpers.get_int_o(res, alu, dec2)
yield from ALUHelpers.get_xer_so(res, alu, dec2)
- print ("res output", res)
+ print("res output", res)
yield from ALUHelpers.get_sim_int_o(sim_o, sim, dec2)
yield from ALUHelpers.get_wr_sim_cr_a(sim_o, sim, dec2)
yield from ALUHelpers.get_sim_xer_ov(sim_o, sim, dec2)
yield from ALUHelpers.get_sim_xer_so(sim_o, sim, dec2)
- print ("sim output", sim_o)
+ print("sim output", sim_o)
ALUHelpers.check_int_o(self, res, sim_o, code)
ALUHelpers.check_cr_a(self, res, sim_o, "CR%d %s" % (cridx, code))
oe = yield dec2.e.do.oe.oe
oe_ok = yield dec2.e.do.oe.ok
- print ("oe, oe_ok", oe, oe_ok)
+ print("oe, oe_ok", oe, oe_ok)
if not oe or not oe_ok:
# if OE not enabled, XER SO and OV must not be activated
so_ok = yield alu.n.data_o.xer_so.ok
ov_ok = yield alu.n.data_o.xer_ov.ok
- print ("so, ov", so_ok, ov_ok)
+ print("so, ov", so_ok, ov_ok)
self.assertEqual(ov_ok, False, code)
self.assertEqual(so_ok, False, code)