From 953c08839f330eb8e3c04eb8829a61cad21886a9 Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 20 Nov 2016 12:53:44 +0100 Subject: [PATCH] inn works now; add a helper for it. --- mach/powerpc/libem/build.lua | 1 + mach/powerpc/libem/inn.s | 26 ++++++++++++ mach/proto/mcg/treebuilder.c | 9 ++--- plat/qemuppc/tests/inn_e.e | 76 ++++++++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 mach/powerpc/libem/inn.s create mode 100644 plat/qemuppc/tests/inn_e.e diff --git a/mach/powerpc/libem/build.lua b/mach/powerpc/libem/build.lua index dd9ec7542..318be381d 100644 --- a/mach/powerpc/libem/build.lua +++ b/mach/powerpc/libem/build.lua @@ -8,6 +8,7 @@ for _, plat in ipairs(vars.plats) do name = "lib_"..plat, srcs = { "./*.s", + "./*.e", }, vars = { plat = plat }, deps = { diff --git a/mach/powerpc/libem/inn.s b/mach/powerpc/libem/inn.s new file mode 100644 index 000000000..f5ae4c63e --- /dev/null +++ b/mach/powerpc/libem/inn.s @@ -0,0 +1,26 @@ +#include "powerpc.h" + +.sect .text + +/* Tests a bit in a bitset on the stack. + * + * Stack: ( bitset bitnum setsize -- bool ) + */ + +.define .inn +.inn: + lwz r3, 0(sp) /* r3 = size (bytes) */ + lwz r4, 4(sp) /* r4 = bit number */ + addi r5, sp, 8 /* r5 = base address of bit set */ + + srawi r6, r4, 3 /* r6 = byte address into set */ + andi. r7, r4, 7 /* r7 = bit within byte */ + + lbzx r8, r5, r6 /* r8 = individual byte from set */ + sraw r8, r8, r7 + rlwinm r8, r8, 0, 31, 31 + + addi sp, sp, 8 /* retract over the two words */ + add sp, sp, r3 /* retract over bitfield */ + stwu r8, -4(sp) /* push result */ + bclr ALWAYS, 0, 0 /* return */ diff --git a/mach/proto/mcg/treebuilder.c b/mach/proto/mcg/treebuilder.c index 18e77c94a..2ead527fc 100644 --- a/mach/proto/mcg/treebuilder.c +++ b/mach/proto/mcg/treebuilder.c @@ -1447,12 +1447,11 @@ static void insn_ivalue(int opcode, arith value) * (Modula-2 bitset support, I believe). Leave them until leter. */ case op_inn: { - appendir( - new_ir1( - IR_CALL, 0, - new_labelir(".unimplemented") - ) + push( + new_wordir(value) ); + + helper_function(".inn"); break; } diff --git a/plat/qemuppc/tests/inn_e.e b/plat/qemuppc/tests/inn_e.e new file mode 100644 index 000000000..4e53b35c5 --- /dev/null +++ b/plat/qemuppc/tests/inn_e.e @@ -0,0 +1,76 @@ +# + mes 2, 4, 4 + + exp $_m_a_i_n + pro $_m_a_i_n, 0 + + /* Test non-existent bit */ + +.1 + rom 0I1, 0I1, 0I1, 0I1 + loe .1 + loc 1 /* bit number */ + inn 4 + zeq *1 + + loc __LINE__ + cal $fail + ass 4 +1 + + /* Test existent bit */ + +.2 + rom 2I1, 0I1, 0I1, 0I1 + loe .2 + loc 1 /* bit number */ + inn 4 + zne *2 + + loc __LINE__ + cal $fail + ass 4 +2 + + /* Test non-existent high bit */ + +.3 + rom 0I1, 0I1, 0I1, 0I1 + rom 0I1, 0I1, 0I1, 0I1 +.31 + rom 33 /* to defeat constant folding */ + + lae .3 + loi 8 + loe .31 /* bit number */ + inn 8 + zeq *3 + + loc __LINE__ + cal $fail + ass 4 +3 + + /* Test existent high bit */ + +.4 + rom 0I1, 0I1, 0I1, 0I1 + rom 2I1, 0I1, 0I1, 0I1 +.41 + rom 33 /* to defeat constant folding */ + + lae .4 + loi 8 + loe .41 /* bit number */ + inn 8 + zne *4 + + loc __LINE__ + cal $fail + ass 4 +4 + + cal $finished + ret 0 + + end