Annotation of embedaddon/pcre/sljit/sljitNativePPC_32.c, revision 1.1

1.1     ! misho       1: /*
        !             2:  *    Stack-less Just-In-Time compiler
        !             3:  *
        !             4:  *    Copyright 2009-2010 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: /* ppc 32-bit arch dependent functions. */
        !            28: 
        !            29: static int load_immediate(struct sljit_compiler *compiler, int reg, sljit_w imm)
        !            30: {
        !            31:        if (imm <= SIMM_MAX && imm >= SIMM_MIN)
        !            32:                return push_inst(compiler, ADDI | D(reg) | A(0) | IMM(imm));
        !            33: 
        !            34:        FAIL_IF(push_inst(compiler, ADDIS | D(reg) | A(0) | IMM(imm >> 16)));
        !            35:        return (imm & 0xffff) ? push_inst(compiler, ORI | S(reg) | A(reg) | IMM(imm)) : SLJIT_SUCCESS;
        !            36: }
        !            37: 
        !            38: #define INS_CLEAR_LEFT(dst, src, from) \
        !            39:        (RLWINM | S(src) | A(dst) | ((from) << 6) | (31 << 1))
        !            40: 
        !            41: static SLJIT_INLINE int emit_single_op(struct sljit_compiler *compiler, int op, int flags,
        !            42:        int dst, int src1, int src2)
        !            43: {
        !            44:        switch (op) {
        !            45:        case SLJIT_ADD:
        !            46:                if (flags & ALT_FORM1) {
        !            47:                        SLJIT_ASSERT(src2 == TMP_REG2);
        !            48:                        return push_inst(compiler, ADDI | D(dst) | A(src1) | compiler->imm);
        !            49:                }
        !            50:                if (flags & ALT_FORM2) {
        !            51:                        SLJIT_ASSERT(src2 == TMP_REG2);
        !            52:                        return push_inst(compiler, ADDIS | D(dst) | A(src1) | compiler->imm);
        !            53:                }
        !            54:                if (flags & ALT_FORM3) {
        !            55:                        SLJIT_ASSERT(src2 == TMP_REG2);
        !            56:                        return push_inst(compiler, ADDIC | D(dst) | A(src1) | compiler->imm);
        !            57:                }
        !            58:                if (!(flags & ALT_SET_FLAGS))
        !            59:                        return push_inst(compiler, ADD | D(dst) | A(src1) | B(src2));
        !            60:                return push_inst(compiler, ADDC | OERC(ALT_SET_FLAGS) | D(dst) | A(src1) | B(src2));
        !            61: 
        !            62:        case SLJIT_ADDC:
        !            63:                if (flags & ALT_FORM1) {
        !            64:                        FAIL_IF(push_inst(compiler, MFXER | S(0)));
        !            65:                        FAIL_IF(push_inst(compiler, ADDE | D(dst) | A(src1) | B(src2)));
        !            66:                        return push_inst(compiler, MTXER | S(0));
        !            67:                }
        !            68:                return push_inst(compiler, ADDE | D(dst) | A(src1) | B(src2));
        !            69: 
        !            70:        case SLJIT_SUB:
        !            71:                if (flags & ALT_FORM1) {
        !            72:                        SLJIT_ASSERT(src2 == TMP_REG2);
        !            73:                        return push_inst(compiler, SUBFIC | D(dst) | A(src1) | compiler->imm);
        !            74:                }
        !            75:                if (flags & ALT_FORM2) {
        !            76:                        SLJIT_ASSERT(src2 == TMP_REG2);
        !            77:                        return push_inst(compiler, CMPI | CRD(0) | A(src1) | compiler->imm);
        !            78:                }
        !            79:                if (flags & ALT_FORM3) {
        !            80:                        SLJIT_ASSERT(src2 == TMP_REG2);
        !            81:                        return push_inst(compiler, CMPLI | CRD(4) | A(src1) | compiler->imm);
        !            82:                }
        !            83:                if (flags & ALT_FORM4)
        !            84:                        return push_inst(compiler, CMPL | CRD(4) | A(src1) | B(src2));
        !            85:                if (!(flags & ALT_SET_FLAGS))
        !            86:                        return push_inst(compiler, SUBF | D(dst) | A(src2) | B(src1));
        !            87:                if (flags & ALT_FORM5)
        !            88:                        FAIL_IF(push_inst(compiler, CMPL | CRD(4) | A(src1) | B(src2)));
        !            89:                return push_inst(compiler, SUBFC | OERC(ALT_SET_FLAGS) | D(dst) | A(src2) | B(src1));
        !            90: 
        !            91:        case SLJIT_SUBC:
        !            92:                if (flags & ALT_FORM1) {
        !            93:                        FAIL_IF(push_inst(compiler, MFXER | S(0)));
        !            94:                        FAIL_IF(push_inst(compiler, SUBFE | D(dst) | A(src2) | B(src1)));
        !            95:                        return push_inst(compiler, MTXER | S(0));
        !            96:                }
        !            97:                return push_inst(compiler, SUBFE | D(dst) | A(src2) | B(src1));
        !            98: 
        !            99:        case SLJIT_MUL:
        !           100:                if (flags & ALT_FORM1) {
        !           101:                        SLJIT_ASSERT(src2 == TMP_REG2);
        !           102:                        return push_inst(compiler, MULLI | D(dst) | A(src1) | compiler->imm);
        !           103:                }
        !           104:                return push_inst(compiler, MULLW | OERC(flags) | D(dst) | A(src2) | B(src1));
        !           105: 
        !           106:        case SLJIT_AND:
        !           107:                if (flags & ALT_FORM1) {
        !           108:                        SLJIT_ASSERT(src2 == TMP_REG2);
        !           109:                        return push_inst(compiler, ANDI | S(src1) | A(dst) | compiler->imm);
        !           110:                }
        !           111:                if (flags & ALT_FORM2) {
        !           112:                        SLJIT_ASSERT(src2 == TMP_REG2);
        !           113:                        return push_inst(compiler, ANDIS | S(src1) | A(dst) | compiler->imm);
        !           114:                }
        !           115:                return push_inst(compiler, AND | RC(flags) | S(src1) | A(dst) | B(src2));
        !           116: 
        !           117:        case SLJIT_OR:
        !           118:                if (flags & ALT_FORM1) {
        !           119:                        SLJIT_ASSERT(src2 == TMP_REG2);
        !           120:                        return push_inst(compiler, ORI | S(src1) | A(dst) | compiler->imm);
        !           121:                }
        !           122:                if (flags & ALT_FORM2) {
        !           123:                        SLJIT_ASSERT(src2 == TMP_REG2);
        !           124:                        return push_inst(compiler, ORIS | S(src1) | A(dst) | compiler->imm);
        !           125:                }
        !           126:                if (flags & ALT_FORM3) {
        !           127:                        SLJIT_ASSERT(src2 == TMP_REG2);
        !           128:                        FAIL_IF(push_inst(compiler, ORI | S(src1) | A(dst) | IMM(compiler->imm)));
        !           129:                        return push_inst(compiler, ORIS | S(dst) | A(dst) | IMM(compiler->imm >> 16));
        !           130:                }
        !           131:                return push_inst(compiler, OR | RC(flags) | S(src1) | A(dst) | B(src2));
        !           132: 
        !           133:        case SLJIT_XOR:
        !           134:                if (flags & ALT_FORM1) {
        !           135:                        SLJIT_ASSERT(src2 == TMP_REG2);
        !           136:                        return push_inst(compiler, XORI | S(src1) | A(dst) | compiler->imm);
        !           137:                }
        !           138:                if (flags & ALT_FORM2) {
        !           139:                        SLJIT_ASSERT(src2 == TMP_REG2);
        !           140:                        return push_inst(compiler, XORIS | S(src1) | A(dst) | compiler->imm);
        !           141:                }
        !           142:                if (flags & ALT_FORM3) {
        !           143:                        SLJIT_ASSERT(src2 == TMP_REG2);
        !           144:                        FAIL_IF(push_inst(compiler, XORI | S(src1) | A(dst) | IMM(compiler->imm)));
        !           145:                        return push_inst(compiler, XORIS | S(dst) | A(dst) | IMM(compiler->imm >> 16));
        !           146:                }
        !           147:                return push_inst(compiler, XOR | RC(flags) | S(src1) | A(dst) | B(src2));
        !           148: 
        !           149:        case SLJIT_SHL:
        !           150:                if (flags & ALT_FORM1) {
        !           151:                        SLJIT_ASSERT(src2 == TMP_REG2);
        !           152:                        compiler->imm &= 0x1f;
        !           153:                        return push_inst(compiler, RLWINM | RC(flags) | S(src1) | A(dst) | (compiler->imm << 11) | ((31 - compiler->imm) << 1));
        !           154:                }
        !           155:                return push_inst(compiler, SLW | RC(flags) | S(src1) | A(dst) | B(src2));
        !           156: 
        !           157:        case SLJIT_LSHR:
        !           158:                if (flags & ALT_FORM1) {
        !           159:                        SLJIT_ASSERT(src2 == TMP_REG2);
        !           160:                        compiler->imm &= 0x1f;
        !           161:                        return push_inst(compiler, RLWINM | RC(flags) | S(src1) | A(dst) | (((32 - compiler->imm) & 0x1f) << 11) | (compiler->imm << 6) | (31 << 1));
        !           162:                }
        !           163:                return push_inst(compiler, SRW | RC(flags) | S(src1) | A(dst) | B(src2));
        !           164: 
        !           165:        case SLJIT_ASHR:
        !           166:                if (flags & ALT_FORM1) {
        !           167:                        SLJIT_ASSERT(src2 == TMP_REG2);
        !           168:                        compiler->imm &= 0x1f;
        !           169:                        return push_inst(compiler, SRAWI | RC(flags) | S(src1) | A(dst) | (compiler->imm << 11));
        !           170:                }
        !           171:                return push_inst(compiler, SRAW | RC(flags) | S(src1) | A(dst) | B(src2));
        !           172: 
        !           173:        case SLJIT_MOV:
        !           174:        case SLJIT_MOV_UI:
        !           175:        case SLJIT_MOV_SI:
        !           176:                SLJIT_ASSERT(src1 == TMP_REG1);
        !           177:                if (dst != src2)
        !           178:                        return push_inst(compiler, OR | S(src2) | A(dst) | B(src2));
        !           179:                return SLJIT_SUCCESS;
        !           180: 
        !           181:        case SLJIT_MOV_UB:
        !           182:        case SLJIT_MOV_SB:
        !           183:                SLJIT_ASSERT(src1 == TMP_REG1);
        !           184:                if ((flags & (REG_DEST | REG2_SOURCE)) == (REG_DEST | REG2_SOURCE)) {
        !           185:                        if (op == SLJIT_MOV_SB)
        !           186:                                return push_inst(compiler, EXTSB | S(src2) | A(dst));
        !           187:                        return push_inst(compiler, INS_CLEAR_LEFT(dst, src2, 24));
        !           188:                }
        !           189:                else if ((flags & REG_DEST) && op == SLJIT_MOV_SB)
        !           190:                        return push_inst(compiler, EXTSB | S(src2) | A(dst));
        !           191:                else if (dst != src2)
        !           192:                        SLJIT_ASSERT_STOP();
        !           193:                return SLJIT_SUCCESS;
        !           194: 
        !           195:        case SLJIT_MOV_UH:
        !           196:        case SLJIT_MOV_SH:
        !           197:                SLJIT_ASSERT(src1 == TMP_REG1);
        !           198:                if ((flags & (REG_DEST | REG2_SOURCE)) == (REG_DEST | REG2_SOURCE)) {
        !           199:                        if (op == SLJIT_MOV_SH)
        !           200:                                return push_inst(compiler, EXTSH | S(src2) | A(dst));
        !           201:                        return push_inst(compiler, INS_CLEAR_LEFT(dst, src2, 16));
        !           202:                }
        !           203:                else if (dst != src2)
        !           204:                        SLJIT_ASSERT_STOP();
        !           205:                return SLJIT_SUCCESS;
        !           206: 
        !           207:        case SLJIT_NOT:
        !           208:                SLJIT_ASSERT(src1 == TMP_REG1);
        !           209:                return push_inst(compiler, NOR | RC(flags) | S(src2) | A(dst) | B(src2));
        !           210: 
        !           211:        case SLJIT_NEG:
        !           212:                SLJIT_ASSERT(src1 == TMP_REG1);
        !           213:                return push_inst(compiler, NEG | OERC(flags) | D(dst) | A(src2));
        !           214: 
        !           215:        case SLJIT_CLZ:
        !           216:                SLJIT_ASSERT(src1 == TMP_REG1);
        !           217:                return push_inst(compiler, CNTLZW | RC(flags) | S(src2) | A(dst));
        !           218:        }
        !           219: 
        !           220:        SLJIT_ASSERT_STOP();
        !           221:        return SLJIT_SUCCESS;
        !           222: }
        !           223: 
        !           224: static SLJIT_INLINE int emit_const(struct sljit_compiler *compiler, int reg, sljit_w init_value)
        !           225: {
        !           226:        FAIL_IF(push_inst(compiler, ADDIS | D(reg) | A(0) | IMM(init_value >> 16)));
        !           227:        return push_inst(compiler, ORI | S(reg) | A(reg) | IMM(init_value));
        !           228: }
        !           229: 
        !           230: SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_addr)
        !           231: {
        !           232:        sljit_ins *inst = (sljit_ins*)addr;
        !           233: 
        !           234:        inst[0] = (inst[0] & 0xffff0000) | ((new_addr >> 16) & 0xffff);
        !           235:        inst[1] = (inst[1] & 0xffff0000) | (new_addr & 0xffff);
        !           236:        SLJIT_CACHE_FLUSH(inst, inst + 2);
        !           237: }
        !           238: 
        !           239: SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_w new_constant)
        !           240: {
        !           241:        sljit_ins *inst = (sljit_ins*)addr;
        !           242: 
        !           243:        inst[0] = (inst[0] & 0xffff0000) | ((new_constant >> 16) & 0xffff);
        !           244:        inst[1] = (inst[1] & 0xffff0000) | (new_constant & 0xffff);
        !           245:        SLJIT_CACHE_FLUSH(inst, inst + 2);
        !           246: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>