def bitfield_update_checker(self, input_width, range_start, range_end, update_width, test_amt=20): def ref(i, s, e, u): mask = ((1 << (e)) - 1) - ((1 << s) - 1) return (i & ~mask) | ((u << s) & mask) inp, inp_vals = utils.an_input_and_vals(input_width, test_vals=test_amt, name='inp') upd, upd_vals = utils.an_input_and_vals(update_width, test_vals=test_amt, name='upd') #inp_vals = [1,1,0,0] #upd_vals = [0x7,0x6,0x7,0x6] out = pyrtl.Output(input_width, "out") bfu_out = pyrtl.bitfield_update(inp, range_start, range_end, upd) self.assertEqual(len(out), len(bfu_out)) # output should have width of input out <<= bfu_out true_result = [ ref(i, range_start, range_end, u) for i, u in zip(inp_vals, upd_vals) ] upd_result = utils.sim_and_ret_out(out, [inp, upd], [inp_vals, upd_vals]) self.assertEqual(upd_result, true_result)
def test_field_too_big_truncate(self): a = pyrtl.WireVector(name='a', bitwidth=3) b = pyrtl.WireVector(name='b', bitwidth=3) o = pyrtl.bitfield_update(a, 1, 2, b, truncating=True)
def test_no_bits_to_update(self): a = pyrtl.WireVector(name='a', bitwidth=3) b = pyrtl.WireVector(name='b', bitwidth=3) with self.assertRaises(pyrtl.PyrtlError): o = pyrtl.bitfield_update(a, 1, 1, b, truncating=True)
def test_field_too_big(self): a = pyrtl.WireVector(name='a', bitwidth=3) b = pyrtl.WireVector(name='b', bitwidth=3) with self.assertRaises(pyrtl.PyrtlError): o = pyrtl.bitfield_update(a, 1, 2, b)