Annotation of win32/pcre/sljit/sljitNativeMIPS_common.c, revision 1.1
1.1 ! misha 1: /*
! 2: * Stack-less Just-In-Time compiler
! 3: *
! 4: * Copyright 2009-2012 Zoltan Herczeg (hzmester@freemail.hu). All rights reserved.
! 5: *
! 6: * Redistribution and use in source and binary forms, with or without modification, are
! 7: * permitted provided that the following conditions are met:
! 8: *
! 9: * 1. Redistributions of source code must retain the above copyright notice, this list of
! 10: * conditions and the following disclaimer.
! 11: *
! 12: * 2. Redistributions in binary form must reproduce the above copyright notice, this list
! 13: * of conditions and the following disclaimer in the documentation and/or other materials
! 14: * provided with the distribution.
! 15: *
! 16: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
! 17: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
! 18: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
! 19: * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
! 20: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
! 21: * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
! 22: * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
! 23: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
! 24: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
! 25: */
! 26:
! 27: SLJIT_API_FUNC_ATTRIBUTE SLJIT_CONST char* sljit_get_platform_name()
! 28: {
! 29: return "MIPS" SLJIT_CPUINFO;
! 30: }
! 31:
! 32: /* Latest MIPS architecture. */
! 33: /* Detect SLJIT_MIPS_32_64 */
! 34:
! 35: /* Length of an instruction word
! 36: Both for mips-32 and mips-64 */
! 37: typedef sljit_ui sljit_ins;
! 38:
! 39: #define TMP_REG1 (SLJIT_NO_REGISTERS + 1)
! 40: #define TMP_REG2 (SLJIT_NO_REGISTERS + 2)
! 41: #define TMP_REG3 (SLJIT_NO_REGISTERS + 3)
! 42: #define REAL_STACK_PTR (SLJIT_NO_REGISTERS + 4)
! 43:
! 44: /* For position independent code, t9 must contain the function address. */
! 45: #define PIC_ADDR_REG TMP_REG2
! 46:
! 47: /* TMP_EREG1 is used mainly for literal encoding on 64 bit. */
! 48: #define TMP_EREG1 15
! 49: #define TMP_EREG2 24
! 50: /* Floating point status register. */
! 51: #define FCSR_REG 31
! 52: /* Return address register. */
! 53: #define RETURN_ADDR_REG 31
! 54:
! 55: /* Flags are keept in volatile registers. */
! 56: #define EQUAL_FLAG 7
! 57: /* And carry flag as well. */
! 58: #define ULESS_FLAG 10
! 59: #define UGREATER_FLAG 11
! 60: #define LESS_FLAG 12
! 61: #define GREATER_FLAG 13
! 62: #define OVERFLOW_FLAG 14
! 63:
! 64: #define TMP_FREG1 (SLJIT_FLOAT_REG4 + 1)
! 65: #define TMP_FREG2 (SLJIT_FLOAT_REG4 + 2)
! 66:
! 67: /* --------------------------------------------------------------------- */
! 68: /* Instrucion forms */
! 69: /* --------------------------------------------------------------------- */
! 70:
! 71: #define S(s) (reg_map[s] << 21)
! 72: #define T(t) (reg_map[t] << 16)
! 73: #define D(d) (reg_map[d] << 11)
! 74: /* Absolute registers. */
! 75: #define SA(s) ((s) << 21)
! 76: #define TA(t) ((t) << 16)
! 77: #define DA(d) ((d) << 11)
! 78: #define FT(t) ((t) << (16 + 1))
! 79: #define FS(s) ((s) << (11 + 1))
! 80: #define FD(d) ((d) << (6 + 1))
! 81: #define IMM(imm) ((imm) & 0xffff)
! 82: #define SH_IMM(imm) ((imm & 0x1f) << 6)
! 83:
! 84: #define DR(dr) (reg_map[dr])
! 85: #define HI(opcode) ((opcode) << 26)
! 86: #define LO(opcode) (opcode)
! 87: #define FMT_D (17 << 21)
! 88:
! 89: #define ABS_D (HI(17) | FMT_D | LO(5))
! 90: #define ADD_D (HI(17) | FMT_D | LO(0))
! 91: #define ADDU (HI(0) | LO(33))
! 92: #define ADDIU (HI(9))
! 93: #define AND (HI(0) | LO(36))
! 94: #define ANDI (HI(12))
! 95: #define B (HI(4))
! 96: #define BAL (HI(1) | (17 << 16))
! 97: #define BC1F (HI(17) | (8 << 21))
! 98: #define BC1T (HI(17) | (8 << 21) | (1 << 16))
! 99: #define BEQ (HI(4))
! 100: #define BGEZ (HI(1) | (1 << 16))
! 101: #define BGTZ (HI(7))
! 102: #define BLEZ (HI(6))
! 103: #define BLTZ (HI(1) | (0 << 16))
! 104: #define BNE (HI(5))
! 105: #define BREAK (HI(0) | LO(13))
! 106: #define C_UN_D (HI(17) | FMT_D | LO(49))
! 107: #define C_UEQ_D (HI(17) | FMT_D | LO(51))
! 108: #define C_ULE_D (HI(17) | FMT_D | LO(55))
! 109: #define C_ULT_D (HI(17) | FMT_D | LO(53))
! 110: #define DIV (HI(0) | LO(26))
! 111: #define DIVU (HI(0) | LO(27))
! 112: #define DIV_D (HI(17) | FMT_D | LO(3))
! 113: #define J (HI(2))
! 114: #define JAL (HI(3))
! 115: #define JALR (HI(0) | LO(9))
! 116: #define JR (HI(0) | LO(8))
! 117: #define LD (HI(55))
! 118: #define LDC1 (HI(53))
! 119: #define LUI (HI(15))
! 120: #define LW (HI(35))
! 121: #define NEG_D (HI(17) | FMT_D | LO(7))
! 122: #define MFHI (HI(0) | LO(16))
! 123: #define MFLO (HI(0) | LO(18))
! 124: #define MOV_D (HI(17) | FMT_D | LO(6))
! 125: #define CFC1 (HI(17) | (2 << 21))
! 126: #define MOVN (HI(0) | LO(11))
! 127: #define MOVZ (HI(0) | LO(10))
! 128: #define MUL_D (HI(17) | FMT_D | LO(2))
! 129: #define MULT (HI(0) | LO(24))
! 130: #define MULTU (HI(0) | LO(25))
! 131: #define NOP (HI(0) | LO(0))
! 132: #define NOR (HI(0) | LO(39))
! 133: #define OR (HI(0) | LO(37))
! 134: #define ORI (HI(13))
! 135: #define SD (HI(63))
! 136: #define SDC1 (HI(61))
! 137: #define SLT (HI(0) | LO(42))
! 138: #define SLTI (HI(10))
! 139: #define SLTIU (HI(11))
! 140: #define SLTU (HI(0) | LO(43))
! 141: #define SLL (HI(0) | LO(0))
! 142: #define SLLV (HI(0) | LO(4))
! 143: #define SRL (HI(0) | LO(2))
! 144: #define SRLV (HI(0) | LO(6))
! 145: #define SRA (HI(0) | LO(3))
! 146: #define SRAV (HI(0) | LO(7))
! 147: #define SUB_D (HI(17) | FMT_D | LO(1))
! 148: #define SUBU (HI(0) | LO(35))
! 149: #define SW (HI(43))
! 150: #define XOR (HI(0) | LO(38))
! 151: #define XORI (HI(14))
! 152:
! 153: #if (defined SLJIT_MIPS_32_64 && SLJIT_MIPS_32_64)
! 154: #define CLZ (HI(28) | LO(32))
! 155: #define MUL (HI(28) | LO(2))
! 156: #define SEB (HI(31) | (16 << 6) | LO(32))
! 157: #define SEH (HI(31) | (24 << 6) | LO(32))
! 158: #endif
! 159:
! 160: #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
! 161: #define ADDU_W ADDU
! 162: #define ADDIU_W ADDIU
! 163: #define SLL_W SLL
! 164: #define SUBU_W SUBU
! 165: #else
! 166: #define ADDU_W DADDU
! 167: #define ADDIU_W DADDIU
! 168: #define SLL_W DSLL
! 169: #define SUBU_W DSUBU
! 170: #endif
! 171:
! 172: #define SIMM_MAX (0x7fff)
! 173: #define SIMM_MIN (-0x8000)
! 174: #define UIMM_MAX (0xffff)
! 175:
! 176: static SLJIT_CONST sljit_ub reg_map[SLJIT_NO_REGISTERS + 6] = {
! 177: 0, 2, 5, 6, 3, 8, 17, 18, 19, 20, 21, 16, 4, 25, 9, 29
! 178: };
! 179:
! 180: /* dest_reg is the absolute name of the register
! 181: Useful for reordering instructions in the delay slot. */
! 182: static int push_inst(struct sljit_compiler *compiler, sljit_ins ins, int delay_slot)
! 183: {
! 184: sljit_ins *ptr = (sljit_ins*)ensure_buf(compiler, sizeof(sljit_ins));
! 185: FAIL_IF(!ptr);
! 186: *ptr = ins;
! 187: compiler->size++;
! 188: compiler->delay_slot = delay_slot;
! 189: return SLJIT_SUCCESS;
! 190: }
! 191:
! 192: static SLJIT_INLINE sljit_ins invert_branch(int flags)
! 193: {
! 194: return (flags & IS_BIT26_COND) ? (1 << 26) : (1 << 16);
! 195: }
! 196:
! 197: static SLJIT_INLINE sljit_ins* optimize_jump(struct sljit_jump *jump, sljit_ins *code_ptr, sljit_ins *code)
! 198: {
! 199: sljit_w diff;
! 200: sljit_uw target_addr;
! 201: sljit_ins *inst;
! 202: sljit_ins saved_inst;
! 203:
! 204: if (jump->flags & SLJIT_REWRITABLE_JUMP)
! 205: return code_ptr;
! 206:
! 207: if (jump->flags & JUMP_ADDR)
! 208: target_addr = jump->u.target;
! 209: else {
! 210: SLJIT_ASSERT(jump->flags & JUMP_LABEL);
! 211: target_addr = (sljit_uw)(code + jump->u.label->size);
! 212: }
! 213: inst = (sljit_ins*)jump->addr;
! 214: if (jump->flags & IS_COND)
! 215: inst--;
! 216:
! 217: /* B instructions. */
! 218: if (jump->flags & IS_MOVABLE) {
! 219: diff = ((sljit_w)target_addr - (sljit_w)(inst)) >> 2;
! 220: if (diff <= SIMM_MAX && diff >= SIMM_MIN) {
! 221: jump->flags |= PATCH_B;
! 222:
! 223: if (!(jump->flags & IS_COND)) {
! 224: inst[0] = inst[-1];
! 225: inst[-1] = (jump->flags & IS_JAL) ? BAL : B;
! 226: jump->addr -= sizeof(sljit_ins);
! 227: return inst;
! 228: }
! 229: saved_inst = inst[0];
! 230: inst[0] = inst[-1];
! 231: inst[-1] = saved_inst ^ invert_branch(jump->flags);
! 232: jump->addr -= 2 * sizeof(sljit_ins);
! 233: return inst;
! 234: }
! 235: }
! 236:
! 237: diff = ((sljit_w)target_addr - (sljit_w)(inst + 1)) >> 2;
! 238: if (diff <= SIMM_MAX && diff >= SIMM_MIN) {
! 239: jump->flags |= PATCH_B;
! 240:
! 241: if (!(jump->flags & IS_COND)) {
! 242: inst[0] = (jump->flags & IS_JAL) ? BAL : B;
! 243: inst[1] = NOP;
! 244: return inst + 1;
! 245: }
! 246: inst[0] = inst[0] ^ invert_branch(jump->flags);
! 247: inst[1] = NOP;
! 248: jump->addr -= sizeof(sljit_ins);
! 249: return inst + 1;
! 250: }
! 251:
! 252: if (jump->flags & IS_COND) {
! 253: if ((target_addr & ~0xfffffff) == ((jump->addr + 3 * sizeof(sljit_ins)) & ~0xfffffff)) {
! 254: jump->flags |= PATCH_J;
! 255: inst[0] = (inst[0] & 0xffff0000) | 3;
! 256: inst[1] = NOP;
! 257: inst[2] = J;
! 258: inst[3] = NOP;
! 259: jump->addr += sizeof(sljit_ins);
! 260: return inst + 3;
! 261: }
! 262: return code_ptr;
! 263: }
! 264:
! 265: /* J instuctions. */
! 266: if (jump->flags & IS_MOVABLE) {
! 267: if ((target_addr & ~0xfffffff) == (jump->addr & ~0xfffffff)) {
! 268: jump->flags |= PATCH_J;
! 269: inst[0] = inst[-1];
! 270: inst[-1] = (jump->flags & IS_JAL) ? JAL : J;
! 271: jump->addr -= sizeof(sljit_ins);
! 272: return inst;
! 273: }
! 274: }
! 275:
! 276: if ((target_addr & ~0xfffffff) == ((jump->addr + sizeof(sljit_ins)) & ~0xfffffff)) {
! 277: jump->flags |= PATCH_J;
! 278: inst[0] = (jump->flags & IS_JAL) ? JAL : J;
! 279: inst[1] = NOP;
! 280: return inst + 1;
! 281: }
! 282:
! 283: return code_ptr;
! 284: }
! 285:
! 286: #ifdef __GNUC__
! 287: static __attribute__ ((noinline)) void sljit_cache_flush(void* code, void* code_ptr)
! 288: {
! 289: SLJIT_CACHE_FLUSH(code, code_ptr);
! 290: }
! 291: #endif
! 292:
! 293: SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler)
! 294: {
! 295: struct sljit_memory_fragment *buf;
! 296: sljit_ins *code;
! 297: sljit_ins *code_ptr;
! 298: sljit_ins *buf_ptr;
! 299: sljit_ins *buf_end;
! 300: sljit_uw word_count;
! 301: sljit_uw addr;
! 302:
! 303: struct sljit_label *label;
! 304: struct sljit_jump *jump;
! 305: struct sljit_const *const_;
! 306:
! 307: CHECK_ERROR_PTR();
! 308: check_sljit_generate_code(compiler);
! 309: reverse_buf(compiler);
! 310:
! 311: code = (sljit_ins*)SLJIT_MALLOC_EXEC(compiler->size * sizeof(sljit_ins));
! 312: PTR_FAIL_WITH_EXEC_IF(code);
! 313: buf = compiler->buf;
! 314:
! 315: code_ptr = code;
! 316: word_count = 0;
! 317: label = compiler->labels;
! 318: jump = compiler->jumps;
! 319: const_ = compiler->consts;
! 320: do {
! 321: buf_ptr = (sljit_ins*)buf->memory;
! 322: buf_end = buf_ptr + (buf->used_size >> 2);
! 323: do {
! 324: *code_ptr = *buf_ptr++;
! 325: SLJIT_ASSERT(!label || label->size >= word_count);
! 326: SLJIT_ASSERT(!jump || jump->addr >= word_count);
! 327: SLJIT_ASSERT(!const_ || const_->addr >= word_count);
! 328: /* These structures are ordered by their address. */
! 329: if (label && label->size == word_count) {
! 330: /* Just recording the address. */
! 331: label->addr = (sljit_uw)code_ptr;
! 332: label->size = code_ptr - code;
! 333: label = label->next;
! 334: }
! 335: if (jump && jump->addr == word_count) {
! 336: #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
! 337: jump->addr = (sljit_uw)(code_ptr - 3);
! 338: #else
! 339: jump->addr = (sljit_uw)(code_ptr - 6);
! 340: #endif
! 341: code_ptr = optimize_jump(jump, code_ptr, code);
! 342: jump = jump->next;
! 343: }
! 344: if (const_ && const_->addr == word_count) {
! 345: /* Just recording the address. */
! 346: const_->addr = (sljit_uw)code_ptr;
! 347: const_ = const_->next;
! 348: }
! 349: code_ptr ++;
! 350: word_count ++;
! 351: } while (buf_ptr < buf_end);
! 352:
! 353: buf = buf->next;
! 354: } while (buf);
! 355:
! 356: if (label && label->size == word_count) {
! 357: label->addr = (sljit_uw)code_ptr;
! 358: label->size = code_ptr - code;
! 359: label = label->next;
! 360: }
! 361:
! 362: SLJIT_ASSERT(!label);
! 363: SLJIT_ASSERT(!jump);
! 364: SLJIT_ASSERT(!const_);
! 365: SLJIT_ASSERT(code_ptr - code <= (int)compiler->size);
! 366:
! 367: jump = compiler->jumps;
! 368: while (jump) {
! 369: do {
! 370: addr = (jump->flags & JUMP_LABEL) ? jump->u.label->addr : jump->u.target;
! 371: buf_ptr = (sljit_ins*)jump->addr;
! 372:
! 373: if (jump->flags & PATCH_B) {
! 374: addr = (sljit_w)(addr - (jump->addr + sizeof(sljit_ins))) >> 2;
! 375: SLJIT_ASSERT((sljit_w)addr <= SIMM_MAX && (sljit_w)addr >= SIMM_MIN);
! 376: buf_ptr[0] = (buf_ptr[0] & 0xffff0000) | (addr & 0xffff);
! 377: break;
! 378: }
! 379: if (jump->flags & PATCH_J) {
! 380: SLJIT_ASSERT((addr & ~0xfffffff) == ((jump->addr + sizeof(sljit_ins)) & ~0xfffffff));
! 381: buf_ptr[0] |= (addr >> 2) & 0x03ffffff;
! 382: break;
! 383: }
! 384:
! 385: /* Set the fields of immediate loads. */
! 386: #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
! 387: buf_ptr[0] = (buf_ptr[0] & 0xffff0000) | ((addr >> 16) & 0xffff);
! 388: buf_ptr[1] = (buf_ptr[1] & 0xffff0000) | (addr & 0xffff);
! 389: #else
! 390: buf_ptr[0] = (buf_ptr[0] & 0xffff0000) | ((addr >> 48) & 0xffff);
! 391: buf_ptr[1] = (buf_ptr[1] & 0xffff0000) | ((addr >> 32) & 0xffff);
! 392: buf_ptr[3] = (buf_ptr[3] & 0xffff0000) | ((addr >> 16) & 0xffff);
! 393: buf_ptr[4] = (buf_ptr[4] & 0xffff0000) | (addr & 0xffff);
! 394: #endif
! 395: } while (0);
! 396: jump = jump->next;
! 397: }
! 398:
! 399: compiler->error = SLJIT_ERR_COMPILED;
! 400: compiler->executable_size = compiler->size * sizeof(sljit_ins);
! 401: #ifndef __GNUC__
! 402: SLJIT_CACHE_FLUSH(code, code_ptr);
! 403: #else
! 404: /* GCC workaround for invalid code generation with -O2. */
! 405: sljit_cache_flush(code, code_ptr);
! 406: #endif
! 407: return code;
! 408: }
! 409:
! 410: /* Creates an index in data_transfer_insts array. */
! 411: #define WORD_DATA 0x00
! 412: #define BYTE_DATA 0x01
! 413: #define HALF_DATA 0x02
! 414: #define INT_DATA 0x03
! 415: #define SIGNED_DATA 0x04
! 416: #define LOAD_DATA 0x08
! 417:
! 418: #define MEM_MASK 0x0f
! 419:
! 420: #define WRITE_BACK 0x00010
! 421: #define ARG_TEST 0x00020
! 422: #define CUMULATIVE_OP 0x00040
! 423: #define LOGICAL_OP 0x00080
! 424: #define IMM_OP 0x00100
! 425: #define SRC2_IMM 0x00200
! 426:
! 427: #define UNUSED_DEST 0x00400
! 428: #define REG_DEST 0x00800
! 429: #define REG1_SOURCE 0x01000
! 430: #define REG2_SOURCE 0x02000
! 431: #define SLOW_SRC1 0x04000
! 432: #define SLOW_SRC2 0x08000
! 433: #define SLOW_DEST 0x10000
! 434:
! 435: /* Only these flags are set. UNUSED_DEST is not set when no flags should be set. */
! 436: #define CHECK_FLAGS(list) \
! 437: (!(flags & UNUSED_DEST) || (op & GET_FLAGS(~(list))))
! 438:
! 439: #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
! 440: #include "sljitNativeMIPS_32.c"
! 441: #else
! 442: #include "sljitNativeMIPS_64.c"
! 443: #endif
! 444:
! 445: #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
! 446: #define STACK_STORE SW
! 447: #define STACK_LOAD LW
! 448: #else
! 449: #define STACK_STORE SD
! 450: #define STACK_LOAD LD
! 451: #endif
! 452:
! 453: static int emit_op(struct sljit_compiler *compiler, int op, int inp_flags,
! 454: int dst, sljit_w dstw,
! 455: int src1, sljit_w src1w,
! 456: int src2, sljit_w src2w);
! 457:
! 458: SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_enter(struct sljit_compiler *compiler, int args, int temporaries, int saveds, int local_size)
! 459: {
! 460: sljit_ins base;
! 461:
! 462: CHECK_ERROR();
! 463: check_sljit_emit_enter(compiler, args, temporaries, saveds, local_size);
! 464:
! 465: compiler->temporaries = temporaries;
! 466: compiler->saveds = saveds;
! 467:
! 468: compiler->has_locals = local_size > 0;
! 469: local_size += (saveds + 2 + 4) * sizeof(sljit_w);
! 470: local_size = (local_size + 15) & ~0xf;
! 471: compiler->local_size = local_size;
! 472:
! 473: if (local_size <= SIMM_MAX) {
! 474: /* Frequent case. */
! 475: FAIL_IF(push_inst(compiler, ADDIU_W | S(REAL_STACK_PTR) | T(REAL_STACK_PTR) | IMM(-local_size), DR(REAL_STACK_PTR)));
! 476: base = S(REAL_STACK_PTR);
! 477: }
! 478: else {
! 479: FAIL_IF(load_immediate(compiler, DR(TMP_REG1), local_size));
! 480: FAIL_IF(push_inst(compiler, ADDU_W | S(REAL_STACK_PTR) | TA(0) | D(TMP_REG2), DR(TMP_REG2)));
! 481: FAIL_IF(push_inst(compiler, SUBU_W | S(REAL_STACK_PTR) | T(TMP_REG1) | D(REAL_STACK_PTR), DR(REAL_STACK_PTR)));
! 482: base = S(TMP_REG2);
! 483: local_size = 0;
! 484: }
! 485:
! 486: FAIL_IF(push_inst(compiler, STACK_STORE | base | TA(RETURN_ADDR_REG) | IMM(local_size - 1 * (int)sizeof(sljit_w)), MOVABLE_INS));
! 487: if (compiler->has_locals)
! 488: FAIL_IF(push_inst(compiler, STACK_STORE | base | T(SLJIT_LOCALS_REG) | IMM(local_size - 2 * (int)sizeof(sljit_w)), MOVABLE_INS));
! 489: if (saveds >= 1)
! 490: FAIL_IF(push_inst(compiler, STACK_STORE | base | T(SLJIT_SAVED_REG1) | IMM(local_size - 3 * (int)sizeof(sljit_w)), MOVABLE_INS));
! 491: if (saveds >= 2)
! 492: FAIL_IF(push_inst(compiler, STACK_STORE | base | T(SLJIT_SAVED_REG2) | IMM(local_size - 4 * (int)sizeof(sljit_w)), MOVABLE_INS));
! 493: if (saveds >= 3)
! 494: FAIL_IF(push_inst(compiler, STACK_STORE | base | T(SLJIT_SAVED_REG3) | IMM(local_size - 5 * (int)sizeof(sljit_w)), MOVABLE_INS));
! 495: if (saveds >= 4)
! 496: FAIL_IF(push_inst(compiler, STACK_STORE | base | T(SLJIT_SAVED_EREG1) | IMM(local_size - 6 * (int)sizeof(sljit_w)), MOVABLE_INS));
! 497: if (saveds >= 5)
! 498: FAIL_IF(push_inst(compiler, STACK_STORE | base | T(SLJIT_SAVED_EREG2) | IMM(local_size - 7 * (int)sizeof(sljit_w)), MOVABLE_INS));
! 499:
! 500: if (compiler->has_locals)
! 501: FAIL_IF(push_inst(compiler, ADDIU_W | S(REAL_STACK_PTR) | T(SLJIT_LOCALS_REG) | IMM(4 * sizeof(sljit_w)), DR(SLJIT_LOCALS_REG)));
! 502:
! 503: if (args >= 1)
! 504: FAIL_IF(push_inst(compiler, ADDU_W | SA(4) | TA(0) | D(SLJIT_SAVED_REG1), DR(SLJIT_SAVED_REG1)));
! 505: if (args >= 2)
! 506: FAIL_IF(push_inst(compiler, ADDU_W | SA(5) | TA(0) | D(SLJIT_SAVED_REG2), DR(SLJIT_SAVED_REG2)));
! 507: if (args >= 3)
! 508: FAIL_IF(push_inst(compiler, ADDU_W | SA(6) | TA(0) | D(SLJIT_SAVED_REG3), DR(SLJIT_SAVED_REG3)));
! 509:
! 510: return SLJIT_SUCCESS;
! 511: }
! 512:
! 513: SLJIT_API_FUNC_ATTRIBUTE void sljit_set_context(struct sljit_compiler *compiler, int args, int temporaries, int saveds, int local_size)
! 514: {
! 515: CHECK_ERROR_VOID();
! 516: check_sljit_set_context(compiler, args, temporaries, saveds, local_size);
! 517:
! 518: compiler->temporaries = temporaries;
! 519: compiler->saveds = saveds;
! 520:
! 521: compiler->has_locals = local_size > 0;
! 522: local_size += (saveds + 2 + 4) * sizeof(sljit_w);
! 523: compiler->local_size = (local_size + 15) & ~0xf;
! 524: }
! 525:
! 526: SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_return(struct sljit_compiler *compiler, int op, int src, sljit_w srcw)
! 527: {
! 528: int local_size;
! 529: sljit_ins base;
! 530:
! 531: CHECK_ERROR();
! 532: check_sljit_emit_return(compiler, op, src, srcw);
! 533:
! 534: FAIL_IF(emit_mov_before_return(compiler, op, src, srcw));
! 535:
! 536: local_size = compiler->local_size;
! 537: if (local_size <= SIMM_MAX)
! 538: base = S(REAL_STACK_PTR);
! 539: else {
! 540: FAIL_IF(load_immediate(compiler, DR(TMP_REG1), local_size));
! 541: FAIL_IF(push_inst(compiler, ADDU_W | S(REAL_STACK_PTR) | T(TMP_REG1) | D(TMP_REG1), DR(TMP_REG1)));
! 542: base = S(TMP_REG1);
! 543: local_size = 0;
! 544: }
! 545:
! 546: FAIL_IF(push_inst(compiler, STACK_LOAD | base | TA(RETURN_ADDR_REG) | IMM(local_size - 1 * (int)sizeof(sljit_w)), RETURN_ADDR_REG));
! 547: if (compiler->saveds >= 5)
! 548: FAIL_IF(push_inst(compiler, STACK_LOAD | base | T(SLJIT_SAVED_EREG2) | IMM(local_size - 7 * (int)sizeof(sljit_w)), DR(SLJIT_SAVED_EREG2)));
! 549: if (compiler->saveds >= 4)
! 550: FAIL_IF(push_inst(compiler, STACK_LOAD | base | T(SLJIT_SAVED_EREG1) | IMM(local_size - 6 * (int)sizeof(sljit_w)), DR(SLJIT_SAVED_EREG1)));
! 551: if (compiler->saveds >= 3)
! 552: FAIL_IF(push_inst(compiler, STACK_LOAD | base | T(SLJIT_SAVED_REG3) | IMM(local_size - 5 * (int)sizeof(sljit_w)), DR(SLJIT_SAVED_REG3)));
! 553: if (compiler->saveds >= 2)
! 554: FAIL_IF(push_inst(compiler, STACK_LOAD | base | T(SLJIT_SAVED_REG2) | IMM(local_size - 4 * (int)sizeof(sljit_w)), DR(SLJIT_SAVED_REG2)));
! 555: if (compiler->saveds >= 1)
! 556: FAIL_IF(push_inst(compiler, STACK_LOAD | base | T(SLJIT_SAVED_REG1) | IMM(local_size - 3 * (int)sizeof(sljit_w)), DR(SLJIT_SAVED_REG1)));
! 557: if (compiler->has_locals)
! 558: FAIL_IF(push_inst(compiler, STACK_LOAD | base | T(SLJIT_LOCALS_REG) | IMM(local_size - 2 * (int)sizeof(sljit_w)), DR(SLJIT_LOCALS_REG)));
! 559:
! 560: FAIL_IF(push_inst(compiler, JR | SA(RETURN_ADDR_REG), UNMOVABLE_INS));
! 561: if (compiler->local_size <= SIMM_MAX)
! 562: return push_inst(compiler, ADDIU_W | S(REAL_STACK_PTR) | T(REAL_STACK_PTR) | IMM(compiler->local_size), UNMOVABLE_INS);
! 563: else
! 564: return push_inst(compiler, ADDU_W | S(TMP_REG1) | TA(0) | D(REAL_STACK_PTR), UNMOVABLE_INS);
! 565: }
! 566:
! 567: #undef STACK_STORE
! 568: #undef STACK_LOAD
! 569:
! 570: /* --------------------------------------------------------------------- */
! 571: /* Operators */
! 572: /* --------------------------------------------------------------------- */
! 573:
! 574: #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
! 575: #define ARCH_DEPEND(a, b) a
! 576: #else
! 577: #define ARCH_DEPEND(a, b) b
! 578: #endif
! 579:
! 580: static SLJIT_CONST sljit_ins data_transfer_insts[16] = {
! 581: /* s u w */ ARCH_DEPEND(HI(43) /* sw */, HI(63) /* sd */),
! 582: /* s u b */ HI(40) /* sb */,
! 583: /* s u h */ HI(41) /* sh*/,
! 584: /* s u i */ HI(43) /* sw */,
! 585:
! 586: /* s s w */ ARCH_DEPEND(HI(43) /* sw */, HI(63) /* sd */),
! 587: /* s s b */ HI(40) /* sb */,
! 588: /* s s h */ HI(41) /* sh*/,
! 589: /* s s i */ HI(43) /* sw */,
! 590:
! 591: /* l u w */ ARCH_DEPEND(HI(35) /* lw */, HI(55) /* ld */),
! 592: /* l u b */ HI(36) /* lbu */,
! 593: /* l u h */ HI(37) /* lhu */,
! 594: /* l u i */ ARCH_DEPEND(HI(35) /* lw */, HI(39) /* lwu */),
! 595:
! 596: /* l s w */ ARCH_DEPEND(HI(35) /* lw */, HI(55) /* ld */),
! 597: /* l s b */ HI(32) /* lb */,
! 598: /* l s h */ HI(33) /* lh */,
! 599: /* l s i */ HI(35) /* lw */,
! 600: };
! 601:
! 602: /* reg_ar is an absoulute register! */
! 603:
! 604: /* Can perform an operation using at most 1 instruction. */
! 605: static int getput_arg_fast(struct sljit_compiler *compiler, int flags, int reg_ar, int arg, sljit_w argw)
! 606: {
! 607: SLJIT_ASSERT(arg & SLJIT_MEM);
! 608:
! 609: if (!(flags & WRITE_BACK) && !(arg & 0xf0) && argw <= SIMM_MAX && argw >= SIMM_MIN) {
! 610: /* Works for both absoulte and relative addresses. */
! 611: if (SLJIT_UNLIKELY(flags & ARG_TEST))
! 612: return 1;
! 613: FAIL_IF(push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | S(arg & 0xf) | TA(reg_ar) | IMM(argw), (flags & LOAD_DATA) ? reg_ar : MOVABLE_INS));
! 614: return -1;
! 615: }
! 616: return (flags & ARG_TEST) ? SLJIT_SUCCESS : 0;
! 617: }
! 618:
! 619: /* See getput_arg below.
! 620: Note: can_cache is called only for binary operators. Those
! 621: operators always uses word arguments without write back. */
! 622: static int can_cache(int arg, sljit_w argw, int next_arg, sljit_w next_argw)
! 623: {
! 624: if (!(next_arg & SLJIT_MEM))
! 625: return 0;
! 626:
! 627: /* Simple operation except for updates. */
! 628: if (arg & 0xf0) {
! 629: argw &= 0x3;
! 630: next_argw &= 0x3;
! 631: if (argw && argw == next_argw && (arg == next_arg || (arg & 0xf0) == (next_arg & 0xf0)))
! 632: return 1;
! 633: return 0;
! 634: }
! 635:
! 636: if (arg == next_arg) {
! 637: if (((sljit_uw)(next_argw - argw) <= SIMM_MAX && (sljit_uw)(next_argw - argw) >= SIMM_MIN))
! 638: return 1;
! 639: return 0;
! 640: }
! 641:
! 642: return 0;
! 643: }
! 644:
! 645: /* Emit the necessary instructions. See can_cache above. */
! 646: static int getput_arg(struct sljit_compiler *compiler, int flags, int reg_ar, int arg, sljit_w argw, int next_arg, sljit_w next_argw)
! 647: {
! 648: int tmp_ar;
! 649: int base;
! 650:
! 651: SLJIT_ASSERT(arg & SLJIT_MEM);
! 652: if (!(next_arg & SLJIT_MEM)) {
! 653: next_arg = 0;
! 654: next_argw = 0;
! 655: }
! 656:
! 657: tmp_ar = (flags & LOAD_DATA) ? reg_ar : DR(TMP_REG3);
! 658: base = arg & 0xf;
! 659:
! 660: if (SLJIT_UNLIKELY(arg & 0xf0)) {
! 661: argw &= 0x3;
! 662: if ((flags & WRITE_BACK) && reg_ar == DR(base)) {
! 663: SLJIT_ASSERT(!(flags & LOAD_DATA) && DR(TMP_REG1) != reg_ar);
! 664: FAIL_IF(push_inst(compiler, ADDU_W | SA(reg_ar) | TA(0) | D(TMP_REG1), DR(TMP_REG1)));
! 665: reg_ar = DR(TMP_REG1);
! 666: }
! 667:
! 668: /* Using the cache. */
! 669: if (argw == compiler->cache_argw) {
! 670: if (!(flags & WRITE_BACK)) {
! 671: if (arg == compiler->cache_arg)
! 672: return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | S(TMP_REG3) | TA(reg_ar), (flags & LOAD_DATA) ? reg_ar : MOVABLE_INS);
! 673: if ((SLJIT_MEM | (arg & 0xf0)) == compiler->cache_arg) {
! 674: if (arg == next_arg && argw == (next_argw & 0x3)) {
! 675: compiler->cache_arg = arg;
! 676: compiler->cache_argw = argw;
! 677: FAIL_IF(push_inst(compiler, ADDU_W | S(base) | T(TMP_REG3) | D(TMP_REG3), DR(TMP_REG3)));
! 678: return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | S(TMP_REG3) | TA(reg_ar), (flags & LOAD_DATA) ? reg_ar : MOVABLE_INS);
! 679: }
! 680: FAIL_IF(push_inst(compiler, ADDU_W | S(base) | T(TMP_REG3) | DA(tmp_ar), tmp_ar));
! 681: return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | SA(tmp_ar) | TA(reg_ar), (flags & LOAD_DATA) ? reg_ar : MOVABLE_INS);
! 682: }
! 683: }
! 684: else {
! 685: if ((SLJIT_MEM | (arg & 0xf0)) == compiler->cache_arg) {
! 686: FAIL_IF(push_inst(compiler, ADDU_W | S(base) | T(TMP_REG3) | D(base), DR(base)));
! 687: return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | S(base) | TA(reg_ar), (flags & LOAD_DATA) ? reg_ar : MOVABLE_INS);
! 688: }
! 689: }
! 690: }
! 691:
! 692: if (SLJIT_UNLIKELY(argw)) {
! 693: compiler->cache_arg = SLJIT_MEM | (arg & 0xf0);
! 694: compiler->cache_argw = argw;
! 695: FAIL_IF(push_inst(compiler, SLL_W | T((arg >> 4) & 0xf) | D(TMP_REG3) | SH_IMM(argw), DR(TMP_REG3)));
! 696: }
! 697:
! 698: if (!(flags & WRITE_BACK)) {
! 699: if (arg == next_arg && argw == (next_argw & 0x3)) {
! 700: compiler->cache_arg = arg;
! 701: compiler->cache_argw = argw;
! 702: FAIL_IF(push_inst(compiler, ADDU_W | S(base) | T(!argw ? ((arg >> 4) & 0xf) : TMP_REG3) | D(TMP_REG3), DR(TMP_REG3)));
! 703: tmp_ar = DR(TMP_REG3);
! 704: }
! 705: else
! 706: FAIL_IF(push_inst(compiler, ADDU_W | S(base) | T(!argw ? ((arg >> 4) & 0xf) : TMP_REG3) | DA(tmp_ar), tmp_ar));
! 707: return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | SA(tmp_ar) | TA(reg_ar), (flags & LOAD_DATA) ? reg_ar : MOVABLE_INS);
! 708: }
! 709: FAIL_IF(push_inst(compiler, ADDU_W | S(base) | T(!argw ? ((arg >> 4) & 0xf) : TMP_REG3) | D(base), DR(base)));
! 710: return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | S(base) | TA(reg_ar), (flags & LOAD_DATA) ? reg_ar : MOVABLE_INS);
! 711: }
! 712:
! 713: if (SLJIT_UNLIKELY(flags & WRITE_BACK) && base) {
! 714: /* Update only applies if a base register exists. */
! 715: if (reg_ar == DR(base)) {
! 716: SLJIT_ASSERT(!(flags & LOAD_DATA) && DR(TMP_REG1) != reg_ar);
! 717: if (argw <= SIMM_MAX && argw >= SIMM_MIN) {
! 718: FAIL_IF(push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | S(base) | TA(reg_ar) | IMM(argw), MOVABLE_INS));
! 719: if (argw)
! 720: return push_inst(compiler, ADDIU_W | S(base) | T(base) | IMM(argw), DR(base));
! 721: return SLJIT_SUCCESS;
! 722: }
! 723: FAIL_IF(push_inst(compiler, ADDU_W | SA(reg_ar) | TA(0) | D(TMP_REG1), DR(TMP_REG1)));
! 724: reg_ar = DR(TMP_REG1);
! 725: }
! 726:
! 727: if (argw <= SIMM_MAX && argw >= SIMM_MIN) {
! 728: if (argw)
! 729: FAIL_IF(push_inst(compiler, ADDIU_W | S(base) | T(base) | IMM(argw), DR(base)));
! 730: }
! 731: else {
! 732: if (compiler->cache_arg == SLJIT_MEM && argw - compiler->cache_argw <= SIMM_MAX && argw - compiler->cache_argw >= SIMM_MIN) {
! 733: if (argw != compiler->cache_argw) {
! 734: FAIL_IF(push_inst(compiler, ADDIU_W | S(TMP_REG3) | T(TMP_REG3) | IMM(argw - compiler->cache_argw), DR(TMP_REG3)));
! 735: compiler->cache_argw = argw;
! 736: }
! 737: FAIL_IF(push_inst(compiler, ADDU_W | S(base) | T(TMP_REG3) | D(base), DR(base)));
! 738: }
! 739: else {
! 740: compiler->cache_arg = SLJIT_MEM;
! 741: compiler->cache_argw = argw;
! 742: FAIL_IF(load_immediate(compiler, DR(TMP_REG3), argw));
! 743: FAIL_IF(push_inst(compiler, ADDU_W | S(base) | T(TMP_REG3) | D(base), DR(base)));
! 744: }
! 745: }
! 746: return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | S(base) | TA(reg_ar), (flags & LOAD_DATA) ? reg_ar : MOVABLE_INS);
! 747: }
! 748:
! 749: if (compiler->cache_arg == arg && argw - compiler->cache_argw <= SIMM_MAX && argw - compiler->cache_argw >= SIMM_MIN) {
! 750: if (argw != compiler->cache_argw) {
! 751: FAIL_IF(push_inst(compiler, ADDIU_W | S(TMP_REG3) | T(TMP_REG3) | IMM(argw - compiler->cache_argw), DR(TMP_REG3)));
! 752: compiler->cache_argw = argw;
! 753: }
! 754: return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | S(TMP_REG3) | TA(reg_ar), (flags & LOAD_DATA) ? reg_ar : MOVABLE_INS);
! 755: }
! 756:
! 757: if (compiler->cache_arg == SLJIT_MEM && argw - compiler->cache_argw <= SIMM_MAX && argw - compiler->cache_argw >= SIMM_MIN) {
! 758: if (argw != compiler->cache_argw)
! 759: FAIL_IF(push_inst(compiler, ADDIU_W | S(TMP_REG3) | T(TMP_REG3) | IMM(argw - compiler->cache_argw), DR(TMP_REG3)));
! 760: }
! 761: else {
! 762: compiler->cache_arg = SLJIT_MEM;
! 763: FAIL_IF(load_immediate(compiler, DR(TMP_REG3), argw));
! 764: }
! 765: compiler->cache_argw = argw;
! 766:
! 767: if (!base)
! 768: return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | S(TMP_REG3) | TA(reg_ar), (flags & LOAD_DATA) ? reg_ar : MOVABLE_INS);
! 769:
! 770: if (arg == next_arg && next_argw - argw <= SIMM_MAX && next_argw - argw >= SIMM_MIN) {
! 771: compiler->cache_arg = arg;
! 772: FAIL_IF(push_inst(compiler, ADDU_W | S(TMP_REG3) | T(base) | D(TMP_REG3), DR(TMP_REG3)));
! 773: return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | S(TMP_REG3) | TA(reg_ar), (flags & LOAD_DATA) ? reg_ar : MOVABLE_INS);
! 774: }
! 775:
! 776: FAIL_IF(push_inst(compiler, ADDU_W | S(TMP_REG3) | T(base) | DA(tmp_ar), tmp_ar));
! 777: return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | SA(tmp_ar) | TA(reg_ar), (flags & LOAD_DATA) ? reg_ar : MOVABLE_INS);
! 778: }
! 779:
! 780: static SLJIT_INLINE int emit_op_mem(struct sljit_compiler *compiler, int flags, int reg_ar, int arg, sljit_w argw)
! 781: {
! 782: if (getput_arg_fast(compiler, flags, reg_ar, arg, argw))
! 783: return compiler->error;
! 784: compiler->cache_arg = 0;
! 785: compiler->cache_argw = 0;
! 786: return getput_arg(compiler, flags, reg_ar, arg, argw, 0, 0);
! 787: }
! 788:
! 789: static int emit_op(struct sljit_compiler *compiler, int op, int flags,
! 790: int dst, sljit_w dstw,
! 791: int src1, sljit_w src1w,
! 792: int src2, sljit_w src2w)
! 793: {
! 794: /* arg1 goes to TMP_REG1 or src reg
! 795: arg2 goes to TMP_REG2, imm or src reg
! 796: TMP_REG3 can be used for caching
! 797: result goes to TMP_REG2, so put result can use TMP_REG1 and TMP_REG3. */
! 798: int dst_r = TMP_REG2;
! 799: int src1_r;
! 800: sljit_w src2_r = 0;
! 801: int sugg_src2_r = TMP_REG2;
! 802:
! 803: compiler->cache_arg = 0;
! 804: compiler->cache_argw = 0;
! 805:
! 806: if (dst >= SLJIT_TEMPORARY_REG1 && dst <= TMP_REG3) {
! 807: dst_r = dst;
! 808: flags |= REG_DEST;
! 809: if (GET_OPCODE(op) >= SLJIT_MOV && GET_OPCODE(op) <= SLJIT_MOVU_SI)
! 810: sugg_src2_r = dst_r;
! 811: }
! 812: else if (dst == SLJIT_UNUSED) {
! 813: if (op >= SLJIT_MOV && op <= SLJIT_MOVU_SI && !(src2 & SLJIT_MEM))
! 814: return SLJIT_SUCCESS;
! 815: if (GET_FLAGS(op))
! 816: flags |= UNUSED_DEST;
! 817: }
! 818: else if ((dst & SLJIT_MEM) && !getput_arg_fast(compiler, flags | ARG_TEST, DR(TMP_REG1), dst, dstw))
! 819: flags |= SLOW_DEST;
! 820:
! 821: if (flags & IMM_OP) {
! 822: if ((src2 & SLJIT_IMM) && src2w) {
! 823: if ((!(flags & LOGICAL_OP) && (src2w <= SIMM_MAX && src2w >= SIMM_MIN))
! 824: || ((flags & LOGICAL_OP) && !(src2w & ~UIMM_MAX))) {
! 825: flags |= SRC2_IMM;
! 826: src2_r = src2w;
! 827: }
! 828: }
! 829: if ((src1 & SLJIT_IMM) && src1w && (flags & CUMULATIVE_OP) && !(flags & SRC2_IMM)) {
! 830: if ((!(flags & LOGICAL_OP) && (src1w <= SIMM_MAX && src1w >= SIMM_MIN))
! 831: || ((flags & LOGICAL_OP) && !(src1w & ~UIMM_MAX))) {
! 832: flags |= SRC2_IMM;
! 833: src2_r = src1w;
! 834:
! 835: /* And swap arguments. */
! 836: src1 = src2;
! 837: src1w = src2w;
! 838: src2 = SLJIT_IMM;
! 839: /* src2w = src2_r unneeded. */
! 840: }
! 841: }
! 842: }
! 843:
! 844: /* Source 1. */
! 845: if (src1 >= SLJIT_TEMPORARY_REG1 && src1 <= TMP_REG3) {
! 846: src1_r = src1;
! 847: flags |= REG1_SOURCE;
! 848: }
! 849: else if (src1 & SLJIT_IMM) {
! 850: if (src1w) {
! 851: FAIL_IF(load_immediate(compiler, DR(TMP_REG1), src1w));
! 852: src1_r = TMP_REG1;
! 853: }
! 854: else
! 855: src1_r = 0;
! 856: }
! 857: else {
! 858: if (getput_arg_fast(compiler, flags | LOAD_DATA, DR(TMP_REG1), src1, src1w))
! 859: FAIL_IF(compiler->error);
! 860: else
! 861: flags |= SLOW_SRC1;
! 862: src1_r = TMP_REG1;
! 863: }
! 864:
! 865: /* Source 2. */
! 866: if (src2 >= SLJIT_TEMPORARY_REG1 && src2 <= TMP_REG3) {
! 867: src2_r = src2;
! 868: flags |= REG2_SOURCE;
! 869: if (!(flags & REG_DEST) && GET_OPCODE(op) >= SLJIT_MOV && GET_OPCODE(op) <= SLJIT_MOVU_SI)
! 870: dst_r = src2_r;
! 871: }
! 872: else if (src2 & SLJIT_IMM) {
! 873: if (!(flags & SRC2_IMM)) {
! 874: if (src2w || (GET_OPCODE(op) >= SLJIT_MOV && GET_OPCODE(op) <= SLJIT_MOVU_SI)) {
! 875: FAIL_IF(load_immediate(compiler, DR(sugg_src2_r), src2w));
! 876: src2_r = sugg_src2_r;
! 877: }
! 878: else
! 879: src2_r = 0;
! 880: }
! 881: }
! 882: else {
! 883: if (getput_arg_fast(compiler, flags | LOAD_DATA, DR(sugg_src2_r), src2, src2w))
! 884: FAIL_IF(compiler->error);
! 885: else
! 886: flags |= SLOW_SRC2;
! 887: src2_r = sugg_src2_r;
! 888: }
! 889:
! 890: if ((flags & (SLOW_SRC1 | SLOW_SRC2)) == (SLOW_SRC1 | SLOW_SRC2)) {
! 891: SLJIT_ASSERT(src2_r == TMP_REG2);
! 892: if (!can_cache(src1, src1w, src2, src2w) && can_cache(src1, src1w, dst, dstw)) {
! 893: FAIL_IF(getput_arg(compiler, flags | LOAD_DATA, DR(TMP_REG2), src2, src2w, src1, src1w));
! 894: FAIL_IF(getput_arg(compiler, flags | LOAD_DATA, DR(TMP_REG1), src1, src1w, dst, dstw));
! 895: }
! 896: else {
! 897: FAIL_IF(getput_arg(compiler, flags | LOAD_DATA, DR(TMP_REG1), src1, src1w, src2, src2w));
! 898: FAIL_IF(getput_arg(compiler, flags | LOAD_DATA, DR(TMP_REG2), src2, src2w, dst, dstw));
! 899: }
! 900: }
! 901: else if (flags & SLOW_SRC1)
! 902: FAIL_IF(getput_arg(compiler, flags | LOAD_DATA, DR(TMP_REG1), src1, src1w, dst, dstw));
! 903: else if (flags & SLOW_SRC2)
! 904: FAIL_IF(getput_arg(compiler, flags | LOAD_DATA, DR(sugg_src2_r), src2, src2w, dst, dstw));
! 905:
! 906: FAIL_IF(emit_single_op(compiler, op, flags, dst_r, src1_r, src2_r));
! 907:
! 908: if (dst & SLJIT_MEM) {
! 909: if (!(flags & SLOW_DEST)) {
! 910: getput_arg_fast(compiler, flags, DR(dst_r), dst, dstw);
! 911: return compiler->error;
! 912: }
! 913: return getput_arg(compiler, flags, DR(dst_r), dst, dstw, 0, 0);
! 914: }
! 915:
! 916: return SLJIT_SUCCESS;
! 917: }
! 918:
! 919: SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_op0(struct sljit_compiler *compiler, int op)
! 920: {
! 921: CHECK_ERROR();
! 922: check_sljit_emit_op0(compiler, op);
! 923:
! 924: op = GET_OPCODE(op);
! 925: switch (op) {
! 926: case SLJIT_BREAKPOINT:
! 927: return push_inst(compiler, BREAK, UNMOVABLE_INS);
! 928: case SLJIT_NOP:
! 929: return push_inst(compiler, NOP, UNMOVABLE_INS);
! 930: case SLJIT_UMUL:
! 931: case SLJIT_SMUL:
! 932: FAIL_IF(push_inst(compiler, (op == SLJIT_UMUL ? MULTU : MULT) | S(SLJIT_TEMPORARY_REG1) | T(SLJIT_TEMPORARY_REG2), MOVABLE_INS));
! 933: FAIL_IF(push_inst(compiler, MFLO | D(SLJIT_TEMPORARY_REG1), DR(SLJIT_TEMPORARY_REG1)));
! 934: return push_inst(compiler, MFHI | D(SLJIT_TEMPORARY_REG2), DR(SLJIT_TEMPORARY_REG2));
! 935: case SLJIT_UDIV:
! 936: case SLJIT_SDIV:
! 937: #if !(defined SLJIT_MIPS_32_64 && SLJIT_MIPS_32_64)
! 938: FAIL_IF(push_inst(compiler, NOP, UNMOVABLE_INS));
! 939: FAIL_IF(push_inst(compiler, NOP, UNMOVABLE_INS));
! 940: #endif
! 941: FAIL_IF(push_inst(compiler, (op == SLJIT_UDIV ? DIVU : DIV) | S(SLJIT_TEMPORARY_REG1) | T(SLJIT_TEMPORARY_REG2), MOVABLE_INS));
! 942: FAIL_IF(push_inst(compiler, MFLO | D(SLJIT_TEMPORARY_REG1), DR(SLJIT_TEMPORARY_REG1)));
! 943: return push_inst(compiler, MFHI | D(SLJIT_TEMPORARY_REG2), DR(SLJIT_TEMPORARY_REG2));
! 944: }
! 945:
! 946: return SLJIT_SUCCESS;
! 947: }
! 948:
! 949: SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_op1(struct sljit_compiler *compiler, int op,
! 950: int dst, sljit_w dstw,
! 951: int src, sljit_w srcw)
! 952: {
! 953: #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
! 954: #define inp_flags 0
! 955: #endif
! 956:
! 957: CHECK_ERROR();
! 958: check_sljit_emit_op1(compiler, op, dst, dstw, src, srcw);
! 959:
! 960: SLJIT_COMPILE_ASSERT(SLJIT_MOV + 7 == SLJIT_MOVU, movu_offset);
! 961:
! 962: switch (GET_OPCODE(op)) {
! 963: case SLJIT_MOV:
! 964: return emit_op(compiler, SLJIT_MOV, inp_flags | WORD_DATA, dst, dstw, TMP_REG1, 0, src, srcw);
! 965:
! 966: case SLJIT_MOV_UI:
! 967: return emit_op(compiler, SLJIT_MOV_UI, inp_flags | INT_DATA, dst, dstw, TMP_REG1, 0, src, srcw);
! 968:
! 969: case SLJIT_MOV_SI:
! 970: return emit_op(compiler, SLJIT_MOV_SI, inp_flags | INT_DATA | SIGNED_DATA, dst, dstw, TMP_REG1, 0, src, srcw);
! 971:
! 972: case SLJIT_MOV_UB:
! 973: return emit_op(compiler, SLJIT_MOV_UB, inp_flags | BYTE_DATA, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (unsigned char)srcw : srcw);
! 974:
! 975: case SLJIT_MOV_SB:
! 976: return emit_op(compiler, SLJIT_MOV_SB, inp_flags | BYTE_DATA | SIGNED_DATA, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (signed char)srcw : srcw);
! 977:
! 978: case SLJIT_MOV_UH:
! 979: return emit_op(compiler, SLJIT_MOV_UH, inp_flags | HALF_DATA, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (unsigned short)srcw : srcw);
! 980:
! 981: case SLJIT_MOV_SH:
! 982: return emit_op(compiler, SLJIT_MOV_SH, inp_flags | HALF_DATA | SIGNED_DATA, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (signed short)srcw : srcw);
! 983:
! 984: case SLJIT_MOVU:
! 985: return emit_op(compiler, SLJIT_MOV, inp_flags | WORD_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, srcw);
! 986:
! 987: case SLJIT_MOVU_UI:
! 988: return emit_op(compiler, SLJIT_MOV_UI, inp_flags | INT_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, srcw);
! 989:
! 990: case SLJIT_MOVU_SI:
! 991: return emit_op(compiler, SLJIT_MOV_SI, inp_flags | INT_DATA | SIGNED_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, srcw);
! 992:
! 993: case SLJIT_MOVU_UB:
! 994: return emit_op(compiler, SLJIT_MOV_UB, inp_flags | BYTE_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (unsigned char)srcw : srcw);
! 995:
! 996: case SLJIT_MOVU_SB:
! 997: return emit_op(compiler, SLJIT_MOV_SB, inp_flags | BYTE_DATA | SIGNED_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (signed char)srcw : srcw);
! 998:
! 999: case SLJIT_MOVU_UH:
! 1000: return emit_op(compiler, SLJIT_MOV_UH, inp_flags | HALF_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (unsigned short)srcw : srcw);
! 1001:
! 1002: case SLJIT_MOVU_SH:
! 1003: return emit_op(compiler, SLJIT_MOV_SH, inp_flags | HALF_DATA | SIGNED_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (signed short)srcw : srcw);
! 1004:
! 1005: case SLJIT_NOT:
! 1006: return emit_op(compiler, op, inp_flags, dst, dstw, TMP_REG1, 0, src, srcw);
! 1007:
! 1008: case SLJIT_NEG:
! 1009: return emit_op(compiler, SLJIT_SUB | GET_ALL_FLAGS(op), inp_flags | IMM_OP, dst, dstw, SLJIT_IMM, 0, src, srcw);
! 1010:
! 1011: case SLJIT_CLZ:
! 1012: return emit_op(compiler, op, inp_flags, dst, dstw, TMP_REG1, 0, src, srcw);
! 1013: }
! 1014:
! 1015: return SLJIT_SUCCESS;
! 1016: #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
! 1017: #undef inp_flags
! 1018: #endif
! 1019: }
! 1020:
! 1021: SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_op2(struct sljit_compiler *compiler, int op,
! 1022: int dst, sljit_w dstw,
! 1023: int src1, sljit_w src1w,
! 1024: int src2, sljit_w src2w)
! 1025: {
! 1026: #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
! 1027: #define inp_flags 0
! 1028: #endif
! 1029:
! 1030: CHECK_ERROR();
! 1031: check_sljit_emit_op2(compiler, op, dst, dstw, src1, src1w, src2, src2w);
! 1032:
! 1033: switch (GET_OPCODE(op)) {
! 1034: case SLJIT_ADD:
! 1035: case SLJIT_ADDC:
! 1036: return emit_op(compiler, op, inp_flags | CUMULATIVE_OP | IMM_OP, dst, dstw, src1, src1w, src2, src2w);
! 1037:
! 1038: case SLJIT_SUB:
! 1039: case SLJIT_SUBC:
! 1040: return emit_op(compiler, op, inp_flags | IMM_OP, dst, dstw, src1, src1w, src2, src2w);
! 1041:
! 1042: case SLJIT_MUL:
! 1043: return emit_op(compiler, op, inp_flags | CUMULATIVE_OP, dst, dstw, src1, src1w, src2, src2w);
! 1044:
! 1045: case SLJIT_AND:
! 1046: case SLJIT_OR:
! 1047: case SLJIT_XOR:
! 1048: return emit_op(compiler, op, inp_flags | CUMULATIVE_OP | LOGICAL_OP | IMM_OP, dst, dstw, src1, src1w, src2, src2w);
! 1049:
! 1050: case SLJIT_SHL:
! 1051: case SLJIT_LSHR:
! 1052: case SLJIT_ASHR:
! 1053: #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
! 1054: if (src2 & SLJIT_IMM)
! 1055: src2w &= 0x1f;
! 1056: #else
! 1057: if (src2 & SLJIT_IMM)
! 1058: src2w &= 0x3f;
! 1059: #endif
! 1060: return emit_op(compiler, op, inp_flags | IMM_OP, dst, dstw, src1, src1w, src2, src2w);
! 1061: }
! 1062:
! 1063: return SLJIT_SUCCESS;
! 1064: #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
! 1065: #undef inp_flags
! 1066: #endif
! 1067: }
! 1068:
! 1069: SLJIT_API_FUNC_ATTRIBUTE int sljit_get_register_index(int reg)
! 1070: {
! 1071: check_sljit_get_register_index(reg);
! 1072: return reg_map[reg];
! 1073: }
! 1074:
! 1075: SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_op_custom(struct sljit_compiler *compiler,
! 1076: void *instruction, int size)
! 1077: {
! 1078: CHECK_ERROR();
! 1079: check_sljit_emit_op_custom(compiler, instruction, size);
! 1080: SLJIT_ASSERT(size == 4);
! 1081:
! 1082: return push_inst(compiler, *(sljit_ins*)instruction, UNMOVABLE_INS);
! 1083: }
! 1084:
! 1085: /* --------------------------------------------------------------------- */
! 1086: /* Floating point operators */
! 1087: /* --------------------------------------------------------------------- */
! 1088:
! 1089: SLJIT_API_FUNC_ATTRIBUTE int sljit_is_fpu_available(void)
! 1090: {
! 1091: #if (defined SLJIT_QEMU && SLJIT_QEMU)
! 1092: /* Qemu says fir is 0 by default. */
! 1093: return 1;
! 1094: #elif defined(__GNUC__)
! 1095: sljit_w fir;
! 1096: asm ("cfc1 %0, $0" : "=r"(fir));
! 1097: return (fir >> 22) & 0x1;
! 1098: #else
! 1099: #error "FIR check is not implemented for this architecture"
! 1100: #endif
! 1101: }
! 1102:
! 1103: static int emit_fpu_data_transfer(struct sljit_compiler *compiler, int fpu_reg, int load, int arg, sljit_w argw)
! 1104: {
! 1105: int hi_reg;
! 1106:
! 1107: SLJIT_ASSERT(arg & SLJIT_MEM);
! 1108:
! 1109: /* Fast loads and stores. */
! 1110: if (!(arg & 0xf0)) {
! 1111: /* Both for (arg & 0xf) == SLJIT_UNUSED and (arg & 0xf) != SLJIT_UNUSED. */
! 1112: if (argw <= SIMM_MAX && argw >= SIMM_MIN)
! 1113: return push_inst(compiler, (load ? LDC1 : SDC1) | S(arg & 0xf) | FT(fpu_reg) | IMM(argw), MOVABLE_INS);
! 1114: }
! 1115:
! 1116: if (arg & 0xf0) {
! 1117: argw &= 0x3;
! 1118: hi_reg = (arg >> 4) & 0xf;
! 1119: if (argw) {
! 1120: FAIL_IF(push_inst(compiler, SLL_W | T(hi_reg) | D(TMP_REG1) | SH_IMM(argw), DR(TMP_REG1)));
! 1121: hi_reg = TMP_REG1;
! 1122: }
! 1123: FAIL_IF(push_inst(compiler, ADDU_W | S(hi_reg) | T(arg & 0xf) | D(TMP_REG1), DR(TMP_REG1)));
! 1124: return push_inst(compiler, (load ? LDC1 : SDC1) | S(TMP_REG1) | FT(fpu_reg) | IMM(0), MOVABLE_INS);
! 1125: }
! 1126:
! 1127: /* Use cache. */
! 1128: if (compiler->cache_arg == arg && argw - compiler->cache_argw <= SIMM_MAX && argw - compiler->cache_argw >= SIMM_MIN)
! 1129: return push_inst(compiler, (load ? LDC1 : SDC1) | S(TMP_REG3) | FT(fpu_reg) | IMM(argw - compiler->cache_argw), MOVABLE_INS);
! 1130:
! 1131: /* Put value to cache. */
! 1132: compiler->cache_arg = arg;
! 1133: compiler->cache_argw = argw;
! 1134:
! 1135: FAIL_IF(load_immediate(compiler, DR(TMP_REG3), argw));
! 1136: if (arg & 0xf)
! 1137: FAIL_IF(push_inst(compiler, ADDU_W | S(TMP_REG3) | T(arg & 0xf) | D(TMP_REG3), DR(TMP_REG3)));
! 1138: return push_inst(compiler, (load ? LDC1 : SDC1) | S(TMP_REG3) | FT(fpu_reg) | IMM(0), MOVABLE_INS);
! 1139: }
! 1140:
! 1141: SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_fop1(struct sljit_compiler *compiler, int op,
! 1142: int dst, sljit_w dstw,
! 1143: int src, sljit_w srcw)
! 1144: {
! 1145: int dst_fr;
! 1146:
! 1147: CHECK_ERROR();
! 1148: check_sljit_emit_fop1(compiler, op, dst, dstw, src, srcw);
! 1149:
! 1150: compiler->cache_arg = 0;
! 1151: compiler->cache_argw = 0;
! 1152:
! 1153: if (GET_OPCODE(op) == SLJIT_FCMP) {
! 1154: if (dst > SLJIT_FLOAT_REG4) {
! 1155: FAIL_IF(emit_fpu_data_transfer(compiler, TMP_FREG1, 1, dst, dstw));
! 1156: dst = TMP_FREG1;
! 1157: }
! 1158: if (src > SLJIT_FLOAT_REG4) {
! 1159: FAIL_IF(emit_fpu_data_transfer(compiler, TMP_FREG2, 1, src, srcw));
! 1160: src = TMP_FREG2;
! 1161: }
! 1162:
! 1163: /* src and dst are swapped. */
! 1164: if (op & SLJIT_SET_E) {
! 1165: FAIL_IF(push_inst(compiler, C_UEQ_D | FT(src) | FS(dst), UNMOVABLE_INS));
! 1166: FAIL_IF(push_inst(compiler, CFC1 | TA(EQUAL_FLAG) | DA(FCSR_REG), EQUAL_FLAG));
! 1167: FAIL_IF(push_inst(compiler, SRL | TA(EQUAL_FLAG) | DA(EQUAL_FLAG) | SH_IMM(23), EQUAL_FLAG));
! 1168: FAIL_IF(push_inst(compiler, ANDI | SA(EQUAL_FLAG) | TA(EQUAL_FLAG) | IMM(1), EQUAL_FLAG));
! 1169: }
! 1170: if (op & SLJIT_SET_S) {
! 1171: /* Mixing the instructions for the two checks. */
! 1172: FAIL_IF(push_inst(compiler, C_ULT_D | FT(src) | FS(dst), UNMOVABLE_INS));
! 1173: FAIL_IF(push_inst(compiler, CFC1 | TA(ULESS_FLAG) | DA(FCSR_REG), ULESS_FLAG));
! 1174: FAIL_IF(push_inst(compiler, C_ULT_D | FT(dst) | FS(src), UNMOVABLE_INS));
! 1175: FAIL_IF(push_inst(compiler, SRL | TA(ULESS_FLAG) | DA(ULESS_FLAG) | SH_IMM(23), ULESS_FLAG));
! 1176: FAIL_IF(push_inst(compiler, ANDI | SA(ULESS_FLAG) | TA(ULESS_FLAG) | IMM(1), ULESS_FLAG));
! 1177: FAIL_IF(push_inst(compiler, CFC1 | TA(UGREATER_FLAG) | DA(FCSR_REG), UGREATER_FLAG));
! 1178: FAIL_IF(push_inst(compiler, SRL | TA(UGREATER_FLAG) | DA(UGREATER_FLAG) | SH_IMM(23), UGREATER_FLAG));
! 1179: FAIL_IF(push_inst(compiler, ANDI | SA(UGREATER_FLAG) | TA(UGREATER_FLAG) | IMM(1), UGREATER_FLAG));
! 1180: }
! 1181: return push_inst(compiler, C_UN_D | FT(src) | FS(dst), FCSR_FCC);
! 1182: }
! 1183:
! 1184: dst_fr = (dst > SLJIT_FLOAT_REG4) ? TMP_FREG1 : dst;
! 1185:
! 1186: if (src > SLJIT_FLOAT_REG4) {
! 1187: FAIL_IF(emit_fpu_data_transfer(compiler, dst_fr, 1, src, srcw));
! 1188: src = dst_fr;
! 1189: }
! 1190:
! 1191: switch (op) {
! 1192: case SLJIT_FMOV:
! 1193: if (src != dst_fr && dst_fr != TMP_FREG1)
! 1194: FAIL_IF(push_inst(compiler, MOV_D | FS(src) | FD(dst_fr), MOVABLE_INS));
! 1195: break;
! 1196: case SLJIT_FNEG:
! 1197: FAIL_IF(push_inst(compiler, NEG_D | FS(src) | FD(dst_fr), MOVABLE_INS));
! 1198: break;
! 1199: case SLJIT_FABS:
! 1200: FAIL_IF(push_inst(compiler, ABS_D | FS(src) | FD(dst_fr), MOVABLE_INS));
! 1201: break;
! 1202: }
! 1203:
! 1204: if (dst_fr == TMP_FREG1)
! 1205: FAIL_IF(emit_fpu_data_transfer(compiler, src, 0, dst, dstw));
! 1206:
! 1207: return SLJIT_SUCCESS;
! 1208: }
! 1209:
! 1210: SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_fop2(struct sljit_compiler *compiler, int op,
! 1211: int dst, sljit_w dstw,
! 1212: int src1, sljit_w src1w,
! 1213: int src2, sljit_w src2w)
! 1214: {
! 1215: int dst_fr;
! 1216:
! 1217: CHECK_ERROR();
! 1218: check_sljit_emit_fop2(compiler, op, dst, dstw, src1, src1w, src2, src2w);
! 1219:
! 1220: compiler->cache_arg = 0;
! 1221: compiler->cache_argw = 0;
! 1222:
! 1223: dst_fr = (dst > SLJIT_FLOAT_REG4) ? TMP_FREG1 : dst;
! 1224:
! 1225: if (src2 > SLJIT_FLOAT_REG4) {
! 1226: FAIL_IF(emit_fpu_data_transfer(compiler, TMP_FREG2, 1, src2, src2w));
! 1227: src2 = TMP_FREG2;
! 1228: }
! 1229:
! 1230: if (src1 > SLJIT_FLOAT_REG4) {
! 1231: FAIL_IF(emit_fpu_data_transfer(compiler, TMP_FREG1, 1, src1, src1w));
! 1232: src1 = TMP_FREG1;
! 1233: }
! 1234:
! 1235: switch (op) {
! 1236: case SLJIT_FADD:
! 1237: FAIL_IF(push_inst(compiler, ADD_D | FT(src2) | FS(src1) | FD(dst_fr), MOVABLE_INS));
! 1238: break;
! 1239:
! 1240: case SLJIT_FSUB:
! 1241: FAIL_IF(push_inst(compiler, SUB_D | FT(src2) | FS(src1) | FD(dst_fr), MOVABLE_INS));
! 1242: break;
! 1243:
! 1244: case SLJIT_FMUL:
! 1245: FAIL_IF(push_inst(compiler, MUL_D | FT(src2) | FS(src1) | FD(dst_fr), MOVABLE_INS));
! 1246: break;
! 1247:
! 1248: case SLJIT_FDIV:
! 1249: FAIL_IF(push_inst(compiler, DIV_D | FT(src2) | FS(src1) | FD(dst_fr), MOVABLE_INS));
! 1250: break;
! 1251: }
! 1252:
! 1253: if (dst_fr == TMP_FREG1)
! 1254: FAIL_IF(emit_fpu_data_transfer(compiler, TMP_FREG1, 0, dst, dstw));
! 1255:
! 1256: return SLJIT_SUCCESS;
! 1257: }
! 1258:
! 1259: /* --------------------------------------------------------------------- */
! 1260: /* Other instructions */
! 1261: /* --------------------------------------------------------------------- */
! 1262:
! 1263: SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_fast_enter(struct sljit_compiler *compiler, int dst, sljit_w dstw, int args, int temporaries, int saveds, int local_size)
! 1264: {
! 1265: CHECK_ERROR();
! 1266: check_sljit_emit_fast_enter(compiler, dst, dstw, args, temporaries, saveds, local_size);
! 1267:
! 1268: compiler->temporaries = temporaries;
! 1269: compiler->saveds = saveds;
! 1270:
! 1271: compiler->has_locals = local_size > 0;
! 1272: local_size += (saveds + 2 + 4) * sizeof(sljit_w);
! 1273: compiler->local_size = (local_size + 15) & ~0xf;
! 1274:
! 1275: if (dst >= SLJIT_TEMPORARY_REG1 && dst <= SLJIT_NO_REGISTERS)
! 1276: return push_inst(compiler, ADDU_W | SA(RETURN_ADDR_REG) | TA(0) | D(dst), DR(dst));
! 1277: else if (dst & SLJIT_MEM)
! 1278: return emit_op_mem(compiler, WORD_DATA, RETURN_ADDR_REG, dst, dstw);
! 1279: return SLJIT_SUCCESS;
! 1280: }
! 1281:
! 1282: SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_fast_return(struct sljit_compiler *compiler, int src, sljit_w srcw)
! 1283: {
! 1284: CHECK_ERROR();
! 1285: check_sljit_emit_fast_return(compiler, src, srcw);
! 1286:
! 1287: if (src >= SLJIT_TEMPORARY_REG1 && src <= SLJIT_NO_REGISTERS)
! 1288: FAIL_IF(push_inst(compiler, ADDU_W | S(src) | TA(0) | DA(RETURN_ADDR_REG), RETURN_ADDR_REG));
! 1289: else if (src & SLJIT_MEM)
! 1290: FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, RETURN_ADDR_REG, src, srcw));
! 1291: else if (src & SLJIT_IMM)
! 1292: FAIL_IF(load_immediate(compiler, RETURN_ADDR_REG, srcw));
! 1293:
! 1294: FAIL_IF(push_inst(compiler, JR | SA(RETURN_ADDR_REG), UNMOVABLE_INS));
! 1295: return push_inst(compiler, NOP, UNMOVABLE_INS);
! 1296: }
! 1297:
! 1298: /* --------------------------------------------------------------------- */
! 1299: /* Conditional instructions */
! 1300: /* --------------------------------------------------------------------- */
! 1301:
! 1302: SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler)
! 1303: {
! 1304: struct sljit_label *label;
! 1305:
! 1306: CHECK_ERROR_PTR();
! 1307: check_sljit_emit_label(compiler);
! 1308:
! 1309: if (compiler->last_label && compiler->last_label->size == compiler->size)
! 1310: return compiler->last_label;
! 1311:
! 1312: label = (struct sljit_label*)ensure_abuf(compiler, sizeof(struct sljit_label));
! 1313: PTR_FAIL_IF(!label);
! 1314: set_label(label, compiler);
! 1315: compiler->delay_slot = UNMOVABLE_INS;
! 1316: return label;
! 1317: }
! 1318:
! 1319: #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
! 1320: #define JUMP_LENGTH 4
! 1321: #else
! 1322: #define JUMP_LENGTH 7
! 1323: #endif
! 1324:
! 1325: #define BR_Z(src) \
! 1326: inst = BEQ | SA(src) | TA(0) | JUMP_LENGTH; \
! 1327: flags = IS_BIT26_COND; \
! 1328: delay_check = src;
! 1329:
! 1330: #define BR_NZ(src) \
! 1331: inst = BNE | SA(src) | TA(0) | JUMP_LENGTH; \
! 1332: flags = IS_BIT26_COND; \
! 1333: delay_check = src;
! 1334:
! 1335: #define BR_T() \
! 1336: inst = BC1T | JUMP_LENGTH; \
! 1337: flags = IS_BIT16_COND; \
! 1338: delay_check = FCSR_FCC;
! 1339:
! 1340: #define BR_F() \
! 1341: inst = BC1F | JUMP_LENGTH; \
! 1342: flags = IS_BIT16_COND; \
! 1343: delay_check = FCSR_FCC;
! 1344:
! 1345: SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, int type)
! 1346: {
! 1347: struct sljit_jump *jump;
! 1348: sljit_ins inst;
! 1349: int flags = 0;
! 1350: int delay_check = UNMOVABLE_INS;
! 1351:
! 1352: CHECK_ERROR_PTR();
! 1353: check_sljit_emit_jump(compiler, type);
! 1354:
! 1355: jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump));
! 1356: PTR_FAIL_IF(!jump);
! 1357: set_jump(jump, compiler, type & SLJIT_REWRITABLE_JUMP);
! 1358: type &= 0xff;
! 1359:
! 1360: switch (type) {
! 1361: case SLJIT_C_EQUAL:
! 1362: case SLJIT_C_FLOAT_NOT_EQUAL:
! 1363: BR_NZ(EQUAL_FLAG);
! 1364: break;
! 1365: case SLJIT_C_NOT_EQUAL:
! 1366: case SLJIT_C_FLOAT_EQUAL:
! 1367: BR_Z(EQUAL_FLAG);
! 1368: break;
! 1369: case SLJIT_C_LESS:
! 1370: case SLJIT_C_FLOAT_LESS:
! 1371: BR_Z(ULESS_FLAG);
! 1372: break;
! 1373: case SLJIT_C_GREATER_EQUAL:
! 1374: case SLJIT_C_FLOAT_GREATER_EQUAL:
! 1375: BR_NZ(ULESS_FLAG);
! 1376: break;
! 1377: case SLJIT_C_GREATER:
! 1378: case SLJIT_C_FLOAT_GREATER:
! 1379: BR_Z(UGREATER_FLAG);
! 1380: break;
! 1381: case SLJIT_C_LESS_EQUAL:
! 1382: case SLJIT_C_FLOAT_LESS_EQUAL:
! 1383: BR_NZ(UGREATER_FLAG);
! 1384: break;
! 1385: case SLJIT_C_SIG_LESS:
! 1386: BR_Z(LESS_FLAG);
! 1387: break;
! 1388: case SLJIT_C_SIG_GREATER_EQUAL:
! 1389: BR_NZ(LESS_FLAG);
! 1390: break;
! 1391: case SLJIT_C_SIG_GREATER:
! 1392: BR_Z(GREATER_FLAG);
! 1393: break;
! 1394: case SLJIT_C_SIG_LESS_EQUAL:
! 1395: BR_NZ(GREATER_FLAG);
! 1396: break;
! 1397: case SLJIT_C_OVERFLOW:
! 1398: case SLJIT_C_MUL_OVERFLOW:
! 1399: BR_Z(OVERFLOW_FLAG);
! 1400: break;
! 1401: case SLJIT_C_NOT_OVERFLOW:
! 1402: case SLJIT_C_MUL_NOT_OVERFLOW:
! 1403: BR_NZ(OVERFLOW_FLAG);
! 1404: break;
! 1405: case SLJIT_C_FLOAT_NAN:
! 1406: BR_F();
! 1407: break;
! 1408: case SLJIT_C_FLOAT_NOT_NAN:
! 1409: BR_T();
! 1410: break;
! 1411: default:
! 1412: /* Not conditional branch. */
! 1413: inst = 0;
! 1414: break;
! 1415: }
! 1416:
! 1417: jump->flags |= flags;
! 1418: if (compiler->delay_slot == MOVABLE_INS || (compiler->delay_slot != UNMOVABLE_INS && compiler->delay_slot != delay_check))
! 1419: jump->flags |= IS_MOVABLE;
! 1420:
! 1421: if (inst)
! 1422: PTR_FAIL_IF(push_inst(compiler, inst, UNMOVABLE_INS));
! 1423:
! 1424: PTR_FAIL_IF(emit_const(compiler, TMP_REG2, 0));
! 1425: if (type <= SLJIT_JUMP) {
! 1426: PTR_FAIL_IF(push_inst(compiler, JR | S(TMP_REG2), UNMOVABLE_INS));
! 1427: jump->addr = compiler->size;
! 1428: PTR_FAIL_IF(push_inst(compiler, NOP, UNMOVABLE_INS));
! 1429: } else {
! 1430: SLJIT_ASSERT(DR(PIC_ADDR_REG) == 25 && PIC_ADDR_REG == TMP_REG2);
! 1431: /* Cannot be optimized out if type is >= CALL0. */
! 1432: jump->flags |= IS_JAL | (type >= SLJIT_CALL0 ? SLJIT_REWRITABLE_JUMP : 0);
! 1433: PTR_FAIL_IF(push_inst(compiler, JALR | S(TMP_REG2) | DA(RETURN_ADDR_REG), UNMOVABLE_INS));
! 1434: jump->addr = compiler->size;
! 1435: /* A NOP if type < CALL1. */
! 1436: PTR_FAIL_IF(push_inst(compiler, ADDU_W | S(SLJIT_TEMPORARY_REG1) | TA(0) | DA(4), UNMOVABLE_INS));
! 1437: }
! 1438: return jump;
! 1439: }
! 1440:
! 1441: #define RESOLVE_IMM1() \
! 1442: if (src1 & SLJIT_IMM) { \
! 1443: if (src1w) { \
! 1444: PTR_FAIL_IF(load_immediate(compiler, DR(TMP_REG1), src1w)); \
! 1445: src1 = TMP_REG1; \
! 1446: } \
! 1447: else \
! 1448: src1 = 0; \
! 1449: }
! 1450:
! 1451: #define RESOLVE_IMM2() \
! 1452: if (src2 & SLJIT_IMM) { \
! 1453: if (src2w) { \
! 1454: PTR_FAIL_IF(load_immediate(compiler, DR(TMP_REG2), src2w)); \
! 1455: src2 = TMP_REG2; \
! 1456: } \
! 1457: else \
! 1458: src2 = 0; \
! 1459: }
! 1460:
! 1461: SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, int type,
! 1462: int src1, sljit_w src1w,
! 1463: int src2, sljit_w src2w)
! 1464: {
! 1465: struct sljit_jump *jump;
! 1466: int flags;
! 1467: sljit_ins inst;
! 1468:
! 1469: CHECK_ERROR_PTR();
! 1470: check_sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w);
! 1471:
! 1472: compiler->cache_arg = 0;
! 1473: compiler->cache_argw = 0;
! 1474: flags = ((type & SLJIT_INT_OP) ? INT_DATA : WORD_DATA) | LOAD_DATA;
! 1475: if (src1 & SLJIT_MEM) {
! 1476: if (getput_arg_fast(compiler, flags, DR(TMP_REG1), src1, src1w))
! 1477: PTR_FAIL_IF(compiler->error);
! 1478: else
! 1479: PTR_FAIL_IF(getput_arg(compiler, flags, DR(TMP_REG1), src1, src1w, src2, src2w));
! 1480: src1 = TMP_REG1;
! 1481: }
! 1482: if (src2 & SLJIT_MEM) {
! 1483: if (getput_arg_fast(compiler, flags, DR(TMP_REG2), src2, src2w))
! 1484: PTR_FAIL_IF(compiler->error);
! 1485: else
! 1486: PTR_FAIL_IF(getput_arg(compiler, flags, DR(TMP_REG2), src2, src2w, 0, 0));
! 1487: src2 = TMP_REG2;
! 1488: }
! 1489:
! 1490: jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump));
! 1491: PTR_FAIL_IF(!jump);
! 1492: set_jump(jump, compiler, type & SLJIT_REWRITABLE_JUMP);
! 1493: type &= 0xff;
! 1494:
! 1495: if (type <= SLJIT_C_NOT_EQUAL) {
! 1496: RESOLVE_IMM1();
! 1497: RESOLVE_IMM2();
! 1498: jump->flags |= IS_BIT26_COND;
! 1499: if (compiler->delay_slot == MOVABLE_INS || (compiler->delay_slot != UNMOVABLE_INS && compiler->delay_slot != DR(src1) && compiler->delay_slot != DR(src2)))
! 1500: jump->flags |= IS_MOVABLE;
! 1501: PTR_FAIL_IF(push_inst(compiler, (type == SLJIT_C_EQUAL ? BNE : BEQ) | S(src1) | T(src2) | JUMP_LENGTH, UNMOVABLE_INS));
! 1502: }
! 1503: else if (type >= SLJIT_C_SIG_LESS && (((src1 & SLJIT_IMM) && (src1w == 0)) || ((src2 & SLJIT_IMM) && (src2w == 0)))) {
! 1504: inst = NOP;
! 1505: if ((src1 & SLJIT_IMM) && (src1w == 0)) {
! 1506: RESOLVE_IMM2();
! 1507: switch (type) {
! 1508: case SLJIT_C_SIG_LESS:
! 1509: inst = BLEZ;
! 1510: jump->flags |= IS_BIT26_COND;
! 1511: break;
! 1512: case SLJIT_C_SIG_GREATER_EQUAL:
! 1513: inst = BGTZ;
! 1514: jump->flags |= IS_BIT26_COND;
! 1515: break;
! 1516: case SLJIT_C_SIG_GREATER:
! 1517: inst = BGEZ;
! 1518: jump->flags |= IS_BIT16_COND;
! 1519: break;
! 1520: case SLJIT_C_SIG_LESS_EQUAL:
! 1521: inst = BLTZ;
! 1522: jump->flags |= IS_BIT16_COND;
! 1523: break;
! 1524: }
! 1525: src1 = src2;
! 1526: }
! 1527: else {
! 1528: RESOLVE_IMM1();
! 1529: switch (type) {
! 1530: case SLJIT_C_SIG_LESS:
! 1531: inst = BGEZ;
! 1532: jump->flags |= IS_BIT16_COND;
! 1533: break;
! 1534: case SLJIT_C_SIG_GREATER_EQUAL:
! 1535: inst = BLTZ;
! 1536: jump->flags |= IS_BIT16_COND;
! 1537: break;
! 1538: case SLJIT_C_SIG_GREATER:
! 1539: inst = BLEZ;
! 1540: jump->flags |= IS_BIT26_COND;
! 1541: break;
! 1542: case SLJIT_C_SIG_LESS_EQUAL:
! 1543: inst = BGTZ;
! 1544: jump->flags |= IS_BIT26_COND;
! 1545: break;
! 1546: }
! 1547: }
! 1548: PTR_FAIL_IF(push_inst(compiler, inst | S(src1) | JUMP_LENGTH, UNMOVABLE_INS));
! 1549: }
! 1550: else {
! 1551: if (type == SLJIT_C_LESS || type == SLJIT_C_GREATER_EQUAL || type == SLJIT_C_SIG_LESS || type == SLJIT_C_SIG_GREATER_EQUAL) {
! 1552: RESOLVE_IMM1();
! 1553: if ((src2 & SLJIT_IMM) && src2w <= SIMM_MAX && src2w >= SIMM_MIN)
! 1554: PTR_FAIL_IF(push_inst(compiler, (type <= SLJIT_C_LESS_EQUAL ? SLTIU : SLTI) | S(src1) | T(TMP_REG1) | IMM(src2w), DR(TMP_REG1)));
! 1555: else {
! 1556: RESOLVE_IMM2();
! 1557: PTR_FAIL_IF(push_inst(compiler, (type <= SLJIT_C_LESS_EQUAL ? SLTU : SLT) | S(src1) | T(src2) | D(TMP_REG1), DR(TMP_REG1)));
! 1558: }
! 1559: type = (type == SLJIT_C_LESS || type == SLJIT_C_SIG_LESS) ? SLJIT_C_NOT_EQUAL : SLJIT_C_EQUAL;
! 1560: }
! 1561: else {
! 1562: RESOLVE_IMM2();
! 1563: if ((src1 & SLJIT_IMM) && src1w <= SIMM_MAX && src1w >= SIMM_MIN)
! 1564: PTR_FAIL_IF(push_inst(compiler, (type <= SLJIT_C_LESS_EQUAL ? SLTIU : SLTI) | S(src2) | T(TMP_REG1) | IMM(src1w), DR(TMP_REG1)));
! 1565: else {
! 1566: RESOLVE_IMM1();
! 1567: PTR_FAIL_IF(push_inst(compiler, (type <= SLJIT_C_LESS_EQUAL ? SLTU : SLT) | S(src2) | T(src1) | D(TMP_REG1), DR(TMP_REG1)));
! 1568: }
! 1569: type = (type == SLJIT_C_GREATER || type == SLJIT_C_SIG_GREATER) ? SLJIT_C_NOT_EQUAL : SLJIT_C_EQUAL;
! 1570: }
! 1571:
! 1572: jump->flags |= IS_BIT26_COND;
! 1573: PTR_FAIL_IF(push_inst(compiler, (type == SLJIT_C_EQUAL ? BNE : BEQ) | S(TMP_REG1) | TA(0) | JUMP_LENGTH, UNMOVABLE_INS));
! 1574: }
! 1575:
! 1576: PTR_FAIL_IF(emit_const(compiler, TMP_REG2, 0));
! 1577: PTR_FAIL_IF(push_inst(compiler, JR | S(TMP_REG2), UNMOVABLE_INS));
! 1578: jump->addr = compiler->size;
! 1579: PTR_FAIL_IF(push_inst(compiler, NOP, UNMOVABLE_INS));
! 1580: return jump;
! 1581: }
! 1582:
! 1583: #undef RESOLVE_IMM1
! 1584: #undef RESOLVE_IMM2
! 1585:
! 1586: SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, int type,
! 1587: int src1, sljit_w src1w,
! 1588: int src2, sljit_w src2w)
! 1589: {
! 1590: struct sljit_jump *jump;
! 1591: sljit_ins inst;
! 1592: int if_true;
! 1593:
! 1594: CHECK_ERROR_PTR();
! 1595: check_sljit_emit_fcmp(compiler, type, src1, src1w, src2, src2w);
! 1596:
! 1597: compiler->cache_arg = 0;
! 1598: compiler->cache_argw = 0;
! 1599:
! 1600: if (src1 > SLJIT_FLOAT_REG4) {
! 1601: PTR_FAIL_IF(emit_fpu_data_transfer(compiler, TMP_FREG1, 1, src1, src1w));
! 1602: src1 = TMP_FREG1;
! 1603: }
! 1604: if (src2 > SLJIT_FLOAT_REG4) {
! 1605: PTR_FAIL_IF(emit_fpu_data_transfer(compiler, TMP_FREG2, 1, src2, src2w));
! 1606: src2 = TMP_FREG2;
! 1607: }
! 1608:
! 1609: jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump));
! 1610: PTR_FAIL_IF(!jump);
! 1611: set_jump(jump, compiler, type & SLJIT_REWRITABLE_JUMP);
! 1612: jump->flags |= IS_BIT16_COND;
! 1613: type &= 0xff;
! 1614:
! 1615: switch (type) {
! 1616: case SLJIT_C_FLOAT_EQUAL:
! 1617: inst = C_UEQ_D;
! 1618: if_true = 1;
! 1619: break;
! 1620: case SLJIT_C_FLOAT_NOT_EQUAL:
! 1621: inst = C_UEQ_D;
! 1622: if_true = 0;
! 1623: break;
! 1624: case SLJIT_C_FLOAT_LESS:
! 1625: inst = C_ULT_D;
! 1626: if_true = 1;
! 1627: break;
! 1628: case SLJIT_C_FLOAT_GREATER_EQUAL:
! 1629: inst = C_ULT_D;
! 1630: if_true = 0;
! 1631: break;
! 1632: case SLJIT_C_FLOAT_GREATER:
! 1633: inst = C_ULE_D;
! 1634: if_true = 0;
! 1635: break;
! 1636: case SLJIT_C_FLOAT_LESS_EQUAL:
! 1637: inst = C_ULE_D;
! 1638: if_true = 1;
! 1639: break;
! 1640: case SLJIT_C_FLOAT_NAN:
! 1641: inst = C_UN_D;
! 1642: if_true = 1;
! 1643: break;
! 1644: case SLJIT_C_FLOAT_NOT_NAN:
! 1645: default: /* Make compilers happy. */
! 1646: inst = C_UN_D;
! 1647: if_true = 0;
! 1648: break;
! 1649: }
! 1650:
! 1651: PTR_FAIL_IF(push_inst(compiler, inst | FT(src2) | FS(src1), UNMOVABLE_INS));
! 1652: /* Intentionally the other opcode. */
! 1653: PTR_FAIL_IF(push_inst(compiler, (if_true ? BC1F : BC1T) | JUMP_LENGTH, UNMOVABLE_INS));
! 1654: PTR_FAIL_IF(emit_const(compiler, TMP_REG2, 0));
! 1655: PTR_FAIL_IF(push_inst(compiler, JR | S(TMP_REG2), UNMOVABLE_INS));
! 1656: jump->addr = compiler->size;
! 1657: PTR_FAIL_IF(push_inst(compiler, NOP, UNMOVABLE_INS));
! 1658: return jump;
! 1659: }
! 1660:
! 1661: #undef JUMP_LENGTH
! 1662: #undef BR_Z
! 1663: #undef BR_NZ
! 1664: #undef BR_T
! 1665: #undef BR_F
! 1666:
! 1667: SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_ijump(struct sljit_compiler *compiler, int type, int src, sljit_w srcw)
! 1668: {
! 1669: int src_r = TMP_REG2;
! 1670: struct sljit_jump *jump = NULL;
! 1671:
! 1672: CHECK_ERROR();
! 1673: check_sljit_emit_ijump(compiler, type, src, srcw);
! 1674:
! 1675: if (src >= SLJIT_TEMPORARY_REG1 && src <= SLJIT_NO_REGISTERS) {
! 1676: if (DR(src) != 4)
! 1677: src_r = src;
! 1678: else
! 1679: FAIL_IF(push_inst(compiler, ADDU_W | S(src) | TA(0) | D(TMP_REG2), DR(TMP_REG2)));
! 1680: }
! 1681:
! 1682: if (type >= SLJIT_CALL0) {
! 1683: SLJIT_ASSERT(DR(PIC_ADDR_REG) == 25 && PIC_ADDR_REG == TMP_REG2);
! 1684: if (src & (SLJIT_IMM | SLJIT_MEM)) {
! 1685: if (src & SLJIT_IMM)
! 1686: FAIL_IF(load_immediate(compiler, DR(PIC_ADDR_REG), srcw));
! 1687: else {
! 1688: SLJIT_ASSERT(src_r == TMP_REG2 && (src & SLJIT_MEM));
! 1689: FAIL_IF(emit_op(compiler, SLJIT_MOV, WORD_DATA, TMP_REG2, 0, TMP_REG1, 0, src, srcw));
! 1690: }
! 1691: FAIL_IF(push_inst(compiler, JALR | S(PIC_ADDR_REG) | DA(RETURN_ADDR_REG), UNMOVABLE_INS));
! 1692: /* We need an extra instruction in any case. */
! 1693: return push_inst(compiler, ADDU_W | S(SLJIT_TEMPORARY_REG1) | TA(0) | DA(4), UNMOVABLE_INS);
! 1694: }
! 1695:
! 1696: /* Register input. */
! 1697: if (type >= SLJIT_CALL1)
! 1698: FAIL_IF(push_inst(compiler, ADDU_W | S(SLJIT_TEMPORARY_REG1) | TA(0) | DA(4), 4));
! 1699: FAIL_IF(push_inst(compiler, JALR | S(src_r) | DA(RETURN_ADDR_REG), UNMOVABLE_INS));
! 1700: return push_inst(compiler, ADDU_W | S(src_r) | TA(0) | D(PIC_ADDR_REG), UNMOVABLE_INS);
! 1701: }
! 1702:
! 1703: if (src & SLJIT_IMM) {
! 1704: jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump));
! 1705: FAIL_IF(!jump);
! 1706: set_jump(jump, compiler, JUMP_ADDR | ((type >= SLJIT_FAST_CALL) ? IS_JAL : 0));
! 1707: jump->u.target = srcw;
! 1708:
! 1709: if (compiler->delay_slot != UNMOVABLE_INS)
! 1710: jump->flags |= IS_MOVABLE;
! 1711:
! 1712: FAIL_IF(emit_const(compiler, TMP_REG2, 0));
! 1713: }
! 1714: else if (src & SLJIT_MEM)
! 1715: FAIL_IF(emit_op(compiler, SLJIT_MOV, WORD_DATA, TMP_REG2, 0, TMP_REG1, 0, src, srcw));
! 1716:
! 1717: FAIL_IF(push_inst(compiler, JR | S(src_r), UNMOVABLE_INS));
! 1718: if (jump)
! 1719: jump->addr = compiler->size;
! 1720: FAIL_IF(push_inst(compiler, NOP, UNMOVABLE_INS));
! 1721: return SLJIT_SUCCESS;
! 1722: }
! 1723:
! 1724: SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_cond_value(struct sljit_compiler *compiler, int op, int dst, sljit_w dstw, int type)
! 1725: {
! 1726: int sugg_dst_ar, dst_ar;
! 1727:
! 1728: CHECK_ERROR();
! 1729: check_sljit_emit_cond_value(compiler, op, dst, dstw, type);
! 1730:
! 1731: if (dst == SLJIT_UNUSED)
! 1732: return SLJIT_SUCCESS;
! 1733:
! 1734: sugg_dst_ar = DR((op == SLJIT_MOV && dst >= SLJIT_TEMPORARY_REG1 && dst <= SLJIT_NO_REGISTERS) ? dst : TMP_REG2);
! 1735:
! 1736: switch (type) {
! 1737: case SLJIT_C_EQUAL:
! 1738: case SLJIT_C_NOT_EQUAL:
! 1739: FAIL_IF(push_inst(compiler, SLTIU | SA(EQUAL_FLAG) | TA(sugg_dst_ar) | IMM(1), sugg_dst_ar));
! 1740: dst_ar = sugg_dst_ar;
! 1741: break;
! 1742: case SLJIT_C_LESS:
! 1743: case SLJIT_C_GREATER_EQUAL:
! 1744: case SLJIT_C_FLOAT_LESS:
! 1745: case SLJIT_C_FLOAT_GREATER_EQUAL:
! 1746: dst_ar = ULESS_FLAG;
! 1747: break;
! 1748: case SLJIT_C_GREATER:
! 1749: case SLJIT_C_LESS_EQUAL:
! 1750: case SLJIT_C_FLOAT_GREATER:
! 1751: case SLJIT_C_FLOAT_LESS_EQUAL:
! 1752: dst_ar = UGREATER_FLAG;
! 1753: break;
! 1754: case SLJIT_C_SIG_LESS:
! 1755: case SLJIT_C_SIG_GREATER_EQUAL:
! 1756: dst_ar = LESS_FLAG;
! 1757: break;
! 1758: case SLJIT_C_SIG_GREATER:
! 1759: case SLJIT_C_SIG_LESS_EQUAL:
! 1760: dst_ar = GREATER_FLAG;
! 1761: break;
! 1762: case SLJIT_C_OVERFLOW:
! 1763: case SLJIT_C_NOT_OVERFLOW:
! 1764: dst_ar = OVERFLOW_FLAG;
! 1765: break;
! 1766: case SLJIT_C_MUL_OVERFLOW:
! 1767: case SLJIT_C_MUL_NOT_OVERFLOW:
! 1768: FAIL_IF(push_inst(compiler, SLTIU | SA(OVERFLOW_FLAG) | TA(sugg_dst_ar) | IMM(1), sugg_dst_ar));
! 1769: dst_ar = sugg_dst_ar;
! 1770: type ^= 0x1; /* Flip type bit for the XORI below. */
! 1771: break;
! 1772: case SLJIT_C_FLOAT_EQUAL:
! 1773: case SLJIT_C_FLOAT_NOT_EQUAL:
! 1774: dst_ar = EQUAL_FLAG;
! 1775: break;
! 1776:
! 1777: case SLJIT_C_FLOAT_NAN:
! 1778: case SLJIT_C_FLOAT_NOT_NAN:
! 1779: FAIL_IF(push_inst(compiler, CFC1 | TA(sugg_dst_ar) | DA(FCSR_REG), sugg_dst_ar));
! 1780: FAIL_IF(push_inst(compiler, SRL | TA(sugg_dst_ar) | DA(sugg_dst_ar) | SH_IMM(23), sugg_dst_ar));
! 1781: FAIL_IF(push_inst(compiler, ANDI | SA(sugg_dst_ar) | TA(sugg_dst_ar) | IMM(1), sugg_dst_ar));
! 1782: dst_ar = sugg_dst_ar;
! 1783: break;
! 1784:
! 1785: default:
! 1786: SLJIT_ASSERT_STOP();
! 1787: dst_ar = sugg_dst_ar;
! 1788: break;
! 1789: }
! 1790:
! 1791: if (type & 0x1) {
! 1792: FAIL_IF(push_inst(compiler, XORI | SA(dst_ar) | TA(sugg_dst_ar) | IMM(1), sugg_dst_ar));
! 1793: dst_ar = sugg_dst_ar;
! 1794: }
! 1795:
! 1796: if (GET_OPCODE(op) == SLJIT_OR) {
! 1797: if (DR(TMP_REG2) != dst_ar)
! 1798: FAIL_IF(push_inst(compiler, ADDU_W | SA(dst_ar) | TA(0) | D(TMP_REG2), DR(TMP_REG2)));
! 1799: return emit_op(compiler, op, CUMULATIVE_OP | LOGICAL_OP | IMM_OP, dst, dstw, dst, dstw, TMP_REG2, 0);
! 1800: }
! 1801:
! 1802: if (dst & SLJIT_MEM)
! 1803: return emit_op_mem(compiler, WORD_DATA, dst_ar, dst, dstw);
! 1804:
! 1805: if (sugg_dst_ar != dst_ar)
! 1806: return push_inst(compiler, ADDU_W | SA(dst_ar) | TA(0) | DA(sugg_dst_ar), sugg_dst_ar);
! 1807: return SLJIT_SUCCESS;
! 1808: }
! 1809:
! 1810: SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, int dst, sljit_w dstw, sljit_w init_value)
! 1811: {
! 1812: struct sljit_const *const_;
! 1813: int reg;
! 1814:
! 1815: CHECK_ERROR_PTR();
! 1816: check_sljit_emit_const(compiler, dst, dstw, init_value);
! 1817:
! 1818: const_ = (struct sljit_const*)ensure_abuf(compiler, sizeof(struct sljit_const));
! 1819: PTR_FAIL_IF(!const_);
! 1820: set_const(const_, compiler);
! 1821:
! 1822: reg = (dst >= SLJIT_TEMPORARY_REG1 && dst <= SLJIT_NO_REGISTERS) ? dst : TMP_REG2;
! 1823:
! 1824: PTR_FAIL_IF(emit_const(compiler, reg, init_value));
! 1825:
! 1826: if (dst & SLJIT_MEM)
! 1827: PTR_FAIL_IF(emit_op(compiler, SLJIT_MOV, WORD_DATA, dst, dstw, TMP_REG1, 0, TMP_REG2, 0));
! 1828: return const_;
! 1829: }
E-mail: