sljitLir.c revision 1.5.16.1 1 1.5.16.1 pgoyette /* $NetBSD: sljitLir.c,v 1.5.16.1 2019/01/26 22:00:25 pgoyette Exp $ */
2 1.4 alnsn
3 1.1 alnsn /*
4 1.1 alnsn * Stack-less Just-In-Time compiler
5 1.1 alnsn *
6 1.5.16.1 pgoyette * Copyright Zoltan Herczeg (hzmester (at) freemail.hu). All rights reserved.
7 1.1 alnsn *
8 1.1 alnsn * Redistribution and use in source and binary forms, with or without modification, are
9 1.1 alnsn * permitted provided that the following conditions are met:
10 1.1 alnsn *
11 1.1 alnsn * 1. Redistributions of source code must retain the above copyright notice, this list of
12 1.1 alnsn * conditions and the following disclaimer.
13 1.1 alnsn *
14 1.1 alnsn * 2. Redistributions in binary form must reproduce the above copyright notice, this list
15 1.1 alnsn * of conditions and the following disclaimer in the documentation and/or other materials
16 1.1 alnsn * provided with the distribution.
17 1.1 alnsn *
18 1.1 alnsn * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
19 1.1 alnsn * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1 alnsn * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21 1.1 alnsn * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.1 alnsn * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
23 1.1 alnsn * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 1.1 alnsn * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 1.1 alnsn * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 1.1 alnsn * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 1.1 alnsn */
28 1.1 alnsn
29 1.1 alnsn #include "sljitLir.h"
30 1.1 alnsn
31 1.5.16.1 pgoyette #if !(defined SLJIT_STD_MACROS_DEFINED && SLJIT_STD_MACROS_DEFINED)
32 1.5.16.1 pgoyette
33 1.5.16.1 pgoyette #ifndef _KERNEL
34 1.5.16.1 pgoyette /* These libraries are needed for the macros below. */
35 1.5.16.1 pgoyette #include <stdlib.h>
36 1.5.16.1 pgoyette #include <string.h>
37 1.5.16.1 pgoyette #endif
38 1.5.16.1 pgoyette
39 1.5.16.1 pgoyette #endif /* SLJIT_STD_MACROS_DEFINED */
40 1.5.16.1 pgoyette
41 1.1 alnsn #define CHECK_ERROR() \
42 1.1 alnsn do { \
43 1.1 alnsn if (SLJIT_UNLIKELY(compiler->error)) \
44 1.1 alnsn return compiler->error; \
45 1.1 alnsn } while (0)
46 1.1 alnsn
47 1.1 alnsn #define CHECK_ERROR_PTR() \
48 1.1 alnsn do { \
49 1.1 alnsn if (SLJIT_UNLIKELY(compiler->error)) \
50 1.1 alnsn return NULL; \
51 1.1 alnsn } while (0)
52 1.1 alnsn
53 1.1 alnsn #define FAIL_IF(expr) \
54 1.1 alnsn do { \
55 1.1 alnsn if (SLJIT_UNLIKELY(expr)) \
56 1.1 alnsn return compiler->error; \
57 1.1 alnsn } while (0)
58 1.1 alnsn
59 1.1 alnsn #define PTR_FAIL_IF(expr) \
60 1.1 alnsn do { \
61 1.1 alnsn if (SLJIT_UNLIKELY(expr)) \
62 1.1 alnsn return NULL; \
63 1.1 alnsn } while (0)
64 1.1 alnsn
65 1.1 alnsn #define FAIL_IF_NULL(ptr) \
66 1.1 alnsn do { \
67 1.1 alnsn if (SLJIT_UNLIKELY(!(ptr))) { \
68 1.1 alnsn compiler->error = SLJIT_ERR_ALLOC_FAILED; \
69 1.1 alnsn return SLJIT_ERR_ALLOC_FAILED; \
70 1.1 alnsn } \
71 1.1 alnsn } while (0)
72 1.1 alnsn
73 1.1 alnsn #define PTR_FAIL_IF_NULL(ptr) \
74 1.1 alnsn do { \
75 1.1 alnsn if (SLJIT_UNLIKELY(!(ptr))) { \
76 1.1 alnsn compiler->error = SLJIT_ERR_ALLOC_FAILED; \
77 1.1 alnsn return NULL; \
78 1.1 alnsn } \
79 1.1 alnsn } while (0)
80 1.1 alnsn
81 1.1 alnsn #define PTR_FAIL_WITH_EXEC_IF(ptr) \
82 1.1 alnsn do { \
83 1.1 alnsn if (SLJIT_UNLIKELY(!(ptr))) { \
84 1.1 alnsn compiler->error = SLJIT_ERR_EX_ALLOC_FAILED; \
85 1.1 alnsn return NULL; \
86 1.1 alnsn } \
87 1.1 alnsn } while (0)
88 1.1 alnsn
89 1.1 alnsn #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
90 1.1 alnsn
91 1.5.16.1 pgoyette #define VARIABLE_FLAG_SHIFT (10)
92 1.5.16.1 pgoyette #define VARIABLE_FLAG_MASK (0x3f << VARIABLE_FLAG_SHIFT)
93 1.5.16.1 pgoyette #define GET_FLAG_TYPE(op) ((op) >> VARIABLE_FLAG_SHIFT)
94 1.5.16.1 pgoyette
95 1.1 alnsn #define GET_OPCODE(op) \
96 1.5.16.1 pgoyette ((op) & ~(SLJIT_I32_OP | SLJIT_SET_Z | VARIABLE_FLAG_MASK))
97 1.1 alnsn
98 1.5.16.1 pgoyette #define HAS_FLAGS(op) \
99 1.5.16.1 pgoyette ((op) & (SLJIT_SET_Z | VARIABLE_FLAG_MASK))
100 1.1 alnsn
101 1.1 alnsn #define GET_ALL_FLAGS(op) \
102 1.5.16.1 pgoyette ((op) & (SLJIT_I32_OP | SLJIT_SET_Z | VARIABLE_FLAG_MASK))
103 1.3 alnsn
104 1.3 alnsn #define TYPE_CAST_NEEDED(op) \
105 1.5 alnsn (((op) >= SLJIT_MOV_U8 && (op) <= SLJIT_MOV_S16) || ((op) >= SLJIT_MOVU_U8 && (op) <= SLJIT_MOVU_S16))
106 1.1 alnsn
107 1.1 alnsn #define BUF_SIZE 4096
108 1.1 alnsn
109 1.1 alnsn #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
110 1.1 alnsn #define ABUF_SIZE 2048
111 1.1 alnsn #else
112 1.1 alnsn #define ABUF_SIZE 4096
113 1.1 alnsn #endif
114 1.1 alnsn
115 1.3 alnsn /* Parameter parsing. */
116 1.3 alnsn #define REG_MASK 0x3f
117 1.3 alnsn #define OFFS_REG(reg) (((reg) >> 8) & REG_MASK)
118 1.3 alnsn #define OFFS_REG_MASK (REG_MASK << 8)
119 1.3 alnsn #define TO_OFFS_REG(reg) ((reg) << 8)
120 1.3 alnsn /* When reg cannot be unused. */
121 1.3 alnsn #define FAST_IS_REG(reg) ((reg) <= REG_MASK)
122 1.3 alnsn /* When reg can be unused. */
123 1.3 alnsn #define SLOW_IS_REG(reg) ((reg) > 0 && (reg) <= REG_MASK)
124 1.3 alnsn
125 1.1 alnsn /* Jump flags. */
126 1.1 alnsn #define JUMP_LABEL 0x1
127 1.1 alnsn #define JUMP_ADDR 0x2
128 1.1 alnsn /* SLJIT_REWRITABLE_JUMP is 0x1000. */
129 1.1 alnsn
130 1.5 alnsn #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
131 1.3 alnsn # define PATCH_MB 0x4
132 1.3 alnsn # define PATCH_MW 0x8
133 1.1 alnsn #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
134 1.3 alnsn # define PATCH_MD 0x10
135 1.1 alnsn #endif
136 1.1 alnsn #endif
137 1.1 alnsn
138 1.1 alnsn #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
139 1.3 alnsn # define IS_BL 0x4
140 1.3 alnsn # define PATCH_B 0x8
141 1.1 alnsn #endif
142 1.1 alnsn
143 1.1 alnsn #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
144 1.3 alnsn # define CPOOL_SIZE 512
145 1.1 alnsn #endif
146 1.1 alnsn
147 1.1 alnsn #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
148 1.3 alnsn # define IS_COND 0x04
149 1.3 alnsn # define IS_BL 0x08
150 1.1 alnsn /* conditional + imm8 */
151 1.3 alnsn # define PATCH_TYPE1 0x10
152 1.1 alnsn /* conditional + imm20 */
153 1.3 alnsn # define PATCH_TYPE2 0x20
154 1.1 alnsn /* IT + imm24 */
155 1.3 alnsn # define PATCH_TYPE3 0x30
156 1.1 alnsn /* imm11 */
157 1.3 alnsn # define PATCH_TYPE4 0x40
158 1.1 alnsn /* imm24 */
159 1.3 alnsn # define PATCH_TYPE5 0x50
160 1.1 alnsn /* BL + imm24 */
161 1.3 alnsn # define PATCH_BL 0x60
162 1.1 alnsn /* 0xf00 cc code for branches */
163 1.1 alnsn #endif
164 1.1 alnsn
165 1.3 alnsn #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
166 1.3 alnsn # define IS_COND 0x004
167 1.3 alnsn # define IS_CBZ 0x008
168 1.3 alnsn # define IS_BL 0x010
169 1.3 alnsn # define PATCH_B 0x020
170 1.3 alnsn # define PATCH_COND 0x040
171 1.3 alnsn # define PATCH_ABS48 0x080
172 1.3 alnsn # define PATCH_ABS64 0x100
173 1.3 alnsn #endif
174 1.3 alnsn
175 1.5 alnsn #if (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
176 1.3 alnsn # define IS_COND 0x004
177 1.3 alnsn # define IS_CALL 0x008
178 1.3 alnsn # define PATCH_B 0x010
179 1.3 alnsn # define PATCH_ABS_B 0x020
180 1.3 alnsn #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
181 1.3 alnsn # define PATCH_ABS32 0x040
182 1.3 alnsn # define PATCH_ABS48 0x080
183 1.3 alnsn #endif
184 1.3 alnsn # define REMOVE_COND 0x100
185 1.1 alnsn #endif
186 1.1 alnsn
187 1.5 alnsn #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
188 1.3 alnsn # define IS_MOVABLE 0x004
189 1.3 alnsn # define IS_JAL 0x008
190 1.3 alnsn # define IS_CALL 0x010
191 1.3 alnsn # define IS_BIT26_COND 0x020
192 1.3 alnsn # define IS_BIT16_COND 0x040
193 1.3 alnsn
194 1.3 alnsn # define IS_COND (IS_BIT26_COND | IS_BIT16_COND)
195 1.1 alnsn
196 1.3 alnsn # define PATCH_B 0x080
197 1.3 alnsn # define PATCH_J 0x100
198 1.1 alnsn
199 1.3 alnsn #if (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
200 1.3 alnsn # define PATCH_ABS32 0x200
201 1.3 alnsn # define PATCH_ABS48 0x400
202 1.3 alnsn #endif
203 1.1 alnsn
204 1.1 alnsn /* instruction types */
205 1.3 alnsn # define MOVABLE_INS 0
206 1.1 alnsn /* 1 - 31 last destination register */
207 1.1 alnsn /* no destination (i.e: store) */
208 1.3 alnsn # define UNMOVABLE_INS 32
209 1.2 alnsn /* FPU status register */
210 1.3 alnsn # define FCSR_FCC 33
211 1.3 alnsn #endif
212 1.3 alnsn
213 1.3 alnsn #if (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
214 1.3 alnsn # define IS_JAL 0x04
215 1.3 alnsn # define IS_COND 0x08
216 1.3 alnsn
217 1.3 alnsn # define PATCH_B 0x10
218 1.3 alnsn # define PATCH_J 0x20
219 1.2 alnsn #endif
220 1.2 alnsn
221 1.2 alnsn #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
222 1.3 alnsn # define IS_MOVABLE 0x04
223 1.3 alnsn # define IS_COND 0x08
224 1.3 alnsn # define IS_CALL 0x10
225 1.2 alnsn
226 1.3 alnsn # define PATCH_B 0x20
227 1.3 alnsn # define PATCH_CALL 0x40
228 1.2 alnsn
229 1.2 alnsn /* instruction types */
230 1.3 alnsn # define MOVABLE_INS 0
231 1.2 alnsn /* 1 - 31 last destination register */
232 1.2 alnsn /* no destination (i.e: store) */
233 1.3 alnsn # define UNMOVABLE_INS 32
234 1.2 alnsn
235 1.3 alnsn # define DST_INS_MASK 0xff
236 1.2 alnsn
237 1.2 alnsn /* ICC_SET is the same as SET_FLAGS. */
238 1.3 alnsn # define ICC_IS_SET (1 << 23)
239 1.3 alnsn # define FCC_IS_SET (1 << 24)
240 1.1 alnsn #endif
241 1.1 alnsn
242 1.5 alnsn /* Stack management. */
243 1.1 alnsn
244 1.5 alnsn #define GET_SAVED_REGISTERS_SIZE(scratches, saveds, extra) \
245 1.5 alnsn (((scratches < SLJIT_NUMBER_OF_SCRATCH_REGISTERS ? 0 : (scratches - SLJIT_NUMBER_OF_SCRATCH_REGISTERS)) + \
246 1.5 alnsn (saveds < SLJIT_NUMBER_OF_SAVED_REGISTERS ? saveds : SLJIT_NUMBER_OF_SAVED_REGISTERS) + \
247 1.5 alnsn extra) * sizeof(sljit_sw))
248 1.1 alnsn
249 1.5 alnsn #define ADJUST_LOCAL_OFFSET(p, i) \
250 1.5 alnsn if ((p) == (SLJIT_MEM1(SLJIT_SP))) \
251 1.5 alnsn (i) += SLJIT_LOCALS_OFFSET;
252 1.3 alnsn
253 1.5 alnsn #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
254 1.1 alnsn
255 1.5 alnsn /* Utils can still be used even if SLJIT_CONFIG_UNSUPPORTED is set. */
256 1.5 alnsn #include "sljitUtils.c"
257 1.1 alnsn
258 1.5 alnsn #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
259 1.3 alnsn
260 1.5 alnsn #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
261 1.5.16.1 pgoyette
262 1.5.16.1 pgoyette #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR)
263 1.5.16.1 pgoyette #include "sljitProtExecAllocator.c"
264 1.5.16.1 pgoyette #else
265 1.5 alnsn #include "sljitExecAllocator.c"
266 1.2 alnsn #endif
267 1.2 alnsn
268 1.5.16.1 pgoyette #endif
269 1.5.16.1 pgoyette
270 1.5.16.1 pgoyette #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR)
271 1.5.16.1 pgoyette #define SLJIT_ADD_EXEC_OFFSET(ptr, exec_offset) ((sljit_u8 *)(ptr) + (exec_offset))
272 1.5.16.1 pgoyette #else
273 1.5.16.1 pgoyette #define SLJIT_ADD_EXEC_OFFSET(ptr, exec_offset) ((sljit_u8 *)(ptr))
274 1.5.16.1 pgoyette #endif
275 1.5.16.1 pgoyette
276 1.5 alnsn /* Argument checking features. */
277 1.2 alnsn
278 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
279 1.1 alnsn
280 1.5 alnsn /* Returns with error when an invalid argument is passed. */
281 1.1 alnsn
282 1.5 alnsn #define CHECK_ARGUMENT(x) \
283 1.5 alnsn do { \
284 1.5 alnsn if (SLJIT_UNLIKELY(!(x))) \
285 1.5 alnsn return 1; \
286 1.5 alnsn } while (0)
287 1.1 alnsn
288 1.5 alnsn #define CHECK_RETURN_TYPE sljit_s32
289 1.5 alnsn #define CHECK_RETURN_OK return 0
290 1.1 alnsn
291 1.5 alnsn #define CHECK(x) \
292 1.5 alnsn do { \
293 1.5 alnsn if (SLJIT_UNLIKELY(x)) { \
294 1.5 alnsn compiler->error = SLJIT_ERR_BAD_ARGUMENT; \
295 1.5 alnsn return SLJIT_ERR_BAD_ARGUMENT; \
296 1.5 alnsn } \
297 1.5 alnsn } while (0)
298 1.1 alnsn
299 1.5 alnsn #define CHECK_PTR(x) \
300 1.5 alnsn do { \
301 1.5 alnsn if (SLJIT_UNLIKELY(x)) { \
302 1.5 alnsn compiler->error = SLJIT_ERR_BAD_ARGUMENT; \
303 1.5 alnsn return NULL; \
304 1.5 alnsn } \
305 1.5 alnsn } while (0)
306 1.1 alnsn
307 1.5 alnsn #define CHECK_REG_INDEX(x) \
308 1.5 alnsn do { \
309 1.5 alnsn if (SLJIT_UNLIKELY(x)) { \
310 1.5 alnsn return -2; \
311 1.5 alnsn } \
312 1.5 alnsn } while (0)
313 1.1 alnsn
314 1.5 alnsn #elif (defined SLJIT_DEBUG && SLJIT_DEBUG)
315 1.1 alnsn
316 1.5 alnsn /* Assertion failure occures if an invalid argument is passed. */
317 1.5 alnsn #undef SLJIT_ARGUMENT_CHECKS
318 1.5 alnsn #define SLJIT_ARGUMENT_CHECKS 1
319 1.5 alnsn
320 1.5 alnsn #define CHECK_ARGUMENT(x) SLJIT_ASSERT(x)
321 1.5 alnsn #define CHECK_RETURN_TYPE void
322 1.5 alnsn #define CHECK_RETURN_OK return
323 1.5 alnsn #define CHECK(x) x
324 1.5 alnsn #define CHECK_PTR(x) x
325 1.5 alnsn #define CHECK_REG_INDEX(x) x
326 1.5 alnsn
327 1.5 alnsn #elif (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
328 1.5 alnsn
329 1.5 alnsn /* Arguments are not checked. */
330 1.5 alnsn #define CHECK_RETURN_TYPE void
331 1.5 alnsn #define CHECK_RETURN_OK return
332 1.5 alnsn #define CHECK(x) x
333 1.5 alnsn #define CHECK_PTR(x) x
334 1.5 alnsn #define CHECK_REG_INDEX(x) x
335 1.1 alnsn
336 1.5 alnsn #else
337 1.1 alnsn
338 1.5 alnsn /* Arguments are not checked. */
339 1.5 alnsn #define CHECK(x)
340 1.5 alnsn #define CHECK_PTR(x)
341 1.5 alnsn #define CHECK_REG_INDEX(x)
342 1.1 alnsn
343 1.5 alnsn #endif /* SLJIT_ARGUMENT_CHECKS */
344 1.1 alnsn
345 1.1 alnsn /* --------------------------------------------------------------------- */
346 1.1 alnsn /* Public functions */
347 1.1 alnsn /* --------------------------------------------------------------------- */
348 1.1 alnsn
349 1.5 alnsn #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
350 1.1 alnsn #define SLJIT_NEEDS_COMPILER_INIT 1
351 1.5 alnsn static sljit_s32 compiler_initialized = 0;
352 1.1 alnsn /* A thread safe initialization. */
353 1.1 alnsn static void init_compiler(void);
354 1.1 alnsn #endif
355 1.1 alnsn
356 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data)
357 1.1 alnsn {
358 1.5 alnsn struct sljit_compiler *compiler = (struct sljit_compiler*)SLJIT_MALLOC(sizeof(struct sljit_compiler), allocator_data);
359 1.1 alnsn if (!compiler)
360 1.1 alnsn return NULL;
361 1.1 alnsn SLJIT_ZEROMEM(compiler, sizeof(struct sljit_compiler));
362 1.1 alnsn
363 1.1 alnsn SLJIT_COMPILE_ASSERT(
364 1.5 alnsn sizeof(sljit_s8) == 1 && sizeof(sljit_u8) == 1
365 1.5 alnsn && sizeof(sljit_s16) == 2 && sizeof(sljit_u16) == 2
366 1.5 alnsn && sizeof(sljit_s32) == 4 && sizeof(sljit_u32) == 4
367 1.3 alnsn && (sizeof(sljit_p) == 4 || sizeof(sljit_p) == 8)
368 1.3 alnsn && sizeof(sljit_p) <= sizeof(sljit_sw)
369 1.3 alnsn && (sizeof(sljit_sw) == 4 || sizeof(sljit_sw) == 8)
370 1.3 alnsn && (sizeof(sljit_uw) == 4 || sizeof(sljit_uw) == 8),
371 1.1 alnsn invalid_integer_types);
372 1.5 alnsn SLJIT_COMPILE_ASSERT(SLJIT_I32_OP == SLJIT_F32_OP,
373 1.3 alnsn int_op_and_single_op_must_be_the_same);
374 1.5 alnsn SLJIT_COMPILE_ASSERT(SLJIT_REWRITABLE_JUMP != SLJIT_F32_OP,
375 1.3 alnsn rewritable_jump_and_single_op_must_not_be_the_same);
376 1.5.16.1 pgoyette SLJIT_COMPILE_ASSERT(!(SLJIT_EQUAL & 0x1) && !(SLJIT_LESS & 0x1) && !(SLJIT_EQUAL_F64 & 0x1) && !(SLJIT_JUMP & 0x1),
377 1.5.16.1 pgoyette conditional_flags_must_be_even_numbers);
378 1.1 alnsn
379 1.1 alnsn /* Only the non-zero members must be set. */
380 1.1 alnsn compiler->error = SLJIT_SUCCESS;
381 1.1 alnsn
382 1.5 alnsn compiler->allocator_data = allocator_data;
383 1.5 alnsn compiler->buf = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, allocator_data);
384 1.5 alnsn compiler->abuf = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, allocator_data);
385 1.1 alnsn
386 1.1 alnsn if (!compiler->buf || !compiler->abuf) {
387 1.1 alnsn if (compiler->buf)
388 1.5 alnsn SLJIT_FREE(compiler->buf, allocator_data);
389 1.1 alnsn if (compiler->abuf)
390 1.5 alnsn SLJIT_FREE(compiler->abuf, allocator_data);
391 1.5 alnsn SLJIT_FREE(compiler, allocator_data);
392 1.1 alnsn return NULL;
393 1.1 alnsn }
394 1.1 alnsn
395 1.1 alnsn compiler->buf->next = NULL;
396 1.1 alnsn compiler->buf->used_size = 0;
397 1.1 alnsn compiler->abuf->next = NULL;
398 1.1 alnsn compiler->abuf->used_size = 0;
399 1.1 alnsn
400 1.3 alnsn compiler->scratches = -1;
401 1.1 alnsn compiler->saveds = -1;
402 1.5 alnsn compiler->fscratches = -1;
403 1.5 alnsn compiler->fsaveds = -1;
404 1.5 alnsn compiler->local_size = -1;
405 1.1 alnsn
406 1.1 alnsn #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
407 1.1 alnsn compiler->args = -1;
408 1.1 alnsn #endif
409 1.1 alnsn
410 1.1 alnsn #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
411 1.5 alnsn compiler->cpool = (sljit_uw*)SLJIT_MALLOC(CPOOL_SIZE * sizeof(sljit_uw)
412 1.5 alnsn + CPOOL_SIZE * sizeof(sljit_u8), allocator_data);
413 1.1 alnsn if (!compiler->cpool) {
414 1.5 alnsn SLJIT_FREE(compiler->buf, allocator_data);
415 1.5 alnsn SLJIT_FREE(compiler->abuf, allocator_data);
416 1.5 alnsn SLJIT_FREE(compiler, allocator_data);
417 1.1 alnsn return NULL;
418 1.1 alnsn }
419 1.5 alnsn compiler->cpool_unique = (sljit_u8*)(compiler->cpool + CPOOL_SIZE);
420 1.1 alnsn compiler->cpool_diff = 0xffffffff;
421 1.1 alnsn #endif
422 1.1 alnsn
423 1.5 alnsn #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
424 1.1 alnsn compiler->delay_slot = UNMOVABLE_INS;
425 1.1 alnsn #endif
426 1.1 alnsn
427 1.2 alnsn #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
428 1.2 alnsn compiler->delay_slot = UNMOVABLE_INS;
429 1.2 alnsn #endif
430 1.2 alnsn
431 1.1 alnsn #if (defined SLJIT_NEEDS_COMPILER_INIT && SLJIT_NEEDS_COMPILER_INIT)
432 1.1 alnsn if (!compiler_initialized) {
433 1.1 alnsn init_compiler();
434 1.1 alnsn compiler_initialized = 1;
435 1.1 alnsn }
436 1.1 alnsn #endif
437 1.1 alnsn
438 1.1 alnsn return compiler;
439 1.1 alnsn }
440 1.1 alnsn
441 1.1 alnsn SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
442 1.1 alnsn {
443 1.1 alnsn struct sljit_memory_fragment *buf;
444 1.1 alnsn struct sljit_memory_fragment *curr;
445 1.5 alnsn void *allocator_data = compiler->allocator_data;
446 1.5 alnsn SLJIT_UNUSED_ARG(allocator_data);
447 1.1 alnsn
448 1.1 alnsn buf = compiler->buf;
449 1.1 alnsn while (buf) {
450 1.1 alnsn curr = buf;
451 1.1 alnsn buf = buf->next;
452 1.5 alnsn SLJIT_FREE(curr, allocator_data);
453 1.1 alnsn }
454 1.1 alnsn
455 1.1 alnsn buf = compiler->abuf;
456 1.1 alnsn while (buf) {
457 1.1 alnsn curr = buf;
458 1.1 alnsn buf = buf->next;
459 1.5 alnsn SLJIT_FREE(curr, allocator_data);
460 1.1 alnsn }
461 1.1 alnsn
462 1.1 alnsn #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
463 1.5 alnsn SLJIT_FREE(compiler->cpool, allocator_data);
464 1.1 alnsn #endif
465 1.5 alnsn SLJIT_FREE(compiler, allocator_data);
466 1.5 alnsn }
467 1.5 alnsn
468 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler)
469 1.5 alnsn {
470 1.5 alnsn if (compiler->error == SLJIT_SUCCESS)
471 1.5 alnsn compiler->error = SLJIT_ERR_ALLOC_FAILED;
472 1.1 alnsn }
473 1.1 alnsn
474 1.1 alnsn #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
475 1.1 alnsn SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code)
476 1.1 alnsn {
477 1.1 alnsn /* Remove thumb mode flag. */
478 1.1 alnsn SLJIT_FREE_EXEC((void*)((sljit_uw)code & ~0x1));
479 1.1 alnsn }
480 1.1 alnsn #elif (defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL)
481 1.1 alnsn SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code)
482 1.1 alnsn {
483 1.1 alnsn /* Resolve indirection. */
484 1.1 alnsn code = (void*)(*(sljit_uw*)code);
485 1.1 alnsn SLJIT_FREE_EXEC(code);
486 1.1 alnsn }
487 1.1 alnsn #else
488 1.1 alnsn SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code)
489 1.1 alnsn {
490 1.1 alnsn SLJIT_FREE_EXEC(code);
491 1.1 alnsn }
492 1.1 alnsn #endif
493 1.1 alnsn
494 1.1 alnsn SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
495 1.1 alnsn {
496 1.1 alnsn if (SLJIT_LIKELY(!!jump) && SLJIT_LIKELY(!!label)) {
497 1.1 alnsn jump->flags &= ~JUMP_ADDR;
498 1.1 alnsn jump->flags |= JUMP_LABEL;
499 1.1 alnsn jump->u.label = label;
500 1.1 alnsn }
501 1.1 alnsn }
502 1.1 alnsn
503 1.1 alnsn SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
504 1.1 alnsn {
505 1.1 alnsn if (SLJIT_LIKELY(!!jump)) {
506 1.1 alnsn jump->flags &= ~JUMP_LABEL;
507 1.1 alnsn jump->flags |= JUMP_ADDR;
508 1.1 alnsn jump->u.target = target;
509 1.1 alnsn }
510 1.1 alnsn }
511 1.1 alnsn
512 1.5.16.1 pgoyette SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *compiler, sljit_s32 current_flags)
513 1.5.16.1 pgoyette {
514 1.5.16.1 pgoyette SLJIT_UNUSED_ARG(compiler);
515 1.5.16.1 pgoyette SLJIT_UNUSED_ARG(current_flags);
516 1.5.16.1 pgoyette
517 1.5.16.1 pgoyette #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
518 1.5.16.1 pgoyette if ((current_flags & ~(VARIABLE_FLAG_MASK | SLJIT_I32_OP | SLJIT_SET_Z)) == 0) {
519 1.5.16.1 pgoyette compiler->last_flags = GET_FLAG_TYPE(current_flags) | (current_flags & (SLJIT_I32_OP | SLJIT_SET_Z));
520 1.5.16.1 pgoyette }
521 1.5.16.1 pgoyette #endif
522 1.5.16.1 pgoyette }
523 1.5.16.1 pgoyette
524 1.1 alnsn /* --------------------------------------------------------------------- */
525 1.1 alnsn /* Private functions */
526 1.1 alnsn /* --------------------------------------------------------------------- */
527 1.1 alnsn
528 1.3 alnsn static void* ensure_buf(struct sljit_compiler *compiler, sljit_uw size)
529 1.1 alnsn {
530 1.5 alnsn sljit_u8 *ret;
531 1.1 alnsn struct sljit_memory_fragment *new_frag;
532 1.1 alnsn
533 1.3 alnsn SLJIT_ASSERT(size <= 256);
534 1.3 alnsn if (compiler->buf->used_size + size <= (BUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) {
535 1.1 alnsn ret = compiler->buf->memory + compiler->buf->used_size;
536 1.1 alnsn compiler->buf->used_size += size;
537 1.1 alnsn return ret;
538 1.1 alnsn }
539 1.5 alnsn new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, compiler->allocator_data);
540 1.1 alnsn PTR_FAIL_IF_NULL(new_frag);
541 1.1 alnsn new_frag->next = compiler->buf;
542 1.1 alnsn compiler->buf = new_frag;
543 1.1 alnsn new_frag->used_size = size;
544 1.1 alnsn return new_frag->memory;
545 1.1 alnsn }
546 1.1 alnsn
547 1.3 alnsn static void* ensure_abuf(struct sljit_compiler *compiler, sljit_uw size)
548 1.1 alnsn {
549 1.5 alnsn sljit_u8 *ret;
550 1.1 alnsn struct sljit_memory_fragment *new_frag;
551 1.1 alnsn
552 1.3 alnsn SLJIT_ASSERT(size <= 256);
553 1.3 alnsn if (compiler->abuf->used_size + size <= (ABUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) {
554 1.1 alnsn ret = compiler->abuf->memory + compiler->abuf->used_size;
555 1.1 alnsn compiler->abuf->used_size += size;
556 1.1 alnsn return ret;
557 1.1 alnsn }
558 1.5 alnsn new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, compiler->allocator_data);
559 1.1 alnsn PTR_FAIL_IF_NULL(new_frag);
560 1.1 alnsn new_frag->next = compiler->abuf;
561 1.1 alnsn compiler->abuf = new_frag;
562 1.1 alnsn new_frag->used_size = size;
563 1.1 alnsn return new_frag->memory;
564 1.1 alnsn }
565 1.1 alnsn
566 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_s32 size)
567 1.1 alnsn {
568 1.1 alnsn CHECK_ERROR_PTR();
569 1.1 alnsn
570 1.1 alnsn #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
571 1.1 alnsn if (size <= 0 || size > 128)
572 1.1 alnsn return NULL;
573 1.1 alnsn size = (size + 7) & ~7;
574 1.1 alnsn #else
575 1.1 alnsn if (size <= 0 || size > 64)
576 1.1 alnsn return NULL;
577 1.1 alnsn size = (size + 3) & ~3;
578 1.1 alnsn #endif
579 1.1 alnsn return ensure_abuf(compiler, size);
580 1.1 alnsn }
581 1.1 alnsn
582 1.1 alnsn static SLJIT_INLINE void reverse_buf(struct sljit_compiler *compiler)
583 1.1 alnsn {
584 1.1 alnsn struct sljit_memory_fragment *buf = compiler->buf;
585 1.1 alnsn struct sljit_memory_fragment *prev = NULL;
586 1.1 alnsn struct sljit_memory_fragment *tmp;
587 1.1 alnsn
588 1.1 alnsn do {
589 1.1 alnsn tmp = buf->next;
590 1.1 alnsn buf->next = prev;
591 1.1 alnsn prev = buf;
592 1.1 alnsn buf = tmp;
593 1.1 alnsn } while (buf != NULL);
594 1.1 alnsn
595 1.1 alnsn compiler->buf = prev;
596 1.1 alnsn }
597 1.1 alnsn
598 1.5 alnsn static SLJIT_INLINE void set_emit_enter(struct sljit_compiler *compiler,
599 1.5 alnsn sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds,
600 1.5 alnsn sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
601 1.5 alnsn {
602 1.5 alnsn SLJIT_UNUSED_ARG(args);
603 1.5 alnsn SLJIT_UNUSED_ARG(local_size);
604 1.5 alnsn
605 1.5 alnsn compiler->options = options;
606 1.5 alnsn compiler->scratches = scratches;
607 1.5 alnsn compiler->saveds = saveds;
608 1.5 alnsn compiler->fscratches = fscratches;
609 1.5 alnsn compiler->fsaveds = fsaveds;
610 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
611 1.5 alnsn compiler->logical_local_size = local_size;
612 1.5 alnsn #endif
613 1.5 alnsn }
614 1.5 alnsn
615 1.5 alnsn static SLJIT_INLINE void set_set_context(struct sljit_compiler *compiler,
616 1.5 alnsn sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds,
617 1.5 alnsn sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
618 1.5 alnsn {
619 1.5 alnsn SLJIT_UNUSED_ARG(args);
620 1.5 alnsn SLJIT_UNUSED_ARG(local_size);
621 1.5 alnsn
622 1.5 alnsn compiler->options = options;
623 1.5 alnsn compiler->scratches = scratches;
624 1.5 alnsn compiler->saveds = saveds;
625 1.5 alnsn compiler->fscratches = fscratches;
626 1.5 alnsn compiler->fsaveds = fsaveds;
627 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
628 1.5 alnsn compiler->logical_local_size = local_size;
629 1.5 alnsn #endif
630 1.5 alnsn }
631 1.5 alnsn
632 1.1 alnsn static SLJIT_INLINE void set_label(struct sljit_label *label, struct sljit_compiler *compiler)
633 1.1 alnsn {
634 1.1 alnsn label->next = NULL;
635 1.1 alnsn label->size = compiler->size;
636 1.1 alnsn if (compiler->last_label)
637 1.1 alnsn compiler->last_label->next = label;
638 1.1 alnsn else
639 1.1 alnsn compiler->labels = label;
640 1.1 alnsn compiler->last_label = label;
641 1.1 alnsn }
642 1.1 alnsn
643 1.5 alnsn static SLJIT_INLINE void set_jump(struct sljit_jump *jump, struct sljit_compiler *compiler, sljit_s32 flags)
644 1.1 alnsn {
645 1.1 alnsn jump->next = NULL;
646 1.1 alnsn jump->flags = flags;
647 1.1 alnsn if (compiler->last_jump)
648 1.1 alnsn compiler->last_jump->next = jump;
649 1.1 alnsn else
650 1.1 alnsn compiler->jumps = jump;
651 1.1 alnsn compiler->last_jump = jump;
652 1.1 alnsn }
653 1.1 alnsn
654 1.1 alnsn static SLJIT_INLINE void set_const(struct sljit_const *const_, struct sljit_compiler *compiler)
655 1.1 alnsn {
656 1.1 alnsn const_->next = NULL;
657 1.1 alnsn const_->addr = compiler->size;
658 1.1 alnsn if (compiler->last_const)
659 1.1 alnsn compiler->last_const->next = const_;
660 1.1 alnsn else
661 1.1 alnsn compiler->consts = const_;
662 1.1 alnsn compiler->last_const = const_;
663 1.1 alnsn }
664 1.1 alnsn
665 1.1 alnsn #define ADDRESSING_DEPENDS_ON(exp, reg) \
666 1.3 alnsn (((exp) & SLJIT_MEM) && (((exp) & REG_MASK) == reg || OFFS_REG(exp) == reg))
667 1.1 alnsn
668 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
669 1.1 alnsn
670 1.1 alnsn #define FUNCTION_CHECK_IS_REG(r) \
671 1.5 alnsn (((r) >= SLJIT_R0 && (r) < (SLJIT_R0 + compiler->scratches)) || \
672 1.5 alnsn ((r) > (SLJIT_S0 - compiler->saveds) && (r) <= SLJIT_S0))
673 1.5 alnsn
674 1.5 alnsn #define FUNCTION_CHECK_IS_REG_OR_UNUSED(r) \
675 1.1 alnsn ((r) == SLJIT_UNUSED || \
676 1.5 alnsn ((r) >= SLJIT_R0 && (r) < (SLJIT_R0 + compiler->scratches)) || \
677 1.5 alnsn ((r) > (SLJIT_S0 - compiler->saveds) && (r) <= SLJIT_S0))
678 1.5 alnsn
679 1.5 alnsn #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
680 1.5 alnsn #define CHECK_NOT_VIRTUAL_REGISTER(p) \
681 1.5 alnsn CHECK_ARGUMENT((p) < SLJIT_R3 || (p) > SLJIT_R6);
682 1.5 alnsn #else
683 1.5 alnsn #define CHECK_NOT_VIRTUAL_REGISTER(p)
684 1.5 alnsn #endif
685 1.1 alnsn
686 1.1 alnsn #define FUNCTION_CHECK_SRC(p, i) \
687 1.5 alnsn CHECK_ARGUMENT(compiler->scratches != -1 && compiler->saveds != -1); \
688 1.1 alnsn if (FUNCTION_CHECK_IS_REG(p)) \
689 1.5 alnsn CHECK_ARGUMENT((i) == 0); \
690 1.1 alnsn else if ((p) == SLJIT_IMM) \
691 1.1 alnsn ; \
692 1.5 alnsn else if ((p) == (SLJIT_MEM1(SLJIT_SP))) \
693 1.5 alnsn CHECK_ARGUMENT((i) >= 0 && (i) < compiler->logical_local_size); \
694 1.5 alnsn else { \
695 1.5 alnsn CHECK_ARGUMENT((p) & SLJIT_MEM); \
696 1.5 alnsn CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG_OR_UNUSED((p) & REG_MASK)); \
697 1.5 alnsn CHECK_NOT_VIRTUAL_REGISTER((p) & REG_MASK); \
698 1.3 alnsn if ((p) & OFFS_REG_MASK) { \
699 1.5 alnsn CHECK_ARGUMENT(((p) & REG_MASK) != SLJIT_UNUSED); \
700 1.5 alnsn CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(OFFS_REG(p))); \
701 1.5 alnsn CHECK_NOT_VIRTUAL_REGISTER(OFFS_REG(p)); \
702 1.5 alnsn CHECK_ARGUMENT(!((i) & ~0x3)); \
703 1.1 alnsn } \
704 1.5 alnsn CHECK_ARGUMENT(!((p) & ~(SLJIT_MEM | SLJIT_IMM | REG_MASK | OFFS_REG_MASK))); \
705 1.5 alnsn }
706 1.1 alnsn
707 1.1 alnsn #define FUNCTION_CHECK_DST(p, i) \
708 1.5 alnsn CHECK_ARGUMENT(compiler->scratches != -1 && compiler->saveds != -1); \
709 1.5 alnsn if (FUNCTION_CHECK_IS_REG_OR_UNUSED(p)) \
710 1.5 alnsn CHECK_ARGUMENT((i) == 0); \
711 1.5 alnsn else if ((p) == (SLJIT_MEM1(SLJIT_SP))) \
712 1.5 alnsn CHECK_ARGUMENT((i) >= 0 && (i) < compiler->logical_local_size); \
713 1.5 alnsn else { \
714 1.5 alnsn CHECK_ARGUMENT((p) & SLJIT_MEM); \
715 1.5 alnsn CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG_OR_UNUSED((p) & REG_MASK)); \
716 1.5 alnsn CHECK_NOT_VIRTUAL_REGISTER((p) & REG_MASK); \
717 1.3 alnsn if ((p) & OFFS_REG_MASK) { \
718 1.5 alnsn CHECK_ARGUMENT(((p) & REG_MASK) != SLJIT_UNUSED); \
719 1.5 alnsn CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(OFFS_REG(p))); \
720 1.5 alnsn CHECK_NOT_VIRTUAL_REGISTER(OFFS_REG(p)); \
721 1.5 alnsn CHECK_ARGUMENT(!((i) & ~0x3)); \
722 1.1 alnsn } \
723 1.5 alnsn CHECK_ARGUMENT(!((p) & ~(SLJIT_MEM | SLJIT_IMM | REG_MASK | OFFS_REG_MASK))); \
724 1.5 alnsn }
725 1.1 alnsn
726 1.1 alnsn #define FUNCTION_FCHECK(p, i) \
727 1.5 alnsn CHECK_ARGUMENT(compiler->fscratches != -1 && compiler->fsaveds != -1); \
728 1.5 alnsn if (((p) >= SLJIT_FR0 && (p) < (SLJIT_FR0 + compiler->fscratches)) || \
729 1.5 alnsn ((p) > (SLJIT_FS0 - compiler->fsaveds) && (p) <= SLJIT_FS0)) \
730 1.5 alnsn CHECK_ARGUMENT(i == 0); \
731 1.5 alnsn else if ((p) == (SLJIT_MEM1(SLJIT_SP))) \
732 1.5 alnsn CHECK_ARGUMENT((i) >= 0 && (i) < compiler->logical_local_size); \
733 1.5 alnsn else { \
734 1.5 alnsn CHECK_ARGUMENT((p) & SLJIT_MEM); \
735 1.5 alnsn CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG_OR_UNUSED((p) & REG_MASK)); \
736 1.5 alnsn CHECK_NOT_VIRTUAL_REGISTER((p) & REG_MASK); \
737 1.3 alnsn if ((p) & OFFS_REG_MASK) { \
738 1.5 alnsn CHECK_ARGUMENT(((p) & REG_MASK) != SLJIT_UNUSED); \
739 1.5 alnsn CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(OFFS_REG(p))); \
740 1.5 alnsn CHECK_NOT_VIRTUAL_REGISTER(OFFS_REG(p)); \
741 1.5 alnsn CHECK_ARGUMENT(((p) & OFFS_REG_MASK) != TO_OFFS_REG(SLJIT_SP) && !(i & ~0x3)); \
742 1.5 alnsn } \
743 1.5 alnsn CHECK_ARGUMENT(!((p) & ~(SLJIT_MEM | SLJIT_IMM | REG_MASK | OFFS_REG_MASK))); \
744 1.5 alnsn }
745 1.1 alnsn
746 1.5 alnsn #endif /* SLJIT_ARGUMENT_CHECKS */
747 1.1 alnsn
748 1.1 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
749 1.1 alnsn
750 1.1 alnsn SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
751 1.1 alnsn {
752 1.1 alnsn compiler->verbose = verbose;
753 1.1 alnsn }
754 1.1 alnsn
755 1.3 alnsn #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
756 1.1 alnsn #ifdef _WIN64
757 1.3 alnsn # define SLJIT_PRINT_D "I64"
758 1.1 alnsn #else
759 1.3 alnsn # define SLJIT_PRINT_D "l"
760 1.1 alnsn #endif
761 1.1 alnsn #else
762 1.3 alnsn # define SLJIT_PRINT_D ""
763 1.1 alnsn #endif
764 1.1 alnsn
765 1.5 alnsn #define sljit_verbose_reg(compiler, r) \
766 1.5 alnsn do { \
767 1.5 alnsn if ((r) < (SLJIT_R0 + compiler->scratches)) \
768 1.5 alnsn fprintf(compiler->verbose, "r%d", (r) - SLJIT_R0); \
769 1.5.16.1 pgoyette else if ((r) != SLJIT_SP) \
770 1.5 alnsn fprintf(compiler->verbose, "s%d", SLJIT_NUMBER_OF_REGISTERS - (r)); \
771 1.5.16.1 pgoyette else \
772 1.5.16.1 pgoyette fprintf(compiler->verbose, "sp"); \
773 1.5 alnsn } while (0)
774 1.5 alnsn
775 1.5 alnsn #define sljit_verbose_param(compiler, p, i) \
776 1.1 alnsn if ((p) & SLJIT_IMM) \
777 1.1 alnsn fprintf(compiler->verbose, "#%" SLJIT_PRINT_D "d", (i)); \
778 1.1 alnsn else if ((p) & SLJIT_MEM) { \
779 1.3 alnsn if ((p) & REG_MASK) { \
780 1.5 alnsn fputc('[', compiler->verbose); \
781 1.5 alnsn sljit_verbose_reg(compiler, (p) & REG_MASK); \
782 1.5 alnsn if ((p) & OFFS_REG_MASK) { \
783 1.5 alnsn fprintf(compiler->verbose, " + "); \
784 1.5 alnsn sljit_verbose_reg(compiler, OFFS_REG(p)); \
785 1.5 alnsn if (i) \
786 1.5 alnsn fprintf(compiler->verbose, " * %d", 1 << (i)); \
787 1.1 alnsn } \
788 1.5 alnsn else if (i) \
789 1.5 alnsn fprintf(compiler->verbose, " + %" SLJIT_PRINT_D "d", (i)); \
790 1.5 alnsn fputc(']', compiler->verbose); \
791 1.1 alnsn } \
792 1.1 alnsn else \
793 1.1 alnsn fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i)); \
794 1.5 alnsn } else if (p) \
795 1.5 alnsn sljit_verbose_reg(compiler, p); \
796 1.5 alnsn else \
797 1.5 alnsn fprintf(compiler->verbose, "unused");
798 1.5 alnsn
799 1.5 alnsn #define sljit_verbose_fparam(compiler, p, i) \
800 1.1 alnsn if ((p) & SLJIT_MEM) { \
801 1.3 alnsn if ((p) & REG_MASK) { \
802 1.5 alnsn fputc('[', compiler->verbose); \
803 1.5 alnsn sljit_verbose_reg(compiler, (p) & REG_MASK); \
804 1.5 alnsn if ((p) & OFFS_REG_MASK) { \
805 1.5 alnsn fprintf(compiler->verbose, " + "); \
806 1.5 alnsn sljit_verbose_reg(compiler, OFFS_REG(p)); \
807 1.5 alnsn if (i) \
808 1.5 alnsn fprintf(compiler->verbose, "%d", 1 << (i)); \
809 1.1 alnsn } \
810 1.5 alnsn else if (i) \
811 1.5 alnsn fprintf(compiler->verbose, "%" SLJIT_PRINT_D "d", (i)); \
812 1.5 alnsn fputc(']', compiler->verbose); \
813 1.1 alnsn } \
814 1.1 alnsn else \
815 1.1 alnsn fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i)); \
816 1.5 alnsn } \
817 1.5 alnsn else { \
818 1.5 alnsn if ((p) < (SLJIT_FR0 + compiler->fscratches)) \
819 1.5 alnsn fprintf(compiler->verbose, "fr%d", (p) - SLJIT_FR0); \
820 1.5 alnsn else \
821 1.5 alnsn fprintf(compiler->verbose, "fs%d", SLJIT_NUMBER_OF_FLOAT_REGISTERS - (p)); \
822 1.5 alnsn }
823 1.1 alnsn
824 1.5 alnsn static const char* op0_names[] = {
825 1.5 alnsn (char*)"breakpoint", (char*)"nop", (char*)"lmul.uw", (char*)"lmul.sw",
826 1.5 alnsn (char*)"divmod.u", (char*)"divmod.s", (char*)"div.u", (char*)"div.s"
827 1.5 alnsn };
828 1.5 alnsn
829 1.5 alnsn static const char* op1_names[] = {
830 1.5 alnsn (char*)"", (char*)".u8", (char*)".s8", (char*)".u16",
831 1.5 alnsn (char*)".s16", (char*)".u32", (char*)".s32", (char*)".p",
832 1.5 alnsn (char*)"", (char*)".u8", (char*)".s8", (char*)".u16",
833 1.5 alnsn (char*)".s16", (char*)".u32", (char*)".s32", (char*)".p",
834 1.3 alnsn (char*)"not", (char*)"neg", (char*)"clz",
835 1.5 alnsn };
836 1.5 alnsn
837 1.5 alnsn static const char* op2_names[] = {
838 1.1 alnsn (char*)"add", (char*)"addc", (char*)"sub", (char*)"subc",
839 1.1 alnsn (char*)"mul", (char*)"and", (char*)"or", (char*)"xor",
840 1.1 alnsn (char*)"shl", (char*)"lshr", (char*)"ashr",
841 1.5 alnsn };
842 1.5 alnsn
843 1.5 alnsn static const char* fop1_names[] = {
844 1.5 alnsn (char*)"mov", (char*)"conv", (char*)"conv", (char*)"conv",
845 1.5 alnsn (char*)"conv", (char*)"conv", (char*)"cmp", (char*)"neg",
846 1.5 alnsn (char*)"abs",
847 1.5 alnsn };
848 1.5 alnsn
849 1.5 alnsn static const char* fop2_names[] = {
850 1.3 alnsn (char*)"add", (char*)"sub", (char*)"mul", (char*)"div"
851 1.1 alnsn };
852 1.1 alnsn
853 1.5 alnsn #define JUMP_POSTFIX(type) \
854 1.5 alnsn ((type & 0xff) <= SLJIT_MUL_NOT_OVERFLOW ? ((type & SLJIT_I32_OP) ? "32" : "") \
855 1.5 alnsn : ((type & 0xff) <= SLJIT_ORDERED_F64 ? ((type & SLJIT_F32_OP) ? ".f32" : ".f64") : ""))
856 1.5 alnsn
857 1.1 alnsn static char* jump_names[] = {
858 1.3 alnsn (char*)"equal", (char*)"not_equal",
859 1.3 alnsn (char*)"less", (char*)"greater_equal",
860 1.3 alnsn (char*)"greater", (char*)"less_equal",
861 1.3 alnsn (char*)"sig_less", (char*)"sig_greater_equal",
862 1.3 alnsn (char*)"sig_greater", (char*)"sig_less_equal",
863 1.3 alnsn (char*)"overflow", (char*)"not_overflow",
864 1.3 alnsn (char*)"mul_overflow", (char*)"mul_not_overflow",
865 1.5.16.1 pgoyette (char*)"carry", (char*)"",
866 1.5 alnsn (char*)"equal", (char*)"not_equal",
867 1.5 alnsn (char*)"less", (char*)"greater_equal",
868 1.5 alnsn (char*)"greater", (char*)"less_equal",
869 1.5 alnsn (char*)"unordered", (char*)"ordered",
870 1.1 alnsn (char*)"jump", (char*)"fast_call",
871 1.1 alnsn (char*)"call0", (char*)"call1", (char*)"call2", (char*)"call3"
872 1.1 alnsn };
873 1.1 alnsn
874 1.5 alnsn #endif /* SLJIT_VERBOSE */
875 1.1 alnsn
876 1.1 alnsn /* --------------------------------------------------------------------- */
877 1.1 alnsn /* Arch dependent */
878 1.1 alnsn /* --------------------------------------------------------------------- */
879 1.1 alnsn
880 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
881 1.5 alnsn || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
882 1.5 alnsn
883 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_generate_code(struct sljit_compiler *compiler)
884 1.1 alnsn {
885 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
886 1.1 alnsn struct sljit_jump *jump;
887 1.1 alnsn #endif
888 1.5 alnsn
889 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
890 1.1 alnsn
891 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
892 1.5 alnsn CHECK_ARGUMENT(compiler->size > 0);
893 1.1 alnsn jump = compiler->jumps;
894 1.1 alnsn while (jump) {
895 1.1 alnsn /* All jumps have target. */
896 1.5 alnsn CHECK_ARGUMENT(jump->flags & (JUMP_LABEL | JUMP_ADDR));
897 1.1 alnsn jump = jump->next;
898 1.1 alnsn }
899 1.1 alnsn #endif
900 1.5 alnsn CHECK_RETURN_OK;
901 1.1 alnsn }
902 1.1 alnsn
903 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_enter(struct sljit_compiler *compiler,
904 1.5 alnsn sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds,
905 1.5 alnsn sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
906 1.1 alnsn {
907 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
908 1.1 alnsn
909 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
910 1.5.16.1 pgoyette CHECK_ARGUMENT(!(options & ~SLJIT_F64_ALIGNMENT));
911 1.5 alnsn CHECK_ARGUMENT(args >= 0 && args <= 3);
912 1.5 alnsn CHECK_ARGUMENT(scratches >= 0 && scratches <= SLJIT_NUMBER_OF_REGISTERS);
913 1.5 alnsn CHECK_ARGUMENT(saveds >= 0 && saveds <= SLJIT_NUMBER_OF_REGISTERS);
914 1.5 alnsn CHECK_ARGUMENT(scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS);
915 1.5 alnsn CHECK_ARGUMENT(args <= saveds);
916 1.5 alnsn CHECK_ARGUMENT(fscratches >= 0 && fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
917 1.5 alnsn CHECK_ARGUMENT(fsaveds >= 0 && fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
918 1.5 alnsn CHECK_ARGUMENT(fscratches + fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
919 1.5 alnsn CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
920 1.5.16.1 pgoyette compiler->last_flags = 0;
921 1.5 alnsn #endif
922 1.1 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
923 1.1 alnsn if (SLJIT_UNLIKELY(!!compiler->verbose))
924 1.5 alnsn fprintf(compiler->verbose, " enter options:none args:%d scratches:%d saveds:%d fscratches:%d fsaveds:%d local_size:%d\n",
925 1.5 alnsn args, scratches, saveds, fscratches, fsaveds, local_size);
926 1.1 alnsn #endif
927 1.5 alnsn CHECK_RETURN_OK;
928 1.1 alnsn }
929 1.1 alnsn
930 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_set_context(struct sljit_compiler *compiler,
931 1.5 alnsn sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds,
932 1.5 alnsn sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
933 1.1 alnsn {
934 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
935 1.5.16.1 pgoyette CHECK_ARGUMENT(!(options & ~SLJIT_F64_ALIGNMENT));
936 1.5 alnsn CHECK_ARGUMENT(args >= 0 && args <= 3);
937 1.5 alnsn CHECK_ARGUMENT(scratches >= 0 && scratches <= SLJIT_NUMBER_OF_REGISTERS);
938 1.5 alnsn CHECK_ARGUMENT(saveds >= 0 && saveds <= SLJIT_NUMBER_OF_REGISTERS);
939 1.5 alnsn CHECK_ARGUMENT(scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS);
940 1.5 alnsn CHECK_ARGUMENT(args <= saveds);
941 1.5 alnsn CHECK_ARGUMENT(fscratches >= 0 && fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
942 1.5 alnsn CHECK_ARGUMENT(fsaveds >= 0 && fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
943 1.5 alnsn CHECK_ARGUMENT(fscratches + fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
944 1.5 alnsn CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
945 1.5.16.1 pgoyette compiler->last_flags = 0;
946 1.1 alnsn #endif
947 1.1 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
948 1.1 alnsn if (SLJIT_UNLIKELY(!!compiler->verbose))
949 1.5 alnsn fprintf(compiler->verbose, " set_context options:none args:%d scratches:%d saveds:%d fscratches:%d fsaveds:%d local_size:%d\n",
950 1.5 alnsn args, scratches, saveds, fscratches, fsaveds, local_size);
951 1.1 alnsn #endif
952 1.5 alnsn CHECK_RETURN_OK;
953 1.1 alnsn }
954 1.1 alnsn
955 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
956 1.1 alnsn {
957 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
958 1.5 alnsn CHECK_ARGUMENT(compiler->scratches >= 0);
959 1.1 alnsn if (op != SLJIT_UNUSED) {
960 1.5 alnsn CHECK_ARGUMENT(op >= SLJIT_MOV && op <= SLJIT_MOV_P);
961 1.1 alnsn FUNCTION_CHECK_SRC(src, srcw);
962 1.1 alnsn }
963 1.1 alnsn else
964 1.5 alnsn CHECK_ARGUMENT(src == 0 && srcw == 0);
965 1.5.16.1 pgoyette compiler->last_flags = 0;
966 1.1 alnsn #endif
967 1.1 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
968 1.1 alnsn if (SLJIT_UNLIKELY(!!compiler->verbose)) {
969 1.1 alnsn if (op == SLJIT_UNUSED)
970 1.1 alnsn fprintf(compiler->verbose, " return\n");
971 1.1 alnsn else {
972 1.5 alnsn fprintf(compiler->verbose, " return%s ", op1_names[op - SLJIT_OP1_BASE]);
973 1.5 alnsn sljit_verbose_param(compiler, src, srcw);
974 1.1 alnsn fprintf(compiler->verbose, "\n");
975 1.1 alnsn }
976 1.1 alnsn }
977 1.1 alnsn #endif
978 1.5 alnsn CHECK_RETURN_OK;
979 1.1 alnsn }
980 1.1 alnsn
981 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
982 1.1 alnsn {
983 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
984 1.1 alnsn FUNCTION_CHECK_DST(dst, dstw);
985 1.5.16.1 pgoyette compiler->last_flags = 0;
986 1.1 alnsn #endif
987 1.1 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
988 1.1 alnsn if (SLJIT_UNLIKELY(!!compiler->verbose)) {
989 1.1 alnsn fprintf(compiler->verbose, " fast_enter ");
990 1.5 alnsn sljit_verbose_param(compiler, dst, dstw);
991 1.1 alnsn fprintf(compiler->verbose, "\n");
992 1.1 alnsn }
993 1.1 alnsn #endif
994 1.5 alnsn CHECK_RETURN_OK;
995 1.1 alnsn }
996 1.1 alnsn
997 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fast_return(struct sljit_compiler *compiler, sljit_s32 src, sljit_sw srcw)
998 1.1 alnsn {
999 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1000 1.1 alnsn FUNCTION_CHECK_SRC(src, srcw);
1001 1.5.16.1 pgoyette compiler->last_flags = 0;
1002 1.1 alnsn #endif
1003 1.1 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1004 1.1 alnsn if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1005 1.1 alnsn fprintf(compiler->verbose, " fast_return ");
1006 1.5 alnsn sljit_verbose_param(compiler, src, srcw);
1007 1.1 alnsn fprintf(compiler->verbose, "\n");
1008 1.1 alnsn }
1009 1.1 alnsn #endif
1010 1.5 alnsn CHECK_RETURN_OK;
1011 1.1 alnsn }
1012 1.1 alnsn
1013 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op)
1014 1.1 alnsn {
1015 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1016 1.5 alnsn CHECK_ARGUMENT((op >= SLJIT_BREAKPOINT && op <= SLJIT_LMUL_SW)
1017 1.5 alnsn || ((op & ~SLJIT_I32_OP) >= SLJIT_DIVMOD_UW && (op & ~SLJIT_I32_OP) <= SLJIT_DIV_SW));
1018 1.5 alnsn CHECK_ARGUMENT(op < SLJIT_LMUL_UW || compiler->scratches >= 2);
1019 1.5.16.1 pgoyette if (op >= SLJIT_LMUL_UW)
1020 1.5.16.1 pgoyette compiler->last_flags = 0;
1021 1.5 alnsn #endif
1022 1.1 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1023 1.1 alnsn if (SLJIT_UNLIKELY(!!compiler->verbose))
1024 1.5 alnsn {
1025 1.5 alnsn fprintf(compiler->verbose, " %s", op0_names[GET_OPCODE(op) - SLJIT_OP0_BASE]);
1026 1.5 alnsn if (GET_OPCODE(op) >= SLJIT_DIVMOD_UW) {
1027 1.5 alnsn fprintf(compiler->verbose, (op & SLJIT_I32_OP) ? "32" : "w");
1028 1.5 alnsn }
1029 1.5 alnsn fprintf(compiler->verbose, "\n");
1030 1.5 alnsn }
1031 1.1 alnsn #endif
1032 1.5 alnsn CHECK_RETURN_OK;
1033 1.1 alnsn }
1034 1.1 alnsn
1035 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op,
1036 1.5 alnsn sljit_s32 dst, sljit_sw dstw,
1037 1.5 alnsn sljit_s32 src, sljit_sw srcw)
1038 1.1 alnsn {
1039 1.1 alnsn if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1040 1.1 alnsn compiler->skip_checks = 0;
1041 1.5 alnsn CHECK_RETURN_OK;
1042 1.1 alnsn }
1043 1.1 alnsn
1044 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1045 1.5 alnsn CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_MOV && GET_OPCODE(op) <= SLJIT_CLZ);
1046 1.5.16.1 pgoyette
1047 1.5.16.1 pgoyette switch (GET_OPCODE(op)) {
1048 1.5.16.1 pgoyette case SLJIT_NOT:
1049 1.5.16.1 pgoyette case SLJIT_CLZ:
1050 1.5.16.1 pgoyette CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1051 1.5.16.1 pgoyette break;
1052 1.5.16.1 pgoyette case SLJIT_NEG:
1053 1.5.16.1 pgoyette CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1054 1.5.16.1 pgoyette || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW
1055 1.5.16.1 pgoyette || GET_FLAG_TYPE(op) == SLJIT_NOT_OVERFLOW);
1056 1.5.16.1 pgoyette break;
1057 1.5.16.1 pgoyette case SLJIT_MOV:
1058 1.5.16.1 pgoyette case SLJIT_MOV_U32:
1059 1.5.16.1 pgoyette case SLJIT_MOV_P:
1060 1.5.16.1 pgoyette case SLJIT_MOVU:
1061 1.5.16.1 pgoyette case SLJIT_MOVU_U32:
1062 1.5.16.1 pgoyette case SLJIT_MOVU_P:
1063 1.5.16.1 pgoyette /* Nothing allowed */
1064 1.5.16.1 pgoyette CHECK_ARGUMENT(!(op & (SLJIT_I32_OP | SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1065 1.5.16.1 pgoyette break;
1066 1.5.16.1 pgoyette default:
1067 1.5.16.1 pgoyette /* Only SLJIT_I32_OP or SLJIT_F32_OP is allowed. */
1068 1.5.16.1 pgoyette CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1069 1.5.16.1 pgoyette break;
1070 1.5.16.1 pgoyette }
1071 1.5.16.1 pgoyette
1072 1.1 alnsn FUNCTION_CHECK_SRC(src, srcw);
1073 1.1 alnsn FUNCTION_CHECK_DST(dst, dstw);
1074 1.5.16.1 pgoyette
1075 1.5.16.1 pgoyette if (GET_OPCODE(op) >= SLJIT_NOT)
1076 1.5.16.1 pgoyette compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_I32_OP | SLJIT_SET_Z));
1077 1.5.16.1 pgoyette else if (GET_OPCODE(op) >= SLJIT_MOVU) {
1078 1.5.16.1 pgoyette CHECK_ARGUMENT(!(src & SLJIT_MEM) || (src & REG_MASK) != SLJIT_SP);
1079 1.5.16.1 pgoyette CHECK_ARGUMENT(!(dst & SLJIT_MEM) || (dst & REG_MASK) != SLJIT_SP);
1080 1.5.16.1 pgoyette if ((src & REG_MASK) != SLJIT_UNUSED) {
1081 1.5.16.1 pgoyette CHECK_ARGUMENT((src & REG_MASK) != (dst & REG_MASK) && (src & REG_MASK) != OFFS_REG(dst));
1082 1.5.16.1 pgoyette CHECK_ARGUMENT((src & OFFS_REG_MASK) == SLJIT_UNUSED || srcw == 0);
1083 1.5.16.1 pgoyette }
1084 1.5.16.1 pgoyette if ((dst & REG_MASK) != SLJIT_UNUSED) {
1085 1.5.16.1 pgoyette CHECK_ARGUMENT((dst & REG_MASK) != OFFS_REG(src));
1086 1.5.16.1 pgoyette CHECK_ARGUMENT((dst & OFFS_REG_MASK) == SLJIT_UNUSED || dstw == 0);
1087 1.5.16.1 pgoyette }
1088 1.5.16.1 pgoyette compiler->last_flags = 0;
1089 1.5.16.1 pgoyette }
1090 1.1 alnsn #endif
1091 1.1 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1092 1.1 alnsn if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1093 1.5 alnsn if (GET_OPCODE(op) <= SLJIT_MOVU_P)
1094 1.5 alnsn {
1095 1.5 alnsn fprintf(compiler->verbose, " mov%s%s%s ", (GET_OPCODE(op) >= SLJIT_MOVU) ? "u" : "",
1096 1.5 alnsn !(op & SLJIT_I32_OP) ? "" : "32", (op != SLJIT_MOV32 && op != SLJIT_MOVU32) ? op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE] : "");
1097 1.5 alnsn }
1098 1.5 alnsn else
1099 1.5 alnsn {
1100 1.5.16.1 pgoyette fprintf(compiler->verbose, " %s%s%s%s%s ", op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE], !(op & SLJIT_I32_OP) ? "" : "32",
1101 1.5.16.1 pgoyette !(op & SLJIT_SET_Z) ? "" : ".z", !(op & VARIABLE_FLAG_MASK) ? "" : ".",
1102 1.5.16.1 pgoyette !(op & VARIABLE_FLAG_MASK) ? "" : jump_names[GET_FLAG_TYPE(op)]);
1103 1.5 alnsn }
1104 1.5 alnsn
1105 1.5 alnsn sljit_verbose_param(compiler, dst, dstw);
1106 1.1 alnsn fprintf(compiler->verbose, ", ");
1107 1.5 alnsn sljit_verbose_param(compiler, src, srcw);
1108 1.1 alnsn fprintf(compiler->verbose, "\n");
1109 1.1 alnsn }
1110 1.1 alnsn #endif
1111 1.5 alnsn CHECK_RETURN_OK;
1112 1.1 alnsn }
1113 1.1 alnsn
1114 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op,
1115 1.5 alnsn sljit_s32 dst, sljit_sw dstw,
1116 1.5 alnsn sljit_s32 src1, sljit_sw src1w,
1117 1.5 alnsn sljit_s32 src2, sljit_sw src2w)
1118 1.1 alnsn {
1119 1.1 alnsn if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1120 1.1 alnsn compiler->skip_checks = 0;
1121 1.5 alnsn CHECK_RETURN_OK;
1122 1.1 alnsn }
1123 1.1 alnsn
1124 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1125 1.5 alnsn CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_ADD && GET_OPCODE(op) <= SLJIT_ASHR);
1126 1.5.16.1 pgoyette
1127 1.5.16.1 pgoyette switch (GET_OPCODE(op)) {
1128 1.5.16.1 pgoyette case SLJIT_AND:
1129 1.5.16.1 pgoyette case SLJIT_OR:
1130 1.5.16.1 pgoyette case SLJIT_XOR:
1131 1.5.16.1 pgoyette case SLJIT_SHL:
1132 1.5.16.1 pgoyette case SLJIT_LSHR:
1133 1.5.16.1 pgoyette case SLJIT_ASHR:
1134 1.5.16.1 pgoyette CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1135 1.5.16.1 pgoyette break;
1136 1.5.16.1 pgoyette case SLJIT_MUL:
1137 1.5.16.1 pgoyette CHECK_ARGUMENT(!(op & SLJIT_SET_Z));
1138 1.5.16.1 pgoyette CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1139 1.5.16.1 pgoyette || GET_FLAG_TYPE(op) == SLJIT_MUL_OVERFLOW
1140 1.5.16.1 pgoyette || GET_FLAG_TYPE(op) == SLJIT_MUL_NOT_OVERFLOW);
1141 1.5.16.1 pgoyette break;
1142 1.5.16.1 pgoyette case SLJIT_ADD:
1143 1.5.16.1 pgoyette CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1144 1.5.16.1 pgoyette || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY)
1145 1.5.16.1 pgoyette || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW
1146 1.5.16.1 pgoyette || GET_FLAG_TYPE(op) == SLJIT_NOT_OVERFLOW);
1147 1.5.16.1 pgoyette break;
1148 1.5.16.1 pgoyette case SLJIT_SUB:
1149 1.5.16.1 pgoyette CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1150 1.5.16.1 pgoyette || (GET_FLAG_TYPE(op) >= SLJIT_LESS && GET_FLAG_TYPE(op) <= SLJIT_NOT_OVERFLOW)
1151 1.5.16.1 pgoyette || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1152 1.5.16.1 pgoyette break;
1153 1.5.16.1 pgoyette case SLJIT_ADDC:
1154 1.5.16.1 pgoyette case SLJIT_SUBC:
1155 1.5.16.1 pgoyette CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1156 1.5.16.1 pgoyette || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1157 1.5.16.1 pgoyette CHECK_ARGUMENT((compiler->last_flags & 0xff) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1158 1.5.16.1 pgoyette CHECK_ARGUMENT((op & SLJIT_I32_OP) == (compiler->last_flags & SLJIT_I32_OP));
1159 1.5.16.1 pgoyette break;
1160 1.5.16.1 pgoyette default:
1161 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
1162 1.5.16.1 pgoyette break;
1163 1.5.16.1 pgoyette }
1164 1.5.16.1 pgoyette
1165 1.1 alnsn FUNCTION_CHECK_SRC(src1, src1w);
1166 1.1 alnsn FUNCTION_CHECK_SRC(src2, src2w);
1167 1.1 alnsn FUNCTION_CHECK_DST(dst, dstw);
1168 1.5.16.1 pgoyette compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_I32_OP | SLJIT_SET_Z));
1169 1.1 alnsn #endif
1170 1.1 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1171 1.1 alnsn if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1172 1.5.16.1 pgoyette fprintf(compiler->verbose, " %s%s%s%s%s ", op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE], !(op & SLJIT_I32_OP) ? "" : "32",
1173 1.5.16.1 pgoyette !(op & SLJIT_SET_Z) ? "" : ".z", !(op & VARIABLE_FLAG_MASK) ? "" : ".",
1174 1.5.16.1 pgoyette !(op & VARIABLE_FLAG_MASK) ? "" : jump_names[GET_FLAG_TYPE(op)]);
1175 1.5 alnsn sljit_verbose_param(compiler, dst, dstw);
1176 1.1 alnsn fprintf(compiler->verbose, ", ");
1177 1.5 alnsn sljit_verbose_param(compiler, src1, src1w);
1178 1.1 alnsn fprintf(compiler->verbose, ", ");
1179 1.5 alnsn sljit_verbose_param(compiler, src2, src2w);
1180 1.1 alnsn fprintf(compiler->verbose, "\n");
1181 1.1 alnsn }
1182 1.1 alnsn #endif
1183 1.5 alnsn CHECK_RETURN_OK;
1184 1.1 alnsn }
1185 1.1 alnsn
1186 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_register_index(sljit_s32 reg)
1187 1.1 alnsn {
1188 1.1 alnsn SLJIT_UNUSED_ARG(reg);
1189 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1190 1.5 alnsn CHECK_ARGUMENT(reg > 0 && reg <= SLJIT_NUMBER_OF_REGISTERS);
1191 1.5 alnsn #endif
1192 1.5 alnsn CHECK_RETURN_OK;
1193 1.1 alnsn }
1194 1.1 alnsn
1195 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_float_register_index(sljit_s32 reg)
1196 1.3 alnsn {
1197 1.3 alnsn SLJIT_UNUSED_ARG(reg);
1198 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1199 1.5 alnsn CHECK_ARGUMENT(reg > 0 && reg <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1200 1.5 alnsn #endif
1201 1.5 alnsn CHECK_RETURN_OK;
1202 1.3 alnsn }
1203 1.3 alnsn
1204 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_custom(struct sljit_compiler *compiler,
1205 1.5 alnsn void *instruction, sljit_s32 size)
1206 1.1 alnsn {
1207 1.5 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1208 1.5 alnsn int i;
1209 1.5 alnsn #endif
1210 1.5 alnsn
1211 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
1212 1.5 alnsn
1213 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1214 1.5 alnsn CHECK_ARGUMENT(instruction);
1215 1.5.16.1 pgoyette
1216 1.5 alnsn #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
1217 1.5 alnsn CHECK_ARGUMENT(size > 0 && size < 16);
1218 1.5 alnsn #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
1219 1.5 alnsn CHECK_ARGUMENT((size == 2 && (((sljit_sw)instruction) & 0x1) == 0)
1220 1.5 alnsn || (size == 4 && (((sljit_sw)instruction) & 0x3) == 0));
1221 1.5 alnsn #else
1222 1.5 alnsn CHECK_ARGUMENT(size == 4 && (((sljit_sw)instruction) & 0x3) == 0);
1223 1.5 alnsn #endif
1224 1.5 alnsn
1225 1.5.16.1 pgoyette compiler->last_flags = 0;
1226 1.5 alnsn #endif
1227 1.5 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1228 1.5 alnsn if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1229 1.5 alnsn fprintf(compiler->verbose, " op_custom");
1230 1.5 alnsn for (i = 0; i < size; i++)
1231 1.5 alnsn fprintf(compiler->verbose, " 0x%x", ((sljit_u8*)instruction)[i]);
1232 1.5 alnsn fprintf(compiler->verbose, "\n");
1233 1.5 alnsn }
1234 1.5 alnsn #endif
1235 1.5 alnsn CHECK_RETURN_OK;
1236 1.1 alnsn }
1237 1.1 alnsn
1238 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,
1239 1.5 alnsn sljit_s32 dst, sljit_sw dstw,
1240 1.5 alnsn sljit_s32 src, sljit_sw srcw)
1241 1.1 alnsn {
1242 1.5 alnsn if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1243 1.5 alnsn compiler->skip_checks = 0;
1244 1.5 alnsn CHECK_RETURN_OK;
1245 1.5 alnsn }
1246 1.5 alnsn
1247 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1248 1.5 alnsn CHECK_ARGUMENT(sljit_is_fpu_available());
1249 1.5 alnsn CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_MOV_F64 && GET_OPCODE(op) <= SLJIT_ABS_F64);
1250 1.5.16.1 pgoyette CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1251 1.5 alnsn FUNCTION_FCHECK(src, srcw);
1252 1.5 alnsn FUNCTION_FCHECK(dst, dstw);
1253 1.5 alnsn #endif
1254 1.5 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1255 1.5 alnsn if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1256 1.5 alnsn if (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_F32)
1257 1.5 alnsn fprintf(compiler->verbose, " %s%s ", fop1_names[SLJIT_CONV_F64_FROM_F32 - SLJIT_FOP1_BASE],
1258 1.5 alnsn (op & SLJIT_F32_OP) ? ".f32.from.f64" : ".f64.from.f32");
1259 1.5 alnsn else
1260 1.5 alnsn fprintf(compiler->verbose, " %s%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1261 1.5 alnsn (op & SLJIT_F32_OP) ? ".f32" : ".f64");
1262 1.5 alnsn
1263 1.5 alnsn sljit_verbose_fparam(compiler, dst, dstw);
1264 1.5 alnsn fprintf(compiler->verbose, ", ");
1265 1.5 alnsn sljit_verbose_fparam(compiler, src, srcw);
1266 1.5 alnsn fprintf(compiler->verbose, "\n");
1267 1.5 alnsn }
1268 1.5 alnsn #endif
1269 1.5 alnsn CHECK_RETURN_OK;
1270 1.5 alnsn }
1271 1.1 alnsn
1272 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_cmp(struct sljit_compiler *compiler, sljit_s32 op,
1273 1.5 alnsn sljit_s32 src1, sljit_sw src1w,
1274 1.5 alnsn sljit_s32 src2, sljit_sw src2w)
1275 1.5 alnsn {
1276 1.5.16.1 pgoyette #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1277 1.5.16.1 pgoyette compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_I32_OP | SLJIT_SET_Z));
1278 1.5.16.1 pgoyette #endif
1279 1.5.16.1 pgoyette
1280 1.1 alnsn if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1281 1.1 alnsn compiler->skip_checks = 0;
1282 1.5 alnsn CHECK_RETURN_OK;
1283 1.5 alnsn }
1284 1.5 alnsn
1285 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1286 1.5 alnsn CHECK_ARGUMENT(sljit_is_fpu_available());
1287 1.5 alnsn CHECK_ARGUMENT(GET_OPCODE(op) == SLJIT_CMP_F64);
1288 1.5.16.1 pgoyette CHECK_ARGUMENT(!(op & SLJIT_SET_Z));
1289 1.5.16.1 pgoyette CHECK_ARGUMENT((op & VARIABLE_FLAG_MASK)
1290 1.5.16.1 pgoyette || (GET_FLAG_TYPE(op) >= SLJIT_EQUAL_F64 && GET_FLAG_TYPE(op) <= SLJIT_ORDERED_F64));
1291 1.5 alnsn FUNCTION_FCHECK(src1, src1w);
1292 1.5 alnsn FUNCTION_FCHECK(src2, src2w);
1293 1.5 alnsn #endif
1294 1.5 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1295 1.5 alnsn if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1296 1.5.16.1 pgoyette fprintf(compiler->verbose, " %s%s", fop1_names[SLJIT_CMP_F64 - SLJIT_FOP1_BASE], (op & SLJIT_F32_OP) ? ".f32" : ".f64");
1297 1.5.16.1 pgoyette if (op & VARIABLE_FLAG_MASK) {
1298 1.5.16.1 pgoyette fprintf(compiler->verbose, ".%s_f", jump_names[GET_FLAG_TYPE(op)]);
1299 1.5.16.1 pgoyette }
1300 1.5.16.1 pgoyette fprintf(compiler->verbose, " ");
1301 1.5 alnsn sljit_verbose_fparam(compiler, src1, src1w);
1302 1.5 alnsn fprintf(compiler->verbose, ", ");
1303 1.5 alnsn sljit_verbose_fparam(compiler, src2, src2w);
1304 1.5 alnsn fprintf(compiler->verbose, "\n");
1305 1.1 alnsn }
1306 1.1 alnsn #endif
1307 1.5 alnsn CHECK_RETURN_OK;
1308 1.5 alnsn }
1309 1.1 alnsn
1310 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_conv_sw_from_f64(struct sljit_compiler *compiler, sljit_s32 op,
1311 1.5 alnsn sljit_s32 dst, sljit_sw dstw,
1312 1.5 alnsn sljit_s32 src, sljit_sw srcw)
1313 1.5 alnsn {
1314 1.5 alnsn if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1315 1.5 alnsn compiler->skip_checks = 0;
1316 1.5 alnsn CHECK_RETURN_OK;
1317 1.5 alnsn }
1318 1.5 alnsn
1319 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1320 1.5 alnsn CHECK_ARGUMENT(sljit_is_fpu_available());
1321 1.5 alnsn CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_CONV_SW_FROM_F64 && GET_OPCODE(op) <= SLJIT_CONV_S32_FROM_F64);
1322 1.5.16.1 pgoyette CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1323 1.1 alnsn FUNCTION_FCHECK(src, srcw);
1324 1.5 alnsn FUNCTION_CHECK_DST(dst, dstw);
1325 1.1 alnsn #endif
1326 1.1 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1327 1.1 alnsn if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1328 1.5 alnsn fprintf(compiler->verbose, " %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1329 1.5 alnsn (GET_OPCODE(op) == SLJIT_CONV_S32_FROM_F64) ? ".s32" : ".sw",
1330 1.5 alnsn (op & SLJIT_F32_OP) ? ".f32" : ".f64");
1331 1.5 alnsn sljit_verbose_param(compiler, dst, dstw);
1332 1.1 alnsn fprintf(compiler->verbose, ", ");
1333 1.5 alnsn sljit_verbose_fparam(compiler, src, srcw);
1334 1.1 alnsn fprintf(compiler->verbose, "\n");
1335 1.1 alnsn }
1336 1.1 alnsn #endif
1337 1.5 alnsn CHECK_RETURN_OK;
1338 1.1 alnsn }
1339 1.1 alnsn
1340 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_conv_f64_from_sw(struct sljit_compiler *compiler, sljit_s32 op,
1341 1.5 alnsn sljit_s32 dst, sljit_sw dstw,
1342 1.5 alnsn sljit_s32 src, sljit_sw srcw)
1343 1.1 alnsn {
1344 1.5 alnsn if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1345 1.5 alnsn compiler->skip_checks = 0;
1346 1.5 alnsn CHECK_RETURN_OK;
1347 1.5 alnsn }
1348 1.5 alnsn
1349 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1350 1.5 alnsn CHECK_ARGUMENT(sljit_is_fpu_available());
1351 1.5 alnsn CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_CONV_F64_FROM_SW && GET_OPCODE(op) <= SLJIT_CONV_F64_FROM_S32);
1352 1.5.16.1 pgoyette CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1353 1.5 alnsn FUNCTION_CHECK_SRC(src, srcw);
1354 1.5 alnsn FUNCTION_FCHECK(dst, dstw);
1355 1.5 alnsn #endif
1356 1.5 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1357 1.5 alnsn if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1358 1.5 alnsn fprintf(compiler->verbose, " %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1359 1.5 alnsn (op & SLJIT_F32_OP) ? ".f32" : ".f64",
1360 1.5 alnsn (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_S32) ? ".s32" : ".sw");
1361 1.5 alnsn sljit_verbose_fparam(compiler, dst, dstw);
1362 1.5 alnsn fprintf(compiler->verbose, ", ");
1363 1.5 alnsn sljit_verbose_param(compiler, src, srcw);
1364 1.5 alnsn fprintf(compiler->verbose, "\n");
1365 1.5 alnsn }
1366 1.5 alnsn #endif
1367 1.5 alnsn CHECK_RETURN_OK;
1368 1.5 alnsn }
1369 1.1 alnsn
1370 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op,
1371 1.5 alnsn sljit_s32 dst, sljit_sw dstw,
1372 1.5 alnsn sljit_s32 src1, sljit_sw src1w,
1373 1.5 alnsn sljit_s32 src2, sljit_sw src2w)
1374 1.5 alnsn {
1375 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1376 1.5 alnsn CHECK_ARGUMENT(sljit_is_fpu_available());
1377 1.5 alnsn CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_ADD_F64 && GET_OPCODE(op) <= SLJIT_DIV_F64);
1378 1.5.16.1 pgoyette CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1379 1.1 alnsn FUNCTION_FCHECK(src1, src1w);
1380 1.1 alnsn FUNCTION_FCHECK(src2, src2w);
1381 1.1 alnsn FUNCTION_FCHECK(dst, dstw);
1382 1.1 alnsn #endif
1383 1.1 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1384 1.1 alnsn if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1385 1.5 alnsn fprintf(compiler->verbose, " %s%s ", fop2_names[GET_OPCODE(op) - SLJIT_FOP2_BASE], (op & SLJIT_F32_OP) ? ".f32" : ".f64");
1386 1.5 alnsn sljit_verbose_fparam(compiler, dst, dstw);
1387 1.1 alnsn fprintf(compiler->verbose, ", ");
1388 1.5 alnsn sljit_verbose_fparam(compiler, src1, src1w);
1389 1.1 alnsn fprintf(compiler->verbose, ", ");
1390 1.5 alnsn sljit_verbose_fparam(compiler, src2, src2w);
1391 1.1 alnsn fprintf(compiler->verbose, "\n");
1392 1.1 alnsn }
1393 1.1 alnsn #endif
1394 1.5 alnsn CHECK_RETURN_OK;
1395 1.1 alnsn }
1396 1.1 alnsn
1397 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_label(struct sljit_compiler *compiler)
1398 1.1 alnsn {
1399 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
1400 1.1 alnsn
1401 1.5.16.1 pgoyette #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1402 1.5.16.1 pgoyette compiler->last_flags = 0;
1403 1.5.16.1 pgoyette #endif
1404 1.5.16.1 pgoyette
1405 1.1 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1406 1.1 alnsn if (SLJIT_UNLIKELY(!!compiler->verbose))
1407 1.1 alnsn fprintf(compiler->verbose, "label:\n");
1408 1.1 alnsn #endif
1409 1.5 alnsn CHECK_RETURN_OK;
1410 1.1 alnsn }
1411 1.1 alnsn
1412 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type)
1413 1.1 alnsn {
1414 1.1 alnsn if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1415 1.1 alnsn compiler->skip_checks = 0;
1416 1.5 alnsn CHECK_RETURN_OK;
1417 1.1 alnsn }
1418 1.5 alnsn
1419 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1420 1.5 alnsn CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_I32_OP)));
1421 1.5.16.1 pgoyette CHECK_ARGUMENT((type & 0xff) != GET_FLAG_TYPE(SLJIT_SET_CARRY) && (type & 0xff) != (GET_FLAG_TYPE(SLJIT_SET_CARRY) + 1));
1422 1.5 alnsn CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_CALL3);
1423 1.5 alnsn CHECK_ARGUMENT((type & 0xff) < SLJIT_JUMP || !(type & SLJIT_I32_OP));
1424 1.5 alnsn CHECK_ARGUMENT((type & 0xff) <= SLJIT_CALL0 || ((type & 0xff) - SLJIT_CALL0) <= compiler->scratches);
1425 1.5.16.1 pgoyette
1426 1.5.16.1 pgoyette if ((type & 0xff) < SLJIT_JUMP) {
1427 1.5.16.1 pgoyette if ((type & 0xff) <= SLJIT_NOT_ZERO)
1428 1.5.16.1 pgoyette CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
1429 1.5.16.1 pgoyette else
1430 1.5.16.1 pgoyette CHECK_ARGUMENT((type & 0xff) == (compiler->last_flags & 0xff));
1431 1.5.16.1 pgoyette CHECK_ARGUMENT((type & SLJIT_I32_OP) == (compiler->last_flags & SLJIT_I32_OP));
1432 1.5.16.1 pgoyette }
1433 1.1 alnsn #endif
1434 1.1 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1435 1.1 alnsn if (SLJIT_UNLIKELY(!!compiler->verbose))
1436 1.5 alnsn fprintf(compiler->verbose, " jump%s %s%s\n", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1437 1.5 alnsn jump_names[type & 0xff], JUMP_POSTFIX(type));
1438 1.1 alnsn #endif
1439 1.5 alnsn CHECK_RETURN_OK;
1440 1.1 alnsn }
1441 1.1 alnsn
1442 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
1443 1.5 alnsn sljit_s32 src1, sljit_sw src1w,
1444 1.5 alnsn sljit_s32 src2, sljit_sw src2w)
1445 1.1 alnsn {
1446 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1447 1.5 alnsn CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_I32_OP)));
1448 1.5 alnsn CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_SIG_LESS_EQUAL);
1449 1.1 alnsn FUNCTION_CHECK_SRC(src1, src1w);
1450 1.1 alnsn FUNCTION_CHECK_SRC(src2, src2w);
1451 1.5.16.1 pgoyette compiler->last_flags = 0;
1452 1.1 alnsn #endif
1453 1.1 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1454 1.1 alnsn if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1455 1.5 alnsn fprintf(compiler->verbose, " cmp%s %s%s, ", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1456 1.5 alnsn jump_names[type & 0xff], (type & SLJIT_I32_OP) ? "32" : "");
1457 1.5 alnsn sljit_verbose_param(compiler, src1, src1w);
1458 1.1 alnsn fprintf(compiler->verbose, ", ");
1459 1.5 alnsn sljit_verbose_param(compiler, src2, src2w);
1460 1.1 alnsn fprintf(compiler->verbose, "\n");
1461 1.1 alnsn }
1462 1.1 alnsn #endif
1463 1.5 alnsn CHECK_RETURN_OK;
1464 1.1 alnsn }
1465 1.1 alnsn
1466 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
1467 1.5 alnsn sljit_s32 src1, sljit_sw src1w,
1468 1.5 alnsn sljit_s32 src2, sljit_sw src2w)
1469 1.1 alnsn {
1470 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1471 1.5 alnsn CHECK_ARGUMENT(sljit_is_fpu_available());
1472 1.5 alnsn CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_F32_OP)));
1473 1.5 alnsn CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL_F64 && (type & 0xff) <= SLJIT_ORDERED_F64);
1474 1.1 alnsn FUNCTION_FCHECK(src1, src1w);
1475 1.1 alnsn FUNCTION_FCHECK(src2, src2w);
1476 1.5.16.1 pgoyette compiler->last_flags = 0;
1477 1.1 alnsn #endif
1478 1.1 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1479 1.1 alnsn if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1480 1.5 alnsn fprintf(compiler->verbose, " fcmp%s %s%s, ", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1481 1.5 alnsn jump_names[type & 0xff], (type & SLJIT_F32_OP) ? ".f32" : ".f64");
1482 1.5 alnsn sljit_verbose_fparam(compiler, src1, src1w);
1483 1.1 alnsn fprintf(compiler->verbose, ", ");
1484 1.5 alnsn sljit_verbose_fparam(compiler, src2, src2w);
1485 1.1 alnsn fprintf(compiler->verbose, "\n");
1486 1.1 alnsn }
1487 1.1 alnsn #endif
1488 1.5 alnsn CHECK_RETURN_OK;
1489 1.1 alnsn }
1490 1.1 alnsn
1491 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw)
1492 1.1 alnsn {
1493 1.5.16.1 pgoyette #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1494 1.5.16.1 pgoyette compiler->last_flags = 0;
1495 1.5.16.1 pgoyette #endif
1496 1.5.16.1 pgoyette
1497 1.3 alnsn if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1498 1.3 alnsn compiler->skip_checks = 0;
1499 1.5 alnsn CHECK_RETURN_OK;
1500 1.3 alnsn }
1501 1.3 alnsn
1502 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1503 1.5 alnsn CHECK_ARGUMENT(type >= SLJIT_JUMP && type <= SLJIT_CALL3);
1504 1.5 alnsn CHECK_ARGUMENT(type <= SLJIT_CALL0 || (type - SLJIT_CALL0) <= compiler->scratches);
1505 1.1 alnsn FUNCTION_CHECK_SRC(src, srcw);
1506 1.1 alnsn #endif
1507 1.1 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1508 1.1 alnsn if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1509 1.3 alnsn fprintf(compiler->verbose, " ijump.%s ", jump_names[type]);
1510 1.5 alnsn sljit_verbose_param(compiler, src, srcw);
1511 1.1 alnsn fprintf(compiler->verbose, "\n");
1512 1.1 alnsn }
1513 1.1 alnsn #endif
1514 1.5 alnsn CHECK_RETURN_OK;
1515 1.1 alnsn }
1516 1.1 alnsn
1517 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op,
1518 1.5 alnsn sljit_s32 dst, sljit_sw dstw,
1519 1.5 alnsn sljit_s32 src, sljit_sw srcw,
1520 1.5 alnsn sljit_s32 type)
1521 1.5 alnsn {
1522 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1523 1.5 alnsn CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_I32_OP)));
1524 1.5 alnsn CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_ORDERED_F64);
1525 1.5.16.1 pgoyette CHECK_ARGUMENT((type & 0xff) != GET_FLAG_TYPE(SLJIT_SET_CARRY) && (type & 0xff) != (GET_FLAG_TYPE(SLJIT_SET_CARRY) + 1));
1526 1.5 alnsn CHECK_ARGUMENT(op == SLJIT_MOV || GET_OPCODE(op) == SLJIT_MOV_U32 || GET_OPCODE(op) == SLJIT_MOV_S32
1527 1.3 alnsn || (GET_OPCODE(op) >= SLJIT_AND && GET_OPCODE(op) <= SLJIT_XOR));
1528 1.5.16.1 pgoyette CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1529 1.5.16.1 pgoyette
1530 1.5.16.1 pgoyette if ((type & 0xff) <= SLJIT_NOT_ZERO)
1531 1.5.16.1 pgoyette CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
1532 1.5.16.1 pgoyette else
1533 1.5.16.1 pgoyette CHECK_ARGUMENT((type & 0xff) == (compiler->last_flags & 0xff));
1534 1.5.16.1 pgoyette
1535 1.3 alnsn if (GET_OPCODE(op) < SLJIT_ADD) {
1536 1.5 alnsn CHECK_ARGUMENT(src == SLJIT_UNUSED && srcw == 0);
1537 1.3 alnsn } else {
1538 1.5 alnsn CHECK_ARGUMENT(src == dst && srcw == dstw);
1539 1.5.16.1 pgoyette compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_I32_OP | SLJIT_SET_Z));
1540 1.3 alnsn }
1541 1.1 alnsn FUNCTION_CHECK_DST(dst, dstw);
1542 1.1 alnsn #endif
1543 1.1 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1544 1.1 alnsn if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1545 1.5.16.1 pgoyette fprintf(compiler->verbose, " flags%s %s%s, ",
1546 1.5.16.1 pgoyette !(op & SLJIT_SET_Z) ? "" : ".z",
1547 1.5 alnsn GET_OPCODE(op) < SLJIT_OP2_BASE ? "mov" : op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE],
1548 1.5 alnsn GET_OPCODE(op) < SLJIT_OP2_BASE ? op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE] : ((op & SLJIT_I32_OP) ? "32" : ""));
1549 1.5 alnsn sljit_verbose_param(compiler, dst, dstw);
1550 1.3 alnsn if (src != SLJIT_UNUSED) {
1551 1.3 alnsn fprintf(compiler->verbose, ", ");
1552 1.5 alnsn sljit_verbose_param(compiler, src, srcw);
1553 1.3 alnsn }
1554 1.5 alnsn fprintf(compiler->verbose, ", %s%s\n", jump_names[type & 0xff], JUMP_POSTFIX(type));
1555 1.1 alnsn }
1556 1.1 alnsn #endif
1557 1.5 alnsn CHECK_RETURN_OK;
1558 1.1 alnsn }
1559 1.1 alnsn
1560 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
1561 1.1 alnsn {
1562 1.1 alnsn SLJIT_UNUSED_ARG(offset);
1563 1.1 alnsn
1564 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1565 1.1 alnsn FUNCTION_CHECK_DST(dst, dstw);
1566 1.1 alnsn #endif
1567 1.1 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1568 1.1 alnsn if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1569 1.1 alnsn fprintf(compiler->verbose, " local_base ");
1570 1.5 alnsn sljit_verbose_param(compiler, dst, dstw);
1571 1.1 alnsn fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", offset);
1572 1.1 alnsn }
1573 1.1 alnsn #endif
1574 1.5 alnsn CHECK_RETURN_OK;
1575 1.1 alnsn }
1576 1.1 alnsn
1577 1.5 alnsn static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value)
1578 1.1 alnsn {
1579 1.1 alnsn SLJIT_UNUSED_ARG(init_value);
1580 1.1 alnsn
1581 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1582 1.1 alnsn FUNCTION_CHECK_DST(dst, dstw);
1583 1.1 alnsn #endif
1584 1.1 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1585 1.1 alnsn if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1586 1.1 alnsn fprintf(compiler->verbose, " const ");
1587 1.5 alnsn sljit_verbose_param(compiler, dst, dstw);
1588 1.1 alnsn fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", init_value);
1589 1.1 alnsn }
1590 1.1 alnsn #endif
1591 1.5 alnsn CHECK_RETURN_OK;
1592 1.1 alnsn }
1593 1.1 alnsn
1594 1.5 alnsn #endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_VERBOSE */
1595 1.5 alnsn
1596 1.5 alnsn #define SELECT_FOP1_OPERATION_WITH_CHECKS(compiler, op, dst, dstw, src, srcw) \
1597 1.5 alnsn SLJIT_COMPILE_ASSERT(!(SLJIT_CONV_SW_FROM_F64 & 0x1) && !(SLJIT_CONV_F64_FROM_SW & 0x1), \
1598 1.5 alnsn invalid_float_opcodes); \
1599 1.5 alnsn if (GET_OPCODE(op) >= SLJIT_CONV_SW_FROM_F64 && GET_OPCODE(op) <= SLJIT_CMP_F64) { \
1600 1.5 alnsn if (GET_OPCODE(op) == SLJIT_CMP_F64) { \
1601 1.5 alnsn CHECK(check_sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw)); \
1602 1.5 alnsn ADJUST_LOCAL_OFFSET(dst, dstw); \
1603 1.5 alnsn ADJUST_LOCAL_OFFSET(src, srcw); \
1604 1.5 alnsn return sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw); \
1605 1.5 alnsn } \
1606 1.5 alnsn if ((GET_OPCODE(op) | 0x1) == SLJIT_CONV_S32_FROM_F64) { \
1607 1.5 alnsn CHECK(check_sljit_emit_fop1_conv_sw_from_f64(compiler, op, dst, dstw, src, srcw)); \
1608 1.5 alnsn ADJUST_LOCAL_OFFSET(dst, dstw); \
1609 1.5 alnsn ADJUST_LOCAL_OFFSET(src, srcw); \
1610 1.5 alnsn return sljit_emit_fop1_conv_sw_from_f64(compiler, op, dst, dstw, src, srcw); \
1611 1.5 alnsn } \
1612 1.5 alnsn CHECK(check_sljit_emit_fop1_conv_f64_from_sw(compiler, op, dst, dstw, src, srcw)); \
1613 1.5 alnsn ADJUST_LOCAL_OFFSET(dst, dstw); \
1614 1.5 alnsn ADJUST_LOCAL_OFFSET(src, srcw); \
1615 1.5 alnsn return sljit_emit_fop1_conv_f64_from_sw(compiler, op, dst, dstw, src, srcw); \
1616 1.5 alnsn } \
1617 1.5 alnsn CHECK(check_sljit_emit_fop1(compiler, op, dst, dstw, src, srcw)); \
1618 1.5 alnsn ADJUST_LOCAL_OFFSET(dst, dstw); \
1619 1.5 alnsn ADJUST_LOCAL_OFFSET(src, srcw);
1620 1.5 alnsn
1621 1.5 alnsn static SLJIT_INLINE sljit_s32 emit_mov_before_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
1622 1.1 alnsn {
1623 1.1 alnsn /* Return if don't need to do anything. */
1624 1.1 alnsn if (op == SLJIT_UNUSED)
1625 1.1 alnsn return SLJIT_SUCCESS;
1626 1.1 alnsn
1627 1.1 alnsn #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1628 1.3 alnsn /* At the moment the pointer size is always equal to sljit_sw. May be changed in the future. */
1629 1.3 alnsn if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_P))
1630 1.1 alnsn return SLJIT_SUCCESS;
1631 1.1 alnsn #else
1632 1.5 alnsn if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_U32 || op == SLJIT_MOV_S32 || op == SLJIT_MOV_P))
1633 1.1 alnsn return SLJIT_SUCCESS;
1634 1.1 alnsn #endif
1635 1.1 alnsn
1636 1.5 alnsn #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
1637 1.5 alnsn || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1638 1.1 alnsn compiler->skip_checks = 1;
1639 1.1 alnsn #endif
1640 1.1 alnsn return sljit_emit_op1(compiler, op, SLJIT_RETURN_REG, 0, src, srcw);
1641 1.1 alnsn }
1642 1.1 alnsn
1643 1.1 alnsn /* CPU description section */
1644 1.1 alnsn
1645 1.1 alnsn #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
1646 1.1 alnsn #define SLJIT_CPUINFO_PART1 " 32bit ("
1647 1.1 alnsn #elif (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1648 1.1 alnsn #define SLJIT_CPUINFO_PART1 " 64bit ("
1649 1.1 alnsn #else
1650 1.1 alnsn #error "Internal error: CPU type info missing"
1651 1.1 alnsn #endif
1652 1.1 alnsn
1653 1.1 alnsn #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1654 1.1 alnsn #define SLJIT_CPUINFO_PART2 "little endian + "
1655 1.1 alnsn #elif (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
1656 1.1 alnsn #define SLJIT_CPUINFO_PART2 "big endian + "
1657 1.1 alnsn #else
1658 1.1 alnsn #error "Internal error: CPU type info missing"
1659 1.1 alnsn #endif
1660 1.1 alnsn
1661 1.1 alnsn #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED)
1662 1.1 alnsn #define SLJIT_CPUINFO_PART3 "unaligned)"
1663 1.1 alnsn #else
1664 1.1 alnsn #define SLJIT_CPUINFO_PART3 "aligned)"
1665 1.1 alnsn #endif
1666 1.1 alnsn
1667 1.1 alnsn #define SLJIT_CPUINFO SLJIT_CPUINFO_PART1 SLJIT_CPUINFO_PART2 SLJIT_CPUINFO_PART3
1668 1.1 alnsn
1669 1.5 alnsn #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
1670 1.3 alnsn # include "sljitNativeX86_common.c"
1671 1.1 alnsn #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
1672 1.3 alnsn # include "sljitNativeARM_32.c"
1673 1.1 alnsn #elif (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
1674 1.3 alnsn # include "sljitNativeARM_32.c"
1675 1.1 alnsn #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
1676 1.3 alnsn # include "sljitNativeARM_T2_32.c"
1677 1.3 alnsn #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
1678 1.3 alnsn # include "sljitNativeARM_64.c"
1679 1.5 alnsn #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
1680 1.3 alnsn # include "sljitNativePPC_common.c"
1681 1.5 alnsn #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
1682 1.3 alnsn # include "sljitNativeMIPS_common.c"
1683 1.5 alnsn #elif (defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
1684 1.3 alnsn # include "sljitNativeSPARC_common.c"
1685 1.3 alnsn #elif (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
1686 1.3 alnsn # include "sljitNativeTILEGX_64.c"
1687 1.1 alnsn #endif
1688 1.1 alnsn
1689 1.5 alnsn #if !(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
1690 1.1 alnsn
1691 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
1692 1.5 alnsn sljit_s32 src1, sljit_sw src1w,
1693 1.5 alnsn sljit_s32 src2, sljit_sw src2w)
1694 1.1 alnsn {
1695 1.1 alnsn /* Default compare for most architectures. */
1696 1.5 alnsn sljit_s32 flags, tmp_src, condition;
1697 1.3 alnsn sljit_sw tmp_srcw;
1698 1.1 alnsn
1699 1.1 alnsn CHECK_ERROR_PTR();
1700 1.5 alnsn CHECK_PTR(check_sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w));
1701 1.1 alnsn
1702 1.1 alnsn condition = type & 0xff;
1703 1.3 alnsn #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
1704 1.5 alnsn if ((condition == SLJIT_EQUAL || condition == SLJIT_NOT_EQUAL)) {
1705 1.3 alnsn if ((src1 & SLJIT_IMM) && !src1w) {
1706 1.3 alnsn src1 = src2;
1707 1.3 alnsn src1w = src2w;
1708 1.3 alnsn src2 = SLJIT_IMM;
1709 1.3 alnsn src2w = 0;
1710 1.3 alnsn }
1711 1.3 alnsn if ((src2 & SLJIT_IMM) && !src2w)
1712 1.3 alnsn return emit_cmp_to0(compiler, type, src1, src1w);
1713 1.3 alnsn }
1714 1.3 alnsn #endif
1715 1.3 alnsn
1716 1.1 alnsn if (SLJIT_UNLIKELY((src1 & SLJIT_IMM) && !(src2 & SLJIT_IMM))) {
1717 1.1 alnsn /* Immediate is prefered as second argument by most architectures. */
1718 1.1 alnsn switch (condition) {
1719 1.5 alnsn case SLJIT_LESS:
1720 1.5 alnsn condition = SLJIT_GREATER;
1721 1.1 alnsn break;
1722 1.5 alnsn case SLJIT_GREATER_EQUAL:
1723 1.5 alnsn condition = SLJIT_LESS_EQUAL;
1724 1.1 alnsn break;
1725 1.5 alnsn case SLJIT_GREATER:
1726 1.5 alnsn condition = SLJIT_LESS;
1727 1.1 alnsn break;
1728 1.5 alnsn case SLJIT_LESS_EQUAL:
1729 1.5 alnsn condition = SLJIT_GREATER_EQUAL;
1730 1.1 alnsn break;
1731 1.5 alnsn case SLJIT_SIG_LESS:
1732 1.5 alnsn condition = SLJIT_SIG_GREATER;
1733 1.1 alnsn break;
1734 1.5 alnsn case SLJIT_SIG_GREATER_EQUAL:
1735 1.5 alnsn condition = SLJIT_SIG_LESS_EQUAL;
1736 1.1 alnsn break;
1737 1.5 alnsn case SLJIT_SIG_GREATER:
1738 1.5 alnsn condition = SLJIT_SIG_LESS;
1739 1.1 alnsn break;
1740 1.5 alnsn case SLJIT_SIG_LESS_EQUAL:
1741 1.5 alnsn condition = SLJIT_SIG_GREATER_EQUAL;
1742 1.1 alnsn break;
1743 1.1 alnsn }
1744 1.5.16.1 pgoyette
1745 1.5 alnsn type = condition | (type & (SLJIT_I32_OP | SLJIT_REWRITABLE_JUMP));
1746 1.1 alnsn tmp_src = src1;
1747 1.1 alnsn src1 = src2;
1748 1.1 alnsn src2 = tmp_src;
1749 1.1 alnsn tmp_srcw = src1w;
1750 1.1 alnsn src1w = src2w;
1751 1.1 alnsn src2w = tmp_srcw;
1752 1.1 alnsn }
1753 1.1 alnsn
1754 1.5 alnsn if (condition <= SLJIT_NOT_ZERO)
1755 1.5.16.1 pgoyette flags = SLJIT_SET_Z;
1756 1.1 alnsn else
1757 1.5.16.1 pgoyette flags = condition << VARIABLE_FLAG_SHIFT;
1758 1.1 alnsn
1759 1.5 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1760 1.5 alnsn || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1761 1.1 alnsn compiler->skip_checks = 1;
1762 1.1 alnsn #endif
1763 1.5 alnsn PTR_FAIL_IF(sljit_emit_op2(compiler, SLJIT_SUB | flags | (type & SLJIT_I32_OP),
1764 1.1 alnsn SLJIT_UNUSED, 0, src1, src1w, src2, src2w));
1765 1.5 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1766 1.5 alnsn || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1767 1.1 alnsn compiler->skip_checks = 1;
1768 1.1 alnsn #endif
1769 1.5.16.1 pgoyette return sljit_emit_jump(compiler, condition | (type & (SLJIT_REWRITABLE_JUMP | SLJIT_I32_OP)));
1770 1.1 alnsn }
1771 1.1 alnsn
1772 1.5.16.1 pgoyette #endif
1773 1.5.16.1 pgoyette
1774 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
1775 1.5 alnsn sljit_s32 src1, sljit_sw src1w,
1776 1.5 alnsn sljit_s32 src2, sljit_sw src2w)
1777 1.1 alnsn {
1778 1.5 alnsn CHECK_ERROR_PTR();
1779 1.5 alnsn CHECK_PTR(check_sljit_emit_fcmp(compiler, type, src1, src1w, src2, src2w));
1780 1.1 alnsn
1781 1.5 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1782 1.5 alnsn || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1783 1.1 alnsn compiler->skip_checks = 1;
1784 1.1 alnsn #endif
1785 1.5.16.1 pgoyette sljit_emit_fop1(compiler, SLJIT_CMP_F64 | ((type & 0xff) << VARIABLE_FLAG_SHIFT) | (type & SLJIT_I32_OP), src1, src1w, src2, src2w);
1786 1.1 alnsn
1787 1.5 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1788 1.5 alnsn || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1789 1.1 alnsn compiler->skip_checks = 1;
1790 1.1 alnsn #endif
1791 1.5.16.1 pgoyette return sljit_emit_jump(compiler, type);
1792 1.1 alnsn }
1793 1.1 alnsn
1794 1.5 alnsn #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
1795 1.1 alnsn
1796 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
1797 1.1 alnsn {
1798 1.1 alnsn CHECK_ERROR();
1799 1.5 alnsn CHECK(check_sljit_get_local_base(compiler, dst, dstw, offset));
1800 1.1 alnsn
1801 1.5 alnsn ADJUST_LOCAL_OFFSET(SLJIT_MEM1(SLJIT_SP), offset);
1802 1.5 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1803 1.5 alnsn || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1804 1.1 alnsn compiler->skip_checks = 1;
1805 1.1 alnsn #endif
1806 1.1 alnsn if (offset != 0)
1807 1.5.16.1 pgoyette return sljit_emit_op2(compiler, SLJIT_ADD, dst, dstw, SLJIT_SP, 0, SLJIT_IMM, offset);
1808 1.5 alnsn return sljit_emit_op1(compiler, SLJIT_MOV, dst, dstw, SLJIT_SP, 0);
1809 1.1 alnsn }
1810 1.1 alnsn
1811 1.1 alnsn #endif
1812 1.1 alnsn
1813 1.1 alnsn #else /* SLJIT_CONFIG_UNSUPPORTED */
1814 1.1 alnsn
1815 1.1 alnsn /* Empty function bodies for those machines, which are not (yet) supported. */
1816 1.1 alnsn
1817 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE const char* sljit_get_platform_name(void)
1818 1.1 alnsn {
1819 1.1 alnsn return "unsupported";
1820 1.1 alnsn }
1821 1.1 alnsn
1822 1.5.16.1 pgoyette SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data)
1823 1.1 alnsn {
1824 1.5.16.1 pgoyette SLJIT_UNUSED_ARG(allocator_data);
1825 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
1826 1.1 alnsn return NULL;
1827 1.1 alnsn }
1828 1.1 alnsn
1829 1.1 alnsn SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
1830 1.1 alnsn {
1831 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
1832 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
1833 1.5.16.1 pgoyette }
1834 1.5.16.1 pgoyette
1835 1.5.16.1 pgoyette SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler)
1836 1.5.16.1 pgoyette {
1837 1.5.16.1 pgoyette SLJIT_UNUSED_ARG(compiler);
1838 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
1839 1.1 alnsn }
1840 1.1 alnsn
1841 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_s32 size)
1842 1.1 alnsn {
1843 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
1844 1.1 alnsn SLJIT_UNUSED_ARG(size);
1845 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
1846 1.1 alnsn return NULL;
1847 1.1 alnsn }
1848 1.1 alnsn
1849 1.1 alnsn #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1850 1.1 alnsn SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
1851 1.1 alnsn {
1852 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
1853 1.1 alnsn SLJIT_UNUSED_ARG(verbose);
1854 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
1855 1.1 alnsn }
1856 1.1 alnsn #endif
1857 1.1 alnsn
1858 1.1 alnsn SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler)
1859 1.1 alnsn {
1860 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
1861 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
1862 1.1 alnsn return NULL;
1863 1.1 alnsn }
1864 1.1 alnsn
1865 1.1 alnsn SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code)
1866 1.1 alnsn {
1867 1.1 alnsn SLJIT_UNUSED_ARG(code);
1868 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
1869 1.1 alnsn }
1870 1.1 alnsn
1871 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler,
1872 1.5 alnsn sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds,
1873 1.5 alnsn sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
1874 1.1 alnsn {
1875 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
1876 1.5 alnsn SLJIT_UNUSED_ARG(options);
1877 1.1 alnsn SLJIT_UNUSED_ARG(args);
1878 1.3 alnsn SLJIT_UNUSED_ARG(scratches);
1879 1.1 alnsn SLJIT_UNUSED_ARG(saveds);
1880 1.5 alnsn SLJIT_UNUSED_ARG(fscratches);
1881 1.5 alnsn SLJIT_UNUSED_ARG(fsaveds);
1882 1.1 alnsn SLJIT_UNUSED_ARG(local_size);
1883 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
1884 1.1 alnsn return SLJIT_ERR_UNSUPPORTED;
1885 1.1 alnsn }
1886 1.1 alnsn
1887 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler,
1888 1.5 alnsn sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds,
1889 1.5 alnsn sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
1890 1.1 alnsn {
1891 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
1892 1.5 alnsn SLJIT_UNUSED_ARG(options);
1893 1.1 alnsn SLJIT_UNUSED_ARG(args);
1894 1.3 alnsn SLJIT_UNUSED_ARG(scratches);
1895 1.1 alnsn SLJIT_UNUSED_ARG(saveds);
1896 1.5 alnsn SLJIT_UNUSED_ARG(fscratches);
1897 1.5 alnsn SLJIT_UNUSED_ARG(fsaveds);
1898 1.1 alnsn SLJIT_UNUSED_ARG(local_size);
1899 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
1900 1.5 alnsn return SLJIT_ERR_UNSUPPORTED;
1901 1.1 alnsn }
1902 1.1 alnsn
1903 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
1904 1.1 alnsn {
1905 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
1906 1.1 alnsn SLJIT_UNUSED_ARG(op);
1907 1.1 alnsn SLJIT_UNUSED_ARG(src);
1908 1.1 alnsn SLJIT_UNUSED_ARG(srcw);
1909 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
1910 1.1 alnsn return SLJIT_ERR_UNSUPPORTED;
1911 1.1 alnsn }
1912 1.1 alnsn
1913 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
1914 1.1 alnsn {
1915 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
1916 1.1 alnsn SLJIT_UNUSED_ARG(dst);
1917 1.1 alnsn SLJIT_UNUSED_ARG(dstw);
1918 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
1919 1.1 alnsn return SLJIT_ERR_UNSUPPORTED;
1920 1.1 alnsn }
1921 1.1 alnsn
1922 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_return(struct sljit_compiler *compiler, sljit_s32 src, sljit_sw srcw)
1923 1.1 alnsn {
1924 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
1925 1.1 alnsn SLJIT_UNUSED_ARG(src);
1926 1.1 alnsn SLJIT_UNUSED_ARG(srcw);
1927 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
1928 1.1 alnsn return SLJIT_ERR_UNSUPPORTED;
1929 1.1 alnsn }
1930 1.1 alnsn
1931 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op)
1932 1.1 alnsn {
1933 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
1934 1.1 alnsn SLJIT_UNUSED_ARG(op);
1935 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
1936 1.1 alnsn return SLJIT_ERR_UNSUPPORTED;
1937 1.1 alnsn }
1938 1.1 alnsn
1939 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op,
1940 1.5 alnsn sljit_s32 dst, sljit_sw dstw,
1941 1.5 alnsn sljit_s32 src, sljit_sw srcw)
1942 1.1 alnsn {
1943 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
1944 1.1 alnsn SLJIT_UNUSED_ARG(op);
1945 1.1 alnsn SLJIT_UNUSED_ARG(dst);
1946 1.1 alnsn SLJIT_UNUSED_ARG(dstw);
1947 1.1 alnsn SLJIT_UNUSED_ARG(src);
1948 1.1 alnsn SLJIT_UNUSED_ARG(srcw);
1949 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
1950 1.1 alnsn return SLJIT_ERR_UNSUPPORTED;
1951 1.1 alnsn }
1952 1.1 alnsn
1953 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op,
1954 1.5 alnsn sljit_s32 dst, sljit_sw dstw,
1955 1.5 alnsn sljit_s32 src1, sljit_sw src1w,
1956 1.5 alnsn sljit_s32 src2, sljit_sw src2w)
1957 1.1 alnsn {
1958 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
1959 1.1 alnsn SLJIT_UNUSED_ARG(op);
1960 1.1 alnsn SLJIT_UNUSED_ARG(dst);
1961 1.1 alnsn SLJIT_UNUSED_ARG(dstw);
1962 1.1 alnsn SLJIT_UNUSED_ARG(src1);
1963 1.1 alnsn SLJIT_UNUSED_ARG(src1w);
1964 1.1 alnsn SLJIT_UNUSED_ARG(src2);
1965 1.1 alnsn SLJIT_UNUSED_ARG(src2w);
1966 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
1967 1.1 alnsn return SLJIT_ERR_UNSUPPORTED;
1968 1.1 alnsn }
1969 1.1 alnsn
1970 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_register_index(sljit_s32 reg)
1971 1.1 alnsn {
1972 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
1973 1.1 alnsn return reg;
1974 1.1 alnsn }
1975 1.1 alnsn
1976 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *compiler,
1977 1.5 alnsn void *instruction, sljit_s32 size)
1978 1.1 alnsn {
1979 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
1980 1.1 alnsn SLJIT_UNUSED_ARG(instruction);
1981 1.1 alnsn SLJIT_UNUSED_ARG(size);
1982 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
1983 1.1 alnsn return SLJIT_ERR_UNSUPPORTED;
1984 1.1 alnsn }
1985 1.1 alnsn
1986 1.5.16.1 pgoyette SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *compiler, sljit_s32 current_flags)
1987 1.5.16.1 pgoyette {
1988 1.5.16.1 pgoyette SLJIT_UNUSED_ARG(compiler);
1989 1.5.16.1 pgoyette SLJIT_UNUSED_ARG(current_flags);
1990 1.5.16.1 pgoyette }
1991 1.5.16.1 pgoyette
1992 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_is_fpu_available(void)
1993 1.1 alnsn {
1994 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
1995 1.1 alnsn return 0;
1996 1.1 alnsn }
1997 1.1 alnsn
1998 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,
1999 1.5 alnsn sljit_s32 dst, sljit_sw dstw,
2000 1.5 alnsn sljit_s32 src, sljit_sw srcw)
2001 1.1 alnsn {
2002 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
2003 1.1 alnsn SLJIT_UNUSED_ARG(op);
2004 1.1 alnsn SLJIT_UNUSED_ARG(dst);
2005 1.1 alnsn SLJIT_UNUSED_ARG(dstw);
2006 1.1 alnsn SLJIT_UNUSED_ARG(src);
2007 1.1 alnsn SLJIT_UNUSED_ARG(srcw);
2008 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
2009 1.1 alnsn return SLJIT_ERR_UNSUPPORTED;
2010 1.1 alnsn }
2011 1.1 alnsn
2012 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op,
2013 1.5 alnsn sljit_s32 dst, sljit_sw dstw,
2014 1.5 alnsn sljit_s32 src1, sljit_sw src1w,
2015 1.5 alnsn sljit_s32 src2, sljit_sw src2w)
2016 1.1 alnsn {
2017 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
2018 1.1 alnsn SLJIT_UNUSED_ARG(op);
2019 1.1 alnsn SLJIT_UNUSED_ARG(dst);
2020 1.1 alnsn SLJIT_UNUSED_ARG(dstw);
2021 1.1 alnsn SLJIT_UNUSED_ARG(src1);
2022 1.1 alnsn SLJIT_UNUSED_ARG(src1w);
2023 1.1 alnsn SLJIT_UNUSED_ARG(src2);
2024 1.1 alnsn SLJIT_UNUSED_ARG(src2w);
2025 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
2026 1.1 alnsn return SLJIT_ERR_UNSUPPORTED;
2027 1.1 alnsn }
2028 1.1 alnsn
2029 1.1 alnsn SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler)
2030 1.1 alnsn {
2031 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
2032 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
2033 1.1 alnsn return NULL;
2034 1.1 alnsn }
2035 1.1 alnsn
2036 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type)
2037 1.1 alnsn {
2038 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
2039 1.1 alnsn SLJIT_UNUSED_ARG(type);
2040 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
2041 1.1 alnsn return NULL;
2042 1.1 alnsn }
2043 1.1 alnsn
2044 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
2045 1.5 alnsn sljit_s32 src1, sljit_sw src1w,
2046 1.5 alnsn sljit_s32 src2, sljit_sw src2w)
2047 1.1 alnsn {
2048 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
2049 1.1 alnsn SLJIT_UNUSED_ARG(type);
2050 1.1 alnsn SLJIT_UNUSED_ARG(src1);
2051 1.1 alnsn SLJIT_UNUSED_ARG(src1w);
2052 1.1 alnsn SLJIT_UNUSED_ARG(src2);
2053 1.1 alnsn SLJIT_UNUSED_ARG(src2w);
2054 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
2055 1.1 alnsn return NULL;
2056 1.1 alnsn }
2057 1.1 alnsn
2058 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
2059 1.5 alnsn sljit_s32 src1, sljit_sw src1w,
2060 1.5 alnsn sljit_s32 src2, sljit_sw src2w)
2061 1.1 alnsn {
2062 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
2063 1.1 alnsn SLJIT_UNUSED_ARG(type);
2064 1.1 alnsn SLJIT_UNUSED_ARG(src1);
2065 1.1 alnsn SLJIT_UNUSED_ARG(src1w);
2066 1.1 alnsn SLJIT_UNUSED_ARG(src2);
2067 1.1 alnsn SLJIT_UNUSED_ARG(src2w);
2068 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
2069 1.1 alnsn return NULL;
2070 1.1 alnsn }
2071 1.1 alnsn
2072 1.1 alnsn SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
2073 1.1 alnsn {
2074 1.1 alnsn SLJIT_UNUSED_ARG(jump);
2075 1.1 alnsn SLJIT_UNUSED_ARG(label);
2076 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
2077 1.1 alnsn }
2078 1.1 alnsn
2079 1.1 alnsn SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
2080 1.1 alnsn {
2081 1.1 alnsn SLJIT_UNUSED_ARG(jump);
2082 1.1 alnsn SLJIT_UNUSED_ARG(target);
2083 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
2084 1.1 alnsn }
2085 1.1 alnsn
2086 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw)
2087 1.1 alnsn {
2088 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
2089 1.1 alnsn SLJIT_UNUSED_ARG(type);
2090 1.1 alnsn SLJIT_UNUSED_ARG(src);
2091 1.1 alnsn SLJIT_UNUSED_ARG(srcw);
2092 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
2093 1.1 alnsn return SLJIT_ERR_UNSUPPORTED;
2094 1.1 alnsn }
2095 1.1 alnsn
2096 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op,
2097 1.5 alnsn sljit_s32 dst, sljit_sw dstw,
2098 1.5 alnsn sljit_s32 src, sljit_sw srcw,
2099 1.5 alnsn sljit_s32 type)
2100 1.1 alnsn {
2101 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
2102 1.1 alnsn SLJIT_UNUSED_ARG(op);
2103 1.1 alnsn SLJIT_UNUSED_ARG(dst);
2104 1.1 alnsn SLJIT_UNUSED_ARG(dstw);
2105 1.3 alnsn SLJIT_UNUSED_ARG(src);
2106 1.3 alnsn SLJIT_UNUSED_ARG(srcw);
2107 1.1 alnsn SLJIT_UNUSED_ARG(type);
2108 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
2109 1.1 alnsn return SLJIT_ERR_UNSUPPORTED;
2110 1.1 alnsn }
2111 1.1 alnsn
2112 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
2113 1.1 alnsn {
2114 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
2115 1.1 alnsn SLJIT_UNUSED_ARG(dst);
2116 1.1 alnsn SLJIT_UNUSED_ARG(dstw);
2117 1.1 alnsn SLJIT_UNUSED_ARG(offset);
2118 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
2119 1.1 alnsn return SLJIT_ERR_UNSUPPORTED;
2120 1.1 alnsn }
2121 1.1 alnsn
2122 1.5 alnsn SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw initval)
2123 1.1 alnsn {
2124 1.1 alnsn SLJIT_UNUSED_ARG(compiler);
2125 1.1 alnsn SLJIT_UNUSED_ARG(dst);
2126 1.1 alnsn SLJIT_UNUSED_ARG(dstw);
2127 1.1 alnsn SLJIT_UNUSED_ARG(initval);
2128 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
2129 1.1 alnsn return NULL;
2130 1.1 alnsn }
2131 1.1 alnsn
2132 1.5.16.1 pgoyette SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_target, sljit_sw executable_offset)
2133 1.1 alnsn {
2134 1.1 alnsn SLJIT_UNUSED_ARG(addr);
2135 1.5.16.1 pgoyette SLJIT_UNUSED_ARG(new_target);
2136 1.5.16.1 pgoyette SLJIT_UNUSED_ARG(executable_offset);
2137 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
2138 1.1 alnsn }
2139 1.1 alnsn
2140 1.5.16.1 pgoyette SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset)
2141 1.1 alnsn {
2142 1.1 alnsn SLJIT_UNUSED_ARG(addr);
2143 1.1 alnsn SLJIT_UNUSED_ARG(new_constant);
2144 1.5.16.1 pgoyette SLJIT_UNUSED_ARG(executable_offset);
2145 1.5.16.1 pgoyette SLJIT_UNREACHABLE();
2146 1.1 alnsn }
2147 1.1 alnsn
2148 1.1 alnsn #endif
2149