2010-07-12 20:18:36 +00:00
|
|
|
/* Copyright (c) 2010, Avian Contributors
|
2009-08-06 17:52:36 +00:00
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software
|
|
|
|
for any purpose with or without fee is hereby granted, provided
|
|
|
|
that the above copyright notice and this permission notice appear
|
|
|
|
in all copies.
|
|
|
|
|
|
|
|
There is NO WARRANTY for this software. See license.txt for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
#include "assembler.h"
|
|
|
|
#include "vector.h"
|
|
|
|
|
|
|
|
#define CAST1(x) reinterpret_cast<UnaryOperationType>(x)
|
|
|
|
#define CAST2(x) reinterpret_cast<BinaryOperationType>(x)
|
|
|
|
#define CAST3(x) reinterpret_cast<TernaryOperationType>(x)
|
2010-07-12 20:18:36 +00:00
|
|
|
#define CAST_BRANCH(x) reinterpret_cast<BranchOperationType>(x)
|
2009-08-06 17:52:36 +00:00
|
|
|
|
|
|
|
using namespace vm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
namespace isa {
|
|
|
|
// INSTRUCTION OPTIONS
|
2009-10-29 16:12:30 +00:00
|
|
|
enum CONDITION { EQ, NE, CS, CC, MI, PL, VS, VC, HI, LS, GE, LT, GT, LE, AL, NV };
|
|
|
|
enum SHIFTOP { LSL, LSR, ASR, ROR };
|
2009-08-06 17:52:36 +00:00
|
|
|
// INSTRUCTION FORMATS
|
|
|
|
inline int DATA(int cond, int opcode, int S, int Rn, int Rd, int shift, int Sh, int Rm)
|
|
|
|
{ return cond<<28 | opcode<<21 | S<<20 | Rn<<16 | Rd<<12 | shift<<7 | Sh<<5 | Rm; }
|
|
|
|
inline int DATAS(int cond, int opcode, int S, int Rn, int Rd, int Rs, int Sh, int Rm)
|
|
|
|
{ return cond<<28 | opcode<<21 | S<<20 | Rn<<16 | Rd<<12 | Rs<<8 | Sh<<5 | 1<<4 | Rm; }
|
|
|
|
inline int DATAI(int cond, int opcode, int S, int Rn, int Rd, int rot, int imm)
|
2010-08-24 23:59:01 +00:00
|
|
|
{ return cond<<28 | 1<<25 | opcode<<21 | S<<20 | Rn<<16 | Rd<<12 | rot<<8 | (imm&0xff); }
|
2009-08-06 17:52:36 +00:00
|
|
|
inline int BRANCH(int cond, int L, int offset)
|
2010-08-24 23:59:01 +00:00
|
|
|
{ return cond<<28 | 5<<25 | L<<24 | (offset&0xffffff); }
|
2009-08-06 17:52:36 +00:00
|
|
|
inline int BRANCHX(int cond, int L, int Rm)
|
|
|
|
{ return cond<<28 | 0x4bffc<<6 | L<<5 | 1<<4 | Rm; }
|
|
|
|
inline int MULTIPLY(int cond, int mul, int S, int Rd, int Rn, int Rs, int Rm)
|
|
|
|
{ return cond<<28 | mul<<21 | S<<20 | Rd<<16 | Rn<<12 | Rs<<8 | 9<<4 | Rm; }
|
|
|
|
inline int XFER(int cond, int P, int U, int B, int W, int L, int Rn, int Rd, int shift, int Sh, int Rm)
|
|
|
|
{ return cond<<28 | 3<<25 | P<<24 | U<<23 | B<<22 | W<<21 | L<<20 | Rn<<16 | Rd<<12 | shift<<7 | Sh<<5 | Rm; }
|
|
|
|
inline int XFERI(int cond, int P, int U, int B, int W, int L, int Rn, int Rd, int offset)
|
2010-08-24 23:59:01 +00:00
|
|
|
{ return cond<<28 | 2<<25 | P<<24 | U<<23 | B<<22 | W<<21 | L<<20 | Rn<<16 | Rd<<12 | (offset&0xfff); }
|
2009-08-06 17:52:36 +00:00
|
|
|
inline int XFER2(int cond, int P, int U, int W, int L, int Rn, int Rd, int S, int H, int Rm)
|
|
|
|
{ return cond<<28 | P<<24 | U<<23 | W<<21 | L<<20 | Rn<<16 | Rd<<12 | 1<<7 | S<<6 | H<<5 | 1<<4 | Rm; }
|
|
|
|
inline int XFER2I(int cond, int P, int U, int W, int L, int Rn, int Rd, int offsetH, int S, int H, int offsetL)
|
2010-11-10 00:31:52 +00:00
|
|
|
{ return cond<<28 | P<<24 | U<<23 | 1<<22 | W<<21 | L<<20 | Rn<<16 | Rd<<12 | offsetH<<8 | 1<<7 | S<<6 | H<<5 | 1<<4 | (offsetL&0xf); }
|
2009-08-06 17:52:36 +00:00
|
|
|
inline int BLOCKXFER(int cond, int P, int U, int S, int W, int L, int Rn, int rlist)
|
|
|
|
{ return cond<<28 | 4<<25 | P<<24 | U<<23 | S<<22 | W<<21 | L<<20 | Rn<<16 | rlist; }
|
2009-10-29 16:12:30 +00:00
|
|
|
inline int SWI(int cond, int imm)
|
2010-08-24 23:59:01 +00:00
|
|
|
{ return cond<<28 | 0x0f<<24 | (imm&0xffffff); }
|
2009-08-06 17:52:36 +00:00
|
|
|
inline int SWAP(int cond, int B, int Rn, int Rd, int Rm)
|
|
|
|
{ return cond<<28 | 1<<24 | B<<22 | Rn<<16 | Rd<<12 | 9<<4 | Rm; }
|
2010-08-24 23:59:01 +00:00
|
|
|
// FIELD CALCULATORS
|
|
|
|
inline int calcU(int imm) { return imm >= 0 ? 1 : 0; }
|
2009-08-06 17:52:36 +00:00
|
|
|
// INSTRUCTIONS
|
2009-10-29 16:12:30 +00:00
|
|
|
// The "cond" and "S" fields are set using the SETCOND() and SETS() functions
|
|
|
|
inline int b(int offset) { return BRANCH(AL, 0, offset); }
|
|
|
|
inline int bl(int offset) { return BRANCH(AL, 1, offset); }
|
|
|
|
inline int bx(int Rm) { return BRANCHX(AL, 0, Rm); }
|
|
|
|
inline int blx(int Rm) { return BRANCHX(AL, 1, Rm); }
|
|
|
|
inline int swi(int imm) { return SWI(AL, imm); }
|
|
|
|
inline int and_(int Rd, int Rn, int Rm, int Sh=0, int shift=0) { return DATA(AL, 0x0, 0, Rn, Rd, shift, Sh, Rm); }
|
|
|
|
inline int eor(int Rd, int Rn, int Rm, int Sh=0, int shift=0) { return DATA(AL, 0x1, 0, Rn, Rd, shift, Sh, Rm); }
|
|
|
|
inline int sub(int Rd, int Rn, int Rm, int Sh=0, int shift=0) { return DATA(AL, 0x2, 0, Rn, Rd, shift, Sh, Rm); }
|
|
|
|
inline int rsb(int Rd, int Rn, int Rm, int Sh=0, int shift=0) { return DATA(AL, 0x3, 0, Rn, Rd, shift, Sh, Rm); }
|
|
|
|
inline int add(int Rd, int Rn, int Rm, int Sh=0, int shift=0) { return DATA(AL, 0x4, 0, Rn, Rd, shift, Sh, Rm); }
|
|
|
|
inline int adc(int Rd, int Rn, int Rm, int Sh=0, int shift=0) { return DATA(AL, 0x5, 0, Rn, Rd, shift, Sh, Rm); }
|
|
|
|
inline int sbc(int Rd, int Rn, int Rm, int Sh=0, int shift=0) { return DATA(AL, 0x6, 0, Rn, Rd, shift, Sh, Rm); }
|
|
|
|
inline int rsc(int Rd, int Rn, int Rm, int Sh=0, int shift=0) { return DATA(AL, 0x7, 0, Rn, Rd, shift, Sh, Rm); }
|
2010-08-28 00:52:33 +00:00
|
|
|
inline int tst(int Rn, int Rm, int Sh=0, int shift=0) { return DATA(AL, 0x8, 1, Rn, 0, shift, Sh, Rm); }
|
|
|
|
inline int teq(int Rn, int Rm, int Sh=0, int shift=0) { return DATA(AL, 0x9, 1, Rn, 0, shift, Sh, Rm); }
|
|
|
|
inline int cmp(int Rn, int Rm, int Sh=0, int shift=0) { return DATA(AL, 0xa, 1, Rn, 0, shift, Sh, Rm); }
|
|
|
|
inline int cmn(int Rn, int Rm, int Sh=0, int shift=0) { return DATA(AL, 0xb, 1, Rn, 0, shift, Sh, Rm); }
|
2009-10-29 16:12:30 +00:00
|
|
|
inline int orr(int Rd, int Rn, int Rm, int Sh=0, int shift=0) { return DATA(AL, 0xc, 0, Rn, Rd, shift, Sh, Rm); }
|
|
|
|
inline int mov(int Rd, int Rm, int Sh=0, int shift=0) { return DATA(AL, 0xd, 0, 0, Rd, shift, Sh, Rm); }
|
|
|
|
inline int bic(int Rd, int Rn, int Rm, int Sh=0, int shift=0) { return DATA(AL, 0xe, 0, Rn, Rd, shift, Sh, Rm); }
|
|
|
|
inline int mvn(int Rd, int Rm, int Sh=0, int shift=0) { return DATA(AL, 0xf, 0, 0, Rd, shift, Sh, Rm); }
|
|
|
|
inline int andi(int Rd, int Rn, int imm, int rot=0) { return DATAI(AL, 0x0, 0, Rn, Rd, rot, imm); }
|
|
|
|
inline int eori(int Rd, int Rn, int imm, int rot=0) { return DATAI(AL, 0x1, 0, Rn, Rd, rot, imm); }
|
|
|
|
inline int subi(int Rd, int Rn, int imm, int rot=0) { return DATAI(AL, 0x2, 0, Rn, Rd, rot, imm); }
|
|
|
|
inline int rsbi(int Rd, int Rn, int imm, int rot=0) { return DATAI(AL, 0x3, 0, Rn, Rd, rot, imm); }
|
|
|
|
inline int addi(int Rd, int Rn, int imm, int rot=0) { return DATAI(AL, 0x4, 0, Rn, Rd, rot, imm); }
|
|
|
|
inline int adci(int Rd, int Rn, int imm, int rot=0) { return DATAI(AL, 0x5, 0, Rn, Rd, rot, imm); }
|
2010-09-03 17:32:22 +00:00
|
|
|
inline int bici(int Rd, int Rn, int imm, int rot=0) { return DATAI(AL, 0xe, 0, Rn, Rd, rot, imm); }
|
2010-08-28 00:52:33 +00:00
|
|
|
inline int cmpi(int Rn, int imm, int rot=0) { return DATAI(AL, 0xa, 1, Rn, 0, rot, imm); }
|
2009-10-29 16:12:30 +00:00
|
|
|
inline int orri(int Rd, int Rn, int imm, int rot=0) { return DATAI(AL, 0xc, 0, Rn, Rd, rot, imm); }
|
|
|
|
inline int movi(int Rd, int imm, int rot=0) { return DATAI(AL, 0xd, 0, 0, Rd, rot, imm); }
|
2010-09-03 18:52:11 +00:00
|
|
|
inline int orrsh(int Rd, int Rn, int Rm, int Rs, int Sh) { return DATAS(AL, 0xc, 0, Rn, Rd, Rs, Sh, Rm); }
|
2009-10-29 16:12:30 +00:00
|
|
|
inline int movsh(int Rd, int Rm, int Rs, int Sh) { return DATAS(AL, 0xd, 0, 0, Rd, Rs, Sh, Rm); }
|
|
|
|
inline int mul(int Rd, int Rm, int Rs) { return MULTIPLY(AL, 0, 0, Rd, 0, Rs, Rm); }
|
|
|
|
inline int mla(int Rd, int Rm, int Rs, int Rn) { return MULTIPLY(AL, 1, 0, Rd, Rn, Rs, Rm); }
|
2010-09-02 22:09:01 +00:00
|
|
|
inline int umull(int RdLo, int RdHi, int Rm, int Rs) { return MULTIPLY(AL, 4, 0, RdHi, RdLo, Rs, Rm); }
|
|
|
|
inline int umlal(int RdLo, int RdHi, int Rm, int Rs) { return MULTIPLY(AL, 5, 0, RdHi, RdLo, Rs, Rm); }
|
|
|
|
inline int smull(int RdLo, int RdHi, int Rm, int Rs) { return MULTIPLY(AL, 6, 0, RdHi, RdLo, Rs, Rm); }
|
|
|
|
inline int smlal(int RdLo, int RdHi, int Rm, int Rs) { return MULTIPLY(AL, 7, 0, RdHi, RdLo, Rs, Rm); }
|
2010-08-28 00:52:33 +00:00
|
|
|
inline int ldr(int Rd, int Rn, int Rm, int W=0) { return XFER(AL, 1, 1, 0, W, 1, Rn, Rd, 0, 0, Rm); }
|
|
|
|
inline int ldri(int Rd, int Rn, int imm, int W=0) { return XFERI(AL, 1, calcU(imm), 0, W, 1, Rn, Rd, abs(imm)); }
|
2009-10-29 16:12:30 +00:00
|
|
|
inline int ldrb(int Rd, int Rn, int Rm) { return XFER(AL, 1, 1, 1, 0, 1, Rn, Rd, 0, 0, Rm); }
|
2010-08-24 23:59:01 +00:00
|
|
|
inline int ldrbi(int Rd, int Rn, int imm) { return XFERI(AL, 1, calcU(imm), 1, 0, 1, Rn, Rd, abs(imm)); }
|
2009-10-29 16:12:30 +00:00
|
|
|
inline int str(int Rd, int Rn, int Rm, int W=0) { return XFER(AL, 1, 1, 0, W, 0, Rn, Rd, 0, 0, Rm); }
|
2010-08-24 23:59:01 +00:00
|
|
|
inline int stri(int Rd, int Rn, int imm, int W=0) { return XFERI(AL, 1, calcU(imm), 0, W, 0, Rn, Rd, abs(imm)); }
|
2009-10-29 16:12:30 +00:00
|
|
|
inline int strb(int Rd, int Rn, int Rm) { return XFER(AL, 1, 1, 1, 0, 0, Rn, Rd, 0, 0, Rm); }
|
2010-08-24 23:59:01 +00:00
|
|
|
inline int strbi(int Rd, int Rn, int imm) { return XFERI(AL, 1, calcU(imm), 1, 0, 0, Rn, Rd, abs(imm)); }
|
2009-10-29 16:12:30 +00:00
|
|
|
inline int ldrh(int Rd, int Rn, int Rm) { return XFER2(AL, 1, 1, 0, 1, Rn, Rd, 0, 1, Rm); }
|
2010-08-24 23:59:01 +00:00
|
|
|
inline int ldrhi(int Rd, int Rn, int imm) { return XFER2I(AL, 1, calcU(imm), 0, 1, Rn, Rd, abs(imm)>>4 & 0xf, 0, 1, abs(imm)&0xf); }
|
2009-10-29 16:12:30 +00:00
|
|
|
inline int strh(int Rd, int Rn, int Rm) { return XFER2(AL, 1, 1, 0, 0, Rn, Rd, 0, 1, Rm); }
|
2010-08-24 23:59:01 +00:00
|
|
|
inline int strhi(int Rd, int Rn, int imm) { return XFER2I(AL, 1, calcU(imm), 0, 0, Rn, Rd, abs(imm)>>4 & 0xf, 0, 1, abs(imm)&0xf); }
|
2009-10-29 16:12:30 +00:00
|
|
|
inline int ldrsh(int Rd, int Rn, int Rm) { return XFER2(AL, 1, 1, 0, 1, Rn, Rd, 1, 1, Rm); }
|
2010-08-24 23:59:01 +00:00
|
|
|
inline int ldrshi(int Rd, int Rn, int imm) { return XFER2I(AL, 1, calcU(imm), 0, 1, Rn, Rd, abs(imm)>>4 & 0xf, 1, 1, abs(imm)&0xf); }
|
2009-10-29 16:12:30 +00:00
|
|
|
inline int ldrsb(int Rd, int Rn, int Rm) { return XFER2(AL, 1, 1, 0, 1, Rn, Rd, 1, 0, Rm); }
|
2010-08-24 23:59:01 +00:00
|
|
|
inline int ldrsbi(int Rd, int Rn, int imm) { return XFER2I(AL, 1, calcU(imm), 0, 1, Rn, Rd, abs(imm)>>4 & 0xf, 1, 0, abs(imm)&0xf); }
|
2010-08-28 00:52:33 +00:00
|
|
|
inline int pop(int Rd) { return XFERI(AL, 0, 1, 0, 0, 1, 13, Rd, 4); }
|
|
|
|
inline int ldmfd(int Rn, int rlist) { return BLOCKXFER(AL, 0, 1, 0, 1, 1, Rn, rlist); }
|
|
|
|
inline int stmfd(int Rn, int rlist) { return BLOCKXFER(AL, 1, 0, 0, 1, 0, Rn, rlist); }
|
2009-10-29 16:12:30 +00:00
|
|
|
inline int swp(int Rd, int Rm, int Rn) { return SWAP(AL, 0, Rn, Rd, Rm); }
|
|
|
|
inline int swpb(int Rd, int Rm, int Rn) { return SWAP(AL, 1, Rn, Rd, Rm); }
|
2010-07-12 20:18:36 +00:00
|
|
|
inline int SETCOND(int ins, int cond) { return ((ins&0x0fffffff) | (cond<<28)); }
|
2009-10-29 16:12:30 +00:00
|
|
|
inline int SETS(int ins) { return ins | 1<<20; }
|
2009-08-06 17:52:36 +00:00
|
|
|
// PSEUDO-INSTRUCTIONS
|
2009-10-29 16:12:30 +00:00
|
|
|
inline int nop() { return mov(0, 0); }
|
|
|
|
inline int lsl(int Rd, int Rm, int Rs) { return movsh(Rd, Rm, Rs, LSL); }
|
|
|
|
inline int lsli(int Rd, int Rm, int imm) { return mov(Rd, Rm, LSL, imm); }
|
|
|
|
inline int lsr(int Rd, int Rm, int Rs) { return movsh(Rd, Rm, Rs, LSR); }
|
|
|
|
inline int lsri(int Rd, int Rm, int imm) { return mov(Rd, Rm, LSR, imm); }
|
|
|
|
inline int asr(int Rd, int Rm, int Rs) { return movsh(Rd, Rm, Rs, ASR); }
|
|
|
|
inline int asri(int Rd, int Rm, int imm) { return mov(Rd, Rm, ASR, imm); }
|
|
|
|
inline int ror(int Rd, int Rm, int Rs) { return movsh(Rd, Rm, Rs, ROR); }
|
2010-07-12 20:18:36 +00:00
|
|
|
inline int beq(int offset) { return SETCOND(b(offset), EQ); }
|
|
|
|
inline int bne(int offset) { return SETCOND(b(offset), NE); }
|
|
|
|
inline int bls(int offset) { return SETCOND(b(offset), LS); }
|
|
|
|
inline int bhi(int offset) { return SETCOND(b(offset), HI); }
|
|
|
|
inline int blt(int offset) { return SETCOND(b(offset), LT); }
|
|
|
|
inline int bgt(int offset) { return SETCOND(b(offset), GT); }
|
|
|
|
inline int ble(int offset) { return SETCOND(b(offset), LE); }
|
|
|
|
inline int bge(int offset) { return SETCOND(b(offset), GE); }
|
2010-09-01 00:35:55 +00:00
|
|
|
inline int blo(int offset) { return SETCOND(b(offset), CC); }
|
|
|
|
inline int bhs(int offset) { return SETCOND(b(offset), CS); }
|
2009-10-29 16:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const uint64_t MASK_LO32 = 0xffffffff;
|
|
|
|
const unsigned MASK_LO16 = 0xffff;
|
|
|
|
const unsigned MASK_LO8 = 0xff;
|
|
|
|
inline unsigned lo32(int64_t i) { return (unsigned)(i&MASK_LO32); }
|
|
|
|
inline unsigned hi32(int64_t i) { return (unsigned)(i>>32); }
|
|
|
|
inline unsigned lo16(int64_t i) { return (unsigned)(i&MASK_LO16); }
|
|
|
|
inline unsigned hi16(int64_t i) { return lo16(i>>16); }
|
|
|
|
inline unsigned lo8(int64_t i) { return (unsigned)(i&MASK_LO8); }
|
|
|
|
inline unsigned hi8(int64_t i) { return lo8(i>>8); }
|
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
inline int ha16(int32_t i) {
|
|
|
|
return ((i >> 16) + ((i & 0x8000) ? 1 : 0)) & 0xffff;
|
|
|
|
}
|
|
|
|
inline int unha16(int32_t high, int32_t low) {
|
|
|
|
return ((high - ((low & 0x8000) ? 1 : 0)) << 16) | low;
|
|
|
|
}
|
|
|
|
|
2009-10-29 16:12:30 +00:00
|
|
|
inline bool isInt8(intptr_t v) { return v == static_cast<int8_t>(v); }
|
|
|
|
inline bool isInt16(intptr_t v) { return v == static_cast<int16_t>(v); }
|
2010-07-12 20:18:36 +00:00
|
|
|
inline bool isInt24(intptr_t v) { return v == (v & 0xffffff); }
|
2009-10-29 16:12:30 +00:00
|
|
|
inline bool isInt32(intptr_t v) { return v == static_cast<int32_t>(v); }
|
|
|
|
inline int carry16(intptr_t v) { return static_cast<int16_t>(v) < 0 ? 1 : 0; }
|
|
|
|
|
2010-08-30 22:13:10 +00:00
|
|
|
inline bool isOfWidth(long long i, int size) { return static_cast<unsigned long long>(i) >> size == 0; }
|
2010-08-28 00:52:33 +00:00
|
|
|
inline bool isOfWidth(int i, int size) { return static_cast<unsigned>(i) >> size == 0; }
|
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
const unsigned FrameFooterSize = 2;
|
|
|
|
const unsigned FrameHeaderSize = 0;
|
|
|
|
|
2009-10-29 16:12:30 +00:00
|
|
|
const unsigned StackAlignmentInBytes = 8;
|
|
|
|
const unsigned StackAlignmentInWords = StackAlignmentInBytes / BytesPerWord;
|
|
|
|
|
2010-08-28 00:52:33 +00:00
|
|
|
const int ThreadRegister = 8;
|
|
|
|
const int StackRegister = 13;
|
|
|
|
const int LinkRegister = 14;
|
2010-08-24 23:59:01 +00:00
|
|
|
const int ProgramCounter = 15;
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-11-15 23:56:34 +00:00
|
|
|
const int32_t PoolOffsetMask = 0xFFF;
|
2010-11-14 02:28:05 +00:00
|
|
|
|
|
|
|
const bool DebugPool = false;
|
|
|
|
|
|
|
|
class Context;
|
|
|
|
class MyBlock;
|
|
|
|
class PoolOffset;
|
|
|
|
class PoolEvent;
|
|
|
|
|
|
|
|
void
|
|
|
|
resolve(MyBlock*);
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
padding(MyBlock*, unsigned);
|
|
|
|
|
2009-08-06 17:52:36 +00:00
|
|
|
class MyBlock: public Assembler::Block {
|
|
|
|
public:
|
2010-11-14 02:28:05 +00:00
|
|
|
MyBlock(Context* context, unsigned offset):
|
|
|
|
context(context), next(0), poolOffsetHead(0), poolOffsetTail(0),
|
|
|
|
lastPoolOffsetTail(0), poolEventHead(0), poolEventTail(0),
|
|
|
|
lastEventOffset(0), offset(offset), start(~0), size(0)
|
2009-08-06 17:52:36 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual unsigned resolve(unsigned start, Assembler::Block* next) {
|
|
|
|
this->start = start;
|
|
|
|
this->next = static_cast<MyBlock*>(next);
|
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
::resolve(this);
|
|
|
|
|
|
|
|
return start + size + padding(this, size);
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
Context* context;
|
2009-08-06 17:52:36 +00:00
|
|
|
MyBlock* next;
|
2010-11-14 02:28:05 +00:00
|
|
|
PoolOffset* poolOffsetHead;
|
|
|
|
PoolOffset* poolOffsetTail;
|
|
|
|
PoolOffset* lastPoolOffsetTail;
|
|
|
|
PoolEvent* poolEventHead;
|
|
|
|
PoolEvent* poolEventTail;
|
|
|
|
unsigned lastEventOffset;
|
2009-08-06 17:52:36 +00:00
|
|
|
unsigned offset;
|
|
|
|
unsigned start;
|
|
|
|
unsigned size;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Task;
|
2010-07-12 20:18:36 +00:00
|
|
|
class ConstantPoolEntry;
|
2009-08-06 17:52:36 +00:00
|
|
|
|
|
|
|
class Context {
|
|
|
|
public:
|
|
|
|
Context(System* s, Allocator* a, Zone* zone):
|
|
|
|
s(s), zone(zone), client(0), code(s, a, 1024), tasks(0), result(0),
|
2010-11-14 02:28:05 +00:00
|
|
|
firstBlock(new (zone->allocate(sizeof(MyBlock))) MyBlock(this, 0)),
|
|
|
|
lastBlock(firstBlock), poolOffsetHead(0), poolOffsetTail(0),
|
|
|
|
constantPool(0), constantPoolCount(0)
|
2009-08-06 17:52:36 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
System* s;
|
|
|
|
Zone* zone;
|
|
|
|
Assembler::Client* client;
|
|
|
|
Vector code;
|
|
|
|
Task* tasks;
|
|
|
|
uint8_t* result;
|
|
|
|
MyBlock* firstBlock;
|
|
|
|
MyBlock* lastBlock;
|
2010-11-14 02:28:05 +00:00
|
|
|
PoolOffset* poolOffsetHead;
|
|
|
|
PoolOffset* poolOffsetTail;
|
2010-07-12 20:18:36 +00:00
|
|
|
ConstantPoolEntry* constantPool;
|
|
|
|
unsigned constantPoolCount;
|
2009-08-06 17:52:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Task {
|
|
|
|
public:
|
|
|
|
Task(Task* next): next(next) { }
|
|
|
|
|
|
|
|
virtual void run(Context* c) = 0;
|
|
|
|
|
|
|
|
Task* next;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef void (*OperationType)(Context*);
|
|
|
|
|
|
|
|
typedef void (*UnaryOperationType)(Context*, unsigned, Assembler::Operand*);
|
|
|
|
|
|
|
|
typedef void (*BinaryOperationType)
|
|
|
|
(Context*, unsigned, Assembler::Operand*, unsigned, Assembler::Operand*);
|
|
|
|
|
|
|
|
typedef void (*TernaryOperationType)
|
|
|
|
(Context*, unsigned, Assembler::Operand*, Assembler::Operand*,
|
|
|
|
Assembler::Operand*);
|
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
typedef void (*BranchOperationType)
|
|
|
|
(Context*, TernaryOperation, unsigned, Assembler::Operand*,
|
|
|
|
Assembler::Operand*, Assembler::Operand*);
|
|
|
|
|
2009-08-06 17:52:36 +00:00
|
|
|
class ArchitectureContext {
|
|
|
|
public:
|
|
|
|
ArchitectureContext(System* s): s(s) { }
|
|
|
|
|
|
|
|
System* s;
|
|
|
|
OperationType operations[OperationCount];
|
|
|
|
UnaryOperationType unaryOperations[UnaryOperationCount
|
|
|
|
* OperandTypeCount];
|
|
|
|
BinaryOperationType binaryOperations
|
|
|
|
[BinaryOperationCount * OperandTypeCount * OperandTypeCount];
|
|
|
|
TernaryOperationType ternaryOperations
|
2010-07-12 20:18:36 +00:00
|
|
|
[NonBranchTernaryOperationCount * OperandTypeCount];
|
|
|
|
BranchOperationType branchOperations
|
|
|
|
[BranchOperationCount * OperandTypeCount * OperandTypeCount];
|
2009-08-06 17:52:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline void NO_RETURN
|
|
|
|
abort(Context* c)
|
|
|
|
{
|
|
|
|
abort(c->s);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void NO_RETURN
|
|
|
|
abort(ArchitectureContext* c)
|
|
|
|
{
|
|
|
|
abort(c->s);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
inline void
|
|
|
|
assert(Context* c, bool v)
|
|
|
|
{
|
|
|
|
assert(c->s, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
assert(ArchitectureContext* c, bool v)
|
|
|
|
{
|
|
|
|
assert(c->s, v);
|
|
|
|
}
|
|
|
|
#endif // not NDEBUG
|
|
|
|
|
|
|
|
inline void
|
|
|
|
expect(Context* c, bool v)
|
|
|
|
{
|
|
|
|
expect(c->s, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
class Offset: public Promise {
|
|
|
|
public:
|
2010-12-07 22:57:11 +00:00
|
|
|
Offset(Context* c, MyBlock* block, unsigned offset, bool forTrace):
|
|
|
|
c(c), block(block), offset(offset), forTrace(forTrace)
|
2009-08-06 17:52:36 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual bool resolved() {
|
|
|
|
return block->start != static_cast<unsigned>(~0);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int64_t value() {
|
|
|
|
assert(c, resolved());
|
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
unsigned o = offset - block->offset;
|
2010-12-07 22:57:11 +00:00
|
|
|
return block->start + padding(block, forTrace ? o - BytesPerWord : o) + o;
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Context* c;
|
|
|
|
MyBlock* block;
|
|
|
|
unsigned offset;
|
2010-12-07 22:57:11 +00:00
|
|
|
bool forTrace;
|
2009-08-06 17:52:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Promise*
|
2010-12-07 22:57:11 +00:00
|
|
|
offset(Context* c, bool forTrace = false)
|
2009-08-06 17:52:36 +00:00
|
|
|
{
|
|
|
|
return new (c->zone->allocate(sizeof(Offset)))
|
2010-12-07 22:57:11 +00:00
|
|
|
Offset(c, c->lastBlock, c->code.length(), forTrace);
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
bounded(int right, int left, int32_t v)
|
|
|
|
{
|
|
|
|
return ((v << left) >> left) == v and ((v >> right) << right) == v;
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
2010-11-14 02:28:05 +00:00
|
|
|
updateOffset(System* s, uint8_t* instruction, int64_t value)
|
2009-08-06 17:52:36 +00:00
|
|
|
{
|
2010-08-24 23:59:01 +00:00
|
|
|
// ARM's PC is two words ahead, and branches drop the bottom 2 bits.
|
|
|
|
int32_t v = (reinterpret_cast<uint8_t*>(value) - (instruction + 8)) >> 2;
|
|
|
|
|
2009-08-06 17:52:36 +00:00
|
|
|
int32_t mask;
|
2009-10-29 20:14:44 +00:00
|
|
|
expect(s, bounded(0, 8, v));
|
|
|
|
mask = 0xFFFFFF;
|
2009-08-06 17:52:36 +00:00
|
|
|
|
|
|
|
int32_t* p = reinterpret_cast<int32_t*>(instruction);
|
|
|
|
*p = (v & mask) | ((~mask) & *p);
|
|
|
|
|
|
|
|
return instruction + 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
class OffsetListener: public Promise::Listener {
|
|
|
|
public:
|
2010-11-14 02:28:05 +00:00
|
|
|
OffsetListener(System* s, uint8_t* instruction):
|
2009-08-06 17:52:36 +00:00
|
|
|
s(s),
|
2010-11-14 02:28:05 +00:00
|
|
|
instruction(instruction)
|
2009-08-06 17:52:36 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual bool resolve(int64_t value, void** location) {
|
2010-11-14 02:28:05 +00:00
|
|
|
void* p = updateOffset(s, instruction, value);
|
2009-08-06 17:52:36 +00:00
|
|
|
if (location) *location = p;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
System* s;
|
|
|
|
uint8_t* instruction;
|
|
|
|
};
|
|
|
|
|
|
|
|
class OffsetTask: public Task {
|
|
|
|
public:
|
2010-11-14 02:28:05 +00:00
|
|
|
OffsetTask(Task* next, Promise* promise, Promise* instructionOffset):
|
2009-08-06 17:52:36 +00:00
|
|
|
Task(next),
|
|
|
|
promise(promise),
|
2010-11-14 02:28:05 +00:00
|
|
|
instructionOffset(instructionOffset)
|
2009-08-06 17:52:36 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual void run(Context* c) {
|
|
|
|
if (promise->resolved()) {
|
|
|
|
updateOffset
|
2010-11-14 02:28:05 +00:00
|
|
|
(c->s, c->result + instructionOffset->value(), promise->value());
|
2009-08-06 17:52:36 +00:00
|
|
|
} else {
|
|
|
|
new (promise->listen(sizeof(OffsetListener)))
|
2010-11-14 02:28:05 +00:00
|
|
|
OffsetListener(c->s, c->result + instructionOffset->value());
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Promise* promise;
|
|
|
|
Promise* instructionOffset;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2010-11-14 02:28:05 +00:00
|
|
|
appendOffsetTask(Context* c, Promise* promise, Promise* instructionOffset)
|
2009-08-06 17:52:36 +00:00
|
|
|
{
|
|
|
|
c->tasks = new (c->zone->allocate(sizeof(OffsetTask))) OffsetTask
|
2010-11-14 02:28:05 +00:00
|
|
|
(c->tasks, promise, instructionOffset);
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline unsigned
|
2010-07-12 20:18:36 +00:00
|
|
|
index(ArchitectureContext*, UnaryOperation operation, OperandType operand)
|
2009-08-06 17:52:36 +00:00
|
|
|
{
|
|
|
|
return operation + (UnaryOperationCount * operand);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline unsigned
|
2010-07-12 20:18:36 +00:00
|
|
|
index(ArchitectureContext*,
|
|
|
|
BinaryOperation operation,
|
2009-08-06 17:52:36 +00:00
|
|
|
OperandType operand1,
|
|
|
|
OperandType operand2)
|
|
|
|
{
|
|
|
|
return operation
|
|
|
|
+ (BinaryOperationCount * operand1)
|
|
|
|
+ (BinaryOperationCount * OperandTypeCount * operand2);
|
|
|
|
}
|
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
bool
|
|
|
|
isBranch(TernaryOperation op)
|
|
|
|
{
|
|
|
|
return op > FloatMin;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
isFloatBranch(TernaryOperation op)
|
|
|
|
{
|
|
|
|
return op > JumpIfNotEqual;
|
|
|
|
}
|
|
|
|
|
2009-08-06 17:52:36 +00:00
|
|
|
inline unsigned
|
2010-07-12 20:18:36 +00:00
|
|
|
index(ArchitectureContext* c UNUSED,
|
|
|
|
TernaryOperation operation,
|
2009-08-06 17:52:36 +00:00
|
|
|
OperandType operand1)
|
|
|
|
{
|
2010-07-12 20:18:36 +00:00
|
|
|
assert(c, not isBranch(operation));
|
|
|
|
|
|
|
|
return operation + (NonBranchTernaryOperationCount * operand1);
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
unsigned
|
|
|
|
branchIndex(ArchitectureContext* c UNUSED, OperandType operand1,
|
|
|
|
OperandType operand2)
|
|
|
|
{
|
|
|
|
return operand1 + (OperandTypeCount * operand2);
|
|
|
|
}
|
2009-08-06 17:52:36 +00:00
|
|
|
|
|
|
|
// BEGIN OPERATION COMPILERS
|
|
|
|
|
2009-10-29 16:12:30 +00:00
|
|
|
using namespace isa;
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2009-10-29 16:12:30 +00:00
|
|
|
// shortcut functions
|
|
|
|
inline void emit(Context* con, int code) { con->code.append4(code); }
|
|
|
|
inline int newTemp(Context* con) { return con->client->acquireTemporary(); }
|
2009-08-06 17:52:36 +00:00
|
|
|
inline void freeTemp(Context* con, int r) { con->client->releaseTemporary(r); }
|
2010-07-12 20:18:36 +00:00
|
|
|
inline int64_t getValue(Assembler::Constant* c) { return c->value->value(); }
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
inline void
|
|
|
|
write4(uint8_t* dst, uint32_t v)
|
|
|
|
{
|
|
|
|
memcpy(dst, &v, 4);
|
|
|
|
}
|
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
void shiftLeftR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t)
|
2009-08-06 17:52:36 +00:00
|
|
|
{
|
2009-10-29 16:12:30 +00:00
|
|
|
if (size == 8) {
|
2010-09-03 18:52:11 +00:00
|
|
|
int tmp1 = newTemp(con), tmp2 = newTemp(con);
|
|
|
|
emit(con, lsl(tmp1, b->high, a->low));
|
|
|
|
emit(con, rsbi(tmp2, a->low, 32));
|
|
|
|
emit(con, orrsh(tmp1, tmp1, b->low, tmp2, LSR));
|
|
|
|
emit(con, SETS(subi(t->high, a->low, 32)));
|
|
|
|
emit(con, SETCOND(mov(t->high, tmp1), MI));
|
|
|
|
emit(con, SETCOND(lsl(t->high, b->low, t->high), PL));
|
|
|
|
emit(con, lsl(t->low, b->low, a->low));
|
|
|
|
freeTemp(con, tmp1); freeTemp(con, tmp2);
|
|
|
|
} else {
|
|
|
|
emit(con, lsl(t->low, b->low, a->low));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-24 23:59:01 +00:00
|
|
|
void shiftLeftC(Context* con, unsigned size UNUSED, Assembler::Constant* a, Assembler::Register* b, Assembler::Register* t)
|
2009-08-06 17:52:36 +00:00
|
|
|
{
|
2009-10-29 16:12:30 +00:00
|
|
|
assert(con, size == BytesPerWord);
|
|
|
|
emit(con, lsli(t->low, b->low, getValue(a)));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
void shiftRightR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t)
|
2009-08-06 17:52:36 +00:00
|
|
|
{
|
2009-10-29 16:12:30 +00:00
|
|
|
if (size == 8) {
|
2010-09-03 18:52:11 +00:00
|
|
|
int tmp1 = newTemp(con), tmp2 = newTemp(con);
|
|
|
|
emit(con, lsr(tmp1, b->low, a->low));
|
|
|
|
emit(con, rsbi(tmp2, a->low, 32));
|
|
|
|
emit(con, orrsh(tmp1, tmp1, b->high, tmp2, LSL));
|
|
|
|
emit(con, SETS(subi(t->low, a->low, 32)));
|
|
|
|
emit(con, SETCOND(mov(t->low, tmp1), MI));
|
|
|
|
emit(con, SETCOND(asr(t->low, b->high, t->low), PL));
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(con, asr(t->high, b->high, a->low));
|
2010-09-03 18:52:11 +00:00
|
|
|
freeTemp(con, tmp1); freeTemp(con, tmp2);
|
2009-08-06 17:52:36 +00:00
|
|
|
} else {
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(con, asr(t->low, b->low, a->low));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-24 23:59:01 +00:00
|
|
|
void shiftRightC(Context* con, unsigned size UNUSED, Assembler::Constant* a, Assembler::Register* b, Assembler::Register* t)
|
2009-08-06 17:52:36 +00:00
|
|
|
{
|
2009-10-29 16:12:30 +00:00
|
|
|
assert(con, size == BytesPerWord);
|
|
|
|
emit(con, asri(t->low, b->low, getValue(a)));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
void unsignedShiftRightR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t)
|
2009-08-06 17:52:36 +00:00
|
|
|
{
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(con, lsr(t->low, b->low, a->low));
|
|
|
|
if (size == 8) {
|
|
|
|
int tmpHi = newTemp(con), tmpLo = newTemp(con);
|
|
|
|
emit(con, SETS(rsbi(tmpHi, a->low, 32)));
|
|
|
|
emit(con, lsl(tmpLo, b->high, tmpHi));
|
|
|
|
emit(con, orr(t->low, t->low, tmpLo));
|
|
|
|
emit(con, addi(tmpHi, a->low, -32));
|
|
|
|
emit(con, lsr(tmpLo, b->high, tmpHi));
|
|
|
|
emit(con, orr(t->low, t->low, tmpLo));
|
|
|
|
emit(con, lsr(t->high, b->high, a->low));
|
|
|
|
freeTemp(con, tmpHi); freeTemp(con, tmpLo);
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-24 23:59:01 +00:00
|
|
|
void unsignedShiftRightC(Context* con, unsigned size UNUSED, Assembler::Constant* a, Assembler::Register* b, Assembler::Register* t)
|
2009-08-06 17:52:36 +00:00
|
|
|
{
|
2009-10-29 16:12:30 +00:00
|
|
|
assert(con, size == BytesPerWord);
|
|
|
|
emit(con, lsri(t->low, b->low, getValue(a)));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
class ConstantPoolEntry: public Promise {
|
|
|
|
public:
|
2010-11-16 02:38:36 +00:00
|
|
|
ConstantPoolEntry(Context* c, Promise* constant, ConstantPoolEntry* next,
|
|
|
|
Promise* callOffset):
|
|
|
|
c(c), constant(constant), next(next), callOffset(callOffset),
|
|
|
|
address(0)
|
2010-11-14 02:28:05 +00:00
|
|
|
{ }
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
virtual int64_t value() {
|
|
|
|
assert(c, resolved());
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
return reinterpret_cast<intptr_t>(address);
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
virtual bool resolved() {
|
|
|
|
return address != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Context* c;
|
|
|
|
Promise* constant;
|
|
|
|
ConstantPoolEntry* next;
|
2010-11-16 02:38:36 +00:00
|
|
|
Promise* callOffset;
|
2010-11-14 02:28:05 +00:00
|
|
|
void* address;
|
|
|
|
unsigned constantPoolCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ConstantPoolListener: public Promise::Listener {
|
2009-08-06 17:52:36 +00:00
|
|
|
public:
|
2010-11-16 02:38:36 +00:00
|
|
|
ConstantPoolListener(System* s, uintptr_t* address, uint8_t* returnAddress):
|
2010-11-14 02:28:05 +00:00
|
|
|
s(s),
|
2010-11-16 02:38:36 +00:00
|
|
|
address(address),
|
|
|
|
returnAddress(returnAddress)
|
2009-08-06 17:52:36 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual bool resolve(int64_t value, void** location) {
|
2010-11-14 02:28:05 +00:00
|
|
|
*address = value;
|
2010-11-16 02:38:36 +00:00
|
|
|
if (location) {
|
|
|
|
*location = returnAddress ? static_cast<void*>(returnAddress) : address;
|
|
|
|
}
|
2010-11-14 02:28:05 +00:00
|
|
|
return true;
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
System* s;
|
2010-11-14 02:28:05 +00:00
|
|
|
uintptr_t* address;
|
2010-11-16 02:38:36 +00:00
|
|
|
uint8_t* returnAddress;
|
2010-11-14 02:28:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PoolOffset {
|
|
|
|
public:
|
|
|
|
PoolOffset(MyBlock* block, ConstantPoolEntry* entry, unsigned offset):
|
|
|
|
block(block), entry(entry), next(0), offset(offset)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
MyBlock* block;
|
|
|
|
ConstantPoolEntry* entry;
|
|
|
|
PoolOffset* next;
|
2009-08-06 17:52:36 +00:00
|
|
|
unsigned offset;
|
|
|
|
};
|
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
class PoolEvent {
|
2009-08-06 17:52:36 +00:00
|
|
|
public:
|
2010-11-14 02:28:05 +00:00
|
|
|
PoolEvent(PoolOffset* poolOffsetHead, PoolOffset* poolOffsetTail,
|
|
|
|
unsigned offset):
|
|
|
|
poolOffsetHead(poolOffsetHead), poolOffsetTail(poolOffsetTail), next(0),
|
|
|
|
offset(offset)
|
2009-08-06 17:52:36 +00:00
|
|
|
{ }
|
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
PoolOffset* poolOffsetHead;
|
|
|
|
PoolOffset* poolOffsetTail;
|
|
|
|
PoolEvent* next;
|
|
|
|
unsigned offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2010-11-16 02:38:36 +00:00
|
|
|
appendConstantPoolEntry(Context* c, Promise* constant, Promise* callOffset)
|
2010-11-14 02:28:05 +00:00
|
|
|
{
|
|
|
|
if (constant->resolved()) {
|
|
|
|
// make a copy, since the original might be allocated on the
|
|
|
|
// stack, and we need our copy to live until assembly is complete
|
|
|
|
constant = new (c->zone->allocate(sizeof(ResolvedPromise)))
|
|
|
|
ResolvedPromise(constant->value());
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
c->constantPool = new (c->zone->allocate(sizeof(ConstantPoolEntry)))
|
2010-11-16 02:38:36 +00:00
|
|
|
ConstantPoolEntry(c, constant, c->constantPool, callOffset);
|
2010-11-14 02:28:05 +00:00
|
|
|
|
|
|
|
++ c->constantPoolCount;
|
|
|
|
|
|
|
|
PoolOffset* o = new (c->zone->allocate(sizeof(PoolOffset))) PoolOffset
|
|
|
|
(c->lastBlock, c->constantPool, c->code.length() - c->lastBlock->offset);
|
|
|
|
|
|
|
|
if (DebugPool) {
|
|
|
|
fprintf(stderr, "add pool offset %p %d to block %p\n",
|
|
|
|
o, o->offset, c->lastBlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c->lastBlock->poolOffsetTail) {
|
|
|
|
c->lastBlock->poolOffsetTail->next = o;
|
|
|
|
} else {
|
|
|
|
c->lastBlock->poolOffsetHead = o;
|
|
|
|
}
|
|
|
|
c->lastBlock->poolOffsetTail = o;
|
|
|
|
}
|
2009-08-06 17:52:36 +00:00
|
|
|
|
|
|
|
void
|
2010-11-14 02:28:05 +00:00
|
|
|
appendPoolEvent(Context* c, MyBlock* b, unsigned offset, PoolOffset* head,
|
|
|
|
PoolOffset* tail)
|
2009-08-06 17:52:36 +00:00
|
|
|
{
|
2010-11-14 02:28:05 +00:00
|
|
|
PoolEvent* e = new (c->zone->allocate(sizeof(PoolEvent))) PoolEvent
|
|
|
|
(head, tail, offset);
|
|
|
|
|
|
|
|
if (b->poolEventTail) {
|
|
|
|
b->poolEventTail->next = e;
|
|
|
|
} else {
|
|
|
|
b->poolEventHead = e;
|
|
|
|
}
|
|
|
|
b->poolEventTail = e;
|
2010-07-12 20:18:36 +00:00
|
|
|
}
|
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
unsigned
|
|
|
|
padding(MyBlock* b, unsigned offset)
|
|
|
|
{
|
|
|
|
unsigned total = 0;
|
|
|
|
for (PoolEvent* e = b->poolEventHead; e; e = e->next) {
|
|
|
|
if (e->offset <= offset) {
|
|
|
|
total += BytesPerWord;
|
|
|
|
for (PoolOffset* o = e->poolOffsetHead; o; o = o->next) {
|
|
|
|
total += BytesPerWord;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2010-07-12 20:18:36 +00:00
|
|
|
}
|
2010-11-14 02:28:05 +00:00
|
|
|
return total;
|
|
|
|
}
|
2010-07-12 20:18:36 +00:00
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
void
|
|
|
|
resolve(MyBlock* b)
|
|
|
|
{
|
|
|
|
Context* c = b->context;
|
2010-07-12 20:18:36 +00:00
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
if (b->poolOffsetHead) {
|
|
|
|
if (c->poolOffsetTail) {
|
|
|
|
c->poolOffsetTail->next = b->poolOffsetHead;
|
|
|
|
} else {
|
|
|
|
c->poolOffsetHead = b->poolOffsetHead;
|
|
|
|
}
|
|
|
|
c->poolOffsetTail = b->poolOffsetTail;
|
2010-07-12 20:18:36 +00:00
|
|
|
}
|
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
if (c->poolOffsetHead) {
|
|
|
|
bool append;
|
|
|
|
if (b->next == 0 or b->next->poolEventHead) {
|
|
|
|
append = true;
|
|
|
|
} else {
|
2010-12-08 01:17:41 +00:00
|
|
|
int32_t v = (b->start + b->size + b->next->size + BytesPerWord - 8)
|
|
|
|
- (c->poolOffsetHead->offset + c->poolOffsetHead->block->start);
|
2010-07-12 20:18:36 +00:00
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
append = (v != (v & PoolOffsetMask));
|
2010-07-12 20:18:36 +00:00
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
if (DebugPool) {
|
2010-12-08 01:17:41 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"current %p %d %d next %p %d %d\n",
|
|
|
|
b, b->start, b->size, b->next, b->start + b->size,
|
|
|
|
b->next->size);
|
2010-11-14 02:28:05 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"offset %p %d is of distance %d to next block; append? %d\n",
|
|
|
|
c->poolOffsetHead, c->poolOffsetHead->offset, v, append);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (append) {
|
2010-12-08 01:17:41 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
int32_t v = (b->start + b->size - 8)
|
|
|
|
- (c->poolOffsetHead->offset + c->poolOffsetHead->block->start);
|
|
|
|
|
|
|
|
expect(c, v == (v & PoolOffsetMask));
|
|
|
|
#endif // not NDEBUG
|
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
appendPoolEvent(c, b, b->size, c->poolOffsetHead, c->poolOffsetTail);
|
|
|
|
|
|
|
|
if (DebugPool) {
|
|
|
|
for (PoolOffset* o = c->poolOffsetHead; o; o = o->next) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"include %p %d in pool event %p at offset %d in block %p\n",
|
|
|
|
o, o->offset, b->poolEventTail, b->size, b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
c->poolOffsetHead = 0;
|
|
|
|
c->poolOffsetTail = 0;
|
|
|
|
}
|
|
|
|
}
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
jumpR(Context* c, unsigned size UNUSED, Assembler::Register* target)
|
|
|
|
{
|
|
|
|
assert(c, size == BytesPerWord);
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, bx(target->low));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
moveRR(Context* c, unsigned srcSize, Assembler::Register* src,
|
|
|
|
unsigned dstSize, Assembler::Register* dst);
|
|
|
|
|
|
|
|
void
|
|
|
|
swapRR(Context* c, unsigned aSize, Assembler::Register* a,
|
|
|
|
unsigned bSize, Assembler::Register* b)
|
|
|
|
{
|
|
|
|
assert(c, aSize == BytesPerWord);
|
|
|
|
assert(c, bSize == BytesPerWord);
|
|
|
|
|
|
|
|
Assembler::Register tmp(c->client->acquireTemporary());
|
|
|
|
moveRR(c, aSize, a, bSize, &tmp);
|
|
|
|
moveRR(c, bSize, b, aSize, a);
|
|
|
|
moveRR(c, bSize, &tmp, bSize, b);
|
|
|
|
c->client->releaseTemporary(tmp.low);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
moveRR(Context* c, unsigned srcSize, Assembler::Register* src,
|
|
|
|
unsigned dstSize, Assembler::Register* dst)
|
|
|
|
{
|
|
|
|
switch (srcSize) {
|
|
|
|
case 1:
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, lsli(dst->low, src->low, 24));
|
|
|
|
emit(c, asri(dst->low, dst->low, 24));
|
2009-08-06 17:52:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, lsli(dst->low, src->low, 16));
|
|
|
|
emit(c, asri(dst->low, dst->low, 16));
|
2009-08-06 17:52:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
case 8:
|
|
|
|
if (srcSize == 4 and dstSize == 8) {
|
|
|
|
moveRR(c, 4, src, 4, dst);
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, asri(dst->high, src->low, 31));
|
2009-08-06 17:52:36 +00:00
|
|
|
} else if (srcSize == 8 and dstSize == 8) {
|
|
|
|
Assembler::Register srcHigh(src->high);
|
|
|
|
Assembler::Register dstHigh(dst->high);
|
|
|
|
|
|
|
|
if (src->high == dst->low) {
|
|
|
|
if (src->low == dst->high) {
|
|
|
|
swapRR(c, 4, src, 4, dst);
|
|
|
|
} else {
|
|
|
|
moveRR(c, 4, &srcHigh, 4, &dstHigh);
|
|
|
|
moveRR(c, 4, src, 4, dst);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
moveRR(c, 4, src, 4, dst);
|
|
|
|
moveRR(c, 4, &srcHigh, 4, &dstHigh);
|
|
|
|
}
|
|
|
|
} else if (src->low != dst->low) {
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, mov(dst->low, src->low));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: abort(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
moveZRR(Context* c, unsigned srcSize, Assembler::Register* src,
|
|
|
|
unsigned, Assembler::Register* dst)
|
|
|
|
{
|
|
|
|
switch (srcSize) {
|
|
|
|
case 2:
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, lsli(dst->low, src->low, 16));
|
2010-09-01 00:35:55 +00:00
|
|
|
emit(c, lsri(dst->low, dst->low, 16));
|
2009-08-06 17:52:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: abort(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
moveCR2(Context* c, unsigned, Assembler::Constant* src,
|
2010-11-16 02:38:36 +00:00
|
|
|
unsigned dstSize, Assembler::Register* dst, Promise* callOffset)
|
2009-08-06 17:52:36 +00:00
|
|
|
{
|
|
|
|
if (dstSize <= 4) {
|
2010-11-14 02:28:05 +00:00
|
|
|
if (src->value->resolved() and isOfWidth(getValue(src), 8)) {
|
|
|
|
emit(c, movi(dst->low, lo8(getValue(src))));
|
2009-08-06 17:52:36 +00:00
|
|
|
} else {
|
2010-11-16 02:38:36 +00:00
|
|
|
appendConstantPoolEntry(c, src->value, callOffset);
|
2010-11-14 02:28:05 +00:00
|
|
|
emit(c, ldri(dst->low, ProgramCounter, 0));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
abort(c); // todo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
moveCR(Context* c, unsigned srcSize, Assembler::Constant* src,
|
|
|
|
unsigned dstSize, Assembler::Register* dst)
|
|
|
|
{
|
2010-11-16 02:38:36 +00:00
|
|
|
moveCR2(c, srcSize, src, dstSize, dst, 0);
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
void addR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t) {
|
2009-10-29 16:12:30 +00:00
|
|
|
if (size == 8) {
|
2010-09-01 00:35:55 +00:00
|
|
|
emit(con, SETS(add(t->low, a->low, b->low)));
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(con, adc(t->high, a->high, b->high));
|
2009-08-06 17:52:36 +00:00
|
|
|
} else {
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(con, add(t->low, a->low, b->low));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
void subR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t) {
|
2009-10-29 16:12:30 +00:00
|
|
|
if (size == 8) {
|
|
|
|
emit(con, SETS(rsb(t->low, a->low, b->low)));
|
|
|
|
emit(con, rsc(t->high, a->high, b->high));
|
2009-08-06 17:52:36 +00:00
|
|
|
} else {
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(con, rsb(t->low, a->low, b->low));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
void multiplyR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t) {
|
2009-10-29 16:12:30 +00:00
|
|
|
if (size == 8) {
|
2010-09-02 22:09:01 +00:00
|
|
|
bool useTemporaries = b->low == t->low;
|
|
|
|
int tmpLow = useTemporaries ? con->client->acquireTemporary() : t->low;
|
|
|
|
int tmpHigh = useTemporaries ? con->client->acquireTemporary() : t->high;
|
|
|
|
|
|
|
|
emit(con, umull(tmpLow, tmpHigh, a->low, b->low));
|
|
|
|
emit(con, mla(tmpHigh, a->low, b->high, tmpHigh));
|
|
|
|
emit(con, mla(tmpHigh, a->high, b->low, tmpHigh));
|
|
|
|
|
|
|
|
if (useTemporaries) {
|
|
|
|
emit(con, mov(t->low, tmpLow));
|
|
|
|
emit(con, mov(t->high, tmpHigh));
|
|
|
|
con->client->releaseTemporary(tmpLow);
|
|
|
|
con->client->releaseTemporary(tmpHigh);
|
|
|
|
}
|
2009-08-06 17:52:36 +00:00
|
|
|
} else {
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(con, mul(t->low, a->low, b->low));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
normalize(Context* c, int offset, int index, unsigned scale,
|
|
|
|
bool* preserveIndex, bool* release)
|
|
|
|
{
|
|
|
|
if (offset != 0 or scale != 1) {
|
|
|
|
Assembler::Register normalizedIndex
|
|
|
|
(*preserveIndex ? c->client->acquireTemporary() : index);
|
|
|
|
|
|
|
|
if (*preserveIndex) {
|
|
|
|
*release = true;
|
|
|
|
*preserveIndex = false;
|
|
|
|
} else {
|
|
|
|
*release = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int scaled;
|
|
|
|
|
|
|
|
if (scale != 1) {
|
|
|
|
Assembler::Register unscaledIndex(index);
|
|
|
|
|
|
|
|
ResolvedPromise scalePromise(log(scale));
|
|
|
|
Assembler::Constant scaleConstant(&scalePromise);
|
|
|
|
|
|
|
|
shiftLeftC(c, BytesPerWord, &scaleConstant,
|
|
|
|
&unscaledIndex, &normalizedIndex);
|
|
|
|
|
|
|
|
scaled = normalizedIndex.low;
|
|
|
|
} else {
|
|
|
|
scaled = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset != 0) {
|
|
|
|
Assembler::Register untranslatedIndex(scaled);
|
|
|
|
|
|
|
|
ResolvedPromise offsetPromise(offset);
|
|
|
|
Assembler::Constant offsetConstant(&offsetPromise);
|
|
|
|
|
2010-08-30 22:13:10 +00:00
|
|
|
Assembler::Register tmp(c->client->acquireTemporary());
|
|
|
|
moveCR(c, BytesPerWord, &offsetConstant, BytesPerWord, &tmp);
|
|
|
|
addR(c, BytesPerWord, &tmp, &untranslatedIndex, &normalizedIndex);
|
|
|
|
c->client->releaseTemporary(tmp.low);
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return normalizedIndex.low;
|
|
|
|
} else {
|
|
|
|
*release = false;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
store(Context* c, unsigned size, Assembler::Register* src,
|
|
|
|
int base, int offset, int index, unsigned scale, bool preserveIndex)
|
|
|
|
{
|
|
|
|
if (index != NoRegister) {
|
|
|
|
bool release;
|
|
|
|
int normalized = normalize
|
|
|
|
(c, offset, index, scale, &preserveIndex, &release);
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, strb(src->low, base, normalized));
|
2009-08-06 17:52:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, strh(src->low, base, normalized));
|
2009-08-06 17:52:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, str(src->low, base, normalized));
|
2009-08-06 17:52:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 8: {
|
|
|
|
Assembler::Register srcHigh(src->high);
|
|
|
|
store(c, 4, &srcHigh, base, 0, normalized, 1, preserveIndex);
|
|
|
|
store(c, 4, src, base, 4, normalized, 1, preserveIndex);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
default: abort(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (release) c->client->releaseTemporary(normalized);
|
2010-11-10 00:31:52 +00:00
|
|
|
} else if (size == 8
|
|
|
|
or abs(offset) == (abs(offset) & 0xFF)
|
|
|
|
or (size != 2 and abs(offset) == (abs(offset) & 0xFFF)))
|
|
|
|
{
|
2009-08-06 17:52:36 +00:00
|
|
|
switch (size) {
|
|
|
|
case 1:
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, strbi(src->low, base, offset));
|
2009-08-06 17:52:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, strhi(src->low, base, offset));
|
2009-08-06 17:52:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, stri(src->low, base, offset));
|
2009-08-06 17:52:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 8: {
|
|
|
|
Assembler::Register srcHigh(src->high);
|
|
|
|
store(c, 4, &srcHigh, base, offset, NoRegister, 1, false);
|
|
|
|
store(c, 4, src, base, offset + 4, NoRegister, 1, false);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
default: abort(c);
|
|
|
|
}
|
2010-11-09 18:36:38 +00:00
|
|
|
} else {
|
|
|
|
Assembler::Register tmp(c->client->acquireTemporary());
|
|
|
|
ResolvedPromise offsetPromise(offset);
|
|
|
|
Assembler::Constant offsetConstant(&offsetPromise);
|
|
|
|
moveCR(c, BytesPerWord, &offsetConstant, BytesPerWord, &tmp);
|
|
|
|
|
|
|
|
store(c, size, src, base, 0, tmp.low, 1, false);
|
|
|
|
|
|
|
|
c->client->releaseTemporary(tmp.low);
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
moveRM(Context* c, unsigned srcSize, Assembler::Register* src,
|
|
|
|
unsigned dstSize UNUSED, Assembler::Memory* dst)
|
|
|
|
{
|
|
|
|
assert(c, srcSize == dstSize);
|
|
|
|
|
|
|
|
store(c, srcSize, src, dst->base, dst->offset, dst->index, dst->scale, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
moveAndUpdateRM(Context* c, unsigned srcSize UNUSED, Assembler::Register* src,
|
|
|
|
unsigned dstSize UNUSED, Assembler::Memory* dst)
|
|
|
|
{
|
|
|
|
assert(c, srcSize == BytesPerWord);
|
|
|
|
assert(c, dstSize == BytesPerWord);
|
|
|
|
|
2009-10-29 16:12:30 +00:00
|
|
|
if (dst->index == NoRegister) {
|
2010-08-28 00:52:33 +00:00
|
|
|
emit(c, stri(src->low, dst->base, dst->offset, dst->offset ? 1 : 0));
|
2009-10-29 16:12:30 +00:00
|
|
|
} else {
|
|
|
|
assert(c, dst->offset == 0);
|
|
|
|
assert(c, dst->scale == 1);
|
|
|
|
|
2010-11-08 00:41:44 +00:00
|
|
|
emit(c, str(src->low, dst->base, dst->index, 1));
|
2009-10-29 16:12:30 +00:00
|
|
|
}
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
load(Context* c, unsigned srcSize, int base, int offset, int index,
|
|
|
|
unsigned scale, unsigned dstSize, Assembler::Register* dst,
|
|
|
|
bool preserveIndex, bool signExtend)
|
|
|
|
{
|
|
|
|
if (index != NoRegister) {
|
|
|
|
bool release;
|
|
|
|
int normalized = normalize
|
|
|
|
(c, offset, index, scale, &preserveIndex, &release);
|
|
|
|
|
|
|
|
switch (srcSize) {
|
|
|
|
case 1:
|
|
|
|
if (signExtend) {
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, ldrsb(dst->low, base, normalized));
|
|
|
|
} else {
|
|
|
|
emit(c, ldrb(dst->low, base, normalized));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
if (signExtend) {
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, ldrsh(dst->low, base, normalized));
|
2009-08-06 17:52:36 +00:00
|
|
|
} else {
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, ldrh(dst->low, base, normalized));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
case 8: {
|
|
|
|
if (srcSize == 4 and dstSize == 8) {
|
|
|
|
load(c, 4, base, 0, normalized, 1, 4, dst, preserveIndex, false);
|
|
|
|
moveRR(c, 4, dst, 8, dst);
|
|
|
|
} else if (srcSize == 8 and dstSize == 8) {
|
|
|
|
Assembler::Register dstHigh(dst->high);
|
|
|
|
load(c, 4, base, 0, normalized, 1, 4, &dstHigh, preserveIndex, false);
|
|
|
|
load(c, 4, base, 4, normalized, 1, 4, dst, preserveIndex, false);
|
|
|
|
} else {
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, ldr(dst->low, base, normalized));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
default: abort(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (release) c->client->releaseTemporary(normalized);
|
2010-11-09 18:36:38 +00:00
|
|
|
} else if ((srcSize == 8 and dstSize == 8)
|
2010-11-10 00:31:52 +00:00
|
|
|
or abs(offset) == (abs(offset) & 0xFF)
|
|
|
|
or (srcSize != 2
|
|
|
|
and (srcSize != 1 or not signExtend)
|
|
|
|
and abs(offset) == (abs(offset) & 0xFFF)))
|
2010-11-09 18:36:38 +00:00
|
|
|
{
|
2009-08-06 17:52:36 +00:00
|
|
|
switch (srcSize) {
|
|
|
|
case 1:
|
|
|
|
if (signExtend) {
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, ldrsbi(dst->low, base, offset));
|
|
|
|
} else {
|
|
|
|
emit(c, ldrbi(dst->low, base, offset));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
if (signExtend) {
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, ldrshi(dst->low, base, offset));
|
2009-08-06 17:52:36 +00:00
|
|
|
} else {
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, ldrhi(dst->low, base, offset));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, ldri(dst->low, base, offset));
|
2009-08-06 17:52:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 8: {
|
2009-10-29 16:12:30 +00:00
|
|
|
if (dstSize == 8) {
|
2009-08-06 17:52:36 +00:00
|
|
|
Assembler::Register dstHigh(dst->high);
|
|
|
|
load(c, 4, base, offset, NoRegister, 1, 4, &dstHigh, false, false);
|
|
|
|
load(c, 4, base, offset + 4, NoRegister, 1, 4, dst, false, false);
|
|
|
|
} else {
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, ldri(dst->low, base, offset));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
default: abort(c);
|
|
|
|
}
|
2010-11-09 18:36:38 +00:00
|
|
|
} else {
|
|
|
|
Assembler::Register tmp(c->client->acquireTemporary());
|
|
|
|
ResolvedPromise offsetPromise(offset);
|
|
|
|
Assembler::Constant offsetConstant(&offsetPromise);
|
|
|
|
moveCR(c, BytesPerWord, &offsetConstant, BytesPerWord, &tmp);
|
|
|
|
|
|
|
|
load(c, srcSize, base, 0, tmp.low, 1, dstSize, dst, false, signExtend);
|
|
|
|
|
|
|
|
c->client->releaseTemporary(tmp.low);
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
moveMR(Context* c, unsigned srcSize, Assembler::Memory* src,
|
|
|
|
unsigned dstSize, Assembler::Register* dst)
|
|
|
|
{
|
|
|
|
load(c, srcSize, src->base, src->offset, src->index, src->scale,
|
|
|
|
dstSize, dst, true, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
moveZMR(Context* c, unsigned srcSize, Assembler::Memory* src,
|
|
|
|
unsigned dstSize, Assembler::Register* dst)
|
|
|
|
{
|
|
|
|
load(c, srcSize, src->base, src->offset, src->index, src->scale,
|
|
|
|
dstSize, dst, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
andR(Context* c, unsigned size, Assembler::Register* a,
|
|
|
|
Assembler::Register* b, Assembler::Register* dst)
|
|
|
|
{
|
2009-10-29 16:12:30 +00:00
|
|
|
if (size == 8) emit(c, and_(dst->high, a->high, b->high));
|
|
|
|
emit(c, and_(dst->low, a->low, b->low));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
2010-09-03 17:32:22 +00:00
|
|
|
void
|
|
|
|
andC(Context* c, unsigned size, Assembler::Constant* a,
|
|
|
|
Assembler::Register* b, Assembler::Register* dst)
|
|
|
|
{
|
|
|
|
int64_t v = a->value->value();
|
|
|
|
|
|
|
|
if (size == 8) {
|
|
|
|
ResolvedPromise high((v >> 32) & 0xFFFFFFFF);
|
|
|
|
Assembler::Constant ah(&high);
|
|
|
|
|
|
|
|
ResolvedPromise low(v & 0xFFFFFFFF);
|
|
|
|
Assembler::Constant al(&low);
|
|
|
|
|
|
|
|
Assembler::Register bh(b->high);
|
|
|
|
Assembler::Register dh(dst->high);
|
|
|
|
|
|
|
|
andC(c, 4, &al, b, dst);
|
|
|
|
andC(c, 4, &ah, &bh, &dh);
|
|
|
|
} else {
|
|
|
|
uint32_t v32 = static_cast<uint32_t>(v);
|
|
|
|
if (v32 != 0xFFFFFFFF) {
|
|
|
|
if ((v32 & 0xFFFFFF00) == 0xFFFFFF00) {
|
|
|
|
emit(c, bici(dst->low, b->low, (~(v32 & 0xFF)) & 0xFF));
|
|
|
|
} else if ((v32 & 0xFFFFFF00) == 0) {
|
|
|
|
emit(c, andi(dst->low, b->low, v32 & 0xFF));
|
|
|
|
} else {
|
|
|
|
// todo: there are other cases we can handle in one
|
|
|
|
// instruction
|
|
|
|
|
|
|
|
bool useTemporary = b->low == dst->low;
|
|
|
|
Assembler::Register tmp(dst->low);
|
|
|
|
if (useTemporary) {
|
|
|
|
tmp.low = c->client->acquireTemporary();
|
|
|
|
}
|
|
|
|
|
|
|
|
moveCR(c, 4, a, 4, &tmp);
|
|
|
|
andR(c, 4, b, &tmp, dst);
|
|
|
|
|
|
|
|
if (useTemporary) {
|
|
|
|
c->client->releaseTemporary(tmp.low);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
moveRR(c, size, b, size, dst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-06 17:52:36 +00:00
|
|
|
void
|
|
|
|
orR(Context* c, unsigned size, Assembler::Register* a,
|
|
|
|
Assembler::Register* b, Assembler::Register* dst)
|
|
|
|
{
|
2010-09-03 18:52:11 +00:00
|
|
|
if (size == 8) emit(c, orr(dst->high, a->high, b->high));
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, orr(dst->low, a->low, b->low));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-12 20:18:36 +00:00
|
|
|
xorR(Context* con, unsigned size, Assembler::Register* a,
|
2009-08-06 17:52:36 +00:00
|
|
|
Assembler::Register* b, Assembler::Register* dst)
|
|
|
|
{
|
2010-07-12 20:18:36 +00:00
|
|
|
if (size == 8) emit(con, eor(dst->high, a->high, b->high));
|
|
|
|
emit(con, eor(dst->low, a->low, b->low));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-12 20:18:36 +00:00
|
|
|
moveAR2(Context* c, unsigned srcSize, Assembler::Address* src,
|
2010-11-14 02:28:05 +00:00
|
|
|
unsigned dstSize, Assembler::Register* dst)
|
2009-08-06 17:52:36 +00:00
|
|
|
{
|
|
|
|
assert(c, srcSize == 4 and dstSize == 4);
|
|
|
|
|
|
|
|
Assembler::Constant constant(src->address);
|
|
|
|
moveCR(c, srcSize, &constant, dstSize, dst);
|
2010-11-14 02:28:05 +00:00
|
|
|
|
|
|
|
Assembler::Memory memory(dst->low, 0, -1, 0);
|
2009-08-06 17:52:36 +00:00
|
|
|
moveMR(c, dstSize, &memory, dstSize, dst);
|
|
|
|
}
|
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
void
|
|
|
|
moveAR(Context* c, unsigned srcSize, Assembler::Address* src,
|
|
|
|
unsigned dstSize, Assembler::Register* dst)
|
|
|
|
{
|
2010-11-14 02:28:05 +00:00
|
|
|
moveAR2(c, srcSize, src, dstSize, dst);
|
2010-07-12 20:18:36 +00:00
|
|
|
}
|
|
|
|
|
2009-08-06 17:52:36 +00:00
|
|
|
void
|
|
|
|
compareRR(Context* c, unsigned aSize UNUSED, Assembler::Register* a,
|
|
|
|
unsigned bSize UNUSED, Assembler::Register* b)
|
|
|
|
{
|
|
|
|
assert(c, aSize == 4 and bSize == 4);
|
2010-11-09 18:36:38 +00:00
|
|
|
assert(c, b->low != a->low);
|
|
|
|
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, cmp(b->low, a->low));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
compareCR(Context* c, unsigned aSize, Assembler::Constant* a,
|
|
|
|
unsigned bSize, Assembler::Register* b)
|
|
|
|
{
|
|
|
|
assert(c, aSize == 4 and bSize == 4);
|
|
|
|
|
2010-08-30 22:13:10 +00:00
|
|
|
if (a->value->resolved() and isOfWidth(a->value->value(), 8)) {
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, cmpi(b->low, a->value->value()));
|
2009-08-06 17:52:36 +00:00
|
|
|
} else {
|
|
|
|
Assembler::Register tmp(c->client->acquireTemporary());
|
|
|
|
moveCR(c, aSize, a, bSize, &tmp);
|
|
|
|
compareRR(c, bSize, &tmp, bSize, b);
|
|
|
|
c->client->releaseTemporary(tmp.low);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
compareCM(Context* c, unsigned aSize, Assembler::Constant* a,
|
|
|
|
unsigned bSize, Assembler::Memory* b)
|
|
|
|
{
|
|
|
|
assert(c, aSize == 4 and bSize == 4);
|
|
|
|
|
|
|
|
Assembler::Register tmp(c->client->acquireTemporary());
|
|
|
|
moveMR(c, bSize, b, bSize, &tmp);
|
|
|
|
compareCR(c, aSize, a, bSize, &tmp);
|
|
|
|
c->client->releaseTemporary(tmp.low);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
compareRM(Context* c, unsigned aSize, Assembler::Register* a,
|
|
|
|
unsigned bSize, Assembler::Memory* b)
|
|
|
|
{
|
|
|
|
assert(c, aSize == 4 and bSize == 4);
|
|
|
|
|
|
|
|
Assembler::Register tmp(c->client->acquireTemporary());
|
|
|
|
moveMR(c, bSize, b, bSize, &tmp);
|
|
|
|
compareRR(c, aSize, a, bSize, &tmp);
|
|
|
|
c->client->releaseTemporary(tmp.low);
|
|
|
|
}
|
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
int32_t
|
|
|
|
branch(Context* c, TernaryOperation op)
|
2009-08-06 17:52:36 +00:00
|
|
|
{
|
2010-07-12 20:18:36 +00:00
|
|
|
switch (op) {
|
|
|
|
case JumpIfEqual:
|
|
|
|
return beq(0);
|
|
|
|
|
|
|
|
case JumpIfNotEqual:
|
|
|
|
return bne(0);
|
|
|
|
|
|
|
|
case JumpIfLess:
|
|
|
|
return blt(0);
|
|
|
|
|
|
|
|
case JumpIfGreater:
|
|
|
|
return bgt(0);
|
|
|
|
|
|
|
|
case JumpIfLessOrEqual:
|
|
|
|
return ble(0);
|
|
|
|
|
|
|
|
case JumpIfGreaterOrEqual:
|
|
|
|
return bge(0);
|
|
|
|
|
|
|
|
default:
|
|
|
|
abort(c);
|
|
|
|
}
|
|
|
|
}
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
void
|
|
|
|
conditional(Context* c, int32_t branch, Assembler::Constant* target)
|
|
|
|
{
|
2010-11-14 02:28:05 +00:00
|
|
|
appendOffsetTask(c, target->value, offset(c));
|
2010-07-12 20:18:36 +00:00
|
|
|
emit(c, branch);
|
|
|
|
}
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
void
|
|
|
|
branch(Context* c, TernaryOperation op, Assembler::Constant* target)
|
|
|
|
{
|
|
|
|
conditional(c, branch(c, op), target);
|
|
|
|
}
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
void
|
|
|
|
branchLong(Context* c, TernaryOperation op, Assembler::Operand* al,
|
|
|
|
Assembler::Operand* ah, Assembler::Operand* bl,
|
|
|
|
Assembler::Operand* bh, Assembler::Constant* target,
|
|
|
|
BinaryOperationType compareSigned,
|
|
|
|
BinaryOperationType compareUnsigned)
|
|
|
|
{
|
2009-08-06 17:52:36 +00:00
|
|
|
compareSigned(c, 4, ah, 4, bh);
|
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
unsigned next = 0;
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
case JumpIfEqual:
|
|
|
|
next = c->code.length();
|
|
|
|
emit(c, bne(0));
|
|
|
|
|
|
|
|
compareSigned(c, 4, al, 4, bl);
|
|
|
|
conditional(c, beq(0), target);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JumpIfNotEqual:
|
|
|
|
conditional(c, bne(0), target);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
compareSigned(c, 4, al, 4, bl);
|
|
|
|
conditional(c, bne(0), target);
|
|
|
|
break;
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
case JumpIfLess:
|
|
|
|
conditional(c, blt(0), target);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
next = c->code.length();
|
|
|
|
emit(c, bgt(0));
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
compareUnsigned(c, 4, al, 4, bl);
|
2010-09-01 00:35:55 +00:00
|
|
|
conditional(c, blo(0), target);
|
2010-07-12 20:18:36 +00:00
|
|
|
break;
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
case JumpIfGreater:
|
|
|
|
conditional(c, bgt(0), target);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
next = c->code.length();
|
|
|
|
emit(c, blt(0));
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
compareUnsigned(c, 4, al, 4, bl);
|
2010-09-01 00:35:55 +00:00
|
|
|
conditional(c, bhi(0), target);
|
2010-07-12 20:18:36 +00:00
|
|
|
break;
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
case JumpIfLessOrEqual:
|
|
|
|
conditional(c, blt(0), target);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
next = c->code.length();
|
|
|
|
emit(c, bgt(0));
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
compareUnsigned(c, 4, al, 4, bl);
|
2010-09-01 00:35:55 +00:00
|
|
|
conditional(c, bls(0), target);
|
2010-07-12 20:18:36 +00:00
|
|
|
break;
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
case JumpIfGreaterOrEqual:
|
|
|
|
conditional(c, bgt(0), target);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
next = c->code.length();
|
|
|
|
emit(c, blt(0));
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
compareUnsigned(c, 4, al, 4, bl);
|
2010-09-01 00:35:55 +00:00
|
|
|
conditional(c, bhs(0), target);
|
2010-07-12 20:18:36 +00:00
|
|
|
break;
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
default:
|
|
|
|
abort(c);
|
|
|
|
}
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
if (next) {
|
|
|
|
updateOffset
|
2010-11-14 02:28:05 +00:00
|
|
|
(c->s, c->code.data + next, reinterpret_cast<intptr_t>
|
2010-07-12 20:18:36 +00:00
|
|
|
(c->code.data + c->code.length()));
|
|
|
|
}
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-12 20:18:36 +00:00
|
|
|
branchRR(Context* c, TernaryOperation op, unsigned size,
|
|
|
|
Assembler::Register* a, Assembler::Register* b,
|
|
|
|
Assembler::Constant* target)
|
2009-08-06 17:52:36 +00:00
|
|
|
{
|
2010-07-12 20:18:36 +00:00
|
|
|
if (size > BytesPerWord) {
|
|
|
|
Assembler::Register ah(a->high);
|
|
|
|
Assembler::Register bh(b->high);
|
|
|
|
|
|
|
|
branchLong(c, op, a, &ah, b, &bh, target, CAST2(compareRR),
|
|
|
|
CAST2(compareRR));
|
|
|
|
} else {
|
|
|
|
compareRR(c, size, a, size, b);
|
|
|
|
branch(c, op, target);
|
|
|
|
}
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-12 20:18:36 +00:00
|
|
|
branchCR(Context* c, TernaryOperation op, unsigned size,
|
|
|
|
Assembler::Constant* a, Assembler::Register* b,
|
|
|
|
Assembler::Constant* target)
|
2009-08-06 17:52:36 +00:00
|
|
|
{
|
2010-07-12 20:18:36 +00:00
|
|
|
if (size > BytesPerWord) {
|
|
|
|
int64_t v = a->value->value();
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
ResolvedPromise low(v & ~static_cast<uintptr_t>(0));
|
|
|
|
Assembler::Constant al(&low);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
ResolvedPromise high((v >> 32) & ~static_cast<uintptr_t>(0));
|
|
|
|
Assembler::Constant ah(&high);
|
|
|
|
|
|
|
|
Assembler::Register bh(b->high);
|
|
|
|
|
|
|
|
branchLong(c, op, &al, &ah, b, &bh, target, CAST2(compareCR),
|
|
|
|
CAST2(compareCR));
|
|
|
|
} else {
|
|
|
|
compareCR(c, size, a, size, b);
|
|
|
|
branch(c, op, target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
branchRM(Context* c, TernaryOperation op, unsigned size,
|
|
|
|
Assembler::Register* a, Assembler::Memory* b,
|
|
|
|
Assembler::Constant* target)
|
|
|
|
{
|
|
|
|
assert(c, size <= BytesPerWord);
|
|
|
|
|
|
|
|
compareRM(c, size, a, size, b);
|
|
|
|
branch(c, op, target);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
branchCM(Context* c, TernaryOperation op, unsigned size,
|
|
|
|
Assembler::Constant* a, Assembler::Memory* b,
|
|
|
|
Assembler::Constant* target)
|
|
|
|
{
|
|
|
|
assert(c, size <= BytesPerWord);
|
|
|
|
|
|
|
|
compareCM(c, size, a, size, b);
|
|
|
|
branch(c, op, target);
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ShiftMaskPromise*
|
|
|
|
shiftMaskPromise(Context* c, Promise* base, unsigned shift, int64_t mask)
|
|
|
|
{
|
|
|
|
return new (c->zone->allocate(sizeof(ShiftMaskPromise)))
|
|
|
|
ShiftMaskPromise(base, shift, mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
moveCM(Context* c, unsigned srcSize, Assembler::Constant* src,
|
|
|
|
unsigned dstSize, Assembler::Memory* dst)
|
|
|
|
{
|
|
|
|
switch (dstSize) {
|
|
|
|
case 8: {
|
|
|
|
Assembler::Constant srcHigh
|
|
|
|
(shiftMaskPromise(c, src->value, 32, 0xFFFFFFFF));
|
|
|
|
Assembler::Constant srcLow
|
|
|
|
(shiftMaskPromise(c, src->value, 0, 0xFFFFFFFF));
|
|
|
|
|
|
|
|
Assembler::Memory dstLow
|
|
|
|
(dst->base, dst->offset + 4, dst->index, dst->scale);
|
|
|
|
|
|
|
|
moveCM(c, 4, &srcLow, 4, &dstLow);
|
|
|
|
moveCM(c, 4, &srcHigh, 4, dst);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Assembler::Register tmp(c->client->acquireTemporary());
|
|
|
|
moveCR(c, srcSize, src, dstSize, &tmp);
|
|
|
|
moveRM(c, dstSize, &tmp, dstSize, dst);
|
|
|
|
c->client->releaseTemporary(tmp.low);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
negateRR(Context* c, unsigned srcSize, Assembler::Register* src,
|
|
|
|
unsigned dstSize UNUSED, Assembler::Register* dst)
|
|
|
|
{
|
|
|
|
assert(c, srcSize == dstSize);
|
|
|
|
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, mvn(dst->low, src->low));
|
|
|
|
emit(c, SETS(addi(dst->low, dst->low, 1)));
|
2009-08-06 17:52:36 +00:00
|
|
|
if (srcSize == 8) {
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, mvn(dst->high, src->high));
|
|
|
|
emit(c, adci(dst->high, dst->high, 0));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
callR(Context* c, unsigned size UNUSED, Assembler::Register* target)
|
|
|
|
{
|
|
|
|
assert(c, size == BytesPerWord);
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, blx(target->low));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
callC(Context* c, unsigned size UNUSED, Assembler::Constant* target)
|
|
|
|
{
|
|
|
|
assert(c, size == BytesPerWord);
|
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
appendOffsetTask(c, target->value, offset(c));
|
2009-10-29 16:12:30 +00:00
|
|
|
emit(c, bl(0));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
longCallC(Context* c, unsigned size UNUSED, Assembler::Constant* target)
|
|
|
|
{
|
|
|
|
assert(c, size == BytesPerWord);
|
|
|
|
|
2010-08-28 00:52:33 +00:00
|
|
|
Assembler::Register tmp(4);
|
2010-11-16 02:38:36 +00:00
|
|
|
moveCR2(c, BytesPerWord, target, BytesPerWord, &tmp, offset(c));
|
2009-08-06 17:52:36 +00:00
|
|
|
callR(c, BytesPerWord, &tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
longJumpC(Context* c, unsigned size UNUSED, Assembler::Constant* target)
|
|
|
|
{
|
|
|
|
assert(c, size == BytesPerWord);
|
|
|
|
|
2010-08-28 00:52:33 +00:00
|
|
|
Assembler::Register tmp(4); // a non-arg reg that we don't mind clobbering
|
2010-11-16 02:38:36 +00:00
|
|
|
moveCR2(c, BytesPerWord, target, BytesPerWord, &tmp, offset(c));
|
2010-07-12 20:18:36 +00:00
|
|
|
jumpR(c, BytesPerWord, &tmp);
|
|
|
|
}
|
|
|
|
|
2009-08-06 17:52:36 +00:00
|
|
|
void
|
|
|
|
jumpC(Context* c, unsigned size UNUSED, Assembler::Constant* target)
|
|
|
|
{
|
|
|
|
assert(c, size == BytesPerWord);
|
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
appendOffsetTask(c, target->value, offset(c));
|
2009-10-29 20:14:44 +00:00
|
|
|
emit(c, b(0));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
return_(Context* c)
|
|
|
|
{
|
2010-08-28 00:52:33 +00:00
|
|
|
emit(c, bx(LinkRegister));
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-12 20:18:36 +00:00
|
|
|
memoryBarrier(Context*) {}
|
2009-08-06 17:52:36 +00:00
|
|
|
|
|
|
|
// END OPERATION COMPILERS
|
|
|
|
|
|
|
|
void
|
|
|
|
populateTables(ArchitectureContext* c)
|
|
|
|
{
|
|
|
|
const OperandType C = ConstantOperand;
|
|
|
|
const OperandType A = AddressOperand;
|
|
|
|
const OperandType R = RegisterOperand;
|
|
|
|
const OperandType M = MemoryOperand;
|
|
|
|
|
|
|
|
OperationType* zo = c->operations;
|
|
|
|
UnaryOperationType* uo = c->unaryOperations;
|
|
|
|
BinaryOperationType* bo = c->binaryOperations;
|
|
|
|
TernaryOperationType* to = c->ternaryOperations;
|
2010-07-12 20:18:36 +00:00
|
|
|
BranchOperationType* bro = c->branchOperations;
|
2009-08-06 17:52:36 +00:00
|
|
|
|
|
|
|
zo[Return] = return_;
|
|
|
|
zo[LoadBarrier] = memoryBarrier;
|
|
|
|
zo[StoreStoreBarrier] = memoryBarrier;
|
|
|
|
zo[StoreLoadBarrier] = memoryBarrier;
|
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
uo[index(c, LongCall, C)] = CAST1(longCallC);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
uo[index(c, AlignedLongCall, C)] = CAST1(longCallC);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
uo[index(c, LongJump, C)] = CAST1(longJumpC);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
uo[index(c, AlignedLongJump, C)] = CAST1(longJumpC);
|
2009-10-29 16:12:30 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
uo[index(c, Jump, R)] = CAST1(jumpR);
|
|
|
|
uo[index(c, Jump, C)] = CAST1(jumpC);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
uo[index(c, AlignedJump, R)] = CAST1(jumpR);
|
|
|
|
uo[index(c, AlignedJump, C)] = CAST1(jumpC);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
uo[index(c, Call, C)] = CAST1(callC);
|
|
|
|
uo[index(c, Call, R)] = CAST1(callR);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
uo[index(c, AlignedCall, C)] = CAST1(callC);
|
|
|
|
uo[index(c, AlignedCall, R)] = CAST1(callR);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
bo[index(c, Move, R, R)] = CAST2(moveRR);
|
|
|
|
bo[index(c, Move, C, R)] = CAST2(moveCR);
|
|
|
|
bo[index(c, Move, C, M)] = CAST2(moveCM);
|
|
|
|
bo[index(c, Move, M, R)] = CAST2(moveMR);
|
|
|
|
bo[index(c, Move, R, M)] = CAST2(moveRM);
|
|
|
|
bo[index(c, Move, A, R)] = CAST2(moveAR);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
bo[index(c, MoveZ, R, R)] = CAST2(moveZRR);
|
|
|
|
bo[index(c, MoveZ, M, R)] = CAST2(moveZMR);
|
|
|
|
bo[index(c, MoveZ, C, R)] = CAST2(moveCR);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
bo[index(c, Negate, R, R)] = CAST2(negateRR);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
to[index(c, Add, R)] = CAST3(addR);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
to[index(c, Subtract, R)] = CAST3(subR);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
to[index(c, Multiply, R)] = CAST3(multiplyR);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
to[index(c, ShiftLeft, R)] = CAST3(shiftLeftR);
|
|
|
|
to[index(c, ShiftLeft, C)] = CAST3(shiftLeftC);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
to[index(c, ShiftRight, R)] = CAST3(shiftRightR);
|
|
|
|
to[index(c, ShiftRight, C)] = CAST3(shiftRightC);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
to[index(c, UnsignedShiftRight, R)] = CAST3(unsignedShiftRightR);
|
|
|
|
to[index(c, UnsignedShiftRight, C)] = CAST3(unsignedShiftRightC);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
to[index(c, And, R)] = CAST3(andR);
|
2010-09-03 17:32:22 +00:00
|
|
|
to[index(c, And, C)] = CAST3(andC);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
to[index(c, Or, R)] = CAST3(orR);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
to[index(c, Xor, R)] = CAST3(xorR);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
bro[branchIndex(c, R, R)] = CAST_BRANCH(branchRR);
|
|
|
|
bro[branchIndex(c, C, R)] = CAST_BRANCH(branchCR);
|
|
|
|
bro[branchIndex(c, C, M)] = CAST_BRANCH(branchCM);
|
|
|
|
bro[branchIndex(c, R, M)] = CAST_BRANCH(branchRM);
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class MyArchitecture: public Assembler::Architecture {
|
|
|
|
public:
|
|
|
|
MyArchitecture(System* system): c(system), referenceCount(0) {
|
|
|
|
populateTables(&c);
|
|
|
|
}
|
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
virtual unsigned floatRegisterSize() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual uint32_t generalRegisterMask() {
|
2010-08-24 23:59:01 +00:00
|
|
|
return 0xFFFF;
|
2010-07-12 20:18:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual uint32_t floatRegisterMask() {
|
|
|
|
return 0;
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual int stack() {
|
|
|
|
return StackRegister;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int thread() {
|
|
|
|
return ThreadRegister;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int returnLow() {
|
2010-07-12 20:18:36 +00:00
|
|
|
return 0;
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual int returnHigh() {
|
2010-07-12 20:18:36 +00:00
|
|
|
return 1;
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
2009-10-29 16:12:30 +00:00
|
|
|
virtual int virtualCallTarget() {
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual int virtualCallIndex() {
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
virtual bool bigEndian() {
|
2009-08-06 17:52:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
virtual uintptr_t maximumImmediateJump() {
|
2010-08-24 23:59:01 +00:00
|
|
|
return 0x1FFFFFF;
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool reserved(int register_) {
|
|
|
|
switch (register_) {
|
2010-11-08 00:41:44 +00:00
|
|
|
case LinkRegister:
|
2009-08-06 17:52:36 +00:00
|
|
|
case StackRegister:
|
|
|
|
case ThreadRegister:
|
2010-08-24 23:59:01 +00:00
|
|
|
case ProgramCounter:
|
2009-08-06 17:52:36 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-29 16:12:30 +00:00
|
|
|
virtual unsigned frameFootprint(unsigned footprint) {
|
|
|
|
return max(footprint, StackAlignmentInWords);
|
|
|
|
}
|
|
|
|
|
2009-08-06 17:52:36 +00:00
|
|
|
virtual unsigned argumentFootprint(unsigned footprint) {
|
2009-10-29 16:12:30 +00:00
|
|
|
return max(pad(footprint, StackAlignmentInWords), StackAlignmentInWords);
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
support stack unwinding without using a frame pointer
Previously, we unwound the stack by following the chain of frame
pointers for normal returns, stack trace creation, and exception
unwinding. On x86, this required reserving EBP/RBP for frame pointer
duties, making it unavailable for general computation and requiring
that it be explicitly saved and restored on entry and exit,
respectively.
On PowerPC, we use an ABI that makes the stack pointer double as a
frame pointer, so it doesn't cost us anything. We've been using the
same convention on ARM, but it doesn't match the native calling
convention, which makes it unusable when we want to call native code
from Java and pass arguments on the stack.
So far, the ARM calling convention mismatch hasn't been an issue
because we've never passed more arguments from Java to native code
than would fit in registers. However, we must now pass an extra
argument (the thread pointer) to e.g. divideLong so it can throw an
exception on divide by zero, which means the last argument must be
passed on the stack. This will clobber the linkage area we've been
using to hold the frame pointer, so we need to stop using it.
One solution would be to use the same convention on ARM as we do on
x86, but this would introduce the same overhead of making a register
unavailable for general use and extra code at method entry and exit.
Instead, this commit removes the need for a frame pointer. Unwinding
involves consulting a map of instruction offsets to frame sizes which
is generated at compile time. This is necessary because stack trace
creation can happen at any time due to Thread.getStackTrace being
called by another thread, and the frame size varies during the
execution of a method.
So far, only x86(_64) is working, and continuations and tail call
optimization are probably broken. More to come.
2011-01-17 02:05:05 +00:00
|
|
|
virtual bool argumentAlignment() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-08-06 17:52:36 +00:00
|
|
|
virtual unsigned argumentRegisterCount() {
|
2009-10-29 20:14:44 +00:00
|
|
|
return 4;
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual int argumentRegister(unsigned index) {
|
|
|
|
assert(&c, index < argumentRegisterCount());
|
|
|
|
|
2010-11-08 00:41:44 +00:00
|
|
|
return index;
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
2010-07-12 20:18:36 +00:00
|
|
|
|
2009-10-29 16:12:30 +00:00
|
|
|
virtual unsigned stackAlignmentInWords() {
|
|
|
|
return StackAlignmentInWords;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool matchCall(void* returnAddress, void* target) {
|
|
|
|
uint32_t* instruction = static_cast<uint32_t*>(returnAddress) - 1;
|
|
|
|
|
|
|
|
return *instruction == static_cast<uint32_t>
|
|
|
|
(bl(static_cast<uint8_t*>(target)
|
|
|
|
- reinterpret_cast<uint8_t*>(instruction)));
|
|
|
|
}
|
|
|
|
|
2009-08-06 17:52:36 +00:00
|
|
|
virtual void updateCall(UnaryOperation op UNUSED,
|
2010-07-12 20:18:36 +00:00
|
|
|
void* returnAddress,
|
2009-08-06 17:52:36 +00:00
|
|
|
void* newTarget)
|
|
|
|
{
|
|
|
|
switch (op) {
|
|
|
|
case Call:
|
2010-07-12 20:18:36 +00:00
|
|
|
case Jump:
|
|
|
|
case AlignedCall:
|
|
|
|
case AlignedJump: {
|
2010-11-14 02:28:05 +00:00
|
|
|
updateOffset(c.s, static_cast<uint8_t*>(returnAddress) - 4,
|
2009-08-06 17:52:36 +00:00
|
|
|
reinterpret_cast<intptr_t>(newTarget));
|
|
|
|
} break;
|
|
|
|
|
2010-11-16 02:38:36 +00:00
|
|
|
case LongCall:
|
|
|
|
case LongJump:
|
2010-07-12 20:18:36 +00:00
|
|
|
case AlignedLongCall:
|
|
|
|
case AlignedLongJump: {
|
2010-11-16 02:38:36 +00:00
|
|
|
uint32_t* p = static_cast<uint32_t*>(returnAddress) - 2;
|
|
|
|
*reinterpret_cast<void**>(p + (((*p & PoolOffsetMask) + 8) / 4))
|
2010-07-12 20:18:36 +00:00
|
|
|
= newTarget;
|
2009-08-06 17:52:36 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
default: abort(&c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-29 16:12:30 +00:00
|
|
|
virtual unsigned constantCallSize() {
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
2009-08-06 17:52:36 +00:00
|
|
|
virtual void setConstant(void* dst, uintptr_t constant) {
|
2010-11-14 02:28:05 +00:00
|
|
|
*static_cast<uintptr_t*>(dst) = constant;
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual unsigned alignFrameSize(unsigned sizeInWords) {
|
2009-10-29 16:12:30 +00:00
|
|
|
const unsigned alignment = StackAlignmentInBytes / BytesPerWord;
|
2009-08-06 17:52:36 +00:00
|
|
|
return (ceiling(sizeInWords + FrameFooterSize, alignment) * alignment);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void* frameIp(void* stack) {
|
2010-08-28 00:52:33 +00:00
|
|
|
return stack ? static_cast<void**>(stack)[returnAddressOffset()] : 0;
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual unsigned frameHeaderSize() {
|
2010-07-12 20:18:36 +00:00
|
|
|
return FrameHeaderSize;
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual unsigned frameReturnAddressSize() {
|
2010-08-28 00:52:33 +00:00
|
|
|
return 0;
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual unsigned frameFooterSize() {
|
|
|
|
return FrameFooterSize;
|
|
|
|
}
|
|
|
|
|
2009-10-29 16:12:30 +00:00
|
|
|
virtual int returnAddressOffset() {
|
2010-07-12 20:18:36 +00:00
|
|
|
return 1;
|
2009-10-29 16:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual int framePointerOffset() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-06 17:52:36 +00:00
|
|
|
virtual void nextFrame(void** stack, void**) {
|
|
|
|
assert(&c, *static_cast<void**>(*stack) != *stack);
|
|
|
|
|
|
|
|
*stack = *static_cast<void**>(*stack);
|
|
|
|
}
|
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
virtual BinaryOperation hasBinaryIntrinsic(Thread*, object) {
|
|
|
|
return NoBinaryOperation;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual TernaryOperation hasTernaryIntrinsic(Thread*, object) {
|
|
|
|
return NoTernaryOperation;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool alwaysCondensed(BinaryOperation) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool alwaysCondensed(TernaryOperation) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-06 17:52:36 +00:00
|
|
|
virtual void plan
|
|
|
|
(UnaryOperation,
|
|
|
|
unsigned, uint8_t* aTypeMask, uint64_t* aRegisterMask,
|
|
|
|
bool* thunk)
|
|
|
|
{
|
|
|
|
*aTypeMask = (1 << RegisterOperand) | (1 << ConstantOperand);
|
|
|
|
*aRegisterMask = ~static_cast<uint64_t>(0);
|
|
|
|
*thunk = false;
|
|
|
|
}
|
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
virtual void planSource
|
2009-08-06 17:52:36 +00:00
|
|
|
(BinaryOperation op,
|
|
|
|
unsigned, uint8_t* aTypeMask, uint64_t* aRegisterMask,
|
2010-07-12 20:18:36 +00:00
|
|
|
unsigned, bool* thunk)
|
2009-08-06 17:52:36 +00:00
|
|
|
{
|
|
|
|
*aTypeMask = ~0;
|
|
|
|
*aRegisterMask = ~static_cast<uint64_t>(0);
|
|
|
|
|
|
|
|
*thunk = false;
|
|
|
|
|
|
|
|
switch (op) {
|
2010-07-12 20:18:36 +00:00
|
|
|
case Negate:
|
|
|
|
*aTypeMask = (1 << RegisterOperand);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Absolute:
|
|
|
|
case FloatAbsolute:
|
|
|
|
case FloatSquareRoot:
|
|
|
|
case FloatNegate:
|
|
|
|
case Float2Float:
|
|
|
|
case Float2Int:
|
|
|
|
case Int2Float:
|
|
|
|
*thunk = true;
|
2009-08-06 17:52:36 +00:00
|
|
|
break;
|
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void planDestination
|
|
|
|
(BinaryOperation op,
|
|
|
|
unsigned, uint8_t, uint64_t,
|
|
|
|
unsigned, uint8_t* bTypeMask, uint64_t* bRegisterMask)
|
|
|
|
{
|
|
|
|
*bTypeMask = (1 << RegisterOperand) | (1 << MemoryOperand);
|
|
|
|
*bRegisterMask = ~static_cast<uint64_t>(0);
|
|
|
|
|
|
|
|
switch (op) {
|
2009-08-06 17:52:36 +00:00
|
|
|
case Negate:
|
|
|
|
*bTypeMask = (1 << RegisterOperand);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
virtual void planMove
|
|
|
|
(unsigned, uint8_t* srcTypeMask, uint64_t* srcRegisterMask,
|
|
|
|
uint8_t* tmpTypeMask, uint64_t* tmpRegisterMask,
|
|
|
|
uint8_t dstTypeMask, uint64_t)
|
|
|
|
{
|
|
|
|
*srcTypeMask = ~0;
|
|
|
|
*srcRegisterMask = ~static_cast<uint64_t>(0);
|
|
|
|
|
|
|
|
*tmpTypeMask = 0;
|
|
|
|
*tmpRegisterMask = 0;
|
|
|
|
|
|
|
|
if (dstTypeMask & (1 << MemoryOperand)) {
|
|
|
|
// can't move directly from memory or constant to memory
|
|
|
|
*srcTypeMask = 1 << RegisterOperand;
|
|
|
|
*tmpTypeMask = 1 << RegisterOperand;
|
|
|
|
*tmpRegisterMask = ~static_cast<uint64_t>(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void planSource
|
2009-08-06 17:52:36 +00:00
|
|
|
(TernaryOperation op,
|
2010-09-01 00:35:55 +00:00
|
|
|
unsigned, uint8_t* aTypeMask, uint64_t* aRegisterMask,
|
|
|
|
unsigned bSize, uint8_t* bTypeMask, uint64_t* bRegisterMask,
|
2010-07-12 20:18:36 +00:00
|
|
|
unsigned, bool* thunk)
|
2009-08-06 17:52:36 +00:00
|
|
|
{
|
|
|
|
*aTypeMask = (1 << RegisterOperand) | (1 << ConstantOperand);
|
|
|
|
*aRegisterMask = ~static_cast<uint64_t>(0);
|
|
|
|
|
|
|
|
*bTypeMask = (1 << RegisterOperand);
|
|
|
|
*bRegisterMask = ~static_cast<uint64_t>(0);
|
|
|
|
|
|
|
|
*thunk = false;
|
|
|
|
|
|
|
|
switch (op) {
|
2010-09-01 00:35:55 +00:00
|
|
|
case ShiftLeft:
|
|
|
|
case ShiftRight:
|
|
|
|
case UnsignedShiftRight:
|
|
|
|
if (bSize == 8) *aTypeMask = *bTypeMask = (1 << RegisterOperand);
|
|
|
|
break;
|
|
|
|
|
2009-08-06 17:52:36 +00:00
|
|
|
case Add:
|
|
|
|
case Subtract:
|
2010-08-30 22:13:10 +00:00
|
|
|
case Or:
|
|
|
|
case Xor:
|
2009-08-06 17:52:36 +00:00
|
|
|
case Multiply:
|
|
|
|
*aTypeMask = *bTypeMask = (1 << RegisterOperand);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Divide:
|
2009-10-29 20:14:44 +00:00
|
|
|
case Remainder:
|
2010-07-12 20:18:36 +00:00
|
|
|
case FloatAdd:
|
|
|
|
case FloatSubtract:
|
|
|
|
case FloatMultiply:
|
|
|
|
case FloatDivide:
|
|
|
|
case FloatRemainder:
|
|
|
|
case JumpIfFloatEqual:
|
|
|
|
case JumpIfFloatNotEqual:
|
|
|
|
case JumpIfFloatLess:
|
|
|
|
case JumpIfFloatGreater:
|
|
|
|
case JumpIfFloatLessOrEqual:
|
|
|
|
case JumpIfFloatGreaterOrEqual:
|
|
|
|
case JumpIfFloatLessOrUnordered:
|
|
|
|
case JumpIfFloatGreaterOrUnordered:
|
|
|
|
case JumpIfFloatLessOrEqualOrUnordered:
|
|
|
|
case JumpIfFloatGreaterOrEqualOrUnordered:
|
2009-10-29 16:12:30 +00:00
|
|
|
*thunk = true;
|
2009-08-06 17:52:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-07-12 20:18:36 +00:00
|
|
|
}
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
virtual void planDestination
|
|
|
|
(TernaryOperation op,
|
|
|
|
unsigned, uint8_t, uint64_t,
|
|
|
|
unsigned, uint8_t, const uint64_t,
|
|
|
|
unsigned, uint8_t* cTypeMask, uint64_t* cRegisterMask)
|
|
|
|
{
|
|
|
|
if (isBranch(op)) {
|
|
|
|
*cTypeMask = (1 << ConstantOperand);
|
|
|
|
*cRegisterMask = 0;
|
|
|
|
} else {
|
|
|
|
*cTypeMask = (1 << RegisterOperand);
|
|
|
|
*cRegisterMask = ~static_cast<uint64_t>(0);
|
|
|
|
}
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void acquire() {
|
|
|
|
++ referenceCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void release() {
|
|
|
|
if (-- referenceCount == 0) {
|
|
|
|
c.s->free(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ArchitectureContext c;
|
|
|
|
unsigned referenceCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MyAssembler: public Assembler {
|
|
|
|
public:
|
|
|
|
MyAssembler(System* s, Allocator* a, Zone* zone, MyArchitecture* arch):
|
|
|
|
c(s, a, zone), arch_(arch)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual void setClient(Client* client) {
|
|
|
|
assert(&c, c.client == 0);
|
|
|
|
c.client = client;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Architecture* arch() {
|
|
|
|
return arch_;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void saveFrame(unsigned stackOffset, unsigned) {
|
2010-09-02 23:18:19 +00:00
|
|
|
Register returnAddress(LinkRegister);
|
|
|
|
Memory returnAddressDst
|
|
|
|
(StackRegister, arch_->returnAddressOffset() * BytesPerWord);
|
|
|
|
moveRM(&c, BytesPerWord, &returnAddress, BytesPerWord, &returnAddressDst);
|
|
|
|
|
2009-08-06 17:52:36 +00:00
|
|
|
Register stack(StackRegister);
|
|
|
|
Memory stackDst(ThreadRegister, stackOffset);
|
|
|
|
moveRM(&c, BytesPerWord, &stack, BytesPerWord, &stackDst);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void pushFrame(unsigned argumentCount, ...) {
|
|
|
|
struct {
|
|
|
|
unsigned size;
|
|
|
|
OperandType type;
|
|
|
|
Operand* operand;
|
|
|
|
} arguments[argumentCount];
|
|
|
|
|
|
|
|
va_list a; va_start(a, argumentCount);
|
|
|
|
unsigned footprint = 0;
|
|
|
|
for (unsigned i = 0; i < argumentCount; ++i) {
|
|
|
|
arguments[i].size = va_arg(a, unsigned);
|
|
|
|
arguments[i].type = static_cast<OperandType>(va_arg(a, int));
|
|
|
|
arguments[i].operand = va_arg(a, Operand*);
|
|
|
|
footprint += ceiling(arguments[i].size, BytesPerWord);
|
|
|
|
}
|
|
|
|
va_end(a);
|
|
|
|
|
|
|
|
allocateFrame(arch_->alignFrameSize(footprint));
|
|
|
|
|
|
|
|
unsigned offset = 0;
|
|
|
|
for (unsigned i = 0; i < argumentCount; ++i) {
|
|
|
|
if (i < arch_->argumentRegisterCount()) {
|
|
|
|
Register dst(arch_->argumentRegister(i));
|
|
|
|
|
|
|
|
apply(Move,
|
|
|
|
arguments[i].size, arguments[i].type, arguments[i].operand,
|
|
|
|
pad(arguments[i].size), RegisterOperand, &dst);
|
|
|
|
|
|
|
|
offset += ceiling(arguments[i].size, BytesPerWord);
|
|
|
|
} else {
|
|
|
|
Memory dst(ThreadRegister, (offset + FrameFooterSize) * BytesPerWord);
|
|
|
|
|
|
|
|
apply(Move,
|
|
|
|
arguments[i].size, arguments[i].type, arguments[i].operand,
|
|
|
|
pad(arguments[i].size), MemoryOperand, &dst);
|
|
|
|
|
|
|
|
offset += ceiling(arguments[i].size, BytesPerWord);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void allocateFrame(unsigned footprint) {
|
2010-08-28 00:52:33 +00:00
|
|
|
Register returnAddress(LinkRegister);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-08-28 00:52:33 +00:00
|
|
|
Memory returnAddressDst(StackRegister, arch_->returnAddressOffset() * BytesPerWord);
|
2009-08-06 17:52:36 +00:00
|
|
|
moveRM(&c, BytesPerWord, &returnAddress, BytesPerWord, &returnAddressDst);
|
|
|
|
|
|
|
|
Register stack(StackRegister);
|
|
|
|
Memory stackDst(StackRegister, -footprint * BytesPerWord);
|
|
|
|
moveAndUpdateRM(&c, BytesPerWord, &stack, BytesPerWord, &stackDst);
|
|
|
|
}
|
|
|
|
|
2009-10-29 16:12:30 +00:00
|
|
|
virtual void adjustFrame(unsigned footprint) {
|
2010-11-08 00:41:44 +00:00
|
|
|
Register nextStack(5);
|
2009-10-29 16:12:30 +00:00
|
|
|
Memory stackSrc(StackRegister, 0);
|
|
|
|
moveMR(&c, BytesPerWord, &stackSrc, BytesPerWord, &nextStack);
|
|
|
|
|
|
|
|
Memory stackDst(StackRegister, -footprint * BytesPerWord);
|
|
|
|
moveAndUpdateRM(&c, BytesPerWord, &nextStack, BytesPerWord, &stackDst);
|
|
|
|
}
|
|
|
|
|
2009-08-06 17:52:36 +00:00
|
|
|
virtual void popFrame() {
|
|
|
|
Register stack(StackRegister);
|
2010-08-28 00:52:33 +00:00
|
|
|
Memory stackSrc(StackRegister, arch_->framePointerOffset() * BytesPerWord);
|
2009-08-06 17:52:36 +00:00
|
|
|
moveMR(&c, BytesPerWord, &stackSrc, BytesPerWord, &stack);
|
|
|
|
|
2010-08-28 00:52:33 +00:00
|
|
|
Register returnAddress(LinkRegister);
|
|
|
|
Memory returnAddressSrc(StackRegister, arch_->returnAddressOffset() * BytesPerWord);
|
2009-08-06 17:52:36 +00:00
|
|
|
moveMR(&c, BytesPerWord, &returnAddressSrc, BytesPerWord, &returnAddress);
|
2009-10-29 16:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void popFrameForTailCall(unsigned footprint,
|
|
|
|
int offset,
|
|
|
|
int returnAddressSurrogate,
|
|
|
|
int framePointerSurrogate)
|
|
|
|
{
|
|
|
|
if (TailCalls) {
|
|
|
|
if (offset) {
|
2010-11-08 00:41:44 +00:00
|
|
|
Register link(LinkRegister);
|
|
|
|
Memory returnAddressSrc
|
|
|
|
(StackRegister, BytesPerWord + (footprint * BytesPerWord));
|
|
|
|
moveMR(&c, BytesPerWord, &returnAddressSrc, BytesPerWord, &link);
|
2009-10-29 16:12:30 +00:00
|
|
|
|
2010-11-08 00:41:44 +00:00
|
|
|
Register tmp(c.client->acquireTemporary());
|
2009-10-29 16:12:30 +00:00
|
|
|
Memory stackSrc(StackRegister, footprint * BytesPerWord);
|
|
|
|
moveMR(&c, BytesPerWord, &stackSrc, BytesPerWord, &tmp);
|
|
|
|
|
|
|
|
Memory stackDst(StackRegister, (footprint - offset) * BytesPerWord);
|
|
|
|
moveAndUpdateRM(&c, BytesPerWord, &tmp, BytesPerWord, &stackDst);
|
|
|
|
|
2010-11-08 00:41:44 +00:00
|
|
|
c.client->releaseTemporary(tmp.low);
|
|
|
|
|
2009-10-29 16:12:30 +00:00
|
|
|
if (returnAddressSurrogate != NoRegister) {
|
|
|
|
assert(&c, offset > 0);
|
|
|
|
|
|
|
|
Register ras(returnAddressSurrogate);
|
2010-11-08 00:41:44 +00:00
|
|
|
Memory dst(StackRegister, BytesPerWord + (offset * BytesPerWord));
|
2009-10-29 16:12:30 +00:00
|
|
|
moveRM(&c, BytesPerWord, &ras, BytesPerWord, &dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (framePointerSurrogate != NoRegister) {
|
|
|
|
assert(&c, offset > 0);
|
|
|
|
|
|
|
|
Register fps(framePointerSurrogate);
|
|
|
|
Memory dst(StackRegister, offset * BytesPerWord);
|
|
|
|
moveRM(&c, BytesPerWord, &fps, BytesPerWord, &dst);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
popFrame();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
abort(&c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void popFrameAndPopArgumentsAndReturn(unsigned argumentFootprint) {
|
|
|
|
popFrame();
|
|
|
|
|
|
|
|
assert(&c, argumentFootprint >= StackAlignmentInWords);
|
|
|
|
assert(&c, (argumentFootprint % StackAlignmentInWords) == 0);
|
|
|
|
|
|
|
|
if (TailCalls and argumentFootprint > StackAlignmentInWords) {
|
2010-11-08 00:41:44 +00:00
|
|
|
Register tmp(5);
|
2009-10-29 16:12:30 +00:00
|
|
|
Memory stackSrc(StackRegister, 0);
|
|
|
|
moveMR(&c, BytesPerWord, &stackSrc, BytesPerWord, &tmp);
|
|
|
|
|
|
|
|
Memory stackDst(StackRegister,
|
|
|
|
(argumentFootprint - StackAlignmentInWords)
|
|
|
|
* BytesPerWord);
|
|
|
|
moveAndUpdateRM(&c, BytesPerWord, &tmp, BytesPerWord, &stackDst);
|
|
|
|
}
|
|
|
|
|
|
|
|
return_(&c);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void popFrameAndUpdateStackAndReturn(unsigned stackOffsetFromThread)
|
|
|
|
{
|
|
|
|
popFrame();
|
|
|
|
|
2010-08-30 15:16:02 +00:00
|
|
|
Register tmp1(6);
|
2009-10-29 16:12:30 +00:00
|
|
|
Memory stackSrc(StackRegister, 0);
|
|
|
|
moveMR(&c, BytesPerWord, &stackSrc, BytesPerWord, &tmp1);
|
|
|
|
|
|
|
|
Register tmp2(5);
|
|
|
|
Memory newStackSrc(ThreadRegister, stackOffsetFromThread);
|
|
|
|
moveMR(&c, BytesPerWord, &newStackSrc, BytesPerWord, &tmp2);
|
|
|
|
|
|
|
|
Register stack(StackRegister);
|
|
|
|
subR(&c, BytesPerWord, &stack, &tmp2, &tmp2);
|
|
|
|
|
|
|
|
Memory stackDst(StackRegister, 0, tmp2.low);
|
|
|
|
moveAndUpdateRM(&c, BytesPerWord, &tmp1, BytesPerWord, &stackDst);
|
|
|
|
|
|
|
|
return_(&c);
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void apply(Operation op) {
|
|
|
|
arch_->c.operations[op](&c);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void apply(UnaryOperation op,
|
|
|
|
unsigned aSize, OperandType aType, Operand* aOperand)
|
|
|
|
{
|
2010-07-12 20:18:36 +00:00
|
|
|
arch_->c.unaryOperations[index(&(arch_->c), op, aType)]
|
|
|
|
(&c, aSize, aOperand);
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void apply(BinaryOperation op,
|
|
|
|
unsigned aSize, OperandType aType, Operand* aOperand,
|
|
|
|
unsigned bSize, OperandType bType, Operand* bOperand)
|
|
|
|
{
|
2010-07-12 20:18:36 +00:00
|
|
|
arch_->c.binaryOperations[index(&(arch_->c), op, aType, bType)]
|
2009-08-06 17:52:36 +00:00
|
|
|
(&c, aSize, aOperand, bSize, bOperand);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void apply(TernaryOperation op,
|
2010-07-12 20:18:36 +00:00
|
|
|
unsigned aSize, OperandType aType, Operand* aOperand,
|
2009-08-06 17:52:36 +00:00
|
|
|
unsigned bSize, OperandType bType UNUSED,
|
|
|
|
Operand* bOperand,
|
|
|
|
unsigned cSize UNUSED, OperandType cType UNUSED,
|
|
|
|
Operand* cOperand)
|
|
|
|
{
|
2010-07-12 20:18:36 +00:00
|
|
|
if (isBranch(op)) {
|
|
|
|
assert(&c, aSize == bSize);
|
|
|
|
assert(&c, cSize == BytesPerWord);
|
|
|
|
assert(&c, cType == ConstantOperand);
|
2009-08-06 17:52:36 +00:00
|
|
|
|
2010-07-12 20:18:36 +00:00
|
|
|
arch_->c.branchOperations[branchIndex(&(arch_->c), aType, bType)]
|
|
|
|
(&c, op, aSize, aOperand, bOperand, cOperand);
|
|
|
|
} else {
|
|
|
|
assert(&c, bSize == cSize);
|
|
|
|
assert(&c, bType == RegisterOperand);
|
|
|
|
assert(&c, cType == RegisterOperand);
|
|
|
|
|
|
|
|
arch_->c.ternaryOperations[index(&(arch_->c), op, aType)]
|
|
|
|
(&c, bSize, aOperand, bOperand, cOperand);
|
|
|
|
}
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void writeTo(uint8_t* dst) {
|
|
|
|
c.result = dst;
|
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
unsigned dstOffset = 0;
|
2009-08-06 17:52:36 +00:00
|
|
|
for (MyBlock* b = c.firstBlock; b; b = b->next) {
|
2010-11-14 02:28:05 +00:00
|
|
|
if (DebugPool) {
|
|
|
|
fprintf(stderr, "write block %p\n", b);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned blockOffset = 0;
|
|
|
|
for (PoolEvent* e = b->poolEventHead; e; e = e->next) {
|
|
|
|
unsigned size = e->offset - blockOffset;
|
|
|
|
memcpy(dst + dstOffset, c.code.data + b->offset + blockOffset, size);
|
|
|
|
blockOffset = e->offset;
|
|
|
|
dstOffset += size;
|
|
|
|
|
|
|
|
unsigned poolSize = 0;
|
|
|
|
for (PoolOffset* o = e->poolOffsetHead; o; o = o->next) {
|
|
|
|
if (DebugPool) {
|
|
|
|
fprintf(stderr, "visit pool offset %p %d in block %p\n",
|
|
|
|
o, o->offset, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
poolSize += BytesPerWord;
|
|
|
|
|
|
|
|
unsigned entry = dstOffset + poolSize;
|
|
|
|
|
|
|
|
o->entry->address = dst + entry;
|
|
|
|
|
|
|
|
unsigned instruction = o->block->start
|
|
|
|
+ padding(o->block, o->offset) + o->offset;
|
|
|
|
|
|
|
|
int32_t v = (entry - 8) - instruction;
|
|
|
|
expect(&c, v == (v & PoolOffsetMask));
|
|
|
|
|
|
|
|
int32_t* p = reinterpret_cast<int32_t*>(dst + instruction);
|
|
|
|
*p = (v & PoolOffsetMask) | ((~PoolOffsetMask) & *p);
|
|
|
|
}
|
|
|
|
|
|
|
|
write4(dst + dstOffset, ::b((poolSize + BytesPerWord - 8) >> 2));
|
|
|
|
|
|
|
|
dstOffset += poolSize + BytesPerWord;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned size = b->size - blockOffset;
|
|
|
|
|
|
|
|
memcpy(dst + dstOffset,
|
|
|
|
c.code.data + b->offset + blockOffset,
|
|
|
|
size);
|
|
|
|
|
|
|
|
dstOffset += size;
|
2010-07-12 20:18:36 +00:00
|
|
|
}
|
2010-11-14 02:28:05 +00:00
|
|
|
|
2009-08-06 17:52:36 +00:00
|
|
|
for (Task* t = c.tasks; t; t = t->next) {
|
|
|
|
t->run(&c);
|
|
|
|
}
|
2010-07-12 20:18:36 +00:00
|
|
|
|
|
|
|
for (ConstantPoolEntry* e = c.constantPool; e; e = e->next) {
|
2010-11-14 02:28:05 +00:00
|
|
|
if (e->constant->resolved()) {
|
|
|
|
*static_cast<uintptr_t*>(e->address) = e->constant->value();
|
|
|
|
} else {
|
|
|
|
new (e->constant->listen(sizeof(ConstantPoolListener)))
|
2010-11-16 02:38:36 +00:00
|
|
|
ConstantPoolListener(c.s, static_cast<uintptr_t*>(e->address),
|
|
|
|
e->callOffset
|
|
|
|
? dst + e->callOffset->value() + 8
|
|
|
|
: 0);
|
2010-11-14 02:28:05 +00:00
|
|
|
}
|
2010-07-12 20:18:36 +00:00
|
|
|
// fprintf(stderr, "constant %p at %p\n", reinterpret_cast<void*>(e->constant->value()), e->address);
|
|
|
|
}
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
2010-12-07 22:57:11 +00:00
|
|
|
virtual Promise* offset(bool forTrace) {
|
|
|
|
return ::offset(&c, forTrace);
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual Block* endBlock(bool startNew) {
|
|
|
|
MyBlock* b = c.lastBlock;
|
|
|
|
b->size = c.code.length() - b->offset;
|
|
|
|
if (startNew) {
|
|
|
|
c.lastBlock = new (c.zone->allocate(sizeof(MyBlock)))
|
2010-11-14 02:28:05 +00:00
|
|
|
MyBlock(&c, c.code.length());
|
2009-08-06 17:52:36 +00:00
|
|
|
} else {
|
|
|
|
c.lastBlock = 0;
|
|
|
|
}
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
virtual void endEvent() {
|
|
|
|
MyBlock* b = c.lastBlock;
|
|
|
|
unsigned thisEventOffset = c.code.length() - b->offset;
|
|
|
|
if (b->poolOffsetHead) {
|
|
|
|
int32_t v = (thisEventOffset + BytesPerWord - 8)
|
|
|
|
- b->poolOffsetHead->offset;
|
|
|
|
|
|
|
|
if (v > 0 and v != (v & PoolOffsetMask)) {
|
|
|
|
appendPoolEvent
|
|
|
|
(&c, b, b->lastEventOffset, b->poolOffsetHead,
|
|
|
|
b->lastPoolOffsetTail);
|
|
|
|
|
|
|
|
if (DebugPool) {
|
|
|
|
for (PoolOffset* o = b->poolOffsetHead;
|
|
|
|
o != b->lastPoolOffsetTail->next; o = o->next)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"in endEvent, include %p %d in pool event %p at offset %d "
|
|
|
|
"in block %p\n",
|
|
|
|
o, o->offset, b->poolEventTail, b->lastEventOffset, b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
b->poolOffsetHead = b->lastPoolOffsetTail->next;
|
|
|
|
b->lastPoolOffsetTail->next = 0;
|
|
|
|
if (b->poolOffsetHead == 0) {
|
|
|
|
b->poolOffsetTail = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
b->lastEventOffset = thisEventOffset;
|
|
|
|
b->lastPoolOffsetTail = b->poolOffsetTail;
|
2009-08-06 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
virtual unsigned length() {
|
|
|
|
return c.code.length();
|
2010-07-12 20:18:36 +00:00
|
|
|
}
|
|
|
|
|
2009-08-06 17:52:36 +00:00
|
|
|
virtual void dispose() {
|
|
|
|
c.code.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
Context c;
|
|
|
|
MyArchitecture* arch_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace vm {
|
|
|
|
|
|
|
|
Assembler::Architecture*
|
2010-07-12 20:18:36 +00:00
|
|
|
makeArchitecture(System* system, bool)
|
2009-08-06 17:52:36 +00:00
|
|
|
{
|
|
|
|
return new (allocate(system, sizeof(MyArchitecture))) MyArchitecture(system);
|
|
|
|
}
|
|
|
|
|
|
|
|
Assembler*
|
|
|
|
makeAssembler(System* system, Allocator* allocator, Zone* zone,
|
|
|
|
Assembler::Architecture* architecture)
|
|
|
|
{
|
|
|
|
return new (zone->allocate(sizeof(MyAssembler)))
|
|
|
|
MyAssembler(system, allocator, zone,
|
|
|
|
static_cast<MyArchitecture*>(architecture));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace vm
|