/[pcre]/code/trunk/sljit/sljitNativePPC_32.c
ViewVC logotype

Contents of /code/trunk/sljit/sljitNativePPC_32.c

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.5