Skip to content
Permalink
Browse files

Merge branch 'packing-32-bit'

  • Loading branch information
alex committed Jun 26, 2013
2 parents 2add178 + c608fd0 commit 7d294b392d161d5ebad3bd69711d03a754de2459
Showing with 49 additions and 4 deletions.
  1. +13 −0 topaz/objects/bignumobject.py
  2. +14 −1 topaz/objects/intobject.py
  3. +22 −3 topaz/utils/packing/intpacking.py
@@ -1,5 +1,6 @@
from rpython.rlib.rbigint import rbigint
from rpython.rlib.rfloat import INFINITY
from rpython.rtyper.lltypesystem import lltype, rffi

from topaz.module import ClassDef
from topaz.objects.integerobject import W_IntegerObject
@@ -37,6 +38,18 @@ def bigint_w(self, space):
def float_w(self, space):
return self.bigint.tofloat()

def intmask_w(self, space):
return rffi.cast(lltype.Signed, self.uintmask_w((space)))

def uintmask_w(self, space):
return self.bigint.uintmask()

def longlongmask_w(self, space):
return rffi.cast(lltype.SignedLongLong, self.ulonglongmask_w((space)))

def ulonglongmask_w(self, space):
return self.bigint.ulonglongmask()

@classdef.method("to_s")
def method_to_s(self, space):
return space.newstr_fromstr(self.bigint.str())
@@ -4,7 +4,8 @@
from rpython.rlib import rfloat
from rpython.rlib.debug import check_regular_int
from rpython.rlib.objectmodel import specialize
from rpython.rlib.rarithmetic import ovfcheck, LONG_BIT
from rpython.rlib.rarithmetic import (r_uint, r_longlong, r_ulonglong,
ovfcheck, LONG_BIT)
from rpython.rlib.rbigint import rbigint
from rpython.rtyper.lltypesystem import lltype, rffi

@@ -52,6 +53,18 @@ def bigint_w(self, space):
def float_w(self, space):
return float(self.intvalue)

def intmask_w(self, space):
return self.intvalue

def uintmask_w(self, space):
return r_uint(self.intvalue)

def longlongmask_w(self, space):
return r_longlong(self.intvalue)

def ulonglongmask_w(self, space):
return r_ulonglong(self.intvalue)

def find_instance_var(self, space, name):
storage = space.fromcache(FixnumStorage).get_or_create(space, self.intvalue)
return storage.find_instance_var(space, name)
@@ -1,12 +1,31 @@
from rpython.rtyper.lltypesystem import rffi, lltype


def select_conversion_method(size, signed):
if signed:
if size <= rffi.sizeof(lltype.Signed):
return "intmask_w"
else:
return "longlongmask_w"
else:
if size < rffi.sizeof(lltype.Signed):
return "intmask_w"
elif size == rffi.sizeof(lltype.Signed):
return "uintmask_w"
else:
return "ulonglongmask_w"


def make_int_packer(size, signed, bigendian):
conversion_method = select_conversion_method(size, signed)

def pack_int(space, packer, repetitions):
if repetitions > len(packer.args_w) - packer.args_index:
raise space.error(space.w_ArgumentError, "too few arguments")

for i in xrange(packer.args_index, repetitions + packer.args_index):
num = space.int_w(
space.convert_type(packer.args_w[i], space.w_integer, "to_int")
)
w_num = space.convert_type(packer.args_w[i], space.w_integer, "to_int")
num = getattr(w_num, conversion_method)(space)
if bigendian:
for i in xrange(size - 1, -1, -1):
x = (num >> (8 * i)) & 0xff

0 comments on commit 7d294b3

Please sign in to comment.
You can’t perform that action at this time.