2016-09-17 22:02:16 +00:00
|
|
|
#include "mcg.h"
|
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
static struct basicblock* current_bb;
|
2016-09-18 21:24:54 +00:00
|
|
|
|
|
|
|
static int stackptr;
|
|
|
|
static struct ir* stack[64];
|
|
|
|
|
2018-09-19 22:12:03 +00:00
|
|
|
struct jumptable
|
|
|
|
{
|
|
|
|
struct basicblock* defaulttarget;
|
|
|
|
IMAPOF(struct basicblock) targets;
|
|
|
|
};
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
static struct ir* convert(struct ir* src, int srcsize, int destsize, int opcode);
|
2016-09-19 21:06:59 +00:00
|
|
|
static struct ir* appendir(struct ir* ir);
|
2016-11-20 10:57:21 +00:00
|
|
|
static void insn_ivalue(int opcode, arith value);
|
2016-09-19 21:06:59 +00:00
|
|
|
|
2018-09-19 22:12:03 +00:00
|
|
|
static void parse_csa(struct basicblock* data_bb, struct jumptable* table);
|
|
|
|
static void parse_csb(struct basicblock* data_bb, struct jumptable* table);
|
|
|
|
static void emit_jumptable(struct ir* targetvalue, struct jumptable* table);
|
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
static void reset_stack(void)
|
2016-09-17 22:02:16 +00:00
|
|
|
{
|
2016-09-18 21:24:54 +00:00
|
|
|
stackptr = 0;
|
2016-09-17 22:02:16 +00:00
|
|
|
}
|
|
|
|
|
2016-09-18 21:24:54 +00:00
|
|
|
static void push(struct ir* ir)
|
2016-09-17 22:02:16 +00:00
|
|
|
{
|
2016-09-18 21:24:54 +00:00
|
|
|
if (stackptr == sizeof(stack)/sizeof(*stack))
|
|
|
|
fatal("stack overflow");
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
#if 0
|
2016-09-19 21:06:59 +00:00
|
|
|
/* If we try to push something which is too small, convert it to a word
|
|
|
|
* first. */
|
2016-09-17 22:02:16 +00:00
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
if (ir->size < EM_wordsize)
|
2016-10-23 19:54:14 +00:00
|
|
|
ir = convertu(ir, EM_wordsize);
|
|
|
|
#endif
|
2016-09-18 21:24:54 +00:00
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
stack[stackptr++] = ir;
|
2016-09-17 22:02:16 +00:00
|
|
|
}
|
|
|
|
|
2017-01-07 17:47:00 +00:00
|
|
|
/* Returns the size of the top item on the stack. */
|
|
|
|
static int peek(int delta)
|
|
|
|
{
|
|
|
|
if (stackptr <= delta)
|
|
|
|
return EM_wordsize;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct ir* ir = stack[stackptr-1-delta];
|
|
|
|
return ir->size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
static struct ir* pop(int size)
|
2016-09-17 22:02:16 +00:00
|
|
|
{
|
2016-10-23 19:54:14 +00:00
|
|
|
if (size < EM_wordsize)
|
|
|
|
size = EM_wordsize;
|
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
if (stackptr == 0)
|
|
|
|
{
|
|
|
|
/* Nothing in our fake stack, so we have to read from the real stack. */
|
2016-09-18 21:24:54 +00:00
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
if (size < EM_wordsize)
|
|
|
|
size = EM_wordsize;
|
|
|
|
return
|
2016-09-21 22:15:48 +00:00
|
|
|
appendir(
|
|
|
|
new_ir0(
|
|
|
|
IR_POP, size
|
|
|
|
)
|
2016-09-19 21:06:59 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct ir* ir = stack[--stackptr];
|
2016-09-17 22:02:16 +00:00
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
#if 0
|
2016-09-19 21:06:59 +00:00
|
|
|
/* If we try to pop something which is smaller than a word, convert it first. */
|
2017-01-15 21:28:14 +00:00
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
if (size < EM_wordsize)
|
2016-10-23 19:54:14 +00:00
|
|
|
ir = convertu(ir, size);
|
|
|
|
#endif
|
2016-09-19 21:06:59 +00:00
|
|
|
if (ir->size != size)
|
2016-10-29 10:48:05 +00:00
|
|
|
{
|
|
|
|
if ((size == (EM_wordsize*2)) && (ir->size == EM_wordsize))
|
|
|
|
{
|
|
|
|
/* Tried to read a long, but we got an int. Assemble the long
|
|
|
|
* out of two ints. Note that EM doesn't specify an order. */
|
|
|
|
return
|
|
|
|
new_ir2(
|
|
|
|
IR_FROMIPAIR, size,
|
|
|
|
ir,
|
|
|
|
pop(EM_wordsize)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else if ((size == EM_wordsize) && (ir->size == (EM_wordsize*2)))
|
|
|
|
{
|
2018-09-18 21:32:53 +00:00
|
|
|
appendir(ir);
|
|
|
|
|
2016-10-29 10:48:05 +00:00
|
|
|
/* Tried to read an int, but we got a long. */
|
|
|
|
push(
|
|
|
|
new_ir1(
|
|
|
|
IR_FROML1, EM_wordsize,
|
|
|
|
ir
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return
|
|
|
|
new_ir1(
|
|
|
|
IR_FROML0, EM_wordsize,
|
|
|
|
ir
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fatal("expected an item on stack of size %d, but got %d\n", size, ir->size);
|
|
|
|
}
|
2016-09-19 21:06:59 +00:00
|
|
|
return ir;
|
|
|
|
}
|
2016-09-17 22:02:16 +00:00
|
|
|
}
|
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
static void print_stack(void)
|
2016-09-17 22:02:16 +00:00
|
|
|
{
|
2016-09-18 21:24:54 +00:00
|
|
|
int i;
|
|
|
|
|
2016-09-21 22:15:48 +00:00
|
|
|
tracef('E', "E: stack:");
|
2016-09-18 21:24:54 +00:00
|
|
|
for (i=0; i<stackptr; i++)
|
2016-09-19 21:06:59 +00:00
|
|
|
{
|
|
|
|
struct ir* ir = stack[i];
|
2016-09-21 22:15:48 +00:00
|
|
|
tracef('E', " $%d.%d", ir->id, ir->size);
|
2016-09-19 21:06:59 +00:00
|
|
|
}
|
2016-09-21 22:15:48 +00:00
|
|
|
tracef('E', " (top)\n");
|
|
|
|
}
|
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
static struct ir* appendir(struct ir* ir)
|
2016-09-17 22:02:16 +00:00
|
|
|
{
|
2016-09-18 21:24:54 +00:00
|
|
|
int i;
|
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
assert(current_bb != NULL);
|
2016-10-11 22:45:36 +00:00
|
|
|
array_appendu(¤t_bb->irs, ir);
|
2016-09-18 21:24:54 +00:00
|
|
|
|
2016-09-21 22:15:48 +00:00
|
|
|
ir_print('0', ir);
|
2016-09-19 21:06:59 +00:00
|
|
|
return ir;
|
2016-09-17 22:02:16 +00:00
|
|
|
}
|
|
|
|
|
2017-01-07 12:17:39 +00:00
|
|
|
static void sequence_point(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Ensures that any partially-evaluated expressions on the stack are executed right
|
|
|
|
* now. This typically needs to happen before store operations, to prevents loads of
|
|
|
|
* the same address being delayed until after the store (at which point they'll
|
|
|
|
* return incorrect values).
|
|
|
|
*/
|
|
|
|
|
|
|
|
assert(current_bb != NULL);
|
|
|
|
|
|
|
|
for (i=0; i<stackptr; i++)
|
|
|
|
{
|
|
|
|
struct ir* ir = stack[i];
|
|
|
|
array_appendu(¤t_bb->irs, ir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
static void materialise_stack(void)
|
2016-09-17 22:02:16 +00:00
|
|
|
{
|
2016-09-19 21:06:59 +00:00
|
|
|
int i;
|
2016-09-18 21:24:54 +00:00
|
|
|
|
2016-09-19 22:19:39 +00:00
|
|
|
for (i=0; i<stackptr; i++)
|
2016-09-18 21:24:54 +00:00
|
|
|
{
|
2016-09-19 21:06:59 +00:00
|
|
|
struct ir* ir = stack[i];
|
|
|
|
appendir(
|
|
|
|
new_ir1(
|
|
|
|
IR_PUSH, ir->size,
|
|
|
|
ir
|
|
|
|
)
|
|
|
|
);
|
2016-09-18 21:24:54 +00:00
|
|
|
}
|
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
reset_stack();
|
2016-09-17 22:02:16 +00:00
|
|
|
}
|
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
void tb_filestart(void)
|
2016-09-17 22:02:16 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
void tb_fileend(void)
|
2016-09-17 22:02:16 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-01 22:30:33 +00:00
|
|
|
void tb_regvar(struct procedure* procedure, arith offset, int size, int type, int priority)
|
2016-09-17 22:02:16 +00:00
|
|
|
{
|
2016-10-01 22:30:33 +00:00
|
|
|
struct local* local = calloc(1, sizeof(*local));
|
|
|
|
local->size = size;
|
2016-10-02 14:08:46 +00:00
|
|
|
local->offset = offset;
|
2016-10-01 22:30:33 +00:00
|
|
|
local->is_register = true;
|
|
|
|
imap_put(&procedure->locals, offset, local);
|
2016-09-17 22:02:16 +00:00
|
|
|
}
|
|
|
|
|
2016-09-19 22:19:39 +00:00
|
|
|
static struct ir* address_of_external(const char* label, arith offset)
|
|
|
|
{
|
|
|
|
if (offset != 0)
|
|
|
|
return
|
|
|
|
new_ir2(
|
|
|
|
IR_ADD, EM_pointersize,
|
|
|
|
new_labelir(label),
|
|
|
|
new_wordir(offset)
|
|
|
|
);
|
|
|
|
else
|
|
|
|
return
|
|
|
|
new_labelir(label);
|
|
|
|
}
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
static struct ir* convert(struct ir* src, int srcsize, int destsize, int opcode)
|
2016-09-18 21:24:54 +00:00
|
|
|
{
|
2017-01-15 21:28:14 +00:00
|
|
|
if (srcsize == 1)
|
2016-09-18 21:24:54 +00:00
|
|
|
{
|
2016-10-23 19:54:14 +00:00
|
|
|
if ((opcode == IR_FROMSI) || (opcode == IR_FROMSL))
|
|
|
|
{
|
|
|
|
src = new_ir1(
|
|
|
|
IR_EXTENDB, EM_wordsize,
|
|
|
|
src
|
|
|
|
);
|
|
|
|
}
|
|
|
|
srcsize = EM_wordsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((srcsize == 2) && (srcsize != EM_wordsize))
|
|
|
|
{
|
|
|
|
if ((opcode == IR_FROMSI) || (opcode == IR_FROMSL))
|
|
|
|
{
|
|
|
|
src = new_ir1(
|
|
|
|
IR_EXTENDH, EM_wordsize,
|
|
|
|
src
|
|
|
|
);
|
|
|
|
}
|
|
|
|
srcsize = EM_wordsize;
|
2016-09-18 21:24:54 +00:00
|
|
|
}
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
if (src->size == EM_wordsize)
|
|
|
|
{}
|
|
|
|
else if (src->size == (2*EM_wordsize))
|
|
|
|
opcode++;
|
|
|
|
else
|
|
|
|
fatal("can't convert from %d to %d", src->size, destsize);
|
|
|
|
|
2016-09-18 21:24:54 +00:00
|
|
|
return
|
|
|
|
new_ir1(
|
|
|
|
opcode, destsize,
|
2016-09-19 21:06:59 +00:00
|
|
|
src
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-10-21 22:48:26 +00:00
|
|
|
static struct ir* compare(struct ir* left, struct ir* right,
|
|
|
|
int size, int opcode)
|
2016-09-19 21:06:59 +00:00
|
|
|
{
|
2016-10-23 19:54:14 +00:00
|
|
|
if (size == EM_wordsize)
|
|
|
|
{}
|
|
|
|
else if (size == (2*EM_wordsize))
|
|
|
|
opcode++;
|
|
|
|
else
|
|
|
|
fatal("can't compare things of size %d", size);
|
2016-09-19 21:06:59 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
new_ir2(
|
2016-09-21 22:15:48 +00:00
|
|
|
opcode, EM_wordsize,
|
2016-09-19 21:06:59 +00:00
|
|
|
left, right
|
2016-09-18 21:24:54 +00:00
|
|
|
);
|
2016-09-17 22:02:16 +00:00
|
|
|
}
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
static struct ir* store(int size, struct ir* address, int offset, struct ir* value)
|
|
|
|
{
|
|
|
|
int opcode;
|
|
|
|
|
2017-01-07 12:17:39 +00:00
|
|
|
sequence_point();
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
if (size == 1)
|
|
|
|
{
|
|
|
|
opcode = IR_STOREB;
|
|
|
|
size = EM_wordsize;
|
|
|
|
}
|
|
|
|
else if ((size < EM_wordsize) && (size == 2))
|
|
|
|
{
|
|
|
|
opcode = IR_STOREH;
|
|
|
|
size = EM_wordsize;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
opcode = IR_STORE;
|
|
|
|
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
if (offset != 0)
|
2016-10-23 19:54:14 +00:00
|
|
|
address = new_ir2(
|
|
|
|
IR_ADD, EM_pointersize,
|
|
|
|
address, new_wordir(offset)
|
|
|
|
);
|
|
|
|
|
|
|
|
return
|
|
|
|
new_ir2(
|
|
|
|
opcode, size,
|
|
|
|
address, value
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ir* load(int size, struct ir* address, int offset)
|
|
|
|
{
|
|
|
|
int opcode;
|
|
|
|
|
|
|
|
if (size == 1)
|
|
|
|
{
|
|
|
|
opcode = IR_LOADB;
|
|
|
|
size = EM_wordsize;
|
|
|
|
}
|
|
|
|
else if ((size < EM_wordsize) && (size == 2))
|
|
|
|
{
|
|
|
|
opcode = IR_LOADH;
|
|
|
|
size = EM_wordsize;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
opcode = IR_LOAD;
|
|
|
|
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
if (offset != 0)
|
2016-10-23 19:54:14 +00:00
|
|
|
address = new_ir2(
|
|
|
|
IR_ADD, EM_pointersize,
|
|
|
|
address, new_wordir(offset)
|
|
|
|
);
|
|
|
|
|
|
|
|
return
|
|
|
|
new_ir1(
|
|
|
|
opcode, size,
|
|
|
|
address
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-10-21 22:48:26 +00:00
|
|
|
static struct ir* tristate_compare(int size, int opcode)
|
|
|
|
{
|
|
|
|
struct ir* right = pop(size);
|
|
|
|
struct ir* left = pop(size);
|
|
|
|
|
|
|
|
return compare(left, right, size, opcode);
|
|
|
|
}
|
|
|
|
|
2016-10-22 18:32:51 +00:00
|
|
|
static struct ir* tristate_compare0(int size, int opcode)
|
|
|
|
{
|
|
|
|
struct ir* right = new_wordir(0);
|
|
|
|
struct ir* left = pop(size);
|
|
|
|
|
|
|
|
return compare(left, right, size, opcode);
|
|
|
|
}
|
|
|
|
|
2016-09-19 22:19:39 +00:00
|
|
|
static void simple_convert(int opcode)
|
2016-09-19 21:30:41 +00:00
|
|
|
{
|
|
|
|
struct ir* destsize = pop(EM_wordsize);
|
|
|
|
struct ir* srcsize = pop(EM_wordsize);
|
|
|
|
struct ir* value;
|
|
|
|
|
2016-09-21 22:15:48 +00:00
|
|
|
assert(srcsize->opcode == IR_CONST);
|
|
|
|
assert(destsize->opcode == IR_CONST);
|
2016-09-19 21:30:41 +00:00
|
|
|
|
|
|
|
value = pop(srcsize->u.ivalue);
|
|
|
|
push(
|
2016-10-23 19:54:14 +00:00
|
|
|
convert(value, srcsize->u.ivalue, destsize->u.ivalue, opcode)
|
2016-09-19 21:30:41 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-10-22 18:32:51 +00:00
|
|
|
static void simple_branch2(int opcode, int size,
|
|
|
|
struct basicblock* truebb, struct basicblock* falsebb,
|
|
|
|
int irop)
|
|
|
|
{
|
|
|
|
struct ir* right = pop(size);
|
|
|
|
struct ir* left = pop(size);
|
|
|
|
|
|
|
|
materialise_stack();
|
|
|
|
appendir(
|
|
|
|
new_ir2(
|
|
|
|
irop, 0,
|
2016-10-23 19:54:14 +00:00
|
|
|
compare(left, right, size, IR_COMPARESI),
|
2016-10-22 18:32:51 +00:00
|
|
|
new_ir2(
|
|
|
|
IR_PAIR, 0,
|
|
|
|
new_bbir(truebb),
|
|
|
|
new_bbir(falsebb)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void compare0_branch2(int opcode,
|
|
|
|
struct basicblock* truebb, struct basicblock* falsebb,
|
|
|
|
int irop)
|
|
|
|
{
|
|
|
|
push(
|
|
|
|
new_wordir(0)
|
|
|
|
);
|
|
|
|
|
|
|
|
simple_branch2(opcode, EM_wordsize, truebb, falsebb, irop);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void simple_test(int size, int irop)
|
|
|
|
{
|
|
|
|
push(
|
|
|
|
new_ir1(
|
|
|
|
irop, EM_wordsize,
|
2016-10-23 19:54:14 +00:00
|
|
|
tristate_compare0(size, IR_COMPARESI)
|
2016-10-22 18:32:51 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void simple_test_neg(int size, int irop)
|
|
|
|
{
|
|
|
|
simple_test(size, irop);
|
|
|
|
|
|
|
|
push(
|
|
|
|
new_ir1(
|
|
|
|
IR_NOT, EM_wordsize,
|
|
|
|
pop(EM_wordsize)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-10-29 09:57:56 +00:00
|
|
|
static void helper_function(const char* name)
|
|
|
|
{
|
|
|
|
/* Delegates to a helper function; these leave their result on the stack
|
|
|
|
* rather than returning values through lfr. */
|
|
|
|
|
|
|
|
materialise_stack();
|
|
|
|
appendir(
|
|
|
|
new_ir1(
|
|
|
|
IR_CALL, 0,
|
|
|
|
new_labelir(name)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
static void helper_function_with_arg(const char* name, struct ir* arg)
|
|
|
|
{
|
|
|
|
/* Abuses IR_SETRET to set a register to pass one argument to a
|
|
|
|
* helper function.
|
|
|
|
*
|
|
|
|
* FIXME: As of January 2018, mach/powerpc/libem takes an
|
|
|
|
* argument in register r3 only for ".los4", ".sts4", ".trp".
|
|
|
|
* This is an accident. Should the argument be on the stack, or
|
|
|
|
* should other helpers use a register? */
|
|
|
|
|
|
|
|
materialise_stack();
|
|
|
|
appendir(
|
|
|
|
new_ir1(
|
|
|
|
IR_SETRET, arg->size,
|
|
|
|
arg
|
|
|
|
)
|
|
|
|
);
|
|
|
|
appendir(
|
|
|
|
new_ir1(
|
|
|
|
IR_CALL, 0,
|
|
|
|
new_labelir(name)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
static void insn_simple(int opcode)
|
2016-09-17 22:02:16 +00:00
|
|
|
{
|
2016-09-18 21:24:54 +00:00
|
|
|
switch (opcode)
|
|
|
|
{
|
2016-09-19 21:30:41 +00:00
|
|
|
case op_bra:
|
2016-09-18 21:24:54 +00:00
|
|
|
{
|
2016-09-19 21:30:41 +00:00
|
|
|
struct ir* dest = pop(EM_pointersize);
|
2016-09-18 21:24:54 +00:00
|
|
|
|
2016-09-19 21:30:41 +00:00
|
|
|
materialise_stack();
|
|
|
|
appendir(
|
|
|
|
new_ir1(
|
|
|
|
IR_JUMP, 0,
|
|
|
|
dest
|
|
|
|
)
|
2016-09-18 21:24:54 +00:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
2017-01-15 21:28:14 +00:00
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
case op_cii: simple_convert(IR_FROMSI); break;
|
|
|
|
case op_ciu: simple_convert(IR_FROMSI); break;
|
|
|
|
case op_cui: simple_convert(IR_FROMUI); break;
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
case op_cuu: simple_convert(IR_FROMUI); break;
|
2016-11-20 10:27:40 +00:00
|
|
|
case op_cfu: simple_convert(IR_FROMUF); break;
|
|
|
|
case op_cfi: simple_convert(IR_FROMSF); break;
|
2016-10-23 19:54:14 +00:00
|
|
|
case op_cif: simple_convert(IR_FROMSI); break;
|
2016-10-29 09:57:56 +00:00
|
|
|
case op_cuf: simple_convert(IR_FROMUI); break;
|
2016-11-20 10:27:40 +00:00
|
|
|
case op_cff: simple_convert(IR_FROMSF); break;
|
2016-09-18 21:24:54 +00:00
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
case op_cmp:
|
|
|
|
push(
|
2016-10-23 19:54:14 +00:00
|
|
|
tristate_compare(EM_pointersize, IR_COMPAREUI)
|
2016-09-19 21:06:59 +00:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2016-10-23 20:24:08 +00:00
|
|
|
case op_teq: simple_test( EM_wordsize, IR_IFEQ); break;
|
2016-10-22 18:32:51 +00:00
|
|
|
case op_tne: simple_test_neg(EM_wordsize, IR_IFEQ); break;
|
2016-10-23 20:24:08 +00:00
|
|
|
case op_tlt: simple_test( EM_wordsize, IR_IFLT); break;
|
|
|
|
case op_tge: simple_test_neg(EM_wordsize, IR_IFLT); break;
|
|
|
|
case op_tle: simple_test( EM_wordsize, IR_IFLE); break;
|
|
|
|
case op_tgt: simple_test_neg(EM_wordsize, IR_IFLE); break;
|
2016-10-15 11:07:59 +00:00
|
|
|
|
2016-09-19 21:30:41 +00:00
|
|
|
case op_cai:
|
|
|
|
{
|
|
|
|
struct ir* dest = pop(EM_pointersize);
|
|
|
|
|
|
|
|
materialise_stack();
|
2016-10-29 09:57:56 +00:00
|
|
|
appendir(
|
2016-09-19 21:30:41 +00:00
|
|
|
new_ir1(
|
|
|
|
IR_CALL, 0,
|
|
|
|
dest
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
2016-10-10 22:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case op_inc:
|
|
|
|
{
|
|
|
|
push(
|
|
|
|
new_ir2(
|
|
|
|
IR_ADD, EM_wordsize,
|
|
|
|
pop(EM_wordsize),
|
|
|
|
new_wordir(1)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case op_dec:
|
|
|
|
{
|
|
|
|
push(
|
|
|
|
new_ir2(
|
|
|
|
IR_SUB, EM_wordsize,
|
|
|
|
pop(EM_wordsize),
|
|
|
|
new_wordir(1)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
2016-09-19 21:30:41 +00:00
|
|
|
}
|
|
|
|
|
2016-10-15 11:07:59 +00:00
|
|
|
case op_lim:
|
|
|
|
{
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
/* Traps use only 16 bits of .ignmask, but we keep an
|
|
|
|
* entire word, even if a word has more than 2 bytes. */
|
2016-10-15 11:07:59 +00:00
|
|
|
push(
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
load(
|
|
|
|
EM_wordsize,
|
|
|
|
new_labelir(".ignmask"), 0
|
2016-10-15 11:07:59 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case op_sim:
|
|
|
|
{
|
|
|
|
appendir(
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
store(
|
|
|
|
EM_wordsize,
|
|
|
|
new_labelir(".ignmask"), 0,
|
2016-10-15 11:07:59 +00:00
|
|
|
pop(EM_wordsize)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
case op_trp:
|
|
|
|
helper_function_with_arg(".trp", pop(EM_wordsize));
|
|
|
|
break;
|
2017-01-17 21:31:38 +00:00
|
|
|
|
|
|
|
case op_sig:
|
|
|
|
{
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
struct ir* label = new_labelir(".trppc");
|
2017-01-17 21:31:38 +00:00
|
|
|
struct ir* value = pop(EM_pointersize);
|
2018-09-18 21:32:53 +00:00
|
|
|
appendir(label); /* because we need to use label twice */
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
push(
|
|
|
|
load(
|
|
|
|
EM_pointersize,
|
|
|
|
label, 0
|
|
|
|
)
|
|
|
|
);
|
2017-01-17 21:31:38 +00:00
|
|
|
appendir(
|
|
|
|
store(
|
|
|
|
EM_pointersize,
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
label, 0,
|
2017-01-17 21:31:38 +00:00
|
|
|
value
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
2016-11-20 10:57:21 +00:00
|
|
|
|
|
|
|
case op_rtt:
|
|
|
|
{
|
|
|
|
insn_ivalue(op_ret, 0);
|
|
|
|
break;
|
|
|
|
}
|
2016-10-29 09:57:56 +00:00
|
|
|
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
case op_and: helper_function(".and"); break;
|
|
|
|
case op_ior: helper_function(".ior"); break;
|
|
|
|
case op_xor: helper_function(".xor"); break;
|
|
|
|
case op_com: helper_function(".com"); break;
|
|
|
|
case op_cms: helper_function(".cms"); break;
|
|
|
|
case op_set: helper_function(".set"); break;
|
|
|
|
case op_inn: helper_function(".inn"); break;
|
2017-01-15 21:28:14 +00:00
|
|
|
|
2016-10-29 09:57:56 +00:00
|
|
|
case op_dch:
|
|
|
|
push(
|
2016-10-21 22:48:26 +00:00
|
|
|
new_ir1(
|
2016-10-29 09:57:56 +00:00
|
|
|
IR_CHAINFP, EM_pointersize,
|
|
|
|
pop(EM_pointersize)
|
2016-10-21 22:48:26 +00:00
|
|
|
)
|
|
|
|
);
|
2016-10-21 22:48:55 +00:00
|
|
|
break;
|
2017-01-15 21:28:14 +00:00
|
|
|
|
2016-10-29 09:57:56 +00:00
|
|
|
case op_lpb:
|
|
|
|
push(
|
2016-10-23 20:24:08 +00:00
|
|
|
new_ir1(
|
2016-10-29 09:57:56 +00:00
|
|
|
IR_FPTOAB, EM_pointersize,
|
|
|
|
pop(EM_pointersize)
|
2016-10-23 20:24:08 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2016-10-15 11:07:59 +00:00
|
|
|
case op_lni:
|
|
|
|
{
|
|
|
|
/* Increment line number --- ignore. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-18 21:24:54 +00:00
|
|
|
default:
|
2016-09-19 21:06:59 +00:00
|
|
|
fatal("treebuilder: unknown simple instruction '%s'",
|
2016-09-18 21:24:54 +00:00
|
|
|
em_mnem[opcode - sp_fmnem]);
|
|
|
|
}
|
2016-09-17 22:02:16 +00:00
|
|
|
}
|
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
static void insn_bvalue(int opcode, struct basicblock* leftbb, struct basicblock* rightbb)
|
|
|
|
{
|
|
|
|
switch (opcode)
|
|
|
|
{
|
2016-09-24 20:46:08 +00:00
|
|
|
case op_zeq: compare0_branch2(opcode, leftbb, rightbb, IR_CJUMPEQ); break;
|
|
|
|
case op_zlt: compare0_branch2(opcode, leftbb, rightbb, IR_CJUMPLT); break;
|
|
|
|
case op_zle: compare0_branch2(opcode, leftbb, rightbb, IR_CJUMPLE); break;
|
2016-09-19 21:06:59 +00:00
|
|
|
|
2016-09-24 20:46:08 +00:00
|
|
|
case op_zne: compare0_branch2(opcode, rightbb, leftbb, IR_CJUMPEQ); break;
|
|
|
|
case op_zge: compare0_branch2(opcode, rightbb, leftbb, IR_CJUMPLT); break;
|
|
|
|
case op_zgt: compare0_branch2(opcode, rightbb, leftbb, IR_CJUMPLE); break;
|
2016-09-18 21:24:54 +00:00
|
|
|
|
2016-10-04 21:28:16 +00:00
|
|
|
case op_beq: simple_branch2(opcode, EM_wordsize, leftbb, rightbb, IR_CJUMPEQ); break;
|
|
|
|
case op_blt: simple_branch2(opcode, EM_wordsize, leftbb, rightbb, IR_CJUMPLT); break;
|
|
|
|
case op_ble: simple_branch2(opcode, EM_wordsize, leftbb, rightbb, IR_CJUMPLE); break;
|
|
|
|
|
|
|
|
case op_bne: simple_branch2(opcode, EM_wordsize, rightbb, leftbb, IR_CJUMPEQ); break;
|
|
|
|
case op_bge: simple_branch2(opcode, EM_wordsize, rightbb, leftbb, IR_CJUMPLT); break;
|
|
|
|
case op_bgt: simple_branch2(opcode, EM_wordsize, rightbb, leftbb, IR_CJUMPLE); break;
|
|
|
|
|
2016-09-18 21:24:54 +00:00
|
|
|
case op_bra:
|
|
|
|
{
|
2016-09-19 21:06:59 +00:00
|
|
|
materialise_stack();
|
2016-09-18 21:24:54 +00:00
|
|
|
|
|
|
|
appendir(
|
|
|
|
new_ir1(
|
|
|
|
IR_JUMP, 0,
|
2016-09-19 21:06:59 +00:00
|
|
|
new_bbir(leftbb)
|
2016-09-18 21:24:54 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-23 23:04:00 +00:00
|
|
|
case op_lae:
|
|
|
|
push(
|
|
|
|
new_bbir(leftbb)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2016-09-18 21:24:54 +00:00
|
|
|
default:
|
2016-09-19 21:06:59 +00:00
|
|
|
fatal("treebuilder: unknown bvalue instruction '%s'",
|
2016-09-18 21:24:54 +00:00
|
|
|
em_mnem[opcode - sp_fmnem]);
|
|
|
|
}
|
2016-09-17 22:02:16 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 21:28:14 +00:00
|
|
|
static void simple_alu1(int opcode, int size, int irop, const char* fallback)
|
2016-09-19 21:06:59 +00:00
|
|
|
{
|
2017-01-15 21:28:14 +00:00
|
|
|
if (size > (2*EM_wordsize))
|
|
|
|
{
|
|
|
|
if (!fallback)
|
2017-01-17 21:31:38 +00:00
|
|
|
fatal("treebuilder: can't do opcode %s with size %d", em_mnem[opcode - sp_fmnem], size);
|
2017-01-15 21:28:14 +00:00
|
|
|
push(
|
|
|
|
new_wordir(size)
|
|
|
|
);
|
|
|
|
helper_function(fallback);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct ir* val = pop(size);
|
2016-09-19 21:06:59 +00:00
|
|
|
|
2017-01-15 21:28:14 +00:00
|
|
|
push(
|
|
|
|
new_ir1(
|
|
|
|
irop, size,
|
|
|
|
val
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2016-09-19 21:06:59 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 21:28:14 +00:00
|
|
|
static void simple_alu2(int opcode, int size, int irop, const char* fallback)
|
2016-09-17 22:02:16 +00:00
|
|
|
{
|
2017-01-15 21:28:14 +00:00
|
|
|
if (size > (2*EM_wordsize))
|
|
|
|
{
|
|
|
|
if (!fallback)
|
2017-01-17 21:31:38 +00:00
|
|
|
fatal("treebuilder: can't do opcode %s with size %d", em_mnem[opcode - sp_fmnem], size);
|
2017-01-15 21:28:14 +00:00
|
|
|
push(
|
|
|
|
new_wordir(size)
|
|
|
|
);
|
|
|
|
helper_function(fallback);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct ir* right = pop(size);
|
|
|
|
struct ir* left = pop(size);
|
2016-09-19 21:06:59 +00:00
|
|
|
|
2017-01-15 21:28:14 +00:00
|
|
|
push(
|
|
|
|
new_ir2(
|
|
|
|
irop, size,
|
|
|
|
left, right
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2016-09-19 21:06:59 +00:00
|
|
|
}
|
2016-09-18 21:24:54 +00:00
|
|
|
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
static void rotate(int opcode, int size, int irop, int irop_reverse)
|
|
|
|
{
|
|
|
|
if (size > (2*EM_wordsize))
|
|
|
|
fatal("treebuilder: can't do opcode %s with size %d", em_mnem[opcode - sp_fmnem], size);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct ir* right = pop(size);
|
|
|
|
struct ir* left = pop(size);
|
|
|
|
struct ir* bits = new_wordir(8 * size);
|
|
|
|
|
2018-09-17 12:13:39 +00:00
|
|
|
/* Fix left and right so we can refer to them multiple times. */
|
|
|
|
appendir(right);
|
|
|
|
appendir(left);
|
|
|
|
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
/* a rol b -> (a << b) | (a >> (32 - b)) */
|
|
|
|
push(
|
|
|
|
new_ir2(
|
|
|
|
IR_OR, size,
|
|
|
|
new_ir2(irop, size, left, right),
|
|
|
|
new_ir2(
|
|
|
|
irop_reverse, size,
|
|
|
|
left,
|
|
|
|
new_ir2(IR_SUB, size, bits, right)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-02 12:44:21 +00:00
|
|
|
static void change_by(struct ir* address, int amount)
|
|
|
|
{
|
|
|
|
appendir(
|
2016-10-23 19:54:14 +00:00
|
|
|
store(
|
|
|
|
EM_wordsize, address, 0,
|
2016-10-02 12:44:21 +00:00
|
|
|
new_ir2(
|
|
|
|
IR_ADD, EM_wordsize,
|
2016-10-23 19:54:14 +00:00
|
|
|
load(
|
|
|
|
EM_wordsize, address, 0
|
2016-10-02 12:44:21 +00:00
|
|
|
),
|
|
|
|
new_wordir(amount)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-10-22 08:48:22 +00:00
|
|
|
static struct ir* ptradd(struct ir* address, int offset)
|
|
|
|
{
|
|
|
|
if (offset == 0)
|
|
|
|
return address;
|
|
|
|
|
|
|
|
return
|
|
|
|
new_ir2(
|
|
|
|
IR_ADD, EM_pointersize,
|
|
|
|
address,
|
|
|
|
new_wordir(offset)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
static struct ir* walk_static_chain(int level)
|
2016-10-29 09:57:56 +00:00
|
|
|
{
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
struct ir* ir;
|
2016-10-29 09:57:56 +00:00
|
|
|
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
/* The static chain, when it exists, is the first argument of each
|
|
|
|
* procedure. The chain begins with the current frame at level 0,
|
|
|
|
* and continues until we reach the outermost procedure. */
|
|
|
|
ir = new_ir0(
|
|
|
|
IR_GETFP, EM_pointersize
|
2016-10-29 09:57:56 +00:00
|
|
|
);
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
while (level--)
|
|
|
|
{
|
|
|
|
/* Walk to the next frame pointer. */
|
|
|
|
ir = load(
|
|
|
|
EM_pointersize,
|
|
|
|
new_ir1(
|
|
|
|
IR_FPTOAB, EM_pointersize,
|
|
|
|
ir
|
|
|
|
), 0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return ir;
|
2016-10-29 09:57:56 +00:00
|
|
|
}
|
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
static void insn_ivalue(int opcode, arith value)
|
|
|
|
{
|
2016-09-18 21:24:54 +00:00
|
|
|
switch (opcode)
|
|
|
|
{
|
2017-01-15 21:28:14 +00:00
|
|
|
case op_adi: simple_alu2(opcode, value, IR_ADD, NULL); break;
|
|
|
|
case op_sbi: simple_alu2(opcode, value, IR_SUB, NULL); break;
|
|
|
|
case op_mli: simple_alu2(opcode, value, IR_MUL, NULL); break;
|
|
|
|
case op_dvi: simple_alu2(opcode, value, IR_DIV, NULL); break;
|
|
|
|
case op_rmi: simple_alu2(opcode, value, IR_MOD, NULL); break;
|
|
|
|
case op_sli: simple_alu2(opcode, value, IR_ASL, NULL); break;
|
|
|
|
case op_sri: simple_alu2(opcode, value, IR_ASR, NULL); break;
|
|
|
|
case op_ngi: simple_alu1(opcode, value, IR_NEG, NULL); break;
|
|
|
|
|
|
|
|
case op_adu: simple_alu2(opcode, value, IR_ADD, NULL); break;
|
|
|
|
case op_sbu: simple_alu2(opcode, value, IR_SUB, NULL); break;
|
|
|
|
case op_mlu: simple_alu2(opcode, value, IR_MUL, NULL); break;
|
|
|
|
case op_slu: simple_alu2(opcode, value, IR_LSL, NULL); break;
|
|
|
|
case op_sru: simple_alu2(opcode, value, IR_LSR, NULL); break;
|
|
|
|
case op_rmu: simple_alu2(opcode, value, IR_MODU, NULL); break;
|
|
|
|
case op_dvu: simple_alu2(opcode, value, IR_DIVU, NULL); break;
|
|
|
|
|
2017-01-17 21:31:38 +00:00
|
|
|
case op_and: simple_alu2(opcode, value, IR_AND, ".and"); break;
|
2017-01-15 21:28:14 +00:00
|
|
|
case op_ior: simple_alu2(opcode, value, IR_OR, ".ior"); break;
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
case op_xor: simple_alu2(opcode, value, IR_EOR, ".xor"); break;
|
2017-01-17 21:31:38 +00:00
|
|
|
case op_com: simple_alu1(opcode, value, IR_NOT, ".com"); break;
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
case op_rol: rotate(opcode, value, IR_LSL, IR_LSR); break;
|
|
|
|
case op_ror: rotate(opcode, value, IR_LSR, IR_LSL); break;
|
2017-01-15 21:28:14 +00:00
|
|
|
|
|
|
|
case op_adf: simple_alu2(opcode, value, IR_ADDF, NULL); break;
|
|
|
|
case op_sbf: simple_alu2(opcode, value, IR_SUBF, NULL); break;
|
|
|
|
case op_mlf: simple_alu2(opcode, value, IR_MULF, NULL); break;
|
|
|
|
case op_dvf: simple_alu2(opcode, value, IR_DIVF, NULL); break;
|
|
|
|
case op_ngf: simple_alu1(opcode, value, IR_NEGF, NULL); break;
|
2016-09-21 22:15:48 +00:00
|
|
|
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
case op_cms:
|
|
|
|
if (value > (2*EM_wordsize))
|
|
|
|
{
|
|
|
|
push(new_wordir(value));
|
|
|
|
helper_function(".cms");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
case op_cmu: push(tristate_compare(value, IR_COMPAREUI)); break;
|
2016-10-23 19:54:14 +00:00
|
|
|
case op_cmi: push(tristate_compare(value, IR_COMPARESI)); break;
|
|
|
|
case op_cmf: push(tristate_compare(value, IR_COMPAREF)); break;
|
2016-10-19 21:29:05 +00:00
|
|
|
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
case op_rck:
|
|
|
|
if (value != EM_wordsize)
|
|
|
|
fatal("'rck %d' not supported", value);
|
|
|
|
helper_function(".rck");
|
|
|
|
break;
|
2017-01-15 21:28:14 +00:00
|
|
|
case op_set: push(new_wordir(value)); helper_function(".set"); break;
|
|
|
|
case op_inn: push(new_wordir(value)); helper_function(".inn"); break;
|
|
|
|
|
2016-09-18 21:24:54 +00:00
|
|
|
case op_lol:
|
|
|
|
push(
|
2016-10-23 19:54:14 +00:00
|
|
|
load(
|
|
|
|
EM_wordsize,
|
|
|
|
new_localir(value), 0
|
2016-09-18 21:24:54 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2016-10-19 21:29:05 +00:00
|
|
|
case op_ldl:
|
|
|
|
push(
|
2016-10-23 19:54:14 +00:00
|
|
|
load(
|
|
|
|
EM_wordsize*2,
|
|
|
|
new_localir(value), 0
|
2016-10-19 21:29:05 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2016-09-18 21:24:54 +00:00
|
|
|
case op_stl:
|
|
|
|
appendir(
|
2016-10-23 19:54:14 +00:00
|
|
|
store(
|
|
|
|
EM_wordsize,
|
|
|
|
new_localir(value), 0,
|
2016-09-19 21:06:59 +00:00
|
|
|
pop(EM_wordsize)
|
2016-09-18 21:24:54 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2016-10-21 21:31:00 +00:00
|
|
|
case op_sdl:
|
|
|
|
appendir(
|
2016-10-23 19:54:14 +00:00
|
|
|
store(
|
|
|
|
EM_wordsize*2,
|
|
|
|
new_localir(value), 0,
|
2016-10-21 21:31:00 +00:00
|
|
|
pop(EM_wordsize*2)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
case op_lal:
|
|
|
|
push(
|
2016-09-21 22:15:48 +00:00
|
|
|
new_localir(value)
|
2016-09-19 21:06:59 +00:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2016-10-09 12:45:13 +00:00
|
|
|
case op_lil:
|
|
|
|
push(
|
2016-10-23 19:54:14 +00:00
|
|
|
load(
|
|
|
|
EM_wordsize,
|
|
|
|
load(
|
|
|
|
EM_pointersize,
|
|
|
|
new_localir(value), 0
|
|
|
|
), 0
|
2016-10-09 12:45:13 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case op_sil:
|
|
|
|
appendir(
|
2016-10-23 19:54:14 +00:00
|
|
|
store(
|
|
|
|
EM_wordsize,
|
|
|
|
load(
|
|
|
|
EM_pointersize,
|
|
|
|
new_localir(value), 0
|
|
|
|
), 0,
|
2016-10-09 12:45:13 +00:00
|
|
|
pop(EM_wordsize)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2016-10-02 12:44:21 +00:00
|
|
|
case op_inl:
|
|
|
|
change_by(new_localir(value), 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case op_del:
|
|
|
|
change_by(new_localir(value), -1);
|
|
|
|
break;
|
|
|
|
|
2016-10-02 14:08:46 +00:00
|
|
|
case op_zrl:
|
|
|
|
appendir(
|
2016-10-23 19:54:14 +00:00
|
|
|
store(
|
|
|
|
EM_wordsize,
|
|
|
|
new_localir(value), 0,
|
2016-10-02 14:08:46 +00:00
|
|
|
new_wordir(0)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2016-10-22 18:32:51 +00:00
|
|
|
case op_zrf:
|
|
|
|
{
|
|
|
|
struct ir* ir = new_constir(value, 0);
|
2016-10-29 09:57:56 +00:00
|
|
|
ir->opcode = IR_CONST;
|
2016-10-22 18:32:51 +00:00
|
|
|
push(ir);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-10-17 22:31:26 +00:00
|
|
|
case op_loe:
|
|
|
|
push(
|
2016-10-23 19:54:14 +00:00
|
|
|
load(
|
|
|
|
EM_wordsize,
|
|
|
|
new_labelir(".hol0"), value
|
2016-10-17 22:31:26 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2016-10-29 11:32:09 +00:00
|
|
|
case op_lae:
|
|
|
|
push(
|
|
|
|
new_ir2(
|
|
|
|
IR_ADD, EM_pointersize,
|
|
|
|
new_labelir(".hol0"),
|
|
|
|
new_wordir(value)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2016-10-17 22:31:26 +00:00
|
|
|
case op_ste:
|
|
|
|
appendir(
|
2016-10-23 19:54:14 +00:00
|
|
|
store(
|
|
|
|
EM_wordsize,
|
|
|
|
new_labelir(".hol0"), value,
|
2016-10-17 22:31:26 +00:00
|
|
|
pop(EM_wordsize)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case op_zre:
|
|
|
|
appendir(
|
2016-10-23 19:54:14 +00:00
|
|
|
store(
|
|
|
|
EM_wordsize,
|
|
|
|
new_labelir(".hol0"), value,
|
2016-10-17 22:31:26 +00:00
|
|
|
new_wordir(0)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
2017-01-15 21:28:14 +00:00
|
|
|
|
2016-09-18 21:24:54 +00:00
|
|
|
case op_loc:
|
|
|
|
push(
|
|
|
|
new_wordir(value)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case op_loi:
|
2016-10-22 08:48:22 +00:00
|
|
|
{
|
|
|
|
struct ir* ptr = pop(EM_pointersize);
|
|
|
|
int offset = 0;
|
|
|
|
|
|
|
|
if (value > (EM_wordsize*2))
|
2017-01-07 17:47:00 +00:00
|
|
|
{
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
/* We're going to need to do multiple loads; fix the address
|
2017-01-07 17:47:00 +00:00
|
|
|
* so it'll go into a register and we can do maths on it. */
|
2016-10-22 08:48:22 +00:00
|
|
|
appendir(ptr);
|
2017-01-07 17:47:00 +00:00
|
|
|
}
|
2016-10-22 08:48:22 +00:00
|
|
|
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
/* Stack grows down. Load backwards. */
|
2016-10-22 08:48:22 +00:00
|
|
|
while (value > 0)
|
|
|
|
{
|
2017-01-07 17:47:00 +00:00
|
|
|
int s = EM_wordsize*2;
|
|
|
|
if (value < s)
|
2016-10-22 08:48:22 +00:00
|
|
|
s = value;
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
value -= s;
|
2016-10-22 08:48:22 +00:00
|
|
|
push(
|
2016-10-23 19:54:14 +00:00
|
|
|
load(
|
|
|
|
s,
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
ptr, value
|
2016-10-22 08:48:22 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(value == 0);
|
2016-09-18 21:24:54 +00:00
|
|
|
break;
|
2016-10-22 08:48:22 +00:00
|
|
|
}
|
2016-09-18 21:24:54 +00:00
|
|
|
|
2016-10-15 09:22:40 +00:00
|
|
|
case op_lof:
|
|
|
|
{
|
|
|
|
struct ir* ptr = pop(EM_pointersize);
|
|
|
|
|
|
|
|
push(
|
2016-10-23 19:54:14 +00:00
|
|
|
load(
|
|
|
|
EM_wordsize,
|
|
|
|
ptr, value
|
2016-10-15 09:22:40 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-10-24 10:08:40 +00:00
|
|
|
case op_ldf:
|
|
|
|
{
|
|
|
|
struct ir* ptr = pop(EM_pointersize);
|
|
|
|
|
|
|
|
push(
|
|
|
|
load(
|
|
|
|
EM_wordsize*2,
|
|
|
|
ptr, value
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-18 21:24:54 +00:00
|
|
|
case op_sti:
|
2016-09-19 21:06:59 +00:00
|
|
|
{
|
|
|
|
struct ir* ptr = pop(EM_pointersize);
|
2016-10-29 10:48:05 +00:00
|
|
|
int offset = 0;
|
2016-09-18 21:24:54 +00:00
|
|
|
|
2017-01-07 17:47:00 +00:00
|
|
|
if (value > peek(0))
|
|
|
|
{
|
|
|
|
/* We're going to need to do multiple stores; fix the address
|
|
|
|
* so it'll go into a register and we can do maths on it. */
|
2016-10-29 10:48:05 +00:00
|
|
|
appendir(ptr);
|
2017-01-07 17:47:00 +00:00
|
|
|
}
|
2016-10-29 10:48:05 +00:00
|
|
|
|
|
|
|
while (value > 0)
|
|
|
|
{
|
2017-01-07 17:47:00 +00:00
|
|
|
struct ir* v = pop(peek(0));
|
|
|
|
int s = v->size;
|
|
|
|
if (value < s)
|
2016-10-29 10:48:05 +00:00
|
|
|
s = value;
|
|
|
|
|
|
|
|
appendir(
|
|
|
|
store(
|
|
|
|
s,
|
|
|
|
ptr, offset,
|
2017-01-07 17:47:00 +00:00
|
|
|
v
|
2016-10-29 10:48:05 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
value -= s;
|
|
|
|
offset += s;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(value == 0);
|
2016-09-18 21:24:54 +00:00
|
|
|
break;
|
2016-09-19 21:06:59 +00:00
|
|
|
}
|
2016-09-18 21:24:54 +00:00
|
|
|
|
2016-10-15 09:22:40 +00:00
|
|
|
case op_stf:
|
|
|
|
{
|
|
|
|
struct ir* ptr = pop(EM_pointersize);
|
2016-10-17 22:31:26 +00:00
|
|
|
struct ir* val = pop(EM_wordsize);
|
2016-10-15 09:22:40 +00:00
|
|
|
|
|
|
|
appendir(
|
2016-10-23 19:54:14 +00:00
|
|
|
store(
|
|
|
|
EM_wordsize,
|
|
|
|
ptr, value,
|
2016-10-15 09:22:40 +00:00
|
|
|
val
|
|
|
|
)
|
|
|
|
);
|
2016-10-24 10:08:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case op_sdf:
|
|
|
|
{
|
|
|
|
struct ir* ptr = pop(EM_pointersize);
|
|
|
|
struct ir* val = pop(EM_wordsize*2);
|
|
|
|
|
|
|
|
appendir(
|
|
|
|
store(
|
|
|
|
EM_wordsize*2,
|
|
|
|
ptr, value,
|
|
|
|
val
|
|
|
|
)
|
|
|
|
);
|
2016-10-15 09:22:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-18 21:24:54 +00:00
|
|
|
case op_ads:
|
2016-09-19 21:06:59 +00:00
|
|
|
{
|
|
|
|
struct ir* off = pop(value);
|
|
|
|
struct ir* ptr = pop(EM_pointersize);
|
2016-09-18 21:24:54 +00:00
|
|
|
|
|
|
|
if (value != EM_pointersize)
|
2016-10-23 19:54:14 +00:00
|
|
|
off = convert(off, value, EM_pointersize, IR_FROMUI);
|
2016-09-18 21:24:54 +00:00
|
|
|
|
|
|
|
push(
|
|
|
|
new_ir2(
|
2016-09-19 21:06:59 +00:00
|
|
|
IR_ADD, EM_pointersize,
|
|
|
|
ptr, off
|
2016-09-18 21:24:54 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
2016-09-19 21:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case op_adp:
|
|
|
|
{
|
|
|
|
struct ir* ptr = pop(EM_pointersize);
|
2016-09-18 21:24:54 +00:00
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
push(
|
|
|
|
new_ir2(
|
|
|
|
IR_ADD, EM_pointersize,
|
|
|
|
ptr,
|
|
|
|
new_wordir(value)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case op_sbs:
|
|
|
|
{
|
|
|
|
struct ir* right = pop(EM_pointersize);
|
|
|
|
struct ir* left = pop(EM_pointersize);
|
|
|
|
|
2017-01-15 21:28:14 +00:00
|
|
|
struct ir* delta =
|
2016-09-19 21:06:59 +00:00
|
|
|
new_ir2(
|
|
|
|
IR_SUB, EM_pointersize,
|
|
|
|
left, right
|
|
|
|
);
|
|
|
|
|
|
|
|
if (value != EM_pointersize)
|
2016-10-23 19:54:14 +00:00
|
|
|
delta = convert(delta, EM_pointersize, value, IR_FROMUI);
|
2016-09-19 21:06:59 +00:00
|
|
|
|
|
|
|
push(delta);
|
|
|
|
break;
|
|
|
|
}
|
2017-01-15 21:28:14 +00:00
|
|
|
|
2016-09-18 21:24:54 +00:00
|
|
|
case op_dup:
|
|
|
|
{
|
2017-01-07 17:47:00 +00:00
|
|
|
sequence_point();
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
if (value > (2*EM_wordsize))
|
|
|
|
{
|
|
|
|
push(new_wordir(value));
|
|
|
|
helper_function(".dus4");
|
|
|
|
}
|
|
|
|
else if ((value == (EM_wordsize*2)) && (peek(0) == EM_wordsize) && (peek(1) == EM_wordsize))
|
2017-01-07 17:47:00 +00:00
|
|
|
{
|
|
|
|
struct ir* v1 = pop(EM_wordsize);
|
|
|
|
struct ir* v2 = pop(EM_wordsize);
|
|
|
|
push(v2);
|
|
|
|
push(v1);
|
|
|
|
push(v2);
|
|
|
|
push(v1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct ir* v = pop(value);
|
|
|
|
push(v);
|
|
|
|
push(v);
|
|
|
|
}
|
2016-09-18 21:24:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
case op_dus:
|
|
|
|
{
|
|
|
|
if (value != EM_wordsize)
|
|
|
|
fatal("'dus %d' not supported", value);
|
|
|
|
helper_function(".dus4");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-10-29 11:32:09 +00:00
|
|
|
case op_exg:
|
|
|
|
{
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
if (value > (2*EM_wordsize))
|
|
|
|
{
|
|
|
|
push(
|
|
|
|
new_wordir(value)
|
|
|
|
);
|
|
|
|
helper_function(".exg");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct ir* v1 = pop(value);
|
|
|
|
struct ir* v2 = pop(value);
|
|
|
|
push(v1);
|
|
|
|
push(v2);
|
|
|
|
}
|
2016-10-29 11:32:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-01-15 21:28:14 +00:00
|
|
|
case op_zer:
|
|
|
|
{
|
|
|
|
if (value <= EM_wordsize)
|
|
|
|
push(new_constir(value, 0));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
push(new_wordir(value));
|
|
|
|
helper_function(".zer");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-18 21:24:54 +00:00
|
|
|
case op_asp:
|
|
|
|
{
|
|
|
|
switch (value)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
case -2:
|
|
|
|
case -4:
|
|
|
|
case -8:
|
|
|
|
push(new_anyir(-value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-09-21 22:15:48 +00:00
|
|
|
while ((value > 0) && (stackptr > 0))
|
|
|
|
{
|
2017-01-07 17:47:00 +00:00
|
|
|
int s = peek(0);
|
|
|
|
if (s > value)
|
|
|
|
s = value;
|
|
|
|
pop(s);
|
|
|
|
value -= s;
|
2016-09-21 22:15:48 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 21:28:14 +00:00
|
|
|
appendir(
|
|
|
|
new_ir1(
|
|
|
|
IR_STACKADJUST, EM_pointersize,
|
|
|
|
new_wordir(value)
|
|
|
|
)
|
|
|
|
);
|
2016-09-18 21:24:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-10-22 09:26:28 +00:00
|
|
|
case op_ass:
|
|
|
|
appendir(
|
|
|
|
new_ir1(
|
|
|
|
IR_STACKADJUST, EM_pointersize,
|
|
|
|
pop(value)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2016-09-18 21:24:54 +00:00
|
|
|
case op_ret:
|
|
|
|
{
|
|
|
|
if (value > 0)
|
|
|
|
{
|
2016-09-19 21:06:59 +00:00
|
|
|
struct ir* retval = pop(value);
|
2016-09-21 22:15:48 +00:00
|
|
|
materialise_stack();
|
2016-09-18 21:24:54 +00:00
|
|
|
appendir(
|
2016-09-21 22:15:48 +00:00
|
|
|
new_ir1(
|
|
|
|
IR_SETRET, value,
|
2016-09-19 21:06:59 +00:00
|
|
|
retval
|
2016-09-18 21:24:54 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-10-15 16:38:46 +00:00
|
|
|
if (!current_proc->exit)
|
|
|
|
{
|
|
|
|
current_proc->exit = bb_get(NULL);
|
|
|
|
array_append(¤t_proc->blocks, current_proc->exit);
|
|
|
|
|
|
|
|
/* This is actually ignored --- the entire block gets special
|
|
|
|
* treatment. But a lot of the rest of the code assumes that
|
|
|
|
* all basic blocks have one instruction, so we insert one. */
|
2016-10-15 20:53:56 +00:00
|
|
|
|
2016-10-15 16:38:46 +00:00
|
|
|
array_append(¤t_proc->exit->irs,
|
|
|
|
new_ir0(
|
|
|
|
IR_RET, 0
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-09-18 21:24:54 +00:00
|
|
|
appendir(
|
2016-10-15 16:38:46 +00:00
|
|
|
new_ir1(
|
|
|
|
IR_JUMP, 0,
|
|
|
|
new_bbir(current_proc->exit)
|
2016-09-18 21:24:54 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
2017-01-15 21:28:14 +00:00
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
case op_lfr:
|
|
|
|
{
|
2016-10-29 09:57:56 +00:00
|
|
|
push(
|
|
|
|
appendir(
|
|
|
|
new_ir0(
|
|
|
|
IR_GETRET, value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2016-09-19 21:06:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-19 22:19:39 +00:00
|
|
|
case op_csa:
|
2018-09-19 22:12:03 +00:00
|
|
|
{
|
|
|
|
struct ir* descriptor = pop(EM_pointersize);
|
|
|
|
struct ir* targetvalue = appendir(pop(EM_pointersize));
|
|
|
|
struct jumptable jumptable = {};
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (descriptor->opcode != IR_LABEL)
|
|
|
|
fatal("csa is only supported if it refers "
|
|
|
|
"directly to a descriptor block");
|
|
|
|
|
|
|
|
parse_csa(bb_get(descriptor->u.lvalue), &jumptable);
|
|
|
|
emit_jumptable(targetvalue, &jumptable);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-19 22:19:39 +00:00
|
|
|
case op_csb:
|
|
|
|
{
|
|
|
|
struct ir* descriptor = pop(EM_pointersize);
|
2018-09-19 22:12:03 +00:00
|
|
|
struct ir* targetvalue = appendir(pop(EM_pointersize));
|
|
|
|
struct jumptable jumptable = {};
|
|
|
|
int i;
|
2016-09-19 22:19:39 +00:00
|
|
|
|
|
|
|
if (descriptor->opcode != IR_LABEL)
|
2018-09-19 22:12:03 +00:00
|
|
|
fatal("csb is only supported if it refers "
|
2016-09-19 22:19:39 +00:00
|
|
|
"directly to a descriptor block");
|
|
|
|
|
2018-09-19 22:12:03 +00:00
|
|
|
parse_csb(bb_get(descriptor->u.lvalue), &jumptable);
|
|
|
|
emit_jumptable(targetvalue, &jumptable);
|
2016-09-19 22:19:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-10-15 11:07:59 +00:00
|
|
|
case op_sar:
|
|
|
|
case op_lar:
|
|
|
|
case op_aar:
|
|
|
|
{
|
|
|
|
const char* helper;
|
|
|
|
if (value != EM_wordsize)
|
|
|
|
fatal("sar/lar/aar are only supported when using "
|
|
|
|
"word-size descriptors");
|
|
|
|
|
|
|
|
switch (opcode)
|
|
|
|
{
|
|
|
|
case op_sar: helper = ".sar4"; break;
|
|
|
|
case op_lar: helper = ".lar4"; break;
|
|
|
|
case op_aar: helper = ".aar4"; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
materialise_stack();
|
2016-10-24 18:15:22 +00:00
|
|
|
/* No push here, because the helper function leaves the result on
|
|
|
|
* the physical stack (which is very dubious). */
|
|
|
|
appendir(
|
|
|
|
new_ir1(
|
2016-10-29 09:57:56 +00:00
|
|
|
IR_CALL, 0,
|
2016-10-24 18:15:22 +00:00
|
|
|
new_labelir(helper)
|
2016-10-15 11:07:59 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case op_lxl:
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
push(
|
|
|
|
walk_static_chain(value)
|
2016-10-15 11:07:59 +00:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case op_lxa:
|
2016-11-20 10:57:21 +00:00
|
|
|
push(
|
2016-10-15 11:07:59 +00:00
|
|
|
new_ir1(
|
2016-11-20 10:57:21 +00:00
|
|
|
IR_FPTOAB, EM_pointersize,
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
walk_static_chain(value)
|
2016-10-15 11:07:59 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2016-10-17 22:31:26 +00:00
|
|
|
case op_fef:
|
|
|
|
{
|
|
|
|
struct ir* f = pop(value);
|
2016-10-21 22:48:26 +00:00
|
|
|
|
2016-10-21 22:02:15 +00:00
|
|
|
/* fef is implemented by calling a helper function which then mutates
|
|
|
|
* the stack. We read the return values off the stack when retracting
|
|
|
|
* the stack pointer. */
|
|
|
|
|
|
|
|
push(f);
|
|
|
|
push(new_wordir(0));
|
|
|
|
|
2016-10-17 22:31:26 +00:00
|
|
|
materialise_stack();
|
|
|
|
appendir(
|
|
|
|
new_ir1(
|
|
|
|
IR_CALL, 0,
|
2016-10-21 22:02:15 +00:00
|
|
|
new_labelir((value == 4) ? ".fef4" : ".fef8")
|
2016-10-17 22:31:26 +00:00
|
|
|
)
|
|
|
|
);
|
2017-01-15 21:28:14 +00:00
|
|
|
|
2016-10-21 22:02:15 +00:00
|
|
|
/* exit, leaving an int and then a float (or double) on the stack. */
|
2016-10-17 22:31:26 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-01-15 21:28:14 +00:00
|
|
|
|
2016-10-21 22:48:26 +00:00
|
|
|
case op_fif:
|
|
|
|
{
|
|
|
|
/* fif is implemented by calling a helper function which then mutates
|
|
|
|
* the stack. We read the return values off the stack when retracting
|
|
|
|
* the stack pointer. */
|
|
|
|
|
|
|
|
/* We start with two floats on the stack. */
|
|
|
|
|
|
|
|
materialise_stack();
|
|
|
|
appendir(
|
|
|
|
new_ir1(
|
|
|
|
IR_CALL, 0,
|
|
|
|
new_labelir((value == 4) ? ".fif4" : ".fif8")
|
|
|
|
)
|
|
|
|
);
|
2017-01-15 21:28:14 +00:00
|
|
|
|
2016-10-21 22:48:26 +00:00
|
|
|
/* exit, leaving two floats (or doubles) on the stack. */
|
|
|
|
break;
|
|
|
|
}
|
2017-01-15 21:28:14 +00:00
|
|
|
|
2016-10-22 09:26:28 +00:00
|
|
|
case op_lor:
|
|
|
|
{
|
|
|
|
switch (value)
|
|
|
|
{
|
2016-10-29 09:57:56 +00:00
|
|
|
case 0:
|
2016-11-17 21:04:32 +00:00
|
|
|
push(
|
|
|
|
appendir(
|
|
|
|
new_ir1(
|
|
|
|
IR_FPTOLB, EM_pointersize,
|
|
|
|
new_ir0(
|
|
|
|
IR_GETFP, EM_pointersize
|
|
|
|
)
|
2016-10-29 09:57:56 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
2017-01-15 21:28:14 +00:00
|
|
|
|
2016-10-22 09:26:28 +00:00
|
|
|
case 1:
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
materialise_stack();
|
2016-11-17 21:04:32 +00:00
|
|
|
push(
|
|
|
|
appendir(
|
|
|
|
new_ir0(
|
|
|
|
IR_GETSP, EM_pointersize
|
|
|
|
)
|
2016-10-22 09:26:28 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fatal("'lor %d' not supported", value);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case op_str:
|
|
|
|
{
|
|
|
|
switch (value)
|
|
|
|
{
|
2016-10-29 09:57:56 +00:00
|
|
|
case 0:
|
|
|
|
appendir(
|
|
|
|
new_ir1(
|
|
|
|
IR_SETFP, EM_pointersize,
|
|
|
|
pop(EM_pointersize)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2016-10-22 09:26:28 +00:00
|
|
|
case 1:
|
|
|
|
appendir(
|
|
|
|
new_ir1(
|
|
|
|
IR_SETSP, EM_pointersize,
|
|
|
|
pop(EM_pointersize)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fatal("'str %d' not supported", value);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case op_blm:
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
push(new_wordir(value));
|
|
|
|
helper_function(".bls4");
|
2016-10-29 09:57:56 +00:00
|
|
|
break;
|
2016-10-22 09:26:28 +00:00
|
|
|
|
2016-10-29 09:57:56 +00:00
|
|
|
case op_bls:
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
if (value != EM_wordsize)
|
|
|
|
fatal("'bls %d' not supported", value);
|
|
|
|
helper_function(".bls4");
|
2016-10-22 09:26:28 +00:00
|
|
|
break;
|
2016-10-23 20:24:08 +00:00
|
|
|
|
|
|
|
case op_los:
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
if (value != EM_wordsize)
|
|
|
|
fatal("'los %d' not supported", value);
|
|
|
|
helper_function_with_arg(".los4", pop(EM_wordsize));
|
2016-10-23 20:24:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case op_sts:
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
if (value != EM_wordsize)
|
|
|
|
fatal("'sts %d' not supported", value);
|
|
|
|
helper_function_with_arg(".sts4", pop(EM_wordsize));
|
2016-10-23 20:24:08 +00:00
|
|
|
break;
|
2016-10-24 18:15:22 +00:00
|
|
|
|
2016-10-15 11:07:59 +00:00
|
|
|
case op_lin:
|
|
|
|
{
|
|
|
|
/* Set line number --- ignore. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-18 21:24:54 +00:00
|
|
|
default:
|
2016-09-19 21:06:59 +00:00
|
|
|
fatal("treebuilder: unknown ivalue instruction '%s'",
|
2016-09-18 21:24:54 +00:00
|
|
|
em_mnem[opcode - sp_fmnem]);
|
|
|
|
}
|
2016-09-17 22:02:16 +00:00
|
|
|
}
|
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
static void insn_lvalue(int opcode, const char* label, arith offset)
|
|
|
|
{
|
|
|
|
switch (opcode)
|
|
|
|
{
|
2016-10-19 21:29:05 +00:00
|
|
|
case op_lpi:
|
2016-09-19 21:06:59 +00:00
|
|
|
case op_lae:
|
|
|
|
push(
|
2016-09-19 22:19:39 +00:00
|
|
|
address_of_external(label, offset)
|
2016-09-19 21:06:59 +00:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case op_loe:
|
|
|
|
push(
|
|
|
|
new_ir1(
|
|
|
|
IR_LOAD, EM_wordsize,
|
2016-09-19 22:19:39 +00:00
|
|
|
address_of_external(label, offset)
|
2016-09-19 21:06:59 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2016-10-21 21:31:00 +00:00
|
|
|
case op_lde:
|
|
|
|
push(
|
|
|
|
new_ir1(
|
|
|
|
IR_LOAD, EM_wordsize*2,
|
|
|
|
address_of_external(label, offset)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
case op_ste:
|
2017-01-07 12:17:39 +00:00
|
|
|
sequence_point();
|
2016-09-19 21:06:59 +00:00
|
|
|
appendir(
|
|
|
|
new_ir2(
|
|
|
|
IR_STORE, EM_wordsize,
|
2016-09-19 22:19:39 +00:00
|
|
|
address_of_external(label, offset),
|
2016-09-19 21:06:59 +00:00
|
|
|
pop(EM_wordsize)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2016-10-21 21:31:00 +00:00
|
|
|
case op_sde:
|
2017-01-07 12:17:39 +00:00
|
|
|
sequence_point();
|
2016-10-21 21:31:00 +00:00
|
|
|
appendir(
|
|
|
|
new_ir2(
|
|
|
|
IR_STORE, EM_wordsize*2,
|
|
|
|
address_of_external(label, offset),
|
|
|
|
pop(EM_wordsize*2)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2016-10-11 22:45:36 +00:00
|
|
|
case op_zre:
|
2017-01-07 12:17:39 +00:00
|
|
|
sequence_point();
|
2016-10-11 22:45:36 +00:00
|
|
|
appendir(
|
|
|
|
new_ir2(
|
|
|
|
IR_STORE, EM_wordsize,
|
|
|
|
address_of_external(label, offset),
|
|
|
|
new_wordir(0)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
2017-01-15 21:28:14 +00:00
|
|
|
|
2016-10-17 22:31:26 +00:00
|
|
|
case op_ine:
|
2017-01-07 12:17:39 +00:00
|
|
|
sequence_point();
|
2016-10-17 22:31:26 +00:00
|
|
|
appendir(
|
|
|
|
new_ir2(
|
|
|
|
IR_STORE, EM_wordsize,
|
|
|
|
address_of_external(label, offset),
|
|
|
|
new_ir2(
|
|
|
|
IR_ADD, EM_wordsize,
|
|
|
|
new_ir1(
|
|
|
|
IR_LOAD, EM_wordsize,
|
|
|
|
address_of_external(label, offset)
|
|
|
|
),
|
|
|
|
new_wordir(1)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case op_dee:
|
2017-01-07 12:17:39 +00:00
|
|
|
sequence_point();
|
2016-10-17 22:31:26 +00:00
|
|
|
appendir(
|
|
|
|
new_ir2(
|
|
|
|
IR_STORE, EM_wordsize,
|
|
|
|
address_of_external(label, offset),
|
|
|
|
new_ir2(
|
|
|
|
IR_ADD, EM_wordsize,
|
|
|
|
new_ir1(
|
|
|
|
IR_LOAD, EM_wordsize,
|
|
|
|
address_of_external(label, offset)
|
|
|
|
),
|
|
|
|
new_wordir(-1)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
case op_cal:
|
|
|
|
assert(offset == 0);
|
|
|
|
materialise_stack();
|
2016-10-29 09:57:56 +00:00
|
|
|
appendir(
|
2016-09-19 21:06:59 +00:00
|
|
|
new_ir1(
|
|
|
|
IR_CALL, 0,
|
|
|
|
new_labelir(label)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
2016-09-19 22:19:39 +00:00
|
|
|
|
|
|
|
case op_bra:
|
|
|
|
assert(offset == 0);
|
|
|
|
materialise_stack();
|
|
|
|
appendir(
|
|
|
|
new_ir1(
|
|
|
|
IR_JUMP, 0,
|
|
|
|
new_labelir(label)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
2016-10-15 11:07:59 +00:00
|
|
|
|
2016-10-29 10:48:05 +00:00
|
|
|
case op_gto:
|
|
|
|
{
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
struct ir* descriptor = address_of_external(label, offset);
|
2016-10-29 10:48:05 +00:00
|
|
|
|
|
|
|
appendir(
|
|
|
|
new_ir1(
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
IR_SETFP, EM_pointersize,
|
2016-10-29 10:48:05 +00:00
|
|
|
load(EM_pointersize, descriptor, EM_pointersize*2)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
appendir(
|
|
|
|
new_ir1(
|
Teach mcg to pass our tests.
Tests pass if one edits the top build.lua to uncomment "qemuppc" from
both vars.plats and vars.plats_with_tests, and one leaves mcg in
plat/qemuppc/descr.
Add or correct some EM instructions in treebuilder.c:
- "lof", "stf": handle negative offsets in load() and store().
- "cuu": add using IR_FROMUI.
- "lim", "sim": keep an entire word in ".ignmask", to be compatible
with mach/powerpc/libem/trp.s and ncg. We also keep a word in
".ignmask" in ncg for both i386 and m68020.
- "trp": pass trap number in register. See comment in
helper_function_with_arg().
- "sig": push the old value of .trppc on the stack.
- "and ?", "ior ?", "xor ?", "com ?", "cms ?", "set ?", "inn ?":
connect to helper functions in libem.
- "blm", "bls": drop call to memmove() and use new helper ".bls4",
because tests/plat/structcopy_e.c can't call memmove().
- "xor s", "cms s": if s is large, fall back on helper function.
- "rol", "ror": add by decomposing each rotate into 4 IR ops.
- "rck s", "bls s": make fatal unless s is word size.
- "loi": push multiple loads in the correct order.
- "dup s", "exg s": if s is large, fall back on helper.
- "dus": add using new helper ".dus4".
- "lxl", "lxa": follow the static chain, not the dynamic chain.
- "lor 1": materialise the stack before pushing the stack pointer.
- "lor 2", "str 2": make fatal.
- "los", "sts": drop calls to memcpy() and use helpers ".los4" and
and ".sts4", so lang/m2/libm2/LtoUset.e starts working.
- "gto": correctly read descriptor.
Change mach/powerpc/mcg/table:
- ANY.L: add for "asp -8".
- LOAD.L: work around register corruption.
- COMPAREUL.I: add for "cms 8".
2018-01-30 20:53:26 +00:00
|
|
|
IR_SETSP, EM_pointersize,
|
2016-10-29 10:48:05 +00:00
|
|
|
load(EM_pointersize, descriptor, EM_pointersize*1)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
appendir(
|
|
|
|
new_ir1(
|
|
|
|
IR_JUMP, 0,
|
|
|
|
load(EM_pointersize, descriptor, EM_pointersize*0)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-10-15 11:07:59 +00:00
|
|
|
case op_fil:
|
|
|
|
{
|
|
|
|
/* Set filename --- ignore. */
|
|
|
|
break;
|
|
|
|
}
|
2017-01-15 21:28:14 +00:00
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
default:
|
|
|
|
fatal("treebuilder: unknown lvalue instruction '%s'",
|
|
|
|
em_mnem[opcode - sp_fmnem]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void generate_tree(struct basicblock* bb)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2016-09-21 22:15:48 +00:00
|
|
|
tracef('0', "0: block %s\n", bb->name);
|
2016-09-19 22:19:39 +00:00
|
|
|
|
2016-09-19 21:06:59 +00:00
|
|
|
current_bb = bb;
|
|
|
|
reset_stack();
|
|
|
|
|
2016-09-26 20:48:58 +00:00
|
|
|
for (i=0; i<bb->ems.count; i++)
|
2016-09-19 21:06:59 +00:00
|
|
|
{
|
2016-09-26 20:48:58 +00:00
|
|
|
struct em* em = bb->ems.item[i];
|
2016-09-25 10:29:03 +00:00
|
|
|
tracef('E', "E: read %s ", em_mnem[em->opcode - sp_fmnem]);
|
|
|
|
switch (em->paramtype)
|
2016-09-19 21:06:59 +00:00
|
|
|
{
|
|
|
|
case PARAM_NONE:
|
2016-09-21 22:15:48 +00:00
|
|
|
tracef('E', "\n");
|
2016-09-25 10:29:03 +00:00
|
|
|
insn_simple(em->opcode);
|
2016-09-19 21:06:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PARAM_IVALUE:
|
2016-09-25 10:29:03 +00:00
|
|
|
tracef('E', "value=%d\n", em->u.ivalue);
|
|
|
|
insn_ivalue(em->opcode, em->u.ivalue);
|
2016-09-19 21:06:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PARAM_LVALUE:
|
2017-01-15 21:28:14 +00:00
|
|
|
tracef('E', "label=%s offset=%d\n",
|
2016-09-25 10:29:03 +00:00
|
|
|
em->u.lvalue.label, em->u.lvalue.offset);
|
|
|
|
insn_lvalue(em->opcode, em->u.lvalue.label, em->u.lvalue.offset);
|
2016-09-19 21:06:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PARAM_BVALUE:
|
2016-09-25 10:29:03 +00:00
|
|
|
tracef('E', "true=%s", em->u.bvalue.left->name);
|
|
|
|
if (em->u.bvalue.right)
|
|
|
|
tracef('E', " false=%s", em->u.bvalue.right->name);
|
2016-09-21 22:15:48 +00:00
|
|
|
tracef('E', "\n");
|
2016-09-25 10:29:03 +00:00
|
|
|
insn_bvalue(em->opcode, em->u.bvalue.left, em->u.bvalue.right);
|
2016-09-19 21:06:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
2016-09-21 22:15:48 +00:00
|
|
|
if (tracing('E'))
|
|
|
|
print_stack();
|
2016-09-19 21:06:59 +00:00
|
|
|
}
|
|
|
|
|
2016-11-14 20:47:49 +00:00
|
|
|
/* Yes, we are allowed to leave stuff on the stack at the end of the procedure.
|
|
|
|
* It's discarded as part of the function return. */
|
2016-09-19 21:06:59 +00:00
|
|
|
}
|
|
|
|
|
2016-10-15 21:19:44 +00:00
|
|
|
void tb_procedure(void)
|
2016-09-19 21:06:59 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2016-09-26 20:48:58 +00:00
|
|
|
for (i=0; i<current_proc->blocks.count; i++)
|
|
|
|
generate_tree(current_proc->blocks.item[i]);
|
2016-09-19 21:06:59 +00:00
|
|
|
}
|
|
|
|
|
2018-09-19 22:12:03 +00:00
|
|
|
static void parse_csa(struct basicblock* data_bb, struct jumptable* table)
|
|
|
|
{
|
|
|
|
struct em* em;
|
|
|
|
int lowerbound;
|
|
|
|
int count;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
assert(data_bb->ems.count >= 3);
|
|
|
|
|
|
|
|
/* Default target */
|
|
|
|
|
|
|
|
em = data_bb->ems.item[0];
|
|
|
|
assert(em->opcode == op_bra);
|
|
|
|
assert(em->paramtype == PARAM_BVALUE);
|
|
|
|
table->defaulttarget = em->u.bvalue.left;
|
|
|
|
|
|
|
|
/* Lower bound */
|
|
|
|
|
|
|
|
em = data_bb->ems.item[1];
|
|
|
|
assert(em->opcode == op_loc);
|
|
|
|
assert(em->paramtype == PARAM_IVALUE);
|
|
|
|
lowerbound = em->u.ivalue;
|
|
|
|
|
|
|
|
/* Count */
|
|
|
|
|
|
|
|
em = data_bb->ems.item[2];
|
|
|
|
assert(em->opcode == op_loc);
|
|
|
|
assert(em->paramtype == PARAM_IVALUE);
|
|
|
|
count = em->u.ivalue + 1; /* value in descriptor is inclusive */
|
|
|
|
assert(data_bb->ems.count >= (count + 3));
|
|
|
|
|
|
|
|
/* Now, each target in turn. */
|
|
|
|
|
|
|
|
for (i=0; i<count; i++)
|
|
|
|
{
|
|
|
|
struct basicblock* target;
|
|
|
|
|
|
|
|
em = data_bb->ems.item[3 + i];
|
|
|
|
assert(em->opcode == op_bra);
|
|
|
|
assert(em->paramtype == PARAM_BVALUE);
|
|
|
|
target = em->u.bvalue.left;
|
|
|
|
|
|
|
|
imap_put(&table->targets, lowerbound+i, target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void parse_csb(struct basicblock* data_bb, struct jumptable* table)
|
|
|
|
{
|
|
|
|
struct em* em;
|
|
|
|
int count;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
assert(data_bb->ems.count >= 2);
|
|
|
|
|
|
|
|
/* Default target */
|
|
|
|
|
|
|
|
em = data_bb->ems.item[0];
|
|
|
|
assert(em->opcode == op_bra);
|
|
|
|
assert(em->paramtype == PARAM_BVALUE);
|
|
|
|
table->defaulttarget = em->u.bvalue.left;
|
|
|
|
|
|
|
|
/* Number of targets */
|
|
|
|
|
|
|
|
em = data_bb->ems.item[1];
|
|
|
|
assert(em->opcode == op_loc);
|
|
|
|
assert(em->paramtype == PARAM_IVALUE);
|
|
|
|
count = em->u.ivalue;
|
|
|
|
assert(data_bb->ems.count >= (count*2 + 2));
|
|
|
|
|
|
|
|
/* Now, each target in turn. */
|
|
|
|
|
|
|
|
for (i=0; i<count; i++)
|
|
|
|
{
|
|
|
|
int value;
|
|
|
|
struct basicblock* target;
|
|
|
|
|
|
|
|
em = data_bb->ems.item[2 + i*2];
|
|
|
|
assert(em->opcode == op_loc);
|
|
|
|
assert(em->paramtype == PARAM_IVALUE);
|
|
|
|
value = em->u.ivalue;
|
|
|
|
|
|
|
|
em = data_bb->ems.item[3 + i*2];
|
|
|
|
assert(em->opcode == op_bra);
|
|
|
|
assert(em->paramtype == PARAM_BVALUE);
|
|
|
|
target = em->u.bvalue.left;
|
|
|
|
|
|
|
|
imap_put(&table->targets, value, target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void emit_jumptable(struct ir* targetvalue, struct jumptable* jumptable)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
materialise_stack();
|
|
|
|
for (i=0; i<jumptable->targets.count; i++)
|
|
|
|
{
|
|
|
|
int value = jumptable->targets.item[i].left;
|
|
|
|
struct basicblock* target = jumptable->targets.item[i].right;
|
|
|
|
struct basicblock* nextblock = bb_get(NULL);
|
|
|
|
|
|
|
|
array_append(¤t_proc->blocks, nextblock);
|
|
|
|
appendir(
|
|
|
|
new_ir2(
|
|
|
|
IR_CJUMPEQ, 0,
|
|
|
|
new_ir2(
|
|
|
|
IR_COMPARESI, EM_wordsize,
|
|
|
|
targetvalue,
|
|
|
|
new_wordir(value)
|
|
|
|
),
|
|
|
|
new_ir2(
|
|
|
|
IR_PAIR, 0,
|
|
|
|
new_bbir(target),
|
|
|
|
new_bbir(nextblock)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
current_bb = nextblock;
|
|
|
|
}
|
|
|
|
|
|
|
|
appendir(
|
|
|
|
new_ir1(
|
|
|
|
IR_JUMP, 0,
|
|
|
|
new_bbir(jumptable->defaulttarget)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-09-17 22:02:16 +00:00
|
|
|
/* vim: set sw=4 ts=4 expandtab : */
|