Ejemplo n.º 1
0
 def test_decode_signed(self):
     field = Field("test", 16, 31, 'signed')
     for i in range(1000):
         hi = long(random.randrange(0x10000)) << 16
         lo = long(random.randrange(0x10000))
         word = hi|lo
         if lo & 0x8000:
             lo |= ~0xFFFF
         assert field.decode(word) == lo
Ejemplo n.º 2
0
 def test_error_checking_unsigned(self):
     for b in range(0, 17):
         field = Field("test", b, 15+b)
         assert field.decode(field.encode(0)) == 0
         assert field.decode(field.encode(32768)) == 32768
         assert field.decode(field.encode(65535)) == 65535
         raises(ValueError, field.encode, -32768)
         raises(ValueError, field.encode, -1)
         raises(ValueError, field.encode, 65536)
Ejemplo n.º 3
0
 def test_decode_signed(self):
     field = Field("test", 16, 31, 'signed')
     for i in range(1000):
         hi = long(random.randrange(0x10000)) << 16
         lo = long(random.randrange(0x10000))
         word = hi | lo
         if lo & 0x8000:
             lo |= ~0xFFFF
         assert field.decode(word) == lo
Ejemplo n.º 4
0
 def test_error_checking_signed(self):
     for b in range(0, 17):
         field = Field("test", b, 15 + b, 'signed')
         assert field.decode(field.encode(0)) == 0
         assert field.decode(field.encode(-32768)) == -32768
         assert field.decode(field.encode(32767)) == 32767
         raises(ValueError, field.encode, 32768)
         raises(ValueError, field.encode, -32769)
Ejemplo n.º 5
0
 def test_error_checking_signed(self):
     for b in range(0, 17):
         field = Field("test", b, 15+b, 'signed')
         assert field.decode(field.encode(0)) == 0
         assert field.decode(field.encode(-32768)) == -32768
         assert field.decode(field.encode(32767)) == 32767
         raises(ValueError, field.encode, 32768)
         raises(ValueError, field.encode, -32769)
Ejemplo n.º 6
0
 def test_decode(self):
     # this test is crappy
     field = Field("test", 0, 31)
     for i in range(100):
         j = random.randrange(maxppcint)
         assert field.decode(j) == j
     field = Field("test", 0, 31 - 4)
     for i in range(100):
         j = random.randrange(maxppcint)
         assert field.decode(j) == j >> 4
         assert field.decode(j) == j >> 4
     field = Field("test", 3, 31 - 4)
     for i in range(100):
         j = random.randrange(maxppcint >> 3)
         assert field.decode(j) == j >> 4
Ejemplo n.º 7
0
 def test_error_checking_unsigned(self):
     for b in range(0, 17):
         field = Field("test", b, 15 + b)
         assert field.decode(field.encode(0)) == 0
         assert field.decode(field.encode(32768)) == 32768
         assert field.decode(field.encode(65535)) == 65535
         raises(ValueError, field.encode, -32768)
         raises(ValueError, field.encode, -1)
         raises(ValueError, field.encode, 65536)
Ejemplo n.º 8
0
 def test_decode(self):
     # this test is crappy
     field = Field("test", 0, 31)
     for i in range(100):
         j = random.randrange(maxppcint)
         assert field.decode(j) == j
     field = Field("test", 0, 31-4)
     for i in range(100):
         j = random.randrange(maxppcint)
         assert field.decode(j) == j>>4
         assert field.decode(j) == j>>4
     field = Field("test", 3, 31-4)
     for i in range(100):
         j = random.randrange(maxppcint>>3)
         assert field.decode(j) == j>>4
Ejemplo n.º 9
0
 def test_decode_unsigned(self):
     field = Field("test", 16, 31)
     for i in range(1000):
         hi = long(random.randrange(0x10000)) << 16
         lo = long(random.randrange(0x10000))
         assert field.decode(hi|lo) == lo
Ejemplo n.º 10
0
 def test_decode_unsigned(self):
     field = Field("test", 16, 31)
     for i in range(1000):
         hi = long(random.randrange(0x10000)) << 16
         lo = long(random.randrange(0x10000))
         assert field.decode(hi | lo) == lo
Ejemplo n.º 11
0
 def test_bitclash(self):
     raises(FormException, TForm, 'h', 'hh')
     raises(FormException, TForm, Field('t1', 0, 0), Field('t2', 0, 0))
Ejemplo n.º 12
0
from py.test import raises

from rpython.jit.backend.ppc.form import Form, FormException
from rpython.jit.backend.ppc.field import Field
from rpython.jit.backend.ppc.opassembler import OpAssembler as Assembler

# 0                              31
# +-------------------------------+
# |       h       |       l       |
# +-------------------------------+
# |  hh   |  hl   |  lh   |  ll   |
# +-------------------------------+

test_fieldmap = {
    'l': Field('l', 16, 31),
    'h': Field('h', 0, 15),
    'll': Field('ll', 24, 31),
    'lh': Field('lh', 16, 23),
    'hl': Field('hl', 8, 15),
    'hh': Field('hh', 0, 7),
}


def p(a):
    import struct
    w = a.insts[-1].assemble()
    return struct.pack('>i', w)


class TForm(Form):
    fieldmap = test_fieldmap
Ejemplo n.º 13
0
    def decode(self, inst):
        value = super(mbe, self).decode(inst)
        return (value & 1) << 5 | (value >> 1 & 31)


class sh(Field):
    def encode(self, value):
        value = (value & 31) << 10 | (value & 32) >> 5
        return super(sh, self).encode(value)

    def decode(self, inst):
        value = super(sh, self).decode(inst)
        return (value & 32) << 5 | (value >> 10 & 31)


# other special fields?

ppc_fields = {
    "LI": IField("LI", *fields["LI"]),
    "BD": IField("BD", *fields["BD"]),
    "ds": IField("ds", *fields["ds"]),
    "mbe": mbe("mbe", *fields["mbe"]),
    "sh": sh("sh", *fields["sh"]),
    "spr": spr("spr", *fields["spr"]),
}

for f in fields:
    if f not in ppc_fields:
        ppc_fields[f] = Field(f, *fields[f])