Improve the style of utils.
[sljit.git] / test_src / sljitTest.c
blobdcdd74166165cb0db6c773a53cef35ea3feea9dc
1 /*
2 * Stack-less Just-In-Time compiler
4 * Copyright Zoltan Herczeg (hzmester@freemail.hu). All rights reserved.
6 * Redistribution and use in source and binary forms, with or without modification, are
7 * permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright notice, this list of
10 * conditions and the following disclaimer.
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.
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.
27 /* Must be the first one. Must not depend on any other include. */
28 #include "sljitLir.h"
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
34 #ifdef _MSC_VER
35 #pragma warning(push)
36 #pragma warning(disable: 4127) /* conditional expression is constant */
37 #endif
39 #if defined _WIN32 || defined _WIN64
40 #define COLOR_RED
41 #define COLOR_GREEN
42 #define COLOR_ARCH
43 #define COLOR_DEFAULT
44 #else
45 #define COLOR_RED "\33[31m"
46 #define COLOR_GREEN "\33[32m"
47 #define COLOR_ARCH "\33[33m"
48 #define COLOR_DEFAULT "\33[0m"
49 #endif
51 union executable_code {
52 void* code;
53 sljit_sw (SLJIT_FUNC *func0)(void);
54 sljit_sw (SLJIT_FUNC *func1)(sljit_sw a);
55 sljit_sw (SLJIT_FUNC *func2)(sljit_sw a, sljit_sw b);
56 sljit_sw (SLJIT_FUNC *func3)(sljit_sw a, sljit_sw b, sljit_sw c);
58 typedef union executable_code executable_code;
60 static sljit_s32 successful_tests = 0;
61 static sljit_s32 verbose = 0;
62 static sljit_s32 silent = 0;
64 #define FAILED(cond, text) \
65 if (SLJIT_UNLIKELY(cond)) { \
66 printf(text); \
67 return; \
70 #define CHECK(compiler) \
71 if (sljit_get_compiler_error(compiler) != SLJIT_ERR_COMPILED) { \
72 printf("Compiler error: %d\n", sljit_get_compiler_error(compiler)); \
73 sljit_free_compiler(compiler); \
74 return; \
77 static void cond_set(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_s32 type)
79 /* Testing both sljit_emit_op_flags and sljit_emit_jump. */
80 struct sljit_jump* jump;
81 struct sljit_label* label;
83 sljit_emit_op_flags(compiler, SLJIT_MOV, dst, dstw, type);
84 jump = sljit_emit_jump(compiler, type);
85 sljit_emit_op2(compiler, SLJIT_ADD, dst, dstw, dst, dstw, SLJIT_IMM, 2);
86 label = sljit_emit_label(compiler);
87 sljit_set_label(jump, label);
90 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
92 #define MALLOC_EXEC(result, size) \
93 result = SLJIT_MALLOC_EXEC(size); \
94 if (!result) { \
95 printf("Cannot allocate executable memory\n"); \
96 return; \
97 } \
98 memset(result, 255, size);
100 #define FREE_EXEC(ptr) \
101 SLJIT_FREE_EXEC(((sljit_u8*)(ptr)) + SLJIT_EXEC_OFFSET(ptr));
103 static void test_exec_allocator(void)
105 /* This is not an sljit test. */
106 void *ptr1;
107 void *ptr2;
108 void *ptr3;
110 if (verbose)
111 printf("Run executable allocator test\n");
113 MALLOC_EXEC(ptr1, 32);
114 MALLOC_EXEC(ptr2, 512);
115 MALLOC_EXEC(ptr3, 512);
116 FREE_EXEC(ptr2);
117 FREE_EXEC(ptr3);
118 FREE_EXEC(ptr1);
119 MALLOC_EXEC(ptr1, 262104);
120 MALLOC_EXEC(ptr2, 32000);
121 FREE_EXEC(ptr1);
122 MALLOC_EXEC(ptr1, 262104);
123 FREE_EXEC(ptr1);
124 FREE_EXEC(ptr2);
125 MALLOC_EXEC(ptr1, 512);
126 MALLOC_EXEC(ptr2, 512);
127 MALLOC_EXEC(ptr3, 512);
128 FREE_EXEC(ptr2);
129 MALLOC_EXEC(ptr2, 512);
130 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
131 sljit_free_unused_memory_exec();
132 #endif
133 FREE_EXEC(ptr3);
134 FREE_EXEC(ptr1);
135 FREE_EXEC(ptr2);
136 #if (defined SLJIT_UTIL_GLOBAL_LOCK && SLJIT_UTIL_GLOBAL_LOCK)
137 /* Just call the global locks. */
138 sljit_grab_lock();
139 sljit_release_lock();
140 #endif
142 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
143 sljit_free_unused_memory_exec();
144 #endif
147 #undef MALLOC_EXEC
149 #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
151 static void test1(void)
153 /* Enter and return from an sljit function. */
154 executable_code code;
155 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
157 if (verbose)
158 printf("Run test1\n");
160 FAILED(!compiler, "cannot create compiler\n");
162 /* 3 arguments passed, 3 arguments used. */
163 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), 3, 3, 0, 0, 0);
164 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_S1, 0);
166 SLJIT_ASSERT(sljit_get_generated_code_size(compiler) == 0);
167 code.code = sljit_generate_code(compiler);
168 CHECK(compiler);
169 SLJIT_ASSERT(compiler->error == SLJIT_ERR_COMPILED);
170 SLJIT_ASSERT(sljit_get_generated_code_size(compiler) > 0);
171 sljit_free_compiler(compiler);
173 FAILED(code.func3(3, -21, 86) != -21, "test1 case 1 failed\n");
174 FAILED(code.func3(4789, 47890, 997) != 47890, "test1 case 2 failed\n");
176 sljit_free_code(code.code);
177 successful_tests++;
180 static void test2(void)
182 /* Test mov. */
183 executable_code code;
184 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
185 sljit_sw buf[8];
186 static sljit_sw data[2] = { 0, -9876 };
188 if (verbose)
189 printf("Run test2\n");
191 FAILED(!compiler, "cannot create compiler\n");
193 buf[0] = 5678;
194 buf[1] = 0;
195 buf[2] = 0;
196 buf[3] = 0;
197 buf[4] = 0;
198 buf[5] = 0;
199 buf[6] = 0;
200 buf[7] = 0;
201 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 2, 0, 0, 0);
202 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 9999);
203 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_S0, 0);
204 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_sw), SLJIT_R0, 0);
205 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
206 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM2(SLJIT_S1, SLJIT_R1), 0);
207 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, 2);
208 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_S1, SLJIT_S0), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_S1, SLJIT_R1), 0);
209 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, 3);
210 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_S1, SLJIT_S0), SLJIT_WORD_SHIFT, SLJIT_MEM0(), (sljit_sw)&buf);
211 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw));
212 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R0), (sljit_sw)&data);
213 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
214 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf - 0x12345678);
215 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R0), 0x12345678);
216 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_sw), SLJIT_R0, 0);
217 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 3456);
218 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&buf - 0xff890 + 6 * sizeof(sljit_sw));
219 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 0xff890, SLJIT_R0, 0);
220 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&buf + 0xff890 + 7 * sizeof(sljit_sw));
221 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), -0xff890, SLJIT_R0, 0);
222 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R2, 0);
224 code.code = sljit_generate_code(compiler);
225 CHECK(compiler);
226 sljit_free_compiler(compiler);
228 FAILED(code.func1((sljit_sw)&buf) != 9999, "test2 case 1 failed\n");
229 FAILED(buf[1] != 9999, "test2 case 2 failed\n");
230 FAILED(buf[2] != 9999, "test2 case 3 failed\n");
231 FAILED(buf[3] != 5678, "test2 case 4 failed\n");
232 FAILED(buf[4] != -9876, "test2 case 5 failed\n");
233 FAILED(buf[5] != 5678, "test2 case 6 failed\n");
234 FAILED(buf[6] != 3456, "test2 case 6 failed\n");
235 FAILED(buf[7] != 3456, "test2 case 6 failed\n");
237 sljit_free_code(code.code);
238 successful_tests++;
241 static void test3(void)
243 /* Test not. */
244 executable_code code;
245 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
246 sljit_sw buf[5];
248 if (verbose)
249 printf("Run test3\n");
251 FAILED(!compiler, "cannot create compiler\n");
252 buf[0] = 1234;
253 buf[1] = 0;
254 buf[2] = 9876;
255 buf[3] = 0;
256 buf[4] = 0x12345678;
258 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 0, 0, 0);
259 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 0);
260 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM0(), (sljit_sw)&buf[1], SLJIT_MEM0(), (sljit_sw)&buf[1]);
261 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_S0), 0);
262 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2);
263 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&buf[4] - 0xff0000 - 0x20);
264 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, (sljit_sw)&buf[4] - 0xff0000);
265 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM1(SLJIT_R1), 0xff0000 + 0x20, SLJIT_MEM1(SLJIT_R2), 0xff0000);
266 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
268 code.code = sljit_generate_code(compiler);
269 CHECK(compiler);
270 sljit_free_compiler(compiler);
272 FAILED(code.func1((sljit_sw)&buf) != ~1234, "test3 case 1 failed\n");
273 FAILED(buf[1] != ~1234, "test3 case 2 failed\n");
274 FAILED(buf[3] != ~9876, "test3 case 3 failed\n");
275 FAILED(buf[4] != ~0x12345678, "test3 case 4 failed\n");
277 sljit_free_code(code.code);
278 successful_tests++;
281 static void test4(void)
283 /* Test neg. */
284 executable_code code;
285 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
286 sljit_sw buf[4];
288 if (verbose)
289 printf("Run test4\n");
291 FAILED(!compiler, "cannot create compiler\n");
292 buf[0] = 0;
293 buf[1] = 1234;
294 buf[2] = 0;
295 buf[3] = 0;
297 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 3, 2, 0, 0, 0);
298 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_S1, 0);
299 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM0(), (sljit_sw)&buf[0], SLJIT_MEM0(), (sljit_sw)&buf[1]);
300 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 299);
301 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_R1, 0);
302 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_RETURN_REG, 0, SLJIT_S1, 0);
303 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
305 code.code = sljit_generate_code(compiler);
306 CHECK(compiler);
307 sljit_free_compiler(compiler);
309 FAILED(code.func2((sljit_sw)&buf, 4567) != -4567, "test4 case 1 failed\n");
310 FAILED(buf[0] != -1234, "test4 case 2 failed\n");
311 FAILED(buf[2] != -4567, "test4 case 3 failed\n");
312 FAILED(buf[3] != -299, "test4 case 4 failed\n");
314 sljit_free_code(code.code);
315 successful_tests++;
318 static void test5(void)
320 /* Test add. */
321 executable_code code;
322 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
323 sljit_sw buf[9];
325 if (verbose)
326 printf("Run test5\n");
328 FAILED(!compiler, "cannot create compiler\n");
329 buf[0] = 100;
330 buf[1] = 200;
331 buf[2] = 300;
332 buf[3] = 0;
333 buf[4] = 0;
334 buf[5] = 0;
335 buf[6] = 0;
336 buf[7] = 0;
337 buf[8] = 313;
339 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 2, 0, 0, 0);
340 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw));
341 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 50);
342 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 1, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 1, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 0);
343 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw) + 2);
344 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 50);
345 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 0);
346 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
347 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_IMM, 4, SLJIT_R0, 0);
348 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_IMM, 50, SLJIT_R1, 0);
349 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_IMM, 50, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw));
350 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R1, 0);
351 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw));
352 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw));
353 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R1, 0);
354 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x1e7d39f2);
355 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_R1, 0, SLJIT_IMM, 0x23de7c06);
356 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_IMM, 0x3d72e452, SLJIT_R1, 0);
357 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_IMM, -43, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw));
358 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_IMM, 1000, SLJIT_R0, 0);
359 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 1430);
360 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_IMM, -99, SLJIT_R0, 0);
362 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
364 code.code = sljit_generate_code(compiler);
365 CHECK(compiler);
366 sljit_free_compiler(compiler);
368 FAILED(code.func1((sljit_sw)&buf) != 2437 + 2 * sizeof(sljit_sw), "test5 case 1 failed\n");
369 FAILED(buf[0] != 202 + 2 * sizeof(sljit_sw), "test5 case 2 failed\n");
370 FAILED(buf[2] != 500, "test5 case 3 failed\n");
371 FAILED(buf[3] != 400, "test5 case 4 failed\n");
372 FAILED(buf[4] != 200, "test5 case 5 failed\n");
373 FAILED(buf[5] != 250, "test5 case 6 failed\n");
374 FAILED(buf[6] != 0x425bb5f8, "test5 case 7 failed\n");
375 FAILED(buf[7] != 0x5bf01e44, "test5 case 8 failed\n");
376 FAILED(buf[8] != 270, "test5 case 9 failed\n");
378 sljit_free_code(code.code);
379 successful_tests++;
382 static void test6(void)
384 /* Test addc, sub, subc. */
385 executable_code code;
386 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
387 sljit_sw buf[10];
389 if (verbose)
390 printf("Run test6\n");
392 FAILED(!compiler, "cannot create compiler\n");
393 buf[0] = 0;
394 buf[1] = 0;
395 buf[2] = 0;
396 buf[3] = 0;
397 buf[4] = 0;
398 buf[5] = 0;
399 buf[6] = 0;
400 buf[7] = 0;
401 buf[8] = 0;
402 buf[9] = 0;
404 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 0, 0, 0);
405 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
406 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, -1);
407 sljit_emit_op2(compiler, SLJIT_ADDC, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0, SLJIT_IMM, 0);
408 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R0, 0);
409 sljit_emit_op2(compiler, SLJIT_ADDC, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, 4);
410 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 100);
411 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0, SLJIT_IMM, 50);
412 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 6000);
413 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_IMM, 10);
414 sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_IMM, 5);
415 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 100);
416 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2);
417 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R0, 0);
418 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 5000);
419 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R0, 0);
420 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_R1, 0);
421 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_R1, 0);
422 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 5000);
423 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_IMM, 6000, SLJIT_R0, 0);
424 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_R0, 0);
425 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 100);
426 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 32768);
427 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_R1, 0);
428 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -32767);
429 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_R1, 0);
430 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x52cd3bf4);
431 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 9, SLJIT_R0, 0, SLJIT_IMM, 0x3da297c6);
432 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 10);
433 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_CARRY, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 5);
434 sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 2);
435 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, -2220);
436 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
438 code.code = sljit_generate_code(compiler);
439 CHECK(compiler);
440 sljit_free_compiler(compiler);
442 FAILED(code.func1((sljit_sw)&buf) != 2223, "test6 case 1 failed\n");
443 FAILED(buf[0] != 1, "test6 case 2 failed\n");
444 FAILED(buf[1] != 5, "test6 case 3 failed\n");
445 FAILED(buf[2] != 50, "test6 case 4 failed\n");
446 FAILED(buf[3] != 4, "test6 case 5 failed\n");
447 FAILED(buf[4] != 50, "test6 case 6 failed\n");
448 FAILED(buf[5] != 50, "test6 case 7 failed\n");
449 FAILED(buf[6] != 1000, "test6 case 8 failed\n");
450 FAILED(buf[7] != 100 - 32768, "test6 case 9 failed\n");
451 FAILED(buf[8] != 100 + 32767, "test6 case 10 failed\n");
452 FAILED(buf[9] != 0x152aa42e, "test6 case 11 failed\n");
454 sljit_free_code(code.code);
455 successful_tests++;
458 static void test7(void)
460 /* Test logical operators. */
461 executable_code code;
462 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
463 sljit_sw buf[8];
465 if (verbose)
466 printf("Run test7\n");
468 FAILED(!compiler, "cannot create compiler\n");
469 buf[0] = 0xff80;
470 buf[1] = 0x0f808080;
471 buf[2] = 0;
472 buf[3] = 0xaaaaaa;
473 buf[4] = 0;
474 buf[5] = 0x4040;
475 buf[6] = 0;
476 buf[7] = 0xc43a7f95;
478 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 0, 0, 0);
479 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xf0C000);
480 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0, SLJIT_IMM, 0x308f);
481 sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw));
482 sljit_emit_op2(compiler, SLJIT_AND, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_IMM, 0xf0f0f0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3);
483 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xC0F0);
484 sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5);
485 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xff0000);
486 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R0, 0);
487 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 0xC0F0);
488 sljit_emit_op2(compiler, SLJIT_AND, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5);
489 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_R2, 0, SLJIT_IMM, 0xff0000);
490 sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, 0xFFFFFF, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw));
491 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_IMM, 0xa56c82c0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6);
492 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7);
493 sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_IMM, 0xff00ff00, SLJIT_R0, 0);
494 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xff00ff00);
495 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 0x0f);
496 sljit_emit_op2(compiler, SLJIT_AND, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0x888888, SLJIT_R1, 0);
497 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
499 code.code = sljit_generate_code(compiler);
500 CHECK(compiler);
501 sljit_free_compiler(compiler);
503 FAILED(code.func1((sljit_sw)&buf) != 0x8808, "test7 case 1 failed\n");
504 FAILED(buf[0] != 0x0F807F00, "test7 case 2 failed\n");
505 FAILED(buf[1] != 0x0F7F7F7F, "test7 case 3 failed\n");
506 FAILED(buf[2] != 0x00F0F08F, "test7 case 4 failed\n");
507 FAILED(buf[3] != 0x00A0A0A0, "test7 case 5 failed\n");
508 FAILED(buf[4] != 0x00FF80B0, "test7 case 6 failed\n");
509 FAILED(buf[5] != 0x00FF4040, "test7 case 7 failed\n");
510 FAILED(buf[6] != 0xa56c82c0, "test7 case 8 failed\n");
511 FAILED(buf[7] != 0x3b3a8095, "test7 case 9 failed\n");
513 sljit_free_code(code.code);
514 successful_tests++;
517 static void test8(void)
519 /* Test flags (neg, cmp, test). */
520 executable_code code;
521 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
522 sljit_sw buf[13];
524 if (verbose)
525 printf("Run test8\n");
527 FAILED(!compiler, "cannot create compiler\n");
528 buf[0] = 100;
529 buf[1] = 3;
530 buf[2] = 3;
531 buf[3] = 3;
532 buf[4] = 3;
533 buf[5] = 3;
534 buf[6] = 3;
535 buf[7] = 3;
536 buf[8] = 3;
537 buf[9] = 3;
538 buf[10] = 3;
539 buf[11] = 3;
540 buf[12] = 3;
542 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 2, 0, 0, 0);
543 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 20);
544 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 10);
545 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_IMM, 6, SLJIT_IMM, 5);
546 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_NOT_EQUAL);
547 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_EQUAL);
548 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 3000);
549 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_GREATER);
550 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 3000);
551 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_S1, 0);
552 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_LESS);
553 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R2, 0);
554 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, -15);
555 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_SIG_GREATER);
556 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_R2, 0);
557 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)1 << ((sizeof(sljit_sw) << 3) - 1));
558 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
559 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
560 sljit_emit_op1(compiler, SLJIT_NEG | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R0, 0);
561 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_OVERFLOW);
562 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
563 sljit_emit_op1(compiler, SLJIT_NOT | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_R0, 0);
564 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_ZERO);
565 sljit_emit_op1(compiler, SLJIT_NOT | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R1, 0);
566 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_ZERO);
567 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_IMM, 0xffff, SLJIT_R0, 0);
568 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffff);
569 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 9, SLJIT_NOT_ZERO);
570 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_IMM, 0xffff, SLJIT_R1, 0);
571 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R1, 0, SLJIT_IMM, 0xffff);
572 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R1, 0);
573 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), 0);
574 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0);
575 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0x1);
576 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 10, SLJIT_NOT_ZERO);
577 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(1) << ((sizeof(sljit_sw) << 3) - 1));
578 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
579 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R1, 0, SLJIT_R0, 0);
580 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 11, SLJIT_OVERFLOW);
581 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R1, 0, SLJIT_R0, 0);
582 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 12, SLJIT_OVERFLOW);
583 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
585 code.code = sljit_generate_code(compiler);
586 CHECK(compiler);
587 sljit_free_compiler(compiler);
589 code.func1((sljit_sw)&buf);
590 FAILED(buf[1] != 1, "test8 case 1 failed\n");
591 FAILED(buf[2] != 0, "test8 case 2 failed\n");
592 FAILED(buf[3] != 0, "test8 case 3 failed\n");
593 FAILED(buf[4] != 1, "test8 case 4 failed\n");
594 FAILED(buf[5] != 1, "test8 case 5 failed\n");
595 FAILED(buf[6] != 1, "test8 case 6 failed\n");
596 FAILED(buf[7] != 1, "test8 case 7 failed\n");
597 FAILED(buf[8] != 0, "test8 case 8 failed\n");
598 FAILED(buf[9] != 1, "test8 case 9 failed\n");
599 FAILED(buf[10] != 0, "test8 case 10 failed\n");
600 FAILED(buf[11] != 1, "test8 case 11 failed\n");
601 FAILED(buf[12] != 0, "test8 case 12 failed\n");
603 sljit_free_code(code.code);
604 successful_tests++;
607 static void test9(void)
609 /* Test shift. */
610 executable_code code;
611 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
612 sljit_sw buf[13];
613 #ifdef SLJIT_PREF_SHIFT_REG
614 sljit_s32 shift_reg = SLJIT_PREF_SHIFT_REG;
615 #else
616 sljit_s32 shift_reg = SLJIT_R2;
617 #endif
619 SLJIT_ASSERT(shift_reg >= SLJIT_R2 && shift_reg <= SLJIT_R3);
621 if (verbose)
622 printf("Run test9\n");
624 FAILED(!compiler, "cannot create compiler\n");
625 buf[0] = 0;
626 buf[1] = 0;
627 buf[2] = 0;
628 buf[3] = 0;
629 buf[4] = 1 << 10;
630 buf[5] = 0;
631 buf[6] = 0;
632 buf[7] = 0;
633 buf[8] = 0;
634 buf[9] = 3;
635 buf[10] = 0;
636 buf[11] = 0;
637 buf[12] = 0;
639 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 4, 2, 0, 0, 0);
640 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xf);
641 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 3);
642 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
643 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
644 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
645 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R1, 0, SLJIT_IMM, 1);
646 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -64);
647 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 2);
648 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0, shift_reg, 0);
650 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 0xff);
651 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4);
652 sljit_emit_op2(compiler, SLJIT_SHL, shift_reg, 0, shift_reg, 0, SLJIT_R0, 0);
653 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, shift_reg, 0);
654 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 0xff);
655 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
656 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R0, 0);
657 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, shift_reg, 0, SLJIT_R0, 0);
659 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, 0xf);
660 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
661 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_R0, 0);
662 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_S1, 0);
663 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_R0, 0);
664 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_R0, 0);
665 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 0xf00);
666 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4);
667 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_R1, 0, SLJIT_R2, 0, SLJIT_R0, 0);
668 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_R1, 0);
670 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)buf);
671 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 9);
672 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), SLJIT_WORD_SHIFT);
674 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 4);
675 sljit_emit_op2(compiler, SLJIT_SHL, shift_reg, 0, SLJIT_IMM, 2, shift_reg, 0);
676 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 10, shift_reg, 0);
678 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xa9);
679 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 0);
680 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x7d00);
681 sljit_emit_op2(compiler, SLJIT_LSHR32, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 32);
682 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
683 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
684 #endif
685 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_R0, 0);
686 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xe30000);
687 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
688 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffc0);
689 #else
690 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffe0);
691 #endif
692 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_R0, 0);
693 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x25000000);
694 sljit_emit_op2(compiler, SLJIT_SHL32, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xfffe1);
695 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
696 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
697 #endif
698 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 11, SLJIT_R1, 0, SLJIT_R0, 0);
700 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 0);
701 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x5c);
702 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R1, 0, SLJIT_R0, 0, shift_reg, 0);
703 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0xf600);
704 sljit_emit_op2(compiler, SLJIT_LSHR32, SLJIT_R0, 0, SLJIT_R0, 0, shift_reg, 0);
705 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
706 /* Alternative form of uint32 type cast. */
707 sljit_emit_op2(compiler, SLJIT_AND, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffffffff);
708 #endif
709 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_R0, 0);
710 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x630000);
711 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_R0, 0, SLJIT_R0, 0, shift_reg, 0);
712 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 12, SLJIT_R1, 0, SLJIT_R0, 0);
714 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
716 code.code = sljit_generate_code(compiler);
717 CHECK(compiler);
718 sljit_free_compiler(compiler);
720 code.func1((sljit_sw)&buf);
721 FAILED(buf[0] != 0x3c, "test9 case 1 failed\n");
722 FAILED(buf[1] != 0xf0, "test9 case 2 failed\n");
723 FAILED(buf[2] != -16, "test9 case 3 failed\n");
724 FAILED(buf[3] != 0xff0, "test9 case 4 failed\n");
725 FAILED(buf[4] != 4, "test9 case 5 failed\n");
726 FAILED(buf[5] != 0xff00, "test9 case 6 failed\n");
727 FAILED(buf[6] != 0x3c, "test9 case 7 failed\n");
728 FAILED(buf[7] != 0xf0, "test9 case 8 failed\n");
729 FAILED(buf[8] != 0xf0, "test9 case 9 failed\n");
730 FAILED(buf[9] != 0x18, "test9 case 10 failed\n");
731 FAILED(buf[10] != 32, "test9 case 11 failed\n");
732 FAILED(buf[11] != 0x4ae37da9, "test9 case 12 failed\n");
733 FAILED(buf[12] != 0x63f65c, "test9 case 13 failed\n");
735 sljit_free_code(code.code);
736 successful_tests++;
739 static void test10(void)
741 /* Test multiplications. */
742 executable_code code;
743 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
744 sljit_sw buf[7];
746 if (verbose)
747 printf("Run test10\n");
749 FAILED(!compiler, "cannot create compiler\n");
750 buf[0] = 3;
751 buf[1] = 0;
752 buf[2] = 0;
753 buf[3] = 6;
754 buf[4] = -10;
755 buf[5] = 0;
756 buf[6] = 0;
758 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 0, 0, 0);
759 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 5);
760 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
761 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
762 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 7);
763 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_R2, 0, SLJIT_IMM, 8);
764 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
765 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_IMM, -3, SLJIT_IMM, -4);
766 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0);
767 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -2);
768 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_R0, 0);
769 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw) / 2);
770 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&buf[3]);
771 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 1, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 1, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 1);
772 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 9);
773 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R0, 0);
774 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_R0, 0);
775 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
776 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 3);
777 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x123456789));
778 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_R0, 0);
779 #endif
780 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 11, SLJIT_IMM, 10);
781 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
783 code.code = sljit_generate_code(compiler);
784 CHECK(compiler);
785 sljit_free_compiler(compiler);
787 FAILED(code.func1((sljit_sw)&buf) != 110, "test10 case 1 failed\n");
788 FAILED(buf[0] != 15, "test10 case 2 failed\n");
789 FAILED(buf[1] != 56, "test10 case 3 failed\n");
790 FAILED(buf[2] != 12, "test10 case 4 failed\n");
791 FAILED(buf[3] != -12, "test10 case 5 failed\n");
792 FAILED(buf[4] != 100, "test10 case 6 failed\n");
793 FAILED(buf[5] != 81, "test10 case 7 failed\n");
794 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
795 FAILED(buf[6] != SLJIT_W(0x123456789) * 3, "test10 case 8 failed\n");
796 #endif
798 sljit_free_code(code.code);
799 successful_tests++;
802 static void test11(void)
804 /* Test rewritable constants. */
805 executable_code code;
806 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
807 struct sljit_const* const1;
808 struct sljit_const* const2;
809 struct sljit_const* const3;
810 struct sljit_const* const4;
811 void* value;
812 sljit_sw executable_offset;
813 sljit_uw const1_addr;
814 sljit_uw const2_addr;
815 sljit_uw const3_addr;
816 sljit_uw const4_addr;
817 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
818 sljit_sw word_value1 = SLJIT_W(0xaaaaaaaaaaaaaaaa);
819 sljit_sw word_value2 = SLJIT_W(0xfee1deadfbadf00d);
820 #else
821 sljit_sw word_value1 = 0xaaaaaaaal;
822 sljit_sw word_value2 = 0xfbadf00dl;
823 #endif
824 sljit_sw buf[3];
826 if (verbose)
827 printf("Run test11\n");
829 FAILED(!compiler, "cannot create compiler\n");
830 buf[0] = 0;
831 buf[1] = 0;
832 buf[2] = 0;
834 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 0, 0, 0);
836 SLJIT_ASSERT(!sljit_alloc_memory(compiler, 0));
837 SLJIT_ASSERT(!sljit_alloc_memory(compiler, 16 * sizeof(sljit_sw) + 1));
839 const1 = sljit_emit_const(compiler, SLJIT_MEM0(), (sljit_sw)&buf[0], -0x81b9);
841 value = sljit_alloc_memory(compiler, 16 * sizeof(sljit_sw));
842 if (value != NULL)
844 SLJIT_ASSERT(!((sljit_sw)value & (sizeof(sljit_sw) - 1)));
845 memset(value, 255, 16 * sizeof(sljit_sw));
848 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
849 const2 = sljit_emit_const(compiler, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_WORD_SHIFT - 1, -65535);
850 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[0] + 2 * sizeof(sljit_sw) - 2);
851 const3 = sljit_emit_const(compiler, SLJIT_MEM1(SLJIT_R0), 0, word_value1);
853 value = sljit_alloc_memory(compiler, 17);
854 if (value != NULL)
856 SLJIT_ASSERT(!((sljit_sw)value & (sizeof(sljit_sw) - 1)));
857 memset(value, 255, 16);
860 const4 = sljit_emit_const(compiler, SLJIT_RETURN_REG, 0, 0xf7afcdb7);
862 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
864 code.code = sljit_generate_code(compiler);
865 CHECK(compiler);
866 executable_offset = sljit_get_executable_offset(compiler);
867 const1_addr = sljit_get_const_addr(const1);
868 const2_addr = sljit_get_const_addr(const2);
869 const3_addr = sljit_get_const_addr(const3);
870 const4_addr = sljit_get_const_addr(const4);
871 sljit_free_compiler(compiler);
873 FAILED(code.func1((sljit_sw)&buf) != 0xf7afcdb7, "test11 case 1 failed\n");
874 FAILED(buf[0] != -0x81b9, "test11 case 2 failed\n");
875 FAILED(buf[1] != -65535, "test11 case 3 failed\n");
876 FAILED(buf[2] != word_value1, "test11 case 4 failed\n");
878 sljit_set_const(const1_addr, -1, executable_offset);
879 sljit_set_const(const2_addr, word_value2, executable_offset);
880 sljit_set_const(const3_addr, 0xbab0fea1, executable_offset);
881 sljit_set_const(const4_addr, -60089, executable_offset);
883 FAILED(code.func1((sljit_sw)&buf) != -60089, "test11 case 5 failed\n");
884 FAILED(buf[0] != -1, "test11 case 6 failed\n");
885 FAILED(buf[1] != word_value2, "test11 case 7 failed\n");
886 FAILED(buf[2] != 0xbab0fea1, "test11 case 8 failed\n");
888 sljit_free_code(code.code);
889 successful_tests++;
892 static void test12(void)
894 /* Test rewriteable jumps. */
895 executable_code code;
896 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
897 struct sljit_label *label1;
898 struct sljit_label *label2;
899 struct sljit_label *label3;
900 struct sljit_jump *jump1;
901 struct sljit_jump *jump2;
902 struct sljit_jump *jump3;
903 sljit_sw executable_offset;
904 void* value;
905 sljit_uw jump1_addr;
906 sljit_uw label1_addr;
907 sljit_uw label2_addr;
908 sljit_sw buf[1];
910 if (verbose)
911 printf("Run test12\n");
913 FAILED(!compiler, "cannot create compiler\n");
914 buf[0] = 0;
916 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 3, 2, 0, 0, 0);
917 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_UNUSED, 0, SLJIT_S1, 0, SLJIT_IMM, 10);
918 jump1 = sljit_emit_jump(compiler, SLJIT_REWRITABLE_JUMP | SLJIT_SIG_GREATER);
919 /* Default handler. */
920 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 5);
921 jump2 = sljit_emit_jump(compiler, SLJIT_JUMP);
923 value = sljit_alloc_memory(compiler, 15);
924 if (value != NULL)
926 SLJIT_ASSERT(!((sljit_sw)value & (sizeof(sljit_sw) - 1)));
927 memset(value, 255, 15);
930 /* Handler 1. */
931 label1 = sljit_emit_label(compiler);
932 sljit_emit_op0(compiler, SLJIT_ENDBR);
933 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 6);
934 jump3 = sljit_emit_jump(compiler, SLJIT_JUMP);
935 /* Handler 2. */
936 label2 = sljit_emit_label(compiler);
937 sljit_emit_op0(compiler, SLJIT_ENDBR);
938 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 7);
939 /* Exit. */
940 label3 = sljit_emit_label(compiler);
941 sljit_emit_op0(compiler, SLJIT_ENDBR);
942 sljit_set_label(jump2, label3);
943 sljit_set_label(jump3, label3);
944 /* By default, set to handler 1. */
945 sljit_set_label(jump1, label1);
946 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
948 value = sljit_alloc_memory(compiler, 8);
949 if (value != NULL)
951 SLJIT_ASSERT(!((sljit_sw)value & (sizeof(sljit_sw) - 1)));
952 memset(value, 255, 8);
955 code.code = sljit_generate_code(compiler);
956 CHECK(compiler);
957 executable_offset = sljit_get_executable_offset(compiler);
958 jump1_addr = sljit_get_jump_addr(jump1);
959 label1_addr = sljit_get_label_addr(label1);
960 label2_addr = sljit_get_label_addr(label2);
961 sljit_free_compiler(compiler);
963 code.func2((sljit_sw)&buf, 4);
964 FAILED(buf[0] != 5, "test12 case 1 failed\n");
966 code.func2((sljit_sw)&buf, 11);
967 FAILED(buf[0] != 6, "test12 case 2 failed\n");
969 sljit_set_jump_addr(jump1_addr, label2_addr, executable_offset);
970 code.func2((sljit_sw)&buf, 12);
971 FAILED(buf[0] != 7, "test12 case 3 failed\n");
973 sljit_set_jump_addr(jump1_addr, label1_addr, executable_offset);
974 code.func2((sljit_sw)&buf, 13);
975 FAILED(buf[0] != 6, "test12 case 4 failed\n");
977 sljit_free_code(code.code);
978 successful_tests++;
981 static void test13(void)
983 /* Test fpu monadic functions. */
984 executable_code code;
985 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
986 sljit_f64 buf[7];
987 sljit_sw buf2[6];
989 if (verbose)
990 printf("Run test13\n");
992 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
993 if (verbose)
994 printf("no fpu available, test13 skipped\n");
995 successful_tests++;
996 if (compiler)
997 sljit_free_compiler(compiler);
998 return;
1001 FAILED(!compiler, "cannot create compiler\n");
1002 buf[0] = 7.75;
1003 buf[1] = -4.5;
1004 buf[2] = 0.0;
1005 buf[3] = 0.0;
1006 buf[4] = 0.0;
1007 buf[5] = 0.0;
1008 buf[6] = 0.0;
1010 buf2[0] = 10;
1011 buf2[1] = 10;
1012 buf2[2] = 10;
1013 buf2[3] = 10;
1014 buf2[4] = 10;
1015 buf2[5] = 10;
1017 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 3, 2, 6, 0, 0);
1018 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM0(), (sljit_sw)&buf[2], SLJIT_MEM0(), (sljit_sw)&buf[1]);
1019 sljit_emit_fop1(compiler, SLJIT_ABS_F64, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1020 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM0(), (sljit_sw)&buf[0]);
1021 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2 * sizeof(sljit_f64));
1022 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 0);
1023 sljit_emit_fop1(compiler, SLJIT_NEG_F64, SLJIT_FR2, 0, SLJIT_FR0, 0);
1024 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR3, 0, SLJIT_FR2, 0);
1025 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM0(), (sljit_sw)&buf[4], SLJIT_FR3, 0);
1026 sljit_emit_fop1(compiler, SLJIT_ABS_F64, SLJIT_FR4, 0, SLJIT_FR1, 0);
1027 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f64), SLJIT_FR4, 0);
1028 sljit_emit_fop1(compiler, SLJIT_NEG_F64, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64), SLJIT_FR4, 0);
1030 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), 0);
1031 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_GREATER_F, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1032 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_GREATER_F64);
1033 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_GREATER_F, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64), SLJIT_FR5, 0);
1034 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_sw), SLJIT_GREATER_F64);
1035 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_FR5, 0);
1036 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR1, 0);
1037 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_sw), SLJIT_EQUAL_F64);
1038 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_LESS_F, SLJIT_FR1, 0, SLJIT_FR1, 0);
1039 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw), SLJIT_LESS_F64);
1040 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1041 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_sw), SLJIT_EQUAL_F64);
1042 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_NOT_EQUAL_F, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1043 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_sw), SLJIT_NOT_EQUAL_F64);
1045 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1047 code.code = sljit_generate_code(compiler);
1048 CHECK(compiler);
1049 sljit_free_compiler(compiler);
1051 code.func2((sljit_sw)&buf, (sljit_sw)&buf2);
1052 FAILED(buf[2] != -4.5, "test13 case 1 failed\n");
1053 FAILED(buf[3] != 4.5, "test13 case 2 failed\n");
1054 FAILED(buf[4] != -7.75, "test13 case 3 failed\n");
1055 FAILED(buf[5] != 4.5, "test13 case 4 failed\n");
1056 FAILED(buf[6] != -4.5, "test13 case 5 failed\n");
1058 FAILED(buf2[0] != 1, "test13 case 6 failed\n");
1059 FAILED(buf2[1] != 0, "test13 case 7 failed\n");
1060 FAILED(buf2[2] != 1, "test13 case 8 failed\n");
1061 FAILED(buf2[3] != 0, "test13 case 9 failed\n");
1062 FAILED(buf2[4] != 0, "test13 case 10 failed\n");
1063 FAILED(buf2[5] != 1, "test13 case 11 failed\n");
1065 sljit_free_code(code.code);
1066 successful_tests++;
1069 static void test14(void)
1071 /* Test fpu diadic functions. */
1072 executable_code code;
1073 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1074 sljit_f64 buf[15];
1076 if (verbose)
1077 printf("Run test14\n");
1079 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
1080 if (verbose)
1081 printf("no fpu available, test14 skipped\n");
1082 successful_tests++;
1083 if (compiler)
1084 sljit_free_compiler(compiler);
1085 return;
1087 buf[0] = 7.25;
1088 buf[1] = 3.5;
1089 buf[2] = 1.75;
1090 buf[3] = 0.0;
1091 buf[4] = 0.0;
1092 buf[5] = 0.0;
1093 buf[6] = 0.0;
1094 buf[7] = 0.0;
1095 buf[8] = 0.0;
1096 buf[9] = 0.0;
1097 buf[10] = 0.0;
1098 buf[11] = 0.0;
1099 buf[12] = 8.0;
1100 buf[13] = 4.0;
1101 buf[14] = 0.0;
1103 FAILED(!compiler, "cannot create compiler\n");
1104 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 6, 0, 0);
1106 /* ADD */
1107 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_f64));
1108 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1109 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 2);
1110 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 3, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 0, SLJIT_MEM1(SLJIT_S0), 0);
1111 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR0, 0, SLJIT_FR0, 0, SLJIT_FR1, 0);
1112 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR1, 0, SLJIT_FR0, 0, SLJIT_FR1, 0);
1113 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 4, SLJIT_FR0, 0);
1114 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 5, SLJIT_FR1, 0);
1116 /* SUB */
1117 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 0);
1118 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR3, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 2);
1119 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 2);
1120 sljit_emit_fop2(compiler, SLJIT_SUB_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 6, SLJIT_FR3, 0, SLJIT_MEM2(SLJIT_S0, SLJIT_R1), SLJIT_F64_SHIFT);
1121 sljit_emit_fop2(compiler, SLJIT_SUB_F64, SLJIT_FR2, 0, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 2);
1122 sljit_emit_fop2(compiler, SLJIT_SUB_F64, SLJIT_FR3, 0, SLJIT_FR2, 0, SLJIT_FR3, 0);
1123 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 7, SLJIT_FR2, 0);
1124 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 8, SLJIT_FR3, 0);
1126 /* MUL */
1127 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
1128 sljit_emit_fop2(compiler, SLJIT_MUL_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 9, SLJIT_MEM2(SLJIT_S0, SLJIT_R1), SLJIT_F64_SHIFT, SLJIT_FR1, 0);
1129 sljit_emit_fop2(compiler, SLJIT_MUL_F64, SLJIT_FR1, 0, SLJIT_FR1, 0, SLJIT_FR2, 0);
1130 sljit_emit_fop2(compiler, SLJIT_MUL_F64, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 2, SLJIT_FR2, 0);
1131 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 10, SLJIT_FR1, 0);
1132 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 11, SLJIT_FR5, 0);
1134 /* DIV */
1135 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 12);
1136 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 13);
1137 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR4, 0, SLJIT_FR5, 0);
1138 sljit_emit_fop2(compiler, SLJIT_DIV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 12, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 12, SLJIT_FR1, 0);
1139 sljit_emit_fop2(compiler, SLJIT_DIV_F64, SLJIT_FR5, 0, SLJIT_FR5, 0, SLJIT_FR1, 0);
1140 sljit_emit_fop2(compiler, SLJIT_DIV_F64, SLJIT_FR4, 0, SLJIT_FR1, 0, SLJIT_FR4, 0);
1141 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 13, SLJIT_FR5, 0);
1142 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 14, SLJIT_FR4, 0);
1144 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1146 code.code = sljit_generate_code(compiler);
1147 CHECK(compiler);
1148 sljit_free_compiler(compiler);
1150 code.func1((sljit_sw)&buf);
1151 FAILED(buf[3] != 10.75, "test14 case 1 failed\n");
1152 FAILED(buf[4] != 5.25, "test14 case 2 failed\n");
1153 FAILED(buf[5] != 7.0, "test14 case 3 failed\n");
1154 FAILED(buf[6] != 0.0, "test14 case 4 failed\n");
1155 FAILED(buf[7] != 5.5, "test14 case 5 failed\n");
1156 FAILED(buf[8] != 3.75, "test14 case 6 failed\n");
1157 FAILED(buf[9] != 24.5, "test14 case 7 failed\n");
1158 FAILED(buf[10] != 38.5, "test14 case 8 failed\n");
1159 FAILED(buf[11] != 9.625, "test14 case 9 failed\n");
1160 FAILED(buf[12] != 2.0, "test14 case 10 failed\n");
1161 FAILED(buf[13] != 2.0, "test14 case 11 failed\n");
1162 FAILED(buf[14] != 0.5, "test14 case 12 failed\n");
1164 sljit_free_code(code.code);
1165 successful_tests++;
1168 static sljit_sw SLJIT_FUNC func(sljit_sw a, sljit_sw b, sljit_sw c)
1170 return a + b + c + 5;
1173 static void test15(void)
1175 /* Test function call. */
1176 executable_code code;
1177 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1178 struct sljit_jump* jump = NULL;
1179 sljit_sw buf[7];
1181 if (verbose)
1182 printf("Run test15\n");
1184 FAILED(!compiler, "cannot create compiler\n");
1185 buf[0] = 0;
1186 buf[1] = 0;
1187 buf[2] = 0;
1188 buf[3] = 0;
1189 buf[4] = 0;
1190 buf[5] = 0;
1191 buf[6] = SLJIT_FUNC_OFFSET(func);
1193 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 4, 1, 0, 0, 0);
1195 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 5);
1196 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 7);
1197 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -3);
1198 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1199 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_RETURN_REG, 0);
1201 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -5);
1202 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -10);
1203 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 2);
1204 jump = sljit_emit_call(compiler, SLJIT_CALL | SLJIT_REWRITABLE_JUMP, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW));
1205 sljit_set_target(jump, (sljit_uw)-1);
1206 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1208 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1209 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 40);
1210 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -3);
1211 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), SLJIT_R0, 0);
1212 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1214 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -60);
1215 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1216 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -30);
1217 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), SLJIT_R1, 0);
1218 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1220 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 10);
1221 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 16);
1222 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1223 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), SLJIT_R2, 0);
1224 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1226 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 100);
1227 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 110);
1228 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 120);
1229 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1230 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), SLJIT_R3, 0);
1231 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1233 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -10);
1234 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -16);
1235 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 6);
1236 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw));
1237 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1239 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1241 code.code = sljit_generate_code(compiler);
1242 CHECK(compiler);
1243 sljit_set_jump_addr(sljit_get_jump_addr(jump), SLJIT_FUNC_OFFSET(func), sljit_get_executable_offset(compiler));
1244 sljit_free_compiler(compiler);
1246 FAILED(code.func1((sljit_sw)&buf) != -15, "test15 case 1 failed\n");
1247 FAILED(buf[0] != 14, "test15 case 2 failed\n");
1248 FAILED(buf[1] != -8, "test15 case 3 failed\n");
1249 FAILED(buf[2] != SLJIT_FUNC_OFFSET(func) + 42, "test15 case 4 failed\n");
1250 FAILED(buf[3] != SLJIT_FUNC_OFFSET(func) - 85, "test15 case 5 failed\n");
1251 FAILED(buf[4] != SLJIT_FUNC_OFFSET(func) + 31, "test15 case 6 failed\n");
1252 FAILED(buf[5] != 335, "test15 case 7 failed\n");
1253 FAILED(buf[6] != -15, "test15 case 8 failed\n");
1255 sljit_free_code(code.code);
1256 successful_tests++;
1259 static void test16(void)
1261 /* Ackermann benchmark. */
1262 executable_code code;
1263 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1264 struct sljit_label *entry;
1265 struct sljit_label *label;
1266 struct sljit_jump *jump;
1267 struct sljit_jump *jump1;
1268 struct sljit_jump *jump2;
1270 if (verbose)
1271 printf("Run test16\n");
1273 FAILED(!compiler, "cannot create compiler\n");
1275 entry = sljit_emit_label(compiler);
1276 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 3, 2, 0, 0, 0);
1277 /* If x == 0. */
1278 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_S0, 0, SLJIT_IMM, 0);
1279 jump1 = sljit_emit_jump(compiler, SLJIT_EQUAL);
1280 /* If y == 0. */
1281 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_S1, 0, SLJIT_IMM, 0);
1282 jump2 = sljit_emit_jump(compiler, SLJIT_EQUAL);
1284 /* Ack(x,y-1). */
1285 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
1286 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_S1, 0, SLJIT_IMM, 1);
1287 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW));
1288 sljit_set_label(jump, entry);
1290 /* Returns with Ack(x-1, Ack(x,y-1)). */
1291 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_RETURN_REG, 0);
1292 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
1293 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW));
1294 sljit_set_label(jump, entry);
1295 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1297 /* Returns with y+1. */
1298 label = sljit_emit_label(compiler);
1299 sljit_set_label(jump1, label);
1300 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1, SLJIT_S1, 0);
1301 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1303 /* Returns with Ack(x-1,1) */
1304 label = sljit_emit_label(compiler);
1305 sljit_set_label(jump2, label);
1306 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
1307 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
1308 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW));
1309 sljit_set_label(jump, entry);
1310 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1312 code.code = sljit_generate_code(compiler);
1313 CHECK(compiler);
1314 sljit_free_compiler(compiler);
1316 FAILED(code.func2(3, 3) != 61, "test16 case 1 failed\n");
1317 /* For benchmarking. */
1318 /* FAILED(code.func2(3, 11) != 16381, "test16 case 1 failed\n"); */
1320 sljit_free_code(code.code);
1321 successful_tests++;
1324 static void test17(void)
1326 /* Test arm constant pool. */
1327 executable_code code;
1328 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1329 sljit_s32 i;
1330 sljit_sw buf[5];
1332 if (verbose)
1333 printf("Run test17\n");
1335 FAILED(!compiler, "cannot create compiler\n");
1336 buf[0] = 0;
1337 buf[1] = 0;
1338 buf[2] = 0;
1339 buf[3] = 0;
1340 buf[4] = 0;
1342 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 0, 0, 0);
1343 for (i = 0; i <= 0xfff; i++) {
1344 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x81818000 | i);
1345 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x81818000 | i);
1346 if ((i & 0x3ff) == 0)
1347 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), (i >> 10) * sizeof(sljit_sw), SLJIT_R0, 0);
1349 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
1350 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1352 code.code = sljit_generate_code(compiler);
1353 CHECK(compiler);
1354 sljit_free_compiler(compiler);
1356 code.func1((sljit_sw)&buf);
1357 FAILED((sljit_uw)buf[0] != 0x81818000, "test17 case 1 failed\n");
1358 FAILED((sljit_uw)buf[1] != 0x81818400, "test17 case 2 failed\n");
1359 FAILED((sljit_uw)buf[2] != 0x81818800, "test17 case 3 failed\n");
1360 FAILED((sljit_uw)buf[3] != 0x81818c00, "test17 case 4 failed\n");
1361 FAILED((sljit_uw)buf[4] != 0x81818fff, "test17 case 5 failed\n");
1363 sljit_free_code(code.code);
1364 successful_tests++;
1367 static void test18(void)
1369 /* Test 64 bit. */
1370 executable_code code;
1371 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1372 sljit_sw buf[11];
1374 if (verbose)
1375 printf("Run test18\n");
1377 FAILED(!compiler, "cannot create compiler\n");
1378 buf[0] = 0;
1379 buf[1] = 0;
1380 buf[2] = 0;
1381 buf[3] = 0;
1382 buf[4] = 0;
1383 buf[5] = 100;
1384 buf[6] = 100;
1385 buf[7] = 100;
1386 buf[8] = 100;
1387 buf[9] = 0;
1388 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) && (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
1389 buf[10] = SLJIT_W(1) << 32;
1390 #else
1391 buf[10] = 1;
1392 #endif
1394 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 2, 0, 0, 0);
1396 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1397 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, SLJIT_W(0x1122334455667788));
1398 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x1122334455667788));
1400 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(1000000000000));
1401 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(1000000000000));
1402 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_IMM, SLJIT_W(5000000000000), SLJIT_R0, 0);
1404 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x1108080808));
1405 sljit_emit_op2(compiler, SLJIT_ADD32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x1120202020));
1407 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1108080808));
1408 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1120202020));
1409 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_ZERO);
1410 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_S1, 0);
1411 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
1412 sljit_emit_op2(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1120202020));
1413 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_ZERO32);
1415 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1108080808));
1416 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x2208080808));
1417 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_LESS);
1418 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
1419 sljit_emit_op2(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1104040404));
1420 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_NOT_ZERO32);
1422 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 4);
1423 sljit_emit_op2(compiler, SLJIT_SHL32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 9, SLJIT_IMM, SLJIT_W(0xffff0000), SLJIT_R0, 0);
1425 sljit_emit_op2(compiler, SLJIT_MUL32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 10, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 10, SLJIT_IMM, -1);
1426 #else
1427 /* 32 bit operations. */
1429 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0x11223344);
1430 sljit_emit_op2(compiler, SLJIT_ADD32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, 0x44332211);
1432 #endif
1434 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1436 code.code = sljit_generate_code(compiler);
1437 CHECK(compiler);
1438 sljit_free_compiler(compiler);
1440 code.func1((sljit_sw)&buf);
1441 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1442 FAILED(buf[0] != SLJIT_W(0x1122334455667788), "test18 case 1 failed\n");
1443 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1444 FAILED(buf[1] != 0x55667788, "test18 case 2 failed\n");
1445 #else
1446 FAILED(buf[1] != SLJIT_W(0x5566778800000000), "test18 case 2 failed\n");
1447 #endif
1448 FAILED(buf[2] != SLJIT_W(2000000000000), "test18 case 3 failed\n");
1449 FAILED(buf[3] != SLJIT_W(4000000000000), "test18 case 4 failed\n");
1450 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1451 FAILED(buf[4] != 0x28282828, "test18 case 5 failed\n");
1452 #else
1453 FAILED(buf[4] != SLJIT_W(0x2828282800000000), "test18 case 5 failed\n");
1454 #endif
1455 FAILED(buf[5] != 0, "test18 case 6 failed\n");
1456 FAILED(buf[6] != 1, "test18 case 7 failed\n");
1457 FAILED(buf[7] != 1, "test18 case 8 failed\n");
1458 FAILED(buf[8] != 0, "test18 case 9 failed\n");
1459 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1460 FAILED(buf[9] != 0xfff00000, "test18 case 10 failed\n");
1461 FAILED(buf[10] != 0xffffffff, "test18 case 11 failed\n");
1462 #else
1463 FAILED(buf[9] != SLJIT_W(0xfff0000000000000), "test18 case 10 failed\n");
1464 FAILED(buf[10] != SLJIT_W(0xffffffff00000000), "test18 case 11 failed\n");
1465 #endif
1466 #else
1467 FAILED(buf[0] != 0x11223344, "test18 case 1 failed\n");
1468 FAILED(buf[1] != 0x44332211, "test18 case 2 failed\n");
1469 #endif
1471 sljit_free_code(code.code);
1472 successful_tests++;
1475 static void test19(void)
1477 /* Test arm partial instruction caching. */
1478 executable_code code;
1479 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1480 sljit_sw buf[10];
1482 if (verbose)
1483 printf("Run test19\n");
1485 FAILED(!compiler, "cannot create compiler\n");
1486 buf[0] = 6;
1487 buf[1] = 4;
1488 buf[2] = 0;
1489 buf[3] = 0;
1490 buf[4] = 0;
1491 buf[5] = 0;
1492 buf[6] = 2;
1493 buf[7] = 0;
1495 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 0, 0, 0);
1496 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw));
1497 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM0(), (sljit_sw)&buf[2], SLJIT_MEM0(), (sljit_sw)&buf[1], SLJIT_MEM0(), (sljit_sw)&buf[0]);
1498 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
1499 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
1500 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_MEM1(SLJIT_R0), (sljit_sw)&buf[0], SLJIT_MEM1(SLJIT_R1), (sljit_sw)&buf[0]);
1501 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_MEM0(), (sljit_sw)&buf[0], SLJIT_IMM, 2);
1502 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_MEM1(SLJIT_R0), (sljit_sw)&buf[0] + 4 * sizeof(sljit_sw));
1503 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_IMM, 10);
1504 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 7);
1505 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_R1), (sljit_sw)&buf[5], SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_MEM1(SLJIT_R1), (sljit_sw)&buf[5]);
1507 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1509 code.code = sljit_generate_code(compiler);
1510 CHECK(compiler);
1511 sljit_free_compiler(compiler);
1513 code.func1((sljit_sw)&buf);
1514 FAILED(buf[0] != 10, "test19 case 1 failed\n");
1515 FAILED(buf[1] != 4, "test19 case 2 failed\n");
1516 FAILED(buf[2] != 14, "test19 case 3 failed\n");
1517 FAILED(buf[3] != 14, "test19 case 4 failed\n");
1518 FAILED(buf[4] != 8, "test19 case 5 failed\n");
1519 FAILED(buf[5] != 6, "test19 case 6 failed\n");
1520 FAILED(buf[6] != 12, "test19 case 7 failed\n");
1521 FAILED(buf[7] != 10, "test19 case 8 failed\n");
1523 sljit_free_code(code.code);
1524 successful_tests++;
1527 static void test20(void)
1529 /* Test stack. */
1530 executable_code code;
1531 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1532 struct sljit_jump* jump;
1533 struct sljit_label* label;
1534 sljit_sw buf[6];
1535 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1536 sljit_sw offset_value = SLJIT_W(0x1234567812345678);
1537 #else
1538 sljit_sw offset_value = SLJIT_W(0x12345678);
1539 #endif
1541 if (verbose)
1542 printf("Run test20\n");
1544 FAILED(!compiler, "cannot create compiler\n");
1545 buf[0] = 5;
1546 buf[1] = 12;
1547 buf[2] = 0;
1548 buf[3] = 0;
1549 buf[4] = 111;
1550 buf[5] = -12345;
1552 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 5, 5, 0, 0, 4 * sizeof(sljit_sw));
1553 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw), SLJIT_MEM1(SLJIT_S0), 0);
1554 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw));
1555 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -1);
1556 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_IMM, -1);
1557 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, -1);
1558 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S4, 0, SLJIT_IMM, -1);
1559 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_uw), SLJIT_MEM1(SLJIT_SP), 0, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw));
1560 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_uw), SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw), SLJIT_MEM1(SLJIT_SP), 0);
1561 sljit_get_local_base(compiler, SLJIT_R0, 0, -offset_value);
1562 sljit_get_local_base(compiler, SLJIT_MEM1(SLJIT_S0), 0, -0x1234);
1563 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), 0);
1564 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_uw), SLJIT_MEM1(SLJIT_R0), offset_value, SLJIT_MEM1(SLJIT_R1), 0x1234 + sizeof(sljit_sw));
1565 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_uw));
1566 /* Dummy last instructions. */
1567 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, 23);
1568 sljit_emit_label(compiler);
1570 code.code = sljit_generate_code(compiler);
1571 CHECK(compiler);
1572 sljit_free_compiler(compiler);
1574 FAILED(code.func1((sljit_sw)&buf) != -12345, "test20 case 1 failed\n")
1576 FAILED(buf[2] != 60, "test20 case 2 failed\n");
1577 FAILED(buf[3] != 17, "test20 case 3 failed\n");
1578 FAILED(buf[4] != 7, "test20 case 4 failed\n");
1580 sljit_free_code(code.code);
1582 compiler = sljit_create_compiler(NULL);
1583 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), 3, 3, 0, 0, SLJIT_MAX_LOCAL_SIZE);
1585 sljit_get_local_base(compiler, SLJIT_R0, 0, SLJIT_MAX_LOCAL_SIZE - sizeof(sljit_sw));
1586 sljit_get_local_base(compiler, SLJIT_R1, 0, -(sljit_sw)sizeof(sljit_sw));
1587 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -1);
1588 label = sljit_emit_label(compiler);
1589 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
1590 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 0, SLJIT_R2, 0);
1591 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R1, 0, SLJIT_R0, 0);
1592 jump = sljit_emit_jump(compiler, SLJIT_NOT_EQUAL);
1593 sljit_set_label(jump, label);
1595 /* Saved registers should keep their value. */
1596 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_S1, 0);
1597 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_S2, 0);
1598 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
1600 code.code = sljit_generate_code(compiler);
1601 CHECK(compiler);
1602 sljit_free_compiler(compiler);
1604 FAILED(code.func3(1234, 5678, 9012) != 15924, "test20 case 5 failed\n");
1606 sljit_free_code(code.code);
1608 compiler = sljit_create_compiler(NULL);
1609 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, 0, 3, 0, 0, 0, SLJIT_MAX_LOCAL_SIZE);
1611 sljit_get_local_base(compiler, SLJIT_R0, 0, SLJIT_MAX_LOCAL_SIZE - sizeof(sljit_sw));
1612 sljit_get_local_base(compiler, SLJIT_R1, 0, -(sljit_sw)sizeof(sljit_sw));
1613 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -1);
1614 label = sljit_emit_label(compiler);
1615 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
1616 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 0, SLJIT_R2, 0);
1617 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R1, 0, SLJIT_R0, 0);
1618 jump = sljit_emit_jump(compiler, SLJIT_NOT_EQUAL);
1619 sljit_set_label(jump, label);
1621 sljit_get_local_base(compiler, SLJIT_R0, 0, 0);
1622 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
1624 code.code = sljit_generate_code(compiler);
1625 CHECK(compiler);
1626 sljit_free_compiler(compiler);
1628 FAILED(code.func0() % sizeof(sljit_f64) != 0, "test20 case 6 failed\n");
1630 sljit_free_code(code.code);
1631 successful_tests++;
1634 static void test21(void)
1636 /* Test set context. The parts of the jit code can be separated in the memory. */
1637 executable_code code1;
1638 executable_code code2;
1639 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1640 struct sljit_jump* jump = NULL;
1641 sljit_uw addr;
1642 sljit_sw executable_offset;
1643 sljit_sw buf[4];
1645 if (verbose)
1646 printf("Run test21\n");
1648 FAILED(!compiler, "cannot create compiler\n");
1649 buf[0] = 9;
1650 buf[1] = -6;
1651 buf[2] = 0;
1652 buf[3] = 0;
1654 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 2, 0, 0, 2 * sizeof(sljit_sw));
1656 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, 10);
1657 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_SP), 0);
1659 jump = sljit_emit_jump(compiler, SLJIT_JUMP | SLJIT_REWRITABLE_JUMP);
1660 sljit_set_target(jump, 0);
1662 code1.code = sljit_generate_code(compiler);
1663 CHECK(compiler);
1665 executable_offset = sljit_get_executable_offset(compiler);
1666 addr = sljit_get_jump_addr(jump);
1668 sljit_free_compiler(compiler);
1670 compiler = sljit_create_compiler(NULL);
1671 FAILED(!compiler, "cannot create compiler\n");
1673 /* Other part of the jit code. */
1674 sljit_set_context(compiler, 0, 1, 3, 2, 0, 0, 2 * sizeof(sljit_sw));
1676 sljit_emit_op0(compiler, SLJIT_ENDBR);
1677 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SP), 0);
1678 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_MEM1(SLJIT_SP), 0);
1679 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_sw));
1681 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1683 code2.code = sljit_generate_code(compiler);
1684 CHECK(compiler);
1685 sljit_free_compiler(compiler);
1687 sljit_set_jump_addr(addr, SLJIT_FUNC_OFFSET(code2.code), executable_offset);
1689 FAILED(code1.func1((sljit_sw)&buf) != 19, "test21 case 1 failed\n");
1690 FAILED(buf[2] != -16, "test21 case 2 failed\n");
1691 FAILED(buf[3] != 100, "test21 case 3 failed\n");
1693 sljit_free_code(code1.code);
1694 sljit_free_code(code2.code);
1695 successful_tests++;
1698 static void test22(void)
1700 /* Test simple byte and half-int data transfers. */
1701 executable_code code;
1702 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1703 sljit_sw buf[2];
1704 sljit_s16 sbuf[9];
1705 sljit_s8 bbuf[5];
1707 if (verbose)
1708 printf("Run test22\n");
1710 FAILED(!compiler, "cannot create compiler\n");
1711 buf[0] = 0;
1712 buf[1] = 0;
1714 sbuf[0] = 0;
1715 sbuf[1] = 0;
1716 sbuf[2] = -9;
1717 sbuf[3] = 0;
1718 sbuf[4] = 0;
1719 sbuf[5] = 0;
1720 sbuf[6] = 0;
1722 bbuf[0] = 0;
1723 bbuf[1] = 0;
1724 bbuf[2] = -56;
1725 bbuf[3] = 0;
1726 bbuf[4] = 0;
1728 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), 3, 3, 0, 0, 0);
1730 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, -13);
1731 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s16), SLJIT_IMM, 0x1234);
1732 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_s16));
1733 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
1734 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_IMM, 2 * sizeof(sljit_s16));
1735 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s16), SLJIT_MEM1(SLJIT_S1), -(sljit_sw)sizeof(sljit_s16));
1736 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xff0000 + 8000);
1737 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 2);
1738 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM2(SLJIT_S1, SLJIT_R1), 1, SLJIT_R0, 0);
1739 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R2, 0, SLJIT_S1, 0, SLJIT_IMM, 0x1234 - 3 * sizeof(sljit_s16));
1740 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_R2), 0x1234, SLJIT_IMM, -9317);
1741 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S1, 0, SLJIT_IMM, 0x1234 + 4 * sizeof(sljit_s16));
1742 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_R2), -0x1234, SLJIT_IMM, -9317);
1743 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R2, 0, SLJIT_S1, 0, SLJIT_IMM, 0x12348 - 5 * sizeof(sljit_s16));
1744 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_R2), 0x12348, SLJIT_IMM, -8888);
1745 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S1, 0, SLJIT_IMM, 0x12348 + 6 * sizeof(sljit_s16));
1746 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_R2), -0x12348, SLJIT_IMM, -8888);
1748 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_MEM1(SLJIT_S2), 0, SLJIT_IMM, -45);
1749 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_s8), SLJIT_IMM, 0x12);
1750 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4 * sizeof(sljit_s8));
1751 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_s8));
1752 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_S1, 0, SLJIT_R1, 0);
1753 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_S1, 0, SLJIT_S1, 0);
1754 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R2, 0, SLJIT_S1, 0);
1755 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R2, 0);
1756 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S2), 3 * sizeof(sljit_s8), SLJIT_S1, 0);
1757 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM2(SLJIT_S2, SLJIT_R0), 0, SLJIT_R0, 0);
1759 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1761 code.code = sljit_generate_code(compiler);
1762 CHECK(compiler);
1763 sljit_free_compiler(compiler);
1765 code.func3((sljit_sw)&buf, (sljit_sw)&sbuf, (sljit_sw)&bbuf);
1766 FAILED(buf[0] != -9, "test22 case 1 failed\n");
1767 FAILED(buf[1] != -56, "test22 case 2 failed\n");
1769 FAILED(sbuf[0] != -13, "test22 case 3 failed\n");
1770 FAILED(sbuf[1] != 0x1234, "test22 case 4 failed\n");
1771 FAILED(sbuf[3] != 0x1234, "test22 case 5 failed\n");
1772 FAILED(sbuf[4] != 8000, "test22 case 6 failed\n");
1773 FAILED(sbuf[5] != -9317, "test22 case 7 failed\n");
1774 FAILED(sbuf[6] != -9317, "test22 case 8 failed\n");
1775 FAILED(sbuf[7] != -8888, "test22 case 9 failed\n");
1776 FAILED(sbuf[8] != -8888, "test22 case 10 failed\n");
1778 FAILED(bbuf[0] != -45, "test22 case 11 failed\n");
1779 FAILED(bbuf[1] != 0x12, "test22 case 12 failed\n");
1780 FAILED(bbuf[3] != -56, "test22 case 13 failed\n");
1781 FAILED(bbuf[4] != 4, "test22 case 14 failed\n");
1783 sljit_free_code(code.code);
1784 successful_tests++;
1787 static void test23(void)
1789 /* Test 32 bit / 64 bit signed / unsigned int transfer and conversion.
1790 This test has do real things on 64 bit systems, but works on 32 bit systems as well. */
1791 executable_code code;
1792 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1793 sljit_sw buf[9];
1794 sljit_s32 ibuf[5];
1795 union {
1796 sljit_s32 asint;
1797 sljit_u8 asbytes[4];
1798 } u;
1799 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1800 sljit_sw garbage = SLJIT_W(0x1234567812345678);
1801 #else
1802 sljit_sw garbage = 0x12345678;
1803 #endif
1805 if (verbose)
1806 printf("Run test23\n");
1808 FAILED(!compiler, "cannot create compiler\n");
1809 buf[0] = 0;
1810 buf[1] = 0;
1811 buf[2] = 0;
1812 buf[3] = 0;
1813 buf[4] = 0;
1814 buf[5] = 0;
1815 buf[6] = 0;
1816 buf[7] = 0;
1817 buf[8] = 0;
1819 ibuf[0] = 0;
1820 ibuf[1] = 0;
1821 ibuf[2] = -5791;
1822 ibuf[3] = 43579;
1823 ibuf[4] = 658923;
1825 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 3, 3, 0, 0, 0);
1826 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, 34567);
1827 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4);
1828 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), 0, SLJIT_IMM, -7654);
1829 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, garbage);
1830 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_s32));
1831 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
1832 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, garbage);
1833 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_s32));
1834 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
1835 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, garbage);
1836 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_s32));
1837 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
1838 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
1839 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x0f00f00);
1840 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 0x7777);
1841 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 0x7777 + 3 * sizeof(sljit_sw), SLJIT_R0, 0);
1842 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 0x7777);
1843 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), -0x7777 + 4 * (sljit_sw)sizeof(sljit_sw), SLJIT_R0, 0);
1844 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 5 * sizeof(sljit_sw));
1845 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 1);
1846 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_R1, SLJIT_R1), 0, SLJIT_IMM, 16);
1847 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
1848 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), 1, SLJIT_IMM, 64, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), 1);
1849 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM0(), (sljit_sw)&buf[7], SLJIT_IMM, 0x123456);
1850 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), (sljit_sw)&buf[6], SLJIT_MEM0(), (sljit_sw)&buf[7]);
1851 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 5 * sizeof(sljit_sw));
1852 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 2 * sizeof(sljit_sw), SLJIT_R1, 0);
1853 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S0, 0, SLJIT_IMM, 7 * sizeof(sljit_sw));
1854 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, 1);
1855 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM2(SLJIT_R2, SLJIT_R2), 0);
1856 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[8] - 0x12340);
1857 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0x12340, SLJIT_R2, 0);
1858 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_R0), 0x12340, SLJIT_MEM1(SLJIT_R2), 3 * sizeof(sljit_sw), SLJIT_IMM, 6);
1859 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_s32), SLJIT_IMM, 0x12345678);
1860 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x2bd700 | 243);
1861 sljit_emit_return(compiler, SLJIT_MOV_S8, SLJIT_R1, 0);
1863 code.code = sljit_generate_code(compiler);
1864 CHECK(compiler);
1865 sljit_free_compiler(compiler);
1867 FAILED(code.func2((sljit_sw)&buf, (sljit_sw)&ibuf) != -13, "test23 case 1 failed\n");
1868 FAILED(buf[0] != -5791, "test23 case 2 failed\n");
1869 FAILED(buf[1] != 43579, "test23 case 3 failed\n");
1870 FAILED(buf[2] != 658923, "test23 case 4 failed\n");
1871 FAILED(buf[3] != 0x0f00f00, "test23 case 5 failed\n");
1872 FAILED(buf[4] != 0x0f00f00, "test23 case 6 failed\n");
1873 FAILED(buf[5] != 80, "test23 case 7 failed\n");
1874 FAILED(buf[6] != 0x123456, "test23 case 8 failed\n");
1875 FAILED(buf[7] != (sljit_sw)&buf[5], "test23 case 9 failed\n");
1876 FAILED(buf[8] != (sljit_sw)&buf[5] + 6, "test23 case 10 failed\n");
1878 FAILED(ibuf[0] != 34567, "test23 case 11 failed\n");
1879 FAILED(ibuf[1] != -7654, "test23 case 12 failed\n");
1880 u.asint = ibuf[4];
1881 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1882 FAILED(u.asbytes[0] != 0x78, "test23 case 13 failed\n");
1883 FAILED(u.asbytes[1] != 0x56, "test23 case 14 failed\n");
1884 FAILED(u.asbytes[2] != 0x34, "test23 case 15 failed\n");
1885 FAILED(u.asbytes[3] != 0x12, "test23 case 16 failed\n");
1886 #else
1887 FAILED(u.asbytes[0] != 0x12, "test23 case 13 failed\n");
1888 FAILED(u.asbytes[1] != 0x34, "test23 case 14 failed\n");
1889 FAILED(u.asbytes[2] != 0x56, "test23 case 15 failed\n");
1890 FAILED(u.asbytes[3] != 0x78, "test23 case 16 failed\n");
1891 #endif
1893 sljit_free_code(code.code);
1894 successful_tests++;
1897 static void test24(void)
1899 /* Some complicated addressing modes. */
1900 executable_code code;
1901 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1902 sljit_sw buf[9];
1903 sljit_s16 sbuf[5];
1904 sljit_s8 bbuf[7];
1906 if (verbose)
1907 printf("Run test24\n");
1909 FAILED(!compiler, "cannot create compiler\n");
1911 buf[0] = 100567;
1912 buf[1] = 75799;
1913 buf[2] = 0;
1914 buf[3] = -8;
1915 buf[4] = -50;
1916 buf[5] = 0;
1917 buf[6] = 0;
1918 buf[7] = 0;
1919 buf[8] = 0;
1921 sbuf[0] = 30000;
1922 sbuf[1] = 0;
1923 sbuf[2] = 0;
1924 sbuf[3] = -12345;
1925 sbuf[4] = 0;
1927 bbuf[0] = -128;
1928 bbuf[1] = 0;
1929 bbuf[2] = 0;
1930 bbuf[3] = 99;
1931 bbuf[4] = 0;
1932 bbuf[5] = 0;
1933 bbuf[6] = 0;
1935 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), 3, 3, 0, 0, 0);
1937 /* Nothing should be updated. */
1938 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM0(), (sljit_sw)&sbuf[1], SLJIT_MEM0(), (sljit_sw)&sbuf[0]);
1939 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_MEM0(), (sljit_sw)&bbuf[1], SLJIT_MEM0(), (sljit_sw)&bbuf[0]);
1940 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
1941 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), 1, SLJIT_MEM0(), (sljit_sw)&sbuf[3]);
1942 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[0]);
1943 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
1944 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 2);
1945 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM2(SLJIT_R0, SLJIT_R2), SLJIT_WORD_SHIFT, SLJIT_MEM0(), (sljit_sw)&buf[0], SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 0);
1946 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_s8));
1947 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_R0), (sljit_sw)&bbuf[1], SLJIT_MEM1(SLJIT_R0), (sljit_sw)&bbuf[2]);
1949 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_s16));
1950 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_R1), (sljit_sw)&sbuf[3], SLJIT_R1, 0);
1952 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 3);
1953 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_WORD_SHIFT);
1954 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4);
1955 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_S0, 0);
1956 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_WORD_SHIFT);
1958 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 9 * sizeof(sljit_sw));
1959 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 4 * sizeof(sljit_sw));
1960 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -4 << SLJIT_WORD_SHIFT);
1961 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_R0, SLJIT_R2), 0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
1963 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf - 0x7fff8000 + 6 * sizeof(sljit_sw));
1964 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 952467);
1965 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0x7fff8000, SLJIT_R1, 0);
1966 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0x7fff8000 + sizeof(sljit_sw), SLJIT_MEM1(SLJIT_R0), 0x7fff8000);
1968 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf + 0x7fff7fff + 6 * sizeof(sljit_sw));
1969 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_R0), -0x7fff7fff + 2 * (sljit_sw)sizeof(sljit_sw), SLJIT_MEM1(SLJIT_R0), -0x7fff7fff + (sljit_sw)sizeof(sljit_sw), SLJIT_MEM1(SLJIT_R0), -0x7fff7fff);
1970 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&bbuf - 0x7fff7ffe + 3 * sizeof(sljit_s8));
1971 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_MEM1(SLJIT_R0), 0x7fff7fff, SLJIT_MEM1(SLJIT_R0), 0x7fff7ffe);
1972 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&bbuf + 0x7fff7fff + 5 * sizeof(sljit_s8));
1973 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_MEM1(SLJIT_R0), -0x7fff7fff, SLJIT_MEM1(SLJIT_R0), -0x7fff8000);
1974 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1975 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&bbuf - SLJIT_W(0x123456123456));
1976 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&bbuf - SLJIT_W(0x123456123456));
1977 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_MEM1(SLJIT_R0), SLJIT_W(0x123456123456) + 6 * sizeof(sljit_s8), SLJIT_MEM1(SLJIT_R1), SLJIT_W(0x123456123456));
1978 #endif
1980 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1982 code.code = sljit_generate_code(compiler);
1983 CHECK(compiler);
1984 sljit_free_compiler(compiler);
1986 code.func3((sljit_sw)&buf, (sljit_sw)&sbuf, (sljit_sw)&bbuf);
1987 FAILED(buf[2] != 176366, "test24 case 1 failed\n");
1988 FAILED(buf[3] != 64, "test24 case 2 failed\n");
1989 FAILED(buf[4] != -100, "test24 case 3 failed\n");
1990 FAILED(buf[5] != 100567, "test24 case 4 failed\n");
1991 FAILED(buf[6] != 952467, "test24 case 5 failed\n");
1992 FAILED(buf[7] != 952467, "test24 case 6 failed\n");
1993 FAILED(buf[8] != 952467 * 2, "test24 case 7 failed\n");
1995 FAILED(sbuf[1] != 30000, "test24 case 8 failed\n");
1996 FAILED(sbuf[2] != -12345, "test24 case 9 failed\n");
1997 FAILED(sbuf[4] != sizeof(sljit_s16), "test24 case 10 failed\n");
1999 FAILED(bbuf[1] != -128, "test24 case 11 failed\n");
2000 FAILED(bbuf[2] != 99, "test24 case 12 failed\n");
2001 FAILED(bbuf[4] != 99, "test24 case 13 failed\n");
2002 FAILED(bbuf[5] != 99, "test24 case 14 failed\n");
2003 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2004 FAILED(bbuf[6] != -128, "test24 case 15 failed\n");
2005 #endif
2007 sljit_free_code(code.code);
2008 successful_tests++;
2011 static void test25(void)
2013 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2014 /* 64 bit loads. */
2015 executable_code code;
2016 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2017 sljit_sw buf[14];
2019 if (verbose)
2020 printf("Run test25\n");
2022 FAILED(!compiler, "cannot create compiler\n");
2023 buf[0] = 7;
2024 buf[1] = 0;
2025 buf[2] = 0;
2026 buf[3] = 0;
2027 buf[4] = 0;
2028 buf[5] = 0;
2029 buf[6] = 0;
2030 buf[7] = 0;
2031 buf[8] = 0;
2032 buf[9] = 0;
2033 buf[10] = 0;
2034 buf[11] = 0;
2035 buf[12] = 0;
2036 buf[13] = 0;
2038 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 0, 0, 0);
2040 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0);
2041 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 1 * sizeof(sljit_sw), SLJIT_IMM, 0x7fff);
2042 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_IMM, -0x8000);
2043 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_IMM, 0x7fffffff);
2044 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(-0x80000000));
2045 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x1234567887654321));
2046 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0xff80000000));
2047 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x3ff0000000));
2048 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0xfffffff800100000));
2049 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0xfffffff80010f000));
2050 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00000008001));
2051 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00080010000));
2052 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00080018001));
2053 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00ffff00000));
2055 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2057 code.code = sljit_generate_code(compiler);
2058 CHECK(compiler);
2059 sljit_free_compiler(compiler);
2061 code.func1((sljit_sw)&buf);
2062 FAILED(buf[0] != 0, "test25 case 1 failed\n");
2063 FAILED(buf[1] != 0x7fff, "test25 case 2 failed\n");
2064 FAILED(buf[2] != -0x8000, "test25 case 3 failed\n");
2065 FAILED(buf[3] != 0x7fffffff, "test25 case 4 failed\n");
2066 FAILED(buf[4] != SLJIT_W(-0x80000000), "test25 case 5 failed\n");
2067 FAILED(buf[5] != SLJIT_W(0x1234567887654321), "test25 case 6 failed\n");
2068 FAILED(buf[6] != SLJIT_W(0xff80000000), "test25 case 7 failed\n");
2069 FAILED(buf[7] != SLJIT_W(0x3ff0000000), "test25 case 8 failed\n");
2070 FAILED((sljit_uw)buf[8] != SLJIT_W(0xfffffff800100000), "test25 case 9 failed\n");
2071 FAILED((sljit_uw)buf[9] != SLJIT_W(0xfffffff80010f000), "test25 case 10 failed\n");
2072 FAILED(buf[10] != SLJIT_W(0x07fff00000008001), "test25 case 11 failed\n");
2073 FAILED(buf[11] != SLJIT_W(0x07fff00080010000), "test25 case 12 failed\n");
2074 FAILED(buf[12] != SLJIT_W(0x07fff00080018001), "test25 case 13 failed\n");
2075 FAILED(buf[13] != SLJIT_W(0x07fff00ffff00000), "test25 case 14 failed\n");
2077 sljit_free_code(code.code);
2078 #endif
2079 successful_tests++;
2082 static void test26(void)
2084 /* Aligned access without aligned offsets. */
2085 executable_code code;
2086 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2087 sljit_sw buf[4];
2088 sljit_s32 ibuf[4];
2089 sljit_f64 dbuf[4];
2091 if (verbose)
2092 printf("Run test26\n");
2094 FAILED(!compiler, "cannot create compiler\n");
2096 buf[0] = -2789;
2097 buf[1] = 0;
2098 buf[2] = 4;
2099 buf[3] = -4;
2101 ibuf[0] = -689;
2102 ibuf[1] = 0;
2103 ibuf[2] = -6;
2104 ibuf[3] = 3;
2106 dbuf[0] = 5.75;
2107 dbuf[1] = 0.0;
2108 dbuf[2] = 0.0;
2109 dbuf[3] = -4.0;
2111 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), 3, 3, 0, 0, 0);
2113 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 3);
2114 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_IMM, 1);
2115 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), -3);
2116 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32) - 1, SLJIT_R0, 0);
2117 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), -1);
2118 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) - 3, SLJIT_R0, 0);
2120 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 100);
2121 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_sw) * 2 - 103, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2 - 3, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3 - 3);
2122 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_IMM, 100);
2123 sljit_emit_op2(compiler, SLJIT_MUL32, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_s32) * 2 - 101, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32) * 2 - 1, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32) * 3 - 1);
2125 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
2126 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S2, 0, SLJIT_S2, 0, SLJIT_IMM, 3);
2127 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f64) - 3, SLJIT_MEM1(SLJIT_S2), -3);
2128 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f64) * 2 - 3, SLJIT_MEM1(SLJIT_S2), -3, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f64) - 3);
2129 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S2, 0, SLJIT_IMM, 2);
2130 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sizeof(sljit_f64) * 3 - 4) >> 1);
2131 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, 1);
2132 sljit_emit_fop2(compiler, SLJIT_DIV_F64, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_f64) * 3 - 5, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f64) * 2 - 3, SLJIT_MEM2(SLJIT_R2, SLJIT_R1), 1);
2135 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2137 code.code = sljit_generate_code(compiler);
2138 CHECK(compiler);
2139 sljit_free_compiler(compiler);
2141 code.func3((sljit_sw)&buf, (sljit_sw)&ibuf, (sljit_sw)&dbuf);
2143 FAILED(buf[1] != -689, "test26 case 1 failed\n");
2144 FAILED(buf[2] != -16, "test26 case 2 failed\n");
2145 FAILED(ibuf[1] != -2789, "test26 case 3 failed\n");
2146 FAILED(ibuf[2] != -18, "test26 case 4 failed\n");
2148 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
2149 FAILED(dbuf[1] != 5.75, "test26 case 5 failed\n");
2150 FAILED(dbuf[2] != 11.5, "test26 case 6 failed\n");
2151 FAILED(dbuf[3] != -2.875, "test26 case 7 failed\n");
2154 sljit_free_code(code.code);
2155 successful_tests++;
2158 static void test27(void)
2160 #define SET_NEXT_BYTE(type) \
2161 cond_set(compiler, SLJIT_R2, 0, type); \
2162 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R2, 0); \
2163 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
2164 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2165 #define RESULT(i) i
2166 #else
2167 #define RESULT(i) (3 - i)
2168 #endif
2170 /* Playing with conditional flags. */
2171 executable_code code;
2172 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2173 sljit_u8 buf[37];
2174 sljit_s32 i;
2175 #ifdef SLJIT_PREF_SHIFT_REG
2176 sljit_s32 shift_reg = SLJIT_PREF_SHIFT_REG;
2177 #else
2178 sljit_s32 shift_reg = SLJIT_R2;
2179 #endif
2181 SLJIT_ASSERT(shift_reg >= SLJIT_R2 && shift_reg <= SLJIT_R3);
2183 if (verbose)
2184 printf("Run test27\n");
2186 for (i = 0; i < 37; ++i)
2187 buf[i] = 10;
2189 FAILED(!compiler, "cannot create compiler\n");
2191 /* 3 arguments passed, 3 arguments used. */
2192 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 4, 3, 0, 0, 0);
2194 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
2196 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x1001);
2197 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 20);
2198 /* 0x100100000 on 64 bit machines, 0x100000 on 32 bit machines. */
2199 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x800000);
2200 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2201 sljit_emit_op0(compiler, SLJIT_ENDBR); /* ENDBR should keep the flags. */
2202 sljit_emit_op0(compiler, SLJIT_NOP); /* Nop should keep the flags. */
2203 SET_NEXT_BYTE(SLJIT_GREATER);
2204 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2205 SET_NEXT_BYTE(SLJIT_LESS);
2206 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
2207 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_R1, 0);
2208 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2209 sljit_emit_op0(compiler, SLJIT_ENDBR); /* ENDBR should keep the flags. */
2210 sljit_emit_op0(compiler, SLJIT_NOP); /* Nop should keep the flags. */
2211 SET_NEXT_BYTE(SLJIT_GREATER32);
2212 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2213 SET_NEXT_BYTE(SLJIT_LESS32);
2215 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x1000);
2216 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 20);
2217 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0x10);
2218 /* 0x100000010 on 64 bit machines, 0x10 on 32 bit machines. */
2219 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0x80);
2220 SET_NEXT_BYTE(SLJIT_GREATER);
2221 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0x80);
2222 SET_NEXT_BYTE(SLJIT_LESS);
2223 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
2224 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0x80);
2225 SET_NEXT_BYTE(SLJIT_GREATER32);
2226 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0x80);
2227 SET_NEXT_BYTE(SLJIT_LESS32);
2229 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2230 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2231 /* 0xff..ff on all machines. */
2232 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS_EQUAL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2233 SET_NEXT_BYTE(SLJIT_LESS_EQUAL);
2234 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2235 SET_NEXT_BYTE(SLJIT_GREATER_EQUAL);
2236 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_R2, 0, SLJIT_R1, 0, SLJIT_IMM, -1);
2237 SET_NEXT_BYTE(SLJIT_SIG_GREATER);
2238 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, -1);
2239 SET_NEXT_BYTE(SLJIT_SIG_LESS);
2240 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R2, 0, SLJIT_R1, 0, SLJIT_R0, 0);
2241 SET_NEXT_BYTE(SLJIT_EQUAL);
2242 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_R0, 0);
2243 SET_NEXT_BYTE(SLJIT_NOT_EQUAL);
2244 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, -2);
2245 SET_NEXT_BYTE(SLJIT_OVERFLOW);
2246 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, -2);
2247 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW);
2248 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, -2);
2249 SET_NEXT_BYTE(SLJIT_GREATER_EQUAL);
2250 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, -2);
2251 SET_NEXT_BYTE(SLJIT_LESS_EQUAL);
2253 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x80000000);
2254 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 16);
2255 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 16);
2256 /* 0x80..0 on 64 bit machines, 0 on 32 bit machines. */
2257 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0xffffffff);
2258 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2259 SET_NEXT_BYTE(SLJIT_OVERFLOW);
2260 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2261 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW);
2262 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
2263 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R1, 0, SLJIT_R1, 0);
2264 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2265 SET_NEXT_BYTE(SLJIT_OVERFLOW32);
2266 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2267 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW32);
2269 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2270 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_CARRY, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2271 sljit_emit_op2(compiler, SLJIT_SUBC | SLJIT_SET_CARRY, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0);
2272 sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_R0, 0, SLJIT_IMM, 6, SLJIT_R0, 0);
2273 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R0, 0);
2274 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
2276 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
2277 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_CARRY, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2278 sljit_emit_op2(compiler, SLJIT_ADDC | SLJIT_SET_CARRY, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2279 sljit_emit_op2(compiler, SLJIT_ADDC, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 9);
2280 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R0, 0);
2281 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
2283 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
2284 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, (8 * sizeof(sljit_sw)) - 1);
2285 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0);
2286 SET_NEXT_BYTE(SLJIT_EQUAL);
2287 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R0, 0);
2288 SET_NEXT_BYTE(SLJIT_EQUAL);
2290 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2291 sljit_emit_op2(compiler, SLJIT_ASHR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0);
2292 SET_NEXT_BYTE(SLJIT_EQUAL);
2293 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
2294 sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffffc0);
2295 SET_NEXT_BYTE(SLJIT_NOT_EQUAL);
2296 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 0);
2297 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2298 sljit_emit_op2(compiler, SLJIT_ASHR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0, shift_reg, 0);
2299 SET_NEXT_BYTE(SLJIT_EQUAL);
2300 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 0);
2301 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
2302 sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0, shift_reg, 0);
2303 SET_NEXT_BYTE(SLJIT_NOT_EQUAL);
2305 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2306 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
2307 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_CARRY, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R0, 0);
2308 sljit_emit_op2(compiler, SLJIT_SUBC | SLJIT_SET_CARRY, SLJIT_R2, 0, SLJIT_IMM, 1, SLJIT_R0, 0);
2309 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R2, 0);
2310 sljit_emit_op2(compiler, SLJIT_SUBC | SLJIT_SET_CARRY, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2311 sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_R2, 0, SLJIT_IMM, 1, SLJIT_R0, 0);
2312 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 2, SLJIT_R2, 0);
2313 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 2);
2315 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -34);
2316 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0x1234);
2317 SET_NEXT_BYTE(SLJIT_LESS);
2318 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0x1234);
2319 SET_NEXT_BYTE(SLJIT_SIG_LESS);
2320 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2321 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x12300000000) - 43);
2322 #else
2323 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, -43);
2324 #endif
2325 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -96);
2326 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2327 SET_NEXT_BYTE(SLJIT_LESS32);
2328 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_SIG_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2329 SET_NEXT_BYTE(SLJIT_SIG_GREATER32);
2331 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2333 code.code = sljit_generate_code(compiler);
2334 CHECK(compiler);
2335 sljit_free_compiler(compiler);
2337 code.func1((sljit_sw)&buf);
2339 FAILED(buf[0] != RESULT(1), "test27 case 1 failed\n");
2340 FAILED(buf[1] != RESULT(2), "test27 case 2 failed\n");
2341 FAILED(buf[2] != 2, "test27 case 3 failed\n");
2342 FAILED(buf[3] != 1, "test27 case 4 failed\n");
2343 FAILED(buf[4] != RESULT(1), "test27 case 5 failed\n");
2344 FAILED(buf[5] != RESULT(2), "test27 case 6 failed\n");
2345 FAILED(buf[6] != 2, "test27 case 7 failed\n");
2346 FAILED(buf[7] != 1, "test27 case 8 failed\n");
2348 FAILED(buf[8] != 2, "test27 case 9 failed\n");
2349 FAILED(buf[9] != 1, "test27 case 10 failed\n");
2350 FAILED(buf[10] != 2, "test27 case 11 failed\n");
2351 FAILED(buf[11] != 1, "test27 case 12 failed\n");
2352 FAILED(buf[12] != 1, "test27 case 13 failed\n");
2353 FAILED(buf[13] != 2, "test27 case 14 failed\n");
2354 FAILED(buf[14] != 2, "test27 case 15 failed\n");
2355 FAILED(buf[15] != 1, "test27 case 16 failed\n");
2356 FAILED(buf[16] != 1, "test27 case 17 failed\n");
2357 FAILED(buf[17] != 2, "test27 case 18 failed\n");
2359 FAILED(buf[18] != RESULT(1), "test27 case 19 failed\n");
2360 FAILED(buf[19] != RESULT(2), "test27 case 20 failed\n");
2361 FAILED(buf[20] != 2, "test27 case 21 failed\n");
2362 FAILED(buf[21] != 1, "test27 case 22 failed\n");
2364 FAILED(buf[22] != 5, "test27 case 23 failed\n");
2365 FAILED(buf[23] != 9, "test27 case 24 failed\n");
2367 FAILED(buf[24] != 2, "test27 case 25 failed\n");
2368 FAILED(buf[25] != 1, "test27 case 26 failed\n");
2370 FAILED(buf[26] != 1, "test27 case 27 failed\n");
2371 FAILED(buf[27] != 1, "test27 case 28 failed\n");
2372 FAILED(buf[28] != 1, "test27 case 29 failed\n");
2373 FAILED(buf[29] != 1, "test27 case 30 failed\n");
2375 FAILED(buf[30] != 1, "test27 case 31 failed\n");
2376 FAILED(buf[31] != 0, "test27 case 32 failed\n");
2378 FAILED(buf[32] != 2, "test27 case 33 failed\n");
2379 FAILED(buf[33] != 1, "test27 case 34 failed\n");
2380 FAILED(buf[34] != 2, "test27 case 35 failed\n");
2381 FAILED(buf[35] != 1, "test27 case 36 failed\n");
2382 FAILED(buf[36] != 10, "test27 case 37 failed\n");
2384 sljit_free_code(code.code);
2385 successful_tests++;
2386 #undef SET_NEXT_BYTE
2387 #undef RESULT
2390 static void test28(void)
2392 /* Test mov. */
2393 executable_code code;
2394 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2395 struct sljit_const* const1 = NULL;
2396 struct sljit_label* label = NULL;
2397 sljit_uw label_addr = 0;
2398 sljit_sw buf[5];
2400 if (verbose)
2401 printf("Run test28\n");
2403 FAILED(!compiler, "cannot create compiler\n");
2405 buf[0] = -36;
2406 buf[1] = 8;
2407 buf[2] = 0;
2408 buf[3] = 10;
2409 buf[4] = 0;
2411 FAILED(!compiler, "cannot create compiler\n");
2412 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 5, 5, 0, 0, 0);
2413 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -234);
2414 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw));
2415 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_S3, 0, SLJIT_R3, 0, SLJIT_R4, 0);
2416 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_S3, 0);
2417 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_S3, 0, SLJIT_IMM, 0);
2418 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_NOT_ZERO);
2419 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_S3, 0);
2420 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S4, 0, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw));
2421 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S4, 0, SLJIT_S4, 0, SLJIT_R4, 0);
2422 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_S4, 0);
2424 const1 = sljit_emit_const(compiler, SLJIT_S3, 0, 0);
2425 sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_S3, 0);
2426 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S3, 0, SLJIT_S3, 0, SLJIT_IMM, 100);
2427 label = sljit_emit_label(compiler);
2428 sljit_emit_op0(compiler, SLJIT_ENDBR);
2429 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_S3, 0);
2431 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R4, 0);
2433 code.code = sljit_generate_code(compiler);
2434 CHECK(compiler);
2436 label_addr = sljit_get_label_addr(label);
2437 sljit_set_const(sljit_get_const_addr(const1), label_addr, sljit_get_executable_offset(compiler));
2439 sljit_free_compiler(compiler);
2441 FAILED(code.func1((sljit_sw)&buf) != 8, "test28 case 1 failed\n");
2442 FAILED(buf[1] != -1872, "test28 case 2 failed\n");
2443 FAILED(buf[2] != 1, "test28 case 3 failed\n");
2444 FAILED(buf[3] != 2, "test28 case 4 failed\n");
2445 FAILED(buf[4] != label_addr, "test28 case 5 failed\n");
2447 sljit_free_code(code.code);
2448 successful_tests++;
2451 static void test29(void)
2453 /* Test signed/unsigned bytes and halfs. */
2454 executable_code code;
2455 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2456 sljit_sw buf[25];
2457 sljit_s32 i;
2459 if (verbose)
2460 printf("Run test29\n");
2462 for (i = 0; i < 25; i++)
2463 buf[i] = 0;
2465 FAILED(!compiler, "cannot create compiler\n");
2466 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 5, 5, 0, 0, 0);
2468 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R0, 0, SLJIT_IMM, -187);
2469 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
2470 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R0, 0, SLJIT_IMM, -605);
2471 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R0, 0);
2472 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R0, 0, SLJIT_IMM, -56);
2473 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_uw), SLJIT_R0, 0);
2474 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R4, 0, SLJIT_IMM, 0xcde5);
2475 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_uw), SLJIT_R4, 0);
2477 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_R0, 0, SLJIT_IMM, -45896);
2478 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_uw), SLJIT_R0, 0);
2479 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_R0, 0, SLJIT_IMM, -1472797);
2480 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_uw), SLJIT_R0, 0);
2481 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_R0, 0, SLJIT_IMM, -12890);
2482 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_uw), SLJIT_R0, 0);
2483 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_R4, 0, SLJIT_IMM, 0x9cb0a6);
2484 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_uw), SLJIT_R4, 0);
2486 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2487 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-3580429715));
2488 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_uw), SLJIT_R0, 0);
2489 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-100722768662));
2490 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_uw), SLJIT_R0, 0);
2491 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-1457052677972));
2492 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_uw), SLJIT_R0, 0);
2493 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R4, 0, SLJIT_IMM, SLJIT_W(0xcef97a70b5));
2494 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_uw), SLJIT_R4, 0);
2495 #endif
2497 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -187);
2498 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R0, 0, SLJIT_R1, 0);
2499 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_uw), SLJIT_R0, 0);
2500 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, -605);
2501 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R0, 0, SLJIT_S2, 0);
2502 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_uw), SLJIT_R0, 0);
2503 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -56);
2504 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R0, 0, SLJIT_R2, 0);
2505 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_uw), SLJIT_R0, 0);
2506 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0xcde5);
2507 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R4, 0, SLJIT_R3, 0);
2508 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 15 * sizeof(sljit_uw), SLJIT_R4, 0);
2510 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -45896);
2511 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_R0, 0, SLJIT_R1, 0);
2512 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 16 * sizeof(sljit_uw), SLJIT_R0, 0);
2513 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, -1472797);
2514 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_R0, 0, SLJIT_S2, 0);
2515 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 17 * sizeof(sljit_uw), SLJIT_R0, 0);
2516 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -12890);
2517 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_R0, 0, SLJIT_R2, 0);
2518 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_uw), SLJIT_R0, 0);
2519 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0x9cb0a6);
2520 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_R4, 0, SLJIT_R3, 0);
2521 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 19 * sizeof(sljit_uw), SLJIT_R4, 0);
2523 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2524 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(-3580429715));
2525 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R1, 0);
2526 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 20 * sizeof(sljit_uw), SLJIT_R0, 0);
2527 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, SLJIT_W(-100722768662));
2528 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_S2, 0);
2529 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 21 * sizeof(sljit_uw), SLJIT_R0, 0);
2530 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, SLJIT_W(-1457052677972));
2531 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R2, 0);
2532 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 22 * sizeof(sljit_uw), SLJIT_R0, 0);
2533 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, SLJIT_W(0xcef97a70b5));
2534 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R4, 0, SLJIT_R3, 0);
2535 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 23 * sizeof(sljit_uw), SLJIT_R4, 0);
2536 #endif
2538 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, 0x9faa5);
2539 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_S2, 0, SLJIT_S2, 0);
2540 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 24 * sizeof(sljit_uw), SLJIT_S2, 0);
2542 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2544 code.code = sljit_generate_code(compiler);
2545 CHECK(compiler);
2546 sljit_free_compiler(compiler);
2548 code.func1((sljit_sw)&buf);
2549 FAILED(buf[0] != 69, "test29 case 1 failed\n");
2550 FAILED(buf[1] != -93, "test29 case 2 failed\n");
2551 FAILED(buf[2] != 200, "test29 case 3 failed\n");
2552 FAILED(buf[3] != 0xe5, "test29 case 4 failed\n");
2553 FAILED(buf[4] != 19640, "test29 case 5 failed\n");
2554 FAILED(buf[5] != -31005, "test29 case 6 failed\n");
2555 FAILED(buf[6] != 52646, "test29 case 7 failed\n");
2556 FAILED(buf[7] != 0xb0a6, "test29 case 8 failed\n");
2558 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2559 FAILED(buf[8] != SLJIT_W(714537581), "test29 case 9 failed\n");
2560 FAILED(buf[9] != SLJIT_W(-1938520854), "test29 case 10 failed\n");
2561 FAILED(buf[10] != SLJIT_W(3236202668), "test29 case 11 failed\n");
2562 FAILED(buf[11] != SLJIT_W(0xf97a70b5), "test29 case 12 failed\n");
2563 #endif
2565 FAILED(buf[12] != 69, "test29 case 13 failed\n");
2566 FAILED(buf[13] != -93, "test29 case 14 failed\n");
2567 FAILED(buf[14] != 200, "test29 case 15 failed\n");
2568 FAILED(buf[15] != 0xe5, "test29 case 16 failed\n");
2569 FAILED(buf[16] != 19640, "test29 case 17 failed\n");
2570 FAILED(buf[17] != -31005, "test29 case 18 failed\n");
2571 FAILED(buf[18] != 52646, "test29 case 19 failed\n");
2572 FAILED(buf[19] != 0xb0a6, "test29 case 20 failed\n");
2574 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2575 FAILED(buf[20] != SLJIT_W(714537581), "test29 case 21 failed\n");
2576 FAILED(buf[21] != SLJIT_W(-1938520854), "test29 case 22 failed\n");
2577 FAILED(buf[22] != SLJIT_W(3236202668), "test29 case 23 failed\n");
2578 FAILED(buf[23] != SLJIT_W(0xf97a70b5), "test29 case 24 failed\n");
2579 #endif
2581 FAILED(buf[24] != -91, "test29 case 25 failed\n");
2583 sljit_free_code(code.code);
2584 successful_tests++;
2587 static void test30(void)
2589 /* Test unused results. */
2590 executable_code code;
2591 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2592 sljit_sw buf[1];
2594 if (verbose)
2595 printf("Run test30\n");
2597 FAILED(!compiler, "cannot create compiler\n");
2598 buf[0] = 0;
2599 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 5, 5, 0, 0, 0);
2601 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
2602 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
2603 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 1);
2604 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 1);
2605 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_IMM, 1);
2606 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2607 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_S1, 0, SLJIT_IMM, SLJIT_W(-0x123ffffffff));
2608 #else
2609 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_S1, 0, SLJIT_IMM, 1);
2610 #endif
2611 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, 1);
2612 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, 1);
2613 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S4, 0, SLJIT_IMM, 1);
2615 /* Some calculations with unused results. */
2616 sljit_emit_op1(compiler, SLJIT_NOT | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R1, 0);
2617 sljit_emit_op1(compiler, SLJIT_NEG | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0);
2618 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0);
2619 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_GREATER_EQUAL, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0);
2620 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_S0, 0, SLJIT_MEM1(SLJIT_S0), 0);
2621 sljit_emit_op2(compiler, SLJIT_SHL | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_S3, 0, SLJIT_R2, 0);
2622 sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 5);
2623 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0xff);
2624 sljit_emit_op1(compiler, SLJIT_NOT32 | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_S1, 0);
2626 /* Testing that any change happens. */
2627 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2628 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R2, 0);
2629 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R3, 0);
2630 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R4, 0);
2631 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_S1, 0, SLJIT_S1, 0);
2632 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S1, 0);
2633 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S2, 0);
2634 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S3, 0);
2635 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0, SLJIT_S4, 0);
2637 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2639 code.code = sljit_generate_code(compiler);
2640 CHECK(compiler);
2641 sljit_free_compiler(compiler);
2643 code.func1((sljit_sw)&buf);
2644 FAILED(buf[0] != 9, "test30 case 1 failed\n");
2646 sljit_free_code(code.code);
2647 successful_tests++;
2650 static void test31(void)
2652 /* Integer mul and set flags. */
2653 executable_code code;
2654 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2655 sljit_sw buf[12];
2656 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2657 sljit_sw big_word = SLJIT_W(0x7fffffff00000000);
2658 sljit_sw big_word2 = SLJIT_W(0x7fffffff00000012);
2659 #else
2660 sljit_sw big_word = 0x7fffffff;
2661 sljit_sw big_word2 = 0x00000012;
2662 #endif
2664 if (verbose)
2665 printf("Run test31\n");
2667 buf[0] = 3;
2668 buf[1] = 3;
2669 buf[2] = 3;
2670 buf[3] = 3;
2671 buf[4] = 3;
2672 buf[5] = 3;
2673 buf[6] = 3;
2674 buf[7] = 3;
2675 buf[8] = 3;
2676 buf[9] = 3;
2677 buf[10] = 3;
2678 buf[11] = 3;
2680 FAILED(!compiler, "cannot create compiler\n");
2682 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 5, 0, 0, 0);
2683 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
2684 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R1, 0, SLJIT_IMM, -45);
2685 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MUL_NOT_OVERFLOW);
2686 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R1, 0, SLJIT_IMM, -45);
2687 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MUL_OVERFLOW);
2689 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, big_word);
2690 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_OVERFLOW, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, -2);
2691 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 33); /* Should not change flags. */
2692 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0); /* Should not change flags. */
2693 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_MUL_OVERFLOW);
2694 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_OVERFLOW, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, -2);
2695 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_MUL_NOT_OVERFLOW);
2697 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_S3, 0, SLJIT_IMM, 0x3f6b0);
2698 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_S4, 0, SLJIT_IMM, 0x2a783);
2699 sljit_emit_op2(compiler, SLJIT_MUL32 | SLJIT_SET_MUL_OVERFLOW, SLJIT_R1, 0, SLJIT_S3, 0, SLJIT_S4, 0);
2700 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_MUL_OVERFLOW32);
2701 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R1, 0);
2703 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, big_word2);
2704 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R2, 0, SLJIT_R1, 0);
2705 sljit_emit_op2(compiler, SLJIT_MUL32 | SLJIT_SET_MUL_OVERFLOW, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 23);
2706 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_MUL_OVERFLOW32);
2708 sljit_emit_op2(compiler, SLJIT_MUL32 | SLJIT_SET_MUL_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, -23);
2709 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_MUL_NOT_OVERFLOW32);
2710 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, -23);
2711 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_MUL_NOT_OVERFLOW);
2713 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 67);
2714 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_OVERFLOW, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, -23);
2715 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_R1, 0);
2717 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2719 code.code = sljit_generate_code(compiler);
2720 CHECK(compiler);
2721 sljit_free_compiler(compiler);
2723 code.func1((sljit_sw)&buf);
2725 FAILED(buf[0] != 1, "test31 case 1 failed\n");
2726 FAILED(buf[1] != 2, "test31 case 2 failed\n");
2727 /* Qemu issues for 64 bit muls. */
2728 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2729 FAILED(buf[2] != 1, "test31 case 3 failed\n");
2730 FAILED(buf[3] != 2, "test31 case 4 failed\n");
2731 #endif
2732 FAILED(buf[4] != 1, "test31 case 5 failed\n");
2733 FAILED((buf[5] & 0xffffffff) != 0x85540c10, "test31 case 6 failed\n");
2734 FAILED(buf[6] != 2, "test31 case 7 failed\n");
2735 FAILED(buf[7] != 1, "test31 case 8 failed\n");
2736 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2737 FAILED(buf[8] != 1, "test31 case 9 failed\n");
2738 #endif
2739 FAILED(buf[9] != -1541, "test31 case 10 failed\n");
2741 sljit_free_code(code.code);
2742 successful_tests++;
2745 static void test32(void)
2747 /* Floating point set flags. */
2748 executable_code code;
2749 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2751 sljit_sw buf[16];
2752 union {
2753 sljit_f64 value;
2754 struct {
2755 sljit_s32 value1;
2756 sljit_s32 value2;
2757 } u;
2758 } dbuf[4];
2760 if (verbose)
2761 printf("Run test32\n");
2763 buf[0] = 5;
2764 buf[1] = 5;
2765 buf[2] = 5;
2766 buf[3] = 5;
2767 buf[4] = 5;
2768 buf[5] = 5;
2769 buf[6] = 5;
2770 buf[7] = 5;
2771 buf[8] = 5;
2772 buf[9] = 5;
2773 buf[10] = 5;
2774 buf[11] = 5;
2775 buf[12] = 5;
2776 buf[13] = 5;
2777 buf[14] = 5;
2778 buf[15] = 5;
2780 /* Two NaNs */
2781 dbuf[0].u.value1 = 0x7fffffff;
2782 dbuf[0].u.value2 = 0x7fffffff;
2783 dbuf[1].u.value1 = 0x7fffffff;
2784 dbuf[1].u.value2 = 0x7fffffff;
2785 dbuf[2].value = -13.0;
2786 dbuf[3].value = 27.0;
2788 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
2789 if (verbose)
2790 printf("no fpu available, test32 skipped\n");
2791 successful_tests++;
2792 if (compiler)
2793 sljit_free_compiler(compiler);
2794 return;
2797 FAILED(!compiler, "cannot create compiler\n");
2798 SLJIT_ASSERT(sizeof(sljit_f64) == 8 && sizeof(sljit_s32) == 4 && sizeof(dbuf[0]) == 8);
2800 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 1, 2, 4, 0, 0);
2802 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), 0);
2803 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_UNORDERED_F, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64), SLJIT_FR0, 0);
2804 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f64));
2805 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_UNORDERED_F64);
2806 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_ORDERED_F, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64), SLJIT_FR0, 0);
2807 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_ORDERED_F64);
2809 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64));
2810 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_UNORDERED_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2811 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_UNORDERED_F64);
2812 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_ORDERED_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2813 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_ORDERED_F64);
2814 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_LESS_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2815 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_LESS_F64);
2816 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_GREATER_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2817 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_GREATER_EQUAL_F64);
2818 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_GREATER_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2819 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_GREATER_F64);
2820 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_LESS_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2821 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_LESS_EQUAL_F64);
2822 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2823 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_EQUAL_F64);
2824 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_NOT_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2825 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_NOT_EQUAL_F64);
2827 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_UNORDERED_F, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64));
2828 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR3, 0, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f64));
2829 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_UNORDERED_F64);
2830 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_EQUAL_F, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64));
2831 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_EQUAL_F64);
2833 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_ORDERED_F, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f64), SLJIT_FR0, 0);
2834 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_ORDERED_F64);
2836 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_UNORDERED_F, SLJIT_FR3, 0, SLJIT_FR2, 0);
2837 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), 0);
2838 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_UNORDERED_F64);
2840 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2842 code.code = sljit_generate_code(compiler);
2843 CHECK(compiler);
2844 sljit_free_compiler(compiler);
2846 code.func2((sljit_sw)&buf, (sljit_sw)&dbuf);
2848 FAILED(buf[0] != 1, "test32 case 1 failed\n");
2849 FAILED(buf[1] != 2, "test32 case 2 failed\n");
2850 FAILED(buf[2] != 2, "test32 case 3 failed\n");
2851 FAILED(buf[3] != 1, "test32 case 4 failed\n");
2852 FAILED(buf[4] != 1, "test32 case 5 failed\n");
2853 FAILED(buf[5] != 2, "test32 case 6 failed\n");
2854 FAILED(buf[6] != 2, "test32 case 7 failed\n");
2855 FAILED(buf[7] != 1, "test32 case 8 failed\n");
2856 FAILED(buf[8] != 2, "test32 case 9 failed\n");
2857 FAILED(buf[9] != 1, "test32 case 10 failed\n");
2858 FAILED(buf[10] != 2, "test32 case 11 failed\n");
2859 FAILED(buf[11] != 1, "test32 case 12 failed\n");
2860 FAILED(buf[12] != 2, "test32 case 13 failed\n");
2861 FAILED(buf[13] != 1, "test32 case 14 failed\n");
2863 sljit_free_code(code.code);
2864 successful_tests++;
2867 static void test33(void)
2869 /* Test setting multiple flags. */
2870 executable_code code;
2871 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2872 struct sljit_jump* jump;
2873 sljit_sw buf[10];
2875 if (verbose)
2876 printf("Run test33\n");
2878 buf[0] = 3;
2879 buf[1] = 3;
2880 buf[2] = 3;
2881 buf[3] = 3;
2882 buf[4] = 3;
2883 buf[5] = 3;
2884 buf[6] = 3;
2885 buf[7] = 3;
2886 buf[8] = 3;
2887 buf[9] = 3;
2889 FAILED(!compiler, "cannot create compiler\n");
2891 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 3, 0, 0, 0);
2893 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 20);
2894 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 10);
2895 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2896 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_ZERO);
2897 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -10);
2898 jump = sljit_emit_jump(compiler, SLJIT_LESS);
2899 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, 11);
2900 sljit_set_label(jump, sljit_emit_label(compiler));
2902 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_SIG_GREATER, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2903 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_SIG_GREATER);
2904 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_IMM, 45);
2905 jump = sljit_emit_jump(compiler, SLJIT_NOT_EQUAL);
2906 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_IMM, 55);
2907 sljit_set_label(jump, sljit_emit_label(compiler));
2909 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2910 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x8000000000000000));
2911 #else
2912 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x80000000));
2913 #endif
2914 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
2915 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2916 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_IMM, 33);
2917 jump = sljit_emit_jump(compiler, SLJIT_NOT_OVERFLOW);
2918 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_ZERO);
2919 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_IMM, 13);
2920 sljit_set_label(jump, sljit_emit_label(compiler));
2922 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x80000000));
2923 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_R0, 0);
2924 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2925 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 0);
2926 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_NOT_ZERO);
2927 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_IMM, 78);
2928 jump = sljit_emit_jump(compiler, SLJIT_OVERFLOW32);
2929 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_IMM, 48);
2930 sljit_set_label(jump, sljit_emit_label(compiler));
2932 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2933 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x8000000000000000));
2934 #else
2935 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x80000000));
2936 #endif
2937 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_R0, 0);
2938 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2939 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_IMM, 30);
2940 jump = sljit_emit_jump(compiler, SLJIT_NOT_OVERFLOW);
2941 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_IMM, 50);
2942 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_ZERO);
2943 sljit_set_label(jump, sljit_emit_label(compiler));
2945 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2947 code.code = sljit_generate_code(compiler);
2948 CHECK(compiler);
2949 sljit_free_compiler(compiler);
2951 code.func1((sljit_sw)&buf);
2953 FAILED(buf[0] != 0, "test33 case 1 failed\n");
2954 FAILED(buf[1] != 11, "test33 case 2 failed\n");
2955 FAILED(buf[2] != 1, "test33 case 3 failed\n");
2956 FAILED(buf[3] != 45, "test33 case 4 failed\n");
2957 FAILED(buf[4] != 13, "test33 case 5 failed\n");
2958 FAILED(buf[5] != 0, "test33 case 6 failed\n");
2959 FAILED(buf[6] != 0, "test33 case 7 failed\n");
2960 FAILED(buf[7] != 48, "test33 case 8 failed\n");
2961 FAILED(buf[8] != 50, "test33 case 9 failed\n");
2962 FAILED(buf[9] != 1, "test33 case 10 failed\n");
2964 sljit_free_code(code.code);
2965 successful_tests++;
2968 static void test34(void)
2970 /* Test fast calls. */
2971 executable_code codeA;
2972 executable_code codeB;
2973 executable_code codeC;
2974 executable_code codeD;
2975 executable_code codeE;
2976 executable_code codeF;
2977 struct sljit_compiler* compiler;
2978 struct sljit_jump *jump;
2979 struct sljit_label* label;
2980 sljit_uw addr;
2981 sljit_p buf[2];
2983 if (verbose)
2984 printf("Run test34\n");
2986 buf[0] = 0;
2987 buf[1] = 0;
2989 /* A */
2990 compiler = sljit_create_compiler(NULL);
2991 FAILED(!compiler, "cannot create compiler\n");
2992 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
2994 sljit_emit_op0(compiler, SLJIT_ENDBR);
2995 sljit_emit_fast_enter(compiler, SLJIT_R1, 0);
2996 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 4);
2997 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_R1, 0);
2999 codeA.code = sljit_generate_code(compiler);
3000 CHECK(compiler);
3001 sljit_free_compiler(compiler);
3003 /* B */
3004 compiler = sljit_create_compiler(NULL);
3005 FAILED(!compiler, "cannot create compiler\n");
3006 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3008 sljit_emit_op0(compiler, SLJIT_ENDBR);
3009 sljit_emit_fast_enter(compiler, SLJIT_R4, 0);
3010 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 6);
3011 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(codeA.code));
3012 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_R1, 0);
3013 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_R4, 0);
3015 codeB.code = sljit_generate_code(compiler);
3016 CHECK(compiler);
3017 sljit_free_compiler(compiler);
3019 /* C */
3020 compiler = sljit_create_compiler(NULL);
3021 FAILED(!compiler, "cannot create compiler\n");
3022 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3024 sljit_emit_op0(compiler, SLJIT_ENDBR);
3025 sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_p));
3026 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 8);
3027 jump = sljit_emit_jump(compiler, SLJIT_FAST_CALL | SLJIT_REWRITABLE_JUMP);
3028 sljit_set_target(jump, SLJIT_FUNC_OFFSET(codeB.code));
3029 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_p));
3031 codeC.code = sljit_generate_code(compiler);
3032 CHECK(compiler);
3033 sljit_free_compiler(compiler);
3035 /* D */
3036 compiler = sljit_create_compiler(NULL);
3037 FAILED(!compiler, "cannot create compiler\n");
3038 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3040 sljit_emit_op0(compiler, SLJIT_ENDBR);
3041 sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_SP), 0);
3042 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 10);
3043 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_OFFSET(codeC.code));
3044 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_MEM1(SLJIT_SP), 0);
3046 codeD.code = sljit_generate_code(compiler);
3047 CHECK(compiler);
3048 sljit_free_compiler(compiler);
3050 /* E */
3051 compiler = sljit_create_compiler(NULL);
3052 FAILED(!compiler, "cannot create compiler\n");
3053 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3055 sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_S0), 0);
3056 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 12);
3057 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_p), SLJIT_IMM, SLJIT_FUNC_OFFSET(codeD.code));
3058 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_p));
3059 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_MEM1(SLJIT_S0), 0);
3061 codeE.code = sljit_generate_code(compiler);
3062 CHECK(compiler);
3063 sljit_free_compiler(compiler);
3065 /* F */
3066 compiler = sljit_create_compiler(NULL);
3067 FAILED(!compiler, "cannot create compiler\n");
3069 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 5, 5, 0, 0, 2 * sizeof(sljit_p));
3070 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
3071 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_OFFSET(codeE.code));
3072 label = sljit_emit_label(compiler);
3073 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
3075 codeF.code = sljit_generate_code(compiler);
3076 CHECK(compiler);
3077 addr = sljit_get_label_addr(label);
3078 sljit_free_compiler(compiler);
3080 FAILED(codeF.func1((sljit_sw)&buf) != 40, "test34 case 1 failed\n");
3081 FAILED(buf[0] != addr - SLJIT_RETURN_ADDRESS_OFFSET, "test34 case 2 failed\n");
3083 sljit_free_code(codeA.code);
3084 sljit_free_code(codeB.code);
3085 sljit_free_code(codeC.code);
3086 sljit_free_code(codeD.code);
3087 sljit_free_code(codeE.code);
3088 sljit_free_code(codeF.code);
3089 successful_tests++;
3092 static void test35(void)
3094 /* More complicated tests for fast calls. */
3095 executable_code codeA;
3096 executable_code codeB;
3097 executable_code codeC;
3098 struct sljit_compiler* compiler;
3099 struct sljit_jump *jump = NULL;
3100 struct sljit_label* label;
3101 sljit_sw executable_offset;
3102 sljit_uw return_addr;
3103 sljit_uw jump_addr = 0;
3104 sljit_p buf[1];
3106 if (verbose)
3107 printf("Run test35\n");
3109 buf[0] = 0;
3111 /* A */
3112 compiler = sljit_create_compiler(NULL);
3113 FAILED(!compiler, "cannot create compiler\n");
3114 sljit_set_context(compiler, 0, 0, 2, 2, 0, 0, 0);
3116 sljit_emit_fast_enter(compiler, SLJIT_MEM0(), (sljit_sw)&buf[0]);
3117 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 5);
3119 jump = sljit_emit_jump(compiler, SLJIT_FAST_CALL | SLJIT_REWRITABLE_JUMP);
3120 sljit_set_target(jump, 0);
3122 label = sljit_emit_label(compiler);
3123 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_MEM0(), (sljit_sw)&buf[0]);
3125 codeA.code = sljit_generate_code(compiler);
3126 CHECK(compiler);
3127 executable_offset = sljit_get_executable_offset(compiler);
3128 jump_addr = sljit_get_jump_addr(jump);
3129 sljit_free_compiler(compiler);
3131 /* B */
3132 compiler = sljit_create_compiler(NULL);
3133 FAILED(!compiler, "cannot create compiler\n");
3134 sljit_set_context(compiler, 0, 0, 2, 2, 0, 0, 0);
3136 sljit_emit_op0(compiler, SLJIT_ENDBR);
3137 sljit_emit_fast_enter(compiler, SLJIT_R1, 0);
3138 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 7);
3139 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_R1, 0);
3141 codeB.code = sljit_generate_code(compiler);
3142 CHECK(compiler);
3143 sljit_free_compiler(compiler);
3145 sljit_set_jump_addr(jump_addr, SLJIT_FUNC_OFFSET(codeB.code), executable_offset);
3147 /* C */
3148 compiler = sljit_create_compiler(NULL);
3149 FAILED(!compiler, "cannot create compiler\n");
3151 sljit_emit_enter(compiler, 0, 0, 2, 2, 0, 0, 0);
3152 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
3153 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_OFFSET(codeA.code));
3154 label = sljit_emit_label(compiler);
3155 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
3157 codeC.code = sljit_generate_code(compiler);
3158 CHECK(compiler);
3159 return_addr = sljit_get_label_addr(label);
3160 sljit_free_compiler(compiler);
3162 FAILED(codeC.func0() != 12, "test35 case 1 failed\n");
3163 FAILED(buf[0] != return_addr - SLJIT_RETURN_ADDRESS_OFFSET, "test35 case 2 failed\n");
3165 sljit_free_code(codeA.code);
3166 sljit_free_code(codeB.code);
3167 sljit_free_code(codeC.code);
3168 successful_tests++;
3171 static void cmp_test(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src1, sljit_sw src1w, sljit_s32 src2, sljit_sw src2w)
3173 /* 2 = true, 1 = false */
3174 struct sljit_jump* jump;
3175 struct sljit_label* label;
3177 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_IMM, 2);
3178 jump = sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w);
3179 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_IMM, 1);
3180 label = sljit_emit_label(compiler);
3181 sljit_emit_op0(compiler, SLJIT_ENDBR);
3182 sljit_set_label(jump, label);
3183 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
3186 #define TEST_CASES (7 + 10 + 12 + 11 + 4)
3187 static void test36(void)
3189 /* Compare instruction. */
3190 executable_code code;
3191 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
3193 sljit_s8 buf[TEST_CASES];
3194 sljit_s8 compare_buf[TEST_CASES] = {
3195 1, 1, 2, 2, 1, 2, 2,
3196 1, 1, 2, 2, 2, 1, 2, 2, 1, 1,
3197 2, 2, 2, 1, 2, 2, 2, 2, 1, 1, 2, 2,
3198 2, 1, 2, 1, 1, 1, 2, 1, 2, 1, 2,
3199 2, 1, 1, 2
3201 sljit_sw data[4];
3202 sljit_s32 i;
3204 if (verbose)
3205 printf("Run test36\n");
3207 FAILED(!compiler, "cannot create compiler\n");
3208 for (i = 0; i < TEST_CASES; ++i)
3209 buf[i] = 100;
3210 data[0] = 32;
3211 data[1] = -9;
3212 data[2] = 43;
3213 data[3] = -13;
3215 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 3, 2, 0, 0, 0);
3216 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
3218 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 13);
3219 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 15);
3220 cmp_test(compiler, SLJIT_EQUAL, SLJIT_IMM, 9, SLJIT_R0, 0);
3221 cmp_test(compiler, SLJIT_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3222 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 3);
3223 cmp_test(compiler, SLJIT_EQUAL, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_IMM, -13);
3224 cmp_test(compiler, SLJIT_NOT_EQUAL, SLJIT_IMM, 0, SLJIT_R0, 0);
3225 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
3226 cmp_test(compiler, SLJIT_NOT_EQUAL | SLJIT_REWRITABLE_JUMP, SLJIT_IMM, 0, SLJIT_R0, 0);
3227 cmp_test(compiler, SLJIT_EQUAL, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT);
3228 cmp_test(compiler, SLJIT_EQUAL | SLJIT_REWRITABLE_JUMP, SLJIT_R0, 0, SLJIT_IMM, 0);
3230 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, 0);
3231 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -8);
3232 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
3233 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_R0, 0, SLJIT_IMM, 0);
3234 cmp_test(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 0);
3235 cmp_test(compiler, SLJIT_SIG_LESS | SLJIT_REWRITABLE_JUMP, SLJIT_R0, 0, SLJIT_IMM, 0);
3236 cmp_test(compiler, SLJIT_SIG_GREATER_EQUAL, SLJIT_R1, 0, SLJIT_IMM, 0);
3237 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_sw));
3238 cmp_test(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_IMM, 0, SLJIT_R1, 0);
3239 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_sw));
3240 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw));
3241 cmp_test(compiler, SLJIT_SIG_LESS | SLJIT_REWRITABLE_JUMP, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw));
3243 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
3244 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
3245 cmp_test(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_sw));
3246 cmp_test(compiler, SLJIT_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 8);
3247 cmp_test(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_IMM, -10);
3248 cmp_test(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_IMM, 8);
3249 cmp_test(compiler, SLJIT_GREATER_EQUAL, SLJIT_IMM, 8, SLJIT_R1, 0);
3250 cmp_test(compiler, SLJIT_GREATER_EQUAL | SLJIT_REWRITABLE_JUMP, SLJIT_IMM, 8, SLJIT_R1, 0);
3251 cmp_test(compiler, SLJIT_GREATER, SLJIT_IMM, 8, SLJIT_R1, 0);
3252 cmp_test(compiler, SLJIT_LESS_EQUAL, SLJIT_IMM, 7, SLJIT_R0, 0);
3253 cmp_test(compiler, SLJIT_GREATER, SLJIT_IMM, 1, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw));
3254 cmp_test(compiler, SLJIT_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3255 cmp_test(compiler, SLJIT_GREATER, SLJIT_R0, 0, SLJIT_R1, 0);
3256 cmp_test(compiler, SLJIT_GREATER | SLJIT_REWRITABLE_JUMP, SLJIT_R0, 0, SLJIT_R1, 0);
3258 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -3);
3259 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
3260 cmp_test(compiler, SLJIT_SIG_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3261 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_R0, 0, SLJIT_IMM, -1);
3262 cmp_test(compiler, SLJIT_SIG_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 1);
3263 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, -1);
3264 cmp_test(compiler, SLJIT_SIG_LESS | SLJIT_REWRITABLE_JUMP, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, -1);
3265 cmp_test(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3266 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_R0, 0, SLJIT_R1, 0);
3267 cmp_test(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_IMM, -4, SLJIT_R0, 0);
3268 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_IMM, -1, SLJIT_R1, 0);
3269 cmp_test(compiler, SLJIT_SIG_GREATER | SLJIT_REWRITABLE_JUMP, SLJIT_R1, 0, SLJIT_IMM, -1);
3271 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3272 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xf00000004));
3273 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_R0, 0);
3274 cmp_test(compiler, SLJIT_LESS32, SLJIT_R1, 0, SLJIT_IMM, 5);
3275 cmp_test(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_IMM, 5);
3276 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xff0000004));
3277 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_R0, 0);
3278 cmp_test(compiler, SLJIT_SIG_GREATER32, SLJIT_R1, 0, SLJIT_IMM, 5);
3279 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_R0, 0, SLJIT_IMM, 5);
3280 #else
3281 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 4);
3282 cmp_test(compiler, SLJIT_LESS32, SLJIT_R0, 0, SLJIT_IMM, 5);
3283 cmp_test(compiler, SLJIT_GREATER32, SLJIT_R0, 0, SLJIT_IMM, 5);
3284 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0xf0000004);
3285 cmp_test(compiler, SLJIT_SIG_GREATER32, SLJIT_R0, 0, SLJIT_IMM, 5);
3286 cmp_test(compiler, SLJIT_SIG_LESS32, SLJIT_R0, 0, SLJIT_IMM, 5);
3287 #endif
3289 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
3291 code.code = sljit_generate_code(compiler);
3292 CHECK(compiler);
3293 sljit_free_compiler(compiler);
3295 code.func2((sljit_sw)&buf, (sljit_sw)&data);
3297 for (i = 0; i < TEST_CASES; ++i)
3298 if (SLJIT_UNLIKELY(buf[i] != compare_buf[i])) {
3299 printf("test36 case %d failed\n", i + 1);
3300 return;
3303 sljit_free_code(code.code);
3304 successful_tests++;
3306 #undef TEST_CASES
3308 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3309 #define BITN(n) (SLJIT_W(1) << (63 - (n)))
3310 #define RESN(n) (n)
3311 #else
3312 #define BITN(n) (1 << (31 - ((n) & 0x1f)))
3313 #define RESN(n) ((n) & 0x1f)
3314 #endif
3316 static void test37(void)
3318 /* Test count leading zeroes. */
3319 executable_code code;
3320 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
3321 sljit_sw buf[9];
3322 sljit_s32 ibuf[2];
3323 sljit_s32 i;
3325 if (verbose)
3326 printf("Run test37\n");
3328 FAILED(!compiler, "cannot create compiler\n");
3330 for (i = 0; i < 9; i++)
3331 buf[i] = -1;
3332 buf[2] = 0;
3333 buf[4] = BITN(13);
3334 ibuf[0] = -1;
3335 ibuf[1] = -1;
3336 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 1, 3, 0, 0, 0);
3337 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, BITN(27));
3338 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
3339 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, BITN(47));
3340 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_R0, 0, SLJIT_S2, 0);
3341 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
3342 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw));
3343 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
3344 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_R0, 0, SLJIT_R0, 0);
3345 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_R0, 0);
3346 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0);
3347 sljit_emit_op1(compiler, SLJIT_CLZ32, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_R0, 0);
3348 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
3349 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw));
3350 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
3351 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, BITN(58));
3352 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R0, 0);
3353 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
3354 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_R0, 0);
3355 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3356 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xff08a00000));
3357 #else
3358 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x08a00000);
3359 #endif
3360 sljit_emit_op1(compiler, SLJIT_CLZ32, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32), SLJIT_R0, 0);
3361 sljit_emit_op1(compiler, SLJIT_CLZ32, SLJIT_R0, 0, SLJIT_R0, 0);
3362 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R0, 0);
3363 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3364 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xffc8a00000));
3365 #else
3366 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0xc8a00000);
3367 #endif
3368 sljit_emit_op1(compiler, SLJIT_CLZ32, SLJIT_R0, 0, SLJIT_R0, 0);
3369 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R0, 0);
3371 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
3373 code.code = sljit_generate_code(compiler);
3374 CHECK(compiler);
3375 sljit_free_compiler(compiler);
3377 code.func2((sljit_sw)&buf, (sljit_sw)&ibuf);
3378 FAILED(buf[0] != RESN(27), "test37 case 1 failed\n");
3379 FAILED(buf[1] != RESN(47), "test37 case 2 failed\n");
3380 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3381 FAILED(buf[2] != 64, "test37 case 3 failed\n");
3382 #else
3383 FAILED(buf[2] != 32, "test37 case 3 failed\n");
3384 #endif
3385 FAILED(buf[3] != 0, "test37 case 4 failed\n");
3386 FAILED(ibuf[0] != 32, "test37 case 5 failed\n");
3387 FAILED(buf[4] != RESN(13), "test37 case 6 failed\n");
3388 FAILED(buf[5] != RESN(58), "test37 case 7 failed\n");
3389 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3390 FAILED(buf[6] != 64, "test37 case 8 failed\n");
3391 #else
3392 FAILED(buf[6] != 32, "test37 case 8 failed\n");
3393 #endif
3394 FAILED(ibuf[1] != 4, "test37 case 9 failed\n");
3396 FAILED((buf[7] & 0xffffffff) != 4, "test37 case 10 failed\n");
3397 FAILED((buf[8] & 0xffffffff) != 0, "test37 case 11 failed\n");
3399 sljit_free_code(code.code);
3400 successful_tests++;
3402 #undef BITN
3403 #undef RESN
3405 static void test38(void)
3407 #if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK)
3408 /* Test stack utility. */
3409 executable_code code;
3410 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
3411 struct sljit_jump* alloc1_fail;
3412 struct sljit_jump* alloc2_fail;
3413 struct sljit_jump* alloc3_fail;
3414 struct sljit_jump* sanity1_fail;
3415 struct sljit_jump* sanity2_fail;
3416 struct sljit_jump* sanity3_fail;
3417 struct sljit_jump* sanity4_fail;
3418 struct sljit_jump* jump;
3419 struct sljit_label* label;
3421 if (verbose)
3422 printf("Run test38\n");
3424 FAILED(!compiler, "cannot create compiler\n");
3426 sljit_emit_enter(compiler, 0, 0, 3, 1, 0, 0, 0);
3428 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8192);
3429 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 65536);
3430 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 0);
3431 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_allocate_stack));
3432 alloc1_fail = sljit_emit_cmp(compiler, SLJIT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
3433 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_RETURN_REG, 0);
3435 /* Write 8k data. */
3436 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, start));
3437 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 8192);
3438 label = sljit_emit_label(compiler);
3439 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_IMM, -1);
3440 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw));
3441 jump = sljit_emit_cmp(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
3442 sljit_set_label(jump, label);
3444 /* Grow stack. */
3445 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
3446 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, end), SLJIT_IMM, 65536);
3447 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW), SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_stack_resize));
3448 alloc2_fail = sljit_emit_cmp(compiler, SLJIT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
3449 sanity1_fail = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, start));
3451 /* Write 64k data. */
3452 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, start));
3453 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 65536);
3454 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, min_start));
3455 sanity2_fail = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_R0, 0, SLJIT_R2, 0);
3456 label = sljit_emit_label(compiler);
3457 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_IMM, -1);
3458 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw));
3459 jump = sljit_emit_cmp(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
3460 sljit_set_label(jump, label);
3462 /* Shrink stack. */
3463 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
3464 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, end), SLJIT_IMM, 32768);
3465 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW), SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_stack_resize));
3466 alloc3_fail = sljit_emit_cmp(compiler, SLJIT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
3467 sanity3_fail = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, start));
3469 /* Write 32k data. */
3470 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, start));
3471 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, end));
3472 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R2, 0, SLJIT_R1, 0, SLJIT_IMM, 32768);
3473 sanity4_fail = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_R0, 0, SLJIT_R2, 0);
3474 label = sljit_emit_label(compiler);
3475 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_IMM, -1);
3476 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw));
3477 jump = sljit_emit_cmp(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
3478 sljit_set_label(jump, label);
3480 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
3481 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
3482 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW), SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_free_stack));
3484 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, 4567);
3486 label = sljit_emit_label(compiler);
3487 sljit_set_label(alloc1_fail, label);
3488 sljit_set_label(alloc2_fail, label);
3489 sljit_set_label(alloc3_fail, label);
3490 sljit_set_label(sanity1_fail, label);
3491 sljit_set_label(sanity2_fail, label);
3492 sljit_set_label(sanity3_fail, label);
3493 sljit_set_label(sanity4_fail, label);
3494 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, 0);
3496 code.code = sljit_generate_code(compiler);
3497 CHECK(compiler);
3498 sljit_free_compiler(compiler);
3500 /* Just survive this. */
3501 FAILED(code.func0() != 4567, "test38 case 1 failed\n");
3503 sljit_free_code(code.code);
3504 #endif
3505 successful_tests++;
3508 static void test39(void)
3510 /* Test error handling. */
3511 executable_code code;
3512 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
3513 struct sljit_jump* jump;
3515 if (verbose)
3516 printf("Run test39\n");
3518 FAILED(!compiler, "cannot create compiler\n");
3520 /* Such assignment should never happen in a regular program. */
3521 compiler->error = -3967;
3523 SLJIT_ASSERT(sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 5, 5, 6, 0, 32) == -3967);
3524 SLJIT_ASSERT(sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R1, 0) == -3967);
3525 SLJIT_ASSERT(sljit_emit_op0(compiler, SLJIT_NOP) == -3967);
3526 SLJIT_ASSERT(sljit_emit_op0(compiler, SLJIT_ENDBR) == -3967);
3527 SLJIT_ASSERT(sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), 1) == -3967);
3528 SLJIT_ASSERT(sljit_emit_op2(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R0), 64, SLJIT_MEM1(SLJIT_S0), -64) == -3967);
3529 SLJIT_ASSERT(sljit_emit_fop1(compiler, SLJIT_ABS_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_R1), 0) == -3967);
3530 SLJIT_ASSERT(sljit_emit_fop2(compiler, SLJIT_DIV_F64, SLJIT_FR2, 0, SLJIT_MEM2(SLJIT_R0, SLJIT_S0), 0, SLJIT_FR2, 0) == -3967);
3531 SLJIT_ASSERT(!sljit_emit_label(compiler));
3532 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW));
3533 SLJIT_ASSERT(!jump);
3534 sljit_set_label(jump, (struct sljit_label*)0x123450);
3535 sljit_set_target(jump, 0x123450);
3536 jump = sljit_emit_cmp(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3537 SLJIT_ASSERT(!jump);
3538 SLJIT_ASSERT(sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_MEM1(SLJIT_R0), 8) == -3967);
3539 SLJIT_ASSERT(sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MUL_OVERFLOW) == -3967);
3540 SLJIT_ASSERT(!sljit_emit_const(compiler, SLJIT_R0, 0, 99));
3542 SLJIT_ASSERT(!compiler->labels && !compiler->jumps && !compiler->consts);
3543 SLJIT_ASSERT(!compiler->last_label && !compiler->last_jump && !compiler->last_const);
3544 SLJIT_ASSERT(!compiler->buf->next && !compiler->buf->used_size);
3545 SLJIT_ASSERT(!compiler->abuf->next && !compiler->abuf->used_size);
3547 sljit_set_compiler_memory_error(compiler);
3548 FAILED(sljit_get_compiler_error(compiler) != -3967, "test39 case 1 failed\n");
3550 code.code = sljit_generate_code(compiler);
3551 FAILED(sljit_get_compiler_error(compiler) != -3967, "test39 case 2 failed\n");
3552 FAILED(!!code.code, "test39 case 3 failed\n");
3553 sljit_free_compiler(compiler);
3555 compiler = sljit_create_compiler(NULL);
3556 FAILED(!compiler, "cannot create compiler\n");
3558 FAILED(sljit_get_compiler_error(compiler) != SLJIT_SUCCESS, "test39 case 4 failed\n");
3559 sljit_set_compiler_memory_error(compiler);
3560 FAILED(sljit_get_compiler_error(compiler) != SLJIT_ERR_ALLOC_FAILED, "test39 case 5 failed\n");
3561 sljit_free_compiler(compiler);
3563 successful_tests++;
3566 static void test40(void)
3568 /* Test emit_op_flags. */
3569 executable_code code;
3570 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
3571 sljit_sw buf[10];
3573 if (verbose)
3574 printf("Run test40\n");
3576 FAILED(!compiler, "cannot create compiler\n");
3577 buf[0] = -100;
3578 buf[1] = -100;
3579 buf[2] = -100;
3580 buf[3] = -8;
3581 buf[4] = -100;
3582 buf[5] = -100;
3583 buf[6] = 0;
3584 buf[7] = 0;
3585 buf[8] = -100;
3586 buf[9] = -100;
3588 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 4, 0, 0, sizeof(sljit_sw));
3590 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -5);
3591 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_UNUSED, 0, SLJIT_IMM, -6, SLJIT_R0, 0);
3592 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x123456);
3593 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_SIG_LESS);
3594 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R1, 0);
3596 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -13);
3597 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_IMM, -13, SLJIT_R0, 0);
3598 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, 0);
3599 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_EQUAL);
3600 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_NOT_EQUAL);
3601 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SP), 0);
3602 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_IMM, -13, SLJIT_R0, 0);
3603 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
3604 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_EQUAL);
3605 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_EQUAL);
3607 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -13);
3608 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 3);
3609 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R1, 0);
3610 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_MEM2(SLJIT_S0, SLJIT_R1), SLJIT_WORD_SHIFT, SLJIT_SIG_LESS);
3612 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -8);
3613 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 33);
3614 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
3615 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, 0);
3616 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_R2, 0, SLJIT_GREATER);
3617 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_S1, 0, SLJIT_EQUAL);
3618 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
3619 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, 0x88);
3620 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_S3, 0, SLJIT_NOT_EQUAL);
3621 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_S1, 0);
3622 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_S3, 0);
3624 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x84);
3625 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_IMM, 0x180, SLJIT_R0, 0);
3626 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_EQUAL);
3627 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_EQUAL);
3629 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
3630 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
3631 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_NOT_EQUAL);
3632 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_NOT_EQUAL);
3634 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x123456);
3635 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
3636 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_R0, 0, SLJIT_GREATER);
3637 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 9, SLJIT_R0, 0);
3639 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, 0xbaddead);
3640 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0);
3642 code.code = sljit_generate_code(compiler);
3643 CHECK(compiler);
3644 sljit_free_compiler(compiler);
3646 FAILED(code.func1((sljit_sw)&buf) != 0xbaddead, "test40 case 1 failed\n");
3647 FAILED(buf[0] != 0x123457, "test40 case 2 failed\n");
3648 FAILED(buf[1] != 1, "test40 case 3 failed\n");
3649 FAILED(buf[2] != 0, "test40 case 4 failed\n");
3650 FAILED(buf[3] != -7, "test40 case 5 failed\n");
3651 FAILED(buf[4] != 0, "test40 case 6 failed\n");
3652 FAILED(buf[5] != 0x89, "test40 case 7 failed\n");
3653 FAILED(buf[6] != 0, "test40 case 8 failed\n");
3654 FAILED(buf[7] != 1, "test40 case 9 failed\n");
3655 FAILED(buf[8] != 1, "test40 case 10 failed\n");
3656 FAILED(buf[9] != 0x123457, "test40 case 11 failed\n");
3658 sljit_free_code(code.code);
3659 successful_tests++;
3662 static void test41(void)
3664 /* Test inline assembly. */
3665 executable_code code;
3666 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
3667 sljit_s32 i;
3668 sljit_f64 buf[3];
3669 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3670 sljit_u8 inst[16];
3671 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3672 sljit_u8 inst[16];
3673 sljit_s32 reg;
3674 #else
3675 sljit_u32 inst;
3676 #endif
3678 if (verbose)
3679 printf("Run test41\n");
3681 #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3682 SLJIT_ASSERT(sljit_has_cpu_feature(SLJIT_HAS_VIRTUAL_REGISTERS) == 0);
3683 #endif
3685 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++) {
3686 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3687 if (SLJIT_R(i) >= SLJIT_R3 && SLJIT_R(i) <= SLJIT_R8) {
3688 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R(i)) == -1);
3689 continue;
3691 #endif
3692 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R(i)) >= 0 && sljit_get_register_index(SLJIT_R(i)) < 64);
3695 FAILED(!compiler, "cannot create compiler\n");
3696 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 3, 3, 0, 0, 0);
3698 /* Returns with the sum of SLJIT_S0 and SLJIT_S1. */
3699 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3700 /* lea SLJIT_RETURN_REG, [SLJIT_S0, SLJIT_S1] */
3701 inst[0] = 0x48;
3702 inst[1] = 0x8d;
3703 inst[2] = 0x04 | ((sljit_get_register_index(SLJIT_RETURN_REG) & 0x7) << 3);
3704 inst[3] = (sljit_get_register_index(SLJIT_S0) & 0x7)
3705 | ((sljit_get_register_index(SLJIT_S1) & 0x7) << 3);
3706 sljit_emit_op_custom(compiler, inst, 4);
3707 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3708 /* lea SLJIT_RETURN_REG, [SLJIT_S0, SLJIT_S1] */
3709 inst[0] = 0x48; /* REX_W */
3710 inst[1] = 0x8d;
3711 inst[2] = 0x04;
3712 reg = sljit_get_register_index(SLJIT_RETURN_REG);
3713 inst[2] |= ((reg & 0x7) << 3);
3714 if (reg > 7)
3715 inst[0] |= 0x04; /* REX_R */
3716 reg = sljit_get_register_index(SLJIT_S0);
3717 inst[3] = reg & 0x7;
3718 if (reg > 7)
3719 inst[0] |= 0x01; /* REX_B */
3720 reg = sljit_get_register_index(SLJIT_S1);
3721 inst[3] |= (reg & 0x7) << 3;
3722 if (reg > 7)
3723 inst[0] |= 0x02; /* REX_X */
3724 sljit_emit_op_custom(compiler, inst, 4);
3725 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
3726 /* add rd, rn, rm */
3727 inst = 0xe0800000 | (sljit_get_register_index(SLJIT_RETURN_REG) << 12)
3728 | (sljit_get_register_index(SLJIT_S0) << 16)
3729 | sljit_get_register_index(SLJIT_S1);
3730 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3731 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
3732 /* add rd, rn, rm */
3733 inst = 0xeb000000 | (sljit_get_register_index(SLJIT_RETURN_REG) << 8)
3734 | (sljit_get_register_index(SLJIT_S0) << 16)
3735 | sljit_get_register_index(SLJIT_S1);
3736 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3737 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
3738 /* add rd, rn, rm */
3739 inst = 0x8b000000 | sljit_get_register_index(SLJIT_RETURN_REG)
3740 | (sljit_get_register_index(SLJIT_S0) << 5)
3741 | (sljit_get_register_index(SLJIT_S1) << 16);
3742 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3743 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
3744 /* add rD, rA, rB */
3745 inst = (31 << 26) | (266 << 1) | (sljit_get_register_index(SLJIT_RETURN_REG) << 21)
3746 | (sljit_get_register_index(SLJIT_S0) << 16)
3747 | (sljit_get_register_index(SLJIT_S1) << 11);
3748 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3749 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
3750 /* addu rd, rs, rt */
3751 inst = 33 | (sljit_get_register_index(SLJIT_RETURN_REG) << 11)
3752 | (sljit_get_register_index(SLJIT_S0) << 21)
3753 | (sljit_get_register_index(SLJIT_S1) << 16);
3754 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3755 #elif (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
3756 /* daddu rd, rs, rt */
3757 inst = 45 | (sljit_get_register_index(SLJIT_RETURN_REG) << 11)
3758 | (sljit_get_register_index(SLJIT_S0) << 21)
3759 | (sljit_get_register_index(SLJIT_S1) << 16);
3760 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3761 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3762 /* add rd, rs1, rs2 */
3763 inst = (0x2 << 30) | (sljit_get_register_index(SLJIT_RETURN_REG) << 25)
3764 | (sljit_get_register_index(SLJIT_S0) << 14)
3765 | sljit_get_register_index(SLJIT_S1);
3766 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3767 #else
3768 inst = 0;
3769 sljit_emit_op_custom(compiler, &inst, 0);
3770 #endif
3772 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
3774 code.code = sljit_generate_code(compiler);
3775 CHECK(compiler);
3776 sljit_free_compiler(compiler);
3778 FAILED(code.func2(32, -11) != 21, "test41 case 1 failed\n");
3779 FAILED(code.func2(1000, 234) != 1234, "test41 case 2 failed\n");
3780 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3781 FAILED(code.func2(SLJIT_W(0x20f0a04090c06070), SLJIT_W(0x020f0a04090c0607)) != SLJIT_W(0x22ffaa4499cc6677), "test41 case 3 failed\n");
3782 #endif
3784 sljit_free_code(code.code);
3786 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
3787 buf[0] = 13.5;
3788 buf[1] = -2.25;
3789 buf[2] = 0.0;
3791 compiler = sljit_create_compiler(NULL);
3792 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 0, 1, 2, 0, 0);
3793 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 0);
3794 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
3795 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3796 /* addsd x, xm */
3797 inst[0] = 0xf2;
3798 inst[1] = 0x0f;
3799 inst[2] = 0x58;
3800 inst[3] = 0xc0 | (sljit_get_float_register_index(SLJIT_FR0) << 3)
3801 | sljit_get_float_register_index(SLJIT_FR1);
3802 sljit_emit_op_custom(compiler, inst, 4);
3803 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3804 /* addsd x, xm */
3805 if (sljit_get_float_register_index(SLJIT_FR0) > 7 || sljit_get_float_register_index(SLJIT_FR1) > 7) {
3806 inst[0] = 0;
3807 if (sljit_get_float_register_index(SLJIT_FR0) > 7)
3808 inst[0] |= 0x04; /* REX_R */
3809 if (sljit_get_float_register_index(SLJIT_FR1) > 7)
3810 inst[0] |= 0x01; /* REX_B */
3811 inst[1] = 0xf2;
3812 inst[2] = 0x0f;
3813 inst[3] = 0x58;
3814 inst[4] = 0xc0 | ((sljit_get_float_register_index(SLJIT_FR0) & 0x7) << 3)
3815 | (sljit_get_float_register_index(SLJIT_FR1) & 0x7);
3816 sljit_emit_op_custom(compiler, inst, 5);
3818 else {
3819 inst[0] = 0xf2;
3820 inst[1] = 0x0f;
3821 inst[2] = 0x58;
3822 inst[3] = 0xc0 | (sljit_get_float_register_index(SLJIT_FR0) << 3)
3823 | sljit_get_float_register_index(SLJIT_FR1);
3824 sljit_emit_op_custom(compiler, inst, 4);
3826 #elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32)
3827 /* vadd.f64 dd, dn, dm */
3828 inst = 0xee300b00 | ((sljit_get_float_register_index(SLJIT_FR0) >> 1) << 12)
3829 | ((sljit_get_float_register_index(SLJIT_FR0) >> 1) << 16)
3830 | (sljit_get_float_register_index(SLJIT_FR1) >> 1);
3831 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3832 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
3833 /* fadd rd, rn, rm */
3834 inst = 0x1e602800 | sljit_get_float_register_index(SLJIT_FR0)
3835 | (sljit_get_float_register_index(SLJIT_FR0) << 5)
3836 | (sljit_get_float_register_index(SLJIT_FR1) << 16);
3837 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3838 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
3839 /* fadd frD, frA, frB */
3840 inst = (63 << 26) | (21 << 1) | (sljit_get_float_register_index(SLJIT_FR0) << 21)
3841 | (sljit_get_float_register_index(SLJIT_FR0) << 16)
3842 | (sljit_get_float_register_index(SLJIT_FR1) << 11);
3843 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3844 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
3845 /* add.d fd, fs, ft */
3846 inst = (17 << 26) | (17 << 21) | (sljit_get_float_register_index(SLJIT_FR0) << 6)
3847 | (sljit_get_float_register_index(SLJIT_FR0) << 11)
3848 | (sljit_get_float_register_index(SLJIT_FR1) << 16);
3849 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3850 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3851 /* faddd rd, rs1, rs2 */
3852 inst = (0x2 << 30) | (0x34 << 19) | (0x42 << 5)
3853 | (sljit_get_float_register_index(SLJIT_FR0) << 25)
3854 | (sljit_get_float_register_index(SLJIT_FR0) << 14)
3855 | sljit_get_float_register_index(SLJIT_FR1);
3856 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3857 #endif
3858 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64), SLJIT_FR0, 0);
3859 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
3861 code.code = sljit_generate_code(compiler);
3862 CHECK(compiler);
3863 sljit_free_compiler(compiler);
3865 code.func1((sljit_sw)&buf);
3866 FAILED(buf[2] != 11.25, "test41 case 3 failed\n");
3868 sljit_free_code(code.code);
3871 successful_tests++;
3874 static void test42(void)
3876 /* Test long multiply and division. */
3877 executable_code code;
3878 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
3879 sljit_s32 i;
3880 sljit_sw buf[7 + 4 + 8 + 8];
3882 if (verbose)
3883 printf("Run test42\n");
3885 FAILED(!compiler, "cannot create compiler\n");
3886 for (i = 0; i < 7 + 4 + 8 + 8; i++)
3887 buf[i] = -1;
3889 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 5, 5, 0, 0, 0);
3891 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -0x1fb308a);
3892 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0xf50c873);
3893 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_IMM, 0x8a0475b);
3894 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, 0x9dc849b);
3895 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, -0x7c69a35);
3896 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, 0x5a4d0c4);
3897 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S4, 0, SLJIT_IMM, 0x9a3b06d);
3899 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3900 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3901 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3902 sljit_emit_op0(compiler, SLJIT_LMUL_UW);
3903 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R0, 0);
3904 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R1, 0);
3906 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3907 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3908 sljit_emit_op0(compiler, SLJIT_LMUL_SW);
3909 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_R0, 0);
3910 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_R1, 0);
3912 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3913 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3914 sljit_emit_op0(compiler, SLJIT_DIVMOD_UW);
3915 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_R0, 0);
3916 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_R1, 0);
3918 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3919 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3920 sljit_emit_op0(compiler, SLJIT_DIVMOD_SW);
3921 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_R0, 0);
3922 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_sw), SLJIT_R1, 0);
3924 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x5cf783d3cf0a74b0));
3925 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3d5df42d03a28fc7));
3926 sljit_emit_op0(compiler, SLJIT_DIVMOD_U32);
3927 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
3928 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R1, 0, SLJIT_R1, 0);
3929 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 15 * sizeof(sljit_sw), SLJIT_R0, 0);
3930 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 16 * sizeof(sljit_sw), SLJIT_R1, 0);
3932 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x371df5197ba26a28));
3933 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x46c78a5cfd6a420c));
3934 sljit_emit_op0(compiler, SLJIT_DIVMOD_S32);
3935 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
3936 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R1, 0, SLJIT_R1, 0);
3937 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 17 * sizeof(sljit_sw), SLJIT_R0, 0);
3938 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_sw), SLJIT_R1, 0);
3940 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xc456f048c28a611b));
3941 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3d4af2c543));
3942 sljit_emit_op0(compiler, SLJIT_DIV_UW);
3943 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 19 * sizeof(sljit_sw), SLJIT_R0, 0);
3944 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 20 * sizeof(sljit_sw), SLJIT_R1, 0);
3946 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x720fa4b74c329b14));
3947 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0xa64ae42b7d6));
3948 sljit_emit_op0(compiler, SLJIT_DIV_SW);
3949 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 21 * sizeof(sljit_sw), SLJIT_R0, 0);
3950 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 22 * sizeof(sljit_sw), SLJIT_R1, 0);
3952 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x4af51c027b34));
3953 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x9ba4ff2906b14));
3954 sljit_emit_op0(compiler, SLJIT_DIV_U32);
3955 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
3956 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R1, 0, SLJIT_R1, 0);
3957 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 23 * sizeof(sljit_sw), SLJIT_R0, 0);
3958 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 24 * sizeof(sljit_sw), SLJIT_R1, 0);
3960 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xc40b58a3f20d));
3961 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(-0xa63c923));
3962 sljit_emit_op0(compiler, SLJIT_DIV_S32);
3963 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
3964 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R1, 0, SLJIT_R1, 0);
3965 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 25 * sizeof(sljit_sw), SLJIT_R0, 0);
3966 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 26 * sizeof(sljit_sw), SLJIT_R1, 0);
3968 #else
3969 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -0x58cd67f5);
3970 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x3cb088df);
3971 sljit_emit_op0(compiler, SLJIT_LMUL_UW);
3972 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R0, 0);
3973 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R1, 0);
3975 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -0x58cd67f5);
3976 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x3cb088df);
3977 sljit_emit_op0(compiler, SLJIT_LMUL_SW);
3978 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_R0, 0);
3979 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_R1, 0);
3981 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -0x58cd67f5);
3982 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x3cb088df);
3983 sljit_emit_op0(compiler, SLJIT_DIVMOD_UW);
3984 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_R0, 0);
3985 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_R1, 0);
3987 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -0x58cd67f5);
3988 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x3cb088df);
3989 sljit_emit_op0(compiler, SLJIT_DIVMOD_SW);
3990 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_R0, 0);
3991 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_sw), SLJIT_R1, 0);
3993 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0xcf0a74b0);
3994 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 0x03a28fc7);
3995 sljit_emit_op0(compiler, SLJIT_DIVMOD_U32);
3996 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 15 * sizeof(sljit_sw), SLJIT_R0, 0);
3997 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 16 * sizeof(sljit_sw), SLJIT_R1, 0);
3999 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x7ba26a28);
4000 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)0xfd6a420c);
4001 sljit_emit_op0(compiler, SLJIT_DIVMOD_S32);
4002 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 17 * sizeof(sljit_sw), SLJIT_R0, 0);
4003 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_sw), SLJIT_R1, 0);
4005 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x9d4b7036));
4006 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0xb86d0));
4007 sljit_emit_op0(compiler, SLJIT_DIV_UW);
4008 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 19 * sizeof(sljit_sw), SLJIT_R0, 0);
4009 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 20 * sizeof(sljit_sw), SLJIT_R1, 0);
4011 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x58b0692c));
4012 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0xd357));
4013 sljit_emit_op0(compiler, SLJIT_DIV_SW);
4014 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 21 * sizeof(sljit_sw), SLJIT_R0, 0);
4015 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 22 * sizeof(sljit_sw), SLJIT_R1, 0);
4017 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1c027b34));
4018 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0xf2906b14));
4019 sljit_emit_op0(compiler, SLJIT_DIV_U32);
4020 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
4021 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R1, 0, SLJIT_R1, 0);
4022 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 23 * sizeof(sljit_sw), SLJIT_R0, 0);
4023 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 24 * sizeof(sljit_sw), SLJIT_R1, 0);
4025 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x58a3f20d));
4026 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(-0xa63c923));
4027 sljit_emit_op0(compiler, SLJIT_DIV_S32);
4028 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
4029 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R1, 0, SLJIT_R1, 0);
4030 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 25 * sizeof(sljit_sw), SLJIT_R0, 0);
4031 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 26 * sizeof(sljit_sw), SLJIT_R1, 0);
4032 #endif
4034 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R2, 0);
4035 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R3, 0);
4036 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R4, 0);
4037 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_S1, 0);
4038 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_S2, 0);
4039 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_S3, 0);
4040 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_S4, 0);
4042 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
4044 code.code = sljit_generate_code(compiler);
4045 CHECK(compiler);
4046 sljit_free_compiler(compiler);
4048 code.func1((sljit_sw)&buf);
4050 FAILED(buf[0] != -0x1fb308a, "test42 case 1 failed\n");
4051 FAILED(buf[1] != 0xf50c873, "test42 case 2 failed\n");
4052 FAILED(buf[2] != 0x8a0475b, "test42 case 3 failed\n");
4053 FAILED(buf[3] != 0x9dc849b, "test42 case 4 failed\n");
4054 FAILED(buf[4] != -0x7c69a35, "test42 case 5 failed\n");
4055 FAILED(buf[5] != 0x5a4d0c4, "test42 case 6 failed\n");
4056 FAILED(buf[6] != 0x9a3b06d, "test42 case 7 failed\n");
4058 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4059 FAILED(buf[7] != SLJIT_W(-4388959407985636971), "test42 case 8 failed\n");
4060 FAILED(buf[8] != SLJIT_W(2901680654366567099), "test42 case 9 failed\n");
4061 FAILED(buf[9] != SLJIT_W(-4388959407985636971), "test42 case 10 failed\n");
4062 FAILED(buf[10] != SLJIT_W(-1677173957268872740), "test42 case 11 failed\n");
4063 FAILED(buf[11] != SLJIT_W(2), "test42 case 12 failed\n");
4064 FAILED(buf[12] != SLJIT_W(2532236178951865933), "test42 case 13 failed\n");
4065 FAILED(buf[13] != SLJIT_W(-1), "test42 case 14 failed\n");
4066 FAILED(buf[14] != SLJIT_W(-2177944059851366166), "test42 case 15 failed\n");
4067 #else
4068 FAILED(buf[7] != -1587000939, "test42 case 8 failed\n");
4069 FAILED(buf[8] != 665003983, "test42 case 9 failed\n");
4070 FAILED(buf[9] != -1587000939, "test42 case 10 failed\n");
4071 FAILED(buf[10] != -353198352, "test42 case 11 failed\n");
4072 FAILED(buf[11] != 2, "test42 case 12 failed\n");
4073 FAILED(buf[12] != 768706125, "test42 case 13 failed\n");
4074 FAILED(buf[13] != -1, "test42 case 14 failed\n");
4075 FAILED(buf[14] != -471654166, "test42 case 15 failed\n");
4076 #endif
4078 FAILED(buf[15] != SLJIT_W(56), "test42 case 16 failed\n");
4079 FAILED(buf[16] != SLJIT_W(58392872), "test42 case 17 failed\n");
4080 FAILED(buf[17] != SLJIT_W(-47), "test42 case 18 failed\n");
4081 FAILED(buf[18] != SLJIT_W(35949148), "test42 case 19 failed\n");
4083 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4084 FAILED(buf[19] != SLJIT_W(0x3340bfc), "test42 case 20 failed\n");
4085 FAILED(buf[20] != SLJIT_W(0x3d4af2c543), "test42 case 21 failed\n");
4086 FAILED(buf[21] != SLJIT_W(-0xaf978), "test42 case 22 failed\n");
4087 FAILED(buf[22] != SLJIT_W(0xa64ae42b7d6), "test42 case 23 failed\n");
4088 #else
4089 FAILED(buf[19] != SLJIT_W(0xda5), "test42 case 20 failed\n");
4090 FAILED(buf[20] != SLJIT_W(0xb86d0), "test42 case 21 failed\n");
4091 FAILED(buf[21] != SLJIT_W(-0x6b6e), "test42 case 22 failed\n");
4092 FAILED(buf[22] != SLJIT_W(0xd357), "test42 case 23 failed\n");
4093 #endif
4095 FAILED(buf[23] != SLJIT_W(0x0), "test42 case 24 failed\n");
4096 FAILED(buf[24] != SLJIT_W(0xf2906b14), "test42 case 25 failed\n");
4097 FAILED(buf[25] != SLJIT_W(-0x8), "test42 case 26 failed\n");
4098 FAILED(buf[26] != SLJIT_W(-0xa63c923), "test42 case 27 failed\n");
4100 sljit_free_code(code.code);
4101 successful_tests++;
4104 static void test43(void)
4106 /* Test floating point compare. */
4107 executable_code code;
4108 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4109 struct sljit_jump* jump;
4111 union {
4112 sljit_f64 value;
4113 struct {
4114 sljit_u32 value1;
4115 sljit_u32 value2;
4116 } u;
4117 } dbuf[4];
4119 if (verbose)
4120 printf("Run test43\n");
4122 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
4123 if (verbose)
4124 printf("no fpu available, test43 skipped\n");
4125 successful_tests++;
4126 if (compiler)
4127 sljit_free_compiler(compiler);
4128 return;
4131 FAILED(!compiler, "cannot create compiler\n");
4133 dbuf[0].value = 12.125;
4134 /* a NaN */
4135 dbuf[1].u.value1 = 0x7fffffff;
4136 dbuf[1].u.value2 = 0x7fffffff;
4137 dbuf[2].value = -13.5;
4138 dbuf[3].value = 12.125;
4140 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 1, 1, 3, 0, 0);
4141 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
4142 /* dbuf[0] < dbuf[2] -> -2 */
4143 jump = sljit_emit_fcmp(compiler, SLJIT_GREATER_EQUAL_F64, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_F64_SHIFT);
4144 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, -2);
4146 sljit_set_label(jump, sljit_emit_label(compiler));
4147 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 0);
4148 /* dbuf[0] and dbuf[1] is not NaN -> 5 */
4149 jump = sljit_emit_fcmp(compiler, SLJIT_UNORDERED_F64, SLJIT_MEM0(), (sljit_sw)&dbuf[1], SLJIT_FR1, 0);
4150 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, 5);
4152 sljit_set_label(jump, sljit_emit_label(compiler));
4153 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f64));
4154 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 11);
4155 /* dbuf[0] == dbuf[3] -> 11 */
4156 jump = sljit_emit_fcmp(compiler, SLJIT_EQUAL_F64, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_FR2, 0);
4158 /* else -> -17 */
4159 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, -17);
4160 sljit_set_label(jump, sljit_emit_label(compiler));
4161 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
4163 code.code = sljit_generate_code(compiler);
4164 CHECK(compiler);
4165 sljit_free_compiler(compiler);
4167 FAILED(code.func1((sljit_sw)&dbuf) != 11, "test43 case 1 failed\n");
4168 dbuf[3].value = 12;
4169 FAILED(code.func1((sljit_sw)&dbuf) != -17, "test43 case 2 failed\n");
4170 dbuf[1].value = 0;
4171 FAILED(code.func1((sljit_sw)&dbuf) != 5, "test43 case 3 failed\n");
4172 dbuf[2].value = 20;
4173 FAILED(code.func1((sljit_sw)&dbuf) != -2, "test43 case 4 failed\n");
4175 sljit_free_code(code.code);
4176 successful_tests++;
4179 static void test44(void)
4181 /* Test mov. */
4182 executable_code code;
4183 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4184 void *buf[5];
4186 if (verbose)
4187 printf("Run test44\n");
4189 FAILED(!compiler, "cannot create compiler\n");
4191 buf[0] = buf + 2;
4192 buf[1] = NULL;
4193 buf[2] = NULL;
4194 buf[3] = NULL;
4195 buf[4] = NULL;
4196 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 2, 0, 0, 0);
4198 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 0);
4199 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_p), SLJIT_R0, 0);
4200 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_p));
4201 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 2);
4202 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_MEM2(SLJIT_S0, SLJIT_R1), SLJIT_POINTER_SHIFT, SLJIT_R0, 0);
4203 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_p));
4204 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 3 << SLJIT_POINTER_SHIFT);
4205 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_S0, 0);
4206 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_MEM2(SLJIT_R2, SLJIT_R1), 0, SLJIT_R0, 0);
4207 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 2 * sizeof(sljit_p));
4208 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1 << SLJIT_POINTER_SHIFT);
4209 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_MEM2(SLJIT_R2, SLJIT_R1), 2, SLJIT_R0, 0);
4211 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
4213 code.code = sljit_generate_code(compiler);
4214 CHECK(compiler);
4215 sljit_free_compiler(compiler);
4217 FAILED(code.func1((sljit_sw)&buf) != (sljit_sw)(buf + 2), "test44 case 1 failed\n");
4218 FAILED(buf[1] != buf + 2, "test44 case 2 failed\n");
4219 FAILED(buf[2] != buf + 3, "test44 case 3 failed\n");
4220 FAILED(buf[3] != buf + 4, "test44 case 4 failed\n");
4221 FAILED(buf[4] != buf + 2, "test44 case 5 failed\n");
4223 sljit_free_code(code.code);
4224 successful_tests++;
4227 static void test45(void)
4229 /* Test single precision floating point. */
4231 executable_code code;
4232 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4233 sljit_f32 buf[12];
4234 sljit_sw buf2[6];
4235 struct sljit_jump* jump;
4237 if (verbose)
4238 printf("Run test45\n");
4240 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
4241 if (verbose)
4242 printf("no fpu available, test45 skipped\n");
4243 successful_tests++;
4244 if (compiler)
4245 sljit_free_compiler(compiler);
4246 return;
4249 FAILED(!compiler, "cannot create compiler\n");
4251 buf[0] = 5.5;
4252 buf[1] = -7.25;
4253 buf[2] = 0;
4254 buf[3] = 0;
4255 buf[4] = 0;
4256 buf[5] = 0;
4257 buf[6] = 0;
4258 buf[7] = 8.75;
4259 buf[8] = 0;
4260 buf[9] = 16.5;
4261 buf[10] = 0;
4262 buf[11] = 0;
4264 buf2[0] = -1;
4265 buf2[1] = -1;
4266 buf2[2] = -1;
4267 buf2[3] = -1;
4268 buf2[4] = -1;
4269 buf2[5] = -1;
4271 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 3, 2, 6, 0, 0);
4273 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 0);
4274 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4275 sljit_emit_fop1(compiler, SLJIT_NEG_F32, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f32), SLJIT_FR0, 0);
4276 sljit_emit_fop1(compiler, SLJIT_ABS_F32, SLJIT_FR1, 0, SLJIT_FR5, 0);
4277 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f32), SLJIT_FR1, 0);
4278 sljit_emit_fop1(compiler, SLJIT_ABS_F32, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f32), SLJIT_FR5, 0);
4279 sljit_emit_fop1(compiler, SLJIT_NEG_F32, SLJIT_FR4, 0, SLJIT_MEM1(SLJIT_S0), 0);
4280 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f32), SLJIT_FR4, 0);
4282 sljit_emit_fop2(compiler, SLJIT_ADD_F32, SLJIT_FR0, 0, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4283 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f32), SLJIT_FR0, 0);
4284 sljit_emit_fop2(compiler, SLJIT_SUB_F32, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_f32), SLJIT_FR5, 0);
4285 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 0);
4286 sljit_emit_fop2(compiler, SLJIT_MUL_F32, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_f32), SLJIT_FR0, 0, SLJIT_FR0, 0);
4287 sljit_emit_fop2(compiler, SLJIT_DIV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f32), SLJIT_FR0, 0);
4288 sljit_emit_fop1(compiler, SLJIT_ABS_F32, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f32), SLJIT_FR2, 0);
4289 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 0x3d0ac);
4290 sljit_emit_fop1(compiler, SLJIT_NEG_F32, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_R0), 0x3d0ac);
4291 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 0x3d0ac + sizeof(sljit_f32));
4292 sljit_emit_fop1(compiler, SLJIT_ABS_F32, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_R0), -0x3d0ac);
4294 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 0);
4295 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4296 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 0);
4297 cond_set(compiler, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_EQUAL_F32);
4298 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_LESS_F, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 0);
4299 cond_set(compiler, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_sw), SLJIT_LESS_F32);
4300 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
4301 cond_set(compiler, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_sw), SLJIT_EQUAL_F32);
4302 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_GREATER_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
4303 cond_set(compiler, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw), SLJIT_GREATER_EQUAL_F32);
4305 jump = sljit_emit_fcmp(compiler, SLJIT_LESS_EQUAL_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4306 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_sw), SLJIT_IMM, 7);
4307 sljit_set_label(jump, sljit_emit_label(compiler));
4309 jump = sljit_emit_fcmp(compiler, SLJIT_GREATER_F32, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_FR2, 0);
4310 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_sw), SLJIT_IMM, 6);
4311 sljit_set_label(jump, sljit_emit_label(compiler));
4313 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
4315 code.code = sljit_generate_code(compiler);
4316 CHECK(compiler);
4317 sljit_free_compiler(compiler);
4319 code.func2((sljit_sw)&buf, (sljit_sw)&buf2);
4320 FAILED(buf[2] != -5.5, "test45 case 1 failed\n");
4321 FAILED(buf[3] != 7.25, "test45 case 2 failed\n");
4322 FAILED(buf[4] != 7.25, "test45 case 3 failed\n");
4323 FAILED(buf[5] != -5.5, "test45 case 4 failed\n");
4324 FAILED(buf[6] != -1.75, "test45 case 5 failed\n");
4325 FAILED(buf[7] != 16.0, "test45 case 6 failed\n");
4326 FAILED(buf[8] != 30.25, "test45 case 7 failed\n");
4327 FAILED(buf[9] != 3, "test45 case 8 failed\n");
4328 FAILED(buf[10] != -5.5, "test45 case 9 failed\n");
4329 FAILED(buf[11] != 7.25, "test45 case 10 failed\n");
4330 FAILED(buf2[0] != 1, "test45 case 11 failed\n");
4331 FAILED(buf2[1] != 2, "test45 case 12 failed\n");
4332 FAILED(buf2[2] != 2, "test45 case 13 failed\n");
4333 FAILED(buf2[3] != 1, "test45 case 14 failed\n");
4334 FAILED(buf2[4] != 7, "test45 case 15 failed\n");
4335 FAILED(buf2[5] != -1, "test45 case 16 failed\n");
4337 sljit_free_code(code.code);
4338 successful_tests++;
4341 static void test46(void)
4343 /* Test sljit_emit_op_flags with 32 bit operations. */
4345 executable_code code;
4346 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4347 sljit_s32 buf[24];
4348 sljit_sw buf2[6];
4349 sljit_s32 i;
4351 if (verbose)
4352 printf("Run test46\n");
4354 for (i = 0; i < 24; ++i)
4355 buf[i] = -17;
4356 buf[16] = 0;
4357 for (i = 0; i < 6; ++i)
4358 buf2[i] = -13;
4359 buf2[4] = -124;
4361 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 3, 3, 0, 0, 0);
4363 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -7);
4364 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, 13);
4365 sljit_emit_op_flags(compiler, SLJIT_MOV32, SLJIT_MEM0(), (sljit_sw)&buf, SLJIT_LESS);
4366 sljit_emit_op_flags(compiler, SLJIT_AND32, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_s32), SLJIT_NOT_ZERO);
4368 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, -7);
4369 sljit_emit_op_flags(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_s32), SLJIT_EQUAL);
4370 sljit_emit_op_flags(compiler, SLJIT_AND32, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_s32), SLJIT_NOT_EQUAL);
4371 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x1235);
4372 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0x1235);
4373 sljit_emit_op_flags(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_ZERO);
4374 sljit_emit_op_flags(compiler, SLJIT_AND32, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_s32), SLJIT_ZERO32);
4375 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_s32), SLJIT_R0, 0);
4377 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, -7);
4378 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 12);
4379 sljit_emit_op_flags(compiler, SLJIT_MOV32, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 2, SLJIT_EQUAL);
4380 sljit_emit_op_flags(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_EQUAL);
4381 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_s32), SLJIT_R0, 0);
4382 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 16);
4383 sljit_emit_op_flags(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 2, SLJIT_EQUAL);
4384 sljit_emit_op_flags(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_s32), SLJIT_NOT_EQUAL32);
4386 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, -7);
4387 sljit_emit_op_flags(compiler, SLJIT_XOR32 | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), 20 * sizeof(sljit_s32), SLJIT_ZERO);
4388 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 39);
4389 sljit_emit_op_flags(compiler, SLJIT_XOR32, SLJIT_R0, 0, SLJIT_NOT_ZERO);
4390 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S0), 22 * sizeof(sljit_s32), SLJIT_R0, 0);
4392 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, -7);
4393 sljit_emit_op_flags(compiler, SLJIT_AND, SLJIT_MEM0(), (sljit_sw)&buf2, SLJIT_GREATER);
4394 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, 5);
4395 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
4396 sljit_emit_op_flags(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_SIG_LESS);
4397 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
4398 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, 5);
4399 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_LESS);
4400 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_NOT_EQUAL);
4401 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, 5);
4402 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw), SLJIT_S2, 0);
4403 sljit_emit_op_flags(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_SIG_LESS);
4404 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_sw), SLJIT_ZERO);
4405 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, 0);
4406 sljit_emit_op_flags(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_sw), SLJIT_GREATER);
4408 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
4410 code.code = sljit_generate_code(compiler);
4411 CHECK(compiler);
4412 sljit_free_compiler(compiler);
4414 code.func2((sljit_sw)&buf, (sljit_sw)&buf2);
4415 FAILED(buf[0] != 0, "test46 case 1 failed\n");
4416 FAILED(buf[1] != -17, "test46 case 2 failed\n");
4417 FAILED(buf[2] != 1, "test46 case 3 failed\n");
4418 FAILED(buf[3] != -17, "test46 case 4 failed\n");
4419 FAILED(buf[4] != 1, "test46 case 5 failed\n");
4420 FAILED(buf[5] != -17, "test46 case 6 failed\n");
4421 FAILED(buf[6] != 1, "test46 case 7 failed\n");
4422 FAILED(buf[7] != -17, "test46 case 8 failed\n");
4423 FAILED(buf[8] != 0, "test46 case 9 failed\n");
4424 FAILED(buf[9] != -17, "test46 case 10 failed\n");
4425 FAILED(buf[10] != 1, "test46 case 11 failed\n");
4426 FAILED(buf[11] != -17, "test46 case 12 failed\n");
4427 FAILED(buf[12] != 1, "test46 case 13 failed\n");
4428 FAILED(buf[13] != -17, "test46 case 14 failed\n");
4429 FAILED(buf[14] != 1, "test46 case 15 failed\n");
4430 FAILED(buf[15] != -17, "test46 case 16 failed\n");
4431 FAILED(buf[16] != 0, "test46 case 17 failed\n");
4432 FAILED(buf[17] != -17, "test46 case 18 failed\n");
4433 FAILED(buf[18] != 0, "test46 case 19 failed\n");
4434 FAILED(buf[19] != -17, "test46 case 20 failed\n");
4435 FAILED(buf[20] != -18, "test46 case 21 failed\n");
4436 FAILED(buf[21] != -17, "test46 case 22 failed\n");
4437 FAILED(buf[22] != 38, "test46 case 23 failed\n");
4438 FAILED(buf[23] != -17, "test46 case 24 failed\n");
4440 FAILED(buf2[0] != 0, "test46 case 25 failed\n");
4441 FAILED(buf2[1] != 1, "test46 case 26 failed\n");
4442 FAILED(buf2[2] != 0, "test46 case 27 failed\n");
4443 FAILED(buf2[3] != 1, "test46 case 28 failed\n");
4444 FAILED(buf2[4] != -123, "test46 case 29 failed\n");
4445 FAILED(buf2[5] != -14, "test46 case 30 failed\n");
4447 sljit_free_code(code.code);
4448 successful_tests++;
4451 static void test47(void)
4453 /* Test jump optimizations. */
4454 executable_code code;
4455 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4456 sljit_sw buf[3];
4458 if (verbose)
4459 printf("Run test47\n");
4461 FAILED(!compiler, "cannot create compiler\n");
4462 buf[0] = 0;
4463 buf[1] = 0;
4464 buf[2] = 0;
4466 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 0, 0, 0);
4467 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x3a5c6f);
4468 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 3);
4469 sljit_set_target(sljit_emit_jump(compiler, SLJIT_LESS), 0x11223344);
4470 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
4471 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xd37c10);
4472 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4473 sljit_set_target(sljit_emit_jump(compiler, SLJIT_LESS), SLJIT_W(0x112233445566));
4474 #endif
4475 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
4476 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x59b48e);
4477 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4478 sljit_set_target(sljit_emit_jump(compiler, SLJIT_LESS), SLJIT_W(0x1122334455667788));
4479 #endif
4480 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
4481 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
4483 code.code = sljit_generate_code(compiler);
4484 CHECK(compiler);
4485 sljit_free_compiler(compiler);
4487 code.func1((sljit_sw)&buf);
4488 FAILED(buf[0] != 0x3a5c6f, "test47 case 1 failed\n");
4489 FAILED(buf[1] != 0xd37c10, "test47 case 2 failed\n");
4490 FAILED(buf[2] != 0x59b48e, "test47 case 3 failed\n");
4492 sljit_free_code(code.code);
4493 successful_tests++;
4496 static void test48(void)
4498 /* Test floating point conversions. */
4499 executable_code code;
4500 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4501 int i;
4502 sljit_f64 dbuf[10];
4503 sljit_f32 sbuf[10];
4504 sljit_sw wbuf[10];
4505 sljit_s32 ibuf[10];
4507 if (verbose)
4508 printf("Run test48\n");
4510 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
4511 if (verbose)
4512 printf("no fpu available, test48 skipped\n");
4513 successful_tests++;
4514 if (compiler)
4515 sljit_free_compiler(compiler);
4516 return;
4519 FAILED(!compiler, "cannot create compiler\n");
4520 for (i = 0; i < 10; i++) {
4521 dbuf[i] = 0.0;
4522 sbuf[i] = 0.0;
4523 wbuf[i] = 0;
4524 ibuf[i] = 0;
4527 dbuf[0] = 123.5;
4528 dbuf[1] = -367;
4529 dbuf[2] = 917.75;
4531 sbuf[0] = 476.25;
4532 sbuf[1] = -1689.75;
4534 wbuf[0] = 2345;
4536 ibuf[0] = 312;
4537 ibuf[1] = -9324;
4539 sljit_emit_enter(compiler, 0, 0, 3, 3, 6, 0, 0);
4540 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, (sljit_sw)&dbuf);
4541 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, (sljit_sw)&sbuf);
4542 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, (sljit_sw)&wbuf);
4543 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, (sljit_sw)&ibuf);
4545 /* sbuf[2] */
4546 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_F64, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_S0), 0);
4547 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), 0);
4548 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 3);
4549 /* sbuf[3] */
4550 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_F64, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_F32_SHIFT, SLJIT_FR5, 0);
4551 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_F32, SLJIT_FR4, 0, SLJIT_MEM1(SLJIT_S1), 0);
4552 /* dbuf[3] */
4553 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f64), SLJIT_FR4, 0);
4554 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR3, 0, SLJIT_MEM1(SLJIT_S1), 0);
4555 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_F32, SLJIT_FR2, 0, SLJIT_FR3, 0);
4556 /* dbuf[4] */
4557 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f64), SLJIT_FR2, 0);
4558 /* sbuf[4] */
4559 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_f32), SLJIT_FR3, 0);
4561 /* wbuf[1] */
4562 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F64, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
4563 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
4564 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F64, SLJIT_R0, 0, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_F64_SHIFT);
4565 /* wbuf[2] */
4566 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
4567 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S1), 0);
4568 /* wbuf[3] */
4569 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F32, SLJIT_MEM1(SLJIT_S2), 3 * sizeof(sljit_sw), SLJIT_FR5, 0);
4570 sljit_emit_fop1(compiler, SLJIT_NEG_F32, SLJIT_FR0, 0, SLJIT_FR5, 0);
4571 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 4);
4572 /* wbuf[4] */
4573 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F32, SLJIT_MEM2(SLJIT_S2, SLJIT_R1), SLJIT_WORD_SHIFT, SLJIT_FR0, 0);
4574 sljit_emit_fop1(compiler, SLJIT_NEG_F64, SLJIT_FR4, 0, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64));
4575 /* ibuf[2] */
4576 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F64, SLJIT_MEM1(SLJIT_R2), 2 * sizeof(sljit_s32), SLJIT_FR4, 0);
4577 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f32));
4578 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F32, SLJIT_R0, 0, SLJIT_FR1, 0);
4579 /* ibuf[3] */
4580 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM1(SLJIT_R2), 3 * sizeof(sljit_s32), SLJIT_R0, 0);
4582 /* dbuf[5] */
4583 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_S2), 0);
4584 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_FR2, 0, SLJIT_IMM, -6213);
4585 /* dbuf[6] */
4586 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64), SLJIT_FR2, 0);
4587 /* dbuf[7] */
4588 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_S32, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_f64), SLJIT_MEM0(), (sljit_sw)&ibuf[0]);
4589 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R2), sizeof(sljit_s32));
4590 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_S32, SLJIT_FR1, 0, SLJIT_R0, 0);
4591 /* dbuf[8] */
4592 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_f64), SLJIT_FR1, 0);
4593 /* dbuf[9] */
4594 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_MEM0(), (sljit_sw)(dbuf + 9), SLJIT_IMM, -77);
4595 /* sbuf[5] */
4596 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_SW, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_f32), SLJIT_IMM, -123);
4597 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 7190);
4598 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_SW, SLJIT_FR3, 0, SLJIT_R0, 0);
4599 /* sbuf[6] */
4600 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 6 * sizeof(sljit_f32), SLJIT_FR3, 0);
4601 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 123);
4602 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_R2, 0, SLJIT_IMM, 123 * sizeof(sljit_s32));
4603 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_S32, SLJIT_FR1, 0, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 2);
4604 /* sbuf[7] */
4605 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 7 * sizeof(sljit_f32), SLJIT_FR1, 0);
4606 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
4607 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 3812);
4608 /* sbuf[8] */
4609 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_S32, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_F32_SHIFT, SLJIT_R1, 0);
4610 /* sbuf[9] */
4611 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_SW, SLJIT_MEM0(), (sljit_sw)(sbuf + 9), SLJIT_IMM, -79);
4613 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
4615 code.code = sljit_generate_code(compiler);
4616 CHECK(compiler);
4617 sljit_free_compiler(compiler);
4619 code.func0();
4620 FAILED(dbuf[3] != 476.25, "test48 case 1 failed\n");
4621 FAILED(dbuf[4] != 476.25, "test48 case 2 failed\n");
4622 FAILED(dbuf[5] != 2345.0, "test48 case 3 failed\n");
4623 FAILED(dbuf[6] != -6213.0, "test48 case 4 failed\n");
4624 FAILED(dbuf[7] != 312.0, "test48 case 5 failed\n");
4625 FAILED(dbuf[8] != -9324.0, "test48 case 6 failed\n");
4626 FAILED(dbuf[9] != -77.0, "test48 case 7 failed\n");
4628 FAILED(sbuf[2] != 123.5, "test48 case 8 failed\n");
4629 FAILED(sbuf[3] != 123.5, "test48 case 9 failed\n");
4630 FAILED(sbuf[4] != 476.25, "test48 case 10 failed\n");
4631 FAILED(sbuf[5] != -123, "test48 case 11 failed\n");
4632 FAILED(sbuf[6] != 7190, "test48 case 12 failed\n");
4633 FAILED(sbuf[7] != 312, "test48 case 13 failed\n");
4634 FAILED(sbuf[8] != 3812, "test48 case 14 failed\n");
4635 FAILED(sbuf[9] != -79.0, "test48 case 15 failed\n");
4637 FAILED(wbuf[1] != -367, "test48 case 16 failed\n");
4638 FAILED(wbuf[2] != 917, "test48 case 17 failed\n");
4639 FAILED(wbuf[3] != 476, "test48 case 18 failed\n");
4640 FAILED(wbuf[4] != -476, "test48 case 19 failed\n");
4642 FAILED(ibuf[2] != -917, "test48 case 20 failed\n");
4643 FAILED(ibuf[3] != -1689, "test48 case 21 failed\n");
4645 sljit_free_code(code.code);
4646 successful_tests++;
4649 static void test49(void)
4651 /* Test floating point conversions. */
4652 executable_code code;
4653 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4654 int i;
4655 sljit_f64 dbuf[10];
4656 sljit_f32 sbuf[9];
4657 sljit_sw wbuf[9];
4658 sljit_s32 ibuf[9];
4659 sljit_s32* dbuf_ptr = (sljit_s32*)dbuf;
4660 sljit_s32* sbuf_ptr = (sljit_s32*)sbuf;
4662 if (verbose)
4663 printf("Run test49\n");
4665 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
4666 if (verbose)
4667 printf("no fpu available, test49 skipped\n");
4668 successful_tests++;
4669 if (compiler)
4670 sljit_free_compiler(compiler);
4671 return;
4674 FAILED(!compiler, "cannot create compiler\n");
4676 for (i = 0; i < 9; i++) {
4677 dbuf_ptr[i << 1] = -1;
4678 dbuf_ptr[(i << 1) + 1] = -1;
4679 sbuf_ptr[i] = -1;
4680 wbuf[i] = -1;
4681 ibuf[i] = -1;
4684 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4685 dbuf[9] = (sljit_f64)SLJIT_W(0x1122334455);
4686 #endif
4687 dbuf[0] = 673.75;
4688 sbuf[0] = -879.75;
4689 wbuf[0] = 345;
4690 ibuf[0] = -249;
4692 sljit_emit_enter(compiler, 0, 0, 3, 3, 3, 0, 0);
4693 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, (sljit_sw)&dbuf);
4694 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, (sljit_sw)&sbuf);
4695 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, (sljit_sw)&wbuf);
4696 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, (sljit_sw)&ibuf);
4698 /* dbuf[2] */
4699 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_F32, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_S1), 0);
4700 /* sbuf[2] */
4701 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_F64, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_S0), 0);
4702 /* wbuf[2] */
4703 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F64, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 0);
4704 /* wbuf[4] */
4705 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F32, SLJIT_MEM1(SLJIT_S2), 4 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S1), 0);
4706 /* ibuf[2] */
4707 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F64, SLJIT_MEM1(SLJIT_R2), 2 * sizeof(sljit_s32), SLJIT_MEM1(SLJIT_S0), 0);
4708 /* ibuf[4] */
4709 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F32, SLJIT_MEM1(SLJIT_R2), 4 * sizeof(sljit_s32), SLJIT_MEM1(SLJIT_S1), 0);
4710 /* dbuf[4] */
4711 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_S2), 0);
4712 /* sbuf[4] */
4713 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_SW, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_S2), 0);
4714 /* dbuf[6] */
4715 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_S32, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_R2), 0);
4716 /* sbuf[6] */
4717 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_S32, SLJIT_MEM1(SLJIT_S1), 6 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_R2), 0);
4719 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4720 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F64, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f64));
4721 /* wbuf[8] */
4722 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S2), 8 * sizeof(sljit_sw), SLJIT_R0, 0);
4723 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f64));
4724 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F64, SLJIT_R0, 0, SLJIT_FR2, 0);
4725 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
4726 sljit_emit_op2(compiler, SLJIT_AND32, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffff);
4727 /* ibuf[8] */
4728 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_R2), 8 * sizeof(sljit_s32), SLJIT_R0, 0);
4729 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x4455667788));
4730 /* dbuf[8] */
4731 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_f64), SLJIT_R0, 0);
4732 /* dbuf[9] */
4733 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_S32, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f64), SLJIT_IMM, SLJIT_W(0x7766554433));
4734 #endif
4736 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
4738 code.code = sljit_generate_code(compiler);
4739 CHECK(compiler);
4740 sljit_free_compiler(compiler);
4742 code.func0();
4744 FAILED(dbuf_ptr[(1 * 2) + 0] != -1, "test49 case 1 failed\n");
4745 FAILED(dbuf_ptr[(1 * 2) + 1] != -1, "test49 case 2 failed\n");
4746 FAILED(dbuf[2] != -879.75, "test49 case 3 failed\n");
4747 FAILED(dbuf_ptr[(3 * 2) + 0] != -1, "test49 case 4 failed\n");
4748 FAILED(dbuf_ptr[(3 * 2) + 1] != -1, "test49 case 5 failed\n");
4749 FAILED(dbuf[4] != 345, "test49 case 6 failed\n");
4750 FAILED(dbuf_ptr[(5 * 2) + 0] != -1, "test49 case 7 failed\n");
4751 FAILED(dbuf_ptr[(5 * 2) + 1] != -1, "test49 case 8 failed\n");
4752 FAILED(dbuf[6] != -249, "test49 case 9 failed\n");
4753 FAILED(dbuf_ptr[(7 * 2) + 0] != -1, "test49 case 10 failed\n");
4754 FAILED(dbuf_ptr[(7 * 2) + 1] != -1, "test49 case 11 failed\n");
4756 FAILED(sbuf_ptr[1] != -1, "test49 case 12 failed\n");
4757 FAILED(sbuf[2] != 673.75, "test49 case 13 failed\n");
4758 FAILED(sbuf_ptr[3] != -1, "test49 case 14 failed\n");
4759 FAILED(sbuf[4] != 345, "test49 case 15 failed\n");
4760 FAILED(sbuf_ptr[5] != -1, "test49 case 16 failed\n");
4761 FAILED(sbuf[6] != -249, "test49 case 17 failed\n");
4762 FAILED(sbuf_ptr[7] != -1, "test49 case 18 failed\n");
4764 FAILED(wbuf[1] != -1, "test49 case 19 failed\n");
4765 FAILED(wbuf[2] != 673, "test49 case 20 failed\n");
4766 FAILED(wbuf[3] != -1, "test49 case 21 failed\n");
4767 FAILED(wbuf[4] != -879, "test49 case 22 failed\n");
4768 FAILED(wbuf[5] != -1, "test49 case 23 failed\n");
4770 FAILED(ibuf[1] != -1, "test49 case 24 failed\n");
4771 FAILED(ibuf[2] != 673, "test49 case 25 failed\n");
4772 FAILED(ibuf[3] != -1, "test49 case 26 failed\n");
4773 FAILED(ibuf[4] != -879, "test49 case 27 failed\n");
4774 FAILED(ibuf[5] != -1, "test49 case 28 failed\n");
4776 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4777 FAILED(dbuf[8] != (sljit_f64)SLJIT_W(0x4455667788), "test49 case 29 failed\n");
4778 FAILED(dbuf[9] != (sljit_f64)SLJIT_W(0x66554433), "test49 case 30 failed\n");
4779 FAILED(wbuf[8] != SLJIT_W(0x1122334455), "test48 case 31 failed\n");
4780 FAILED(ibuf[8] == 0x4455, "test48 case 32 failed\n");
4781 #endif
4783 sljit_free_code(code.code);
4784 successful_tests++;
4787 static void test50(void)
4789 /* Test stack and floating point operations. */
4790 executable_code code;
4791 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4792 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4793 sljit_uw size1, size2, size3;
4794 int result;
4795 #endif
4796 sljit_f32 sbuf[7];
4798 if (verbose)
4799 printf("Run test50\n");
4801 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
4802 if (verbose)
4803 printf("no fpu available, test50 skipped\n");
4804 successful_tests++;
4805 if (compiler)
4806 sljit_free_compiler(compiler);
4807 return;
4810 FAILED(!compiler, "cannot create compiler\n");
4812 sbuf[0] = 245.5;
4813 sbuf[1] = -100.25;
4814 sbuf[2] = 713.75;
4816 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 3, 6, 0, 8 * sizeof(sljit_f32));
4818 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_MEM1(SLJIT_S0), 0);
4819 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), 0);
4820 /* sbuf[3] */
4821 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), sizeof(sljit_f32));
4822 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_f32), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4823 sljit_emit_fop2(compiler, SLJIT_ADD_F32, SLJIT_MEM1(SLJIT_SP), 2 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), 0, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_f32));
4824 /* sbuf[4] */
4825 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), 2 * sizeof(sljit_f32));
4826 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 2 * sizeof(sljit_f32), SLJIT_IMM, 5934);
4827 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_SW, SLJIT_MEM1(SLJIT_SP), 3 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), 2 * sizeof(sljit_f32));
4828 /* sbuf[5] */
4829 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), 3 * sizeof(sljit_f32));
4831 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4832 size1 = compiler->size;
4833 #endif
4834 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f32));
4835 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4836 size2 = compiler->size;
4837 #endif
4838 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR5, 0, SLJIT_FR2, 0);
4839 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4840 size3 = compiler->size;
4841 #endif
4842 /* sbuf[6] */
4843 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f32), SLJIT_FR5, 0);
4844 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4845 result = (compiler->size - size3) == (size3 - size2) && (size3 - size2) == (size2 - size1);
4846 #endif
4848 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
4850 code.code = sljit_generate_code(compiler);
4851 CHECK(compiler);
4852 sljit_free_compiler(compiler);
4854 code.func1((sljit_sw)&sbuf);
4856 FAILED(sbuf[3] != 245.5, "test50 case 1 failed\n");
4857 FAILED(sbuf[4] != 145.25, "test50 case 2 failed\n");
4858 FAILED(sbuf[5] != 5934, "test50 case 3 failed\n");
4859 FAILED(sbuf[6] != 713.75, "test50 case 4 failed\n");
4860 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4861 FAILED(!result, "test50 case 5 failed\n");
4862 #endif
4864 sljit_free_code(code.code);
4865 successful_tests++;
4868 static void test51(void)
4870 /* Test all registers provided by the CPU. */
4871 executable_code code;
4872 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4873 struct sljit_jump* jump;
4874 sljit_sw buf[2];
4875 sljit_s32 i;
4877 if (verbose)
4878 printf("Run test51\n");
4880 FAILED(!compiler, "cannot create compiler\n");
4882 buf[0] = 39;
4884 sljit_emit_enter(compiler, 0, 0, SLJIT_NUMBER_OF_REGISTERS, 0, 0, 0, 0);
4886 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4887 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 32);
4889 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)buf);
4890 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
4892 for (i = 2; i < SLJIT_NUMBER_OF_REGISTERS; i++) {
4893 if (sljit_get_register_index(SLJIT_R(i)) >= 0) {
4894 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_R0, 0);
4895 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_R(i)), 0);
4896 } else
4897 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, buf[0]);
4900 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 32);
4901 for (i = 2; i < SLJIT_NUMBER_OF_REGISTERS; i++) {
4902 if (sljit_get_register_index(SLJIT_R(i)) >= 0) {
4903 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_R0, 0);
4904 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_R(i)), 32);
4905 } else
4906 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, buf[0]);
4909 for (i = 2; i < SLJIT_NUMBER_OF_REGISTERS; i++) {
4910 if (sljit_get_register_index(SLJIT_R(i)) >= 0) {
4911 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 32);
4912 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM2(SLJIT_R(i), SLJIT_R0), 0);
4913 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM2(SLJIT_R0, SLJIT_R(i)), 0);
4914 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 8);
4915 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM2(SLJIT_R0, SLJIT_R(i)), 2);
4916 } else
4917 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 3 * buf[0]);
4920 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 32 + sizeof(sljit_sw), SLJIT_R1, 0);
4922 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
4924 code.code = sljit_generate_code(compiler);
4925 CHECK(compiler);
4926 sljit_free_compiler(compiler);
4928 code.func0();
4930 FAILED(buf[1] != (39 * 5 * (SLJIT_NUMBER_OF_REGISTERS - 2)), "test51 case 1 failed\n");
4932 sljit_free_code(code.code);
4934 /* Next test. */
4936 compiler = sljit_create_compiler(NULL);
4938 FAILED(!compiler, "cannot create compiler\n");
4940 sljit_emit_enter(compiler, 0, 0, SLJIT_NUMBER_OF_SCRATCH_REGISTERS, SLJIT_NUMBER_OF_SAVED_REGISTERS, 0, 0, 0);
4942 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4943 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 17);
4945 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_RET(SW));
4946 /* SLJIT_R0 contains the first value. */
4947 for (i = 1; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4948 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R(i), 0);
4950 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
4952 sljit_set_label(jump, sljit_emit_label(compiler));
4953 sljit_emit_enter(compiler, 0, 0, SLJIT_NUMBER_OF_REGISTERS, 0, 0, 0, 0);
4954 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4955 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 35);
4956 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
4958 code.code = sljit_generate_code(compiler);
4959 CHECK(compiler);
4960 sljit_free_compiler(compiler);
4962 FAILED(code.func0() != (SLJIT_NUMBER_OF_SCRATCH_REGISTERS * 35 + SLJIT_NUMBER_OF_SAVED_REGISTERS * 17), "test51 case 2 failed\n");
4964 sljit_free_code(code.code);
4966 /* Next test. */
4968 compiler = sljit_create_compiler(NULL);
4970 FAILED(!compiler, "cannot create compiler\n");
4972 sljit_emit_enter(compiler, 0, 0, SLJIT_NUMBER_OF_SCRATCH_REGISTERS, SLJIT_NUMBER_OF_SAVED_REGISTERS, 0, 0, 0);
4974 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4975 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 68);
4977 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_RET(SW));
4978 /* SLJIT_R0 contains the first value. */
4979 for (i = 1; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4980 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R(i), 0);
4982 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
4984 sljit_set_label(jump, sljit_emit_label(compiler));
4985 sljit_emit_enter(compiler, 0, 0, 0, SLJIT_NUMBER_OF_REGISTERS, 0, 0, 0);
4986 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4987 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S(i), 0, SLJIT_IMM, 43);
4988 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
4990 code.code = sljit_generate_code(compiler);
4991 CHECK(compiler);
4992 sljit_free_compiler(compiler);
4994 FAILED(code.func0() != (SLJIT_NUMBER_OF_SCRATCH_REGISTERS * 43 + SLJIT_NUMBER_OF_SAVED_REGISTERS * 68), "test51 case 3 failed\n");
4996 sljit_free_code(code.code);
4997 successful_tests++;
5000 static void test52(void)
5002 /* Test all registers provided by the CPU. */
5003 executable_code code;
5004 struct sljit_compiler* compiler;
5005 struct sljit_jump* jump;
5006 sljit_f64 buf[3];
5007 sljit_s32 i;
5009 if (verbose)
5010 printf("Run test52\n");
5012 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5013 if (verbose)
5014 printf("no fpu available, test52 skipped\n");
5015 successful_tests++;
5016 return;
5019 /* Next test. */
5021 compiler = sljit_create_compiler(NULL);
5022 FAILED(!compiler, "cannot create compiler\n");
5023 buf[0] = 6.25;
5024 buf[1] = 17.75;
5026 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 0, 1, SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS, SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS, 0);
5028 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5029 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR(i), 0, SLJIT_MEM1(SLJIT_S0), 0);
5031 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_RET(VOID));
5032 /* SLJIT_FR0 contains the first value. */
5033 for (i = 1; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5034 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR0, 0, SLJIT_FR0, 0, SLJIT_FR(i), 0);
5035 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64), SLJIT_FR0, 0);
5037 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5039 sljit_set_label(jump, sljit_emit_label(compiler));
5040 sljit_emit_enter(compiler, 0, 0, 1, 0, SLJIT_NUMBER_OF_FLOAT_REGISTERS, 0, 0);
5041 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[1]);
5042 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5043 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR(i), 0, SLJIT_MEM1(SLJIT_R0), 0);
5044 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5046 code.code = sljit_generate_code(compiler);
5047 CHECK(compiler);
5048 sljit_free_compiler(compiler);
5050 code.func1((sljit_sw)&buf);
5051 FAILED(buf[2] != (SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS * 17.75 + SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS * 6.25), "test52 case 1 failed\n");
5053 sljit_free_code(code.code);
5055 /* Next test. */
5057 compiler = sljit_create_compiler(NULL);
5058 FAILED(!compiler, "cannot create compiler\n");
5059 buf[0] = -32.5;
5060 buf[1] = -11.25;
5062 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 0, 1, SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS, SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS, 0);
5064 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5065 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR(i), 0, SLJIT_MEM1(SLJIT_S0), 0);
5067 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_RET(VOID));
5068 /* SLJIT_FR0 contains the first value. */
5069 for (i = 1; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5070 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR0, 0, SLJIT_FR0, 0, SLJIT_FR(i), 0);
5071 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64), SLJIT_FR0, 0);
5073 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5075 sljit_set_label(jump, sljit_emit_label(compiler));
5076 sljit_emit_enter(compiler, 0, 0, 1, 0, 0, SLJIT_NUMBER_OF_FLOAT_REGISTERS, 0);
5077 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[1]);
5078 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5079 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FS(i), 0, SLJIT_MEM1(SLJIT_R0), 0);
5080 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5082 code.code = sljit_generate_code(compiler);
5083 CHECK(compiler);
5084 sljit_free_compiler(compiler);
5086 code.func1((sljit_sw)&buf);
5087 FAILED(buf[2] != (SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS * -11.25 + SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS * -32.5), "test52 case 2 failed\n");
5089 sljit_free_code(code.code);
5090 successful_tests++;
5093 static void test53(void)
5095 /* Check SLJIT_DOUBLE_ALIGNMENT. */
5096 executable_code code;
5097 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
5098 sljit_sw buf[1];
5100 if (verbose)
5101 printf("Run test53\n");
5103 FAILED(!compiler, "cannot create compiler\n");
5104 buf[0] = -1;
5106 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, SLJIT_ARG1(SW), 1, 1, 0, 0, 2 * sizeof(sljit_sw));
5108 sljit_get_local_base(compiler, SLJIT_R0, 0, 0);
5109 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
5111 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5113 code.code = sljit_generate_code(compiler);
5114 CHECK(compiler);
5115 sljit_free_compiler(compiler);
5117 code.func1((sljit_sw)&buf);
5119 FAILED((buf[0] & (sizeof(sljit_f64) - 1)) != 0, "test53 case 1 failed\n");
5121 sljit_free_code(code.code);
5123 /* Next test. */
5125 compiler = sljit_create_compiler(NULL);
5126 FAILED(!compiler, "cannot create compiler\n");
5127 buf[0] = -1;
5129 /* One more saved register to break the alignment on x86-32. */
5130 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, SLJIT_ARG1(SW), 1, 2, 0, 0, 2 * sizeof(sljit_sw));
5132 sljit_get_local_base(compiler, SLJIT_R0, 0, 0);
5133 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
5135 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5137 code.code = sljit_generate_code(compiler);
5138 CHECK(compiler);
5139 sljit_free_compiler(compiler);
5141 code.func1((sljit_sw)&buf);
5143 FAILED((buf[0] & (sizeof(sljit_f64) - 1)) != 0, "test53 case 2 failed\n");
5145 sljit_free_code(code.code);
5146 successful_tests++;
5149 static void test54(void)
5151 /* Check cmov. */
5152 executable_code code;
5153 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
5154 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
5155 sljit_sw large_num = SLJIT_W(0x1234567812345678);
5156 #else
5157 sljit_sw large_num = SLJIT_W(0x12345678);
5158 #endif
5159 int i;
5160 sljit_sw buf[19];
5161 sljit_s32 ibuf[4];
5163 union {
5164 sljit_f32 value;
5165 sljit_s32 s32_value;
5166 } sbuf[3];
5168 sbuf[0].s32_value = 0x7fffffff;
5169 sbuf[1].value = 7.5;
5170 sbuf[2].value = -14.75;
5172 if (verbose)
5173 printf("Run test54\n");
5175 FAILED(!compiler, "cannot create compiler\n");
5177 for (i = 0; i < 19; i++)
5178 buf[i] = 0;
5179 for (i = 0; i < 4; i++)
5180 ibuf[i] = 0;
5182 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), 5, 3, 3, 0, 0);
5184 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 17);
5185 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 34);
5186 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, -10);
5187 sljit_emit_cmov(compiler, SLJIT_SIG_LESS, SLJIT_R0, SLJIT_R1, 0);
5188 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
5189 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, -10);
5190 sljit_emit_cmov(compiler, SLJIT_SIG_GREATER, SLJIT_R0, SLJIT_R1, 0);
5191 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
5193 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 24);
5194 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 24);
5195 sljit_emit_cmov(compiler, SLJIT_NOT_EQUAL, SLJIT_R0, SLJIT_IMM, 66);
5196 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
5197 sljit_emit_cmov(compiler, SLJIT_EQUAL, SLJIT_R0, SLJIT_IMM, 78);
5198 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_R0, 0);
5199 sljit_emit_cmov(compiler, SLJIT_EQUAL, SLJIT_R0, SLJIT_IMM, large_num);
5200 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
5202 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
5203 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R3) == -1 && sljit_get_register_index(SLJIT_R4) == -1);
5204 #endif
5205 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 7);
5206 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -45);
5207 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_OVERFLOW, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 8);
5208 sljit_emit_cmov(compiler, SLJIT_MUL_OVERFLOW, SLJIT_R3, SLJIT_IMM, 35);
5209 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R3, 0);
5210 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, large_num);
5211 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, large_num);
5212 sljit_emit_cmov(compiler, SLJIT_MUL_OVERFLOW, SLJIT_R3, SLJIT_IMM, 35);
5213 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_R3, 0);
5215 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 71);
5216 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 13);
5217 sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 8);
5218 sljit_emit_cmov(compiler, SLJIT_EQUAL, SLJIT_R3, SLJIT_R0, 0);
5219 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R3, 0);
5221 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 12);
5222 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -29);
5223 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_OVERFLOW, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 8);
5224 sljit_emit_cmov(compiler, SLJIT_MUL_NOT_OVERFLOW, SLJIT_R0, SLJIT_R3, 0);
5225 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R3, 0);
5227 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 16);
5228 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -12);
5229 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_IMM, 21);
5230 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 8);
5231 sljit_emit_cmov(compiler, SLJIT_NOT_EQUAL, SLJIT_R3, SLJIT_R4, 0);
5232 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_R3, 0);
5233 sljit_emit_cmov(compiler, SLJIT_EQUAL, SLJIT_R3, SLJIT_R4, 0);
5234 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_R3, 0);
5236 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5237 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S2), 0);
5238 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f32));
5239 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_f32));
5241 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 16);
5242 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
5243 sljit_emit_cmov(compiler, SLJIT_EQUAL_F32, SLJIT_R0, SLJIT_IMM, -45);
5244 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_R0, 0);
5245 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_GREATER_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
5246 sljit_emit_cmov(compiler, SLJIT_GREATER_F32, SLJIT_R0, SLJIT_IMM, -45);
5247 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_R0, 0);
5248 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_GREATER_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
5249 sljit_emit_cmov(compiler, SLJIT_GREATER_EQUAL_F32, SLJIT_R0, SLJIT_IMM, 33);
5250 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_R0, 0);
5252 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
5253 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_LESS_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
5254 sljit_emit_cmov(compiler, SLJIT_LESS_F32, SLJIT_R0, SLJIT_IMM, -70);
5255 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_sw), SLJIT_R0, 0);
5256 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_LESS_EQUAL_F, SLJIT_FR2, 0, SLJIT_FR1, 0);
5257 sljit_emit_cmov(compiler, SLJIT_LESS_EQUAL_F32, SLJIT_R0, SLJIT_IMM, -60);
5258 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 15 * sizeof(sljit_sw), SLJIT_R0, 0);
5259 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_NOT_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
5260 sljit_emit_cmov(compiler, SLJIT_NOT_EQUAL_F32, SLJIT_R0, SLJIT_IMM, 31);
5261 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 16 * sizeof(sljit_sw), SLJIT_R0, 0);
5263 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 53);
5264 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_ORDERED_F, SLJIT_FR1, 0, SLJIT_FR0, 0);
5265 sljit_emit_cmov(compiler, SLJIT_ORDERED_F32, SLJIT_R0, SLJIT_IMM, 17);
5266 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 17 * sizeof(sljit_sw), SLJIT_R0, 0);
5267 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_UNORDERED_F, SLJIT_FR1, 0, SLJIT_FR0, 0);
5268 sljit_emit_cmov(compiler, SLJIT_UNORDERED_F32, SLJIT_R0, SLJIT_IMM, 59);
5269 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_sw), SLJIT_R0, 0);
5272 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 177);
5273 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 178);
5274 sljit_emit_cmov(compiler, SLJIT_LESS32, SLJIT_R0 | SLJIT_I32_OP, SLJIT_IMM, 200);
5275 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_R0, 0);
5277 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 95);
5278 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R3, 0, SLJIT_IMM, 177);
5279 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_LESS_EQUAL, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 95);
5280 sljit_emit_cmov(compiler, SLJIT_LESS_EQUAL, SLJIT_R3 | SLJIT_I32_OP, SLJIT_R0, 0);
5281 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0);
5282 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32), SLJIT_R3, 0);
5284 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R3, 0, SLJIT_IMM, 56);
5285 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R4, 0, SLJIT_IMM, -63);
5286 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_SIG_LESS, SLJIT_UNUSED, 0, SLJIT_R3, 0, SLJIT_R4, 0);
5287 sljit_emit_cmov(compiler, SLJIT_SIG_LESS32, SLJIT_R3 | SLJIT_I32_OP, SLJIT_R4, 0);
5288 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_s32), SLJIT_R3, 0);
5289 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_SIG_GREATER, SLJIT_UNUSED, 0, SLJIT_R3, 0, SLJIT_R4, 0);
5290 sljit_emit_cmov(compiler, SLJIT_SIG_GREATER32, SLJIT_R3 | SLJIT_I32_OP, SLJIT_R4, 0);
5291 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_s32), SLJIT_R3, 0);
5293 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5295 code.code = sljit_generate_code(compiler);
5296 CHECK(compiler);
5297 sljit_free_compiler(compiler);
5299 code.func3((sljit_sw)&buf, (sljit_sw)&ibuf, (sljit_sw)&sbuf);
5301 FAILED(buf[0] != 17, "test54 case 1 failed\n");
5302 FAILED(buf[1] != 34, "test54 case 2 failed\n");
5303 FAILED(buf[2] != 24, "test54 case 3 failed\n");
5304 FAILED(buf[3] != 78, "test54 case 4 failed\n");
5305 FAILED(buf[4] != large_num, "test54 case 5 failed\n");
5306 FAILED(buf[5] != -45, "test54 case 6 failed\n");
5307 FAILED(buf[6] != 35, "test54 case 7 failed\n");
5308 FAILED(buf[7] != 71, "test54 case 8 failed\n");
5309 FAILED(buf[8] != -29, "test54 case 9 failed\n");
5310 FAILED(buf[9] != -12, "test54 case 10 failed\n");
5311 FAILED(buf[10] != 21, "test54 case 11 failed\n");
5313 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5314 FAILED(buf[11] != 16, "test54 case 12 failed\n");
5315 FAILED(buf[12] != -45, "test54 case 13 failed\n");
5316 FAILED(buf[13] != 33, "test54 case 14 failed\n");
5317 FAILED(buf[14] != 8, "test54 case 15 failed\n");
5318 FAILED(buf[15] != -60, "test54 case 16 failed\n");
5319 FAILED(buf[16] != 31, "test54 case 17 failed\n");
5320 FAILED(buf[17] != 53, "test54 case 18 failed\n");
5321 FAILED(buf[18] != 59, "test54 case 19 failed\n");
5324 FAILED(ibuf[0] != 200, "test54 case 12 failed\n");
5325 FAILED(ibuf[1] != 95, "test54 case 13 failed\n");
5326 FAILED(ibuf[2] != 56, "test54 case 14 failed\n");
5327 FAILED(ibuf[3] != -63, "test54 case 15 failed\n");
5329 sljit_free_code(code.code);
5330 successful_tests++;
5333 static void test55(void)
5335 /* Check value preservation. */
5336 executable_code code;
5337 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
5338 sljit_sw buf[2];
5339 sljit_s32 i;
5341 if (verbose)
5342 printf("Run test55\n");
5344 FAILED(!compiler, "cannot create compiler\n");
5345 buf[0] = 0;
5346 buf[1] = 0;
5348 sljit_emit_enter(compiler, 0, 0, SLJIT_NUMBER_OF_REGISTERS, 0, 0, 0, sizeof (sljit_sw));
5350 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, 217);
5352 /* Check 1 */
5353 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5354 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 118);
5356 sljit_emit_op0(compiler, SLJIT_DIVMOD_SW);
5358 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
5360 for (i = 2; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5361 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R(i), 0);
5362 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_SP), 0);
5364 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM0(), (sljit_sw)(buf + 0), SLJIT_R0, 0);
5366 /* Check 2 */
5367 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5368 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 146);
5370 sljit_emit_op0(compiler, SLJIT_DIV_SW);
5372 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
5374 for (i = 1; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5375 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R(i), 0);
5376 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_SP), 0);
5378 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM0(), (sljit_sw)(buf + 1), SLJIT_R0, 0);
5380 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5382 code.code = sljit_generate_code(compiler);
5383 CHECK(compiler);
5384 sljit_free_compiler(compiler);
5386 code.func0();
5388 FAILED(buf[0] != (SLJIT_NUMBER_OF_REGISTERS - 2) * 118 + 217, "test55 case 1 failed\n");
5389 FAILED(buf[1] != (SLJIT_NUMBER_OF_REGISTERS - 1) * 146 + 217, "test55 case 2 failed\n");
5391 sljit_free_code(code.code);
5392 successful_tests++;
5395 static void test56(void)
5397 /* Check integer substraction with negative immediate. */
5398 executable_code code;
5399 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
5400 sljit_sw buf[13];
5401 sljit_s32 i;
5403 if (verbose)
5404 printf("Run test56\n");
5406 for (i = 0; i < 13; i++)
5407 buf[i] = 77;
5409 FAILED(!compiler, "cannot create compiler\n");
5411 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 0, 0, 0);
5413 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 90 << 12);
5414 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5415 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R1, 0);
5416 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_SIG_GREATER);
5417 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5418 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R1, 0);
5419 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_LESS);
5420 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER_EQUAL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5421 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_SIG_GREATER_EQUAL);
5422 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS_EQUAL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5423 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_LESS_EQUAL);
5424 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5425 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_GREATER);
5426 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5427 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_SIG_LESS);
5429 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 90);
5430 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, -91);
5431 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R0, 0);
5432 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_SIG_GREATER);
5433 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 90);
5434 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, -91);
5435 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_LESS_EQUAL);
5437 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, -0x7fffffff);
5438 sljit_emit_op2(compiler, SLJIT_ADD32 | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5439 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_OVERFLOW32);
5441 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)-0x80000000);
5442 sljit_emit_op1(compiler, SLJIT_NEG32 | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R0, 0);
5443 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_OVERFLOW32);
5445 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5447 code.code = sljit_generate_code(compiler);
5448 CHECK(compiler);
5449 sljit_free_compiler(compiler);
5451 code.func1((sljit_sw)&buf);
5453 FAILED(buf[0] != (181 << 12), "test56 case 1 failed\n");
5454 FAILED(buf[1] != 1, "test56 case 2 failed\n");
5455 FAILED(buf[2] != (181 << 12), "test56 case 3 failed\n");
5456 FAILED(buf[3] != 1, "test56 case 4 failed\n");
5457 FAILED(buf[4] != 1, "test56 case 5 failed\n");
5458 FAILED(buf[5] != 1, "test56 case 6 failed\n");
5459 FAILED(buf[6] != 0, "test56 case 7 failed\n");
5460 FAILED(buf[7] != 0, "test56 case 8 failed\n");
5461 FAILED(buf[8] != 181, "test56 case 9 failed\n");
5462 FAILED(buf[9] != 1, "test56 case 10 failed\n");
5463 FAILED(buf[10] != 1, "test56 case 11 failed\n");
5464 FAILED(buf[11] != 1, "test56 case 12 failed\n");
5465 FAILED(buf[12] != 1, "test56 case 13 failed\n");
5467 sljit_free_code(code.code);
5468 successful_tests++;
5471 static void test57(void)
5473 /* Check prefetch instructions. */
5474 executable_code code;
5475 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
5476 struct sljit_label* labels[5];
5478 if (verbose)
5479 printf("Run test57\n");
5481 FAILED(!compiler, "cannot create compiler\n");
5483 sljit_emit_enter(compiler, 0, 0, 3, 1, 0, 0, 0);
5485 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
5486 labels[0] = sljit_emit_label(compiler);
5487 /* Should never crash. */
5488 sljit_emit_op_src(compiler, SLJIT_PREFETCH_L1, SLJIT_MEM2(SLJIT_R0, SLJIT_R0), 2);
5489 labels[1] = sljit_emit_label(compiler);
5490 sljit_emit_op_src(compiler, SLJIT_PREFETCH_L2, SLJIT_MEM0(), 0);
5491 labels[2] = sljit_emit_label(compiler);
5492 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
5493 sljit_emit_op_src(compiler, SLJIT_PREFETCH_L3, SLJIT_MEM1(SLJIT_R0), SLJIT_W(0x1122334455667788));
5494 #else
5495 sljit_emit_op_src(compiler, SLJIT_PREFETCH_L3, SLJIT_MEM1(SLJIT_R0), 0x11223344);
5496 #endif
5497 labels[3] = sljit_emit_label(compiler);
5498 sljit_emit_op_src(compiler, SLJIT_PREFETCH_ONCE, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_sw));
5499 labels[4] = sljit_emit_label(compiler);
5501 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5503 code.code = sljit_generate_code(compiler);
5504 CHECK(compiler);
5505 sljit_free_compiler(compiler);
5507 code.func0();
5509 if (sljit_has_cpu_feature(SLJIT_HAS_PREFETCH)) {
5510 FAILED(sljit_get_label_addr(labels[0]) == sljit_get_label_addr(labels[1]), "test57 case 1 failed\n");
5511 FAILED(sljit_get_label_addr(labels[1]) == sljit_get_label_addr(labels[2]), "test57 case 2 failed\n");
5512 FAILED(sljit_get_label_addr(labels[2]) == sljit_get_label_addr(labels[3]), "test57 case 3 failed\n");
5513 FAILED(sljit_get_label_addr(labels[3]) == sljit_get_label_addr(labels[4]), "test57 case 4 failed\n");
5515 else {
5516 FAILED(sljit_get_label_addr(labels[0]) != sljit_get_label_addr(labels[1]), "test57 case 1 failed\n");
5517 FAILED(sljit_get_label_addr(labels[1]) != sljit_get_label_addr(labels[2]), "test57 case 2 failed\n");
5518 FAILED(sljit_get_label_addr(labels[2]) != sljit_get_label_addr(labels[3]), "test57 case 3 failed\n");
5519 FAILED(sljit_get_label_addr(labels[3]) != sljit_get_label_addr(labels[4]), "test57 case 4 failed\n");
5522 sljit_free_code(code.code);
5523 successful_tests++;
5526 static sljit_f64 SLJIT_FUNC test58_f1(sljit_f32 a, sljit_f32 b, sljit_f64 c)
5528 return a + b + c;
5531 static sljit_f32 SLJIT_FUNC test58_f2(sljit_sw a, sljit_f64 b, sljit_f32 c)
5533 return a + b + c;
5536 static sljit_f64 SLJIT_FUNC test58_f3(sljit_sw a, sljit_f32 b, sljit_sw c)
5538 return a + b + c;
5541 static sljit_f64 test58_f4(sljit_f32 a, sljit_sw b)
5543 return a + b;
5546 static sljit_f32 test58_f5(sljit_f32 a, sljit_f64 b, sljit_s32 c)
5548 return a + b + c;
5551 static sljit_sw SLJIT_FUNC test58_f6(sljit_f64 a, sljit_sw b)
5553 return (sljit_sw)a + b;
5556 static void test58(void)
5558 /* Check function calls with floating point arguments. */
5559 executable_code code;
5560 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
5561 struct sljit_jump* jump = NULL;
5562 sljit_f64 dbuf[7];
5563 sljit_f32 sbuf[7];
5564 sljit_sw wbuf[2];
5566 if (verbose)
5567 printf("Run test58\n");
5569 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5570 if (verbose)
5571 printf("no fpu available, test58 skipped\n");
5572 successful_tests++;
5573 if (compiler)
5574 sljit_free_compiler(compiler);
5575 return;
5578 dbuf[0] = 5.25;
5579 dbuf[1] = 0.0;
5580 dbuf[2] = 2.5;
5581 dbuf[3] = 0.0;
5582 dbuf[4] = 0.0;
5583 dbuf[5] = 0.0;
5584 dbuf[6] = -18.0;
5586 sbuf[0] = 6.75;
5587 sbuf[1] = -3.5;
5588 sbuf[2] = 1.5;
5589 sbuf[3] = 0.0;
5590 sbuf[4] = 0.0;
5592 wbuf[0] = 0;
5593 wbuf[1] = 0;
5595 FAILED(!compiler, "cannot create compiler\n");
5597 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), 3, 3, 4, 0, sizeof(sljit_sw));
5599 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), 0);
5600 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f32));
5601 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 0);
5602 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(F64) | SLJIT_ARG1(F32) | SLJIT_ARG2(F32) | SLJIT_ARG3(F64), SLJIT_IMM, SLJIT_FUNC_OFFSET(test58_f1));
5603 /* dbuf[1] */
5604 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64), SLJIT_FR0, 0);
5606 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f32));
5607 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f32));
5608 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64));
5609 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_RET(F64) | SLJIT_ARG1(F32) | SLJIT_ARG2(F32) | SLJIT_ARG3(F64));
5610 sljit_set_target(jump, SLJIT_FUNC_OFFSET(test58_f1));
5611 /* dbuf[3] */
5612 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f64), SLJIT_FR0, 0);
5614 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(test58_f2));
5615 sljit_get_local_base(compiler, SLJIT_R1, 0, -16);
5616 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 16);
5617 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 0);
5618 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f32));
5619 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(F32) | SLJIT_ARG1(SW) | SLJIT_ARG2(F64) | SLJIT_ARG3(F32), SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 0);
5620 /* sbuf[3] */
5621 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f32), SLJIT_FR0, 0);
5623 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -4);
5624 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 9);
5625 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 0);
5626 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), 0);
5627 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_RET(F64) | SLJIT_ARG1(SW) | SLJIT_ARG2(F32) | SLJIT_ARG3(SW));
5628 sljit_set_target(jump, SLJIT_FUNC_OFFSET(test58_f3));
5629 /* dbuf[4] */
5630 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f64), SLJIT_FR0, 0);
5632 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f32));
5633 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -6);
5634 jump = sljit_emit_call(compiler, SLJIT_CALL_CDECL, SLJIT_RET(F64) | SLJIT_ARG1(F32) | SLJIT_ARG2(SW));
5635 sljit_set_target(jump, SLJIT_FUNC_OFFSET(test58_f4));
5636 /* dbuf[5] */
5637 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f64), SLJIT_FR0, 0);
5639 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(test58_f5));
5640 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f32));
5641 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64));
5642 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
5643 sljit_emit_icall(compiler, SLJIT_CALL_CDECL, SLJIT_RET(F32) | SLJIT_ARG1(F32) | SLJIT_ARG2(F64) | SLJIT_ARG3(S32), SLJIT_MEM1(SLJIT_SP), 0);
5644 /* sbuf[4] */
5645 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_f32), SLJIT_FR0, 0);
5647 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64));
5648 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(test58_f6));
5649 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(F64) | SLJIT_ARG2(SW), SLJIT_R0, 0);
5650 /* wbuf[0] */
5651 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S2), 0, SLJIT_R0, 0);
5653 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64));
5654 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 319);
5655 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(test58_f6));
5656 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(F64) | SLJIT_ARG2(SW), SLJIT_R1, 0);
5657 /* wbuf[1] */
5658 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_sw), SLJIT_R0, 0);
5660 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5662 code.code = sljit_generate_code(compiler);
5663 CHECK(compiler);
5664 sljit_free_compiler(compiler);
5666 code.func3((sljit_sw)&dbuf, (sljit_sw)&sbuf, (sljit_sw)&wbuf);
5668 FAILED(dbuf[1] != 8.5, "test58 case 1 failed\n");
5669 FAILED(dbuf[3] != 0.5, "test58 case 2 failed\n");
5670 FAILED(sbuf[3] != 17.75, "test58 case 3 failed\n");
5671 FAILED(dbuf[4] != 11.75, "test58 case 4 failed\n");
5672 FAILED(dbuf[5] != -9.5, "test58 case 5 failed\n");
5673 FAILED(sbuf[4] != 12, "test58 case 6 failed\n");
5674 FAILED(wbuf[0] != SLJIT_FUNC_OFFSET(test58_f6) - 18, "test58 case 7 failed\n");
5675 FAILED(wbuf[1] != 301, "test58 case 8 failed\n");
5677 sljit_free_code(code.code);
5678 successful_tests++;
5681 static sljit_sw SLJIT_FUNC test59_f1(sljit_sw a, sljit_s32 b, sljit_sw c, sljit_sw d)
5683 return (sljit_sw)(a + b + c + d - SLJIT_FUNC_OFFSET(test59_f1));
5686 static sljit_sw test59_f2(sljit_sw a, sljit_s32 b, sljit_sw c, sljit_sw d)
5688 return (sljit_sw)(a + b + c + d - SLJIT_FUNC_OFFSET(test59_f2));
5691 static sljit_s32 SLJIT_FUNC test59_f3(sljit_f64 a, sljit_f32 b, sljit_f64 c, sljit_sw d)
5693 return (sljit_s32)(a + b + c + d);
5696 static sljit_f32 SLJIT_FUNC test59_f4(sljit_f32 a, sljit_s32 b, sljit_f64 c, sljit_sw d)
5698 return (sljit_f32)(a + b + c + d);
5701 static sljit_f32 SLJIT_FUNC test59_f5(sljit_f32 a, sljit_f64 b, sljit_f32 c, sljit_f64 d)
5703 return (sljit_f32)(a + b + c + d);
5706 static void test59(void)
5708 /* Check function calls with four arguments. */
5709 executable_code code;
5710 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
5711 struct sljit_jump* jump = NULL;
5712 sljit_sw wbuf[6];
5713 sljit_f64 dbuf[3];
5714 sljit_f32 sbuf[4];
5716 if (verbose)
5717 printf("Run test59\n");
5719 wbuf[0] = 0;
5720 wbuf[1] = 0;
5721 wbuf[2] = 0;
5722 wbuf[3] = SLJIT_FUNC_OFFSET(test59_f1);
5723 wbuf[4] = 0;
5724 wbuf[5] = 0;
5726 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5727 dbuf[0] = 5.125;
5728 dbuf[1] = 6.125;
5729 dbuf[2] = 4.25;
5731 sbuf[0] = 0.75;
5732 sbuf[1] = -1.5;
5733 sbuf[2] = 0.0;
5734 sbuf[3] = 0.0;
5737 FAILED(!compiler, "cannot create compiler\n");
5739 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), 4, 3, 4, 0, sizeof(sljit_sw));
5741 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 33);
5742 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -20);
5743 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(test59_f1));
5744 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -40);
5745 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(S32) | SLJIT_ARG3(SW) | SLJIT_ARG4(SW), SLJIT_R2, 0);
5746 /* wbuf[0] */
5747 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
5749 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 16);
5750 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -30);
5751 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 50);
5752 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(test59_f2));
5753 sljit_emit_icall(compiler, SLJIT_CALL_CDECL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(S32) | SLJIT_ARG3(SW) | SLJIT_ARG4(SW), SLJIT_R3, 0);
5754 /* wbuf[1] */
5755 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
5757 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(test59_f1));
5758 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -25);
5759 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 100);
5760 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -10);
5761 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(S32) | SLJIT_ARG3(SW) | SLJIT_ARG4(SW), SLJIT_R0, 0);
5762 /* wbuf[2] */
5763 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
5765 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
5766 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 231);
5767 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 3);
5768 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(test59_f1) - 100);
5769 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(S32) | SLJIT_ARG3(SW) | SLJIT_ARG4(SW), SLJIT_MEM2(SLJIT_R0, SLJIT_R2), SLJIT_WORD_SHIFT);
5770 /* wbuf[4] */
5771 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
5773 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5774 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), 0);
5775 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S2), 0);
5776 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f64));
5777 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -100);
5778 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(S32) | SLJIT_ARG1(F64) | SLJIT_ARG2(F32) | SLJIT_ARG3(F64) | SLJIT_ARG4(SW), SLJIT_IMM, SLJIT_FUNC_OFFSET(test59_f3));
5779 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
5780 /* wbuf[5] */
5781 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R0, 0);
5783 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f32));
5784 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f64));
5785 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 36);
5786 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 41);
5787 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_RET(F32) | SLJIT_ARG1(F32) | SLJIT_ARG2(S32) | SLJIT_ARG3(F64) | SLJIT_ARG4(SW));
5788 sljit_set_target(jump, SLJIT_FUNC_OFFSET(test59_f4));
5789 /* sbuf[2] */
5790 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_f32), SLJIT_FR0, 0);
5792 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(test59_f5));
5793 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S2), 0);
5794 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), 0);
5795 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f32));
5796 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR3, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f64));
5797 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(F32) | SLJIT_ARG1(F32) | SLJIT_ARG2(F64) | SLJIT_ARG3(F32) | SLJIT_ARG4(F64), SLJIT_R0, 0);
5798 /* sbuf[2] */
5799 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S2), 3 * sizeof(sljit_f32), SLJIT_FR0, 0);
5802 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5804 code.code = sljit_generate_code(compiler);
5805 CHECK(compiler);
5806 sljit_free_compiler(compiler);
5808 code.func3((sljit_sw)&wbuf, (sljit_sw)&dbuf, (sljit_sw)&sbuf);
5810 FAILED(wbuf[0] != -27, "test59 case 1 failed\n");
5811 FAILED(wbuf[1] != 36, "test59 case 2 failed\n");
5812 FAILED(wbuf[2] != 65, "test59 case 3 failed\n");
5813 FAILED(wbuf[4] != (sljit_sw)wbuf + 134, "test59 case 4 failed\n");
5815 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5816 FAILED(wbuf[5] != -88, "test59 case 5 failed\n");
5817 FAILED(sbuf[2] != 79.75, "test59 case 6 failed\n");
5818 FAILED(sbuf[3] != 8.625, "test59 case 7 failed\n");
5821 sljit_free_code(code.code);
5822 successful_tests++;
5825 static void test60(void)
5827 /* Test memory accesses with pre/post updates. */
5828 executable_code code;
5829 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
5830 sljit_s32 i;
5831 sljit_s32 supported[10];
5832 sljit_sw wbuf[18];
5833 sljit_s8 bbuf[4];
5834 sljit_s32 ibuf[4];
5836 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
5837 static sljit_u8 expected[10] = { 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 };
5838 #elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32)
5839 static sljit_u8 expected[10] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
5840 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32)
5841 static sljit_u8 expected[10] = { 1, 0, 1, 1, 0, 1, 1, 1, 0, 0 };
5842 #elif (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
5843 static sljit_u8 expected[10] = { 1, 0, 0, 1, 0, 0, 1, 1, 0, 0 };
5844 #else
5845 static sljit_u8 expected[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
5846 #endif
5848 if (verbose)
5849 printf("Run test60\n");
5851 for (i = 0; i < 18; i++)
5852 wbuf[i] = 0;
5853 wbuf[2] = -887766;
5855 bbuf[0] = 0;
5856 bbuf[1] = 0;
5857 bbuf[2] = -13;
5859 ibuf[0] = -5678;
5860 ibuf[1] = 0;
5861 ibuf[2] = 0;
5863 FAILED(!compiler, "cannot create compiler\n");
5865 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), 4, 3, 4, 0, sizeof(sljit_sw));
5867 supported[0] = sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R0), 2 * sizeof(sljit_sw));
5868 if (supported[0] == SLJIT_SUCCESS) {
5869 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
5870 sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R0), 2 * sizeof(sljit_sw));
5871 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R1, 0);
5872 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
5875 supported[1] = sljit_emit_mem(compiler, SLJIT_MOV_S8 | SLJIT_MEM_SUPP | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM1(SLJIT_R2), -2 * (sljit_sw)sizeof(sljit_s8));
5876 if (supported[1] == SLJIT_SUCCESS) {
5877 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S1, 0, SLJIT_IMM, 2 * sizeof(sljit_s8));
5878 sljit_emit_mem(compiler, SLJIT_MOV_S8 | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM1(SLJIT_R2), -2 * (sljit_sw)sizeof(sljit_s8));
5879 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_R0, 0);
5880 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R2, 0);
5883 supported[2] = sljit_emit_mem(compiler, SLJIT_MOV_S32 | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_R2, SLJIT_MEM1(SLJIT_R1), -2 * (sljit_sw)sizeof(sljit_s32));
5884 if (supported[2] == SLJIT_SUCCESS) {
5885 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S2, 0, SLJIT_IMM, 2 * sizeof(sljit_s32));
5886 sljit_emit_mem(compiler, SLJIT_MOV_S32 | SLJIT_MEM_PRE, SLJIT_R2, SLJIT_MEM1(SLJIT_R1), -2 * (sljit_sw)sizeof(sljit_s32));
5887 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R2, 0);
5888 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_R1, 0);
5891 supported[3] = sljit_emit_mem(compiler, SLJIT_MOV32 | SLJIT_MEM_SUPP | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R2), 2 * sizeof(sljit_s32));
5892 if (supported[3] == SLJIT_SUCCESS) {
5893 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -8765);
5894 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, sizeof(sljit_s32));
5895 sljit_emit_mem(compiler, SLJIT_MOV32 | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R2), 2 * sizeof(sljit_s32));
5896 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R2, 0);
5899 supported[4] = sljit_emit_mem(compiler, SLJIT_MOV_S8 | SLJIT_MEM_SUPP | SLJIT_MEM_STORE | SLJIT_MEM_POST, SLJIT_R1, SLJIT_MEM1(SLJIT_R2), -128 * (sljit_sw)sizeof(sljit_s8));
5900 if (supported[4] == SLJIT_SUCCESS) {
5901 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -121);
5902 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_S1, 0);
5903 sljit_emit_mem(compiler, SLJIT_MOV_S8 | SLJIT_MEM_STORE | SLJIT_MEM_POST, SLJIT_R1, SLJIT_MEM1(SLJIT_R2), -128 * (sljit_sw)sizeof(sljit_s8));
5904 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R2, 0);
5907 supported[5] = sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R0), 1);
5908 if (supported[5] == SLJIT_SUCCESS) {
5909 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 9 * sizeof(sljit_sw) - 1);
5910 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -881199);
5911 sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R0), 1);
5912 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_R0, 0);
5915 supported[6] = sljit_emit_mem(compiler, SLJIT_MOV_S32 | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
5916 if (supported[6] == SLJIT_SUCCESS) {
5917 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S2, 0, SLJIT_IMM, 213);
5918 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -213);
5919 sljit_emit_mem(compiler, SLJIT_MOV_S32 | SLJIT_MEM_PRE, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
5920 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_R0, 0);
5921 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_R1, 0);
5924 supported[7] = sljit_emit_mem(compiler, SLJIT_MOV_S32 | SLJIT_MEM_SUPP | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
5925 if (supported[7] == SLJIT_SUCCESS) {
5926 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_S2, 0);
5927 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 2 * sizeof(sljit_s32));
5928 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -7890);
5929 sljit_emit_mem(compiler, SLJIT_MOV_S32 | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
5930 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_R1, 0);
5933 supported[8] = sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 2);
5934 if (supported[8] == SLJIT_SUCCESS) {
5935 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));
5936 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));
5937 sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 2);
5938 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_sw), SLJIT_R0, 0);
5939 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 15 * sizeof(sljit_sw), SLJIT_R1, 0);
5942 supported[9] = sljit_emit_mem(compiler, SLJIT_MOV_S8 | SLJIT_MEM_SUPP | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
5943 if (supported[9] == SLJIT_SUCCESS) {
5944 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S1, 0, SLJIT_IMM, 2 * sizeof(sljit_s8));
5945 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -2 * (sljit_sw)sizeof(sljit_s8));
5946 sljit_emit_mem(compiler, SLJIT_MOV_S8 | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
5947 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 16 * sizeof(sljit_sw), SLJIT_R0, 0);
5948 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 17 * sizeof(sljit_sw), SLJIT_R1, 0);
5951 SLJIT_ASSERT(sljit_emit_mem(compiler, SLJIT_MOV_S8 | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 1) == SLJIT_ERR_UNSUPPORTED);
5952 SLJIT_ASSERT(sljit_emit_mem(compiler, SLJIT_MOV_S8 | SLJIT_MEM_SUPP | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 1) == SLJIT_ERR_UNSUPPORTED);
5954 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5956 code.code = sljit_generate_code(compiler);
5957 CHECK(compiler);
5958 sljit_free_compiler(compiler);
5960 code.func3((sljit_sw)&wbuf, (sljit_sw)&bbuf, (sljit_sw)&ibuf);
5962 FAILED(sizeof(expected) != sizeof(supported) / sizeof(sljit_s32), "test60 case 1 failed\n");
5964 for (i = 0; i < sizeof(expected); i++) {
5965 if (expected[i]) {
5966 if (supported[i] != SLJIT_SUCCESS) {
5967 printf("tast60 case %d should be supported\n", i + 1);
5968 return;
5970 } else {
5971 if (supported[i] == SLJIT_SUCCESS) {
5972 printf("test60 case %d should not be supported\n", i + 1);
5973 return;
5978 FAILED(supported[0] == SLJIT_SUCCESS && wbuf[0] != -887766, "test60 case 2 failed\n");
5979 FAILED(supported[0] == SLJIT_SUCCESS && wbuf[1] != (sljit_sw)(wbuf + 2), "test60 case 3 failed\n");
5980 FAILED(supported[1] == SLJIT_SUCCESS && wbuf[3] != -13, "test60 case 4 failed\n");
5981 FAILED(supported[1] == SLJIT_SUCCESS && wbuf[4] != (sljit_sw)(bbuf), "test60 case 5 failed\n");
5982 FAILED(supported[2] == SLJIT_SUCCESS && wbuf[5] != -5678, "test60 case 6 failed\n");
5983 FAILED(supported[2] == SLJIT_SUCCESS && wbuf[6] != (sljit_sw)(ibuf), "test60 case 7 failed\n");
5984 FAILED(supported[3] == SLJIT_SUCCESS && ibuf[1] != -8765, "test60 case 8 failed\n");
5985 FAILED(supported[3] == SLJIT_SUCCESS && wbuf[7] != (sljit_sw)(ibuf + 1), "test60 case 9 failed\n");
5986 FAILED(supported[4] == SLJIT_SUCCESS && bbuf[0] != -121, "test60 case 10 failed\n");
5987 FAILED(supported[4] == SLJIT_SUCCESS && wbuf[8] != (sljit_sw)(bbuf) - 128 * sizeof(sljit_s8), "test60 case 11 failed\n");
5988 FAILED(supported[5] == SLJIT_SUCCESS && wbuf[9] != -881199, "test60 case 12 failed\n");
5989 FAILED(supported[5] == SLJIT_SUCCESS && wbuf[10] != (sljit_sw)(wbuf + 9), "test60 case 13 failed\n");
5990 FAILED(supported[6] == SLJIT_SUCCESS && wbuf[11] != -5678, "test60 case 14 failed\n");
5991 FAILED(supported[6] == SLJIT_SUCCESS && wbuf[12] != (sljit_sw)(ibuf), "test60 case 15 failed\n");
5992 FAILED(supported[7] == SLJIT_SUCCESS && ibuf[2] != -7890, "test60 case 16 failed\n");
5993 FAILED(supported[7] == SLJIT_SUCCESS && wbuf[13] != (sljit_sw)(ibuf + 2), "test60 case 17 failed\n");
5994 FAILED(supported[8] == SLJIT_SUCCESS && wbuf[14] != -887766, "test60 case 18 failed\n");
5995 FAILED(supported[8] == SLJIT_SUCCESS && wbuf[15] != (sljit_sw)(wbuf + 10), "test60 case 19 failed\n");
5996 FAILED(supported[9] == SLJIT_SUCCESS && wbuf[16] != -13, "test60 case 20 failed\n");
5997 FAILED(supported[9] == SLJIT_SUCCESS && wbuf[17] != (sljit_sw)(bbuf), "test60 case 21 failed\n");
5999 sljit_free_code(code.code);
6000 successful_tests++;
6003 static void test61(void)
6005 /* Test float memory accesses with pre/post updates. */
6006 executable_code code;
6007 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
6008 sljit_s32 i;
6009 sljit_s32 supported[6];
6010 sljit_sw wbuf[6];
6011 sljit_f64 dbuf[4];
6012 sljit_f32 sbuf[4];
6013 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
6014 static sljit_u8 expected[6] = { 1, 1, 1, 1, 0, 0 };
6015 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
6016 static sljit_u8 expected[6] = { 1, 0, 1, 0, 1, 1 };
6017 #else
6018 static sljit_u8 expected[6] = { 0, 0, 0, 0, 0, 0 };
6019 #endif
6021 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
6022 if (verbose)
6023 printf("no fpu available, test61 skipped\n");
6024 successful_tests++;
6025 if (compiler)
6026 sljit_free_compiler(compiler);
6027 return;
6030 if (verbose)
6031 printf("Run test61\n");
6033 for (i = 0; i < 6; i++)
6034 wbuf[i] = 0;
6036 dbuf[0] = 66.725;
6037 dbuf[1] = 0.0;
6038 dbuf[2] = 0.0;
6039 dbuf[3] = 0.0;
6041 sbuf[0] = 0.0;
6042 sbuf[1] = -22.125;
6043 sbuf[2] = 0.0;
6044 sbuf[3] = 0.0;
6046 FAILED(!compiler, "cannot create compiler\n");
6048 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), 4, 3, 4, 0, sizeof(sljit_sw));
6050 supported[0] = sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_FR0, SLJIT_MEM1(SLJIT_R0), 4 * sizeof(sljit_f64));
6051 if (supported[0] == SLJIT_SUCCESS) {
6052 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_IMM, 4 * sizeof(sljit_f64));
6053 sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_PRE, SLJIT_FR0, SLJIT_MEM1(SLJIT_R0), 4 * sizeof(sljit_f64));
6054 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f64), SLJIT_FR0, 0);
6055 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
6058 supported[1] = sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_SUPP | SLJIT_MEM_STORE | SLJIT_MEM_POST, SLJIT_FR2, SLJIT_MEM1(SLJIT_R0), -(sljit_sw)sizeof(sljit_f64));
6059 if (supported[1] == SLJIT_SUCCESS) {
6060 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_IMM, 2 * sizeof(sljit_f64));
6061 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), 0);
6062 sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_STORE | SLJIT_MEM_POST, SLJIT_FR2, SLJIT_MEM1(SLJIT_R0), -(sljit_sw)sizeof(sljit_f64));
6063 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
6066 supported[2] = sljit_emit_fmem(compiler, SLJIT_MOV_F32 | SLJIT_MEM_SUPP | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_FR1, SLJIT_MEM1(SLJIT_R2), -4 * (sljit_sw)sizeof(sljit_f32));
6067 if (supported[2] == SLJIT_SUCCESS) {
6068 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, 4 * sizeof(sljit_f32));
6069 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f32));
6070 sljit_emit_fmem(compiler, SLJIT_MOV_F32 | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_FR1, SLJIT_MEM1(SLJIT_R2), -4 * (sljit_sw)sizeof(sljit_f32));
6071 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R2, 0);
6074 supported[3] = sljit_emit_fmem(compiler, SLJIT_MOV_F32 | SLJIT_MEM_SUPP | SLJIT_MEM_POST, SLJIT_FR1, SLJIT_MEM1(SLJIT_R1), sizeof(sljit_f32));
6075 if (supported[3] == SLJIT_SUCCESS) {
6076 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S2, 0, SLJIT_IMM, sizeof(sljit_f32));
6077 sljit_emit_fmem(compiler, SLJIT_MOV_F32 | SLJIT_MEM_POST, SLJIT_FR1, SLJIT_MEM1(SLJIT_R1), sizeof(sljit_f32));
6078 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_f32), SLJIT_FR1, 0);
6079 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_R1, 0);
6082 supported[4] = sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_FR0, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 0);
6083 if (supported[4] == SLJIT_SUCCESS) {
6084 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S1, 0, SLJIT_IMM, 8 * sizeof(sljit_f64));
6085 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -8 * (sljit_sw)sizeof(sljit_f64));
6086 sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_PRE, SLJIT_FR0, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 0);
6087 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64), SLJIT_FR0, 0);
6088 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R1, 0);
6091 supported[5] = sljit_emit_fmem(compiler, SLJIT_MOV_F32 | SLJIT_MEM_SUPP | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_FR2, SLJIT_MEM2(SLJIT_R2, SLJIT_R1), 0);
6092 if (supported[5] == SLJIT_SUCCESS) {
6093 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_S2, 0);
6094 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 3 * sizeof(sljit_f32));
6095 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f32));
6096 sljit_emit_fmem(compiler, SLJIT_MOV_F32 | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_FR2, SLJIT_MEM2(SLJIT_R2, SLJIT_R1), 0);
6097 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R2, 0);
6100 SLJIT_ASSERT(sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_SUPP | SLJIT_MEM_POST, SLJIT_FR0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0) == SLJIT_ERR_UNSUPPORTED);
6101 SLJIT_ASSERT(sljit_emit_fmem(compiler, SLJIT_MOV_F32 | SLJIT_MEM_SUPP | SLJIT_MEM_STORE | SLJIT_MEM_POST, SLJIT_FR0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0) == SLJIT_ERR_UNSUPPORTED);
6103 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
6105 code.code = sljit_generate_code(compiler);
6106 CHECK(compiler);
6107 sljit_free_compiler(compiler);
6109 code.func3((sljit_sw)&wbuf, (sljit_sw)&dbuf, (sljit_sw)&sbuf);
6111 FAILED(sizeof(expected) != sizeof(supported) / sizeof(sljit_s32), "test61 case 1 failed\n");
6113 for (i = 0; i < sizeof(expected); i++) {
6114 if (expected[i]) {
6115 if (supported[i] != SLJIT_SUCCESS) {
6116 printf("tast61 case %d should be supported\n", i + 1);
6117 return;
6119 } else {
6120 if (supported[i] == SLJIT_SUCCESS) {
6121 printf("test61 case %d should not be supported\n", i + 1);
6122 return;
6127 FAILED(supported[0] == SLJIT_SUCCESS && dbuf[1] != 66.725, "test61 case 2 failed\n");
6128 FAILED(supported[0] == SLJIT_SUCCESS && wbuf[0] != (sljit_sw)(dbuf), "test61 case 3 failed\n");
6129 FAILED(supported[1] == SLJIT_SUCCESS && dbuf[2] != 66.725, "test61 case 4 failed\n");
6130 FAILED(supported[1] == SLJIT_SUCCESS && wbuf[1] != (sljit_sw)(dbuf + 1), "test61 case 5 failed\n");
6131 FAILED(supported[2] == SLJIT_SUCCESS && sbuf[0] != -22.125, "test61 case 6 failed\n");
6132 FAILED(supported[2] == SLJIT_SUCCESS && wbuf[2] != (sljit_sw)(sbuf), "test61 case 7 failed\n");
6133 FAILED(supported[3] == SLJIT_SUCCESS && sbuf[2] != -22.125, "test61 case 8 failed\n");
6134 FAILED(supported[3] == SLJIT_SUCCESS && wbuf[3] != (sljit_sw)(sbuf + 2), "test61 case 9 failed\n");
6135 FAILED(supported[4] == SLJIT_SUCCESS && dbuf[3] != 66.725, "test61 case 10 failed\n");
6136 FAILED(supported[4] == SLJIT_SUCCESS && wbuf[4] != (sljit_sw)(dbuf), "test61 case 11 failed\n");
6137 FAILED(supported[5] == SLJIT_SUCCESS && sbuf[3] != -22.125, "test61 case 12 failed\n");
6138 FAILED(supported[5] == SLJIT_SUCCESS && wbuf[5] != (sljit_sw)(sbuf + 3), "test61 case 13 failed\n");
6140 sljit_free_code(code.code);
6141 successful_tests++;
6144 static void test62(void)
6146 /* Test fast calls flag preservation. */
6147 executable_code code1;
6148 executable_code code2;
6149 struct sljit_compiler* compiler;
6151 if (verbose)
6152 printf("Run test62\n");
6154 /* A */
6155 compiler = sljit_create_compiler(NULL);
6156 FAILED(!compiler, "cannot create compiler\n");
6157 sljit_set_context(compiler, 0, SLJIT_ARG1(SW), 1, 1, 0, 0, 0);
6159 sljit_emit_fast_enter(compiler, SLJIT_R0, 0);
6160 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_S0, 0, SLJIT_IMM, 42);
6161 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_R0, 0);
6163 code1.code = sljit_generate_code(compiler);
6164 CHECK(compiler);
6165 sljit_free_compiler(compiler);
6167 /* B */
6168 compiler = sljit_create_compiler(NULL);
6169 FAILED(!compiler, "cannot create compiler\n");
6171 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 1, 1, 0, 0, 0);
6172 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_OFFSET(code1.code));
6173 sljit_set_current_flags(compiler, SLJIT_SET_Z | SLJIT_SET_LESS);
6174 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_ZERO);
6175 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_LESS);
6176 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
6177 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S0, 0);
6178 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
6180 code2.code = sljit_generate_code(compiler);
6181 CHECK(compiler);
6182 sljit_free_compiler(compiler);
6184 FAILED(code2.func1(88) != 0, "test62 case 1 failed\n");
6185 FAILED(code2.func1(42) != 1, "test62 case 2 failed\n");
6186 FAILED(code2.func1(0) != 2, "test62 case 3 failed\n");
6188 sljit_free_code(code1.code);
6189 sljit_free_code(code2.code);
6190 successful_tests++;
6193 static void test63(void)
6195 /* Test put label. */
6196 executable_code code;
6197 struct sljit_label *label[2];
6198 struct sljit_put_label *put_label[5];
6199 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
6200 sljit_uw addr[2];
6201 sljit_uw buf[4];
6202 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
6203 sljit_sw offs = SLJIT_W(0x123456789012);
6204 #else
6205 sljit_sw offs = 0x12345678;
6206 #endif
6208 if (verbose)
6209 printf("Run test63\n");
6211 FAILED(!compiler, "cannot create compiler\n");
6212 buf[0] = 0;
6213 buf[1] = 0;
6214 buf[2] = 0;
6215 buf[3] = 0;
6217 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 0, 0, 2 * sizeof(sljit_sw));
6219 put_label[0] = sljit_emit_put_label(compiler, SLJIT_R0, 0);
6220 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
6222 put_label[1] = sljit_emit_put_label(compiler, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw));
6223 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw));
6225 label[0] = sljit_emit_label(compiler);
6226 sljit_set_put_label(put_label[0], label[0]);
6227 sljit_set_put_label(put_label[1], label[0]);
6229 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)(buf + 2) - offs);
6230 put_label[2] = sljit_emit_put_label(compiler, SLJIT_MEM1(SLJIT_R0), offs);
6232 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (offs + sizeof(sljit_uw)) >> 1);
6233 put_label[3] = sljit_emit_put_label(compiler, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), 1);
6235 label[1] = sljit_emit_label(compiler);
6236 sljit_set_put_label(put_label[2], label[1]);
6237 sljit_set_put_label(put_label[3], label[1]);
6239 put_label[4] = sljit_emit_put_label(compiler, SLJIT_RETURN_REG, 0);
6240 sljit_set_put_label(put_label[4], label[0]);
6241 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
6243 code.code = sljit_generate_code(compiler);
6244 CHECK(compiler);
6246 addr[0] = sljit_get_label_addr(label[0]);
6247 addr[1] = sljit_get_label_addr(label[1]);
6249 sljit_free_compiler(compiler);
6251 FAILED(code.func1((sljit_sw)&buf) != addr[0], "test63 case 1 failed\n");
6252 FAILED(buf[0] != addr[0], "test63 case 2 failed\n");
6253 FAILED(buf[1] != addr[0], "test63 case 3 failed\n");
6254 FAILED(buf[2] != addr[1], "test63 case 4 failed\n");
6255 FAILED(buf[3] != addr[1], "test63 case 5 failed\n");
6257 sljit_free_code(code.code);
6258 successful_tests++;
6261 static void test64(void)
6263 /* Test put label with false labels (small offsets).
6264 This code is allocator implementation dependent. */
6265 executable_code code;
6266 sljit_sw malloc_addr;
6267 struct sljit_label label[4];
6268 struct sljit_put_label *put_label[2];
6269 struct sljit_compiler* compiler;
6270 sljit_uw buf[5];
6271 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
6272 sljit_sw offs1 = SLJIT_W(0x123456781122);
6273 sljit_sw offs2 = SLJIT_W(0x1234567811223344);
6274 #else
6275 sljit_sw offs1 = 0x12345678;
6276 sljit_sw offs2 = 0x12345678;
6277 #endif
6279 if (verbose)
6280 printf("Run test64\n");
6282 malloc_addr = (sljit_sw)SLJIT_MALLOC_EXEC(1024);
6284 if (malloc_addr == 0) {
6285 printf("Cannot allocate executable memory.");
6286 return;
6289 malloc_addr += SLJIT_EXEC_OFFSET((void*)malloc_addr);
6291 SLJIT_FREE_EXEC((void*)malloc_addr);
6293 label[0].addr = 0x1234;
6294 label[0].size = (sljit_uw)(512 - malloc_addr);
6296 label[1].addr = 0x12345678;
6297 label[1].size = (sljit_uw)(0x123456 - malloc_addr);
6299 label[2].addr = offs1;
6300 label[2].size = (sljit_uw)(offs1 - malloc_addr);
6302 label[3].addr = offs2;
6303 label[3].size = (sljit_uw)(offs2 - malloc_addr);
6305 compiler = sljit_create_compiler(NULL);
6307 FAILED(!compiler, "cannot create compiler\n");
6308 buf[0] = 0;
6309 buf[1] = 0;
6310 buf[2] = 0;
6311 buf[3] = 0;
6312 buf[4] = 0;
6314 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 0, 0, 2 * sizeof(sljit_sw));
6316 put_label[0] = sljit_emit_put_label(compiler, SLJIT_R0, 0);
6317 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
6319 put_label[1] = sljit_emit_put_label(compiler, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw));
6320 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw));
6322 sljit_set_put_label(put_label[0], &label[0]);
6323 sljit_set_put_label(put_label[1], &label[0]);
6325 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)(buf + 2) - offs1);
6326 put_label[0] = sljit_emit_put_label(compiler, SLJIT_MEM1(SLJIT_R0), offs1);
6328 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (offs1 + sizeof(sljit_uw)) >> 1);
6329 put_label[1] = sljit_emit_put_label(compiler, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), 1);
6331 sljit_set_put_label(put_label[0], &label[1]);
6332 sljit_set_put_label(put_label[1], &label[1]);
6334 put_label[0] = sljit_emit_put_label(compiler, SLJIT_R2, 0);
6335 sljit_set_put_label(put_label[0], &label[2]);
6336 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_uw), SLJIT_R2, 0);
6338 put_label[0] = sljit_emit_put_label(compiler, SLJIT_RETURN_REG, 0);
6339 sljit_set_put_label(put_label[0], &label[3]);
6340 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
6342 code.code = sljit_generate_code(compiler);
6343 CHECK(compiler);
6344 sljit_free_compiler(compiler);
6346 if ((sljit_sw)code.code < malloc_addr || (sljit_sw)code.code >= malloc_addr + 1024) {
6347 printf("test64 executable alloc estimation failed\n");
6348 return;
6351 FAILED(code.func1((sljit_sw)&buf) != label[3].addr, "test64 case 1 failed\n");
6352 FAILED(buf[0] != label[0].addr, "test64 case 2 failed\n");
6353 FAILED(buf[1] != label[0].addr, "test64 case 3 failed\n");
6354 FAILED(buf[2] != label[1].addr, "test64 case 4 failed\n");
6355 FAILED(buf[3] != label[1].addr, "test64 case 5 failed\n");
6356 FAILED(buf[4] != label[2].addr, "test64 case 6 failed\n");
6358 sljit_free_code(code.code);
6359 successful_tests++;
6362 static void test65(void)
6364 /* Test jump tables. */
6365 executable_code code;
6366 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
6367 sljit_s32 i;
6368 /* Normally this table is allocated on the heap. */
6369 sljit_uw addr[64];
6370 struct sljit_label *labels[64];
6371 struct sljit_jump *jump;
6373 if (verbose)
6374 printf("Run test65\n");
6376 FAILED(!compiler, "cannot create compiler\n");
6378 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 1, 2, 0, 0, 0);
6380 jump = sljit_emit_cmp(compiler, SLJIT_GREATER_EQUAL, SLJIT_S0, 0, SLJIT_IMM, 64);
6381 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)addr);
6382 sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_MEM2(SLJIT_R0, SLJIT_S0), SLJIT_WORD_SHIFT);
6384 for (i = 0; i < 64; i++) {
6385 labels[i] = sljit_emit_label(compiler);
6386 sljit_emit_op0(compiler, SLJIT_ENDBR);
6387 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_IMM, i * 2);
6388 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
6391 sljit_set_label(jump, sljit_emit_label(compiler));
6392 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, -1);
6394 code.code = sljit_generate_code(compiler);
6395 CHECK(compiler);
6397 for (i = 0; i < 64; i++) {
6398 addr[i] = sljit_get_label_addr(labels[i]);
6401 sljit_free_compiler(compiler);
6403 FAILED(code.func2(64, 0) != -1, "test65 case 1 failed\n");
6405 for (i = 0; i < 64; i++) {
6406 FAILED(code.func2(i, i * 2) != i * 4, "test65 case 2 failed\n");
6409 sljit_free_code(code.code);
6410 successful_tests++;
6413 static void test66(void)
6415 /* Test direct jumps (computed goto). */
6416 executable_code code;
6417 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
6418 sljit_s32 i;
6419 sljit_uw addr[64];
6420 struct sljit_label *labels[64];
6422 if (verbose)
6423 printf("Run test66\n");
6425 FAILED(!compiler, "cannot create compiler\n");
6427 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 1, 2, 0, 0, 0);
6428 sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_S0, 0);
6430 for (i = 0; i < 64; i++) {
6431 labels[i] = sljit_emit_label(compiler);
6432 sljit_emit_op0(compiler, SLJIT_ENDBR);
6433 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_IMM, i * 2);
6434 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
6437 code.code = sljit_generate_code(compiler);
6438 CHECK(compiler);
6440 for (i = 0; i < 64; i++) {
6441 addr[i] = sljit_get_label_addr(labels[i]);
6444 sljit_free_compiler(compiler);
6446 for (i = 0; i < 64; i++) {
6447 FAILED(code.func2(addr[i], i) != i * 3, "test66 case 1 failed\n");
6450 sljit_free_code(code.code);
6451 successful_tests++;
6454 static void test67(void)
6456 /* Test skipping returns from fast calls (return type is fast). */
6457 executable_code code;
6458 struct sljit_compiler *compiler = sljit_create_compiler(NULL);
6459 struct sljit_jump *call, *jump;
6460 struct sljit_label *label;
6462 if (verbose)
6463 printf("Run test67\n");
6465 FAILED(!compiler, "cannot create compiler\n");
6467 sljit_emit_enter(compiler, 0, 0, 3, 1, 0, 0, 0);
6469 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
6470 call = sljit_emit_jump(compiler, SLJIT_FAST_CALL);
6472 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
6474 /* First function, never returns. */
6475 label = sljit_emit_label(compiler);
6476 sljit_set_label(call, label);
6477 sljit_emit_fast_enter(compiler, SLJIT_R1, 0);
6479 call = sljit_emit_jump(compiler, SLJIT_FAST_CALL);
6481 /* Should never return here, marked by a segmentation fault if it does. */
6482 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
6484 /* Second function, skips the first function. */
6485 sljit_set_label(call, sljit_emit_label(compiler));
6486 sljit_emit_fast_enter(compiler, SLJIT_R2, 0);
6488 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
6490 jump = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 1);
6492 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_R1, 0);
6493 sljit_set_label(sljit_emit_jump(compiler, SLJIT_FAST_CALL), label);
6494 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
6495 sljit_emit_op_src(compiler, SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN, SLJIT_S0, 0);
6496 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_S0, 0);
6498 sljit_set_label(jump, sljit_emit_label(compiler));
6499 sljit_emit_op_src(compiler, SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN, SLJIT_R1, 0);
6500 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_R1, 0);
6502 code.code = sljit_generate_code(compiler);
6503 CHECK(compiler);
6505 sljit_free_compiler(compiler);
6507 FAILED(code.func0() != 3, "test67 case 1 failed\n");
6509 sljit_free_code(code.code);
6510 successful_tests++;
6513 static void test68(void)
6515 /* Test skipping returns from fast calls (return type is normal). */
6516 executable_code code;
6517 struct sljit_compiler *compiler;
6518 struct sljit_jump *call, *jump;
6519 struct sljit_label *label;
6520 int i;
6522 if (verbose)
6523 printf("Run test68\n");
6525 for (i = 0; i < 6 * 2; i++) {
6526 compiler = sljit_create_compiler(NULL);
6527 FAILED(!compiler, "cannot create compiler\n");
6529 sljit_emit_enter(compiler, (i >= 6 ? SLJIT_F64_ALIGNMENT : 0), 0, 2 + (i % 6), (i % 6), 0, 0, 0);
6531 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
6532 call = sljit_emit_jump(compiler, SLJIT_FAST_CALL);
6534 /* Should never return here, marked by a segmentation fault if it does. */
6535 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
6537 /* Recursive fast call. */
6538 label = sljit_emit_label(compiler);
6539 sljit_set_label(call, label);
6540 sljit_emit_fast_enter(compiler, SLJIT_R1, 0);
6542 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
6544 jump = sljit_emit_cmp(compiler, SLJIT_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 4);
6546 sljit_set_label(sljit_emit_jump(compiler, SLJIT_FAST_CALL), label);
6548 sljit_set_label(jump, sljit_emit_label(compiler));
6549 sljit_emit_op0(compiler, SLJIT_SKIP_FRAMES_BEFORE_RETURN);
6550 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
6552 code.code = sljit_generate_code(compiler);
6553 CHECK(compiler);
6555 sljit_free_compiler(compiler);
6557 if (SLJIT_UNLIKELY(code.func0() != 4)) {
6558 printf("test68 case %d failed\n", i + 1);
6559 return;
6561 sljit_free_code(code.code);
6564 successful_tests++;
6567 void sljit_test(int argc, char* argv[])
6569 sljit_s32 has_arg = (argc >= 2 && argv[1][0] == '-' && argv[1][2] == '\0');
6570 verbose = has_arg && argv[1][1] == 'v';
6571 silent = has_arg && argv[1][1] == 's';
6573 if (!verbose && !silent)
6574 printf("Pass -v to enable verbose, -s to disable this hint.\n\n");
6576 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
6577 test_exec_allocator();
6578 #endif
6579 test1();
6580 test2();
6581 test3();
6582 test4();
6583 test5();
6584 test6();
6585 test7();
6586 test8();
6587 test9();
6588 test10();
6589 test11();
6590 test12();
6591 test13();
6592 test14();
6593 test15();
6594 test16();
6595 test17();
6596 test18();
6597 test19();
6598 test20();
6599 test21();
6600 test22();
6601 test23();
6602 test24();
6603 test25();
6604 test26();
6605 test27();
6606 test28();
6607 test29();
6608 test30();
6609 test31();
6610 test32();
6611 test33();
6612 test34();
6613 test35();
6614 test36();
6615 test37();
6616 test38();
6617 test39();
6618 test40();
6619 test41();
6620 test42();
6621 test43();
6622 test44();
6623 test45();
6624 test46();
6625 test47();
6626 test48();
6627 test49();
6628 test50();
6629 test51();
6630 test52();
6631 test53();
6632 test54();
6633 test55();
6634 test56();
6635 test57();
6636 test58();
6637 test59();
6638 test60();
6639 test61();
6640 test62();
6641 test63();
6642 test64();
6643 test65();
6644 test66();
6645 test67();
6646 test68();
6648 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
6649 sljit_free_unused_memory_exec();
6650 #endif
6652 # define TEST_COUNT 68
6654 printf("SLJIT tests: ");
6655 if (successful_tests == TEST_COUNT)
6656 printf("all tests are " COLOR_GREEN "PASSED" COLOR_DEFAULT " ");
6657 else
6658 printf(COLOR_RED "%d" COLOR_DEFAULT " (" COLOR_RED "%d%%" COLOR_DEFAULT ") tests are " COLOR_RED "FAILED" COLOR_DEFAULT " ", TEST_COUNT - successful_tests, (TEST_COUNT - successful_tests) * 100 / 47);
6659 printf("on " COLOR_ARCH "%s" COLOR_DEFAULT "%s\n", sljit_get_platform_name(), sljit_has_cpu_feature(SLJIT_HAS_FPU) ? " (with fpu)" : " (without fpu)");
6661 # undef TEST_COUNT
6664 #ifdef _MSC_VER
6665 #pragma warning(pop)
6666 #endif