def cast_pos(self, i, ll_t): pos = rffi.ptradd(self.ll_buffer, self.shape.ll_positions[i]) TP = lltype.Ptr(rffi.CArray(ll_t)) value = rffi.cast(TP, pos)[0] # Handle bitfields for c in unroll_letters_for_numbers: if LL_TYPEMAP[c] is ll_t and self.shape.ll_bitsizes: bitsize = self.shape.ll_bitsizes[i] numbits = NUM_BITS(bitsize) lowbit = LOW_BIT(bitsize) if numbits: value = widen(value) value >>= lowbit value &= BIT_MASK(numbits) if ll_t is lltype.Bool or signedtype(ll_t._type): sign = (value >> (numbits - 1)) & 1 if sign: value = value - (1 << numbits) value = rffi.cast(ll_t, value) break return value
def _compare_helper((int1, int2), opname, operation): r = SomeBool() if int1.is_immutable_constant() and int2.is_immutable_constant(): r.const = operation(int1.const, int2.const) # # The rest of the code propagates nonneg information between # the two arguments. # # Doing the right thing when int1 or int2 change from signed # to unsigned (r_uint) is almost impossible. See test_intcmp_bug. # Instead, we only deduce constrains on the operands in the # case where they are both signed. In other words, if y is # nonneg then "assert x>=y" will let the annotator know that # x is nonneg too, but it will not work if y is unsigned. # if not (rarithmetic.signedtype(int1.knowntype) and rarithmetic.signedtype(int2.knowntype)): return r knowntypedata = {} # XXX HACK HACK HACK fn, block, i = getbookkeeper().position_key op = block.operations[i] assert op.opname == opname assert len(op.args) == 2 def tointtype(int0): if int0.knowntype is bool: return int return int0.knowntype if int1.nonneg and isinstance(op.args[1], Variable): case = opname in ('lt', 'le', 'eq')
def _compare_helper((int1, int2), opname, operation): r = SomeBool() if int1.is_immutable_constant() and int2.is_immutable_constant(): r.const = operation(int1.const, int2.const) # # The rest of the code propagates nonneg information between # the two arguments. # # Doing the right thing when int1 or int2 change from signed # to unsigned (r_uint) is almost impossible. See test_intcmp_bug. # Instead, we only deduce constrains on the operands in the # case where they are both signed. In other words, if y is # nonneg then "assert x>=y" will let the annotator know that # x is nonneg too, but it will not work if y is unsigned. # if not (rarithmetic.signedtype(int1.knowntype) and rarithmetic.signedtype(int2.knowntype)): return r knowntypedata = {} # XXX HACK HACK HACK fn, block, i = getbookkeeper().position_key op = block.operations[i] assert op.opname == opname assert len(op.args) == 2 def tointtype(int0): if int0.knowntype is bool: return int return int0.knowntype if int1.nonneg and isinstance(op.args[1], Variable):
def pow((int1, int2), obj3): knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype) return SomeInteger(nonneg = int1.nonneg, knowntype=knowntype) pow.can_only_throw = [ZeroDivisionError] pow_ovf = _clone(pow, [ZeroDivisionError, OverflowError]) def _compare_helper((int1, int2), opname, operation): r = SomeBool() if int1.is_immutable_constant() and int2.is_immutable_constant(): r.const = operation(int1.const, int2.const) else: # XXX VERY temporary hack if (opname == 'ge' and int2.is_immutable_constant() and int2.const == 0 and not rarithmetic.signedtype(int1.knowntype)): r.const = True knowntypedata = {} # XXX HACK HACK HACK # propagate nonneg information between the two arguments fn, block, i = getbookkeeper().position_key op = block.operations[i] assert op.opname == opname assert len(op.args) == 2 def tointtype(int0): if int0.knowntype is bool: return int return int0.knowntype if int1.nonneg and isinstance(op.args[1], Variable): case = opname in ('lt', 'le', 'eq')