/src/pcre2/deps/sljit/sljit_src/sljitLir.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Stack-less Just-In-Time compiler |
3 | | * |
4 | | * Copyright Zoltan Herczeg (hzmester@freemail.hu). All rights reserved. |
5 | | * |
6 | | * Redistribution and use in source and binary forms, with or without modification, are |
7 | | * permitted provided that the following conditions are met: |
8 | | * |
9 | | * 1. Redistributions of source code must retain the above copyright notice, this list of |
10 | | * conditions and the following disclaimer. |
11 | | * |
12 | | * 2. Redistributions in binary form must reproduce the above copyright notice, this list |
13 | | * of conditions and the following disclaimer in the documentation and/or other materials |
14 | | * provided with the distribution. |
15 | | * |
16 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY |
17 | | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
19 | | * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
21 | | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
22 | | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
24 | | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | | */ |
26 | | |
27 | | #include "sljitLir.h" |
28 | | |
29 | | #ifdef _WIN32 |
30 | | |
31 | | #include <windows.h> |
32 | | |
33 | | #endif /* _WIN32 */ |
34 | | |
35 | | #if !(defined SLJIT_STD_MACROS_DEFINED && SLJIT_STD_MACROS_DEFINED) |
36 | | |
37 | | /* These libraries are needed for the macros below. */ |
38 | | #include <stdlib.h> |
39 | | #include <string.h> |
40 | | |
41 | | #endif /* SLJIT_STD_MACROS_DEFINED */ |
42 | | |
43 | | #define CHECK_ERROR() \ |
44 | 1.15G | do { \ |
45 | 1.15G | if (SLJIT_UNLIKELY(compiler->error)) \ |
46 | 1.15G | return compiler->error; \ |
47 | 1.15G | } while (0) |
48 | | |
49 | | #define CHECK_ERROR_PTR() \ |
50 | 1.18G | do { \ |
51 | 1.18G | if (SLJIT_UNLIKELY(compiler->error)) \ |
52 | 1.18G | return NULL; \ |
53 | 1.18G | } while (0) |
54 | | |
55 | | #define FAIL_IF(expr) \ |
56 | 1.96G | do { \ |
57 | 1.96G | if (SLJIT_UNLIKELY(expr)) \ |
58 | 1.96G | return compiler->error; \ |
59 | 1.96G | } while (0) |
60 | | |
61 | | #define PTR_FAIL_IF(expr) \ |
62 | 1.69G | do { \ |
63 | 1.69G | if (SLJIT_UNLIKELY(expr)) \ |
64 | 1.69G | return NULL; \ |
65 | 1.69G | } while (0) |
66 | | |
67 | | #define FAIL_IF_NULL(ptr) \ |
68 | 31.0M | do { \ |
69 | 31.0M | if (SLJIT_UNLIKELY(!(ptr))) { \ |
70 | 0 | compiler->error = SLJIT_ERR_ALLOC_FAILED; \ |
71 | 0 | return SLJIT_ERR_ALLOC_FAILED; \ |
72 | 0 | } \ |
73 | 31.0M | } while (0) |
74 | | |
75 | | #define PTR_FAIL_IF_NULL(ptr) \ |
76 | 820M | do { \ |
77 | 820M | if (SLJIT_UNLIKELY(!(ptr))) { \ |
78 | 0 | compiler->error = SLJIT_ERR_ALLOC_FAILED; \ |
79 | 0 | return NULL; \ |
80 | 0 | } \ |
81 | 820M | } while (0) |
82 | | |
83 | | #define PTR_FAIL_WITH_EXEC_IF(ptr) \ |
84 | 70.4k | do { \ |
85 | 70.4k | if (SLJIT_UNLIKELY(!(ptr))) { \ |
86 | 0 | compiler->error = SLJIT_ERR_EX_ALLOC_FAILED; \ |
87 | 0 | return NULL; \ |
88 | 0 | } \ |
89 | 70.4k | } while (0) |
90 | | |
91 | | #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) |
92 | | |
93 | 93.2M | #define SSIZE_OF(type) ((sljit_s32)sizeof(sljit_ ## type)) |
94 | | |
95 | 939M | #define VARIABLE_FLAG_SHIFT (10) |
96 | | /* All variable flags are even. */ |
97 | 814M | #define VARIABLE_FLAG_MASK (0x3e << VARIABLE_FLAG_SHIFT) |
98 | 814M | #define ALL_STATUS_FLAGS_MASK (VARIABLE_FLAG_MASK | SLJIT_SET_Z) |
99 | 0 | #define GET_FLAG_TYPE(op) ((op) >> VARIABLE_FLAG_SHIFT) |
100 | | #define GET_FLAG_TYPE_MASK(op) (((op) >> VARIABLE_FLAG_SHIFT) & 0x3e) |
101 | 1.10G | #define GET_OPCODE(op) ((op) & 0xff) |
102 | 200M | #define HAS_FLAGS(op) ((op) & ALL_STATUS_FLAGS_MASK) |
103 | 618M | #define GET_ALL_FLAGS(op) ((op) & (SLJIT_32 | ALL_STATUS_FLAGS_MASK)) |
104 | | |
105 | | #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) |
106 | | #define TYPE_CAST_NEEDED(op) \ |
107 | 0 | ((op) >= SLJIT_MOV_U8 && (op) <= SLJIT_MOV_S32) |
108 | | #else /* !SLJIT_64BIT_ARCHITECTURE */ |
109 | | #define TYPE_CAST_NEEDED(op) \ |
110 | | ((op) >= SLJIT_MOV_U8 && (op) <= SLJIT_MOV_S16) |
111 | | #endif /* SLJIT_64BIT_ARCHITECTURE */ |
112 | | |
113 | 1.77G | #define BUF_SIZE 4096 |
114 | | |
115 | | #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE) |
116 | | #define ABUF_SIZE 2048 |
117 | | #else /* !SLJIT_32BIT_ARCHITECTURE */ |
118 | 929M | #define ABUF_SIZE 4096 |
119 | | #endif /* SLJIT_32BIT_ARCHITECTURE */ |
120 | | |
121 | | /* Parameter parsing. */ |
122 | 8.59G | #define REG_MASK 0x7f |
123 | 212M | #define OFFS_REG(reg) (((reg) >> 8) & REG_MASK) |
124 | 3.34G | #define OFFS_REG_MASK (REG_MASK << 8) |
125 | 423M | #define TO_OFFS_REG(reg) ((reg) << 8) |
126 | 2.60G | #define FAST_IS_REG(reg) ((reg) < REG_MASK) |
127 | | |
128 | | /* Mask for argument types. */ |
129 | 45.8M | #define SLJIT_ARG_MASK 0x7 |
130 | | #define SLJIT_ARG_FULL_MASK (SLJIT_ARG_MASK | SLJIT_ARG_TYPE_SCRATCH_REG) |
131 | | |
132 | | /* Mask for register pairs. */ |
133 | | #define REG_PAIR_MASK 0x7f00 |
134 | | #define REG_PAIR_FIRST(reg) ((reg) & 0x7f) |
135 | | #define REG_PAIR_SECOND(reg) ((reg) >> 8) |
136 | | |
137 | | /* Mask for sljit_emit_enter. */ |
138 | 211k | #define ENTER_GET_REGS(regs) ((regs) & 0xff) |
139 | 140k | #define ENTER_GET_FLOAT_REGS(regs) (((regs) >> 8) & 0xff) |
140 | 140k | #define ENTER_GET_VECTOR_REGS(regs) (((regs) >> 16) & 0xff) |
141 | 140k | #define SLJIT_KEPT_SAVEDS_COUNT(options) ((options) & 0x3) |
142 | | |
143 | | /* Getters for simd operations, which returns with log2(size). */ |
144 | 20.2k | #define SLJIT_SIMD_GET_OPCODE(type) ((type) & 0xff) |
145 | 377k | #define SLJIT_SIMD_GET_REG_SIZE(type) (((type) >> 12) & 0x3f) |
146 | 377k | #define SLJIT_SIMD_GET_ELEM_SIZE(type) (((type) >> 18) & 0x3f) |
147 | 122k | #define SLJIT_SIMD_GET_ELEM2_SIZE(type) (((type) >> 24) & 0x3f) |
148 | | |
149 | | #define SLJIT_SIMD_CHECK_REG(type) (((type) & 0x3f000) >= SLJIT_SIMD_REG_64 && ((type) & 0x3f000) <= SLJIT_SIMD_REG_512) |
150 | | #define SLJIT_SIMD_TYPE_MASK(m) ((sljit_s32)0xff000fff & ~(SLJIT_SIMD_FLOAT | SLJIT_SIMD_TEST | (m))) |
151 | | #define SLJIT_SIMD_TYPE_MASK2(m) ((sljit_s32)0xc0000fff & ~(SLJIT_SIMD_FLOAT | SLJIT_SIMD_TEST | (m))) |
152 | | |
153 | | /* Label definitions. */ |
154 | | |
155 | 165M | #define SLJIT_LABEL_ALIGNED ((~(sljit_uw)0) - 1) |
156 | | |
157 | | struct sljit_extended_label { |
158 | | struct sljit_label label; |
159 | | sljit_uw index; |
160 | | sljit_uw data; |
161 | | }; |
162 | | |
163 | | /* Jump definitions. */ |
164 | | |
165 | | /* Jump flag bits. */ |
166 | 1.73G | #define JUMP_ADDR 0x1 |
167 | 424M | #define JUMP_MOV_ADDR 0x2 |
168 | | /* SLJIT_REWRITABLE_JUMP is 0x10000. */ |
169 | | |
170 | | #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) |
171 | 516M | # define PATCH_MB 0x04 |
172 | 641M | # define PATCH_MW 0x08 |
173 | | #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) |
174 | 1.54M | # define PATCH_MD 0x10 |
175 | 0 | # define MOV_ADDR_HI 0x20 |
176 | 243M | # define JUMP_MAX_SIZE ((sljit_uw)(10 + 3)) |
177 | 990M | # define CJUMP_MAX_SIZE ((sljit_uw)(2 + 10 + 3)) |
178 | | #else /* !SLJIT_CONFIG_X86_64 */ |
179 | | # define JUMP_MAX_SIZE ((sljit_uw)5) |
180 | | # define CJUMP_MAX_SIZE ((sljit_uw)6) |
181 | | #endif /* SLJIT_CONFIG_X86_64 */ |
182 | 1.26G | # define TYPE_SHIFT 17 |
183 | | #if (defined SLJIT_DEBUG && SLJIT_DEBUG) |
184 | | /* Bits 7..15 is for debug jump size, SLJIT_REWRITABLE_JUMP is 0x10000 */ |
185 | | # define JUMP_SIZE_SHIFT 8 |
186 | | #endif /* SLJIT_DEBUG */ |
187 | | #endif /* SLJIT_CONFIG_X86 */ |
188 | | |
189 | | #if (defined SLJIT_CONFIG_ARM_V6 && SLJIT_CONFIG_ARM_V6) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) |
190 | | /* SLJIT_REWRITABLE_JUMP is 0x10000. */ |
191 | | # define IS_BL 0x04 |
192 | | # define PATCH_B 0x08 |
193 | | #endif /* SLJIT_CONFIG_ARM_V6 || SLJIT_CONFIG_ARM_V7 */ |
194 | | |
195 | | #if (defined SLJIT_CONFIG_ARM_V6 && SLJIT_CONFIG_ARM_V6) |
196 | | # define CPOOL_SIZE 512 |
197 | | #endif /* SLJIT_CONFIG_ARM_V6 */ |
198 | | |
199 | | #if (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) |
200 | | # define JUMP_SIZE_SHIFT 26 |
201 | | # define JUMP_MAX_SIZE ((sljit_uw)3) |
202 | | #endif /* SLJIT_CONFIG_ARM_V7 */ |
203 | | |
204 | | #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) |
205 | | /* SLJIT_REWRITABLE_JUMP is 0x10000. */ |
206 | | # define IS_COND 0x04 |
207 | | # define IS_BL 0x08 |
208 | | /* mov_addr does not use IS_BL */ |
209 | | # define IS_ABS IS_BL |
210 | | /* conditional + imm8 */ |
211 | | # define PATCH_TYPE1 0x10 |
212 | | /* conditional + imm20 */ |
213 | | # define PATCH_TYPE2 0x20 |
214 | | /* imm11 */ |
215 | | # define PATCH_TYPE3 0x30 |
216 | | /* imm24 */ |
217 | | # define PATCH_TYPE4 0x40 |
218 | | /* BL + imm24 */ |
219 | | # define PATCH_TYPE5 0x50 |
220 | | /* addwi/subwi */ |
221 | | # define PATCH_TYPE6 0x60 |
222 | | /* 0xf00 cc code for branches */ |
223 | | # define JUMP_SIZE_SHIFT 26 |
224 | | # define JUMP_MAX_SIZE ((sljit_uw)5) |
225 | | #endif /* SLJIT_CONFIG_ARM_THUMB2 */ |
226 | | |
227 | | #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) |
228 | | /* SLJIT_REWRITABLE_JUMP is 0x10000. */ |
229 | | # define IS_COND 0x004 |
230 | | # define IS_CBZ 0x008 |
231 | | # define IS_BL 0x010 |
232 | | # define PATCH_COND 0x020 |
233 | | # define PATCH_B 0x040 |
234 | | # define PATCH_B32 0x080 |
235 | | # define PATCH_ABS48 0x100 |
236 | | # define PATCH_ABS64 0x200 |
237 | | # define JUMP_SIZE_SHIFT 58 |
238 | | # define JUMP_MAX_SIZE ((sljit_uw)5) |
239 | | #endif /* SLJIT_CONFIG_ARM_64 */ |
240 | | |
241 | | #if (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) |
242 | | /* SLJIT_REWRITABLE_JUMP is 0x10000. */ |
243 | | # define IS_COND 0x004 |
244 | | # define IS_CALL 0x008 |
245 | | # define PATCH_B 0x010 |
246 | | # define PATCH_ABS_B 0x020 |
247 | | #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) |
248 | | # define PATCH_ABS32 0x040 |
249 | | # define PATCH_ABS48 0x080 |
250 | | # define JUMP_SIZE_SHIFT 58 |
251 | | # define JUMP_MAX_SIZE ((sljit_uw)7) |
252 | | #else /* !SLJIT_CONFIG_PPC_64 */ |
253 | | # define JUMP_SIZE_SHIFT 26 |
254 | | # define JUMP_MAX_SIZE ((sljit_uw)4) |
255 | | #endif /* SLJIT_CONFIG_PPC_64 */ |
256 | | #endif /* SLJIT_CONFIG_PPC */ |
257 | | |
258 | | #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) |
259 | | /* SLJIT_REWRITABLE_JUMP is 0x10000. */ |
260 | | # define IS_MOVABLE 0x004 |
261 | | # define IS_JAL 0x008 |
262 | | # define IS_CALL 0x010 |
263 | | # define IS_BIT26_COND 0x020 |
264 | | # define IS_BIT16_COND 0x040 |
265 | | # define IS_BIT23_COND 0x080 |
266 | | |
267 | | # define IS_COND (IS_BIT26_COND | IS_BIT16_COND | IS_BIT23_COND) |
268 | | |
269 | | # define PATCH_B 0x100 |
270 | | # define PATCH_J 0x200 |
271 | | |
272 | | #if (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) |
273 | | # define PATCH_ABS32 0x400 |
274 | | # define PATCH_ABS48 0x800 |
275 | | #endif /* SLJIT_CONFIG_MIPS_64 */ |
276 | | |
277 | | /* instruction types */ |
278 | | # define MOVABLE_INS 0 |
279 | | /* 1 - 31 last destination register */ |
280 | | /* no destination (i.e: store) */ |
281 | | # define UNMOVABLE_INS 32 |
282 | | /* FPU status register */ |
283 | | # define FCSR_FCC 33 |
284 | | #endif /* SLJIT_CONFIG_MIPS */ |
285 | | |
286 | | #if (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV) |
287 | | /* SLJIT_REWRITABLE_JUMP is 0x10000. */ |
288 | | # define IS_COND 0x0004 |
289 | | # define IS_CALL 0x0008 |
290 | | |
291 | | # define IS_COND16 0x0010 |
292 | | # define PATCH_B 0x0020 |
293 | | # define PATCH_J 0x0040 |
294 | | # define PATCH_16 0x0080 |
295 | | |
296 | | #if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) |
297 | | # define PATCH_REL32 0x0100 |
298 | | # define PATCH_ABS32 0x0200 |
299 | | # define PATCH_ABS44 0x0400 |
300 | | # define PATCH_ABS52 0x0800 |
301 | | # define JUMP_SIZE_SHIFT 58 |
302 | | # define JUMP_MAX_SIZE ((sljit_uw)12) |
303 | | #else /* !SLJIT_CONFIG_RISCV_64 */ |
304 | | # define JUMP_SIZE_SHIFT 26 |
305 | | # define JUMP_MAX_SIZE ((sljit_uw)4) |
306 | | #endif /* SLJIT_CONFIG_RISCV_64 */ |
307 | | #endif /* SLJIT_CONFIG_RISCV */ |
308 | | |
309 | | #if (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X) |
310 | | /* SLJIT_REWRITABLE_JUMP is 0x10000. */ |
311 | | # define PATCH_POOL 0x004 |
312 | | # define PATCH_IMM32 0x008 |
313 | | #endif /* SLJIT_CONFIG_S390X */ |
314 | | |
315 | | #if (defined SLJIT_CONFIG_LOONGARCH && SLJIT_CONFIG_LOONGARCH) |
316 | | /* SLJIT_REWRITABLE_JUMP is 0x10000. */ |
317 | | # define IS_COND 0x004 |
318 | | # define IS_CALL 0x008 |
319 | | |
320 | | # define PATCH_B 0x010 |
321 | | # define PATCH_J 0x020 |
322 | | |
323 | | # define PATCH_REL32 0x040 |
324 | | # define PATCH_ABS32 0x080 |
325 | | # define PATCH_ABS52 0x100 |
326 | | # define JUMP_SIZE_SHIFT 58 |
327 | | # define JUMP_MAX_SIZE ((sljit_uw)4) |
328 | | |
329 | | #endif /* SLJIT_CONFIG_LOONGARCH */ |
330 | | |
331 | | /* Stack management. */ |
332 | | |
333 | | #define GET_SAVED_REGISTERS_SIZE(scratches, saveds, extra) \ |
334 | 70.4k | (((scratches < SLJIT_NUMBER_OF_SCRATCH_REGISTERS ? 0 : (scratches - SLJIT_NUMBER_OF_SCRATCH_REGISTERS)) + \ |
335 | 70.4k | (saveds) + (sljit_s32)(extra)) * (sljit_s32)sizeof(sljit_sw)) |
336 | | |
337 | | #define GET_SAVED_FLOAT_REGISTERS_SIZE(fscratches, fsaveds, type) \ |
338 | | (((fscratches < SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS ? 0 : (fscratches - SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS)) + \ |
339 | | (fsaveds)) * SSIZE_OF(type)) |
340 | | |
341 | | #define ADJUST_LOCAL_OFFSET(p, i) \ |
342 | 2.45G | if ((p) == (SLJIT_MEM1(SLJIT_SP))) \ |
343 | 2.45G | (i) += SLJIT_LOCALS_OFFSET; |
344 | | |
345 | | #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */ |
346 | | |
347 | | /* Utils can still be used even if SLJIT_CONFIG_UNSUPPORTED is set. */ |
348 | | #include "sljitUtils.c" |
349 | | |
350 | | #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) |
351 | | #define SLJIT_CODE_TO_PTR(code) ((void*)((sljit_up)(code) & ~(sljit_up)0x1)) |
352 | | #elif (defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL) |
353 | | #define SLJIT_CODE_TO_PTR(code) ((void*)(*(sljit_up*)code)) |
354 | | #else /* !SLJIT_CONFIG_ARM_THUMB2 && !SLJIT_INDIRECT_CALL */ |
355 | | #define SLJIT_CODE_TO_PTR(code) ((void*)(code)) |
356 | | #endif /* SLJIT_CONFIG_ARM_THUMB2 || SLJIT_INDIRECT_CALL */ |
357 | | |
358 | | #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) |
359 | | |
360 | | #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR) |
361 | | |
362 | | #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR) |
363 | | |
364 | | #if defined(__NetBSD__) |
365 | | #include "allocator_src/sljitProtExecAllocatorNetBSD.c" |
366 | | #else /* !__NetBSD__ */ |
367 | | #include "allocator_src/sljitProtExecAllocatorPosix.c" |
368 | | #endif /* __NetBSD__ */ |
369 | | |
370 | | #elif (defined SLJIT_WX_EXECUTABLE_ALLOCATOR && SLJIT_WX_EXECUTABLE_ALLOCATOR) |
371 | | |
372 | | #if defined(_WIN32) |
373 | | #include "allocator_src/sljitWXExecAllocatorWindows.c" |
374 | | #else /* !_WIN32 */ |
375 | | #include "allocator_src/sljitWXExecAllocatorPosix.c" |
376 | | #endif /* _WIN32 */ |
377 | | |
378 | | #else /* !SLJIT_PROT_EXECUTABLAE_ALLOCATOR && !SLJIT_WX_EXECUTABLE_ALLOCATOR */ |
379 | | |
380 | | #if defined(_WIN32) |
381 | | #include "allocator_src/sljitExecAllocatorWindows.c" |
382 | | #elif defined(__APPLE__) |
383 | | #include "allocator_src/sljitExecAllocatorApple.c" |
384 | | #elif defined(__FreeBSD__) |
385 | | #include "allocator_src/sljitExecAllocatorFreeBSD.c" |
386 | | #else /* !_WIN32 && !__APPLE__ && !__FreeBSD__ */ |
387 | | #include "allocator_src/sljitExecAllocatorPosix.c" |
388 | | #endif /* _WIN32 */ |
389 | | |
390 | | #endif /* SLJIT_PROT_EXECUTABLE_ALLOCATOR */ |
391 | | |
392 | | #else /* !SLJIT_EXECUTABLE_ALLOCATOR */ |
393 | | |
394 | | #ifndef SLJIT_UPDATE_WX_FLAGS |
395 | | #define SLJIT_UPDATE_WX_FLAGS(from, to, enable_exec) |
396 | | #endif /* SLJIT_UPDATE_WX_FLAGS */ |
397 | | |
398 | | #endif /* SLJIT_EXECUTABLE_ALLOCATOR */ |
399 | | |
400 | | #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR) |
401 | | #define SLJIT_ADD_EXEC_OFFSET(ptr, exec_offset) ((sljit_u8 *)(ptr) + (exec_offset)) |
402 | | #else /* !SLJIT_PROT_EXECUTABLE_ALLOCATOR */ |
403 | 592M | #define SLJIT_ADD_EXEC_OFFSET(ptr, exec_offset) ((sljit_u8 *)(ptr)) |
404 | | #endif /* SLJIT_PROT_EXECUTABLE_ALLOCATOR */ |
405 | | |
406 | | /* Argument checking features. */ |
407 | | |
408 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
409 | | |
410 | | /* Returns with error when an invalid argument is passed. */ |
411 | | |
412 | | #define CHECK_ARGUMENT(x) \ |
413 | | do { \ |
414 | | if (SLJIT_UNLIKELY(!(x))) \ |
415 | | return 1; \ |
416 | | } while (0) |
417 | | |
418 | | #define CHECK_RETURN_TYPE sljit_s32 |
419 | | #define CHECK_RETURN_OK return 0 |
420 | | |
421 | | #define CHECK(x) \ |
422 | | do { \ |
423 | | if (SLJIT_UNLIKELY(x)) { \ |
424 | | compiler->error = SLJIT_ERR_BAD_ARGUMENT; \ |
425 | | return SLJIT_ERR_BAD_ARGUMENT; \ |
426 | | } \ |
427 | | } while (0) |
428 | | |
429 | | #define CHECK_PTR(x) \ |
430 | | do { \ |
431 | | if (SLJIT_UNLIKELY(x)) { \ |
432 | | compiler->error = SLJIT_ERR_BAD_ARGUMENT; \ |
433 | | return NULL; \ |
434 | | } \ |
435 | | } while (0) |
436 | | |
437 | | #define CHECK_REG_INDEX(x) \ |
438 | | do { \ |
439 | | if (SLJIT_UNLIKELY(x)) { \ |
440 | | return -2; \ |
441 | | } \ |
442 | | } while (0) |
443 | | |
444 | | #elif (defined SLJIT_DEBUG && SLJIT_DEBUG) |
445 | | |
446 | | /* Assertion failure occures if an invalid argument is passed. */ |
447 | | #undef SLJIT_ARGUMENT_CHECKS |
448 | | #define SLJIT_ARGUMENT_CHECKS 1 |
449 | | |
450 | | #define CHECK_ARGUMENT(x) SLJIT_ASSERT(x) |
451 | | #define CHECK_RETURN_TYPE void |
452 | | #define CHECK_RETURN_OK return |
453 | | #define CHECK(x) x |
454 | | #define CHECK_PTR(x) x |
455 | | #define CHECK_REG_INDEX(x) x |
456 | | |
457 | | #elif (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
458 | | |
459 | | /* Arguments are not checked. */ |
460 | | #define CHECK_RETURN_TYPE void |
461 | | #define CHECK_RETURN_OK return |
462 | | #define CHECK(x) x |
463 | | #define CHECK_PTR(x) x |
464 | | #define CHECK_REG_INDEX(x) x |
465 | | |
466 | | #else /* !SLJIT_ARGUMENT_CHECKS && !SLJIT_DEBUG && !SLJIT_VERBOSE */ |
467 | | |
468 | | /* Arguments are not checked. */ |
469 | | #define CHECK(x) |
470 | | #define CHECK_PTR(x) |
471 | | #define CHECK_REG_INDEX(x) |
472 | | |
473 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
474 | | |
475 | | /* --------------------------------------------------------------------- */ |
476 | | /* Public functions */ |
477 | | /* --------------------------------------------------------------------- */ |
478 | | |
479 | | #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) || (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV) |
480 | | #define SLJIT_NEEDS_COMPILER_INIT 1 |
481 | | static sljit_s32 compiler_initialized = 0; |
482 | | /* A thread safe initialization. */ |
483 | | static void init_compiler(void); |
484 | | #endif /* SLJIT_CONFIG_X86 || SLJIT_CONFIG_RISCV */ |
485 | | |
486 | | SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data) |
487 | 70.4k | { |
488 | 70.4k | struct sljit_compiler *compiler = (struct sljit_compiler*)SLJIT_MALLOC(sizeof(struct sljit_compiler), allocator_data); |
489 | 70.4k | if (!compiler) |
490 | 0 | return NULL; |
491 | 70.4k | SLJIT_ZEROMEM(compiler, sizeof(struct sljit_compiler)); |
492 | | |
493 | 70.4k | SLJIT_COMPILE_ASSERT( |
494 | 70.4k | sizeof(sljit_s8) == 1 && sizeof(sljit_u8) == 1 |
495 | 70.4k | && sizeof(sljit_s16) == 2 && sizeof(sljit_u16) == 2 |
496 | 70.4k | && sizeof(sljit_s32) == 4 && sizeof(sljit_u32) == 4 |
497 | 70.4k | && (sizeof(sljit_up) == 4 || sizeof(sljit_up) == 8) |
498 | 70.4k | && sizeof(sljit_up) <= sizeof(sljit_sw) |
499 | 70.4k | && sizeof(sljit_up) == sizeof(sljit_sp) |
500 | 70.4k | && (sizeof(sljit_sw) == 4 || sizeof(sljit_sw) == 8) |
501 | 70.4k | && (sizeof(sljit_uw) == sizeof(sljit_sw)), |
502 | 70.4k | invalid_integer_types); |
503 | 70.4k | SLJIT_COMPILE_ASSERT((SLJIT_REWRITABLE_JUMP & SLJIT_32) == 0 |
504 | 70.4k | && (ALL_STATUS_FLAGS_MASK & SLJIT_32) == 0 |
505 | 70.4k | && (SLJIT_REWRITABLE_JUMP & ALL_STATUS_FLAGS_MASK) == 0, |
506 | 70.4k | rewritable_jump_and_status_flag_bits_and_sljit_32_must_not_have_common_bits); |
507 | 70.4k | SLJIT_COMPILE_ASSERT((VARIABLE_FLAG_MASK & SLJIT_SET_Z) == 0, |
508 | 70.4k | rewritable_jump_and_status_flag_bits_must_not_have_common_bits); |
509 | 70.4k | SLJIT_COMPILE_ASSERT(!(SLJIT_EQUAL & 0x1) && !(SLJIT_LESS & 0x1) && !(SLJIT_F_EQUAL & 0x1) && !(SLJIT_JUMP & 0x1), |
510 | 70.4k | conditional_flags_must_be_even_numbers); |
511 | | |
512 | | /* Only the non-zero members must be set. */ |
513 | 70.4k | compiler->error = SLJIT_SUCCESS; |
514 | | |
515 | 70.4k | compiler->allocator_data = allocator_data; |
516 | 70.4k | compiler->buf = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, allocator_data); |
517 | 70.4k | compiler->abuf = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, allocator_data); |
518 | | |
519 | 70.4k | if (!compiler->buf || !compiler->abuf) { |
520 | 0 | if (compiler->buf) |
521 | 0 | SLJIT_FREE(compiler->buf, allocator_data); |
522 | 0 | if (compiler->abuf) |
523 | 0 | SLJIT_FREE(compiler->abuf, allocator_data); |
524 | 0 | SLJIT_FREE(compiler, allocator_data); |
525 | 0 | return NULL; |
526 | 0 | } |
527 | | |
528 | 70.4k | compiler->buf->next = NULL; |
529 | 70.4k | compiler->buf->used_size = 0; |
530 | 70.4k | compiler->abuf->next = NULL; |
531 | 70.4k | compiler->abuf->used_size = 0; |
532 | | |
533 | 70.4k | compiler->scratches = -1; |
534 | 70.4k | compiler->saveds = -1; |
535 | 70.4k | compiler->fscratches = -1; |
536 | 70.4k | compiler->fsaveds = -1; |
537 | | #if (defined SLJIT_SEPARATE_VECTOR_REGISTERS && SLJIT_SEPARATE_VECTOR_REGISTERS) \ |
538 | | || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \ |
539 | | || (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
540 | | compiler->vscratches = -1; |
541 | | compiler->vsaveds = -1; |
542 | | #endif /* SLJIT_SEPARATE_VECTOR_REGISTERS || SLJIT_ARGUMENT_CHECKS || SLJIT_VERBOSE */ |
543 | 70.4k | compiler->local_size = -1; |
544 | | |
545 | | #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) |
546 | | compiler->args_size = -1; |
547 | | #endif /* SLJIT_CONFIG_X86_32 */ |
548 | | |
549 | | #if (defined SLJIT_CONFIG_ARM_V6 && SLJIT_CONFIG_ARM_V6) |
550 | | compiler->cpool = (sljit_uw*)SLJIT_MALLOC(CPOOL_SIZE * sizeof(sljit_uw) |
551 | | + CPOOL_SIZE * sizeof(sljit_u8), allocator_data); |
552 | | if (!compiler->cpool) { |
553 | | SLJIT_FREE(compiler->buf, allocator_data); |
554 | | SLJIT_FREE(compiler->abuf, allocator_data); |
555 | | SLJIT_FREE(compiler, allocator_data); |
556 | | return NULL; |
557 | | } |
558 | | compiler->cpool_unique = (sljit_u8*)(compiler->cpool + CPOOL_SIZE); |
559 | | compiler->cpool_diff = 0xffffffff; |
560 | | #endif /* SLJIT_CONFIG_ARM_V6 */ |
561 | | |
562 | | #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) |
563 | | compiler->delay_slot = UNMOVABLE_INS; |
564 | | #endif /* SLJIT_CONFIG_MIPS */ |
565 | | |
566 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \ |
567 | | || (defined SLJIT_DEBUG && SLJIT_DEBUG) |
568 | | SLJIT_ASSERT(compiler->last_flags == 0 && compiler->logical_local_size == 0); |
569 | | compiler->last_return = -1; |
570 | | #endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_DEBUG */ |
571 | | |
572 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \ |
573 | | || (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
574 | | #if !(defined SLJIT_SEPARATE_VECTOR_REGISTERS && SLJIT_SEPARATE_VECTOR_REGISTERS) |
575 | | compiler->real_fscratches = -1; |
576 | | compiler->real_fsaveds = -1; |
577 | | #endif /* !SLJIT_SEPARATE_VECTOR_REGISTERS */ |
578 | | SLJIT_ASSERT(compiler->skip_checks == 0); |
579 | | #endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_VERBOSE */ |
580 | | |
581 | 70.4k | #if (defined SLJIT_NEEDS_COMPILER_INIT && SLJIT_NEEDS_COMPILER_INIT) |
582 | 70.4k | if (!compiler_initialized) { |
583 | 1 | init_compiler(); |
584 | 1 | compiler_initialized = 1; |
585 | 1 | } |
586 | 70.4k | #endif /* SLJIT_NEEDS_COMPILER_INIT */ |
587 | | |
588 | 70.4k | return compiler; |
589 | 70.4k | } |
590 | | |
591 | | SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler) |
592 | 70.4k | { |
593 | 70.4k | struct sljit_memory_fragment *buf; |
594 | 70.4k | struct sljit_memory_fragment *curr; |
595 | 70.4k | void *allocator_data = compiler->allocator_data; |
596 | 70.4k | SLJIT_UNUSED_ARG(allocator_data); |
597 | | |
598 | 70.4k | buf = compiler->buf; |
599 | 2.03M | while (buf) { |
600 | 1.96M | curr = buf; |
601 | 1.96M | buf = buf->next; |
602 | 1.96M | SLJIT_FREE(curr, allocator_data); |
603 | 1.96M | } |
604 | | |
605 | 70.4k | buf = compiler->abuf; |
606 | 6.21M | while (buf) { |
607 | 6.14M | curr = buf; |
608 | 6.14M | buf = buf->next; |
609 | 6.14M | SLJIT_FREE(curr, allocator_data); |
610 | 6.14M | } |
611 | | |
612 | | #if (defined SLJIT_CONFIG_ARM_V6 && SLJIT_CONFIG_ARM_V6) |
613 | | SLJIT_FREE(compiler->cpool, allocator_data); |
614 | | #endif /* SLJIT_CONFIG_ARM_V6 */ |
615 | 70.4k | SLJIT_FREE(compiler, allocator_data); |
616 | 70.4k | } |
617 | | |
618 | | SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler) |
619 | 0 | { |
620 | 0 | if (compiler->error == SLJIT_SUCCESS) |
621 | 0 | compiler->error = SLJIT_ERR_ALLOC_FAILED; |
622 | 0 | } |
623 | | |
624 | | SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data) |
625 | 70.4k | { |
626 | 70.4k | SLJIT_UNUSED_ARG(exec_allocator_data); |
627 | | |
628 | 70.4k | SLJIT_FREE_EXEC(SLJIT_CODE_TO_PTR(code), exec_allocator_data); |
629 | 70.4k | } |
630 | | |
631 | | SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label) |
632 | 407M | { |
633 | 407M | if (SLJIT_LIKELY(!!jump) && SLJIT_LIKELY(!!label)) { |
634 | 407M | jump->flags &= (sljit_uw)~JUMP_ADDR; |
635 | 407M | jump->u.label = label; |
636 | 407M | } |
637 | 407M | } |
638 | | |
639 | | SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target) |
640 | 0 | { |
641 | 0 | if (SLJIT_LIKELY(!!jump)) { |
642 | 0 | jump->flags |= JUMP_ADDR; |
643 | 0 | jump->u.target = target; |
644 | 0 | } |
645 | 0 | } |
646 | | |
647 | | #define SLJIT_CURRENT_FLAGS_ALL (SLJIT_CURRENT_FLAGS_32 | SLJIT_CURRENT_FLAGS_ADD \ |
648 | | | SLJIT_CURRENT_FLAGS_SUB | SLJIT_CURRENT_FLAGS_COMPARE | SLJIT_CURRENT_FLAGS_OP2CMPZ) |
649 | | |
650 | | SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *compiler, sljit_s32 current_flags) |
651 | 2.70M | { |
652 | 2.70M | SLJIT_UNUSED_ARG(compiler); |
653 | 2.70M | SLJIT_UNUSED_ARG(current_flags); |
654 | | |
655 | | #if (defined SLJIT_HAS_STATUS_FLAGS_STATE && SLJIT_HAS_STATUS_FLAGS_STATE) |
656 | | #if (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X) |
657 | | if (current_flags & SLJIT_CURRENT_FLAGS_OP2CMPZ) { |
658 | | current_flags |= SLJIT_SET_Z; |
659 | | } |
660 | | #endif /* SLJIT_CONFIG_S390X */ |
661 | | |
662 | | compiler->status_flags_state = current_flags; |
663 | | #endif /* SLJIT_HAS_STATUS_FLAGS_STATE */ |
664 | | |
665 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
666 | | compiler->last_flags = 0; |
667 | | if ((current_flags & ~(ALL_STATUS_FLAGS_MASK | SLJIT_CURRENT_FLAGS_ALL)) == 0) { |
668 | | compiler->last_flags = GET_FLAG_TYPE(current_flags) | (current_flags & (SLJIT_32 | SLJIT_SET_Z)); |
669 | | } |
670 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
671 | 2.70M | } |
672 | | |
673 | | /* --------------------------------------------------------------------- */ |
674 | | /* Private functions */ |
675 | | /* --------------------------------------------------------------------- */ |
676 | | |
677 | | static void* ensure_buf(struct sljit_compiler *compiler, sljit_uw size) |
678 | 1.77G | { |
679 | 1.77G | sljit_u8 *ret; |
680 | 1.77G | struct sljit_memory_fragment *new_frag; |
681 | | |
682 | 1.77G | SLJIT_ASSERT(size <= 256); |
683 | 1.77G | if (compiler->buf->used_size + size <= (BUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) { |
684 | 1.76G | ret = compiler->buf->memory + compiler->buf->used_size; |
685 | 1.76G | compiler->buf->used_size += size; |
686 | 1.76G | return ret; |
687 | 1.76G | } |
688 | 1.89M | new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, compiler->allocator_data); |
689 | 1.89M | PTR_FAIL_IF_NULL(new_frag); |
690 | 1.89M | new_frag->next = compiler->buf; |
691 | 1.89M | compiler->buf = new_frag; |
692 | 1.89M | new_frag->used_size = size; |
693 | 1.89M | return new_frag->memory; |
694 | 1.89M | } |
695 | | |
696 | | static void* ensure_abuf(struct sljit_compiler *compiler, sljit_uw size) |
697 | 929M | { |
698 | 929M | sljit_u8 *ret; |
699 | 929M | struct sljit_memory_fragment *new_frag; |
700 | | |
701 | 929M | SLJIT_ASSERT(size <= 256); |
702 | 929M | if (compiler->abuf->used_size + size <= (ABUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) { |
703 | 923M | ret = compiler->abuf->memory + compiler->abuf->used_size; |
704 | 923M | compiler->abuf->used_size += size; |
705 | 923M | return ret; |
706 | 923M | } |
707 | 6.07M | new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, compiler->allocator_data); |
708 | 6.07M | PTR_FAIL_IF_NULL(new_frag); |
709 | 6.07M | new_frag->next = compiler->abuf; |
710 | 6.07M | compiler->abuf = new_frag; |
711 | 6.07M | new_frag->used_size = size; |
712 | 6.07M | return new_frag->memory; |
713 | 6.07M | } |
714 | | |
715 | | SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_s32 size) |
716 | 340M | { |
717 | 340M | CHECK_ERROR_PTR(); |
718 | | |
719 | 340M | #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) |
720 | 340M | if (size <= 0 || size > 128) |
721 | 0 | return NULL; |
722 | 340M | size = (size + 7) & ~7; |
723 | | #else /* !SLJIT_64BIT_ARCHITECTURE */ |
724 | | if (size <= 0 || size > 64) |
725 | | return NULL; |
726 | | size = (size + 3) & ~3; |
727 | | #endif /* SLJIT_64BIT_ARCHITECTURE */ |
728 | 340M | return ensure_abuf(compiler, (sljit_uw)size); |
729 | 340M | } |
730 | | |
731 | | static SLJIT_INLINE void reverse_buf(struct sljit_compiler *compiler) |
732 | 70.4k | { |
733 | 70.4k | struct sljit_memory_fragment *buf = compiler->buf; |
734 | 70.4k | struct sljit_memory_fragment *prev = NULL; |
735 | 70.4k | struct sljit_memory_fragment *tmp; |
736 | | |
737 | 1.96M | do { |
738 | 1.96M | tmp = buf->next; |
739 | 1.96M | buf->next = prev; |
740 | 1.96M | prev = buf; |
741 | 1.96M | buf = tmp; |
742 | 1.96M | } while (buf != NULL); |
743 | | |
744 | 70.4k | compiler->buf = prev; |
745 | 70.4k | } |
746 | | |
747 | | static SLJIT_INLINE void* allocate_executable_memory(sljit_uw size, sljit_s32 options, |
748 | | void *exec_allocator_data, sljit_sw *executable_offset) |
749 | 70.4k | { |
750 | 70.4k | void *code; |
751 | 70.4k | struct sljit_generate_code_buffer *buffer; |
752 | | |
753 | 70.4k | if (SLJIT_LIKELY(!(options & SLJIT_GENERATE_CODE_BUFFER))) { |
754 | 70.4k | code = SLJIT_MALLOC_EXEC(size, exec_allocator_data); |
755 | 70.4k | *executable_offset = SLJIT_EXEC_OFFSET(code); |
756 | 70.4k | return code; |
757 | 70.4k | } |
758 | | |
759 | 0 | buffer = (struct sljit_generate_code_buffer*)exec_allocator_data; |
760 | |
|
761 | 0 | if (size <= buffer->size) { |
762 | 0 | *executable_offset = buffer->executable_offset; |
763 | 0 | return buffer->buffer; |
764 | 0 | } |
765 | | |
766 | 0 | return NULL; |
767 | 0 | } |
768 | | |
769 | 1.13G | #define SLJIT_MAX_ADDRESS ~(sljit_uw)0 |
770 | | |
771 | 166M | #define SLJIT_GET_NEXT_SIZE(ptr) (ptr != NULL) ? ((ptr)->size) : SLJIT_MAX_ADDRESS |
772 | 423M | #define SLJIT_GET_NEXT_ADDRESS(ptr) (ptr != NULL) ? ((ptr)->addr) : SLJIT_MAX_ADDRESS |
773 | | |
774 | | #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) |
775 | | |
776 | | #define SLJIT_NEXT_DEFINE_TYPES \ |
777 | | sljit_uw next_label_size; \ |
778 | | sljit_uw next_jump_addr; \ |
779 | | sljit_uw next_const_addr; \ |
780 | | sljit_uw next_min_addr |
781 | | |
782 | | #define SLJIT_NEXT_INIT_TYPES() \ |
783 | | next_label_size = SLJIT_GET_NEXT_SIZE(label); \ |
784 | | next_jump_addr = SLJIT_GET_NEXT_ADDRESS(jump); \ |
785 | | next_const_addr = SLJIT_GET_NEXT_ADDRESS(const_); |
786 | | |
787 | | #define SLJIT_GET_NEXT_MIN() \ |
788 | | next_min_addr = sljit_get_next_min(next_label_size, next_jump_addr, next_const_addr); |
789 | | |
790 | | static SLJIT_INLINE sljit_uw sljit_get_next_min(sljit_uw next_label_size, |
791 | | sljit_uw next_jump_addr, sljit_uw next_const_addr) |
792 | | { |
793 | | sljit_uw result = next_jump_addr; |
794 | | |
795 | | SLJIT_ASSERT(result == SLJIT_MAX_ADDRESS || result != next_const_addr); |
796 | | |
797 | | if (next_const_addr < result) |
798 | | result = next_const_addr; |
799 | | |
800 | | if (next_label_size < result) |
801 | | result = next_label_size; |
802 | | |
803 | | return result; |
804 | | } |
805 | | |
806 | | #endif /* !SLJIT_CONFIG_X86 */ |
807 | | |
808 | | #if !(defined SLJIT_SEPARATE_VECTOR_REGISTERS && SLJIT_SEPARATE_VECTOR_REGISTERS) |
809 | | |
810 | | static void update_float_register_count(struct sljit_compiler *compiler, sljit_s32 scratches, sljit_s32 saveds) |
811 | 70.4k | { |
812 | 70.4k | sljit_s32 vscratches = ENTER_GET_VECTOR_REGS(scratches); |
813 | 70.4k | sljit_s32 vsaveds = ENTER_GET_VECTOR_REGS(saveds); |
814 | | |
815 | 70.4k | if (compiler->fscratches < vscratches) |
816 | 70.4k | compiler->fscratches = vscratches; |
817 | | |
818 | 70.4k | if (compiler->fsaveds < vsaveds) |
819 | 0 | compiler->fsaveds = vsaveds; |
820 | | |
821 | 70.4k | if (compiler->fsaveds + compiler->fscratches > SLJIT_NUMBER_OF_FLOAT_REGISTERS) |
822 | 0 | compiler->fscratches = SLJIT_NUMBER_OF_FLOAT_REGISTERS - compiler->fsaveds; |
823 | 70.4k | } |
824 | | |
825 | | #endif /* !SLJIT_SEPARATE_VECTOR_REGISTERS */ |
826 | | |
827 | | static SLJIT_INLINE void set_emit_enter(struct sljit_compiler *compiler, |
828 | | sljit_s32 options, sljit_s32 args, |
829 | | sljit_s32 scratches, sljit_s32 saveds, sljit_s32 local_size) |
830 | 70.4k | { |
831 | 70.4k | SLJIT_UNUSED_ARG(args); |
832 | 70.4k | SLJIT_UNUSED_ARG(local_size); |
833 | | |
834 | 70.4k | compiler->options = options; |
835 | 70.4k | compiler->scratches = ENTER_GET_REGS(scratches); |
836 | 70.4k | compiler->saveds = ENTER_GET_REGS(saveds); |
837 | | /* These members may be copied to real_* members below. */ |
838 | 70.4k | compiler->fscratches = ENTER_GET_FLOAT_REGS(scratches); |
839 | 70.4k | compiler->fsaveds = ENTER_GET_FLOAT_REGS(saveds); |
840 | | #if (defined SLJIT_SEPARATE_VECTOR_REGISTERS && SLJIT_SEPARATE_VECTOR_REGISTERS) |
841 | | compiler->vscratches = ENTER_GET_VECTOR_REGS(scratches); |
842 | | compiler->vsaveds = ENTER_GET_VECTOR_REGS(saveds); |
843 | | #else /* !SLJIT_SEPARATE_VECTOR_REGISTERS */ |
844 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \ |
845 | | || (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
846 | | compiler->real_fscratches = compiler->fscratches; |
847 | | compiler->real_fsaveds = compiler->fsaveds; |
848 | | compiler->vscratches = ENTER_GET_VECTOR_REGS(scratches); |
849 | | compiler->vsaveds = ENTER_GET_VECTOR_REGS(saveds); |
850 | | #endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_VERBOSE */ |
851 | 70.4k | update_float_register_count(compiler, scratches, saveds); |
852 | 70.4k | #endif /* SLJIT_SEPARATE_VECTOR_REGISTERS */ |
853 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
854 | | compiler->last_return = args & SLJIT_ARG_MASK; |
855 | | compiler->logical_local_size = local_size; |
856 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
857 | 70.4k | } |
858 | | |
859 | | static SLJIT_INLINE void set_label(struct sljit_label *label, struct sljit_compiler *compiler) |
860 | 165M | { |
861 | 165M | label->next = NULL; |
862 | 165M | label->u.index = compiler->label_count++; |
863 | 165M | label->size = compiler->size; |
864 | | |
865 | 165M | if (compiler->last_label != NULL) |
866 | 165M | compiler->last_label->next = label; |
867 | 70.4k | else |
868 | 70.4k | compiler->labels = label; |
869 | | |
870 | 165M | compiler->last_label = label; |
871 | 165M | } |
872 | | |
873 | | static SLJIT_INLINE void set_extended_label(struct sljit_extended_label *ext_label, struct sljit_compiler *compiler, sljit_uw type, sljit_uw data) |
874 | 0 | { |
875 | 0 | set_label(&ext_label->label, compiler); |
876 | 0 | ext_label->index = ext_label->label.u.index; |
877 | 0 | ext_label->label.u.index = type; |
878 | 0 | ext_label->data = data; |
879 | 0 | } |
880 | | |
881 | | static SLJIT_INLINE void set_jump(struct sljit_jump *jump, struct sljit_compiler *compiler, sljit_u32 flags) |
882 | 421M | { |
883 | 421M | jump->next = NULL; |
884 | 421M | jump->flags = flags; |
885 | 421M | jump->u.label = NULL; |
886 | | |
887 | 421M | if (compiler->last_jump != NULL) |
888 | 421M | compiler->last_jump->next = jump; |
889 | 70.4k | else |
890 | 70.4k | compiler->jumps = jump; |
891 | | |
892 | 421M | compiler->last_jump = jump; |
893 | 421M | } |
894 | | |
895 | | static SLJIT_INLINE void set_mov_addr(struct sljit_jump *jump, struct sljit_compiler *compiler, sljit_uw offset) |
896 | 1.54M | { |
897 | 1.54M | jump->next = NULL; |
898 | 1.54M | jump->addr = compiler->size - offset; |
899 | 1.54M | jump->flags = JUMP_MOV_ADDR; |
900 | 1.54M | jump->u.label = NULL; |
901 | 1.54M | if (compiler->last_jump != NULL) |
902 | 1.54M | compiler->last_jump->next = jump; |
903 | 0 | else |
904 | 0 | compiler->jumps = jump; |
905 | 1.54M | compiler->last_jump = jump; |
906 | 1.54M | } |
907 | | |
908 | | static SLJIT_INLINE void set_const(struct sljit_const *const_, struct sljit_compiler *compiler) |
909 | 0 | { |
910 | 0 | const_->next = NULL; |
911 | 0 | const_->addr = compiler->size; |
912 | 0 | if (compiler->last_const != NULL) |
913 | 0 | compiler->last_const->next = const_; |
914 | 0 | else |
915 | 0 | compiler->consts = const_; |
916 | 0 | compiler->last_const = const_; |
917 | 0 | } |
918 | | |
919 | | #define ADDRESSING_DEPENDS_ON(exp, reg) \ |
920 | 0 | (((exp) & SLJIT_MEM) && (((exp) & REG_MASK) == reg || OFFS_REG(exp) == reg)) |
921 | | |
922 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
923 | | |
924 | | static sljit_s32 function_check_arguments(sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches) |
925 | | { |
926 | | sljit_s32 word_arg_count, scratch_arg_end, saved_arg_count, float_arg_count, curr_type; |
927 | | |
928 | | curr_type = (arg_types & SLJIT_ARG_FULL_MASK); |
929 | | |
930 | | if (curr_type >= SLJIT_ARG_TYPE_F64) { |
931 | | if (curr_type > SLJIT_ARG_TYPE_F32 || fscratches == 0) |
932 | | return 0; |
933 | | } else if (curr_type >= SLJIT_ARG_TYPE_W) { |
934 | | if (scratches == 0) |
935 | | return 0; |
936 | | } |
937 | | |
938 | | arg_types >>= SLJIT_ARG_SHIFT; |
939 | | |
940 | | word_arg_count = 0; |
941 | | scratch_arg_end = 0; |
942 | | saved_arg_count = 0; |
943 | | float_arg_count = 0; |
944 | | while (arg_types != 0) { |
945 | | if (word_arg_count + float_arg_count >= 4) |
946 | | return 0; |
947 | | |
948 | | curr_type = (arg_types & SLJIT_ARG_MASK); |
949 | | |
950 | | if (arg_types & SLJIT_ARG_TYPE_SCRATCH_REG) { |
951 | | if (saveds == -1 || curr_type < SLJIT_ARG_TYPE_W || curr_type > SLJIT_ARG_TYPE_P) |
952 | | return 0; |
953 | | |
954 | | word_arg_count++; |
955 | | scratch_arg_end = word_arg_count; |
956 | | } else { |
957 | | if (curr_type < SLJIT_ARG_TYPE_W || curr_type > SLJIT_ARG_TYPE_F32) |
958 | | return 0; |
959 | | |
960 | | if (curr_type < SLJIT_ARG_TYPE_F64) { |
961 | | word_arg_count++; |
962 | | saved_arg_count++; |
963 | | } else |
964 | | float_arg_count++; |
965 | | } |
966 | | |
967 | | arg_types >>= SLJIT_ARG_SHIFT; |
968 | | } |
969 | | |
970 | | if (saveds == -1) |
971 | | return (word_arg_count <= scratches && float_arg_count <= fscratches); |
972 | | |
973 | | return (saved_arg_count <= saveds && scratch_arg_end <= scratches && float_arg_count <= fscratches); |
974 | | } |
975 | | |
976 | | #define FUNCTION_CHECK_IS_REG(r) \ |
977 | | (((r) >= SLJIT_R0 && (r) < (SLJIT_R0 + compiler->scratches)) \ |
978 | | || ((r) > (SLJIT_S0 - compiler->saveds) && (r) <= SLJIT_S0) \ |
979 | | || ((r) >= SLJIT_TMP_REGISTER_BASE && (r) < (SLJIT_TMP_REGISTER_BASE + SLJIT_NUMBER_OF_TEMPORARY_REGISTERS))) |
980 | | |
981 | | #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) |
982 | | #define CHECK_IF_VIRTUAL_REGISTER(p) ((p) <= SLJIT_S3 && (p) >= SLJIT_S8) |
983 | | #else /* !SLJIT_CONFIG_X86_32 */ |
984 | | #define CHECK_IF_VIRTUAL_REGISTER(p) 0 |
985 | | #endif /* SLJIT_CONFIG_X86_32 */ |
986 | | |
987 | | static sljit_s32 function_check_src_mem(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i) |
988 | | { |
989 | | if (compiler->scratches == -1) |
990 | | return 0; |
991 | | |
992 | | if (!(p & SLJIT_MEM)) |
993 | | return 0; |
994 | | |
995 | | if (p == SLJIT_MEM1(SLJIT_SP)) |
996 | | return (i >= 0 && i < compiler->logical_local_size); |
997 | | |
998 | | if (!(!(p & REG_MASK) || FUNCTION_CHECK_IS_REG(p & REG_MASK))) |
999 | | return 0; |
1000 | | |
1001 | | if (CHECK_IF_VIRTUAL_REGISTER(p & REG_MASK)) |
1002 | | return 0; |
1003 | | |
1004 | | if (p & OFFS_REG_MASK) { |
1005 | | if (!(p & REG_MASK)) |
1006 | | return 0; |
1007 | | |
1008 | | if (!(FUNCTION_CHECK_IS_REG(OFFS_REG(p)))) |
1009 | | return 0; |
1010 | | |
1011 | | if (CHECK_IF_VIRTUAL_REGISTER(OFFS_REG(p))) |
1012 | | return 0; |
1013 | | |
1014 | | if ((i & ~0x3) != 0) |
1015 | | return 0; |
1016 | | } |
1017 | | |
1018 | | return (p & ~(SLJIT_MEM | REG_MASK | OFFS_REG_MASK)) == 0; |
1019 | | } |
1020 | | |
1021 | | #define FUNCTION_CHECK_SRC_MEM(p, i) \ |
1022 | | CHECK_ARGUMENT(function_check_src_mem(compiler, p, i)); |
1023 | | |
1024 | | static sljit_s32 function_check_src(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i) |
1025 | | { |
1026 | | if (compiler->scratches == -1) |
1027 | | return 0; |
1028 | | |
1029 | | if (FUNCTION_CHECK_IS_REG(p)) |
1030 | | return (i == 0); |
1031 | | |
1032 | | if (p == SLJIT_IMM) |
1033 | | return 1; |
1034 | | |
1035 | | return function_check_src_mem(compiler, p, i); |
1036 | | } |
1037 | | |
1038 | | #define FUNCTION_CHECK_SRC(p, i) \ |
1039 | | CHECK_ARGUMENT(function_check_src(compiler, p, i)); |
1040 | | |
1041 | | static sljit_s32 function_check_dst(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i) |
1042 | | { |
1043 | | if (compiler->scratches == -1) |
1044 | | return 0; |
1045 | | |
1046 | | if (FUNCTION_CHECK_IS_REG(p)) |
1047 | | return (i == 0); |
1048 | | |
1049 | | return function_check_src_mem(compiler, p, i); |
1050 | | } |
1051 | | |
1052 | | #define FUNCTION_CHECK_DST(p, i) \ |
1053 | | CHECK_ARGUMENT(function_check_dst(compiler, p, i)); |
1054 | | |
1055 | | #if (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) \ |
1056 | | || (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) |
1057 | | |
1058 | | #define FUNCTION_CHECK_IS_FREG(fr, is_32) \ |
1059 | | function_check_is_freg(compiler, (fr), (is_32)) |
1060 | | |
1061 | | static sljit_s32 function_check_is_freg(struct sljit_compiler *compiler, sljit_s32 fr, sljit_s32 is_32); |
1062 | | |
1063 | | #define FUNCTION_FCHECK(p, i, is_32) \ |
1064 | | CHECK_ARGUMENT(function_fcheck(compiler, (p), (i), (is_32))); |
1065 | | |
1066 | | static sljit_s32 function_fcheck(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i, sljit_s32 is_32) |
1067 | | { |
1068 | | if (compiler->scratches == -1) |
1069 | | return 0; |
1070 | | |
1071 | | if (FUNCTION_CHECK_IS_FREG(p, is_32)) |
1072 | | return (i == 0); |
1073 | | |
1074 | | return function_check_src_mem(compiler, p, i); |
1075 | | } |
1076 | | |
1077 | | static sljit_s32 function_check_is_vreg(struct sljit_compiler *compiler, sljit_s32 vr, sljit_s32 type); |
1078 | | |
1079 | | #define FUNCTION_CHECK_IS_VREG(vr, type) \ |
1080 | | function_check_is_vreg(compiler, (vr), (type)) |
1081 | | |
1082 | | #define FUNCTION_VCHECK(p, i, type) \ |
1083 | | CHECK_ARGUMENT(function_vcheck(compiler, (p), (i), (type))) |
1084 | | |
1085 | | static sljit_s32 function_vcheck(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i, sljit_s32 type) |
1086 | | { |
1087 | | if (compiler->scratches == -1) |
1088 | | return 0; |
1089 | | |
1090 | | if (FUNCTION_CHECK_IS_VREG(p, type)) |
1091 | | return (i == 0); |
1092 | | |
1093 | | return function_check_src_mem(compiler, p, i); |
1094 | | } |
1095 | | |
1096 | | #else /* !SLJIT_CONFIG_ARM_32 && !SLJIT_CONFIG_MIPS_32 */ |
1097 | | |
1098 | | #define FUNCTION_CHECK_IS_FREG(fr, is_32) \ |
1099 | | function_check_is_freg(compiler, (fr)) |
1100 | | |
1101 | | static sljit_s32 function_check_is_freg(struct sljit_compiler *compiler, sljit_s32 fr) |
1102 | | { |
1103 | | sljit_s32 fscratches, fsaveds; |
1104 | | |
1105 | | if (compiler->scratches == -1) |
1106 | | return 0; |
1107 | | |
1108 | | #if (defined SLJIT_SEPARATE_VECTOR_REGISTERS && SLJIT_SEPARATE_VECTOR_REGISTERS) |
1109 | | fscratches = compiler->fscratches; |
1110 | | fsaveds = compiler->fsaveds; |
1111 | | #else /* SLJIT_SEPARATE_VECTOR_REGISTERS */ |
1112 | | fscratches = compiler->real_fscratches; |
1113 | | fsaveds = compiler->real_fsaveds; |
1114 | | #endif /* !SLJIT_SEPARATE_VECTOR_REGISTERS */ |
1115 | | |
1116 | | return (fr >= SLJIT_FR0 && fr < (SLJIT_FR0 + fscratches)) |
1117 | | || (fr > (SLJIT_FS0 - fsaveds) && fr <= SLJIT_FS0) |
1118 | | || (fr >= SLJIT_TMP_FREGISTER_BASE && fr < (SLJIT_TMP_FREGISTER_BASE + SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS)); |
1119 | | } |
1120 | | |
1121 | | #define FUNCTION_FCHECK(p, i, is_32) \ |
1122 | | CHECK_ARGUMENT(function_fcheck(compiler, (p), (i))); |
1123 | | |
1124 | | static sljit_s32 function_fcheck(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i) |
1125 | | { |
1126 | | if (compiler->scratches == -1) |
1127 | | return 0; |
1128 | | |
1129 | | if (function_check_is_freg(compiler, p)) |
1130 | | return (i == 0); |
1131 | | |
1132 | | return function_check_src_mem(compiler, p, i); |
1133 | | } |
1134 | | |
1135 | | #define FUNCTION_CHECK_IS_VREG(vr, type) \ |
1136 | | function_check_is_vreg(compiler, (vr)) |
1137 | | |
1138 | | static sljit_s32 function_check_is_vreg(struct sljit_compiler *compiler, sljit_s32 vr) |
1139 | | { |
1140 | | if (compiler->scratches == -1) |
1141 | | return 0; |
1142 | | |
1143 | | return (vr >= SLJIT_VR0 && vr < (SLJIT_VR0 + compiler->vscratches)) |
1144 | | || (vr > (SLJIT_VS0 - compiler->vsaveds) && vr <= SLJIT_VS0) |
1145 | | || (vr >= SLJIT_TMP_VREGISTER_BASE && vr < (SLJIT_TMP_VREGISTER_BASE + SLJIT_NUMBER_OF_TEMPORARY_VECTOR_REGISTERS)); |
1146 | | } |
1147 | | |
1148 | | #define FUNCTION_VCHECK(p, i, type) \ |
1149 | | CHECK_ARGUMENT(function_vcheck(compiler, (p), (i))) |
1150 | | |
1151 | | static sljit_s32 function_vcheck(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i) |
1152 | | { |
1153 | | if (compiler->scratches == -1) |
1154 | | return 0; |
1155 | | |
1156 | | if (function_check_is_vreg(compiler, p)) |
1157 | | return (i == 0); |
1158 | | |
1159 | | return function_check_src_mem(compiler, p, i); |
1160 | | } |
1161 | | |
1162 | | #endif /* SLJIT_CONFIG_ARM_32 || SLJIT_CONFIG_MIPS_32 */ |
1163 | | |
1164 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
1165 | | |
1166 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
1167 | | |
1168 | | SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose) |
1169 | | { |
1170 | | compiler->verbose = verbose; |
1171 | | } |
1172 | | |
1173 | | #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) |
1174 | | #ifdef _WIN64 |
1175 | | #ifdef __GNUC__ |
1176 | | # define SLJIT_PRINT_D "ll" |
1177 | | #else /* !__GNUC__ */ |
1178 | | # define SLJIT_PRINT_D "I64" |
1179 | | #endif /* __GNUC__ */ |
1180 | | #else /* !_WIN64 */ |
1181 | | # define SLJIT_PRINT_D "l" |
1182 | | #endif /* _WIN64 */ |
1183 | | #else /* !SLJIT_64BIT_ARCHITECTURE */ |
1184 | | # define SLJIT_PRINT_D "" |
1185 | | #endif /* SLJIT_64BIT_ARCHITECTURE */ |
1186 | | |
1187 | | static void sljit_verbose_reg(struct sljit_compiler *compiler, sljit_s32 r) |
1188 | | { |
1189 | | if (r < (SLJIT_R0 + compiler->scratches)) |
1190 | | fprintf(compiler->verbose, "r%d", r - SLJIT_R0); |
1191 | | else if (r < SLJIT_SP) |
1192 | | fprintf(compiler->verbose, "s%d", SLJIT_NUMBER_OF_REGISTERS - r); |
1193 | | else if (r == SLJIT_SP) |
1194 | | fprintf(compiler->verbose, "sp"); |
1195 | | else |
1196 | | fprintf(compiler->verbose, "t%d", r - SLJIT_TMP_REGISTER_BASE); |
1197 | | } |
1198 | | |
1199 | | static void sljit_verbose_freg(struct sljit_compiler *compiler, sljit_s32 r) |
1200 | | { |
1201 | | #if (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) \ |
1202 | | || (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) |
1203 | | if (r >= SLJIT_F64_SECOND(SLJIT_FR0)) { |
1204 | | fprintf(compiler->verbose, "^"); |
1205 | | r -= SLJIT_F64_SECOND(0); |
1206 | | } |
1207 | | #endif /* SLJIT_CONFIG_ARM_32 || SLJIT_CONFIG_MIPS_32 */ |
1208 | | |
1209 | | if (r < (SLJIT_FR0 + compiler->fscratches)) |
1210 | | fprintf(compiler->verbose, "fr%d", r - SLJIT_FR0); |
1211 | | else if (r < SLJIT_TMP_FREGISTER_BASE) |
1212 | | fprintf(compiler->verbose, "fs%d", SLJIT_NUMBER_OF_FLOAT_REGISTERS - r); |
1213 | | else |
1214 | | fprintf(compiler->verbose, "ft%d", r - SLJIT_TMP_FREGISTER_BASE); |
1215 | | } |
1216 | | |
1217 | | static void sljit_verbose_vreg(struct sljit_compiler *compiler, sljit_s32 r) |
1218 | | { |
1219 | | #if (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) \ |
1220 | | || (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) |
1221 | | if (r >= SLJIT_F64_SECOND(SLJIT_VR0)) { |
1222 | | fprintf(compiler->verbose, "^"); |
1223 | | r -= SLJIT_F64_SECOND(0); |
1224 | | } |
1225 | | #endif /* SLJIT_CONFIG_ARM_32 || SLJIT_CONFIG_MIPS_32 */ |
1226 | | |
1227 | | if (r < (SLJIT_VR0 + compiler->vscratches)) |
1228 | | fprintf(compiler->verbose, "vr%d", r - SLJIT_VR0); |
1229 | | else if (r < SLJIT_TMP_VREGISTER_BASE) |
1230 | | fprintf(compiler->verbose, "vs%d", SLJIT_NUMBER_OF_VECTOR_REGISTERS - r); |
1231 | | else |
1232 | | fprintf(compiler->verbose, "vt%d", r - SLJIT_TMP_VREGISTER_BASE); |
1233 | | } |
1234 | | |
1235 | | static void sljit_verbose_mem(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i) |
1236 | | { |
1237 | | if (!(p & REG_MASK)) { |
1238 | | fprintf(compiler->verbose, "[%" SLJIT_PRINT_D "d]", i); |
1239 | | return; |
1240 | | } |
1241 | | |
1242 | | fputc('[', compiler->verbose); |
1243 | | sljit_verbose_reg(compiler, (p) & REG_MASK); |
1244 | | if (p & OFFS_REG_MASK) { |
1245 | | fprintf(compiler->verbose, " + "); |
1246 | | sljit_verbose_reg(compiler, OFFS_REG(p)); |
1247 | | if (i) |
1248 | | fprintf(compiler->verbose, " * %d", 1 << (i)); |
1249 | | } else if (i) |
1250 | | fprintf(compiler->verbose, " + %" SLJIT_PRINT_D "d", (i)); |
1251 | | fputc(']', compiler->verbose); |
1252 | | } |
1253 | | |
1254 | | static void sljit_verbose_param(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i) |
1255 | | { |
1256 | | if (p == SLJIT_IMM) |
1257 | | fprintf(compiler->verbose, "#%" SLJIT_PRINT_D "d", i); |
1258 | | else if (p & SLJIT_MEM) |
1259 | | sljit_verbose_mem(compiler, p, i); |
1260 | | else |
1261 | | sljit_verbose_reg(compiler, p); |
1262 | | } |
1263 | | |
1264 | | static void sljit_verbose_fparam(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i) |
1265 | | { |
1266 | | if (p & SLJIT_MEM) |
1267 | | sljit_verbose_mem(compiler, p, i); |
1268 | | else |
1269 | | sljit_verbose_freg(compiler, p); |
1270 | | } |
1271 | | |
1272 | | static void sljit_verbose_vparam(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i) |
1273 | | { |
1274 | | if (p & SLJIT_MEM) |
1275 | | sljit_verbose_mem(compiler, p, i); |
1276 | | else |
1277 | | sljit_verbose_vreg(compiler, p); |
1278 | | } |
1279 | | |
1280 | | static const char* op0_names[] = { |
1281 | | "breakpoint", "nop", "lmul.uw", "lmul.sw", |
1282 | | "divmod.u", "divmod.s", "div.u", "div.s", |
1283 | | "memory_barrier", "endbr", "skip_frames_before_return" |
1284 | | }; |
1285 | | |
1286 | | static const char* op1_names[] = { |
1287 | | "mov", "mov", "mov", "mov", |
1288 | | "mov", "mov", "mov", "mov", |
1289 | | "mov", "clz", "ctz", "rev", |
1290 | | "rev", "rev", "rev", "rev" |
1291 | | }; |
1292 | | |
1293 | | static const char* op1_types[] = { |
1294 | | "", ".u8", ".s8", ".u16", |
1295 | | ".s16", ".u32", ".s32", "32", |
1296 | | ".p", "", "", "", |
1297 | | ".u16", ".s16", ".u32", ".s32" |
1298 | | }; |
1299 | | |
1300 | | static const char* op2_names[] = { |
1301 | | "add", "addc", "sub", "subc", |
1302 | | "mul", "and", "or", "xor", |
1303 | | "shl", "mshl", "lshr", "mlshr", |
1304 | | "ashr", "mashr", "rotl", "rotr" |
1305 | | }; |
1306 | | |
1307 | | static const char* op2r_names[] = { |
1308 | | "muladd" |
1309 | | }; |
1310 | | |
1311 | | static const char* op_src_dst_names[] = { |
1312 | | "fast_return", "skip_frames_before_fast_return", |
1313 | | "prefetch_l1", "prefetch_l2", |
1314 | | "prefetch_l3", "prefetch_once", |
1315 | | "fast_enter", "get_return_address" |
1316 | | }; |
1317 | | |
1318 | | static const char* fop1_names[] = { |
1319 | | "mov", "conv", "conv", "conv", |
1320 | | "conv", "conv", "conv", "conv", |
1321 | | "cmp", "neg", "abs", |
1322 | | }; |
1323 | | |
1324 | | static const char* fop1_conv_types[] = { |
1325 | | "sw", "s32", "sw", "s32", |
1326 | | "uw", "u32" |
1327 | | }; |
1328 | | |
1329 | | static const char* fop2_names[] = { |
1330 | | "add", "sub", "mul", "div" |
1331 | | }; |
1332 | | |
1333 | | static const char* fop2r_names[] = { |
1334 | | "copysign" |
1335 | | }; |
1336 | | |
1337 | | static const char* simd_op2_names[] = { |
1338 | | "and", "or", "xor", "shuffle" |
1339 | | }; |
1340 | | |
1341 | | static const char* jump_names[] = { |
1342 | | "equal", "not_equal", |
1343 | | "less", "greater_equal", |
1344 | | "greater", "less_equal", |
1345 | | "sig_less", "sig_greater_equal", |
1346 | | "sig_greater", "sig_less_equal", |
1347 | | "overflow", "not_overflow", |
1348 | | "carry", "not_carry", |
1349 | | "atomic_stored", "atomic_not_stored", |
1350 | | "f_equal", "f_not_equal", |
1351 | | "f_less", "f_greater_equal", |
1352 | | "f_greater", "f_less_equal", |
1353 | | "unordered", "ordered", |
1354 | | "ordered_equal", "unordered_or_not_equal", |
1355 | | "ordered_less", "unordered_or_greater_equal", |
1356 | | "ordered_greater", "unordered_or_less_equal", |
1357 | | "unordered_or_equal", "ordered_not_equal", |
1358 | | "unordered_or_less", "ordered_greater_equal", |
1359 | | "unordered_or_greater", "ordered_less_equal", |
1360 | | "jump", "fast_call", |
1361 | | "call", "call_reg_arg" |
1362 | | }; |
1363 | | |
1364 | | static const char* call_arg_names[] = { |
1365 | | "void", "w", "32", "p", "f64", "f32" |
1366 | | }; |
1367 | | |
1368 | | static const char* op_addr_types[] = { |
1369 | | "mov_addr", "mov_abs_addr", "add_abs_addr" |
1370 | | }; |
1371 | | |
1372 | | #endif /* SLJIT_VERBOSE */ |
1373 | | |
1374 | | /* --------------------------------------------------------------------- */ |
1375 | | /* Arch dependent */ |
1376 | | /* --------------------------------------------------------------------- */ |
1377 | | |
1378 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \ |
1379 | | || (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
1380 | | |
1381 | | #define SLJIT_SKIP_CHECKS(compiler) (compiler)->skip_checks = 1 |
1382 | | #define SLJIT_CHECK_OPCODE(op, flags) ((op) & ~(SLJIT_32 | ALL_STATUS_FLAGS_MASK | (flags))) |
1383 | | |
1384 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_generate_code(struct sljit_compiler *compiler) |
1385 | | { |
1386 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
1387 | | struct sljit_jump *jump; |
1388 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
1389 | | |
1390 | | SLJIT_UNUSED_ARG(compiler); |
1391 | | |
1392 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
1393 | | CHECK_ARGUMENT(compiler->size > 0); |
1394 | | jump = compiler->jumps; |
1395 | | while (jump) { |
1396 | | /* All jumps have target. */ |
1397 | | CHECK_ARGUMENT((jump->flags & JUMP_ADDR) || jump->u.label != NULL); |
1398 | | jump = jump->next; |
1399 | | } |
1400 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
1401 | | CHECK_RETURN_OK; |
1402 | | } |
1403 | | |
1404 | | #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) |
1405 | | #define SLJIT_ENTER_CPU_SPECIFIC_OPTIONS (SLJIT_ENTER_USE_VEX) |
1406 | | #else /* !SLJIT_CONFIG_X86 */ |
1407 | | #define SLJIT_ENTER_CPU_SPECIFIC_OPTIONS (0) |
1408 | | #endif /* !SLJIT_CONFIG_X86 */ |
1409 | | |
1410 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_enter(struct sljit_compiler *compiler, |
1411 | | sljit_s32 options, sljit_s32 arg_types, |
1412 | | sljit_s32 scratches, sljit_s32 saveds, sljit_s32 local_size) |
1413 | | { |
1414 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
1415 | | sljit_s32 real_scratches = ENTER_GET_REGS(scratches); |
1416 | | sljit_s32 real_saveds = ENTER_GET_REGS(saveds); |
1417 | | sljit_s32 real_fscratches = ENTER_GET_FLOAT_REGS(scratches); |
1418 | | sljit_s32 real_fsaveds = ENTER_GET_FLOAT_REGS(saveds); |
1419 | | sljit_s32 real_vscratches = ENTER_GET_VECTOR_REGS(scratches); |
1420 | | sljit_s32 real_vsaveds = ENTER_GET_VECTOR_REGS(saveds); |
1421 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
1422 | | SLJIT_UNUSED_ARG(compiler); |
1423 | | |
1424 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
1425 | | if (options & SLJIT_ENTER_REG_ARG) { |
1426 | | CHECK_ARGUMENT(!(options & ~(0x3 | SLJIT_ENTER_REG_ARG | SLJIT_ENTER_CPU_SPECIFIC_OPTIONS))); |
1427 | | } else { |
1428 | | CHECK_ARGUMENT((options & ~SLJIT_ENTER_CPU_SPECIFIC_OPTIONS) == 0); |
1429 | | } |
1430 | | CHECK_ARGUMENT(SLJIT_KEPT_SAVEDS_COUNT(options) <= 3 && SLJIT_KEPT_SAVEDS_COUNT(options) <= saveds); |
1431 | | CHECK_ARGUMENT((scratches & ~0xffffff) == 0 && (saveds & ~0xffffff) == 0); |
1432 | | CHECK_ARGUMENT(real_scratches >= 0 && real_scratches <= SLJIT_NUMBER_OF_REGISTERS); |
1433 | | CHECK_ARGUMENT(real_saveds >= 0 && real_saveds <= SLJIT_NUMBER_OF_SAVED_REGISTERS); |
1434 | | CHECK_ARGUMENT(real_scratches + real_saveds <= SLJIT_NUMBER_OF_REGISTERS); |
1435 | | CHECK_ARGUMENT(real_fscratches >= 0 && real_fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS); |
1436 | | CHECK_ARGUMENT(real_fsaveds >= 0 && real_fsaveds <= SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS); |
1437 | | CHECK_ARGUMENT(real_fscratches + real_fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS); |
1438 | | CHECK_ARGUMENT(real_vscratches >= 0 && real_vscratches <= SLJIT_NUMBER_OF_VECTOR_REGISTERS); |
1439 | | CHECK_ARGUMENT(real_vsaveds >= 0 && real_vsaveds <= SLJIT_NUMBER_OF_SAVED_VECTOR_REGISTERS); |
1440 | | CHECK_ARGUMENT(real_vscratches + real_vsaveds <= SLJIT_NUMBER_OF_VECTOR_REGISTERS); |
1441 | | CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE); |
1442 | | CHECK_ARGUMENT((arg_types & SLJIT_ARG_FULL_MASK) <= SLJIT_ARG_TYPE_F32); |
1443 | | CHECK_ARGUMENT(function_check_arguments(arg_types, real_scratches, |
1444 | | (options & SLJIT_ENTER_REG_ARG) ? 0 : real_saveds, real_fscratches)); |
1445 | | |
1446 | | compiler->last_flags = 0; |
1447 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
1448 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
1449 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
1450 | | fprintf(compiler->verbose, " enter ret[%s", call_arg_names[arg_types & SLJIT_ARG_MASK]); |
1451 | | |
1452 | | arg_types >>= SLJIT_ARG_SHIFT; |
1453 | | if (arg_types) { |
1454 | | fprintf(compiler->verbose, "], args["); |
1455 | | do { |
1456 | | fprintf(compiler->verbose, "%s%s", call_arg_names[arg_types & SLJIT_ARG_MASK], |
1457 | | (arg_types & SLJIT_ARG_TYPE_SCRATCH_REG) ? "_r" : ""); |
1458 | | arg_types >>= SLJIT_ARG_SHIFT; |
1459 | | if (arg_types) |
1460 | | fprintf(compiler->verbose, ","); |
1461 | | } while (arg_types); |
1462 | | } |
1463 | | |
1464 | | fprintf(compiler->verbose, "],"); |
1465 | | |
1466 | | if (options & SLJIT_ENTER_REG_ARG) { |
1467 | | if (SLJIT_KEPT_SAVEDS_COUNT(options) > 0) |
1468 | | fprintf(compiler->verbose, " opt:reg_arg(%d),", SLJIT_KEPT_SAVEDS_COUNT(options)); |
1469 | | else |
1470 | | fprintf(compiler->verbose, " opt:reg_arg,"); |
1471 | | } |
1472 | | |
1473 | | #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) |
1474 | | if (options & SLJIT_ENTER_USE_VEX) { |
1475 | | fprintf(compiler->verbose, " opt:use_vex,"); |
1476 | | } |
1477 | | #endif /* !SLJIT_CONFIG_X86 */ |
1478 | | |
1479 | | fprintf(compiler->verbose, " scratches:%d, saveds:%d, fscratches:%d, fsaveds:%d, vscratches:%d, vsaveds:%d, local_size:%d\n", |
1480 | | ENTER_GET_REGS(scratches), ENTER_GET_REGS(saveds), ENTER_GET_FLOAT_REGS(scratches), ENTER_GET_FLOAT_REGS(saveds), |
1481 | | ENTER_GET_VECTOR_REGS(scratches), ENTER_GET_VECTOR_REGS(saveds), local_size); |
1482 | | } |
1483 | | #endif /* SLJIT_VERBOSE */ |
1484 | | CHECK_RETURN_OK; |
1485 | | } |
1486 | | |
1487 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_set_context(struct sljit_compiler *compiler, |
1488 | | sljit_s32 options, sljit_s32 arg_types, |
1489 | | sljit_s32 scratches, sljit_s32 saveds, sljit_s32 local_size) |
1490 | | { |
1491 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
1492 | | sljit_s32 real_scratches = ENTER_GET_REGS(scratches); |
1493 | | sljit_s32 real_saveds = ENTER_GET_REGS(saveds); |
1494 | | sljit_s32 real_fscratches = ENTER_GET_FLOAT_REGS(scratches); |
1495 | | sljit_s32 real_fsaveds = ENTER_GET_FLOAT_REGS(saveds); |
1496 | | sljit_s32 real_vscratches = ENTER_GET_VECTOR_REGS(scratches); |
1497 | | sljit_s32 real_vsaveds = ENTER_GET_VECTOR_REGS(saveds); |
1498 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
1499 | | SLJIT_UNUSED_ARG(compiler); |
1500 | | |
1501 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
1502 | | if (options & SLJIT_ENTER_REG_ARG) { |
1503 | | CHECK_ARGUMENT(!(options & ~(0x3 | SLJIT_ENTER_REG_ARG | SLJIT_ENTER_CPU_SPECIFIC_OPTIONS))); |
1504 | | } else { |
1505 | | CHECK_ARGUMENT((options & ~SLJIT_ENTER_CPU_SPECIFIC_OPTIONS) == 0); |
1506 | | } |
1507 | | CHECK_ARGUMENT(SLJIT_KEPT_SAVEDS_COUNT(options) <= 3 && SLJIT_KEPT_SAVEDS_COUNT(options) <= saveds); |
1508 | | CHECK_ARGUMENT((scratches & ~0xffffff) == 0 && (saveds & ~0xffffff) == 0); |
1509 | | CHECK_ARGUMENT(real_scratches >= 0 && real_scratches <= SLJIT_NUMBER_OF_REGISTERS); |
1510 | | CHECK_ARGUMENT(real_saveds >= 0 && real_saveds <= SLJIT_NUMBER_OF_SAVED_REGISTERS); |
1511 | | CHECK_ARGUMENT(real_scratches + real_saveds <= SLJIT_NUMBER_OF_REGISTERS); |
1512 | | CHECK_ARGUMENT(real_fscratches >= 0 && real_fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS); |
1513 | | CHECK_ARGUMENT(real_fsaveds >= 0 && real_fsaveds <= SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS); |
1514 | | CHECK_ARGUMENT(real_fscratches + real_fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS); |
1515 | | CHECK_ARGUMENT(real_vscratches >= 0 && real_vscratches <= SLJIT_NUMBER_OF_VECTOR_REGISTERS); |
1516 | | CHECK_ARGUMENT(real_vsaveds >= 0 && real_vsaveds <= SLJIT_NUMBER_OF_SAVED_VECTOR_REGISTERS); |
1517 | | CHECK_ARGUMENT(real_vscratches + real_vsaveds <= SLJIT_NUMBER_OF_VECTOR_REGISTERS); |
1518 | | CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE); |
1519 | | CHECK_ARGUMENT((arg_types & SLJIT_ARG_FULL_MASK) < SLJIT_ARG_TYPE_F64); |
1520 | | CHECK_ARGUMENT(function_check_arguments(arg_types, real_scratches, |
1521 | | (options & SLJIT_ENTER_REG_ARG) ? 0 : real_saveds, real_fscratches)); |
1522 | | |
1523 | | compiler->last_flags = 0; |
1524 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
1525 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
1526 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
1527 | | fprintf(compiler->verbose, " set_context ret[%s", call_arg_names[arg_types & SLJIT_ARG_MASK]); |
1528 | | |
1529 | | arg_types >>= SLJIT_ARG_SHIFT; |
1530 | | if (arg_types) { |
1531 | | fprintf(compiler->verbose, "], args["); |
1532 | | do { |
1533 | | fprintf(compiler->verbose, "%s%s", call_arg_names[arg_types & SLJIT_ARG_MASK], |
1534 | | (arg_types & SLJIT_ARG_TYPE_SCRATCH_REG) ? "_r" : ""); |
1535 | | arg_types >>= SLJIT_ARG_SHIFT; |
1536 | | if (arg_types) |
1537 | | fprintf(compiler->verbose, ","); |
1538 | | } while (arg_types); |
1539 | | } |
1540 | | |
1541 | | fprintf(compiler->verbose, "],"); |
1542 | | |
1543 | | if (options & SLJIT_ENTER_REG_ARG) { |
1544 | | if (SLJIT_KEPT_SAVEDS_COUNT(options) > 0) |
1545 | | fprintf(compiler->verbose, " opt:reg_arg(%d),", SLJIT_KEPT_SAVEDS_COUNT(options)); |
1546 | | else |
1547 | | fprintf(compiler->verbose, " opt:reg_arg,"); |
1548 | | } |
1549 | | |
1550 | | #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) |
1551 | | if (options & SLJIT_ENTER_USE_VEX) { |
1552 | | fprintf(compiler->verbose, " opt:use_vex,"); |
1553 | | } |
1554 | | #endif /* !SLJIT_CONFIG_X86 */ |
1555 | | |
1556 | | fprintf(compiler->verbose, " scratches:%d, saveds:%d, fscratches:%d, fsaveds:%d, vscratches:%d, vsaveds:%d, local_size:%d\n", |
1557 | | ENTER_GET_REGS(scratches), ENTER_GET_REGS(saveds), ENTER_GET_FLOAT_REGS(scratches), ENTER_GET_FLOAT_REGS(saveds), |
1558 | | ENTER_GET_VECTOR_REGS(scratches), ENTER_GET_VECTOR_REGS(saveds), local_size); |
1559 | | } |
1560 | | #endif /* SLJIT_VERBOSE */ |
1561 | | CHECK_RETURN_OK; |
1562 | | } |
1563 | | |
1564 | | #undef SLJIT_ENTER_CPU_SPECIFIC_OPTIONS |
1565 | | |
1566 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_return_void(struct sljit_compiler *compiler) |
1567 | | { |
1568 | | if (SLJIT_UNLIKELY(compiler->skip_checks)) { |
1569 | | compiler->skip_checks = 0; |
1570 | | CHECK_RETURN_OK; |
1571 | | } |
1572 | | |
1573 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
1574 | | CHECK_ARGUMENT(compiler->last_return == SLJIT_ARG_TYPE_RET_VOID); |
1575 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
1576 | | |
1577 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
1578 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
1579 | | fprintf(compiler->verbose, " return_void\n"); |
1580 | | } |
1581 | | #endif /* SLJIT_VERBOSE */ |
1582 | | CHECK_RETURN_OK; |
1583 | | } |
1584 | | |
1585 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw) |
1586 | | { |
1587 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
1588 | | CHECK_ARGUMENT(compiler->scratches >= 0); |
1589 | | |
1590 | | switch (compiler->last_return) { |
1591 | | case SLJIT_ARG_TYPE_W: |
1592 | | CHECK_ARGUMENT(op >= SLJIT_MOV && op <= SLJIT_MOV_S32); |
1593 | | break; |
1594 | | case SLJIT_ARG_TYPE_32: |
1595 | | CHECK_ARGUMENT(op == SLJIT_MOV32 || (op >= SLJIT_MOV32_U8 && op <= SLJIT_MOV32_S16)); |
1596 | | break; |
1597 | | case SLJIT_ARG_TYPE_P: |
1598 | | CHECK_ARGUMENT(op == SLJIT_MOV_P); |
1599 | | break; |
1600 | | case SLJIT_ARG_TYPE_F64: |
1601 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU)); |
1602 | | CHECK_ARGUMENT(op == SLJIT_MOV_F64); |
1603 | | break; |
1604 | | case SLJIT_ARG_TYPE_F32: |
1605 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU)); |
1606 | | CHECK_ARGUMENT(op == SLJIT_MOV_F32); |
1607 | | break; |
1608 | | default: |
1609 | | /* Context not initialized, void, etc. */ |
1610 | | CHECK_ARGUMENT(0); |
1611 | | break; |
1612 | | } |
1613 | | |
1614 | | if (SLJIT_CHECK_OPCODE(op, 0) < SLJIT_MOV_F64) { |
1615 | | FUNCTION_CHECK_SRC(src, srcw); |
1616 | | } else { |
1617 | | FUNCTION_FCHECK(src, srcw, op & SLJIT_32); |
1618 | | } |
1619 | | compiler->last_flags = 0; |
1620 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
1621 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
1622 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
1623 | | if (GET_OPCODE(op) < SLJIT_MOV_F64) { |
1624 | | fprintf(compiler->verbose, " return%s%s ", !(op & SLJIT_32) ? "" : "32", |
1625 | | op1_types[GET_OPCODE(op) - SLJIT_OP1_BASE]); |
1626 | | sljit_verbose_param(compiler, src, srcw); |
1627 | | } else { |
1628 | | fprintf(compiler->verbose, " return%s ", !(op & SLJIT_32) ? ".f64" : ".f32"); |
1629 | | sljit_verbose_fparam(compiler, src, srcw); |
1630 | | } |
1631 | | fprintf(compiler->verbose, "\n"); |
1632 | | } |
1633 | | #endif /* SLJIT_VERBOSE */ |
1634 | | CHECK_RETURN_OK; |
1635 | | } |
1636 | | |
1637 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_return_to(struct sljit_compiler *compiler, |
1638 | | sljit_s32 src, sljit_sw srcw) |
1639 | | { |
1640 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
1641 | | FUNCTION_CHECK_SRC(src, srcw); |
1642 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
1643 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
1644 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
1645 | | fprintf(compiler->verbose, " return_to "); |
1646 | | sljit_verbose_param(compiler, src, srcw); |
1647 | | fprintf(compiler->verbose, "\n"); |
1648 | | } |
1649 | | #endif /* SLJIT_VERBOSE */ |
1650 | | CHECK_RETURN_OK; |
1651 | | } |
1652 | | |
1653 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op) |
1654 | | { |
1655 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
1656 | | CHECK_ARGUMENT((op >= SLJIT_BREAKPOINT && op <= SLJIT_LMUL_SW) |
1657 | | || ((op & ~SLJIT_32) >= SLJIT_DIVMOD_UW && (op & ~SLJIT_32) <= SLJIT_DIV_SW) |
1658 | | || (op >= SLJIT_MEMORY_BARRIER && op <= SLJIT_SKIP_FRAMES_BEFORE_RETURN)); |
1659 | | CHECK_ARGUMENT(SLJIT_CHECK_OPCODE(op, 0) < SLJIT_LMUL_UW || SLJIT_CHECK_OPCODE(op, 0) >= SLJIT_MEMORY_BARRIER || compiler->scratches >= 2); |
1660 | | if ((SLJIT_CHECK_OPCODE(op, 0) >= SLJIT_LMUL_UW && SLJIT_CHECK_OPCODE(op, 0) <= SLJIT_DIV_SW) || op == SLJIT_SKIP_FRAMES_BEFORE_RETURN) |
1661 | | compiler->last_flags = 0; |
1662 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
1663 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
1664 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) |
1665 | | { |
1666 | | fprintf(compiler->verbose, " %s", op0_names[GET_OPCODE(op) - SLJIT_OP0_BASE]); |
1667 | | if (GET_OPCODE(op) >= SLJIT_DIVMOD_UW && GET_OPCODE(op) <= SLJIT_DIV_SW) { |
1668 | | fprintf(compiler->verbose, (op & SLJIT_32) ? "32" : "w"); |
1669 | | } |
1670 | | fprintf(compiler->verbose, "\n"); |
1671 | | } |
1672 | | #endif /* SLJIT_VERBOSE */ |
1673 | | CHECK_RETURN_OK; |
1674 | | } |
1675 | | |
1676 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op, |
1677 | | sljit_s32 dst, sljit_sw dstw, |
1678 | | sljit_s32 src, sljit_sw srcw) |
1679 | | { |
1680 | | if (SLJIT_UNLIKELY(compiler->skip_checks)) { |
1681 | | compiler->skip_checks = 0; |
1682 | | CHECK_RETURN_OK; |
1683 | | } |
1684 | | |
1685 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
1686 | | CHECK_ARGUMENT(SLJIT_CHECK_OPCODE(op, 0) >= SLJIT_MOV && SLJIT_CHECK_OPCODE(op, 0) <= SLJIT_REV_S32); |
1687 | | |
1688 | | switch (GET_OPCODE(op)) { |
1689 | | case SLJIT_MOV: |
1690 | | case SLJIT_MOV_U32: |
1691 | | case SLJIT_MOV_S32: |
1692 | | case SLJIT_MOV32: |
1693 | | case SLJIT_MOV_P: |
1694 | | case SLJIT_REV_U32: |
1695 | | case SLJIT_REV_S32: |
1696 | | /* Nothing allowed */ |
1697 | | CHECK_ARGUMENT(!(op & (SLJIT_32 | ALL_STATUS_FLAGS_MASK))); |
1698 | | break; |
1699 | | default: |
1700 | | /* Only SLJIT_32 is allowed. */ |
1701 | | CHECK_ARGUMENT(!(op & ALL_STATUS_FLAGS_MASK)); |
1702 | | break; |
1703 | | } |
1704 | | |
1705 | | FUNCTION_CHECK_DST(dst, dstw); |
1706 | | FUNCTION_CHECK_SRC(src, srcw); |
1707 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
1708 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
1709 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
1710 | | fprintf(compiler->verbose, " %s%s%s ", op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE], |
1711 | | !(op & SLJIT_32) ? "" : "32", op1_types[GET_OPCODE(op) - SLJIT_OP1_BASE]); |
1712 | | |
1713 | | sljit_verbose_param(compiler, dst, dstw); |
1714 | | fprintf(compiler->verbose, ", "); |
1715 | | sljit_verbose_param(compiler, src, srcw); |
1716 | | fprintf(compiler->verbose, "\n"); |
1717 | | } |
1718 | | #endif /* SLJIT_VERBOSE */ |
1719 | | CHECK_RETURN_OK; |
1720 | | } |
1721 | | |
1722 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_atomic_load(struct sljit_compiler *compiler, sljit_s32 op, |
1723 | | sljit_s32 dst_reg, |
1724 | | sljit_s32 mem_reg) |
1725 | | { |
1726 | | if (SLJIT_UNLIKELY(compiler->skip_checks)) { |
1727 | | compiler->skip_checks = 0; |
1728 | | CHECK_RETURN_OK; |
1729 | | } |
1730 | | |
1731 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
1732 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_ATOMIC)); |
1733 | | CHECK_ARGUMENT(SLJIT_CHECK_OPCODE(op, SLJIT_ATOMIC_TEST | SLJIT_ATOMIC_USE_CAS | SLJIT_ATOMIC_USE_LS | ALL_STATUS_FLAGS_MASK) >= SLJIT_MOV |
1734 | | && SLJIT_CHECK_OPCODE(op, SLJIT_ATOMIC_TEST | SLJIT_ATOMIC_USE_CAS | SLJIT_ATOMIC_USE_LS | ALL_STATUS_FLAGS_MASK) <= SLJIT_MOV_P); |
1735 | | CHECK_ARGUMENT((op & (SLJIT_ATOMIC_USE_CAS | SLJIT_ATOMIC_USE_LS)) != (SLJIT_ATOMIC_USE_CAS | SLJIT_ATOMIC_USE_LS)); |
1736 | | |
1737 | | /* All arguments must be valid registers. */ |
1738 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(dst_reg)); |
1739 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(mem_reg) && !CHECK_IF_VIRTUAL_REGISTER(mem_reg)); |
1740 | | |
1741 | | if (GET_OPCODE(op) < SLJIT_MOV_U8 || GET_OPCODE(op) > SLJIT_MOV_S16) { |
1742 | | /* Nothing allowed. */ |
1743 | | CHECK_ARGUMENT(!(op & SLJIT_32)); |
1744 | | } |
1745 | | |
1746 | | compiler->last_flags = 0; |
1747 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
1748 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
1749 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
1750 | | if (op & SLJIT_ATOMIC_TEST) |
1751 | | CHECK_RETURN_OK; |
1752 | | if (sljit_emit_atomic_load(compiler, op | SLJIT_ATOMIC_TEST, dst_reg, mem_reg)) { |
1753 | | fprintf(compiler->verbose, " # atomic_load: unsupported form, no instructions are emitted\n"); |
1754 | | CHECK_RETURN_OK; |
1755 | | } |
1756 | | |
1757 | | fprintf(compiler->verbose, " atomic_load"); |
1758 | | if (op & SLJIT_ATOMIC_USE_CAS) |
1759 | | fprintf(compiler->verbose, "_cas"); |
1760 | | if (op & SLJIT_ATOMIC_USE_LS) |
1761 | | fprintf(compiler->verbose, "_ls"); |
1762 | | |
1763 | | fprintf(compiler->verbose, "%s%s ", !(op & SLJIT_32) ? "" : "32", |
1764 | | op1_types[GET_OPCODE(op) - SLJIT_OP1_BASE]); |
1765 | | sljit_verbose_reg(compiler, dst_reg); |
1766 | | fprintf(compiler->verbose, ", ["); |
1767 | | sljit_verbose_reg(compiler, mem_reg); |
1768 | | fprintf(compiler->verbose, "]\n"); |
1769 | | } |
1770 | | #endif /* SLJIT_VERBOSE */ |
1771 | | CHECK_RETURN_OK; |
1772 | | } |
1773 | | |
1774 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_atomic_store(struct sljit_compiler *compiler, sljit_s32 op, |
1775 | | sljit_s32 src_reg, |
1776 | | sljit_s32 mem_reg, |
1777 | | sljit_s32 temp_reg) |
1778 | | { |
1779 | | if (SLJIT_UNLIKELY(compiler->skip_checks)) { |
1780 | | compiler->skip_checks = 0; |
1781 | | CHECK_RETURN_OK; |
1782 | | } |
1783 | | |
1784 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
1785 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_ATOMIC)); |
1786 | | CHECK_ARGUMENT(SLJIT_CHECK_OPCODE(op, SLJIT_ATOMIC_TEST | SLJIT_ATOMIC_USE_CAS | SLJIT_ATOMIC_USE_LS | SLJIT_SET_Z) >= SLJIT_MOV |
1787 | | && SLJIT_CHECK_OPCODE(op, SLJIT_ATOMIC_TEST | SLJIT_ATOMIC_USE_CAS | SLJIT_ATOMIC_USE_LS | SLJIT_SET_Z) <= SLJIT_MOV_P); |
1788 | | CHECK_ARGUMENT((op & (SLJIT_ATOMIC_USE_CAS | SLJIT_ATOMIC_USE_LS)) != (SLJIT_ATOMIC_USE_CAS | SLJIT_ATOMIC_USE_LS)); |
1789 | | |
1790 | | /* All arguments must be valid registers. */ |
1791 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(src_reg)); |
1792 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(mem_reg) && !CHECK_IF_VIRTUAL_REGISTER(mem_reg)); |
1793 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(temp_reg) && (src_reg != temp_reg || (op & SLJIT_ATOMIC_USE_LS))); |
1794 | | |
1795 | | CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK) || GET_FLAG_TYPE_MASK(op) == SLJIT_ATOMIC_STORED); |
1796 | | |
1797 | | if (GET_OPCODE(op) < SLJIT_MOV_U8 || GET_OPCODE(op) > SLJIT_MOV_S16) { |
1798 | | /* Nothing allowed. */ |
1799 | | CHECK_ARGUMENT(!(op & SLJIT_32)); |
1800 | | } |
1801 | | |
1802 | | compiler->last_flags = GET_FLAG_TYPE_MASK(op) | (op & SLJIT_32); |
1803 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
1804 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
1805 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
1806 | | if (op & SLJIT_ATOMIC_TEST) |
1807 | | CHECK_RETURN_OK; |
1808 | | if (sljit_emit_atomic_store(compiler, op | SLJIT_ATOMIC_TEST, src_reg, mem_reg, temp_reg)) { |
1809 | | fprintf(compiler->verbose, " # atomic_store: unsupported form, no instructions are emitted\n"); |
1810 | | CHECK_RETURN_OK; |
1811 | | } |
1812 | | |
1813 | | fprintf(compiler->verbose, " atomic_store"); |
1814 | | if (op & SLJIT_ATOMIC_USE_CAS) |
1815 | | fprintf(compiler->verbose, "_cas"); |
1816 | | if (op & SLJIT_ATOMIC_USE_LS) |
1817 | | fprintf(compiler->verbose, "_ls"); |
1818 | | |
1819 | | fprintf(compiler->verbose, "%s%s%s ", !(op & SLJIT_32) ? "" : "32", |
1820 | | op1_types[GET_OPCODE(op) - SLJIT_OP1_BASE], !(op & VARIABLE_FLAG_MASK) ? "" : ".stored"); |
1821 | | sljit_verbose_reg(compiler, src_reg); |
1822 | | fprintf(compiler->verbose, ", ["); |
1823 | | sljit_verbose_reg(compiler, mem_reg); |
1824 | | fprintf(compiler->verbose, "], "); |
1825 | | sljit_verbose_reg(compiler, temp_reg); |
1826 | | fprintf(compiler->verbose, "\n"); |
1827 | | } |
1828 | | #endif /* SLJIT_VERBOSE */ |
1829 | | CHECK_RETURN_OK; |
1830 | | } |
1831 | | |
1832 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
1833 | | |
1834 | | static sljit_s32 check_sljit_emit_op2_operation(struct sljit_compiler *compiler, sljit_s32 op) |
1835 | | { |
1836 | | switch (GET_OPCODE(op)) { |
1837 | | case SLJIT_AND: |
1838 | | case SLJIT_OR: |
1839 | | case SLJIT_XOR: |
1840 | | case SLJIT_SHL: |
1841 | | case SLJIT_MSHL: |
1842 | | case SLJIT_LSHR: |
1843 | | case SLJIT_MLSHR: |
1844 | | case SLJIT_ASHR: |
1845 | | case SLJIT_MASHR: |
1846 | | return !(op & VARIABLE_FLAG_MASK); |
1847 | | case SLJIT_MUL: |
1848 | | return !(op & SLJIT_SET_Z) && (!(op & VARIABLE_FLAG_MASK) || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW); |
1849 | | case SLJIT_ADD: |
1850 | | return !(op & VARIABLE_FLAG_MASK) |
1851 | | || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY) |
1852 | | || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW; |
1853 | | case SLJIT_SUB: |
1854 | | return !(op & VARIABLE_FLAG_MASK) |
1855 | | || (GET_FLAG_TYPE(op) >= SLJIT_LESS && GET_FLAG_TYPE(op) <= SLJIT_OVERFLOW) |
1856 | | || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY); |
1857 | | case SLJIT_ADDC: |
1858 | | case SLJIT_SUBC: |
1859 | | return (!(op & VARIABLE_FLAG_MASK) || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY)) |
1860 | | && (compiler->last_flags & 0xff) == GET_FLAG_TYPE(SLJIT_SET_CARRY) |
1861 | | && (op & SLJIT_32) == (compiler->last_flags & SLJIT_32); |
1862 | | break; |
1863 | | case SLJIT_ROTL: |
1864 | | case SLJIT_ROTR: |
1865 | | return !(op & ALL_STATUS_FLAGS_MASK); |
1866 | | } |
1867 | | |
1868 | | /* Operation type should be checked earlier. */ |
1869 | | SLJIT_UNREACHABLE(); |
1870 | | return 1; |
1871 | | } |
1872 | | |
1873 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
1874 | | |
1875 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 unset, |
1876 | | sljit_s32 dst, sljit_sw dstw, |
1877 | | sljit_s32 src1, sljit_sw src1w, |
1878 | | sljit_s32 src2, sljit_sw src2w) |
1879 | | { |
1880 | | if (SLJIT_UNLIKELY(compiler->skip_checks)) { |
1881 | | compiler->skip_checks = 0; |
1882 | | CHECK_RETURN_OK; |
1883 | | } |
1884 | | |
1885 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
1886 | | CHECK_ARGUMENT(SLJIT_CHECK_OPCODE(op, 0) >= SLJIT_ADD && SLJIT_CHECK_OPCODE(op, 0) <= SLJIT_ROTR); |
1887 | | CHECK_ARGUMENT(check_sljit_emit_op2_operation(compiler, op)); |
1888 | | |
1889 | | if (unset) { |
1890 | | CHECK_ARGUMENT(HAS_FLAGS(op)); |
1891 | | } else { |
1892 | | FUNCTION_CHECK_DST(dst, dstw); |
1893 | | } |
1894 | | FUNCTION_CHECK_SRC(src1, src1w); |
1895 | | FUNCTION_CHECK_SRC(src2, src2w); |
1896 | | compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_32 | SLJIT_SET_Z)); |
1897 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
1898 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
1899 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
1900 | | fprintf(compiler->verbose, " %s%s%s%s%s ", op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE], !(op & SLJIT_32) ? "" : "32", |
1901 | | !(op & SLJIT_SET_Z) ? "" : ".z", !(op & VARIABLE_FLAG_MASK) ? "" : ".", |
1902 | | !(op & VARIABLE_FLAG_MASK) ? "" : jump_names[GET_FLAG_TYPE(op)]); |
1903 | | if (unset) |
1904 | | fprintf(compiler->verbose, "unset"); |
1905 | | else |
1906 | | sljit_verbose_param(compiler, dst, dstw); |
1907 | | fprintf(compiler->verbose, ", "); |
1908 | | sljit_verbose_param(compiler, src1, src1w); |
1909 | | fprintf(compiler->verbose, ", "); |
1910 | | sljit_verbose_param(compiler, src2, src2w); |
1911 | | fprintf(compiler->verbose, "\n"); |
1912 | | } |
1913 | | #endif /* SLJIT_VERBOSE */ |
1914 | | CHECK_RETURN_OK; |
1915 | | } |
1916 | | |
1917 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op2r(struct sljit_compiler *compiler, sljit_s32 op, |
1918 | | sljit_s32 dst_reg, |
1919 | | sljit_s32 src1, sljit_sw src1w, |
1920 | | sljit_s32 src2, sljit_sw src2w) |
1921 | | { |
1922 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
1923 | | CHECK_ARGUMENT((op | SLJIT_32) == SLJIT_MULADD32); |
1924 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(dst_reg)); |
1925 | | FUNCTION_CHECK_SRC(src1, src1w); |
1926 | | FUNCTION_CHECK_SRC(src2, src2w); |
1927 | | compiler->last_flags = 0; |
1928 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
1929 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
1930 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
1931 | | fprintf(compiler->verbose, " %s%s ", op2r_names[GET_OPCODE(op) - SLJIT_OP2R_BASE], !(op & SLJIT_32) ? "" : "32"); |
1932 | | |
1933 | | sljit_verbose_reg(compiler, dst_reg); |
1934 | | fprintf(compiler->verbose, ", "); |
1935 | | sljit_verbose_param(compiler, src1, src1w); |
1936 | | fprintf(compiler->verbose, ", "); |
1937 | | sljit_verbose_param(compiler, src2, src2w); |
1938 | | fprintf(compiler->verbose, "\n"); |
1939 | | } |
1940 | | #endif /* SLJIT_VERBOSE */ |
1941 | | CHECK_RETURN_OK; |
1942 | | } |
1943 | | |
1944 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_shift_into(struct sljit_compiler *compiler, sljit_s32 op, |
1945 | | sljit_s32 dst_reg, |
1946 | | sljit_s32 src1_reg, |
1947 | | sljit_s32 src2_reg, |
1948 | | sljit_s32 src3, sljit_sw src3w) |
1949 | | { |
1950 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
1951 | | CHECK_ARGUMENT(SLJIT_CHECK_OPCODE(op, 0) == SLJIT_SHL || SLJIT_CHECK_OPCODE(op, 0) == SLJIT_LSHR |
1952 | | || SLJIT_CHECK_OPCODE(op, 0) == SLJIT_MSHL || SLJIT_CHECK_OPCODE(op, 0) == SLJIT_MLSHR); |
1953 | | CHECK_ARGUMENT((op & ~(0xff | SLJIT_32 | SLJIT_SHIFT_INTO_NON_ZERO)) == 0); |
1954 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(dst_reg)); |
1955 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(src1_reg)); |
1956 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(src2_reg)); |
1957 | | FUNCTION_CHECK_SRC(src3, src3w); |
1958 | | CHECK_ARGUMENT(dst_reg != src2_reg); |
1959 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
1960 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
1961 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
1962 | | fprintf(compiler->verbose, " %s%s.into%s ", op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE], !(op & SLJIT_32) ? "" : "32", |
1963 | | (op & SLJIT_SHIFT_INTO_NON_ZERO) ? ".nz" : ""); |
1964 | | |
1965 | | sljit_verbose_reg(compiler, dst_reg); |
1966 | | fprintf(compiler->verbose, ", "); |
1967 | | sljit_verbose_reg(compiler, src1_reg); |
1968 | | fprintf(compiler->verbose, ", "); |
1969 | | sljit_verbose_reg(compiler, src2_reg); |
1970 | | fprintf(compiler->verbose, ", "); |
1971 | | sljit_verbose_param(compiler, src3, src3w); |
1972 | | fprintf(compiler->verbose, "\n"); |
1973 | | } |
1974 | | #endif /* SLJIT_VERBOSE */ |
1975 | | CHECK_RETURN_OK; |
1976 | | } |
1977 | | |
1978 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op, |
1979 | | sljit_s32 src, sljit_sw srcw) |
1980 | | { |
1981 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
1982 | | CHECK_ARGUMENT(op >= SLJIT_FAST_RETURN && op <= SLJIT_PREFETCH_ONCE); |
1983 | | FUNCTION_CHECK_SRC(src, srcw); |
1984 | | |
1985 | | if (op == SLJIT_FAST_RETURN || op == SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN) { |
1986 | | CHECK_ARGUMENT(src != SLJIT_IMM); |
1987 | | compiler->last_flags = 0; |
1988 | | } else if (op >= SLJIT_PREFETCH_L1 && op <= SLJIT_PREFETCH_ONCE) { |
1989 | | CHECK_ARGUMENT(src & SLJIT_MEM); |
1990 | | } |
1991 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
1992 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
1993 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
1994 | | fprintf(compiler->verbose, " %s ", op_src_dst_names[op - SLJIT_OP_SRC_DST_BASE]); |
1995 | | sljit_verbose_param(compiler, src, srcw); |
1996 | | fprintf(compiler->verbose, "\n"); |
1997 | | } |
1998 | | #endif /* SLJIT_VERBOSE */ |
1999 | | CHECK_RETURN_OK; |
2000 | | } |
2001 | | |
2002 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_dst(struct sljit_compiler *compiler, sljit_s32 op, |
2003 | | sljit_s32 dst, sljit_sw dstw) |
2004 | | { |
2005 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2006 | | CHECK_ARGUMENT(op >= SLJIT_FAST_ENTER && op <= SLJIT_GET_RETURN_ADDRESS); |
2007 | | FUNCTION_CHECK_DST(dst, dstw); |
2008 | | |
2009 | | if (op == SLJIT_FAST_ENTER) |
2010 | | compiler->last_flags = 0; |
2011 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2012 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2013 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2014 | | fprintf(compiler->verbose, " %s ", op_src_dst_names[op - SLJIT_OP_SRC_DST_BASE]); |
2015 | | sljit_verbose_param(compiler, dst, dstw); |
2016 | | fprintf(compiler->verbose, "\n"); |
2017 | | } |
2018 | | #endif /* SLJIT_VERBOSE */ |
2019 | | CHECK_RETURN_OK; |
2020 | | } |
2021 | | |
2022 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_register_index(sljit_s32 type, sljit_s32 reg) |
2023 | | { |
2024 | | SLJIT_UNUSED_ARG(type); |
2025 | | SLJIT_UNUSED_ARG(reg); |
2026 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2027 | | if (type == SLJIT_GP_REGISTER) { |
2028 | | CHECK_ARGUMENT((reg > 0 && reg <= SLJIT_NUMBER_OF_REGISTERS) |
2029 | | || (reg >= SLJIT_TMP_REGISTER_BASE && reg < (SLJIT_TMP_REGISTER_BASE + SLJIT_NUMBER_OF_TEMPORARY_REGISTERS))); |
2030 | | } |
2031 | | #if (defined SLJIT_SEPARATE_VECTOR_REGISTERS && SLJIT_SEPARATE_VECTOR_REGISTERS) |
2032 | | else if (((type >> 12) == 0 || ((type >> 12) >= 3 && (type >> 12) <= 6))) { |
2033 | | CHECK_ARGUMENT((reg > 0 && reg <= SLJIT_NUMBER_OF_VECTOR_REGISTERS) |
2034 | | || (reg >= SLJIT_TMP_VREGISTER_BASE && reg < (SLJIT_TMP_VREGISTER_BASE + SLJIT_NUMBER_OF_TEMPORARY_VECTOR_REGISTERS))); |
2035 | | } |
2036 | | #endif /* SLJIT_SEPARATE_VECTOR_REGISTERS */ |
2037 | | else { |
2038 | | CHECK_ARGUMENT(type == SLJIT_FLOAT_REGISTER || ((type >> 12) == 0 || ((type >> 12) >= 3 && (type >> 12) <= 6) || (type & (3 << 12)) || (type & (4 << 12)) || (type & (5 << 12)) || (type & (6 << 12)))); |
2039 | | CHECK_ARGUMENT((reg > 0 && reg <= SLJIT_NUMBER_OF_FLOAT_REGISTERS) |
2040 | | || (reg >= SLJIT_TMP_FREGISTER_BASE && reg < (SLJIT_TMP_FREGISTER_BASE + SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS))); |
2041 | | } |
2042 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2043 | | CHECK_RETURN_OK; |
2044 | | } |
2045 | | |
2046 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_custom(struct sljit_compiler *compiler, |
2047 | | void *instruction, sljit_u32 size) |
2048 | | { |
2049 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2050 | | sljit_u32 i; |
2051 | | #endif /* SLJIT_VERBOSE */ |
2052 | | |
2053 | | SLJIT_UNUSED_ARG(compiler); |
2054 | | |
2055 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2056 | | CHECK_ARGUMENT(instruction); |
2057 | | |
2058 | | #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) |
2059 | | CHECK_ARGUMENT(size > 0 && size < 16); |
2060 | | #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) || (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV) |
2061 | | CHECK_ARGUMENT((size == 2 && (((sljit_sw)instruction) & 0x1) == 0) |
2062 | | || (size == 4 && (((sljit_sw)instruction) & 0x3) == 0)); |
2063 | | #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X) |
2064 | | CHECK_ARGUMENT(size == 2 || size == 4 || size == 6); |
2065 | | #else /* !SLJIT_CONFIG_X86 && !SLJIT_CONFIG_ARM_THUMB2 && !SLJIT_CONFIG_RISCV && !SLJIT_CONFIG_S390X */ |
2066 | | CHECK_ARGUMENT(size == 4 && (((sljit_sw)instruction) & 0x3) == 0); |
2067 | | #endif /* SLJIT_CONFIG_X86 */ |
2068 | | |
2069 | | compiler->last_flags = 0; |
2070 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2071 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2072 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2073 | | fprintf(compiler->verbose, " op_custom"); |
2074 | | for (i = 0; i < size; i++) |
2075 | | fprintf(compiler->verbose, " 0x%x", ((sljit_u8*)instruction)[i]); |
2076 | | fprintf(compiler->verbose, "\n"); |
2077 | | } |
2078 | | #endif /* SLJIT_VERBOSE */ |
2079 | | CHECK_RETURN_OK; |
2080 | | } |
2081 | | |
2082 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op, |
2083 | | sljit_s32 dst, sljit_sw dstw, |
2084 | | sljit_s32 src, sljit_sw srcw) |
2085 | | { |
2086 | | if (SLJIT_UNLIKELY(compiler->skip_checks)) { |
2087 | | compiler->skip_checks = 0; |
2088 | | CHECK_RETURN_OK; |
2089 | | } |
2090 | | |
2091 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2092 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU)); |
2093 | | CHECK_ARGUMENT(SLJIT_CHECK_OPCODE(op, 0) >= SLJIT_MOV_F64 && SLJIT_CHECK_OPCODE(op, 0) <= SLJIT_ABS_F64); |
2094 | | CHECK_ARGUMENT(!(op & ALL_STATUS_FLAGS_MASK)); |
2095 | | FUNCTION_FCHECK(src, srcw, op & SLJIT_32); |
2096 | | FUNCTION_FCHECK(dst, dstw, op & SLJIT_32); |
2097 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2098 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2099 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2100 | | if (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_F32) |
2101 | | fprintf(compiler->verbose, " %s%s ", fop1_names[SLJIT_CONV_F64_FROM_F32 - SLJIT_FOP1_BASE], |
2102 | | (op & SLJIT_32) ? ".f32.from.f64" : ".f64.from.f32"); |
2103 | | else |
2104 | | fprintf(compiler->verbose, " %s%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE], |
2105 | | (op & SLJIT_32) ? ".f32" : ".f64"); |
2106 | | |
2107 | | sljit_verbose_fparam(compiler, dst, dstw); |
2108 | | fprintf(compiler->verbose, ", "); |
2109 | | sljit_verbose_fparam(compiler, src, srcw); |
2110 | | fprintf(compiler->verbose, "\n"); |
2111 | | } |
2112 | | #endif /* SLJIT_VERBOSE */ |
2113 | | CHECK_RETURN_OK; |
2114 | | } |
2115 | | |
2116 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_cmp(struct sljit_compiler *compiler, sljit_s32 op, |
2117 | | sljit_s32 src1, sljit_sw src1w, |
2118 | | sljit_s32 src2, sljit_sw src2w) |
2119 | | { |
2120 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2121 | | compiler->last_flags = GET_FLAG_TYPE(op) | (op & SLJIT_32); |
2122 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2123 | | |
2124 | | if (SLJIT_UNLIKELY(compiler->skip_checks)) { |
2125 | | compiler->skip_checks = 0; |
2126 | | CHECK_RETURN_OK; |
2127 | | } |
2128 | | |
2129 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2130 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU)); |
2131 | | CHECK_ARGUMENT(SLJIT_CHECK_OPCODE(op, 0) == SLJIT_CMP_F64); |
2132 | | CHECK_ARGUMENT(!(op & SLJIT_SET_Z)); |
2133 | | CHECK_ARGUMENT((op & VARIABLE_FLAG_MASK) |
2134 | | || (GET_FLAG_TYPE(op) >= SLJIT_F_EQUAL && GET_FLAG_TYPE(op) <= SLJIT_ORDERED_LESS_EQUAL)); |
2135 | | FUNCTION_FCHECK(src1, src1w, op & SLJIT_32); |
2136 | | FUNCTION_FCHECK(src2, src2w, op & SLJIT_32); |
2137 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2138 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2139 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2140 | | fprintf(compiler->verbose, " %s%s", fop1_names[SLJIT_CMP_F64 - SLJIT_FOP1_BASE], (op & SLJIT_32) ? ".f32" : ".f64"); |
2141 | | if (op & VARIABLE_FLAG_MASK) { |
2142 | | fprintf(compiler->verbose, ".%s", jump_names[GET_FLAG_TYPE(op)]); |
2143 | | } |
2144 | | fprintf(compiler->verbose, " "); |
2145 | | sljit_verbose_fparam(compiler, src1, src1w); |
2146 | | fprintf(compiler->verbose, ", "); |
2147 | | sljit_verbose_fparam(compiler, src2, src2w); |
2148 | | fprintf(compiler->verbose, "\n"); |
2149 | | } |
2150 | | #endif /* SLJIT_VERBOSE */ |
2151 | | CHECK_RETURN_OK; |
2152 | | } |
2153 | | |
2154 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_conv_sw_from_f64(struct sljit_compiler *compiler, sljit_s32 op, |
2155 | | sljit_s32 dst, sljit_sw dstw, |
2156 | | sljit_s32 src, sljit_sw srcw) |
2157 | | { |
2158 | | if (SLJIT_UNLIKELY(compiler->skip_checks)) { |
2159 | | compiler->skip_checks = 0; |
2160 | | CHECK_RETURN_OK; |
2161 | | } |
2162 | | |
2163 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2164 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU)); |
2165 | | CHECK_ARGUMENT(!(op & ALL_STATUS_FLAGS_MASK)); |
2166 | | FUNCTION_FCHECK(src, srcw, op & SLJIT_32); |
2167 | | FUNCTION_CHECK_DST(dst, dstw); |
2168 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2169 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2170 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2171 | | fprintf(compiler->verbose, " %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE], |
2172 | | fop1_conv_types[GET_OPCODE(op) - SLJIT_CONV_SW_FROM_F64], |
2173 | | (op & SLJIT_32) ? ".f32" : ".f64"); |
2174 | | sljit_verbose_param(compiler, dst, dstw); |
2175 | | fprintf(compiler->verbose, ", "); |
2176 | | sljit_verbose_fparam(compiler, src, srcw); |
2177 | | fprintf(compiler->verbose, "\n"); |
2178 | | } |
2179 | | #endif /* SLJIT_VERBOSE */ |
2180 | | CHECK_RETURN_OK; |
2181 | | } |
2182 | | |
2183 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_conv_f64_from_w(struct sljit_compiler *compiler, sljit_s32 op, |
2184 | | sljit_s32 dst, sljit_sw dstw, |
2185 | | sljit_s32 src, sljit_sw srcw) |
2186 | | { |
2187 | | if (SLJIT_UNLIKELY(compiler->skip_checks)) { |
2188 | | compiler->skip_checks = 0; |
2189 | | CHECK_RETURN_OK; |
2190 | | } |
2191 | | |
2192 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2193 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU)); |
2194 | | CHECK_ARGUMENT(!(op & ALL_STATUS_FLAGS_MASK)); |
2195 | | FUNCTION_CHECK_SRC(src, srcw); |
2196 | | FUNCTION_FCHECK(dst, dstw, op & SLJIT_32); |
2197 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2198 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2199 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2200 | | fprintf(compiler->verbose, " %s%s.from.%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE], |
2201 | | (op & SLJIT_32) ? ".f32" : ".f64", |
2202 | | fop1_conv_types[GET_OPCODE(op) - SLJIT_CONV_SW_FROM_F64]); |
2203 | | sljit_verbose_fparam(compiler, dst, dstw); |
2204 | | fprintf(compiler->verbose, ", "); |
2205 | | sljit_verbose_param(compiler, src, srcw); |
2206 | | fprintf(compiler->verbose, "\n"); |
2207 | | } |
2208 | | #endif /* SLJIT_VERBOSE */ |
2209 | | CHECK_RETURN_OK; |
2210 | | } |
2211 | | |
2212 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op, |
2213 | | sljit_s32 dst, sljit_sw dstw, |
2214 | | sljit_s32 src1, sljit_sw src1w, |
2215 | | sljit_s32 src2, sljit_sw src2w) |
2216 | | { |
2217 | | if (SLJIT_UNLIKELY(compiler->skip_checks)) { |
2218 | | compiler->skip_checks = 0; |
2219 | | CHECK_RETURN_OK; |
2220 | | } |
2221 | | |
2222 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2223 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU)); |
2224 | | CHECK_ARGUMENT(SLJIT_CHECK_OPCODE(op, 0) >= SLJIT_ADD_F64 && SLJIT_CHECK_OPCODE(op, 0) <= SLJIT_DIV_F64); |
2225 | | CHECK_ARGUMENT(!(op & ALL_STATUS_FLAGS_MASK)); |
2226 | | FUNCTION_FCHECK(src1, src1w, op & SLJIT_32); |
2227 | | FUNCTION_FCHECK(src2, src2w, op & SLJIT_32); |
2228 | | FUNCTION_FCHECK(dst, dstw, op & SLJIT_32); |
2229 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2230 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2231 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2232 | | fprintf(compiler->verbose, " %s%s ", fop2_names[GET_OPCODE(op) - SLJIT_FOP2_BASE], (op & SLJIT_32) ? ".f32" : ".f64"); |
2233 | | sljit_verbose_fparam(compiler, dst, dstw); |
2234 | | fprintf(compiler->verbose, ", "); |
2235 | | sljit_verbose_fparam(compiler, src1, src1w); |
2236 | | fprintf(compiler->verbose, ", "); |
2237 | | sljit_verbose_fparam(compiler, src2, src2w); |
2238 | | fprintf(compiler->verbose, "\n"); |
2239 | | } |
2240 | | #endif /* SLJIT_VERBOSE */ |
2241 | | CHECK_RETURN_OK; |
2242 | | } |
2243 | | |
2244 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop2r(struct sljit_compiler *compiler, sljit_s32 op, |
2245 | | sljit_s32 dst_freg, |
2246 | | sljit_s32 src1, sljit_sw src1w, |
2247 | | sljit_s32 src2, sljit_sw src2w) |
2248 | | { |
2249 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2250 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU)); |
2251 | | CHECK_ARGUMENT(SLJIT_CHECK_OPCODE(op, 0) == SLJIT_COPYSIGN_F64); |
2252 | | FUNCTION_FCHECK(src1, src1w, op & SLJIT_32); |
2253 | | FUNCTION_FCHECK(src2, src2w, op & SLJIT_32); |
2254 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_FREG(dst_freg, op & SLJIT_32)); |
2255 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2256 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2257 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2258 | | fprintf(compiler->verbose, " %s%s ", fop2r_names[GET_OPCODE(op) - SLJIT_FOP2R_BASE], (op & SLJIT_32) ? ".f32" : ".f64"); |
2259 | | sljit_verbose_freg(compiler, dst_freg); |
2260 | | fprintf(compiler->verbose, ", "); |
2261 | | sljit_verbose_fparam(compiler, src1, src1w); |
2262 | | fprintf(compiler->verbose, ", "); |
2263 | | sljit_verbose_fparam(compiler, src2, src2w); |
2264 | | fprintf(compiler->verbose, "\n"); |
2265 | | } |
2266 | | #endif /* SLJIT_VERBOSE */ |
2267 | | CHECK_RETURN_OK; |
2268 | | } |
2269 | | |
2270 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fset32(struct sljit_compiler *compiler, |
2271 | | sljit_s32 freg, sljit_f32 value) |
2272 | | { |
2273 | | SLJIT_UNUSED_ARG(value); |
2274 | | |
2275 | | if (SLJIT_UNLIKELY(compiler->skip_checks)) { |
2276 | | compiler->skip_checks = 0; |
2277 | | CHECK_RETURN_OK; |
2278 | | } |
2279 | | |
2280 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2281 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU)); |
2282 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_FREG(freg, 1)); |
2283 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2284 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2285 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2286 | | fprintf(compiler->verbose, " fset32 "); |
2287 | | sljit_verbose_freg(compiler, freg); |
2288 | | fprintf(compiler->verbose, ", %f\n", value); |
2289 | | } |
2290 | | #endif /* SLJIT_VERBOSE */ |
2291 | | CHECK_RETURN_OK; |
2292 | | } |
2293 | | |
2294 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fset64(struct sljit_compiler *compiler, |
2295 | | sljit_s32 freg, sljit_f64 value) |
2296 | | { |
2297 | | SLJIT_UNUSED_ARG(value); |
2298 | | |
2299 | | if (SLJIT_UNLIKELY(compiler->skip_checks)) { |
2300 | | compiler->skip_checks = 0; |
2301 | | CHECK_RETURN_OK; |
2302 | | } |
2303 | | |
2304 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2305 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU)); |
2306 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_FREG(freg, 0)); |
2307 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2308 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2309 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2310 | | fprintf(compiler->verbose, " fset64 "); |
2311 | | sljit_verbose_freg(compiler, freg); |
2312 | | fprintf(compiler->verbose, ", %f\n", value); |
2313 | | } |
2314 | | #endif /* SLJIT_VERBOSE */ |
2315 | | CHECK_RETURN_OK; |
2316 | | } |
2317 | | |
2318 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fcopy(struct sljit_compiler *compiler, sljit_s32 op, |
2319 | | sljit_s32 freg, sljit_s32 reg) |
2320 | | { |
2321 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2322 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU)); |
2323 | | CHECK_ARGUMENT(SLJIT_CHECK_OPCODE(op, 0) >= SLJIT_COPY_TO_F64 && SLJIT_CHECK_OPCODE(op, 0) <= SLJIT_COPY_FROM_F64); |
2324 | | CHECK_ARGUMENT(!(op & ALL_STATUS_FLAGS_MASK)); |
2325 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_FREG(freg, op & SLJIT_32)); |
2326 | | |
2327 | | #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) |
2328 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(reg)); |
2329 | | #else /* !SLJIT_64BIT_ARCHITECTURE */ |
2330 | | switch (op) { |
2331 | | case SLJIT_COPY32_TO_F32: |
2332 | | case SLJIT_COPY32_FROM_F32: |
2333 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(reg)); |
2334 | | break; |
2335 | | case SLJIT_COPY_TO_F64: |
2336 | | case SLJIT_COPY_FROM_F64: |
2337 | | if (reg & REG_PAIR_MASK) { |
2338 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(REG_PAIR_FIRST(reg))); |
2339 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(REG_PAIR_SECOND(reg))); |
2340 | | |
2341 | | if (op == SLJIT_COPY_TO_F64) |
2342 | | break; |
2343 | | |
2344 | | CHECK_ARGUMENT(REG_PAIR_FIRST(reg) != REG_PAIR_SECOND(reg)); |
2345 | | break; |
2346 | | } |
2347 | | |
2348 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(reg)); |
2349 | | break; |
2350 | | } |
2351 | | #endif /* SLJIT_64BIT_ARCHITECTURE */ |
2352 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2353 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2354 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2355 | | fprintf(compiler->verbose, " copy%s_%s_f%s ", (op & SLJIT_32) ? "32" : "", |
2356 | | GET_OPCODE(op) == SLJIT_COPY_TO_F64 ? "to" : "from", (op & SLJIT_32) ? "32" : "64"); |
2357 | | |
2358 | | sljit_verbose_freg(compiler, freg); |
2359 | | |
2360 | | if (reg & REG_PAIR_MASK) { |
2361 | | fprintf(compiler->verbose, ", {"); |
2362 | | sljit_verbose_reg(compiler, REG_PAIR_FIRST(reg)); |
2363 | | fprintf(compiler->verbose, ", "); |
2364 | | sljit_verbose_reg(compiler, REG_PAIR_SECOND(reg)); |
2365 | | fprintf(compiler->verbose, "}\n"); |
2366 | | } else { |
2367 | | fprintf(compiler->verbose, ", "); |
2368 | | sljit_verbose_reg(compiler, reg); |
2369 | | fprintf(compiler->verbose, "\n"); |
2370 | | } |
2371 | | } |
2372 | | #endif /* SLJIT_VERBOSE */ |
2373 | | CHECK_RETURN_OK; |
2374 | | } |
2375 | | |
2376 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_label(struct sljit_compiler *compiler) |
2377 | | { |
2378 | | SLJIT_UNUSED_ARG(compiler); |
2379 | | |
2380 | | if (SLJIT_UNLIKELY(compiler->skip_checks)) { |
2381 | | compiler->skip_checks = 0; |
2382 | | CHECK_RETURN_OK; |
2383 | | } |
2384 | | |
2385 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2386 | | compiler->last_flags = 0; |
2387 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2388 | | |
2389 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2390 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) |
2391 | | fprintf(compiler->verbose, "label:\n"); |
2392 | | #endif /* SLJIT_VERBOSE */ |
2393 | | CHECK_RETURN_OK; |
2394 | | } |
2395 | | |
2396 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_aligned_label(struct sljit_compiler *compiler, |
2397 | | sljit_s32 alignment, struct sljit_read_only_buffer *buffers) |
2398 | | { |
2399 | | SLJIT_UNUSED_ARG(compiler); |
2400 | | SLJIT_UNUSED_ARG(buffers); |
2401 | | |
2402 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2403 | | CHECK_ARGUMENT(alignment >= SLJIT_LABEL_ALIGN_1 && alignment <= SLJIT_LABEL_ALIGN_16); |
2404 | | compiler->last_flags = 0; |
2405 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2406 | | |
2407 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2408 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2409 | | fprintf(compiler->verbose, "label.al%d:%s", 1 << alignment, buffers == NULL ? "\n" : " ["); |
2410 | | |
2411 | | if (buffers != NULL) { |
2412 | | fprintf(compiler->verbose, "%ld", (long int)buffers->size); |
2413 | | buffers = buffers->next; |
2414 | | |
2415 | | while (buffers != NULL) { |
2416 | | fprintf(compiler->verbose, ", %ld", (long int)buffers->size); |
2417 | | buffers = buffers->next; |
2418 | | } |
2419 | | |
2420 | | fprintf(compiler->verbose, "]\n"); |
2421 | | } |
2422 | | } |
2423 | | #endif /* SLJIT_VERBOSE */ |
2424 | | CHECK_RETURN_OK; |
2425 | | } |
2426 | | |
2427 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2428 | | #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \ |
2429 | | || (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM) |
2430 | | #define CHECK_UNORDERED(type, last_flags) \ |
2431 | | ((((type) & 0xfe) == SLJIT_ORDERED) && \ |
2432 | | ((last_flags) & 0xff) >= SLJIT_UNORDERED && ((last_flags) & 0xff) <= SLJIT_ORDERED_LESS_EQUAL) |
2433 | | #else /* !SLJIT_CONFIG_X86 || SLJIT_CONFIG_ARM */ |
2434 | | #define CHECK_UNORDERED(type, last_flags) 0 |
2435 | | #endif /* SLJIT_CONFIG_X86 || SLJIT_CONFIG_ARM */ |
2436 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2437 | | |
2438 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type) |
2439 | | { |
2440 | | if (SLJIT_UNLIKELY(compiler->skip_checks)) { |
2441 | | compiler->skip_checks = 0; |
2442 | | CHECK_RETURN_OK; |
2443 | | } |
2444 | | |
2445 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2446 | | CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP))); |
2447 | | CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_FAST_CALL); |
2448 | | |
2449 | | if ((type & 0xff) < SLJIT_JUMP) { |
2450 | | if ((type & 0xff) <= SLJIT_NOT_ZERO) |
2451 | | CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z); |
2452 | | else if ((compiler->last_flags & 0xff) == SLJIT_CARRY) { |
2453 | | CHECK_ARGUMENT((type & 0xfe) == SLJIT_CARRY); |
2454 | | compiler->last_flags = 0; |
2455 | | } else |
2456 | | CHECK_ARGUMENT((type & 0xfe) == (compiler->last_flags & 0xff) |
2457 | | || CHECK_UNORDERED(type, compiler->last_flags)); |
2458 | | } |
2459 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2460 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2461 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) |
2462 | | fprintf(compiler->verbose, " jump%s %s\n", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", |
2463 | | jump_names[type & 0xff]); |
2464 | | #endif /* SLJIT_VERBOSE */ |
2465 | | CHECK_RETURN_OK; |
2466 | | } |
2467 | | |
2468 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type, |
2469 | | sljit_s32 arg_types) |
2470 | | { |
2471 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2472 | | CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_CALL_RETURN))); |
2473 | | CHECK_ARGUMENT((type & 0xff) >= SLJIT_CALL && (type & 0xff) <= SLJIT_CALL_REG_ARG); |
2474 | | CHECK_ARGUMENT(function_check_arguments(arg_types, compiler->scratches, -1, compiler->fscratches)); |
2475 | | |
2476 | | if (type & SLJIT_CALL_RETURN) { |
2477 | | CHECK_ARGUMENT((arg_types & SLJIT_ARG_MASK) == compiler->last_return); |
2478 | | |
2479 | | if (compiler->options & SLJIT_ENTER_REG_ARG) { |
2480 | | CHECK_ARGUMENT((type & 0xff) == SLJIT_CALL_REG_ARG); |
2481 | | } else { |
2482 | | CHECK_ARGUMENT((type & 0xff) != SLJIT_CALL_REG_ARG); |
2483 | | } |
2484 | | } |
2485 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2486 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2487 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2488 | | fprintf(compiler->verbose, " %s%s%s ret[%s", jump_names[type & 0xff], |
2489 | | !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", |
2490 | | !(type & SLJIT_CALL_RETURN) ? "" : ".ret", |
2491 | | call_arg_names[arg_types & SLJIT_ARG_MASK]); |
2492 | | |
2493 | | arg_types >>= SLJIT_ARG_SHIFT; |
2494 | | if (arg_types) { |
2495 | | fprintf(compiler->verbose, "], args["); |
2496 | | do { |
2497 | | fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_ARG_MASK]); |
2498 | | arg_types >>= SLJIT_ARG_SHIFT; |
2499 | | if (arg_types) |
2500 | | fprintf(compiler->verbose, ","); |
2501 | | } while (arg_types); |
2502 | | } |
2503 | | fprintf(compiler->verbose, "]\n"); |
2504 | | } |
2505 | | #endif /* SLJIT_VERBOSE */ |
2506 | | CHECK_RETURN_OK; |
2507 | | } |
2508 | | |
2509 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type, |
2510 | | sljit_s32 src1, sljit_sw src1w, |
2511 | | sljit_s32 src2, sljit_sw src2w) |
2512 | | { |
2513 | | if (SLJIT_UNLIKELY(compiler->skip_checks)) { |
2514 | | compiler->skip_checks = 0; |
2515 | | CHECK_RETURN_OK; |
2516 | | } |
2517 | | |
2518 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2519 | | CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_32))); |
2520 | | CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_SIG_LESS_EQUAL); |
2521 | | FUNCTION_CHECK_SRC(src1, src1w); |
2522 | | FUNCTION_CHECK_SRC(src2, src2w); |
2523 | | compiler->last_flags = 0; |
2524 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2525 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2526 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2527 | | fprintf(compiler->verbose, " cmp%s%s %s, ", (type & SLJIT_32) ? "32" : "", |
2528 | | !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", jump_names[type & 0xff]); |
2529 | | sljit_verbose_param(compiler, src1, src1w); |
2530 | | fprintf(compiler->verbose, ", "); |
2531 | | sljit_verbose_param(compiler, src2, src2w); |
2532 | | fprintf(compiler->verbose, "\n"); |
2533 | | } |
2534 | | #endif /* SLJIT_VERBOSE */ |
2535 | | CHECK_RETURN_OK; |
2536 | | } |
2537 | | |
2538 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type, |
2539 | | sljit_s32 src1, sljit_sw src1w, |
2540 | | sljit_s32 src2, sljit_sw src2w) |
2541 | | { |
2542 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2543 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU)); |
2544 | | CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_32))); |
2545 | | CHECK_ARGUMENT((type & 0xff) >= SLJIT_F_EQUAL && (type & 0xff) <= SLJIT_ORDERED_LESS_EQUAL); |
2546 | | FUNCTION_FCHECK(src1, src1w, type & SLJIT_32); |
2547 | | FUNCTION_FCHECK(src2, src2w, type & SLJIT_32); |
2548 | | compiler->last_flags = 0; |
2549 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2550 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2551 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2552 | | fprintf(compiler->verbose, " fcmp%s%s %s, ", (type & SLJIT_32) ? ".f32" : ".f64", |
2553 | | !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", jump_names[type & 0xff]); |
2554 | | sljit_verbose_fparam(compiler, src1, src1w); |
2555 | | fprintf(compiler->verbose, ", "); |
2556 | | sljit_verbose_fparam(compiler, src2, src2w); |
2557 | | fprintf(compiler->verbose, "\n"); |
2558 | | } |
2559 | | #endif /* SLJIT_VERBOSE */ |
2560 | | CHECK_RETURN_OK; |
2561 | | } |
2562 | | |
2563 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op2cmpz(struct sljit_compiler *compiler, sljit_s32 op, |
2564 | | sljit_s32 dst, sljit_sw dstw, |
2565 | | sljit_s32 src1, sljit_sw src1w, |
2566 | | sljit_s32 src2, sljit_sw src2w) |
2567 | | { |
2568 | | SLJIT_COMPILE_ASSERT((SLJIT_JUMP_IF_ZERO == SLJIT_SET_Z) && (SLJIT_JUMP_IF_NON_ZERO == 0), |
2569 | | incorrect_values_for_sljit_jump_zero_or_non_zero); |
2570 | | |
2571 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2572 | | CHECK_ARGUMENT(SLJIT_CHECK_OPCODE(op, SLJIT_REWRITABLE_JUMP) >= SLJIT_ADD && SLJIT_CHECK_OPCODE(op, SLJIT_REWRITABLE_JUMP) <= SLJIT_ROTR); |
2573 | | /* Not all opcodes allow setting zero flags. */ |
2574 | | CHECK_ARGUMENT(check_sljit_emit_op2_operation(compiler, ((op | SLJIT_SET_Z) & ~SLJIT_REWRITABLE_JUMP))); |
2575 | | FUNCTION_CHECK_DST(dst, dstw); |
2576 | | FUNCTION_CHECK_SRC(src1, src1w); |
2577 | | FUNCTION_CHECK_SRC(src2, src2w); |
2578 | | compiler->last_flags = GET_FLAG_TYPE(op) | (op & SLJIT_32); |
2579 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2580 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2581 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2582 | | fprintf(compiler->verbose, " cmp%sz.%s%s%s%s%s ", (op & SLJIT_JUMP_IF_ZERO) ? "" : "n", |
2583 | | op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE], !(op & SLJIT_32) ? "" : "32", |
2584 | | !(op & VARIABLE_FLAG_MASK) ? "" : ".", !(op & VARIABLE_FLAG_MASK) ? "" : jump_names[GET_FLAG_TYPE(op & ~SLJIT_REWRITABLE_JUMP)], |
2585 | | !(op & SLJIT_REWRITABLE_JUMP) ? "" : ".r"); |
2586 | | sljit_verbose_param(compiler, dst, dstw); |
2587 | | fprintf(compiler->verbose, ", "); |
2588 | | sljit_verbose_param(compiler, src1, src1w); |
2589 | | fprintf(compiler->verbose, ", "); |
2590 | | sljit_verbose_param(compiler, src2, src2w); |
2591 | | fprintf(compiler->verbose, "\n"); |
2592 | | } |
2593 | | #endif /* SLJIT_VERBOSE */ |
2594 | | CHECK_RETURN_OK; |
2595 | | } |
2596 | | |
2597 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, |
2598 | | sljit_s32 src, sljit_sw srcw) |
2599 | | { |
2600 | | if (SLJIT_UNLIKELY(compiler->skip_checks)) { |
2601 | | compiler->skip_checks = 0; |
2602 | | CHECK_RETURN_OK; |
2603 | | } |
2604 | | |
2605 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2606 | | CHECK_ARGUMENT(type >= SLJIT_JUMP && type <= SLJIT_FAST_CALL); |
2607 | | FUNCTION_CHECK_SRC(src, srcw); |
2608 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2609 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2610 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2611 | | fprintf(compiler->verbose, " ijump.%s ", jump_names[type]); |
2612 | | sljit_verbose_param(compiler, src, srcw); |
2613 | | fprintf(compiler->verbose, "\n"); |
2614 | | } |
2615 | | #endif /* SLJIT_VERBOSE */ |
2616 | | CHECK_RETURN_OK; |
2617 | | } |
2618 | | |
2619 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type, |
2620 | | sljit_s32 arg_types, |
2621 | | sljit_s32 src, sljit_sw srcw) |
2622 | | { |
2623 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2624 | | CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_CALL_RETURN))); |
2625 | | CHECK_ARGUMENT((type & 0xff) >= SLJIT_CALL && (type & 0xff) <= SLJIT_CALL_REG_ARG); |
2626 | | CHECK_ARGUMENT(function_check_arguments(arg_types, compiler->scratches, -1, compiler->fscratches)); |
2627 | | FUNCTION_CHECK_SRC(src, srcw); |
2628 | | |
2629 | | if (type & SLJIT_CALL_RETURN) { |
2630 | | CHECK_ARGUMENT((arg_types & SLJIT_ARG_MASK) == compiler->last_return); |
2631 | | |
2632 | | if (compiler->options & SLJIT_ENTER_REG_ARG) { |
2633 | | CHECK_ARGUMENT((type & 0xff) == SLJIT_CALL_REG_ARG); |
2634 | | } else { |
2635 | | CHECK_ARGUMENT((type & 0xff) != SLJIT_CALL_REG_ARG); |
2636 | | } |
2637 | | } |
2638 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2639 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2640 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2641 | | fprintf(compiler->verbose, " i%s%s ret[%s", jump_names[type & 0xff], |
2642 | | !(type & SLJIT_CALL_RETURN) ? "" : ".ret", |
2643 | | call_arg_names[arg_types & SLJIT_ARG_MASK]); |
2644 | | |
2645 | | arg_types >>= SLJIT_ARG_SHIFT; |
2646 | | if (arg_types) { |
2647 | | fprintf(compiler->verbose, "], args["); |
2648 | | do { |
2649 | | fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_ARG_MASK]); |
2650 | | arg_types >>= SLJIT_ARG_SHIFT; |
2651 | | if (arg_types) |
2652 | | fprintf(compiler->verbose, ","); |
2653 | | } while (arg_types); |
2654 | | } |
2655 | | fprintf(compiler->verbose, "], "); |
2656 | | sljit_verbose_param(compiler, src, srcw); |
2657 | | fprintf(compiler->verbose, "\n"); |
2658 | | } |
2659 | | #endif /* SLJIT_VERBOSE */ |
2660 | | CHECK_RETURN_OK; |
2661 | | } |
2662 | | |
2663 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op, |
2664 | | sljit_s32 dst, sljit_sw dstw, |
2665 | | sljit_s32 type) |
2666 | | { |
2667 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2668 | | CHECK_ARGUMENT(type >= SLJIT_EQUAL && type <= SLJIT_ORDERED_LESS_EQUAL); |
2669 | | CHECK_ARGUMENT(op == SLJIT_MOV || op == SLJIT_MOV32 |
2670 | | || (SLJIT_CHECK_OPCODE(op, 0) >= SLJIT_AND && SLJIT_CHECK_OPCODE(op, 0) <= SLJIT_XOR)); |
2671 | | CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)); |
2672 | | |
2673 | | if (type <= SLJIT_NOT_ZERO) |
2674 | | CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z); |
2675 | | else |
2676 | | CHECK_ARGUMENT((type & 0xfe) == (compiler->last_flags & 0xff) |
2677 | | || CHECK_UNORDERED(type, compiler->last_flags)); |
2678 | | |
2679 | | FUNCTION_CHECK_DST(dst, dstw); |
2680 | | |
2681 | | if (GET_OPCODE(op) >= SLJIT_ADD) |
2682 | | compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_32 | SLJIT_SET_Z)); |
2683 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2684 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2685 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2686 | | fprintf(compiler->verbose, " flags.%s%s%s ", |
2687 | | GET_OPCODE(op) < SLJIT_OP2_BASE ? "mov" : op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE], |
2688 | | GET_OPCODE(op) < SLJIT_OP2_BASE ? op1_types[GET_OPCODE(op) - SLJIT_OP1_BASE] : ((op & SLJIT_32) ? "32" : ""), |
2689 | | !(op & SLJIT_SET_Z) ? "" : ".z"); |
2690 | | sljit_verbose_param(compiler, dst, dstw); |
2691 | | fprintf(compiler->verbose, ", %s\n", jump_names[type]); |
2692 | | } |
2693 | | #endif /* SLJIT_VERBOSE */ |
2694 | | CHECK_RETURN_OK; |
2695 | | } |
2696 | | |
2697 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_select(struct sljit_compiler *compiler, sljit_s32 type, |
2698 | | sljit_s32 dst_reg, |
2699 | | sljit_s32 src1, sljit_sw src1w, |
2700 | | sljit_s32 src2_reg) |
2701 | | { |
2702 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2703 | | sljit_s32 cond = type & ~SLJIT_32; |
2704 | | |
2705 | | CHECK_ARGUMENT(cond >= SLJIT_EQUAL && cond <= SLJIT_ORDERED_LESS_EQUAL); |
2706 | | |
2707 | | CHECK_ARGUMENT(compiler->scratches != -1 && compiler->saveds != -1); |
2708 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(dst_reg)); |
2709 | | FUNCTION_CHECK_SRC(src1, src1w); |
2710 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(src2_reg)); |
2711 | | |
2712 | | if (cond <= SLJIT_NOT_ZERO) |
2713 | | CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z); |
2714 | | else if ((compiler->last_flags & 0xff) == SLJIT_CARRY) { |
2715 | | CHECK_ARGUMENT((type & 0xfe) == SLJIT_CARRY); |
2716 | | compiler->last_flags = 0; |
2717 | | } else |
2718 | | CHECK_ARGUMENT((cond & 0xfe) == (compiler->last_flags & 0xff) |
2719 | | || CHECK_UNORDERED(cond, compiler->last_flags)); |
2720 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2721 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2722 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2723 | | fprintf(compiler->verbose, " select%s %s, ", |
2724 | | !(type & SLJIT_32) ? "" : "32", |
2725 | | jump_names[type & ~SLJIT_32]); |
2726 | | sljit_verbose_reg(compiler, dst_reg); |
2727 | | fprintf(compiler->verbose, ", "); |
2728 | | sljit_verbose_param(compiler, src1, src1w); |
2729 | | fprintf(compiler->verbose, ", "); |
2730 | | sljit_verbose_reg(compiler, src2_reg); |
2731 | | fprintf(compiler->verbose, "\n"); |
2732 | | } |
2733 | | #endif /* SLJIT_VERBOSE */ |
2734 | | CHECK_RETURN_OK; |
2735 | | } |
2736 | | |
2737 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fselect(struct sljit_compiler *compiler, sljit_s32 type, |
2738 | | sljit_s32 dst_freg, |
2739 | | sljit_s32 src1, sljit_sw src1w, |
2740 | | sljit_s32 src2_freg) |
2741 | | { |
2742 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2743 | | sljit_s32 cond = type & ~SLJIT_32; |
2744 | | |
2745 | | CHECK_ARGUMENT(cond >= SLJIT_EQUAL && cond <= SLJIT_ORDERED_LESS_EQUAL); |
2746 | | |
2747 | | CHECK_ARGUMENT(compiler->fscratches != -1 && compiler->fsaveds != -1); |
2748 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_FREG(dst_freg, type & SLJIT_32)); |
2749 | | FUNCTION_FCHECK(src1, src1w, type & SLJIT_32); |
2750 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_FREG(src2_freg, type & SLJIT_32)); |
2751 | | |
2752 | | if (cond <= SLJIT_NOT_ZERO) |
2753 | | CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z); |
2754 | | else if ((compiler->last_flags & 0xff) == SLJIT_CARRY) { |
2755 | | CHECK_ARGUMENT((type & 0xfe) == SLJIT_CARRY); |
2756 | | compiler->last_flags = 0; |
2757 | | } else |
2758 | | CHECK_ARGUMENT((cond & 0xfe) == (compiler->last_flags & 0xff) |
2759 | | || CHECK_UNORDERED(cond, compiler->last_flags)); |
2760 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2761 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2762 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2763 | | fprintf(compiler->verbose, " fselect%s %s, ", |
2764 | | !(type & SLJIT_32) ? "" : "32", |
2765 | | jump_names[type & ~SLJIT_32]); |
2766 | | sljit_verbose_freg(compiler, dst_freg); |
2767 | | fprintf(compiler->verbose, ", "); |
2768 | | sljit_verbose_fparam(compiler, src1, src1w); |
2769 | | fprintf(compiler->verbose, ", "); |
2770 | | sljit_verbose_freg(compiler, src2_freg); |
2771 | | fprintf(compiler->verbose, "\n"); |
2772 | | } |
2773 | | #endif /* SLJIT_VERBOSE */ |
2774 | | CHECK_RETURN_OK; |
2775 | | } |
2776 | | |
2777 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type, |
2778 | | sljit_s32 reg, |
2779 | | sljit_s32 mem, sljit_sw memw) |
2780 | | { |
2781 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2782 | | sljit_s32 allowed_flags; |
2783 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2784 | | |
2785 | | if (SLJIT_UNLIKELY(compiler->skip_checks)) { |
2786 | | compiler->skip_checks = 0; |
2787 | | CHECK_RETURN_OK; |
2788 | | } |
2789 | | |
2790 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2791 | | if (type & SLJIT_MEM_UNALIGNED) { |
2792 | | CHECK_ARGUMENT(!(type & (SLJIT_MEM_ALIGNED_16 | SLJIT_MEM_ALIGNED_32))); |
2793 | | } else if (type & SLJIT_MEM_ALIGNED_16) { |
2794 | | CHECK_ARGUMENT(!(type & SLJIT_MEM_ALIGNED_32)); |
2795 | | } else { |
2796 | | CHECK_ARGUMENT((reg & REG_PAIR_MASK) || (type & SLJIT_MEM_ALIGNED_32)); |
2797 | | } |
2798 | | |
2799 | | allowed_flags = SLJIT_MEM_UNALIGNED; |
2800 | | |
2801 | | switch (type & 0xff) { |
2802 | | case SLJIT_MOV_P: |
2803 | | case SLJIT_MOV: |
2804 | | allowed_flags |= SLJIT_MEM_ALIGNED_32; |
2805 | | /* fallthrough */ |
2806 | | case SLJIT_MOV_U32: |
2807 | | case SLJIT_MOV_S32: |
2808 | | case SLJIT_MOV32: |
2809 | | allowed_flags |= SLJIT_MEM_ALIGNED_16; |
2810 | | break; |
2811 | | } |
2812 | | |
2813 | | CHECK_ARGUMENT((type & ~(0xff | SLJIT_32 | SLJIT_MEM_STORE | allowed_flags)) == 0); |
2814 | | |
2815 | | if (reg & REG_PAIR_MASK) { |
2816 | | CHECK_ARGUMENT((type & 0xff) == SLJIT_MOV); |
2817 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(REG_PAIR_FIRST(reg))); |
2818 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(REG_PAIR_SECOND(reg))); |
2819 | | CHECK_ARGUMENT(REG_PAIR_FIRST(reg) != REG_PAIR_SECOND(reg)); |
2820 | | } else { |
2821 | | CHECK_ARGUMENT((type & 0xff) >= SLJIT_MOV && (type & 0xff) <= SLJIT_MOV_P); |
2822 | | CHECK_ARGUMENT(!(type & SLJIT_32) || ((type & 0xff) >= SLJIT_MOV_U8 && (type & 0xff) <= SLJIT_MOV_S16)); |
2823 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(reg)); |
2824 | | } |
2825 | | |
2826 | | FUNCTION_CHECK_SRC_MEM(mem, memw); |
2827 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2828 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2829 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2830 | | if ((type & 0xff) == SLJIT_MOV32) |
2831 | | fprintf(compiler->verbose, " %s32", |
2832 | | (type & SLJIT_MEM_STORE) ? "store" : "load"); |
2833 | | else |
2834 | | fprintf(compiler->verbose, " %s%s%s", |
2835 | | (type & SLJIT_MEM_STORE) ? "store" : "load", |
2836 | | !(type & SLJIT_32) ? "" : "32", op1_types[(type & 0xff) - SLJIT_OP1_BASE]); |
2837 | | |
2838 | | if (type & SLJIT_MEM_UNALIGNED) |
2839 | | printf(".unal"); |
2840 | | else if (type & SLJIT_MEM_ALIGNED_16) |
2841 | | printf(".al16"); |
2842 | | else if (type & SLJIT_MEM_ALIGNED_32) |
2843 | | printf(".al32"); |
2844 | | |
2845 | | if (reg & REG_PAIR_MASK) { |
2846 | | fprintf(compiler->verbose, " {"); |
2847 | | sljit_verbose_reg(compiler, REG_PAIR_FIRST(reg)); |
2848 | | fprintf(compiler->verbose, ", "); |
2849 | | sljit_verbose_reg(compiler, REG_PAIR_SECOND(reg)); |
2850 | | fprintf(compiler->verbose, "}, "); |
2851 | | } else { |
2852 | | fprintf(compiler->verbose, " "); |
2853 | | sljit_verbose_reg(compiler, reg); |
2854 | | fprintf(compiler->verbose, ", "); |
2855 | | } |
2856 | | sljit_verbose_param(compiler, mem, memw); |
2857 | | fprintf(compiler->verbose, "\n"); |
2858 | | } |
2859 | | #endif /* SLJIT_VERBOSE */ |
2860 | | CHECK_RETURN_OK; |
2861 | | } |
2862 | | |
2863 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_mem_update(struct sljit_compiler *compiler, sljit_s32 type, |
2864 | | sljit_s32 reg, |
2865 | | sljit_s32 mem, sljit_sw memw) |
2866 | | { |
2867 | | if (SLJIT_UNLIKELY(compiler->skip_checks)) { |
2868 | | compiler->skip_checks = 0; |
2869 | | CHECK_RETURN_OK; |
2870 | | } |
2871 | | |
2872 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2873 | | CHECK_ARGUMENT((type & 0xff) >= SLJIT_MOV && (type & 0xff) <= SLJIT_MOV_P); |
2874 | | CHECK_ARGUMENT((type & ~(0xff | SLJIT_32 | SLJIT_MEM_STORE | SLJIT_MEM_SUPP | SLJIT_MEM_POST)) == 0); |
2875 | | CHECK_ARGUMENT((mem & REG_MASK) != 0 && (mem & REG_MASK) != reg); |
2876 | | |
2877 | | FUNCTION_CHECK_SRC_MEM(mem, memw); |
2878 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2879 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2880 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2881 | | if (type & SLJIT_MEM_SUPP) |
2882 | | CHECK_RETURN_OK; |
2883 | | if (sljit_emit_mem_update(compiler, type | SLJIT_MEM_SUPP, reg, mem, memw) == SLJIT_ERR_UNSUPPORTED) { |
2884 | | fprintf(compiler->verbose, " # mem: unsupported form, no instructions are emitted\n"); |
2885 | | CHECK_RETURN_OK; |
2886 | | } |
2887 | | |
2888 | | if ((type & 0xff) == SLJIT_MOV32) |
2889 | | fprintf(compiler->verbose, " %s32.%s ", |
2890 | | (type & SLJIT_MEM_STORE) ? "store" : "load", |
2891 | | (type & SLJIT_MEM_POST) ? "post" : "pre"); |
2892 | | else |
2893 | | fprintf(compiler->verbose, " %s%s%s.%s ", |
2894 | | (type & SLJIT_MEM_STORE) ? "store" : "load", |
2895 | | !(type & SLJIT_32) ? "" : "32", |
2896 | | op1_types[(type & 0xff) - SLJIT_OP1_BASE], |
2897 | | (type & SLJIT_MEM_POST) ? "post" : "pre"); |
2898 | | |
2899 | | sljit_verbose_reg(compiler, reg); |
2900 | | fprintf(compiler->verbose, ", "); |
2901 | | sljit_verbose_param(compiler, mem, memw); |
2902 | | fprintf(compiler->verbose, "\n"); |
2903 | | } |
2904 | | #endif /* SLJIT_VERBOSE */ |
2905 | | CHECK_RETURN_OK; |
2906 | | } |
2907 | | |
2908 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type, |
2909 | | sljit_s32 freg, |
2910 | | sljit_s32 mem, sljit_sw memw) |
2911 | | { |
2912 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2913 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU)); |
2914 | | CHECK_ARGUMENT((type & 0xff) == SLJIT_MOV_F64); |
2915 | | |
2916 | | if (type & SLJIT_MEM_UNALIGNED) { |
2917 | | CHECK_ARGUMENT(!(type & (SLJIT_MEM_ALIGNED_16 | SLJIT_MEM_ALIGNED_32))); |
2918 | | } else if (type & SLJIT_MEM_ALIGNED_16) { |
2919 | | CHECK_ARGUMENT(!(type & SLJIT_MEM_ALIGNED_32)); |
2920 | | } else { |
2921 | | CHECK_ARGUMENT(type & SLJIT_MEM_ALIGNED_32); |
2922 | | CHECK_ARGUMENT(!(type & SLJIT_32)); |
2923 | | } |
2924 | | |
2925 | | CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_32 | SLJIT_MEM_STORE | SLJIT_MEM_UNALIGNED | SLJIT_MEM_ALIGNED_16 | SLJIT_MEM_ALIGNED_32))); |
2926 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_FREG(freg, type & SLJIT_32)); |
2927 | | FUNCTION_CHECK_SRC_MEM(mem, memw); |
2928 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2929 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2930 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2931 | | fprintf(compiler->verbose, " %s.%s", |
2932 | | (type & SLJIT_MEM_STORE) ? "store" : "load", |
2933 | | !(type & SLJIT_32) ? "f64" : "f32"); |
2934 | | |
2935 | | if (type & SLJIT_MEM_UNALIGNED) |
2936 | | printf(".unal"); |
2937 | | else if (type & SLJIT_MEM_ALIGNED_16) |
2938 | | printf(".al16"); |
2939 | | else if (type & SLJIT_MEM_ALIGNED_32) |
2940 | | printf(".al32"); |
2941 | | |
2942 | | fprintf(compiler->verbose, " "); |
2943 | | sljit_verbose_freg(compiler, freg); |
2944 | | fprintf(compiler->verbose, ", "); |
2945 | | sljit_verbose_param(compiler, mem, memw); |
2946 | | fprintf(compiler->verbose, "\n"); |
2947 | | } |
2948 | | #endif /* SLJIT_VERBOSE */ |
2949 | | CHECK_RETURN_OK; |
2950 | | } |
2951 | | |
2952 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fmem_update(struct sljit_compiler *compiler, sljit_s32 type, |
2953 | | sljit_s32 freg, |
2954 | | sljit_s32 mem, sljit_sw memw) |
2955 | | { |
2956 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2957 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU)); |
2958 | | CHECK_ARGUMENT((type & 0xff) == SLJIT_MOV_F64); |
2959 | | CHECK_ARGUMENT((type & ~(0xff | SLJIT_32 | SLJIT_MEM_STORE | SLJIT_MEM_SUPP | SLJIT_MEM_POST)) == 0); |
2960 | | FUNCTION_CHECK_SRC_MEM(mem, memw); |
2961 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_FREG(freg, type & SLJIT_32)); |
2962 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2963 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
2964 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
2965 | | if (type & SLJIT_MEM_SUPP) |
2966 | | CHECK_RETURN_OK; |
2967 | | if (sljit_emit_fmem_update(compiler, type | SLJIT_MEM_SUPP, freg, mem, memw) == SLJIT_ERR_UNSUPPORTED) { |
2968 | | fprintf(compiler->verbose, " # fmem: unsupported form, no instructions are emitted\n"); |
2969 | | CHECK_RETURN_OK; |
2970 | | } |
2971 | | |
2972 | | fprintf(compiler->verbose, " %s.%s.%s ", |
2973 | | (type & SLJIT_MEM_STORE) ? "store" : "load", |
2974 | | !(type & SLJIT_32) ? "f64" : "f32", |
2975 | | (type & SLJIT_MEM_POST) ? "post" : "pre"); |
2976 | | |
2977 | | sljit_verbose_freg(compiler, freg); |
2978 | | fprintf(compiler->verbose, ", "); |
2979 | | sljit_verbose_param(compiler, mem, memw); |
2980 | | fprintf(compiler->verbose, "\n"); |
2981 | | } |
2982 | | #endif /* SLJIT_VERBOSE */ |
2983 | | CHECK_RETURN_OK; |
2984 | | } |
2985 | | |
2986 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_simd_mov(struct sljit_compiler *compiler, sljit_s32 type, |
2987 | | sljit_s32 vreg, |
2988 | | sljit_s32 srcdst, sljit_sw srcdstw) |
2989 | | { |
2990 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
2991 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_SIMD)); |
2992 | | CHECK_ARGUMENT((type & SLJIT_SIMD_TYPE_MASK2(SLJIT_SIMD_STORE)) == 0); |
2993 | | CHECK_ARGUMENT(SLJIT_SIMD_CHECK_REG(type)); |
2994 | | CHECK_ARGUMENT(SLJIT_SIMD_GET_ELEM_SIZE(type) <= SLJIT_SIMD_GET_REG_SIZE(type)); |
2995 | | CHECK_ARGUMENT(SLJIT_SIMD_GET_ELEM2_SIZE(type) <= (srcdst & SLJIT_MEM) ? SLJIT_SIMD_GET_REG_SIZE(type) : 0); |
2996 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_VREG(vreg, type)); |
2997 | | FUNCTION_VCHECK(srcdst, srcdstw, type); |
2998 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
2999 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
3000 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
3001 | | if (type & SLJIT_SIMD_TEST) |
3002 | | CHECK_RETURN_OK; |
3003 | | if (sljit_emit_simd_mov(compiler, type | SLJIT_SIMD_TEST, vreg, srcdst, srcdstw) == SLJIT_ERR_UNSUPPORTED) { |
3004 | | fprintf(compiler->verbose, " # simd_mem: unsupported form, no instructions are emitted\n"); |
3005 | | CHECK_RETURN_OK; |
3006 | | } |
3007 | | |
3008 | | fprintf(compiler->verbose, " simd_%s.%d.%s%d", |
3009 | | (type & SLJIT_SIMD_STORE) ? "store" : "load", |
3010 | | (8 << SLJIT_SIMD_GET_REG_SIZE(type)), |
3011 | | (type & SLJIT_SIMD_FLOAT) ? "f" : "", |
3012 | | (8 << SLJIT_SIMD_GET_ELEM_SIZE(type))); |
3013 | | |
3014 | | if ((type & 0x3f000000) == SLJIT_SIMD_MEM_UNALIGNED) |
3015 | | fprintf(compiler->verbose, ".unal "); |
3016 | | else |
3017 | | fprintf(compiler->verbose, ".al%d ", (8 << SLJIT_SIMD_GET_ELEM2_SIZE(type))); |
3018 | | |
3019 | | sljit_verbose_vreg(compiler, vreg); |
3020 | | fprintf(compiler->verbose, ", "); |
3021 | | sljit_verbose_vparam(compiler, srcdst, srcdstw); |
3022 | | fprintf(compiler->verbose, "\n"); |
3023 | | } |
3024 | | #endif /* SLJIT_VERBOSE */ |
3025 | | CHECK_RETURN_OK; |
3026 | | } |
3027 | | |
3028 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_simd_replicate(struct sljit_compiler *compiler, sljit_s32 type, |
3029 | | sljit_s32 vreg, |
3030 | | sljit_s32 src, sljit_sw srcw) |
3031 | | { |
3032 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
3033 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_SIMD)); |
3034 | | CHECK_ARGUMENT((type & SLJIT_SIMD_TYPE_MASK(0)) == 0); |
3035 | | CHECK_ARGUMENT(SLJIT_SIMD_CHECK_REG(type)); |
3036 | | CHECK_ARGUMENT(SLJIT_SIMD_GET_ELEM_SIZE(type) < SLJIT_SIMD_GET_REG_SIZE(type)); |
3037 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_VREG(vreg, type)); |
3038 | | |
3039 | | if (type & SLJIT_SIMD_FLOAT) { |
3040 | | if (src == SLJIT_IMM) { |
3041 | | CHECK_ARGUMENT(srcw == 0); |
3042 | | } else { |
3043 | | FUNCTION_FCHECK(src, srcw, SLJIT_SIMD_GET_ELEM_SIZE(type) == 2); |
3044 | | } |
3045 | | } else if (src != SLJIT_IMM) { |
3046 | | FUNCTION_CHECK_DST(src, srcw); |
3047 | | } |
3048 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
3049 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
3050 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
3051 | | if (type & SLJIT_SIMD_TEST) |
3052 | | CHECK_RETURN_OK; |
3053 | | if (sljit_emit_simd_replicate(compiler, type | SLJIT_SIMD_TEST, vreg, src, srcw) == SLJIT_ERR_UNSUPPORTED) { |
3054 | | fprintf(compiler->verbose, " # simd_dup: unsupported form, no instructions are emitted\n"); |
3055 | | CHECK_RETURN_OK; |
3056 | | } |
3057 | | |
3058 | | fprintf(compiler->verbose, " simd_replicate.%d.%s%d ", |
3059 | | (8 << SLJIT_SIMD_GET_REG_SIZE(type)), |
3060 | | (type & SLJIT_SIMD_FLOAT) ? "f" : "", |
3061 | | (8 << SLJIT_SIMD_GET_ELEM_SIZE(type))); |
3062 | | |
3063 | | sljit_verbose_vreg(compiler, vreg); |
3064 | | fprintf(compiler->verbose, ", "); |
3065 | | if (type & SLJIT_SIMD_FLOAT) |
3066 | | sljit_verbose_fparam(compiler, src, srcw); |
3067 | | else |
3068 | | sljit_verbose_param(compiler, src, srcw); |
3069 | | fprintf(compiler->verbose, "\n"); |
3070 | | } |
3071 | | #endif /* SLJIT_VERBOSE */ |
3072 | | CHECK_RETURN_OK; |
3073 | | } |
3074 | | |
3075 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_simd_lane_mov(struct sljit_compiler *compiler, sljit_s32 type, |
3076 | | sljit_s32 vreg, sljit_s32 lane_index, |
3077 | | sljit_s32 srcdst, sljit_sw srcdstw) |
3078 | | { |
3079 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
3080 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_SIMD)); |
3081 | | CHECK_ARGUMENT((type & SLJIT_SIMD_TYPE_MASK(SLJIT_SIMD_STORE | SLJIT_SIMD_LANE_ZERO | SLJIT_SIMD_LANE_SIGNED | SLJIT_32)) == 0); |
3082 | | CHECK_ARGUMENT((type & (SLJIT_SIMD_STORE | SLJIT_SIMD_LANE_ZERO)) != (SLJIT_SIMD_STORE | SLJIT_SIMD_LANE_ZERO)); |
3083 | | CHECK_ARGUMENT((type & (SLJIT_SIMD_STORE | SLJIT_SIMD_LANE_SIGNED)) != SLJIT_SIMD_LANE_SIGNED); |
3084 | | CHECK_ARGUMENT(!(type & SLJIT_SIMD_FLOAT) || !(type & (SLJIT_SIMD_LANE_SIGNED | SLJIT_32))); |
3085 | | CHECK_ARGUMENT(SLJIT_SIMD_CHECK_REG(type)); |
3086 | | CHECK_ARGUMENT(SLJIT_SIMD_GET_ELEM_SIZE(type) < SLJIT_SIMD_GET_REG_SIZE(type)); |
3087 | | CHECK_ARGUMENT(!(type & SLJIT_32) || SLJIT_SIMD_GET_ELEM_SIZE(type) <= 2); |
3088 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_VREG(vreg, type)); |
3089 | | CHECK_ARGUMENT(lane_index >= 0 && lane_index < (1 << (SLJIT_SIMD_GET_REG_SIZE(type) - SLJIT_SIMD_GET_ELEM_SIZE(type)))); |
3090 | | |
3091 | | if (type & SLJIT_SIMD_FLOAT) { |
3092 | | FUNCTION_FCHECK(srcdst, srcdstw, SLJIT_SIMD_GET_ELEM_SIZE(type) == 2); |
3093 | | } else if ((type & SLJIT_SIMD_STORE) || srcdst != SLJIT_IMM) { |
3094 | | FUNCTION_CHECK_DST(srcdst, srcdstw); |
3095 | | } |
3096 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
3097 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
3098 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
3099 | | if (type & SLJIT_SIMD_TEST) |
3100 | | CHECK_RETURN_OK; |
3101 | | if (sljit_emit_simd_lane_mov(compiler, type | SLJIT_SIMD_TEST, vreg, lane_index, srcdst, srcdstw) == SLJIT_ERR_UNSUPPORTED) { |
3102 | | fprintf(compiler->verbose, " # simd_move_lane: unsupported form, no instructions are emitted\n"); |
3103 | | CHECK_RETURN_OK; |
3104 | | } |
3105 | | |
3106 | | fprintf(compiler->verbose, " simd_%s_lane%s%s%s.%d.%s%d ", |
3107 | | (type & SLJIT_SIMD_STORE) ? "store" : "load", |
3108 | | (type & SLJIT_32) ? "32" : "", |
3109 | | (type & SLJIT_SIMD_LANE_ZERO) ? "_z" : "", |
3110 | | (type & SLJIT_SIMD_LANE_SIGNED) ? "_s" : "", |
3111 | | (8 << SLJIT_SIMD_GET_REG_SIZE(type)), |
3112 | | (type & SLJIT_SIMD_FLOAT) ? "f" : "", |
3113 | | (8 << SLJIT_SIMD_GET_ELEM_SIZE(type))); |
3114 | | |
3115 | | sljit_verbose_vreg(compiler, vreg); |
3116 | | fprintf(compiler->verbose, "[%d], ", lane_index); |
3117 | | if (type & SLJIT_SIMD_FLOAT) |
3118 | | sljit_verbose_fparam(compiler, srcdst, srcdstw); |
3119 | | else |
3120 | | sljit_verbose_param(compiler, srcdst, srcdstw); |
3121 | | fprintf(compiler->verbose, "\n"); |
3122 | | } |
3123 | | #endif /* SLJIT_VERBOSE */ |
3124 | | CHECK_RETURN_OK; |
3125 | | } |
3126 | | |
3127 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_simd_lane_replicate(struct sljit_compiler *compiler, sljit_s32 type, |
3128 | | sljit_s32 vreg, |
3129 | | sljit_s32 src, sljit_s32 src_lane_index) |
3130 | | { |
3131 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
3132 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_SIMD)); |
3133 | | CHECK_ARGUMENT((type & SLJIT_SIMD_TYPE_MASK(0)) == 0); |
3134 | | CHECK_ARGUMENT(SLJIT_SIMD_CHECK_REG(type)); |
3135 | | CHECK_ARGUMENT(SLJIT_SIMD_GET_ELEM_SIZE(type) < SLJIT_SIMD_GET_REG_SIZE(type)); |
3136 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_VREG(vreg, type)); |
3137 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_VREG(src, type)); |
3138 | | CHECK_ARGUMENT(src_lane_index >= 0 && src_lane_index < (1 << (SLJIT_SIMD_GET_REG_SIZE(type) - SLJIT_SIMD_GET_ELEM_SIZE(type)))); |
3139 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
3140 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
3141 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
3142 | | if (type & SLJIT_SIMD_TEST) |
3143 | | CHECK_RETURN_OK; |
3144 | | if (sljit_emit_simd_lane_replicate(compiler, type | SLJIT_SIMD_TEST, vreg, src, src_lane_index) == SLJIT_ERR_UNSUPPORTED) { |
3145 | | fprintf(compiler->verbose, " # simd_lane_replicate: unsupported form, no instructions are emitted\n"); |
3146 | | CHECK_RETURN_OK; |
3147 | | } |
3148 | | |
3149 | | fprintf(compiler->verbose, " simd_lane_replicate.%d.%s%d ", |
3150 | | (8 << SLJIT_SIMD_GET_REG_SIZE(type)), |
3151 | | (type & SLJIT_SIMD_FLOAT) ? "f" : "", |
3152 | | (8 << SLJIT_SIMD_GET_ELEM_SIZE(type))); |
3153 | | |
3154 | | sljit_verbose_vreg(compiler, vreg); |
3155 | | fprintf(compiler->verbose, ", "); |
3156 | | sljit_verbose_vreg(compiler, src); |
3157 | | fprintf(compiler->verbose, "[%d]\n", src_lane_index); |
3158 | | } |
3159 | | #endif /* SLJIT_VERBOSE */ |
3160 | | CHECK_RETURN_OK; |
3161 | | } |
3162 | | |
3163 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_simd_extend(struct sljit_compiler *compiler, sljit_s32 type, |
3164 | | sljit_s32 vreg, |
3165 | | sljit_s32 src, sljit_sw srcw) |
3166 | | { |
3167 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
3168 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_SIMD)); |
3169 | | CHECK_ARGUMENT((type & SLJIT_SIMD_TYPE_MASK2(SLJIT_SIMD_EXTEND_SIGNED)) == 0); |
3170 | | CHECK_ARGUMENT((type & (SLJIT_SIMD_EXTEND_SIGNED | SLJIT_SIMD_FLOAT)) != (SLJIT_SIMD_EXTEND_SIGNED | SLJIT_SIMD_FLOAT)); |
3171 | | CHECK_ARGUMENT(SLJIT_SIMD_CHECK_REG(type)); |
3172 | | CHECK_ARGUMENT(SLJIT_SIMD_GET_ELEM2_SIZE(type) < SLJIT_SIMD_GET_REG_SIZE(type)); |
3173 | | CHECK_ARGUMENT(SLJIT_SIMD_GET_ELEM_SIZE(type) < SLJIT_SIMD_GET_ELEM2_SIZE(type)); |
3174 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_VREG(vreg, type)); |
3175 | | FUNCTION_VCHECK(src, srcw, type); |
3176 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
3177 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
3178 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
3179 | | if (type & SLJIT_SIMD_TEST) |
3180 | | CHECK_RETURN_OK; |
3181 | | if (sljit_emit_simd_extend(compiler, type | SLJIT_SIMD_TEST, vreg, src, srcw) == SLJIT_ERR_UNSUPPORTED) { |
3182 | | fprintf(compiler->verbose, " # simd_extend: unsupported form, no instructions are emitted\n"); |
3183 | | CHECK_RETURN_OK; |
3184 | | } |
3185 | | |
3186 | | fprintf(compiler->verbose, " simd_load_extend%s.%d.%s%d.%s%d ", |
3187 | | (type & SLJIT_SIMD_EXTEND_SIGNED) ? "_s" : "", |
3188 | | (8 << SLJIT_SIMD_GET_REG_SIZE(type)), |
3189 | | (type & SLJIT_SIMD_FLOAT) ? "f" : "", |
3190 | | (8 << SLJIT_SIMD_GET_ELEM2_SIZE(type)), |
3191 | | (type & SLJIT_SIMD_FLOAT) ? "f" : "", |
3192 | | (8 << SLJIT_SIMD_GET_ELEM_SIZE(type))); |
3193 | | |
3194 | | sljit_verbose_vreg(compiler, vreg); |
3195 | | fprintf(compiler->verbose, ", "); |
3196 | | sljit_verbose_vparam(compiler, src, srcw); |
3197 | | fprintf(compiler->verbose, "\n"); |
3198 | | } |
3199 | | #endif /* SLJIT_VERBOSE */ |
3200 | | CHECK_RETURN_OK; |
3201 | | } |
3202 | | |
3203 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_simd_sign(struct sljit_compiler *compiler, sljit_s32 type, |
3204 | | sljit_s32 vreg, |
3205 | | sljit_s32 dst, sljit_sw dstw) |
3206 | | { |
3207 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
3208 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_SIMD)); |
3209 | | CHECK_ARGUMENT((type & SLJIT_SIMD_TYPE_MASK(SLJIT_32)) == SLJIT_SIMD_STORE); |
3210 | | CHECK_ARGUMENT(SLJIT_SIMD_CHECK_REG(type)); |
3211 | | CHECK_ARGUMENT(SLJIT_SIMD_GET_ELEM_SIZE(type) < SLJIT_SIMD_GET_REG_SIZE(type)); |
3212 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_VREG(vreg, type)); |
3213 | | FUNCTION_CHECK_DST(dst, dstw); |
3214 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
3215 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
3216 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
3217 | | if (type & SLJIT_SIMD_TEST) |
3218 | | CHECK_RETURN_OK; |
3219 | | if (sljit_emit_simd_sign(compiler, type | SLJIT_SIMD_TEST, vreg, dst, dstw) == SLJIT_ERR_UNSUPPORTED) { |
3220 | | fprintf(compiler->verbose, " # simd_sign: unsupported form, no instructions are emitted\n"); |
3221 | | CHECK_RETURN_OK; |
3222 | | } |
3223 | | |
3224 | | fprintf(compiler->verbose, " simd_store_sign%s.%d.%s%d ", |
3225 | | (type & SLJIT_32) ? "32" : "", |
3226 | | (8 << SLJIT_SIMD_GET_REG_SIZE(type)), |
3227 | | (type & SLJIT_SIMD_FLOAT) ? "f" : "", |
3228 | | (8 << SLJIT_SIMD_GET_ELEM_SIZE(type))); |
3229 | | |
3230 | | sljit_verbose_vreg(compiler, vreg); |
3231 | | fprintf(compiler->verbose, ", "); |
3232 | | sljit_verbose_param(compiler, dst, dstw); |
3233 | | fprintf(compiler->verbose, "\n"); |
3234 | | } |
3235 | | #endif /* SLJIT_VERBOSE */ |
3236 | | CHECK_RETURN_OK; |
3237 | | } |
3238 | | |
3239 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_simd_op2(struct sljit_compiler *compiler, sljit_s32 type, |
3240 | | sljit_s32 dst_vreg, sljit_s32 src1_vreg, sljit_s32 src2, sljit_sw src2w) |
3241 | | { |
3242 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
3243 | | CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_SIMD)); |
3244 | | CHECK_ARGUMENT((type & SLJIT_SIMD_TYPE_MASK2(0)) >= SLJIT_SIMD_OP2_AND && (type & SLJIT_SIMD_TYPE_MASK2(0)) <= SLJIT_SIMD_OP2_SHUFFLE); |
3245 | | CHECK_ARGUMENT(SLJIT_SIMD_CHECK_REG(type)); |
3246 | | CHECK_ARGUMENT(SLJIT_SIMD_GET_ELEM_SIZE(type) <= SLJIT_SIMD_GET_REG_SIZE(type)); |
3247 | | CHECK_ARGUMENT(SLJIT_SIMD_GET_OPCODE(type) != SLJIT_SIMD_OP2_SHUFFLE || (SLJIT_SIMD_GET_ELEM_SIZE(type) == 0 && !(type & SLJIT_SIMD_FLOAT))); |
3248 | | CHECK_ARGUMENT(SLJIT_SIMD_GET_ELEM2_SIZE(type) <= (src2 & SLJIT_MEM) ? SLJIT_SIMD_GET_REG_SIZE(type) : 0); |
3249 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_VREG(dst_vreg, type)); |
3250 | | CHECK_ARGUMENT(FUNCTION_CHECK_IS_VREG(src1_vreg, type)); |
3251 | | FUNCTION_VCHECK(src2, src2w, type); |
3252 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
3253 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
3254 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
3255 | | if (type & SLJIT_SIMD_TEST) |
3256 | | CHECK_RETURN_OK; |
3257 | | if (sljit_emit_simd_op2(compiler, type | SLJIT_SIMD_TEST, dst_vreg, src1_vreg, src2, src2w) == SLJIT_ERR_UNSUPPORTED) { |
3258 | | fprintf(compiler->verbose, " # simd_op2: unsupported form, no instructions are emitted\n"); |
3259 | | CHECK_RETURN_OK; |
3260 | | } |
3261 | | |
3262 | | fprintf(compiler->verbose, " simd_%s.%d.%s%d", |
3263 | | simd_op2_names[SLJIT_SIMD_GET_OPCODE(type) - 1], |
3264 | | (8 << SLJIT_SIMD_GET_REG_SIZE(type)), |
3265 | | (type & SLJIT_SIMD_FLOAT) ? "f" : "", |
3266 | | (8 << SLJIT_SIMD_GET_ELEM_SIZE(type))); |
3267 | | |
3268 | | if ((type & 0x3f000000) != SLJIT_SIMD_MEM_UNALIGNED) |
3269 | | fprintf(compiler->verbose, ".al%d", (8 << SLJIT_SIMD_GET_ELEM2_SIZE(type))); |
3270 | | |
3271 | | fprintf(compiler->verbose, " "); |
3272 | | sljit_verbose_vreg(compiler, dst_vreg); |
3273 | | fprintf(compiler->verbose, ", "); |
3274 | | sljit_verbose_vreg(compiler, src1_vreg); |
3275 | | fprintf(compiler->verbose, ", "); |
3276 | | sljit_verbose_vparam(compiler, src2, src2w); |
3277 | | fprintf(compiler->verbose, "\n"); |
3278 | | } |
3279 | | #endif /* SLJIT_VERBOSE */ |
3280 | | CHECK_RETURN_OK; |
3281 | | } |
3282 | | |
3283 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset) |
3284 | | { |
3285 | | /* Any offset is allowed. */ |
3286 | | SLJIT_UNUSED_ARG(offset); |
3287 | | |
3288 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
3289 | | FUNCTION_CHECK_DST(dst, dstw); |
3290 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
3291 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
3292 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
3293 | | fprintf(compiler->verbose, " local_base "); |
3294 | | sljit_verbose_param(compiler, dst, dstw); |
3295 | | fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", offset); |
3296 | | } |
3297 | | #endif /* SLJIT_VERBOSE */ |
3298 | | CHECK_RETURN_OK; |
3299 | | } |
3300 | | |
3301 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 op, |
3302 | | sljit_s32 dst, sljit_sw dstw, |
3303 | | sljit_sw init_value) |
3304 | | { |
3305 | | SLJIT_UNUSED_ARG(init_value); |
3306 | | |
3307 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
3308 | | CHECK_ARGUMENT(op == SLJIT_MOV || op == SLJIT_MOV_S32 |
3309 | | || op == SLJIT_MOV32 || (op | SLJIT_32) == SLJIT_MOV32_U8); |
3310 | | FUNCTION_CHECK_DST(dst, dstw); |
3311 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
3312 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
3313 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
3314 | | fprintf(compiler->verbose, " const%s%s ", |
3315 | | !(op & SLJIT_32) ? "" : "32", op1_types[GET_OPCODE(op) - SLJIT_OP1_BASE]); |
3316 | | sljit_verbose_param(compiler, dst, dstw); |
3317 | | fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", init_value); |
3318 | | } |
3319 | | #endif /* SLJIT_VERBOSE */ |
3320 | | CHECK_RETURN_OK; |
3321 | | } |
3322 | | |
3323 | | static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_addr(struct sljit_compiler *compiler, sljit_s32 op, |
3324 | | sljit_s32 dst, sljit_sw dstw) |
3325 | | { |
3326 | | #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) |
3327 | | CHECK_ARGUMENT(op == SLJIT_MOV_ADDR || op == SLJIT_MOV_ABS_ADDR || op == SLJIT_ADD_ABS_ADDR); |
3328 | | FUNCTION_CHECK_DST(dst, dstw); |
3329 | | #endif /* SLJIT_ARGUMENT_CHECKS */ |
3330 | | #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
3331 | | if (SLJIT_UNLIKELY(!!compiler->verbose)) { |
3332 | | fprintf(compiler->verbose, " %s ", op_addr_types[op]); |
3333 | | sljit_verbose_param(compiler, dst, dstw); |
3334 | | fprintf(compiler->verbose, "\n"); |
3335 | | } |
3336 | | #endif /* SLJIT_VERBOSE */ |
3337 | | CHECK_RETURN_OK; |
3338 | | } |
3339 | | |
3340 | | #else /* !SLJIT_ARGUMENT_CHECKS && !SLJIT_VERBOSE */ |
3341 | | |
3342 | | #define SLJIT_SKIP_CHECKS(compiler) |
3343 | | |
3344 | | #endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_VERBOSE */ |
3345 | | |
3346 | | #define SELECT_FOP1_OPERATION_WITH_CHECKS(compiler, op, dst, dstw, src, srcw) \ |
3347 | 0 | SLJIT_COMPILE_ASSERT(!(SLJIT_CONV_SW_FROM_F64 & 0x1) && !(SLJIT_CONV_F64_FROM_SW & 0x1) && !(SLJIT_CONV_F64_FROM_UW & 0x1), \ |
3348 | 0 | invalid_float_opcodes); \ |
3349 | 0 | if (GET_OPCODE(op) >= SLJIT_CONV_SW_FROM_F64 && GET_OPCODE(op) <= SLJIT_CMP_F64) { \ |
3350 | 0 | if (GET_OPCODE(op) == SLJIT_CMP_F64) { \ |
3351 | 0 | CHECK(check_sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw)); \ |
3352 | 0 | ADJUST_LOCAL_OFFSET(dst, dstw); \ |
3353 | 0 | ADJUST_LOCAL_OFFSET(src, srcw); \ |
3354 | 0 | return sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw); \ |
3355 | 0 | } \ |
3356 | 0 | if ((GET_OPCODE(op) | 0x1) == SLJIT_CONV_S32_FROM_F64) { \ |
3357 | 0 | CHECK(check_sljit_emit_fop1_conv_sw_from_f64(compiler, op, dst, dstw, src, srcw)); \ |
3358 | 0 | ADJUST_LOCAL_OFFSET(dst, dstw); \ |
3359 | 0 | ADJUST_LOCAL_OFFSET(src, srcw); \ |
3360 | 0 | return sljit_emit_fop1_conv_sw_from_f64(compiler, op, dst, dstw, src, srcw); \ |
3361 | 0 | } \ |
3362 | 0 | if ((GET_OPCODE(op) | 0x1) == SLJIT_CONV_F64_FROM_S32) { \ |
3363 | 0 | CHECK(check_sljit_emit_fop1_conv_f64_from_w(compiler, op, dst, dstw, src, srcw)); \ |
3364 | 0 | ADJUST_LOCAL_OFFSET(dst, dstw); \ |
3365 | 0 | ADJUST_LOCAL_OFFSET(src, srcw); \ |
3366 | 0 | return sljit_emit_fop1_conv_f64_from_sw(compiler, op, dst, dstw, src, srcw); \ |
3367 | 0 | } \ |
3368 | 0 | CHECK(check_sljit_emit_fop1_conv_f64_from_w(compiler, op, dst, dstw, src, srcw)); \ |
3369 | 0 | ADJUST_LOCAL_OFFSET(dst, dstw); \ |
3370 | 0 | ADJUST_LOCAL_OFFSET(src, srcw); \ |
3371 | 0 | return sljit_emit_fop1_conv_f64_from_uw(compiler, op, dst, dstw, src, srcw); \ |
3372 | 0 | } \ |
3373 | 0 | CHECK(check_sljit_emit_fop1(compiler, op, dst, dstw, src, srcw)); \ |
3374 | 0 | ADJUST_LOCAL_OFFSET(dst, dstw); \ |
3375 | 0 | ADJUST_LOCAL_OFFSET(src, srcw); |
3376 | | |
3377 | | #if (!(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) || (defined SLJIT_MIPS_REV && SLJIT_MIPS_REV >= 6)) |
3378 | | |
3379 | | static sljit_s32 sljit_emit_mem_unaligned(struct sljit_compiler *compiler, sljit_s32 type, |
3380 | | sljit_s32 reg, |
3381 | | sljit_s32 mem, sljit_sw memw) |
3382 | 0 | { |
3383 | 0 | SLJIT_SKIP_CHECKS(compiler); |
3384 | 0 |
|
3385 | 0 | if (type & SLJIT_MEM_STORE) |
3386 | 0 | return sljit_emit_op1(compiler, type & (0xff | SLJIT_32), mem, memw, reg, 0); |
3387 | 0 | return sljit_emit_op1(compiler, type & (0xff | SLJIT_32), reg, 0, mem, memw); |
3388 | 0 | } |
3389 | | |
3390 | | #endif /* (!SLJIT_CONFIG_MIPS || SLJIT_MIPS_REV >= 6) */ |
3391 | | |
3392 | | #if (!(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) || (defined SLJIT_MIPS_REV && SLJIT_MIPS_REV >= 6)) \ |
3393 | | && !(defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) |
3394 | | |
3395 | | static sljit_s32 sljit_emit_fmem_unaligned(struct sljit_compiler *compiler, sljit_s32 type, |
3396 | | sljit_s32 freg, |
3397 | | sljit_s32 mem, sljit_sw memw) |
3398 | 0 | { |
3399 | 0 | SLJIT_SKIP_CHECKS(compiler); |
3400 | 0 |
|
3401 | 0 | if (type & SLJIT_MEM_STORE) |
3402 | 0 | return sljit_emit_fop1(compiler, type & (0xff | SLJIT_32), mem, memw, freg, 0); |
3403 | 0 | return sljit_emit_fop1(compiler, type & (0xff | SLJIT_32), freg, 0, mem, memw); |
3404 | 0 | } |
3405 | | |
3406 | | #endif /* (!SLJIT_CONFIG_MIPS || SLJIT_MIPS_REV >= 6) && !SLJIT_CONFIG_ARM */ |
3407 | | |
3408 | | static void sljit_reset_read_only_buffers(struct sljit_read_only_buffer *buffers) |
3409 | 0 | { |
3410 | 0 | while (buffers != NULL) { |
3411 | 0 | buffers->u.label = NULL; |
3412 | 0 | buffers = buffers->next; |
3413 | 0 | } |
3414 | 0 | } |
3415 | | |
3416 | | /* CPU description section */ |
3417 | | |
3418 | | #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE) |
3419 | | #define SLJIT_CPUINFO_PART1 " 32bit (" |
3420 | | #elif (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) |
3421 | | #define SLJIT_CPUINFO_PART1 " 64bit (" |
3422 | | #else /* !SLJIT_32BIT_ARCHITECTURE && !SLJIT_64BIT_ARCHITECTURE */ |
3423 | | #error "Internal error: CPU type info missing" |
3424 | | #endif /* SLJIT_32BIT_ARCHITECTURE */ |
3425 | | |
3426 | | #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN) |
3427 | | #define SLJIT_CPUINFO_PART2 "little endian + " |
3428 | | #elif (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) |
3429 | | #define SLJIT_CPUINFO_PART2 "big endian + " |
3430 | | #else /* !SLJIT_LITTLE_ENDIAN && !SLJIT_BIG_ENDIAN */ |
3431 | | #error "Internal error: CPU type info missing" |
3432 | | #endif /* SLJIT_LITTLE_ENDIAN */ |
3433 | | |
3434 | | #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED) |
3435 | 0 | #define SLJIT_CPUINFO_PART3 "unaligned)" |
3436 | | #else /* !SLJIT_UNALIGNED */ |
3437 | | #define SLJIT_CPUINFO_PART3 "aligned)" |
3438 | | #endif /* SLJIT_UNALIGNED */ |
3439 | | |
3440 | 0 | #define SLJIT_CPUINFO SLJIT_CPUINFO_PART1 SLJIT_CPUINFO_PART2 SLJIT_CPUINFO_PART3 |
3441 | | |
3442 | | #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) |
3443 | | # include "sljitNativeX86_common.c" |
3444 | | #elif (defined SLJIT_CONFIG_ARM_V6 && SLJIT_CONFIG_ARM_V6) |
3445 | | # include "sljitNativeARM_32.c" |
3446 | | #elif (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) |
3447 | | # include "sljitNativeARM_32.c" |
3448 | | #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) |
3449 | | # include "sljitNativeARM_T2_32.c" |
3450 | | #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) |
3451 | | # include "sljitNativeARM_64.c" |
3452 | | #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) |
3453 | | # include "sljitNativePPC_common.c" |
3454 | | #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) |
3455 | | # include "sljitNativeMIPS_common.c" |
3456 | | #elif (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV) |
3457 | | # include "sljitNativeRISCV_common.c" |
3458 | | #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X) |
3459 | | # include "sljitNativeS390X.c" |
3460 | | #elif (defined SLJIT_CONFIG_LOONGARCH && SLJIT_CONFIG_LOONGARCH) |
3461 | | # include "sljitNativeLOONGARCH_64.c" |
3462 | | #endif /* SLJIT_CONFIG_X86 */ |
3463 | | |
3464 | | #include "sljitSerialize.c" |
3465 | | |
3466 | | static SLJIT_INLINE sljit_s32 emit_mov_before_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw) |
3467 | 70.4k | { |
3468 | 70.4k | #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) |
3469 | | /* At the moment the pointer size is always equal to sljit_sw. May be changed in the future. */ |
3470 | 70.4k | if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_P)) |
3471 | 70.4k | return SLJIT_SUCCESS; |
3472 | | #else /* !SLJIT_64BIT_ARCHITECTURE */ |
3473 | | if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_U32 || op == SLJIT_MOV_S32 || op == SLJIT_MOV_P)) |
3474 | | return SLJIT_SUCCESS; |
3475 | | #endif /* SLJIT_64BIT_ARCHITECTURE */ |
3476 | | |
3477 | 0 | SLJIT_SKIP_CHECKS(compiler); |
3478 | 0 | return sljit_emit_op1(compiler, op, SLJIT_RETURN_REG, 0, src, srcw); |
3479 | 70.4k | } |
3480 | | |
3481 | | #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \ |
3482 | | && !((defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) && defined __SOFTFP__) |
3483 | | |
3484 | | static SLJIT_INLINE sljit_s32 emit_fmov_before_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw) |
3485 | 0 | { |
3486 | 0 | if (src == SLJIT_FR0) |
3487 | 0 | return SLJIT_SUCCESS; |
3488 | | |
3489 | 0 | SLJIT_SKIP_CHECKS(compiler); |
3490 | 0 | return sljit_emit_fop1(compiler, op, SLJIT_RETURN_FREG, 0, src, srcw); |
3491 | 0 | } |
3492 | | |
3493 | | #endif /* !SLJIT_CONFIG_X86_32 && !(SLJIT_CONFIG_ARM_32 && __SOFTFP__) */ |
3494 | | |
3495 | | SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw) |
3496 | 70.4k | { |
3497 | 70.4k | CHECK_ERROR(); |
3498 | 70.4k | CHECK(check_sljit_emit_return(compiler, op, src, srcw)); |
3499 | | |
3500 | 70.4k | if (GET_OPCODE(op) < SLJIT_MOV_F64) { |
3501 | 70.4k | FAIL_IF(emit_mov_before_return(compiler, op, src, srcw)); |
3502 | 70.4k | } else { |
3503 | 0 | FAIL_IF(emit_fmov_before_return(compiler, op, src, srcw)); |
3504 | 0 | } |
3505 | | |
3506 | 70.4k | SLJIT_SKIP_CHECKS(compiler); |
3507 | 70.4k | return sljit_emit_return_void(compiler); |
3508 | 70.4k | } |
3509 | | |
3510 | | #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \ |
3511 | | && !(defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X) \ |
3512 | | && !(defined(SLJIT_CONFIG_LOONGARCH_64) && SLJIT_CONFIG_LOONGARCH_64) |
3513 | | |
3514 | | SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2r(struct sljit_compiler *compiler, sljit_s32 op, |
3515 | | sljit_s32 dst_freg, |
3516 | | sljit_s32 src1, sljit_sw src1w, |
3517 | | sljit_s32 src2, sljit_sw src2w) |
3518 | | { |
3519 | | CHECK_ERROR(); |
3520 | | CHECK(check_sljit_emit_fop2r(compiler, op, dst_freg, src1, src1w, src2, src2w)); |
3521 | | ADJUST_LOCAL_OFFSET(src1, src1w); |
3522 | | ADJUST_LOCAL_OFFSET(src2, src2w); |
3523 | | |
3524 | | SLJIT_SKIP_CHECKS(compiler); |
3525 | | return sljit_emit_fop2(compiler, op, dst_freg, 0, src1, src1w, src2, src2w); |
3526 | | } |
3527 | | |
3528 | | #endif /* !SLJIT_CONFIG_X86 && !SLJIT_CONFIG_S390X && !SLJIT_CONFIG_LOONGARCH_64 */ |
3529 | | |
3530 | | #if !(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) \ |
3531 | | && !(defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV) \ |
3532 | | && !(defined SLJIT_CONFIG_LOONGARCH && SLJIT_CONFIG_LOONGARCH) |
3533 | | |
3534 | | SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type, |
3535 | | sljit_s32 src1, sljit_sw src1w, |
3536 | | sljit_s32 src2, sljit_sw src2w) |
3537 | 228M | { |
3538 | | /* Default compare for most architectures. */ |
3539 | 228M | sljit_s32 flags, tmp_src, condition; |
3540 | 228M | sljit_sw tmp_srcw; |
3541 | | |
3542 | 228M | CHECK_ERROR_PTR(); |
3543 | 228M | CHECK_PTR(check_sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w)); |
3544 | | |
3545 | 228M | condition = type & 0xff; |
3546 | | #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) |
3547 | | if ((condition == SLJIT_EQUAL || condition == SLJIT_NOT_EQUAL)) { |
3548 | | if (src1 == SLJIT_IMM && !src1w) { |
3549 | | src1 = src2; |
3550 | | src1w = src2w; |
3551 | | src2 = SLJIT_IMM; |
3552 | | src2w = 0; |
3553 | | } |
3554 | | if (src2 == SLJIT_IMM && !src2w) |
3555 | | return emit_cmp_to0(compiler, type, src1, src1w); |
3556 | | } |
3557 | | #endif /* SLJIT_CONFIG_ARM_64 */ |
3558 | | |
3559 | 228M | if (SLJIT_UNLIKELY(src1 == SLJIT_IMM && src2 != SLJIT_IMM)) { |
3560 | | /* Immediate is preferred as second argument by most architectures. */ |
3561 | 0 | switch (condition) { |
3562 | 0 | case SLJIT_LESS: |
3563 | 0 | condition = SLJIT_GREATER; |
3564 | 0 | break; |
3565 | 0 | case SLJIT_GREATER_EQUAL: |
3566 | 0 | condition = SLJIT_LESS_EQUAL; |
3567 | 0 | break; |
3568 | 0 | case SLJIT_GREATER: |
3569 | 0 | condition = SLJIT_LESS; |
3570 | 0 | break; |
3571 | 0 | case SLJIT_LESS_EQUAL: |
3572 | 0 | condition = SLJIT_GREATER_EQUAL; |
3573 | 0 | break; |
3574 | 0 | case SLJIT_SIG_LESS: |
3575 | 0 | condition = SLJIT_SIG_GREATER; |
3576 | 0 | break; |
3577 | 0 | case SLJIT_SIG_GREATER_EQUAL: |
3578 | 0 | condition = SLJIT_SIG_LESS_EQUAL; |
3579 | 0 | break; |
3580 | 0 | case SLJIT_SIG_GREATER: |
3581 | 0 | condition = SLJIT_SIG_LESS; |
3582 | 0 | break; |
3583 | 0 | case SLJIT_SIG_LESS_EQUAL: |
3584 | 0 | condition = SLJIT_SIG_GREATER_EQUAL; |
3585 | 0 | break; |
3586 | 0 | } |
3587 | | |
3588 | 0 | type = condition | (type & (SLJIT_32 | SLJIT_REWRITABLE_JUMP)); |
3589 | 0 | tmp_src = src1; |
3590 | 0 | src1 = src2; |
3591 | 0 | src2 = tmp_src; |
3592 | 0 | tmp_srcw = src1w; |
3593 | 0 | src1w = src2w; |
3594 | 0 | src2w = tmp_srcw; |
3595 | 0 | } |
3596 | | |
3597 | 228M | if (condition <= SLJIT_NOT_ZERO) |
3598 | 104M | flags = SLJIT_SET_Z; |
3599 | 124M | else |
3600 | 124M | flags = (condition & 0xfe) << VARIABLE_FLAG_SHIFT; |
3601 | | |
3602 | 228M | SLJIT_SKIP_CHECKS(compiler); |
3603 | 228M | PTR_FAIL_IF(sljit_emit_op2u(compiler, |
3604 | 228M | SLJIT_SUB | flags | (type & SLJIT_32), src1, src1w, src2, src2w)); |
3605 | | |
3606 | 228M | SLJIT_SKIP_CHECKS(compiler); |
3607 | 228M | return sljit_emit_jump(compiler, condition | (type & (SLJIT_REWRITABLE_JUMP | SLJIT_32))); |
3608 | 228M | } |
3609 | | |
3610 | | #endif /* !SLJIT_CONFIG_MIPS */ |
3611 | | |
3612 | | #if (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) |
3613 | | |
3614 | | SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_cmp_info(sljit_s32 type) |
3615 | | { |
3616 | | switch (type) { |
3617 | | case SLJIT_UNORDERED_OR_EQUAL: |
3618 | | case SLJIT_ORDERED_NOT_EQUAL: |
3619 | | return 1; |
3620 | | } |
3621 | | |
3622 | | return 0; |
3623 | | } |
3624 | | |
3625 | | #endif /* SLJIT_CONFIG_ARM */ |
3626 | | |
3627 | | SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type, |
3628 | | sljit_s32 src1, sljit_sw src1w, |
3629 | | sljit_s32 src2, sljit_sw src2w) |
3630 | 0 | { |
3631 | 0 | CHECK_ERROR_PTR(); |
3632 | 0 | CHECK_PTR(check_sljit_emit_fcmp(compiler, type, src1, src1w, src2, src2w)); |
3633 | 0 |
|
3634 | 0 | SLJIT_SKIP_CHECKS(compiler); |
3635 | 0 | sljit_emit_fop1(compiler, SLJIT_CMP_F64 | ((type & 0xfe) << VARIABLE_FLAG_SHIFT) | (type & SLJIT_32), src1, src1w, src2, src2w); |
3636 | 0 |
|
3637 | 0 | SLJIT_SKIP_CHECKS(compiler); |
3638 | 0 | return sljit_emit_jump(compiler, type); |
3639 | 0 | } |
3640 | | |
3641 | | #if !(defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV) \ |
3642 | | && !(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) \ |
3643 | | && !(defined SLJIT_CONFIG_LOONGARCH && SLJIT_CONFIG_LOONGARCH) |
3644 | | |
3645 | | SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_op2cmpz(struct sljit_compiler *compiler, sljit_s32 op, |
3646 | | sljit_s32 dst, sljit_sw dstw, |
3647 | | sljit_s32 src1, sljit_sw src1w, |
3648 | | sljit_s32 src2, sljit_sw src2w) |
3649 | 0 | { |
3650 | 0 | CHECK_ERROR_PTR(); |
3651 | 0 | CHECK_PTR(check_sljit_emit_op2cmpz(compiler, op, dst, dstw, src1, src1w, src2, src2w)); |
3652 | 0 |
|
3653 | 0 | SLJIT_SKIP_CHECKS(compiler); |
3654 | 0 | PTR_FAIL_IF(sljit_emit_op2(compiler, ((op | SLJIT_SET_Z) & ~SLJIT_REWRITABLE_JUMP), dst, dstw, src1, src1w, src2, src2w)); |
3655 | 0 |
|
3656 | 0 | SLJIT_SKIP_CHECKS(compiler); |
3657 | 0 | return sljit_emit_jump(compiler, ((op & SLJIT_JUMP_IF_ZERO) ? SLJIT_ZERO : SLJIT_NOT_ZERO) | (op & SLJIT_REWRITABLE_JUMP)); |
3658 | 0 | } |
3659 | | |
3660 | | #else /* SLJIT_CONFIG_RISCV || SLJIT_CONFIG_MIPS || SLJIT_CONFIG_LOONGARCH */ |
3661 | | |
3662 | | SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_op2cmpz(struct sljit_compiler *compiler, sljit_s32 op, |
3663 | | sljit_s32 dst, sljit_sw dstw, |
3664 | | sljit_s32 src1, sljit_sw src1w, |
3665 | | sljit_s32 src2, sljit_sw src2w) |
3666 | | { |
3667 | | sljit_s32 reg; |
3668 | | |
3669 | | CHECK_ERROR_PTR(); |
3670 | | CHECK_PTR(check_sljit_emit_op2cmpz(compiler, op, dst, dstw, src1, src1w, src2, src2w)); |
3671 | | |
3672 | | SLJIT_SKIP_CHECKS(compiler); |
3673 | | PTR_FAIL_IF(sljit_emit_op2(compiler, (op & ~(SLJIT_SET_Z | SLJIT_REWRITABLE_JUMP)), dst, dstw, src1, src1w, src2, src2w)); |
3674 | | |
3675 | | /* When dst is a memory operand, its value is stored in SLJIT_TMP_DEST_FREG. */ |
3676 | | reg = FAST_IS_REG(dst) ? dst : SLJIT_TMP_DEST_REG; |
3677 | | |
3678 | | SLJIT_SKIP_CHECKS(compiler); |
3679 | | return sljit_emit_cmp(compiler, ((op & SLJIT_JUMP_IF_ZERO) ? SLJIT_ZERO : SLJIT_NOT_ZERO) | (op & (SLJIT_32 | SLJIT_REWRITABLE_JUMP)), reg, 0, SLJIT_IMM, 0); |
3680 | | } |
3681 | | |
3682 | | #endif /* !SLJIT_CONFIG_RISCV && !SLJIT_CONFIG_MIPS && !SLJIT_CONFIG_LOONGARCH */ |
3683 | | |
3684 | | #if !(defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM) \ |
3685 | | && !(defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) |
3686 | | |
3687 | | SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem_update(struct sljit_compiler *compiler, sljit_s32 type, |
3688 | | sljit_s32 reg, |
3689 | | sljit_s32 mem, sljit_sw memw) |
3690 | 99.7k | { |
3691 | 99.7k | CHECK_ERROR(); |
3692 | 99.7k | CHECK(check_sljit_emit_mem_update(compiler, type, reg, mem, memw)); |
3693 | 99.7k | SLJIT_UNUSED_ARG(type); |
3694 | 99.7k | SLJIT_UNUSED_ARG(reg); |
3695 | 99.7k | SLJIT_UNUSED_ARG(mem); |
3696 | 99.7k | SLJIT_UNUSED_ARG(memw); |
3697 | | |
3698 | 99.7k | return SLJIT_ERR_UNSUPPORTED; |
3699 | 99.7k | } |
3700 | | |
3701 | | #endif /* !SLJIT_CONFIG_ARM && !SLJIT_CONFIG_PPC */ |
3702 | | |
3703 | | #if !(defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) \ |
3704 | | && !(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) |
3705 | | |
3706 | | SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type, |
3707 | | sljit_s32 freg, |
3708 | | sljit_s32 mem, sljit_sw memw) |
3709 | 0 | { |
3710 | 0 | CHECK_ERROR(); |
3711 | 0 | CHECK(check_sljit_emit_fmem(compiler, type, freg, mem, memw)); |
3712 | 0 |
|
3713 | 0 | return sljit_emit_fmem_unaligned(compiler, type, freg, mem, memw); |
3714 | 0 | } |
3715 | | |
3716 | | #endif /* !SLJIT_CONFIG_ARM_32 && !SLJIT_CONFIG_MIPS */ |
3717 | | |
3718 | | #if !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \ |
3719 | | && !(defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) |
3720 | | |
3721 | | SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem_update(struct sljit_compiler *compiler, sljit_s32 type, |
3722 | | sljit_s32 freg, |
3723 | | sljit_s32 mem, sljit_sw memw) |
3724 | 0 | { |
3725 | 0 | CHECK_ERROR(); |
3726 | 0 | CHECK(check_sljit_emit_fmem_update(compiler, type, freg, mem, memw)); |
3727 | 0 | SLJIT_UNUSED_ARG(type); |
3728 | 0 | SLJIT_UNUSED_ARG(freg); |
3729 | 0 | SLJIT_UNUSED_ARG(mem); |
3730 | 0 | SLJIT_UNUSED_ARG(memw); |
3731 | 0 |
|
3732 | 0 | return SLJIT_ERR_UNSUPPORTED; |
3733 | 0 | } |
3734 | | |
3735 | | #endif /* !SLJIT_CONFIG_ARM_64 && !SLJIT_CONFIG_PPC */ |
3736 | | |
3737 | | #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \ |
3738 | | && !(defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM) \ |
3739 | | && !(defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X) \ |
3740 | | && !(defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV) \ |
3741 | | && !(defined SLJIT_CONFIG_LOONGARCH && SLJIT_CONFIG_LOONGARCH) |
3742 | | |
3743 | | SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_mov(struct sljit_compiler *compiler, sljit_s32 type, |
3744 | | sljit_s32 vreg, |
3745 | | sljit_s32 srcdst, sljit_sw srcdstw) |
3746 | | { |
3747 | | CHECK_ERROR(); |
3748 | | CHECK(check_sljit_emit_simd_mov(compiler, type, vreg, srcdst, srcdstw)); |
3749 | | SLJIT_UNUSED_ARG(compiler); |
3750 | | SLJIT_UNUSED_ARG(type); |
3751 | | SLJIT_UNUSED_ARG(vreg); |
3752 | | SLJIT_UNUSED_ARG(srcdst); |
3753 | | SLJIT_UNUSED_ARG(srcdstw); |
3754 | | |
3755 | | return SLJIT_ERR_UNSUPPORTED; |
3756 | | } |
3757 | | |
3758 | | SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_replicate(struct sljit_compiler *compiler, sljit_s32 type, |
3759 | | sljit_s32 vreg, |
3760 | | sljit_s32 src, sljit_sw srcw) |
3761 | | { |
3762 | | CHECK_ERROR(); |
3763 | | CHECK(check_sljit_emit_simd_replicate(compiler, type, vreg, src, srcw)); |
3764 | | SLJIT_UNUSED_ARG(compiler); |
3765 | | SLJIT_UNUSED_ARG(type); |
3766 | | SLJIT_UNUSED_ARG(vreg); |
3767 | | SLJIT_UNUSED_ARG(src); |
3768 | | SLJIT_UNUSED_ARG(srcw); |
3769 | | |
3770 | | return SLJIT_ERR_UNSUPPORTED; |
3771 | | } |
3772 | | |
3773 | | SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_lane_mov(struct sljit_compiler *compiler, sljit_s32 type, |
3774 | | sljit_s32 vreg, sljit_s32 lane_index, |
3775 | | sljit_s32 srcdst, sljit_sw srcdstw) |
3776 | | { |
3777 | | CHECK_ERROR(); |
3778 | | CHECK(check_sljit_emit_simd_lane_mov(compiler, type, vreg, lane_index, srcdst, srcdstw)); |
3779 | | SLJIT_UNUSED_ARG(compiler); |
3780 | | SLJIT_UNUSED_ARG(type); |
3781 | | SLJIT_UNUSED_ARG(vreg); |
3782 | | SLJIT_UNUSED_ARG(lane_index); |
3783 | | SLJIT_UNUSED_ARG(srcdst); |
3784 | | SLJIT_UNUSED_ARG(srcdstw); |
3785 | | |
3786 | | return SLJIT_ERR_UNSUPPORTED; |
3787 | | } |
3788 | | |
3789 | | SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_lane_replicate(struct sljit_compiler *compiler, sljit_s32 type, |
3790 | | sljit_s32 vreg, |
3791 | | sljit_s32 src, sljit_s32 src_lane_index) |
3792 | | { |
3793 | | CHECK_ERROR(); |
3794 | | CHECK(check_sljit_emit_simd_lane_replicate(compiler, type, vreg, src, src_lane_index)); |
3795 | | SLJIT_UNUSED_ARG(compiler); |
3796 | | SLJIT_UNUSED_ARG(type); |
3797 | | SLJIT_UNUSED_ARG(vreg); |
3798 | | SLJIT_UNUSED_ARG(src); |
3799 | | SLJIT_UNUSED_ARG(src_lane_index); |
3800 | | |
3801 | | return SLJIT_ERR_UNSUPPORTED; |
3802 | | } |
3803 | | |
3804 | | SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_extend(struct sljit_compiler *compiler, sljit_s32 type, |
3805 | | sljit_s32 vreg, |
3806 | | sljit_s32 src, sljit_sw srcw) |
3807 | | { |
3808 | | CHECK_ERROR(); |
3809 | | CHECK(check_sljit_emit_simd_extend(compiler, type, vreg, src, srcw)); |
3810 | | SLJIT_UNUSED_ARG(compiler); |
3811 | | SLJIT_UNUSED_ARG(type); |
3812 | | SLJIT_UNUSED_ARG(vreg); |
3813 | | SLJIT_UNUSED_ARG(src); |
3814 | | SLJIT_UNUSED_ARG(srcw); |
3815 | | |
3816 | | return SLJIT_ERR_UNSUPPORTED; |
3817 | | } |
3818 | | |
3819 | | SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_sign(struct sljit_compiler *compiler, sljit_s32 type, |
3820 | | sljit_s32 vreg, |
3821 | | sljit_s32 dst, sljit_sw dstw) |
3822 | | { |
3823 | | CHECK_ERROR(); |
3824 | | CHECK(check_sljit_emit_simd_sign(compiler, type, vreg, dst, dstw)); |
3825 | | SLJIT_UNUSED_ARG(compiler); |
3826 | | SLJIT_UNUSED_ARG(type); |
3827 | | SLJIT_UNUSED_ARG(vreg); |
3828 | | SLJIT_UNUSED_ARG(dst); |
3829 | | SLJIT_UNUSED_ARG(dstw); |
3830 | | |
3831 | | return SLJIT_ERR_UNSUPPORTED; |
3832 | | } |
3833 | | |
3834 | | SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_op2(struct sljit_compiler *compiler, sljit_s32 type, |
3835 | | sljit_s32 dst_vreg, sljit_s32 src1_vreg, sljit_s32 src2, sljit_sw src2w) |
3836 | | { |
3837 | | CHECK_ERROR(); |
3838 | | CHECK(check_sljit_emit_simd_op2(compiler, type, dst_vreg, src1_vreg, src2, src2w)); |
3839 | | SLJIT_UNUSED_ARG(compiler); |
3840 | | SLJIT_UNUSED_ARG(type); |
3841 | | SLJIT_UNUSED_ARG(dst_vreg); |
3842 | | SLJIT_UNUSED_ARG(src1_vreg); |
3843 | | SLJIT_UNUSED_ARG(src2); |
3844 | | SLJIT_UNUSED_ARG(src2w); |
3845 | | |
3846 | | return SLJIT_ERR_UNSUPPORTED; |
3847 | | } |
3848 | | |
3849 | | #endif /* !SLJIT_CONFIG_X86 && !SLJIT_CONFIG_ARM && !SLJIT_CONFIG_S390X && !SLJIT_CONFIG_LOONGARCH */ |
3850 | | |
3851 | | #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \ |
3852 | | && !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) |
3853 | | |
3854 | | SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset) |
3855 | | { |
3856 | | CHECK_ERROR(); |
3857 | | CHECK(check_sljit_get_local_base(compiler, dst, dstw, offset)); |
3858 | | |
3859 | | ADJUST_LOCAL_OFFSET(SLJIT_MEM1(SLJIT_SP), offset); |
3860 | | |
3861 | | SLJIT_SKIP_CHECKS(compiler); |
3862 | | |
3863 | | if (offset != 0) |
3864 | | return sljit_emit_op2(compiler, SLJIT_ADD, dst, dstw, SLJIT_SP, 0, SLJIT_IMM, offset); |
3865 | | return sljit_emit_op1(compiler, SLJIT_MOV, dst, dstw, SLJIT_SP, 0); |
3866 | | } |
3867 | | |
3868 | | #endif /* !SLJIT_CONFIG_X86 && !SLJIT_CONFIG_ARM_64 */ |
3869 | | |
3870 | | SLJIT_API_FUNC_ATTRIBUTE void* sljit_read_only_buffer_start_writing(sljit_uw addr, sljit_uw size, sljit_sw executable_offset) |
3871 | 0 | { |
3872 | 0 | SLJIT_UNUSED_ARG(size); |
3873 | 0 | SLJIT_UNUSED_ARG(executable_offset); |
3874 | 0 |
|
3875 | 0 | SLJIT_UPDATE_WX_FLAGS((void*)addr, (void*)(addr + size), 0); |
3876 | 0 | return SLJIT_ADD_EXEC_OFFSET(addr, -executable_offset); |
3877 | 0 | } |
3878 | | |
3879 | | SLJIT_API_FUNC_ATTRIBUTE void sljit_read_only_buffer_end_writing(sljit_uw addr, sljit_uw size, sljit_sw executable_offset) |
3880 | 0 | { |
3881 | 0 | SLJIT_UNUSED_ARG(addr); |
3882 | 0 | SLJIT_UNUSED_ARG(size); |
3883 | 0 | SLJIT_UNUSED_ARG(executable_offset); |
3884 | 0 |
|
3885 | 0 | SLJIT_UPDATE_WX_FLAGS((void*)addr, (void*)(addr + size), 1); |
3886 | 0 | SLJIT_CACHE_FLUSH((void*)addr, (void*)(addr + size)); |
3887 | 0 | } |
3888 | | |
3889 | | #endif /* !SLJIT_CONFIG_UNSUPPORTED */ |