Example #1
0
 def load_other(self, other):
     if isinstance(other, cint):
         assert(self.n == other.size)
         self.conv_regint_by_bit(self.n, self, other.to_regint(1))
     elif isinstance(other, int):
         self.set_length(self.n or util.int_len(other))
         self.load_int(other)
     elif isinstance(other, regint):
         assert self.unit == 64
         n_units = int(math.ceil(self.n / self.unit))
         n_convs = min(other.size, n_units)
         for i in range(n_convs):
             x = self[i]
             y = other[i]
             self.conv_regint(min(self.unit, self.n - i * self.unit), x, y)
         for i in range(n_convs, n_units):
             inst.ldbits(self[i], min(self.unit, self.n - i * self.unit), 0)
     elif (isinstance(self, type(other)) or isinstance(other, type(self))) \
          and self.n == other.n:
         for i in range(math.ceil(self.n / self.unit)):
             self.mov(self[i], other[i])
     elif isinstance(other, sint) and isinstance(self, sbits):
         self.mov(self, sbitvec(other, self.n).elements()[0])
     else:
         try:
             bits = other.bit_decompose()
             bits = bits[:self.n] + [sbit(0)] * (self.n - len(bits))
             other = self.bit_compose(bits)
             assert(isinstance(other, type(self)))
             assert(other.n == self.n)
             self.load_other(other)
         except:
             raise CompilerError('cannot convert %s/%s from %s to %s' % \
                                 (str(other), repr(other), type(other), type(self)))
Example #2
0
 def load_int(self, value):
     if abs(value) < 2**31:
         if (abs(value) > (1 << self.n)):
             raise Exception('public value %d longer than %d bits' \
                             % (value, self.n))
         inst.ldbits(self, self.n, value)
     else:
         value %= 2**self.n
         if value >> 64 != 0:
             raise NotImplementedError('public value too large')
         self.load_other(regint(value))
Example #3
0
 def load_int(self, value):
     if (abs(value) > (1 << self.n)):
         raise Exception('public value %d longer than %d bits' \
                         % (value, self.n))
     if self.n <= 32:
         inst.ldbits(self, self.n, value)
     else:
         size = math.ceil(self.n / self.unit)
         tmp = regint(size=size)
         for i in range(size):
             tmp[i].load_int((value >> (i * 64)) % 2**64)
         self.load_other(tmp)
Example #4
0
 def load_int(self, value):
     if (abs(value) > (1 << self.n)):
         raise Exception('public value %d longer than %d bits' \
                         % (value, self.n))
     if self.n <= 32:
         inst.ldbits(self, self.n, value)
     elif self.n <= 64:
         self.load_other(regint(value))
     elif self.n <= 128:
         lower = sbits.get_type(64)(value % 2**64)
         upper = sbits.get_type(self.n - 64)(value >> 64)
         self.mov(self, lower + (upper << 64))
     else:
         raise NotImplementedError('more than 128 bits wanted')
Example #5
0
 def load_int(self, value):
     if (abs(value) > (1 << self.n)):
         raise Exception('public value %d longer than %d bits' \
                         % (value, self.n))
     if self.n <= 32:
         inst.ldbits(self, self.n, value)
     elif self.n <= 64:
         self.load_other(regint(value))
     elif self.n <= 128:
         lower = sbits.get_type(64)(value % 2**64)
         upper = sbits.get_type(self.n - 64)(value >> 64)
         self.mov(self, lower + (upper << 64))
     else:
         raise NotImplementedError('more than 128 bits wanted')