Example #1
0
File: shift.py Project: hoangt/ms3
 def reset(self, machine):
     transform.Transform.reset(self, machine)
     word_size = self.get_word_size()
     bits = machine.addr_bits - util.get_bus_shift(word_size)
     while self.shift < 0:
         self.shift += bits
     self.shift %= bits
Example #2
0
File: shift.py Project: hoangt/ms3
def random_shift(machine, nxt, rand):
    word_size = nxt.get_word_size()
    word_bits = util.get_bus_shift(word_size)
    bits = machine.addr_bits - word_bits - 1
    shift = rand.randint(-bits, bits)
    result = Shift(join.Join(), nxt, shift)
    result.reset(machine)
    return result
Example #3
0
File: shift.py Project: hoangt/ms3
 def _rotate(self, value, count):
     word_size = self.get_word_size()
     word_bits = util.get_bus_shift(word_size)
     word_mask = word_size - 1
     bits = self.machine.addr_bits - word_bits
     mask = (1 << bits) - 1
     shift_part = value >> word_bits
     word_part = value & word_mask
     if count >= 0:
         count2 = bits - count
         shifted = ((shift_part << count) & mask) | (shift_part >> count2)
     else:
         count2 = bits + count
         shifted = ((shift_part << count2) & mask) | (shift_part >> -count)
     return (shifted << word_bits) | word_part
Example #4
0
 def get_addr_width(self, word_size):
     """Get the number of bits needed for an address bus."""
     return self.addr_bits - util.get_bus_shift(word_size)
Example #5
0
File: shift.py Project: hoangt/ms3
 def permute(self, rand):
     word_bits = util.get_bus_shift(self.get_word_size())
     bits = self.machine.addr_bits - word_bits - 1
     self.shift = rand.randint(-bits, bits)
     return True