version 1.1.1.2, 2012/02/21 23:50:25
|
version 1.1.1.3, 2013/07/22 08:25:57
|
Line 26
|
Line 26
|
|
|
/* ppc 64-bit arch dependent functions. */ |
/* ppc 64-bit arch dependent functions. */ |
|
|
#ifdef __GNUC__ | #if defined(__GNUC__) || (defined(__IBM_GCC_ASM) && __IBM_GCC_ASM) |
#define ASM_SLJIT_CLZ(src, dst) \ |
#define ASM_SLJIT_CLZ(src, dst) \ |
asm volatile ( "cntlzd %0, %1" : "=r"(dst) : "r"(src) ) | __asm__ volatile ( "cntlzd %0, %1" : "=r"(dst) : "r"(src) ) |
| #elif defined(__xlc__) |
| #error "Please enable GCC syntax for inline assembly statements" |
#else |
#else |
#error "Must implement count leading zeroes" |
#error "Must implement count leading zeroes" |
#endif |
#endif |
Line 39
|
Line 41
|
#define PUSH_RLDICR(reg, shift) \ |
#define PUSH_RLDICR(reg, shift) \ |
push_inst(compiler, RLDI(reg, reg, 63 - shift, shift, 1)) |
push_inst(compiler, RLDI(reg, reg, 63 - shift, shift, 1)) |
|
|
static int load_immediate(struct sljit_compiler *compiler, int reg, sljit_w imm) | static sljit_si load_immediate(struct sljit_compiler *compiler, sljit_si reg, sljit_sw imm) |
{ |
{ |
sljit_uw tmp; |
sljit_uw tmp; |
sljit_uw shift; |
sljit_uw shift; |
Line 143 static int load_immediate(struct sljit_compiler *compi
|
Line 145 static int load_immediate(struct sljit_compiler *compi
|
src1 = TMP_REG1; \ |
src1 = TMP_REG1; \ |
} |
} |
|
|
static SLJIT_INLINE int emit_single_op(struct sljit_compiler *compiler, int op, int flags, | static SLJIT_INLINE sljit_si emit_single_op(struct sljit_compiler *compiler, sljit_si op, sljit_si flags, |
int dst, int src1, int src2) | sljit_si dst, sljit_si src1, sljit_si src2) |
{ |
{ |
switch (op) { |
switch (op) { |
|
case SLJIT_MOV: |
|
case SLJIT_MOV_P: |
|
SLJIT_ASSERT(src1 == TMP_REG1); |
|
if (dst != src2) |
|
return push_inst(compiler, OR | S(src2) | A(dst) | B(src2)); |
|
return SLJIT_SUCCESS; |
|
|
|
case SLJIT_MOV_UI: |
|
case SLJIT_MOV_SI: |
|
SLJIT_ASSERT(src1 == TMP_REG1); |
|
if ((flags & (REG_DEST | REG2_SOURCE)) == (REG_DEST | REG2_SOURCE)) { |
|
if (op == SLJIT_MOV_SI) |
|
return push_inst(compiler, EXTSW | S(src2) | A(dst)); |
|
return push_inst(compiler, INS_CLEAR_LEFT(dst, src2, 0)); |
|
} |
|
else { |
|
SLJIT_ASSERT(dst == src2); |
|
} |
|
return SLJIT_SUCCESS; |
|
|
|
case SLJIT_MOV_UB: |
|
case SLJIT_MOV_SB: |
|
SLJIT_ASSERT(src1 == TMP_REG1); |
|
if ((flags & (REG_DEST | REG2_SOURCE)) == (REG_DEST | REG2_SOURCE)) { |
|
if (op == SLJIT_MOV_SB) |
|
return push_inst(compiler, EXTSB | S(src2) | A(dst)); |
|
return push_inst(compiler, INS_CLEAR_LEFT(dst, src2, 24)); |
|
} |
|
else if ((flags & REG_DEST) && op == SLJIT_MOV_SB) |
|
return push_inst(compiler, EXTSB | S(src2) | A(dst)); |
|
else { |
|
SLJIT_ASSERT(dst == src2); |
|
} |
|
return SLJIT_SUCCESS; |
|
|
|
case SLJIT_MOV_UH: |
|
case SLJIT_MOV_SH: |
|
SLJIT_ASSERT(src1 == TMP_REG1); |
|
if ((flags & (REG_DEST | REG2_SOURCE)) == (REG_DEST | REG2_SOURCE)) { |
|
if (op == SLJIT_MOV_SH) |
|
return push_inst(compiler, EXTSH | S(src2) | A(dst)); |
|
return push_inst(compiler, INS_CLEAR_LEFT(dst, src2, 16)); |
|
} |
|
else { |
|
SLJIT_ASSERT(dst == src2); |
|
} |
|
return SLJIT_SUCCESS; |
|
|
|
case SLJIT_NOT: |
|
SLJIT_ASSERT(src1 == TMP_REG1); |
|
UN_EXTS(); |
|
return push_inst(compiler, NOR | RC(flags) | S(src2) | A(dst) | B(src2)); |
|
|
|
case SLJIT_NEG: |
|
SLJIT_ASSERT(src1 == TMP_REG1); |
|
UN_EXTS(); |
|
return push_inst(compiler, NEG | OERC(flags) | D(dst) | A(src2)); |
|
|
|
case SLJIT_CLZ: |
|
SLJIT_ASSERT(src1 == TMP_REG1); |
|
if (flags & ALT_FORM1) |
|
return push_inst(compiler, CNTLZW | RC(flags) | S(src2) | A(dst)); |
|
return push_inst(compiler, CNTLZD | RC(flags) | S(src2) | A(dst)); |
|
|
case SLJIT_ADD: |
case SLJIT_ADD: |
if (flags & ALT_FORM1) { |
if (flags & ALT_FORM1) { |
/* Flags does not set: BIN_IMM_EXTS unnecessary. */ |
/* Flags does not set: BIN_IMM_EXTS unnecessary. */ |
Line 175 static SLJIT_INLINE int emit_single_op(struct sljit_co
|
Line 241 static SLJIT_INLINE int emit_single_op(struct sljit_co
|
|
|
case SLJIT_ADDC: |
case SLJIT_ADDC: |
if (flags & ALT_FORM1) { |
if (flags & ALT_FORM1) { |
FAIL_IF(push_inst(compiler, MFXER | S(0))); | FAIL_IF(push_inst(compiler, MFXER | D(0))); |
FAIL_IF(push_inst(compiler, ADDE | D(dst) | A(src1) | B(src2))); |
FAIL_IF(push_inst(compiler, ADDE | D(dst) | A(src1) | B(src2))); |
return push_inst(compiler, MTXER | S(0)); |
return push_inst(compiler, MTXER | S(0)); |
} |
} |
Line 212 static SLJIT_INLINE int emit_single_op(struct sljit_co
|
Line 278 static SLJIT_INLINE int emit_single_op(struct sljit_co
|
|
|
case SLJIT_SUBC: |
case SLJIT_SUBC: |
if (flags & ALT_FORM1) { |
if (flags & ALT_FORM1) { |
FAIL_IF(push_inst(compiler, MFXER | S(0))); | FAIL_IF(push_inst(compiler, MFXER | D(0))); |
FAIL_IF(push_inst(compiler, SUBFE | D(dst) | A(src2) | B(src1))); |
FAIL_IF(push_inst(compiler, SUBFE | D(dst) | A(src2) | B(src1))); |
return push_inst(compiler, MTXER | S(0)); |
return push_inst(compiler, MTXER | S(0)); |
} |
} |
Line 284 static SLJIT_INLINE int emit_single_op(struct sljit_co
|
Line 350 static SLJIT_INLINE int emit_single_op(struct sljit_co
|
return push_inst(compiler, RLDI(dst, src1, compiler->imm, 63 - compiler->imm, 1) | RC(flags)); |
return push_inst(compiler, RLDI(dst, src1, compiler->imm, 63 - compiler->imm, 1) | RC(flags)); |
} |
} |
} |
} |
if (flags & ALT_FORM2) | return push_inst(compiler, ((flags & ALT_FORM2) ? SLW : SLD) | RC(flags) | S(src1) | A(dst) | B(src2)); |
return push_inst(compiler, SLW | RC(flags) | S(src1) | A(dst) | B(src2)); | |
return push_inst(compiler, SLD | RC(flags) | S(src1) | A(dst) | B(src2)); | |
|
|
case SLJIT_LSHR: |
case SLJIT_LSHR: |
if (flags & ALT_FORM1) { |
if (flags & ALT_FORM1) { |
Line 300 static SLJIT_INLINE int emit_single_op(struct sljit_co
|
Line 364 static SLJIT_INLINE int emit_single_op(struct sljit_co
|
return push_inst(compiler, RLDI(dst, src1, 64 - compiler->imm, compiler->imm, 0) | RC(flags)); |
return push_inst(compiler, RLDI(dst, src1, 64 - compiler->imm, compiler->imm, 0) | RC(flags)); |
} |
} |
} |
} |
if (flags & ALT_FORM2) | return push_inst(compiler, ((flags & ALT_FORM2) ? SRW : SRD) | RC(flags) | S(src1) | A(dst) | B(src2)); |
return push_inst(compiler, SRW | RC(flags) | S(src1) | A(dst) | B(src2)); | |
return push_inst(compiler, SRD | RC(flags) | S(src1) | A(dst) | B(src2)); | |
|
|
case SLJIT_ASHR: |
case SLJIT_ASHR: |
|
if (flags & ALT_FORM3) |
|
FAIL_IF(push_inst(compiler, MFXER | D(0))); |
if (flags & ALT_FORM1) { |
if (flags & ALT_FORM1) { |
SLJIT_ASSERT(src2 == TMP_REG2); |
SLJIT_ASSERT(src2 == TMP_REG2); |
if (flags & ALT_FORM2) { |
if (flags & ALT_FORM2) { |
compiler->imm &= 0x1f; |
compiler->imm &= 0x1f; |
return push_inst(compiler, SRAWI | RC(flags) | S(src1) | A(dst) | (compiler->imm << 11)); | FAIL_IF(push_inst(compiler, SRAWI | RC(flags) | S(src1) | A(dst) | (compiler->imm << 11))); |
} |
} |
else { |
else { |
compiler->imm &= 0x3f; |
compiler->imm &= 0x3f; |
return push_inst(compiler, SRADI | RC(flags) | S(src1) | A(dst) | ((compiler->imm & 0x1f) << 11) | ((compiler->imm & 0x20) >> 4)); | FAIL_IF(push_inst(compiler, SRADI | RC(flags) | S(src1) | A(dst) | ((compiler->imm & 0x1f) << 11) | ((compiler->imm & 0x20) >> 4))); |
} |
} |
} |
} |
if (flags & ALT_FORM2) | else |
return push_inst(compiler, SRAW | RC(flags) | S(src1) | A(dst) | B(src2)); | FAIL_IF(push_inst(compiler, ((flags & ALT_FORM2) ? SRAW : SRAD) | RC(flags) | S(src1) | A(dst) | B(src2))); |
return push_inst(compiler, SRAD | RC(flags) | S(src1) | A(dst) | B(src2)); | return (flags & ALT_FORM3) ? push_inst(compiler, MTXER | S(0)) : SLJIT_SUCCESS; |
| |
case SLJIT_MOV: | |
SLJIT_ASSERT(src1 == TMP_REG1); | |
if (dst != src2) | |
return push_inst(compiler, OR | S(src2) | A(dst) | B(src2)); | |
return SLJIT_SUCCESS; | |
| |
case SLJIT_MOV_UI: | |
case SLJIT_MOV_SI: | |
SLJIT_ASSERT(src1 == TMP_REG1); | |
if ((flags & (REG_DEST | REG2_SOURCE)) == (REG_DEST | REG2_SOURCE)) { | |
if (op == SLJIT_MOV_SI) | |
return push_inst(compiler, EXTSW | S(src2) | A(dst)); | |
return push_inst(compiler, INS_CLEAR_LEFT(dst, src2, 0)); | |
} | |
else if (dst != src2) | |
SLJIT_ASSERT_STOP(); | |
return SLJIT_SUCCESS; | |
| |
case SLJIT_MOV_UB: | |
case SLJIT_MOV_SB: | |
SLJIT_ASSERT(src1 == TMP_REG1); | |
if ((flags & (REG_DEST | REG2_SOURCE)) == (REG_DEST | REG2_SOURCE)) { | |
if (op == SLJIT_MOV_SB) | |
return push_inst(compiler, EXTSB | S(src2) | A(dst)); | |
return push_inst(compiler, INS_CLEAR_LEFT(dst, src2, 24)); | |
} | |
else if ((flags & REG_DEST) && op == SLJIT_MOV_SB) | |
return push_inst(compiler, EXTSB | S(src2) | A(dst)); | |
else if (dst != src2) | |
SLJIT_ASSERT_STOP(); | |
return SLJIT_SUCCESS; | |
| |
case SLJIT_MOV_UH: | |
case SLJIT_MOV_SH: | |
SLJIT_ASSERT(src1 == TMP_REG1); | |
if ((flags & (REG_DEST | REG2_SOURCE)) == (REG_DEST | REG2_SOURCE)) { | |
if (op == SLJIT_MOV_SH) | |
return push_inst(compiler, EXTSH | S(src2) | A(dst)); | |
return push_inst(compiler, INS_CLEAR_LEFT(dst, src2, 16)); | |
} | |
else if (dst != src2) | |
SLJIT_ASSERT_STOP(); | |
return SLJIT_SUCCESS; | |
| |
case SLJIT_NOT: | |
SLJIT_ASSERT(src1 == TMP_REG1); | |
UN_EXTS(); | |
return push_inst(compiler, NOR | RC(flags) | S(src2) | A(dst) | B(src2)); | |
| |
case SLJIT_NEG: | |
SLJIT_ASSERT(src1 == TMP_REG1); | |
UN_EXTS(); | |
return push_inst(compiler, NEG | OERC(flags) | D(dst) | A(src2)); | |
| |
case SLJIT_CLZ: | |
SLJIT_ASSERT(src1 == TMP_REG1); | |
if (flags & ALT_FORM1) | |
return push_inst(compiler, CNTLZW | RC(flags) | S(src2) | A(dst)); | |
return push_inst(compiler, CNTLZD | RC(flags) | S(src2) | A(dst)); | |
} |
} |
|
|
SLJIT_ASSERT_STOP(); |
SLJIT_ASSERT_STOP(); |
return SLJIT_SUCCESS; |
return SLJIT_SUCCESS; |
} |
} |
|
|
static SLJIT_INLINE int emit_const(struct sljit_compiler *compiler, int reg, sljit_w init_value) | static SLJIT_INLINE sljit_si emit_const(struct sljit_compiler *compiler, sljit_si reg, sljit_sw init_value) |
{ |
{ |
FAIL_IF(push_inst(compiler, ADDIS | D(reg) | A(0) | IMM(init_value >> 48))); |
FAIL_IF(push_inst(compiler, ADDIS | D(reg) | A(0) | IMM(init_value >> 48))); |
FAIL_IF(push_inst(compiler, ORI | S(reg) | A(reg) | IMM(init_value >> 32))); |
FAIL_IF(push_inst(compiler, ORI | S(reg) | A(reg) | IMM(init_value >> 32))); |
Line 405 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(slji
|
Line 409 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(slji
|
SLJIT_CACHE_FLUSH(inst, inst + 5); |
SLJIT_CACHE_FLUSH(inst, inst + 5); |
} |
} |
|
|
SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_w new_constant) | SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant) |
{ |
{ |
sljit_ins *inst = (sljit_ins*)addr; |
sljit_ins *inst = (sljit_ins*)addr; |
|
|
Line 414 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw
|
Line 418 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw
|
inst[3] = (inst[3] & 0xffff0000) | ((new_constant >> 16) & 0xffff); |
inst[3] = (inst[3] & 0xffff0000) | ((new_constant >> 16) & 0xffff); |
inst[4] = (inst[4] & 0xffff0000) | (new_constant & 0xffff); |
inst[4] = (inst[4] & 0xffff0000) | (new_constant & 0xffff); |
SLJIT_CACHE_FLUSH(inst, inst + 5); |
SLJIT_CACHE_FLUSH(inst, inst + 5); |
} |
|
|
|
SLJIT_API_FUNC_ATTRIBUTE void sljit_set_function_context(void** func_ptr, struct sljit_function_context* context, sljit_w addr, void* func) |
|
{ |
|
sljit_w* ptrs; |
|
if (func_ptr) |
|
*func_ptr = (void*)context; |
|
ptrs = (sljit_w*)func; |
|
context->addr = addr ? addr : ptrs[0]; |
|
context->r2 = ptrs[1]; |
|
context->r11 = ptrs[2]; |
|
} |
} |