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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1149 - (show annotations)
Sat Oct 20 21:33:38 2012 UTC (6 years, 11 months ago) by zherczeg
File MIME type: text/plain
File size: 7541 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 static int load_immediate(struct sljit_compiler *compiler, int dst, sljit_w imm)
28 {
29 if (imm <= SIMM_MAX && imm >= SIMM_MIN)
30 return push_inst(compiler, OR | D(dst) | S1(0) | IMM(imm), DR(dst));
31
32 FAIL_IF(push_inst(compiler, SETHI | D(dst) | ((imm >> 10) & 0x3fffff), DR(dst)));
33 return (imm & 0x3ff) ? push_inst(compiler, OR | D(dst) | S1(dst) | IMM_ARG | (imm & 0x3ff), DR(dst)) : SLJIT_SUCCESS;
34 }
35
36 #define ARG2(flags, src2) ((flags & SRC2_IMM) ? IMM(src2) : S2(src2))
37
38 static SLJIT_INLINE int emit_single_op(struct sljit_compiler *compiler, int op, int flags,
39 int dst, int src1, sljit_w src2)
40 {
41 SLJIT_COMPILE_ASSERT(ICC_IS_SET == SET_FLAGS, icc_is_set_and_set_flags_must_be_the_same);
42
43 switch (op) {
44 case SLJIT_MOV:
45 case SLJIT_MOV_UI:
46 case SLJIT_MOV_SI:
47 SLJIT_ASSERT(src1 == TMP_REG1 && !(flags & SRC2_IMM));
48 if (dst != src2)
49 return push_inst(compiler, OR | D(dst) | S1(0) | S2(src2), DR(dst));
50 return SLJIT_SUCCESS;
51
52 case SLJIT_MOV_UB:
53 case SLJIT_MOV_SB:
54 SLJIT_ASSERT(src1 == TMP_REG1 && !(flags & SRC2_IMM));
55 if ((flags & (REG_DEST | REG2_SOURCE)) == (REG_DEST | REG2_SOURCE)) {
56 if (op == SLJIT_MOV_UB)
57 return push_inst(compiler, AND | D(dst) | S1(src2) | IMM(0xff), DR(dst));
58 FAIL_IF(push_inst(compiler, SLL | D(dst) | S1(src2) | IMM(24), DR(dst)));
59 return push_inst(compiler, SRA | D(dst) | S1(dst) | IMM(24), DR(dst));
60 }
61 else if (dst != src2)
62 SLJIT_ASSERT_STOP();
63 return SLJIT_SUCCESS;
64
65 case SLJIT_MOV_UH:
66 case SLJIT_MOV_SH:
67 SLJIT_ASSERT(src1 == TMP_REG1 && !(flags & SRC2_IMM));
68 if ((flags & (REG_DEST | REG2_SOURCE)) == (REG_DEST | REG2_SOURCE)) {
69 FAIL_IF(push_inst(compiler, SLL | D(dst) | S1(src2) | IMM(16), DR(dst)));
70 return push_inst(compiler, (op == SLJIT_MOV_SH ? SRA : SRL) | D(dst) | S1(dst) | IMM(16), DR(dst));
71 }
72 else if (dst != src2)
73 SLJIT_ASSERT_STOP();
74 return SLJIT_SUCCESS;
75
76 case SLJIT_NOT:
77 SLJIT_ASSERT(src1 == TMP_REG1 && !(flags & SRC2_IMM));
78 return push_inst(compiler, XNOR | (flags & SET_FLAGS) | D(dst) | S1(0) | S2(src2), DR(dst) | (flags & SET_FLAGS));
79
80 case SLJIT_CLZ:
81 SLJIT_ASSERT(src1 == TMP_REG1 && !(flags & SRC2_IMM));
82 /* sparc 32 does not support SLJIT_KEEP_FLAGS. Not sure I can fix this. */
83 FAIL_IF(push_inst(compiler, SUB | SET_FLAGS | D(0) | S1(src2) | S2(0), SET_FLAGS));
84 FAIL_IF(push_inst(compiler, OR | D(TMP_REG1) | S1(0) | S2(src2), DR(TMP_REG1)));
85 FAIL_IF(push_inst(compiler, BICC | DA(0x1) | (7 & DISP_MASK), UNMOVABLE_INS));
86 FAIL_IF(push_inst(compiler, OR | (flags & SET_FLAGS) | D(dst) | S1(0) | IMM(32), UNMOVABLE_INS | (flags & SET_FLAGS)));
87 FAIL_IF(push_inst(compiler, OR | D(dst) | S1(0) | IMM(-1), DR(dst)));
88
89 /* Loop. */
90 FAIL_IF(push_inst(compiler, SUB | SET_FLAGS | D(0) | S1(TMP_REG1) | S2(0), SET_FLAGS));
91 FAIL_IF(push_inst(compiler, SLL | D(TMP_REG1) | S1(TMP_REG1) | IMM(1), DR(TMP_REG1)));
92 FAIL_IF(push_inst(compiler, BICC | DA(0xe) | (-2 & DISP_MASK), UNMOVABLE_INS));
93 return push_inst(compiler, ADD | (flags & SET_FLAGS) | D(dst) | S1(dst) | IMM(1), UNMOVABLE_INS | (flags & SET_FLAGS));
94
95 case SLJIT_ADD:
96 return push_inst(compiler, ADD | (flags & SET_FLAGS) | D(dst) | S1(src1) | ARG2(flags, src2), DR(dst) | (flags & SET_FLAGS));
97
98 case SLJIT_ADDC:
99 return push_inst(compiler, ADDC | (flags & SET_FLAGS) | D(dst) | S1(src1) | ARG2(flags, src2), DR(dst) | (flags & SET_FLAGS));
100
101 case SLJIT_SUB:
102 return push_inst(compiler, SUB | (flags & SET_FLAGS) | D(dst) | S1(src1) | ARG2(flags, src2), DR(dst) | (flags & SET_FLAGS));
103
104 case SLJIT_SUBC:
105 return push_inst(compiler, SUBC | (flags & SET_FLAGS) | D(dst) | S1(src1) | ARG2(flags, src2), DR(dst) | (flags & SET_FLAGS));
106
107 case SLJIT_MUL:
108 FAIL_IF(push_inst(compiler, SMUL | D(dst) | S1(src1) | ARG2(flags, src2), DR(dst)));
109 if (!(flags & SET_FLAGS))
110 return SLJIT_SUCCESS;
111 FAIL_IF(push_inst(compiler, SRA | D(TMP_REG1) | S1(dst) | IMM(31), DR(TMP_REG1)));
112 FAIL_IF(push_inst(compiler, RDY | D(TMP_REG4), DR(TMP_REG4)));
113 return push_inst(compiler, SUB | SET_FLAGS | D(0) | S1(TMP_REG1) | S2(TMP_REG4), MOVABLE_INS | SET_FLAGS);
114
115 case SLJIT_AND:
116 return push_inst(compiler, AND | (flags & SET_FLAGS) | D(dst) | S1(src1) | ARG2(flags, src2), DR(dst) | (flags & SET_FLAGS));
117
118 case SLJIT_OR:
119 return push_inst(compiler, OR | (flags & SET_FLAGS) | D(dst) | S1(src1) | ARG2(flags, src2), DR(dst) | (flags & SET_FLAGS));
120
121 case SLJIT_XOR:
122 return push_inst(compiler, XOR | (flags & SET_FLAGS) | D(dst) | S1(src1) | ARG2(flags, src2), DR(dst) | (flags & SET_FLAGS));
123
124 case SLJIT_SHL:
125 FAIL_IF(push_inst(compiler, SLL | D(dst) | S1(src1) | ARG2(flags, src2), DR(dst)));
126 return !(flags & SET_FLAGS) ? SLJIT_SUCCESS : push_inst(compiler, SUB | SET_FLAGS | D(0) | S1(dst) | S2(0), SET_FLAGS);
127
128 case SLJIT_LSHR:
129 FAIL_IF(push_inst(compiler, SRL | D(dst) | S1(src1) | ARG2(flags, src2), DR(dst)));
130 return !(flags & SET_FLAGS) ? SLJIT_SUCCESS : push_inst(compiler, SUB | SET_FLAGS | D(0) | S1(dst) | S2(0), SET_FLAGS);
131
132 case SLJIT_ASHR:
133 FAIL_IF(push_inst(compiler, SRA | D(dst) | S1(src1) | ARG2(flags, src2), DR(dst)));
134 return !(flags & SET_FLAGS) ? SLJIT_SUCCESS : push_inst(compiler, SUB | SET_FLAGS | D(0) | S1(dst) | S2(0), SET_FLAGS);
135 }
136
137 SLJIT_ASSERT_STOP();
138 return SLJIT_SUCCESS;
139 }
140
141 static SLJIT_INLINE int emit_const(struct sljit_compiler *compiler, int dst, sljit_w init_value)
142 {
143 FAIL_IF(push_inst(compiler, SETHI | D(dst) | ((init_value >> 10) & 0x3fffff), DR(dst)));
144 return push_inst(compiler, OR | D(dst) | S1(dst) | IMM_ARG | (init_value & 0x3ff), DR(dst));
145 }
146
147 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_addr)
148 {
149 sljit_ins *inst = (sljit_ins*)addr;
150
151 inst[0] = (inst[0] & 0xffc00000) | ((new_addr >> 10) & 0x3fffff);
152 inst[1] = (inst[1] & 0xfffffc00) | (new_addr & 0x3ff);
153 SLJIT_CACHE_FLUSH(inst, inst + 2);
154 }
155
156 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_w new_constant)
157 {
158 sljit_ins *inst = (sljit_ins*)addr;
159
160 inst[0] = (inst[0] & 0xffc00000) | ((new_constant >> 10) & 0x3fffff);
161 inst[1] = (inst[1] & 0xfffffc00) | (new_constant & 0x3ff);
162 SLJIT_CACHE_FLUSH(inst, inst + 2);
163 }

  ViewVC Help
Powered by ViewVC 1.1.5