| 1 |
from rpython.rtyper.lltypesystem import lltype, rffi |
| 2 |
|
| 3 |
from rpython.jit.backend.ppc.codebuilder import BasicPPCAssembler, PPCBuilder |
| 4 |
from rpython.jit.backend.ppc.regname import * |
| 5 |
from rpython.jit.backend.ppc.register import * |
| 6 |
from rpython.jit.backend.ppc import form |
| 7 |
from rpython.jit.backend import detect_cpu |
| 8 |
from rpython.jit.backend.ppc.arch import IS_PPC_32, IS_PPC_64, IS_BIG_ENDIAN |
| 9 |
from rpython.jit.backend.ppc.arch import WORD |
| 10 |
|
| 11 |
cpu = detect_cpu.autodetect() |
| 12 |
|
| 13 |
signed = lltype.Signed |
| 14 |
unsigned = lltype.Unsigned |
| 15 |
char = lltype.Char |
| 16 |
|
| 17 |
def vec_asmtest(memory=[]): |
| 18 |
def testmaker(test): |
| 19 |
def newtest(self): |
| 20 |
memory_ptrs = [] |
| 21 |
a = PPCBuilder() |
| 22 |
for (bytes, type, values) in memory: |
| 23 |
|
| 24 |
adr = lltype.malloc(rffi.CArray(char), bytes, flavor="raw") |
| 25 |
memory_ptrs.append(adr) |
| 26 |
address = adr |
| 27 |
for i,value in enumerate(values): |
| 28 |
rffi.cast(rffi.CArrayPtr(type), adr)[i] = rffi.cast(type, value) |
| 29 |
|
| 30 |
expected = test(self, a, *[rffi.cast(lltype.Signed, m) for m in memory_ptrs]) |
| 31 |
f = a.get_assembler_function() |
| 32 |
f() |
| 33 |
for expect, type, ptr in expected: |
| 34 |
value = rffi.cast(rffi.CArrayPtr(type), ptr)[0] |
| 35 |
assert value == expect |
| 36 |
|
| 37 |
while memory_ptrs: |
| 38 |
ptr = memory_ptrs.pop() |
| 39 |
lltype.free(ptr, flavor="raw") |
| 40 |
return newtest |
| 41 |
return testmaker |
| 42 |
|
| 43 |
|
| 44 |
class TestAssemble(object): |
| 45 |
""" |
| 46 |
See how tests are built in test_ppc.py |
| 47 |
|
| 48 |
Instead of asmtest, use vec_asmtest. It adds a parameter 'memory' that |
| 49 |
allocates memory. |
| 50 |
|
| 51 |
|
| 52 |
@vec_asmtest(memory=[(8, [1,2]), 'm2': (16, [1,2,3,4])]) |
| 53 |
def test(self, builder, m, m2): |
| 54 |
# ... |
| 55 |
return [ (value, type, ptr), ... ] |
| 56 |
""" |
| 57 |
def setup_class(cls): |
| 58 |
if cpu not in ["ppc", "ppc64", "ppc-64"]: |
| 59 |
py.test.skip("can't test all of ppcgen on non-PPC!") |
| 60 |
|
| 61 |
@vec_asmtest(memory=[(16, signed, [0,0])]) |
| 62 |
def test_unaligned_load(self, a, mem): |
| 63 |
a.load_imm(r15, mem) |
| 64 |
a.lxvd2x(0, 0, r15.value) |
| 65 |
a.blr() |
| 66 |
return [ (0, signed, mem), (0, signed, mem+8) ] |
| 67 |
|
| 68 |
@vec_asmtest(memory=[(16, signed, [1,2]), (16, signed, [0,0])]) |
| 69 |
def test_unaligned_load_and_store(self, a, mem_l, mem_t): |
| 70 |
a.load_imm(r15, mem_l) |
| 71 |
a.load_imm(r14, mem_t) |
| 72 |
a.lxvd2x(0, 0, r15.value) |
| 73 |
a.stxvd2x(0, 0, r14.value) |
| 74 |
a.blr() |
| 75 |
return [ (1, signed, mem_t), (2, signed, mem_t+8) ] |
| 76 |
|
| 77 |
def test_xx3_instr(self): |
| 78 |
a = PPCBuilder() |
| 79 |
def assign_to_self(v): |
| 80 |
self.last_value = v |
| 81 |
a.emit = assign_to_self |
| 82 |
|
| 83 |
a.xxspltdl(32, 32, 32) |
| 84 |
|
| 85 |
assert hex(int(self.last_value)) == hex(0b11110000000000000000000001010111) |
| 86 |
a.xxspltdl(32, 2, 2) |
| 87 |
|
| 88 |
assert hex(int(self.last_value)) == hex(0b11110000000000100001000001010001) |
| 89 |
a.xxspltdl(0, 63, 0) |
| 90 |
|
| 91 |
assert hex(int(self.last_value)) == hex(0b11110000000111110000000001010100) |
| 92 |
a.xxspltdl(0, 0, 63) |
| 93 |
|
| 94 |
assert hex(int(self.last_value)) == hex(0b11110000000000001111100001010010) |
| 95 |
|