Implement sljit_emit_put_label on arm and sparc.
[sljit.git] / test_src / sljitTest.c
blob69da35ba5c1f3480bdfd0fc369383cff2090c3cd
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 #if defined _WIN32 || defined _WIN64
35 #define COLOR_RED
36 #define COLOR_GREEN
37 #define COLOR_ARCH
38 #define COLOR_DEFAULT
39 #else
40 #define COLOR_RED "\33[31m"
41 #define COLOR_GREEN "\33[32m"
42 #define COLOR_ARCH "\33[33m"
43 #define COLOR_DEFAULT "\33[0m"
44 #endif
46 union executable_code {
47 void* code;
48 sljit_sw (SLJIT_FUNC *func0)(void);
49 sljit_sw (SLJIT_FUNC *func1)(sljit_sw a);
50 sljit_sw (SLJIT_FUNC *func2)(sljit_sw a, sljit_sw b);
51 sljit_sw (SLJIT_FUNC *func3)(sljit_sw a, sljit_sw b, sljit_sw c);
53 typedef union executable_code executable_code;
55 static sljit_s32 successful_tests = 0;
56 static sljit_s32 verbose = 0;
57 static sljit_s32 silent = 0;
59 #define FAILED(cond, text) \
60 if (SLJIT_UNLIKELY(cond)) { \
61 printf(text); \
62 return; \
65 #define CHECK(compiler) \
66 if (sljit_get_compiler_error(compiler) != SLJIT_ERR_COMPILED) { \
67 printf("Compiler error: %d\n", sljit_get_compiler_error(compiler)); \
68 sljit_free_compiler(compiler); \
69 return; \
72 static void cond_set(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_s32 type)
74 /* Testing both sljit_emit_op_flags and sljit_emit_jump. */
75 struct sljit_jump* jump;
76 struct sljit_label* label;
78 sljit_emit_op_flags(compiler, SLJIT_MOV, dst, dstw, type);
79 jump = sljit_emit_jump(compiler, type);
80 sljit_emit_op2(compiler, SLJIT_ADD, dst, dstw, dst, dstw, SLJIT_IMM, 2);
81 label = sljit_emit_label(compiler);
82 sljit_set_label(jump, label);
85 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
87 #define MALLOC_EXEC(result, size) \
88 result = SLJIT_MALLOC_EXEC(size); \
89 if (!result) { \
90 printf("Cannot allocate executable memory\n"); \
91 return; \
92 } \
93 memset(result, 255, size);
95 #define FREE_EXEC(ptr) \
96 SLJIT_FREE_EXEC(((sljit_u8*)(ptr)) + SLJIT_EXEC_OFFSET(ptr));
98 static void test_exec_allocator(void)
100 /* This is not an sljit test. */
101 void *ptr1;
102 void *ptr2;
103 void *ptr3;
105 if (verbose)
106 printf("Run executable allocator test\n");
108 MALLOC_EXEC(ptr1, 32);
109 MALLOC_EXEC(ptr2, 512);
110 MALLOC_EXEC(ptr3, 512);
111 FREE_EXEC(ptr2);
112 FREE_EXEC(ptr3);
113 FREE_EXEC(ptr1);
114 MALLOC_EXEC(ptr1, 262104);
115 MALLOC_EXEC(ptr2, 32000);
116 FREE_EXEC(ptr1);
117 MALLOC_EXEC(ptr1, 262104);
118 FREE_EXEC(ptr1);
119 FREE_EXEC(ptr2);
120 MALLOC_EXEC(ptr1, 512);
121 MALLOC_EXEC(ptr2, 512);
122 MALLOC_EXEC(ptr3, 512);
123 FREE_EXEC(ptr2);
124 MALLOC_EXEC(ptr2, 512);
125 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
126 sljit_free_unused_memory_exec();
127 #endif
128 FREE_EXEC(ptr3);
129 FREE_EXEC(ptr1);
130 FREE_EXEC(ptr2);
131 #if (defined SLJIT_UTIL_GLOBAL_LOCK && SLJIT_UTIL_GLOBAL_LOCK)
132 /* Just call the global locks. */
133 sljit_grab_lock();
134 sljit_release_lock();
135 #endif
137 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
138 sljit_free_unused_memory_exec();
139 #endif
142 #undef MALLOC_EXEC
144 #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
146 static void test1(void)
148 /* Enter and return from an sljit function. */
149 executable_code code;
150 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
152 if (verbose)
153 printf("Run test1\n");
155 FAILED(!compiler, "cannot create compiler\n");
157 /* 3 arguments passed, 3 arguments used. */
158 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), 3, 3, 0, 0, 0);
159 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_S1, 0);
161 SLJIT_ASSERT(sljit_get_generated_code_size(compiler) == 0);
162 code.code = sljit_generate_code(compiler);
163 CHECK(compiler);
164 SLJIT_ASSERT(compiler->error == SLJIT_ERR_COMPILED);
165 SLJIT_ASSERT(sljit_get_generated_code_size(compiler) > 0);
166 sljit_free_compiler(compiler);
168 FAILED(code.func3(3, -21, 86) != -21, "test1 case 1 failed\n");
169 FAILED(code.func3(4789, 47890, 997) != 47890, "test1 case 2 failed\n");
171 sljit_free_code(code.code);
172 successful_tests++;
175 static void test2(void)
177 /* Test mov. */
178 executable_code code;
179 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
180 sljit_sw buf[8];
181 static sljit_sw data[2] = { 0, -9876 };
183 if (verbose)
184 printf("Run test2\n");
186 FAILED(!compiler, "cannot create compiler\n");
188 buf[0] = 5678;
189 buf[1] = 0;
190 buf[2] = 0;
191 buf[3] = 0;
192 buf[4] = 0;
193 buf[5] = 0;
194 buf[6] = 0;
195 buf[7] = 0;
196 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 2, 0, 0, 0);
197 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 9999);
198 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_S0, 0);
199 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_sw), SLJIT_R0, 0);
200 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
201 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM2(SLJIT_S1, SLJIT_R1), 0);
202 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, 2);
203 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_S1, SLJIT_S0), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_S1, SLJIT_R1), 0);
204 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, 3);
205 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_S1, SLJIT_S0), SLJIT_WORD_SHIFT, SLJIT_MEM0(), (sljit_sw)&buf);
206 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw));
207 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R0), (sljit_sw)&data);
208 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
209 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf - 0x12345678);
210 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R0), 0x12345678);
211 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_sw), SLJIT_R0, 0);
212 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 3456);
213 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&buf - 0xff890 + 6 * sizeof(sljit_sw));
214 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 0xff890, SLJIT_R0, 0);
215 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&buf + 0xff890 + 7 * sizeof(sljit_sw));
216 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), -0xff890, SLJIT_R0, 0);
217 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R2, 0);
219 code.code = sljit_generate_code(compiler);
220 CHECK(compiler);
221 sljit_free_compiler(compiler);
223 FAILED(code.func1((sljit_sw)&buf) != 9999, "test2 case 1 failed\n");
224 FAILED(buf[1] != 9999, "test2 case 2 failed\n");
225 FAILED(buf[2] != 9999, "test2 case 3 failed\n");
226 FAILED(buf[3] != 5678, "test2 case 4 failed\n");
227 FAILED(buf[4] != -9876, "test2 case 5 failed\n");
228 FAILED(buf[5] != 5678, "test2 case 6 failed\n");
229 FAILED(buf[6] != 3456, "test2 case 6 failed\n");
230 FAILED(buf[7] != 3456, "test2 case 6 failed\n");
232 sljit_free_code(code.code);
233 successful_tests++;
236 static void test3(void)
238 /* Test not. */
239 executable_code code;
240 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
241 sljit_sw buf[5];
243 if (verbose)
244 printf("Run test3\n");
246 FAILED(!compiler, "cannot create compiler\n");
247 buf[0] = 1234;
248 buf[1] = 0;
249 buf[2] = 9876;
250 buf[3] = 0;
251 buf[4] = 0x12345678;
253 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 0, 0, 0);
254 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_UNUSED, 0, SLJIT_MEM0(), (sljit_sw)&buf);
255 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 0);
256 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM0(), (sljit_sw)&buf[1], SLJIT_MEM0(), (sljit_sw)&buf[1]);
257 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_S0), 0);
258 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2);
259 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&buf[4] - 0xff0000 - 0x20);
260 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, (sljit_sw)&buf[4] - 0xff0000);
261 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM1(SLJIT_R1), 0xff0000 + 0x20, SLJIT_MEM1(SLJIT_R2), 0xff0000);
262 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
264 code.code = sljit_generate_code(compiler);
265 CHECK(compiler);
266 sljit_free_compiler(compiler);
268 FAILED(code.func1((sljit_sw)&buf) != ~1234, "test3 case 1 failed\n");
269 FAILED(buf[1] != ~1234, "test3 case 2 failed\n");
270 FAILED(buf[3] != ~9876, "test3 case 3 failed\n");
271 FAILED(buf[4] != ~0x12345678, "test3 case 4 failed\n");
273 sljit_free_code(code.code);
274 successful_tests++;
277 static void test4(void)
279 /* Test neg. */
280 executable_code code;
281 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
282 sljit_sw buf[4];
284 if (verbose)
285 printf("Run test4\n");
287 FAILED(!compiler, "cannot create compiler\n");
288 buf[0] = 0;
289 buf[1] = 1234;
290 buf[2] = 0;
291 buf[3] = 0;
293 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 3, 2, 0, 0, 0);
294 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0);
295 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_S1, 0);
296 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM0(), (sljit_sw)&buf[0], SLJIT_MEM0(), (sljit_sw)&buf[1]);
297 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 299);
298 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_R1, 0);
299 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_RETURN_REG, 0, SLJIT_S1, 0);
300 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
302 code.code = sljit_generate_code(compiler);
303 CHECK(compiler);
304 sljit_free_compiler(compiler);
306 FAILED(code.func2((sljit_sw)&buf, 4567) != -4567, "test4 case 1 failed\n");
307 FAILED(buf[0] != -1234, "test4 case 2 failed\n");
308 FAILED(buf[2] != -4567, "test4 case 3 failed\n");
309 FAILED(buf[3] != -299, "test4 case 4 failed\n");
311 sljit_free_code(code.code);
312 successful_tests++;
315 static void test5(void)
317 /* Test add. */
318 executable_code code;
319 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
320 sljit_sw buf[9];
322 if (verbose)
323 printf("Run test5\n");
325 FAILED(!compiler, "cannot create compiler\n");
326 buf[0] = 100;
327 buf[1] = 200;
328 buf[2] = 300;
329 buf[3] = 0;
330 buf[4] = 0;
331 buf[5] = 0;
332 buf[6] = 0;
333 buf[7] = 0;
334 buf[8] = 313;
336 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 2, 0, 0, 0);
337 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_UNUSED, 0, SLJIT_IMM, 16, SLJIT_IMM, 16);
338 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_UNUSED, 0, SLJIT_IMM, 255, SLJIT_IMM, 255);
339 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_UNUSED, 0, SLJIT_S0, 0, SLJIT_S0, 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_ASHR, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 2);
645 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
646 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R1, 0, SLJIT_IMM, 1);
647 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -64);
648 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 2);
649 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0, shift_reg, 0);
651 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 0xff);
652 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4);
653 sljit_emit_op2(compiler, SLJIT_SHL, shift_reg, 0, shift_reg, 0, SLJIT_R0, 0);
654 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, shift_reg, 0);
655 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 0xff);
656 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
657 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);
658 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, shift_reg, 0, SLJIT_R0, 0);
660 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, 0xf);
661 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
662 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_R0, 0);
663 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_S1, 0);
664 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_R0, 0);
665 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_R0, 0);
666 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 0xf00);
667 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4);
668 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_R1, 0, SLJIT_R2, 0, SLJIT_R0, 0);
669 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_R1, 0);
671 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)buf);
672 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 9);
673 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);
675 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 4);
676 sljit_emit_op2(compiler, SLJIT_SHL, shift_reg, 0, SLJIT_IMM, 2, shift_reg, 0);
677 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 10, shift_reg, 0);
679 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xa9);
680 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 0);
681 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x7d00);
682 sljit_emit_op2(compiler, SLJIT_LSHR32, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 32);
683 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
684 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
685 #endif
686 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_R0, 0);
687 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xe30000);
688 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
689 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffc0);
690 #else
691 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffe0);
692 #endif
693 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_R0, 0);
694 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x25000000);
695 sljit_emit_op2(compiler, SLJIT_SHL32, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xfffe1);
696 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
697 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
698 #endif
699 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 11, SLJIT_R1, 0, SLJIT_R0, 0);
701 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 0);
702 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x5c);
703 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R1, 0, SLJIT_R0, 0, shift_reg, 0);
704 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0xf600);
705 sljit_emit_op2(compiler, SLJIT_LSHR32, SLJIT_R0, 0, SLJIT_R0, 0, shift_reg, 0);
706 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
707 /* Alternative form of uint32 type cast. */
708 sljit_emit_op2(compiler, SLJIT_AND, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffffffff);
709 #endif
710 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_R0, 0);
711 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x630000);
712 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_R0, 0, SLJIT_R0, 0, shift_reg, 0);
713 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 12, SLJIT_R1, 0, SLJIT_R0, 0);
715 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
717 code.code = sljit_generate_code(compiler);
718 CHECK(compiler);
719 sljit_free_compiler(compiler);
721 code.func1((sljit_sw)&buf);
722 FAILED(buf[0] != 0x3c, "test9 case 1 failed\n");
723 FAILED(buf[1] != 0xf0, "test9 case 2 failed\n");
724 FAILED(buf[2] != -16, "test9 case 3 failed\n");
725 FAILED(buf[3] != 0xff0, "test9 case 4 failed\n");
726 FAILED(buf[4] != 4, "test9 case 5 failed\n");
727 FAILED(buf[5] != 0xff00, "test9 case 6 failed\n");
728 FAILED(buf[6] != 0x3c, "test9 case 7 failed\n");
729 FAILED(buf[7] != 0xf0, "test9 case 8 failed\n");
730 FAILED(buf[8] != 0xf0, "test9 case 9 failed\n");
731 FAILED(buf[9] != 0x18, "test9 case 10 failed\n");
732 FAILED(buf[10] != 32, "test9 case 11 failed\n");
733 FAILED(buf[11] != 0x4ae37da9, "test9 case 12 failed\n");
734 FAILED(buf[12] != 0x63f65c, "test9 case 13 failed\n");
736 sljit_free_code(code.code);
737 successful_tests++;
740 static void test10(void)
742 /* Test multiplications. */
743 executable_code code;
744 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
745 sljit_sw buf[7];
747 if (verbose)
748 printf("Run test10\n");
750 FAILED(!compiler, "cannot create compiler\n");
751 buf[0] = 3;
752 buf[1] = 0;
753 buf[2] = 0;
754 buf[3] = 6;
755 buf[4] = -10;
756 buf[5] = 0;
757 buf[6] = 0;
759 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 0, 0, 0);
760 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 5);
761 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
762 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
763 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 7);
764 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_R2, 0, SLJIT_IMM, 8);
765 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
766 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_IMM, -3, SLJIT_IMM, -4);
767 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0);
768 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -2);
769 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);
770 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw) / 2);
771 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&buf[3]);
772 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);
773 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 9);
774 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R0, 0);
775 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_R0, 0);
776 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
777 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 3);
778 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x123456789));
779 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_R0, 0);
780 #endif
781 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 11, SLJIT_IMM, 10);
782 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
784 code.code = sljit_generate_code(compiler);
785 CHECK(compiler);
786 sljit_free_compiler(compiler);
788 FAILED(code.func1((sljit_sw)&buf) != 110, "test10 case 1 failed\n");
789 FAILED(buf[0] != 15, "test10 case 2 failed\n");
790 FAILED(buf[1] != 56, "test10 case 3 failed\n");
791 FAILED(buf[2] != 12, "test10 case 4 failed\n");
792 FAILED(buf[3] != -12, "test10 case 5 failed\n");
793 FAILED(buf[4] != 100, "test10 case 6 failed\n");
794 FAILED(buf[5] != 81, "test10 case 7 failed\n");
795 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
796 FAILED(buf[6] != SLJIT_W(0x123456789) * 3, "test10 case 8 failed\n");
797 #endif
799 sljit_free_code(code.code);
800 successful_tests++;
803 static void test11(void)
805 /* Test rewritable constants. */
806 executable_code code;
807 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
808 struct sljit_const* const1;
809 struct sljit_const* const2;
810 struct sljit_const* const3;
811 struct sljit_const* const4;
812 void* value;
813 sljit_sw executable_offset;
814 sljit_uw const1_addr;
815 sljit_uw const2_addr;
816 sljit_uw const3_addr;
817 sljit_uw const4_addr;
818 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
819 sljit_sw word_value1 = SLJIT_W(0xaaaaaaaaaaaaaaaa);
820 sljit_sw word_value2 = SLJIT_W(0xfee1deadfbadf00d);
821 #else
822 sljit_sw word_value1 = 0xaaaaaaaal;
823 sljit_sw word_value2 = 0xfbadf00dl;
824 #endif
825 sljit_sw buf[3];
827 if (verbose)
828 printf("Run test11\n");
830 FAILED(!compiler, "cannot create compiler\n");
831 buf[0] = 0;
832 buf[1] = 0;
833 buf[2] = 0;
835 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 0, 0, 0);
837 SLJIT_ASSERT(!sljit_alloc_memory(compiler, 0));
838 SLJIT_ASSERT(!sljit_alloc_memory(compiler, 16 * sizeof(sljit_sw) + 1));
840 const1 = sljit_emit_const(compiler, SLJIT_MEM0(), (sljit_sw)&buf[0], -0x81b9);
842 value = sljit_alloc_memory(compiler, 16 * sizeof(sljit_sw));
843 if (value != NULL)
845 SLJIT_ASSERT(!((sljit_sw)value & (sizeof(sljit_sw) - 1)));
846 memset(value, 255, 16 * sizeof(sljit_sw));
849 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
850 const2 = sljit_emit_const(compiler, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_WORD_SHIFT - 1, -65535);
851 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[0] + 2 * sizeof(sljit_sw) - 2);
852 const3 = sljit_emit_const(compiler, SLJIT_MEM1(SLJIT_R0), 0, word_value1);
854 value = sljit_alloc_memory(compiler, 17);
855 if (value != NULL)
857 SLJIT_ASSERT(!((sljit_sw)value & (sizeof(sljit_sw) - 1)));
858 memset(value, 255, 16);
861 const4 = sljit_emit_const(compiler, SLJIT_RETURN_REG, 0, 0xf7afcdb7);
863 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
865 code.code = sljit_generate_code(compiler);
866 CHECK(compiler);
867 executable_offset = sljit_get_executable_offset(compiler);
868 const1_addr = sljit_get_const_addr(const1);
869 const2_addr = sljit_get_const_addr(const2);
870 const3_addr = sljit_get_const_addr(const3);
871 const4_addr = sljit_get_const_addr(const4);
872 sljit_free_compiler(compiler);
874 FAILED(code.func1((sljit_sw)&buf) != 0xf7afcdb7, "test11 case 1 failed\n");
875 FAILED(buf[0] != -0x81b9, "test11 case 2 failed\n");
876 FAILED(buf[1] != -65535, "test11 case 3 failed\n");
877 FAILED(buf[2] != word_value1, "test11 case 4 failed\n");
879 sljit_set_const(const1_addr, -1, executable_offset);
880 sljit_set_const(const2_addr, word_value2, executable_offset);
881 sljit_set_const(const3_addr, 0xbab0fea1, executable_offset);
882 sljit_set_const(const4_addr, -60089, executable_offset);
884 FAILED(code.func1((sljit_sw)&buf) != -60089, "test11 case 5 failed\n");
885 FAILED(buf[0] != -1, "test11 case 6 failed\n");
886 FAILED(buf[1] != word_value2, "test11 case 7 failed\n");
887 FAILED(buf[2] != 0xbab0fea1, "test11 case 8 failed\n");
889 sljit_free_code(code.code);
890 successful_tests++;
893 static void test12(void)
895 /* Test rewriteable jumps. */
896 executable_code code;
897 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
898 struct sljit_label *label1;
899 struct sljit_label *label2;
900 struct sljit_label *label3;
901 struct sljit_jump *jump1;
902 struct sljit_jump *jump2;
903 struct sljit_jump *jump3;
904 sljit_sw executable_offset;
905 void* value;
906 sljit_uw jump1_addr;
907 sljit_uw label1_addr;
908 sljit_uw label2_addr;
909 sljit_sw buf[1];
911 if (verbose)
912 printf("Run test12\n");
914 FAILED(!compiler, "cannot create compiler\n");
915 buf[0] = 0;
917 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 3, 2, 0, 0, 0);
918 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_UNUSED, 0, SLJIT_S1, 0, SLJIT_IMM, 10);
919 jump1 = sljit_emit_jump(compiler, SLJIT_REWRITABLE_JUMP | SLJIT_SIG_GREATER);
920 /* Default handler. */
921 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 5);
922 jump2 = sljit_emit_jump(compiler, SLJIT_JUMP);
924 value = sljit_alloc_memory(compiler, 15);
925 if (value != NULL)
927 SLJIT_ASSERT(!((sljit_sw)value & (sizeof(sljit_sw) - 1)));
928 memset(value, 255, 15);
931 /* Handler 1. */
932 label1 = sljit_emit_label(compiler);
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_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 7);
938 /* Exit. */
939 label3 = sljit_emit_label(compiler);
940 sljit_set_label(jump2, label3);
941 sljit_set_label(jump3, label3);
942 /* By default, set to handler 1. */
943 sljit_set_label(jump1, label1);
944 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
946 value = sljit_alloc_memory(compiler, 8);
947 if (value != NULL)
949 SLJIT_ASSERT(!((sljit_sw)value & (sizeof(sljit_sw) - 1)));
950 memset(value, 255, 8);
953 code.code = sljit_generate_code(compiler);
954 CHECK(compiler);
955 executable_offset = sljit_get_executable_offset(compiler);
956 jump1_addr = sljit_get_jump_addr(jump1);
957 label1_addr = sljit_get_label_addr(label1);
958 label2_addr = sljit_get_label_addr(label2);
959 sljit_free_compiler(compiler);
961 code.func2((sljit_sw)&buf, 4);
962 FAILED(buf[0] != 5, "test12 case 1 failed\n");
964 code.func2((sljit_sw)&buf, 11);
965 FAILED(buf[0] != 6, "test12 case 2 failed\n");
967 sljit_set_jump_addr(jump1_addr, label2_addr, executable_offset);
968 code.func2((sljit_sw)&buf, 12);
969 FAILED(buf[0] != 7, "test12 case 3 failed\n");
971 sljit_set_jump_addr(jump1_addr, label1_addr, executable_offset);
972 code.func2((sljit_sw)&buf, 13);
973 FAILED(buf[0] != 6, "test12 case 4 failed\n");
975 sljit_free_code(code.code);
976 successful_tests++;
979 static void test13(void)
981 /* Test fpu monadic functions. */
982 executable_code code;
983 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
984 sljit_f64 buf[7];
985 sljit_sw buf2[6];
987 if (verbose)
988 printf("Run test13\n");
990 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
991 if (verbose)
992 printf("no fpu available, test13 skipped\n");
993 successful_tests++;
994 if (compiler)
995 sljit_free_compiler(compiler);
996 return;
999 FAILED(!compiler, "cannot create compiler\n");
1000 buf[0] = 7.75;
1001 buf[1] = -4.5;
1002 buf[2] = 0.0;
1003 buf[3] = 0.0;
1004 buf[4] = 0.0;
1005 buf[5] = 0.0;
1006 buf[6] = 0.0;
1008 buf2[0] = 10;
1009 buf2[1] = 10;
1010 buf2[2] = 10;
1011 buf2[3] = 10;
1012 buf2[4] = 10;
1013 buf2[5] = 10;
1015 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 3, 2, 6, 0, 0);
1016 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM0(), (sljit_sw)&buf[2], SLJIT_MEM0(), (sljit_sw)&buf[1]);
1017 sljit_emit_fop1(compiler, SLJIT_ABS_F64, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1018 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM0(), (sljit_sw)&buf[0]);
1019 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2 * sizeof(sljit_f64));
1020 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 0);
1021 sljit_emit_fop1(compiler, SLJIT_NEG_F64, SLJIT_FR2, 0, SLJIT_FR0, 0);
1022 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR3, 0, SLJIT_FR2, 0);
1023 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM0(), (sljit_sw)&buf[4], SLJIT_FR3, 0);
1024 sljit_emit_fop1(compiler, SLJIT_ABS_F64, SLJIT_FR4, 0, SLJIT_FR1, 0);
1025 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f64), SLJIT_FR4, 0);
1026 sljit_emit_fop1(compiler, SLJIT_NEG_F64, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64), SLJIT_FR4, 0);
1028 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), 0);
1029 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_GREATER_F, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1030 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_GREATER_F64);
1031 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_GREATER_F, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64), SLJIT_FR5, 0);
1032 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_sw), SLJIT_GREATER_F64);
1033 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_FR5, 0);
1034 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR1, 0);
1035 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_sw), SLJIT_EQUAL_F64);
1036 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_LESS_F, SLJIT_FR1, 0, SLJIT_FR1, 0);
1037 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw), SLJIT_LESS_F64);
1038 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1039 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_sw), SLJIT_EQUAL_F64);
1040 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_NOT_EQUAL_F, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1041 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_sw), SLJIT_NOT_EQUAL_F64);
1043 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1045 code.code = sljit_generate_code(compiler);
1046 CHECK(compiler);
1047 sljit_free_compiler(compiler);
1049 code.func2((sljit_sw)&buf, (sljit_sw)&buf2);
1050 FAILED(buf[2] != -4.5, "test13 case 1 failed\n");
1051 FAILED(buf[3] != 4.5, "test13 case 2 failed\n");
1052 FAILED(buf[4] != -7.75, "test13 case 3 failed\n");
1053 FAILED(buf[5] != 4.5, "test13 case 4 failed\n");
1054 FAILED(buf[6] != -4.5, "test13 case 5 failed\n");
1056 FAILED(buf2[0] != 1, "test13 case 6 failed\n");
1057 FAILED(buf2[1] != 0, "test13 case 7 failed\n");
1058 FAILED(buf2[2] != 1, "test13 case 8 failed\n");
1059 FAILED(buf2[3] != 0, "test13 case 9 failed\n");
1060 FAILED(buf2[4] != 0, "test13 case 10 failed\n");
1061 FAILED(buf2[5] != 1, "test13 case 11 failed\n");
1063 sljit_free_code(code.code);
1064 successful_tests++;
1067 static void test14(void)
1069 /* Test fpu diadic functions. */
1070 executable_code code;
1071 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1072 sljit_f64 buf[15];
1074 if (verbose)
1075 printf("Run test14\n");
1077 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
1078 if (verbose)
1079 printf("no fpu available, test14 skipped\n");
1080 successful_tests++;
1081 if (compiler)
1082 sljit_free_compiler(compiler);
1083 return;
1085 buf[0] = 7.25;
1086 buf[1] = 3.5;
1087 buf[2] = 1.75;
1088 buf[3] = 0.0;
1089 buf[4] = 0.0;
1090 buf[5] = 0.0;
1091 buf[6] = 0.0;
1092 buf[7] = 0.0;
1093 buf[8] = 0.0;
1094 buf[9] = 0.0;
1095 buf[10] = 0.0;
1096 buf[11] = 0.0;
1097 buf[12] = 8.0;
1098 buf[13] = 4.0;
1099 buf[14] = 0.0;
1101 FAILED(!compiler, "cannot create compiler\n");
1102 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 6, 0, 0);
1104 /* ADD */
1105 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_f64));
1106 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1107 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 2);
1108 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);
1109 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR0, 0, SLJIT_FR0, 0, SLJIT_FR1, 0);
1110 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR1, 0, SLJIT_FR0, 0, SLJIT_FR1, 0);
1111 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 4, SLJIT_FR0, 0);
1112 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 5, SLJIT_FR1, 0);
1114 /* SUB */
1115 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 0);
1116 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR3, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 2);
1117 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 2);
1118 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);
1119 sljit_emit_fop2(compiler, SLJIT_SUB_F64, SLJIT_FR2, 0, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 2);
1120 sljit_emit_fop2(compiler, SLJIT_SUB_F64, SLJIT_FR3, 0, SLJIT_FR2, 0, SLJIT_FR3, 0);
1121 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 7, SLJIT_FR2, 0);
1122 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 8, SLJIT_FR3, 0);
1124 /* MUL */
1125 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
1126 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);
1127 sljit_emit_fop2(compiler, SLJIT_MUL_F64, SLJIT_FR1, 0, SLJIT_FR1, 0, SLJIT_FR2, 0);
1128 sljit_emit_fop2(compiler, SLJIT_MUL_F64, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 2, SLJIT_FR2, 0);
1129 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 10, SLJIT_FR1, 0);
1130 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 11, SLJIT_FR5, 0);
1132 /* DIV */
1133 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 12);
1134 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 13);
1135 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR4, 0, SLJIT_FR5, 0);
1136 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);
1137 sljit_emit_fop2(compiler, SLJIT_DIV_F64, SLJIT_FR5, 0, SLJIT_FR5, 0, SLJIT_FR1, 0);
1138 sljit_emit_fop2(compiler, SLJIT_DIV_F64, SLJIT_FR4, 0, SLJIT_FR1, 0, SLJIT_FR4, 0);
1139 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 13, SLJIT_FR5, 0);
1140 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 14, SLJIT_FR4, 0);
1142 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1144 code.code = sljit_generate_code(compiler);
1145 CHECK(compiler);
1146 sljit_free_compiler(compiler);
1148 code.func1((sljit_sw)&buf);
1149 FAILED(buf[3] != 10.75, "test14 case 1 failed\n");
1150 FAILED(buf[4] != 5.25, "test14 case 2 failed\n");
1151 FAILED(buf[5] != 7.0, "test14 case 3 failed\n");
1152 FAILED(buf[6] != 0.0, "test14 case 4 failed\n");
1153 FAILED(buf[7] != 5.5, "test14 case 5 failed\n");
1154 FAILED(buf[8] != 3.75, "test14 case 6 failed\n");
1155 FAILED(buf[9] != 24.5, "test14 case 7 failed\n");
1156 FAILED(buf[10] != 38.5, "test14 case 8 failed\n");
1157 FAILED(buf[11] != 9.625, "test14 case 9 failed\n");
1158 FAILED(buf[12] != 2.0, "test14 case 10 failed\n");
1159 FAILED(buf[13] != 2.0, "test14 case 11 failed\n");
1160 FAILED(buf[14] != 0.5, "test14 case 12 failed\n");
1162 sljit_free_code(code.code);
1163 successful_tests++;
1166 static sljit_sw SLJIT_FUNC func(sljit_sw a, sljit_sw b, sljit_sw c)
1168 return a + b + c + 5;
1171 static void test15(void)
1173 /* Test function call. */
1174 executable_code code;
1175 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1176 struct sljit_jump* jump = NULL;
1177 sljit_sw buf[7];
1179 if (verbose)
1180 printf("Run test15\n");
1182 FAILED(!compiler, "cannot create compiler\n");
1183 buf[0] = 0;
1184 buf[1] = 0;
1185 buf[2] = 0;
1186 buf[3] = 0;
1187 buf[4] = 0;
1188 buf[5] = 0;
1189 buf[6] = SLJIT_FUNC_OFFSET(func);
1191 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 4, 1, 0, 0, 0);
1193 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 5);
1194 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 7);
1195 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -3);
1196 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1197 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_RETURN_REG, 0);
1199 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -5);
1200 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -10);
1201 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 2);
1202 jump = sljit_emit_call(compiler, SLJIT_CALL | SLJIT_REWRITABLE_JUMP, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW));
1203 sljit_set_target(jump, (sljit_sw)-1);
1204 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1206 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1207 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 40);
1208 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -3);
1209 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), SLJIT_R0, 0);
1210 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1212 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -60);
1213 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1214 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -30);
1215 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), SLJIT_R1, 0);
1216 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1218 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 10);
1219 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 16);
1220 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1221 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), SLJIT_R2, 0);
1222 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1224 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 100);
1225 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 110);
1226 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 120);
1227 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(func));
1228 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), SLJIT_R3, 0);
1229 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1231 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -10);
1232 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -16);
1233 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 6);
1234 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));
1235 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1237 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1239 code.code = sljit_generate_code(compiler);
1240 CHECK(compiler);
1241 sljit_set_jump_addr(sljit_get_jump_addr(jump), SLJIT_FUNC_OFFSET(func), sljit_get_executable_offset(compiler));
1242 sljit_free_compiler(compiler);
1244 FAILED(code.func1((sljit_sw)&buf) != -15, "test15 case 1 failed\n");
1245 FAILED(buf[0] != 14, "test15 case 2 failed\n");
1246 FAILED(buf[1] != -8, "test15 case 3 failed\n");
1247 FAILED(buf[2] != SLJIT_FUNC_OFFSET(func) + 42, "test15 case 4 failed\n");
1248 FAILED(buf[3] != SLJIT_FUNC_OFFSET(func) - 85, "test15 case 5 failed\n");
1249 FAILED(buf[4] != SLJIT_FUNC_OFFSET(func) + 31, "test15 case 6 failed\n");
1250 FAILED(buf[5] != 335, "test15 case 7 failed\n");
1251 FAILED(buf[6] != -15, "test15 case 8 failed\n");
1253 sljit_free_code(code.code);
1254 successful_tests++;
1257 static void test16(void)
1259 /* Ackermann benchmark. */
1260 executable_code code;
1261 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1262 struct sljit_label *entry;
1263 struct sljit_label *label;
1264 struct sljit_jump *jump;
1265 struct sljit_jump *jump1;
1266 struct sljit_jump *jump2;
1268 if (verbose)
1269 printf("Run test16\n");
1271 FAILED(!compiler, "cannot create compiler\n");
1273 entry = sljit_emit_label(compiler);
1274 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 3, 2, 0, 0, 0);
1275 /* If x == 0. */
1276 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_S0, 0, SLJIT_IMM, 0);
1277 jump1 = sljit_emit_jump(compiler, SLJIT_EQUAL);
1278 /* If y == 0. */
1279 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_S1, 0, SLJIT_IMM, 0);
1280 jump2 = sljit_emit_jump(compiler, SLJIT_EQUAL);
1282 /* Ack(x,y-1). */
1283 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
1284 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_S1, 0, SLJIT_IMM, 1);
1285 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW));
1286 sljit_set_label(jump, entry);
1288 /* Returns with Ack(x-1, Ack(x,y-1)). */
1289 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_RETURN_REG, 0);
1290 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
1291 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW));
1292 sljit_set_label(jump, entry);
1293 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1295 /* Returns with y+1. */
1296 label = sljit_emit_label(compiler);
1297 sljit_set_label(jump1, label);
1298 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1, SLJIT_S1, 0);
1299 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1301 /* Returns with Ack(x-1,1) */
1302 label = sljit_emit_label(compiler);
1303 sljit_set_label(jump2, label);
1304 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
1305 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
1306 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW));
1307 sljit_set_label(jump, entry);
1308 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1310 code.code = sljit_generate_code(compiler);
1311 CHECK(compiler);
1312 sljit_free_compiler(compiler);
1314 FAILED(code.func2(3, 3) != 61, "test16 case 1 failed\n");
1315 /* For benchmarking. */
1316 /* FAILED(code.func2(3, 11) != 16381, "test16 case 1 failed\n"); */
1318 sljit_free_code(code.code);
1319 successful_tests++;
1322 static void test17(void)
1324 /* Test arm constant pool. */
1325 executable_code code;
1326 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1327 sljit_s32 i;
1328 sljit_sw buf[5];
1330 if (verbose)
1331 printf("Run test17\n");
1333 FAILED(!compiler, "cannot create compiler\n");
1334 buf[0] = 0;
1335 buf[1] = 0;
1336 buf[2] = 0;
1337 buf[3] = 0;
1338 buf[4] = 0;
1340 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 0, 0, 0);
1341 for (i = 0; i <= 0xfff; i++) {
1342 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x81818000 | i);
1343 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x81818000 | i);
1344 if ((i & 0x3ff) == 0)
1345 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), (i >> 10) * sizeof(sljit_sw), SLJIT_R0, 0);
1347 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
1348 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1350 code.code = sljit_generate_code(compiler);
1351 CHECK(compiler);
1352 sljit_free_compiler(compiler);
1354 code.func1((sljit_sw)&buf);
1355 FAILED((sljit_uw)buf[0] != 0x81818000, "test17 case 1 failed\n");
1356 FAILED((sljit_uw)buf[1] != 0x81818400, "test17 case 2 failed\n");
1357 FAILED((sljit_uw)buf[2] != 0x81818800, "test17 case 3 failed\n");
1358 FAILED((sljit_uw)buf[3] != 0x81818c00, "test17 case 4 failed\n");
1359 FAILED((sljit_uw)buf[4] != 0x81818fff, "test17 case 5 failed\n");
1361 sljit_free_code(code.code);
1362 successful_tests++;
1365 static void test18(void)
1367 /* Test 64 bit. */
1368 executable_code code;
1369 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1370 sljit_sw buf[11];
1372 if (verbose)
1373 printf("Run test18\n");
1375 FAILED(!compiler, "cannot create compiler\n");
1376 buf[0] = 0;
1377 buf[1] = 0;
1378 buf[2] = 0;
1379 buf[3] = 0;
1380 buf[4] = 0;
1381 buf[5] = 100;
1382 buf[6] = 100;
1383 buf[7] = 100;
1384 buf[8] = 100;
1385 buf[9] = 0;
1386 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) && (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
1387 buf[10] = SLJIT_W(1) << 32;
1388 #else
1389 buf[10] = 1;
1390 #endif
1392 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 2, 0, 0, 0);
1394 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1395 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, SLJIT_W(0x1122334455667788));
1396 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x1122334455667788));
1398 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(1000000000000));
1399 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(1000000000000));
1400 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_IMM, SLJIT_W(5000000000000), SLJIT_R0, 0);
1402 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x1108080808));
1403 sljit_emit_op2(compiler, SLJIT_ADD32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x1120202020));
1405 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1108080808));
1406 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1120202020));
1407 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_ZERO);
1408 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_S1, 0);
1409 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
1410 sljit_emit_op2(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1120202020));
1411 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_ZERO32);
1413 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1108080808));
1414 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x2208080808));
1415 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_LESS);
1416 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
1417 sljit_emit_op2(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1104040404));
1418 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_NOT_ZERO32);
1420 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 4);
1421 sljit_emit_op2(compiler, SLJIT_SHL32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 9, SLJIT_IMM, SLJIT_W(0xffff0000), SLJIT_R0, 0);
1423 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);
1424 #else
1425 /* 32 bit operations. */
1427 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0x11223344);
1428 sljit_emit_op2(compiler, SLJIT_ADD32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, 0x44332211);
1430 #endif
1432 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1434 code.code = sljit_generate_code(compiler);
1435 CHECK(compiler);
1436 sljit_free_compiler(compiler);
1438 code.func1((sljit_sw)&buf);
1439 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1440 FAILED(buf[0] != SLJIT_W(0x1122334455667788), "test18 case 1 failed\n");
1441 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1442 FAILED(buf[1] != 0x55667788, "test18 case 2 failed\n");
1443 #else
1444 FAILED(buf[1] != SLJIT_W(0x5566778800000000), "test18 case 2 failed\n");
1445 #endif
1446 FAILED(buf[2] != SLJIT_W(2000000000000), "test18 case 3 failed\n");
1447 FAILED(buf[3] != SLJIT_W(4000000000000), "test18 case 4 failed\n");
1448 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1449 FAILED(buf[4] != 0x28282828, "test18 case 5 failed\n");
1450 #else
1451 FAILED(buf[4] != SLJIT_W(0x2828282800000000), "test18 case 5 failed\n");
1452 #endif
1453 FAILED(buf[5] != 0, "test18 case 6 failed\n");
1454 FAILED(buf[6] != 1, "test18 case 7 failed\n");
1455 FAILED(buf[7] != 1, "test18 case 8 failed\n");
1456 FAILED(buf[8] != 0, "test18 case 9 failed\n");
1457 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1458 FAILED(buf[9] != 0xfff00000, "test18 case 10 failed\n");
1459 FAILED(buf[10] != 0xffffffff, "test18 case 11 failed\n");
1460 #else
1461 FAILED(buf[9] != SLJIT_W(0xfff0000000000000), "test18 case 10 failed\n");
1462 FAILED(buf[10] != SLJIT_W(0xffffffff00000000), "test18 case 11 failed\n");
1463 #endif
1464 #else
1465 FAILED(buf[0] != 0x11223344, "test18 case 1 failed\n");
1466 FAILED(buf[1] != 0x44332211, "test18 case 2 failed\n");
1467 #endif
1469 sljit_free_code(code.code);
1470 successful_tests++;
1473 static void test19(void)
1475 /* Test arm partial instruction caching. */
1476 executable_code code;
1477 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1478 sljit_sw buf[10];
1480 if (verbose)
1481 printf("Run test19\n");
1483 FAILED(!compiler, "cannot create compiler\n");
1484 buf[0] = 6;
1485 buf[1] = 4;
1486 buf[2] = 0;
1487 buf[3] = 0;
1488 buf[4] = 0;
1489 buf[5] = 0;
1490 buf[6] = 2;
1491 buf[7] = 0;
1493 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 0, 0, 0);
1494 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw));
1495 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM0(), (sljit_sw)&buf[2], SLJIT_MEM0(), (sljit_sw)&buf[1], SLJIT_MEM0(), (sljit_sw)&buf[0]);
1496 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
1497 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
1498 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]);
1499 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_MEM0(), (sljit_sw)&buf[0], SLJIT_IMM, 2);
1500 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));
1501 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_IMM, 10);
1502 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 7);
1503 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]);
1505 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1507 code.code = sljit_generate_code(compiler);
1508 CHECK(compiler);
1509 sljit_free_compiler(compiler);
1511 code.func1((sljit_sw)&buf);
1512 FAILED(buf[0] != 10, "test19 case 1 failed\n");
1513 FAILED(buf[1] != 4, "test19 case 2 failed\n");
1514 FAILED(buf[2] != 14, "test19 case 3 failed\n");
1515 FAILED(buf[3] != 14, "test19 case 4 failed\n");
1516 FAILED(buf[4] != 8, "test19 case 5 failed\n");
1517 FAILED(buf[5] != 6, "test19 case 6 failed\n");
1518 FAILED(buf[6] != 12, "test19 case 7 failed\n");
1519 FAILED(buf[7] != 10, "test19 case 8 failed\n");
1521 sljit_free_code(code.code);
1522 successful_tests++;
1525 static void test20(void)
1527 /* Test stack. */
1528 executable_code code;
1529 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1530 struct sljit_jump* jump;
1531 struct sljit_label* label;
1532 sljit_sw buf[6];
1533 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1534 sljit_sw offset_value = SLJIT_W(0x1234567812345678);
1535 #else
1536 sljit_sw offset_value = SLJIT_W(0x12345678);
1537 #endif
1539 if (verbose)
1540 printf("Run test20\n");
1542 FAILED(!compiler, "cannot create compiler\n");
1543 buf[0] = 5;
1544 buf[1] = 12;
1545 buf[2] = 0;
1546 buf[3] = 0;
1547 buf[4] = 111;
1548 buf[5] = -12345;
1550 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 5, 5, 0, 0, 4 * sizeof(sljit_sw));
1551 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw), SLJIT_MEM1(SLJIT_S0), 0);
1552 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw));
1553 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -1);
1554 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_IMM, -1);
1555 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, -1);
1556 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S4, 0, SLJIT_IMM, -1);
1557 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));
1558 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);
1559 sljit_get_local_base(compiler, SLJIT_R0, 0, -offset_value);
1560 sljit_get_local_base(compiler, SLJIT_MEM1(SLJIT_S0), 0, -0x1234);
1561 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), 0);
1562 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));
1563 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_uw));
1564 /* Dummy last instructions. */
1565 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, 23);
1566 sljit_emit_label(compiler);
1568 code.code = sljit_generate_code(compiler);
1569 CHECK(compiler);
1570 sljit_free_compiler(compiler);
1572 FAILED(code.func1((sljit_sw)&buf) != -12345, "test20 case 1 failed\n")
1574 FAILED(buf[2] != 60, "test20 case 2 failed\n");
1575 FAILED(buf[3] != 17, "test20 case 3 failed\n");
1576 FAILED(buf[4] != 7, "test20 case 4 failed\n");
1578 sljit_free_code(code.code);
1580 compiler = sljit_create_compiler(NULL);
1581 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), 3, 3, 0, 0, SLJIT_MAX_LOCAL_SIZE);
1583 sljit_get_local_base(compiler, SLJIT_R0, 0, SLJIT_MAX_LOCAL_SIZE - sizeof(sljit_sw));
1584 sljit_get_local_base(compiler, SLJIT_R1, 0, -(sljit_sw)sizeof(sljit_sw));
1585 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -1);
1586 label = sljit_emit_label(compiler);
1587 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
1588 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 0, SLJIT_R2, 0);
1589 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R1, 0, SLJIT_R0, 0);
1590 jump = sljit_emit_jump(compiler, SLJIT_NOT_EQUAL);
1591 sljit_set_label(jump, label);
1593 /* Saved registers should keep their value. */
1594 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_S1, 0);
1595 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_S2, 0);
1596 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
1598 code.code = sljit_generate_code(compiler);
1599 CHECK(compiler);
1600 sljit_free_compiler(compiler);
1602 FAILED(code.func3(1234, 5678, 9012) != 15924, "test20 case 5 failed\n");
1604 sljit_free_code(code.code);
1606 compiler = sljit_create_compiler(NULL);
1607 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, 0, 3, 0, 0, 0, SLJIT_MAX_LOCAL_SIZE);
1609 sljit_get_local_base(compiler, SLJIT_R0, 0, SLJIT_MAX_LOCAL_SIZE - sizeof(sljit_sw));
1610 sljit_get_local_base(compiler, SLJIT_R1, 0, -(sljit_sw)sizeof(sljit_sw));
1611 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -1);
1612 label = sljit_emit_label(compiler);
1613 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
1614 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 0, SLJIT_R2, 0);
1615 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R1, 0, SLJIT_R0, 0);
1616 jump = sljit_emit_jump(compiler, SLJIT_NOT_EQUAL);
1617 sljit_set_label(jump, label);
1619 sljit_get_local_base(compiler, SLJIT_R0, 0, 0);
1620 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
1622 code.code = sljit_generate_code(compiler);
1623 CHECK(compiler);
1624 sljit_free_compiler(compiler);
1626 FAILED(code.func0() % sizeof(sljit_f64) != 0, "test20 case 6 failed\n");
1628 sljit_free_code(code.code);
1629 successful_tests++;
1632 static void test21(void)
1634 /* Test set context. The parts of the jit code can be separated in the memory. */
1635 executable_code code1;
1636 executable_code code2;
1637 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1638 struct sljit_jump* jump = NULL;
1639 sljit_uw addr;
1640 sljit_sw executable_offset;
1641 sljit_sw buf[4];
1643 if (verbose)
1644 printf("Run test21\n");
1646 FAILED(!compiler, "cannot create compiler\n");
1647 buf[0] = 9;
1648 buf[1] = -6;
1649 buf[2] = 0;
1650 buf[3] = 0;
1652 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 2, 0, 0, 2 * sizeof(sljit_sw));
1654 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, 10);
1655 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_SP), 0);
1657 jump = sljit_emit_jump(compiler, SLJIT_JUMP | SLJIT_REWRITABLE_JUMP);
1658 sljit_set_target(jump, 0);
1660 code1.code = sljit_generate_code(compiler);
1661 CHECK(compiler);
1663 executable_offset = sljit_get_executable_offset(compiler);
1664 addr = sljit_get_jump_addr(jump);
1666 sljit_free_compiler(compiler);
1668 compiler = sljit_create_compiler(NULL);
1669 FAILED(!compiler, "cannot create compiler\n");
1671 /* Other part of the jit code. */
1672 sljit_set_context(compiler, 0, 1, 3, 2, 0, 0, 2 * sizeof(sljit_sw));
1674 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);
1675 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_MEM1(SLJIT_SP), 0);
1676 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_sw));
1678 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1680 code2.code = sljit_generate_code(compiler);
1681 CHECK(compiler);
1682 sljit_free_compiler(compiler);
1684 sljit_set_jump_addr(addr, SLJIT_FUNC_OFFSET(code2.code), executable_offset);
1686 FAILED(code1.func1((sljit_sw)&buf) != 19, "test21 case 1 failed\n");
1687 FAILED(buf[2] != -16, "test21 case 2 failed\n");
1688 FAILED(buf[3] != 100, "test21 case 3 failed\n");
1690 sljit_free_code(code1.code);
1691 sljit_free_code(code2.code);
1692 successful_tests++;
1695 static void test22(void)
1697 /* Test simple byte and half-int data transfers. */
1698 executable_code code;
1699 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1700 sljit_sw buf[2];
1701 sljit_s16 sbuf[9];
1702 sljit_s8 bbuf[5];
1704 if (verbose)
1705 printf("Run test22\n");
1707 FAILED(!compiler, "cannot create compiler\n");
1708 buf[0] = 0;
1709 buf[1] = 0;
1711 sbuf[0] = 0;
1712 sbuf[1] = 0;
1713 sbuf[2] = -9;
1714 sbuf[3] = 0;
1715 sbuf[4] = 0;
1716 sbuf[5] = 0;
1717 sbuf[6] = 0;
1719 bbuf[0] = 0;
1720 bbuf[1] = 0;
1721 bbuf[2] = -56;
1722 bbuf[3] = 0;
1723 bbuf[4] = 0;
1725 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), 3, 3, 0, 0, 0);
1727 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, -13);
1728 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s16), SLJIT_IMM, 0x1234);
1729 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_s16));
1730 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
1731 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_IMM, 2 * sizeof(sljit_s16));
1732 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s16), SLJIT_MEM1(SLJIT_S1), -(sljit_sw)sizeof(sljit_s16));
1733 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xff0000 + 8000);
1734 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 2);
1735 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM2(SLJIT_S1, SLJIT_R1), 1, SLJIT_R0, 0);
1736 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R2, 0, SLJIT_S1, 0, SLJIT_IMM, 0x1234 - 3 * sizeof(sljit_s16));
1737 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_R2), 0x1234, SLJIT_IMM, -9317);
1738 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S1, 0, SLJIT_IMM, 0x1234 + 4 * sizeof(sljit_s16));
1739 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_R2), -0x1234, SLJIT_IMM, -9317);
1740 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R2, 0, SLJIT_S1, 0, SLJIT_IMM, 0x12348 - 5 * sizeof(sljit_s16));
1741 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_R2), 0x12348, SLJIT_IMM, -8888);
1742 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S1, 0, SLJIT_IMM, 0x12348 + 6 * sizeof(sljit_s16));
1743 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_R2), -0x12348, SLJIT_IMM, -8888);
1745 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_MEM1(SLJIT_S2), 0, SLJIT_IMM, -45);
1746 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_s8), SLJIT_IMM, 0x12);
1747 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4 * sizeof(sljit_s8));
1748 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_s8));
1749 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_S1, 0, SLJIT_R1, 0);
1750 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_S1, 0, SLJIT_S1, 0);
1751 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R2, 0, SLJIT_S1, 0);
1752 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R2, 0);
1753 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S2), 3 * sizeof(sljit_s8), SLJIT_S1, 0);
1754 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM2(SLJIT_S2, SLJIT_R0), 0, SLJIT_R0, 0);
1756 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1758 code.code = sljit_generate_code(compiler);
1759 CHECK(compiler);
1760 sljit_free_compiler(compiler);
1762 code.func3((sljit_sw)&buf, (sljit_sw)&sbuf, (sljit_sw)&bbuf);
1763 FAILED(buf[0] != -9, "test22 case 1 failed\n");
1764 FAILED(buf[1] != -56, "test22 case 2 failed\n");
1766 FAILED(sbuf[0] != -13, "test22 case 3 failed\n");
1767 FAILED(sbuf[1] != 0x1234, "test22 case 4 failed\n");
1768 FAILED(sbuf[3] != 0x1234, "test22 case 5 failed\n");
1769 FAILED(sbuf[4] != 8000, "test22 case 6 failed\n");
1770 FAILED(sbuf[5] != -9317, "test22 case 7 failed\n");
1771 FAILED(sbuf[6] != -9317, "test22 case 8 failed\n");
1772 FAILED(sbuf[7] != -8888, "test22 case 9 failed\n");
1773 FAILED(sbuf[8] != -8888, "test22 case 10 failed\n");
1775 FAILED(bbuf[0] != -45, "test22 case 11 failed\n");
1776 FAILED(bbuf[1] != 0x12, "test22 case 12 failed\n");
1777 FAILED(bbuf[3] != -56, "test22 case 13 failed\n");
1778 FAILED(bbuf[4] != 4, "test22 case 14 failed\n");
1780 sljit_free_code(code.code);
1781 successful_tests++;
1784 static void test23(void)
1786 /* Test 32 bit / 64 bit signed / unsigned int transfer and conversion.
1787 This test has do real things on 64 bit systems, but works on 32 bit systems as well. */
1788 executable_code code;
1789 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1790 sljit_sw buf[9];
1791 sljit_s32 ibuf[5];
1792 union {
1793 sljit_s32 asint;
1794 sljit_u8 asbytes[4];
1795 } u;
1796 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1797 sljit_sw garbage = SLJIT_W(0x1234567812345678);
1798 #else
1799 sljit_sw garbage = 0x12345678;
1800 #endif
1802 if (verbose)
1803 printf("Run test23\n");
1805 FAILED(!compiler, "cannot create compiler\n");
1806 buf[0] = 0;
1807 buf[1] = 0;
1808 buf[2] = 0;
1809 buf[3] = 0;
1810 buf[4] = 0;
1811 buf[5] = 0;
1812 buf[6] = 0;
1813 buf[7] = 0;
1814 buf[8] = 0;
1816 ibuf[0] = 0;
1817 ibuf[1] = 0;
1818 ibuf[2] = -5791;
1819 ibuf[3] = 43579;
1820 ibuf[4] = 658923;
1822 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 3, 3, 0, 0, 0);
1823 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, 34567);
1824 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4);
1825 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), 0, SLJIT_IMM, -7654);
1826 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, garbage);
1827 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_s32));
1828 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
1829 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, garbage);
1830 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_s32));
1831 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
1832 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, garbage);
1833 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_s32));
1834 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
1835 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
1836 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x0f00f00);
1837 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 0x7777);
1838 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 0x7777 + 3 * sizeof(sljit_sw), SLJIT_R0, 0);
1839 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 0x7777);
1840 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), -0x7777 + 4 * (sljit_sw)sizeof(sljit_sw), SLJIT_R0, 0);
1841 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 5 * sizeof(sljit_sw));
1842 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 1);
1843 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_R1, SLJIT_R1), 0, SLJIT_IMM, 16);
1844 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
1845 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), 1, SLJIT_IMM, 64, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), 1);
1846 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM0(), (sljit_sw)&buf[7], SLJIT_IMM, 0x123456);
1847 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), (sljit_sw)&buf[6], SLJIT_MEM0(), (sljit_sw)&buf[7]);
1848 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 5 * sizeof(sljit_sw));
1849 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 2 * sizeof(sljit_sw), SLJIT_R1, 0);
1850 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S0, 0, SLJIT_IMM, 7 * sizeof(sljit_sw));
1851 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, 1);
1852 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM2(SLJIT_R2, SLJIT_R2), 0);
1853 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[8] - 0x12340);
1854 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0x12340, SLJIT_R2, 0);
1855 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_R0), 0x12340, SLJIT_MEM1(SLJIT_R2), 3 * sizeof(sljit_sw), SLJIT_IMM, 6);
1856 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_s32), SLJIT_IMM, 0x12345678);
1857 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x2bd700 | 243);
1858 sljit_emit_return(compiler, SLJIT_MOV_S8, SLJIT_R1, 0);
1860 code.code = sljit_generate_code(compiler);
1861 CHECK(compiler);
1862 sljit_free_compiler(compiler);
1864 FAILED(code.func2((sljit_sw)&buf, (sljit_sw)&ibuf) != -13, "test23 case 1 failed\n");
1865 FAILED(buf[0] != -5791, "test23 case 2 failed\n");
1866 FAILED(buf[1] != 43579, "test23 case 3 failed\n");
1867 FAILED(buf[2] != 658923, "test23 case 4 failed\n");
1868 FAILED(buf[3] != 0x0f00f00, "test23 case 5 failed\n");
1869 FAILED(buf[4] != 0x0f00f00, "test23 case 6 failed\n");
1870 FAILED(buf[5] != 80, "test23 case 7 failed\n");
1871 FAILED(buf[6] != 0x123456, "test23 case 8 failed\n");
1872 FAILED(buf[7] != (sljit_sw)&buf[5], "test23 case 9 failed\n");
1873 FAILED(buf[8] != (sljit_sw)&buf[5] + 6, "test23 case 10 failed\n");
1875 FAILED(ibuf[0] != 34567, "test23 case 11 failed\n");
1876 FAILED(ibuf[1] != -7654, "test23 case 12 failed\n");
1877 u.asint = ibuf[4];
1878 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1879 FAILED(u.asbytes[0] != 0x78, "test23 case 13 failed\n");
1880 FAILED(u.asbytes[1] != 0x56, "test23 case 14 failed\n");
1881 FAILED(u.asbytes[2] != 0x34, "test23 case 15 failed\n");
1882 FAILED(u.asbytes[3] != 0x12, "test23 case 16 failed\n");
1883 #else
1884 FAILED(u.asbytes[0] != 0x12, "test23 case 13 failed\n");
1885 FAILED(u.asbytes[1] != 0x34, "test23 case 14 failed\n");
1886 FAILED(u.asbytes[2] != 0x56, "test23 case 15 failed\n");
1887 FAILED(u.asbytes[3] != 0x78, "test23 case 16 failed\n");
1888 #endif
1890 sljit_free_code(code.code);
1891 successful_tests++;
1894 static void test24(void)
1896 /* Some complicated addressing modes. */
1897 executable_code code;
1898 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
1899 sljit_sw buf[9];
1900 sljit_s16 sbuf[5];
1901 sljit_s8 bbuf[7];
1903 if (verbose)
1904 printf("Run test24\n");
1906 FAILED(!compiler, "cannot create compiler\n");
1908 buf[0] = 100567;
1909 buf[1] = 75799;
1910 buf[2] = 0;
1911 buf[3] = -8;
1912 buf[4] = -50;
1913 buf[5] = 0;
1914 buf[6] = 0;
1915 buf[7] = 0;
1916 buf[8] = 0;
1918 sbuf[0] = 30000;
1919 sbuf[1] = 0;
1920 sbuf[2] = 0;
1921 sbuf[3] = -12345;
1922 sbuf[4] = 0;
1924 bbuf[0] = -128;
1925 bbuf[1] = 0;
1926 bbuf[2] = 0;
1927 bbuf[3] = 99;
1928 bbuf[4] = 0;
1929 bbuf[5] = 0;
1930 bbuf[6] = 0;
1932 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), 3, 3, 0, 0, 0);
1934 /* Nothing should be updated. */
1935 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM0(), (sljit_sw)&sbuf[1], SLJIT_MEM0(), (sljit_sw)&sbuf[0]);
1936 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_MEM0(), (sljit_sw)&bbuf[1], SLJIT_MEM0(), (sljit_sw)&bbuf[0]);
1937 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
1938 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), 1, SLJIT_MEM0(), (sljit_sw)&sbuf[3]);
1939 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[0]);
1940 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
1941 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 2);
1942 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);
1943 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_s8));
1944 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_R0), (sljit_sw)&bbuf[1], SLJIT_MEM1(SLJIT_R0), (sljit_sw)&bbuf[2]);
1946 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_s16));
1947 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_R1), (sljit_sw)&sbuf[3], SLJIT_R1, 0);
1949 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 3);
1950 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);
1951 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4);
1952 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_S0, 0);
1953 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);
1955 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 9 * sizeof(sljit_sw));
1956 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 4 * sizeof(sljit_sw));
1957 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -4 << SLJIT_WORD_SHIFT);
1958 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_R0, SLJIT_R2), 0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
1960 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf - 0x7fff8000 + 6 * sizeof(sljit_sw));
1961 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 952467);
1962 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0x7fff8000, SLJIT_R1, 0);
1963 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0x7fff8000 + sizeof(sljit_sw), SLJIT_MEM1(SLJIT_R0), 0x7fff8000);
1965 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf + 0x7fff7fff + 6 * sizeof(sljit_sw));
1966 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_R0), -0x7fff7fff + 2 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_R0), -0x7fff7fff + sizeof(sljit_sw), SLJIT_MEM1(SLJIT_R0), -0x7fff7fff);
1967 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&bbuf - 0x7fff7ffe + 3 * sizeof(sljit_s8));
1968 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_MEM1(SLJIT_R0), 0x7fff7fff, SLJIT_MEM1(SLJIT_R0), 0x7fff7ffe);
1969 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&bbuf + 0x7fff7fff + 5 * sizeof(sljit_s8));
1970 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_MEM1(SLJIT_R0), -0x7fff7fff, SLJIT_MEM1(SLJIT_R0), -0x7fff8000);
1971 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1972 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&bbuf - SLJIT_W(0x123456123456));
1973 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&bbuf - SLJIT_W(0x123456123456));
1974 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));
1975 #endif
1977 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
1979 code.code = sljit_generate_code(compiler);
1980 CHECK(compiler);
1981 sljit_free_compiler(compiler);
1983 code.func3((sljit_sw)&buf, (sljit_sw)&sbuf, (sljit_sw)&bbuf);
1984 FAILED(buf[2] != 176366, "test24 case 1 failed\n");
1985 FAILED(buf[3] != 64, "test24 case 2 failed\n");
1986 FAILED(buf[4] != -100, "test24 case 3 failed\n");
1987 FAILED(buf[5] != 100567, "test24 case 4 failed\n");
1988 FAILED(buf[6] != 952467, "test24 case 5 failed\n");
1989 FAILED(buf[7] != 952467, "test24 case 6 failed\n");
1990 FAILED(buf[8] != 952467 * 2, "test24 case 7 failed\n");
1992 FAILED(sbuf[1] != 30000, "test24 case 8 failed\n");
1993 FAILED(sbuf[2] != -12345, "test24 case 9 failed\n");
1994 FAILED(sbuf[4] != sizeof(sljit_s16), "test24 case 10 failed\n");
1996 FAILED(bbuf[1] != -128, "test24 case 11 failed\n");
1997 FAILED(bbuf[2] != 99, "test24 case 12 failed\n");
1998 FAILED(bbuf[4] != 99, "test24 case 13 failed\n");
1999 FAILED(bbuf[5] != 99, "test24 case 14 failed\n");
2000 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2001 FAILED(bbuf[6] != -128, "test24 case 15 failed\n");
2002 #endif
2004 sljit_free_code(code.code);
2005 successful_tests++;
2008 static void test25(void)
2010 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2011 /* 64 bit loads. */
2012 executable_code code;
2013 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2014 sljit_sw buf[14];
2016 if (verbose)
2017 printf("Run test25\n");
2019 FAILED(!compiler, "cannot create compiler\n");
2020 buf[0] = 7;
2021 buf[1] = 0;
2022 buf[2] = 0;
2023 buf[3] = 0;
2024 buf[4] = 0;
2025 buf[5] = 0;
2026 buf[6] = 0;
2027 buf[7] = 0;
2028 buf[8] = 0;
2029 buf[9] = 0;
2030 buf[10] = 0;
2031 buf[11] = 0;
2032 buf[12] = 0;
2033 buf[13] = 0;
2035 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 0, 0, 0);
2037 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0);
2038 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 1 * sizeof(sljit_sw), SLJIT_IMM, 0x7fff);
2039 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_IMM, -0x8000);
2040 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_IMM, 0x7fffffff);
2041 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(-0x80000000));
2042 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x1234567887654321));
2043 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0xff80000000));
2044 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x3ff0000000));
2045 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0xfffffff800100000));
2046 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0xfffffff80010f000));
2047 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00000008001));
2048 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00080010000));
2049 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00080018001));
2050 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00ffff00000));
2052 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2054 code.code = sljit_generate_code(compiler);
2055 CHECK(compiler);
2056 sljit_free_compiler(compiler);
2058 code.func1((sljit_sw)&buf);
2059 FAILED(buf[0] != 0, "test25 case 1 failed\n");
2060 FAILED(buf[1] != 0x7fff, "test25 case 2 failed\n");
2061 FAILED(buf[2] != -0x8000, "test25 case 3 failed\n");
2062 FAILED(buf[3] != 0x7fffffff, "test25 case 4 failed\n");
2063 FAILED(buf[4] != SLJIT_W(-0x80000000), "test25 case 5 failed\n");
2064 FAILED(buf[5] != SLJIT_W(0x1234567887654321), "test25 case 6 failed\n");
2065 FAILED(buf[6] != SLJIT_W(0xff80000000), "test25 case 7 failed\n");
2066 FAILED(buf[7] != SLJIT_W(0x3ff0000000), "test25 case 8 failed\n");
2067 FAILED((sljit_uw)buf[8] != SLJIT_W(0xfffffff800100000), "test25 case 9 failed\n");
2068 FAILED((sljit_uw)buf[9] != SLJIT_W(0xfffffff80010f000), "test25 case 10 failed\n");
2069 FAILED(buf[10] != SLJIT_W(0x07fff00000008001), "test25 case 11 failed\n");
2070 FAILED(buf[11] != SLJIT_W(0x07fff00080010000), "test25 case 12 failed\n");
2071 FAILED(buf[12] != SLJIT_W(0x07fff00080018001), "test25 case 13 failed\n");
2072 FAILED(buf[13] != SLJIT_W(0x07fff00ffff00000), "test25 case 14 failed\n");
2074 sljit_free_code(code.code);
2075 #endif
2076 successful_tests++;
2079 static void test26(void)
2081 /* Aligned access without aligned offsets. */
2082 executable_code code;
2083 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2084 sljit_sw buf[4];
2085 sljit_s32 ibuf[4];
2086 sljit_f64 dbuf[4];
2088 if (verbose)
2089 printf("Run test26\n");
2091 FAILED(!compiler, "cannot create compiler\n");
2093 buf[0] = -2789;
2094 buf[1] = 0;
2095 buf[2] = 4;
2096 buf[3] = -4;
2098 ibuf[0] = -689;
2099 ibuf[1] = 0;
2100 ibuf[2] = -6;
2101 ibuf[3] = 3;
2103 dbuf[0] = 5.75;
2104 dbuf[1] = 0.0;
2105 dbuf[2] = 0.0;
2106 dbuf[3] = -4.0;
2108 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), 3, 3, 0, 0, 0);
2110 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 3);
2111 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_IMM, 1);
2112 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), -3);
2113 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32) - 1, SLJIT_R0, 0);
2114 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), -1);
2115 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) - 3, SLJIT_R0, 0);
2117 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 100);
2118 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);
2119 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_IMM, 100);
2120 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);
2122 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
2123 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S2, 0, SLJIT_S2, 0, SLJIT_IMM, 3);
2124 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f64) - 3, SLJIT_MEM1(SLJIT_S2), -3);
2125 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);
2126 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S2, 0, SLJIT_IMM, 2);
2127 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sizeof(sljit_f64) * 3 - 4) >> 1);
2128 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, 1);
2129 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);
2132 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2134 code.code = sljit_generate_code(compiler);
2135 CHECK(compiler);
2136 sljit_free_compiler(compiler);
2138 code.func3((sljit_sw)&buf, (sljit_sw)&ibuf, (sljit_sw)&dbuf);
2140 FAILED(buf[1] != -689, "test26 case 1 failed\n");
2141 FAILED(buf[2] != -16, "test26 case 2 failed\n");
2142 FAILED(ibuf[1] != -2789, "test26 case 3 failed\n");
2143 FAILED(ibuf[2] != -18, "test26 case 4 failed\n");
2145 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
2146 FAILED(dbuf[1] != 5.75, "test26 case 5 failed\n");
2147 FAILED(dbuf[2] != 11.5, "test26 case 6 failed\n");
2148 FAILED(dbuf[3] != -2.875, "test26 case 7 failed\n");
2151 sljit_free_code(code.code);
2152 successful_tests++;
2155 static void test27(void)
2157 #define SET_NEXT_BYTE(type) \
2158 cond_set(compiler, SLJIT_R2, 0, type); \
2159 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R2, 0); \
2160 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
2161 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2162 #define RESULT(i) i
2163 #else
2164 #define RESULT(i) (3 - i)
2165 #endif
2167 /* Playing with conditional flags. */
2168 executable_code code;
2169 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2170 sljit_u8 buf[37];
2171 sljit_s32 i;
2172 #ifdef SLJIT_PREF_SHIFT_REG
2173 sljit_s32 shift_reg = SLJIT_PREF_SHIFT_REG;
2174 #else
2175 sljit_s32 shift_reg = SLJIT_R2;
2176 #endif
2178 SLJIT_ASSERT(shift_reg >= SLJIT_R2 && shift_reg <= SLJIT_R3);
2180 if (verbose)
2181 printf("Run test27\n");
2183 for (i = 0; i < 37; ++i)
2184 buf[i] = 10;
2186 FAILED(!compiler, "cannot create compiler\n");
2188 /* 3 arguments passed, 3 arguments used. */
2189 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 4, 3, 0, 0, 0);
2191 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
2193 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x1001);
2194 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 20);
2195 /* 0x100100000 on 64 bit machines, 0x100000 on 32 bit machines. */
2196 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x800000);
2197 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2198 sljit_emit_op0(compiler, SLJIT_NOP); /* Nop should keep the flags. */
2199 SET_NEXT_BYTE(SLJIT_GREATER);
2200 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2201 SET_NEXT_BYTE(SLJIT_LESS);
2202 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
2203 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_R1, 0);
2204 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2205 sljit_emit_op0(compiler, SLJIT_NOP); /* Nop should keep the flags. */
2206 SET_NEXT_BYTE(SLJIT_GREATER32);
2207 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2208 SET_NEXT_BYTE(SLJIT_LESS32);
2210 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x1000);
2211 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 20);
2212 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0x10);
2213 /* 0x100000010 on 64 bit machines, 0x10 on 32 bit machines. */
2214 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0x80);
2215 SET_NEXT_BYTE(SLJIT_GREATER);
2216 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0x80);
2217 SET_NEXT_BYTE(SLJIT_LESS);
2218 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
2219 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0x80);
2220 SET_NEXT_BYTE(SLJIT_GREATER32);
2221 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0x80);
2222 SET_NEXT_BYTE(SLJIT_LESS32);
2224 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2225 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2226 /* 0xff..ff on all machines. */
2227 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS_EQUAL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2228 SET_NEXT_BYTE(SLJIT_LESS_EQUAL);
2229 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2230 SET_NEXT_BYTE(SLJIT_GREATER_EQUAL);
2231 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_R2, 0, SLJIT_R1, 0, SLJIT_IMM, -1);
2232 SET_NEXT_BYTE(SLJIT_SIG_GREATER);
2233 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, -1);
2234 SET_NEXT_BYTE(SLJIT_SIG_LESS);
2235 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R2, 0, SLJIT_R1, 0, SLJIT_R0, 0);
2236 SET_NEXT_BYTE(SLJIT_EQUAL);
2237 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_R0, 0);
2238 SET_NEXT_BYTE(SLJIT_NOT_EQUAL);
2239 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, -2);
2240 SET_NEXT_BYTE(SLJIT_OVERFLOW);
2241 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, -2);
2242 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW);
2243 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, -2);
2244 SET_NEXT_BYTE(SLJIT_GREATER_EQUAL);
2245 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, -2);
2246 SET_NEXT_BYTE(SLJIT_LESS_EQUAL);
2248 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x80000000);
2249 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 16);
2250 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 16);
2251 /* 0x80..0 on 64 bit machines, 0 on 32 bit machines. */
2252 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0xffffffff);
2253 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2254 SET_NEXT_BYTE(SLJIT_OVERFLOW);
2255 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2256 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW);
2257 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
2258 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R1, 0, SLJIT_R1, 0);
2259 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2260 SET_NEXT_BYTE(SLJIT_OVERFLOW32);
2261 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2262 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW32);
2264 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2265 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_CARRY, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2266 sljit_emit_op2(compiler, SLJIT_SUBC | SLJIT_SET_CARRY, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0);
2267 sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_R0, 0, SLJIT_IMM, 6, SLJIT_R0, 0);
2268 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R0, 0);
2269 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
2271 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
2272 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_CARRY, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2273 sljit_emit_op2(compiler, SLJIT_ADDC | SLJIT_SET_CARRY, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2274 sljit_emit_op2(compiler, SLJIT_ADDC, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 9);
2275 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R0, 0);
2276 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
2278 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
2279 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, (8 * sizeof(sljit_sw)) - 1);
2280 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0);
2281 SET_NEXT_BYTE(SLJIT_EQUAL);
2282 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R0, 0);
2283 SET_NEXT_BYTE(SLJIT_EQUAL);
2285 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2286 sljit_emit_op2(compiler, SLJIT_ASHR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0);
2287 SET_NEXT_BYTE(SLJIT_EQUAL);
2288 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
2289 sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffffc0);
2290 SET_NEXT_BYTE(SLJIT_NOT_EQUAL);
2291 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 0);
2292 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2293 sljit_emit_op2(compiler, SLJIT_ASHR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0, shift_reg, 0);
2294 SET_NEXT_BYTE(SLJIT_EQUAL);
2295 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 0);
2296 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
2297 sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0, shift_reg, 0);
2298 SET_NEXT_BYTE(SLJIT_NOT_EQUAL);
2300 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2301 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
2302 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_CARRY, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R0, 0);
2303 sljit_emit_op2(compiler, SLJIT_SUBC | SLJIT_SET_CARRY, SLJIT_R2, 0, SLJIT_IMM, 1, SLJIT_R0, 0);
2304 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R2, 0);
2305 sljit_emit_op2(compiler, SLJIT_SUBC | SLJIT_SET_CARRY, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2306 sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_R2, 0, SLJIT_IMM, 1, SLJIT_R0, 0);
2307 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 2, SLJIT_R2, 0);
2308 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 2);
2310 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -34);
2311 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0x1234);
2312 SET_NEXT_BYTE(SLJIT_LESS);
2313 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0x1234);
2314 SET_NEXT_BYTE(SLJIT_SIG_LESS);
2315 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2316 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x12300000000) - 43);
2317 #else
2318 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, -43);
2319 #endif
2320 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -96);
2321 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2322 SET_NEXT_BYTE(SLJIT_LESS32);
2323 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_SIG_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2324 SET_NEXT_BYTE(SLJIT_SIG_GREATER32);
2326 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2328 code.code = sljit_generate_code(compiler);
2329 CHECK(compiler);
2330 sljit_free_compiler(compiler);
2332 code.func1((sljit_sw)&buf);
2334 FAILED(buf[0] != RESULT(1), "test27 case 1 failed\n");
2335 FAILED(buf[1] != RESULT(2), "test27 case 2 failed\n");
2336 FAILED(buf[2] != 2, "test27 case 3 failed\n");
2337 FAILED(buf[3] != 1, "test27 case 4 failed\n");
2338 FAILED(buf[4] != RESULT(1), "test27 case 5 failed\n");
2339 FAILED(buf[5] != RESULT(2), "test27 case 6 failed\n");
2340 FAILED(buf[6] != 2, "test27 case 7 failed\n");
2341 FAILED(buf[7] != 1, "test27 case 8 failed\n");
2343 FAILED(buf[8] != 2, "test27 case 9 failed\n");
2344 FAILED(buf[9] != 1, "test27 case 10 failed\n");
2345 FAILED(buf[10] != 2, "test27 case 11 failed\n");
2346 FAILED(buf[11] != 1, "test27 case 12 failed\n");
2347 FAILED(buf[12] != 1, "test27 case 13 failed\n");
2348 FAILED(buf[13] != 2, "test27 case 14 failed\n");
2349 FAILED(buf[14] != 2, "test27 case 15 failed\n");
2350 FAILED(buf[15] != 1, "test27 case 16 failed\n");
2351 FAILED(buf[16] != 1, "test27 case 17 failed\n");
2352 FAILED(buf[17] != 2, "test27 case 18 failed\n");
2354 FAILED(buf[18] != RESULT(1), "test27 case 19 failed\n");
2355 FAILED(buf[19] != RESULT(2), "test27 case 20 failed\n");
2356 FAILED(buf[20] != 2, "test27 case 21 failed\n");
2357 FAILED(buf[21] != 1, "test27 case 22 failed\n");
2359 FAILED(buf[22] != 5, "test27 case 23 failed\n");
2360 FAILED(buf[23] != 9, "test27 case 24 failed\n");
2362 FAILED(buf[24] != 2, "test27 case 25 failed\n");
2363 FAILED(buf[25] != 1, "test27 case 26 failed\n");
2365 FAILED(buf[26] != 1, "test27 case 27 failed\n");
2366 FAILED(buf[27] != 1, "test27 case 28 failed\n");
2367 FAILED(buf[28] != 1, "test27 case 29 failed\n");
2368 FAILED(buf[29] != 1, "test27 case 30 failed\n");
2370 FAILED(buf[30] != 1, "test27 case 31 failed\n");
2371 FAILED(buf[31] != 0, "test27 case 32 failed\n");
2373 FAILED(buf[32] != 2, "test27 case 33 failed\n");
2374 FAILED(buf[33] != 1, "test27 case 34 failed\n");
2375 FAILED(buf[34] != 2, "test27 case 35 failed\n");
2376 FAILED(buf[35] != 1, "test27 case 36 failed\n");
2377 FAILED(buf[36] != 10, "test27 case 37 failed\n");
2379 sljit_free_code(code.code);
2380 successful_tests++;
2381 #undef SET_NEXT_BYTE
2382 #undef RESULT
2385 static void test28(void)
2387 /* Test mov. */
2388 executable_code code;
2389 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2390 struct sljit_const* const1 = NULL;
2391 struct sljit_label* label = NULL;
2392 sljit_uw label_addr = 0;
2393 sljit_sw buf[5];
2395 if (verbose)
2396 printf("Run test28\n");
2398 FAILED(!compiler, "cannot create compiler\n");
2400 buf[0] = -36;
2401 buf[1] = 8;
2402 buf[2] = 0;
2403 buf[3] = 10;
2404 buf[4] = 0;
2406 FAILED(!compiler, "cannot create compiler\n");
2407 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 5, 5, 0, 0, 0);
2408 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -234);
2409 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw));
2410 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_S3, 0, SLJIT_R3, 0, SLJIT_R4, 0);
2411 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_S3, 0);
2412 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_S3, 0, SLJIT_IMM, 0);
2413 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_NOT_ZERO);
2414 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_S3, 0);
2415 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S4, 0, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw));
2416 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S4, 0, SLJIT_S4, 0, SLJIT_R4, 0);
2417 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_S4, 0);
2419 const1 = sljit_emit_const(compiler, SLJIT_S3, 0, 0);
2420 sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_S3, 0);
2421 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S3, 0, SLJIT_S3, 0, SLJIT_IMM, 100);
2422 label = sljit_emit_label(compiler);
2423 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_S3, 0);
2425 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R4, 0);
2427 code.code = sljit_generate_code(compiler);
2428 CHECK(compiler);
2430 label_addr = sljit_get_label_addr(label);
2431 sljit_set_const(sljit_get_const_addr(const1), label_addr, sljit_get_executable_offset(compiler));
2433 sljit_free_compiler(compiler);
2435 FAILED(code.func1((sljit_sw)&buf) != 8, "test28 case 1 failed\n");
2436 FAILED(buf[1] != -1872, "test28 case 2 failed\n");
2437 FAILED(buf[2] != 1, "test28 case 3 failed\n");
2438 FAILED(buf[3] != 2, "test28 case 4 failed\n");
2439 FAILED(buf[4] != label_addr, "test28 case 5 failed\n");
2441 sljit_free_code(code.code);
2442 successful_tests++;
2445 static void test29(void)
2447 /* Test signed/unsigned bytes and halfs. */
2448 executable_code code;
2449 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2450 sljit_sw buf[25];
2451 sljit_s32 i;
2453 if (verbose)
2454 printf("Run test29\n");
2456 for (i = 0; i < 25; i++)
2457 buf[i] = 0;
2459 FAILED(!compiler, "cannot create compiler\n");
2460 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 5, 5, 0, 0, 0);
2462 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R0, 0, SLJIT_IMM, -187);
2463 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
2464 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R0, 0, SLJIT_IMM, -605);
2465 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R0, 0);
2466 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R0, 0, SLJIT_IMM, -56);
2467 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_uw), SLJIT_R0, 0);
2468 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R4, 0, SLJIT_IMM, 0xcde5);
2469 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_uw), SLJIT_R4, 0);
2471 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_R0, 0, SLJIT_IMM, -45896);
2472 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_uw), SLJIT_R0, 0);
2473 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_R0, 0, SLJIT_IMM, -1472797);
2474 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_uw), SLJIT_R0, 0);
2475 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_R0, 0, SLJIT_IMM, -12890);
2476 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_uw), SLJIT_R0, 0);
2477 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_R4, 0, SLJIT_IMM, 0x9cb0a6);
2478 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_uw), SLJIT_R4, 0);
2480 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2481 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-3580429715));
2482 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_uw), SLJIT_R0, 0);
2483 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-100722768662));
2484 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_uw), SLJIT_R0, 0);
2485 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-1457052677972));
2486 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_uw), SLJIT_R0, 0);
2487 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R4, 0, SLJIT_IMM, SLJIT_W(0xcef97a70b5));
2488 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_uw), SLJIT_R4, 0);
2489 #endif
2491 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -187);
2492 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R0, 0, SLJIT_R1, 0);
2493 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_uw), SLJIT_R0, 0);
2494 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, -605);
2495 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R0, 0, SLJIT_S2, 0);
2496 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_uw), SLJIT_R0, 0);
2497 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -56);
2498 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R0, 0, SLJIT_R2, 0);
2499 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_uw), SLJIT_R0, 0);
2500 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0xcde5);
2501 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R4, 0, SLJIT_R3, 0);
2502 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 15 * sizeof(sljit_uw), SLJIT_R4, 0);
2504 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -45896);
2505 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_R0, 0, SLJIT_R1, 0);
2506 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 16 * sizeof(sljit_uw), SLJIT_R0, 0);
2507 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, -1472797);
2508 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_R0, 0, SLJIT_S2, 0);
2509 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 17 * sizeof(sljit_uw), SLJIT_R0, 0);
2510 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -12890);
2511 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_R0, 0, SLJIT_R2, 0);
2512 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_uw), SLJIT_R0, 0);
2513 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0x9cb0a6);
2514 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_R4, 0, SLJIT_R3, 0);
2515 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 19 * sizeof(sljit_uw), SLJIT_R4, 0);
2517 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2518 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(-3580429715));
2519 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R1, 0);
2520 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 20 * sizeof(sljit_uw), SLJIT_R0, 0);
2521 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, SLJIT_W(-100722768662));
2522 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_S2, 0);
2523 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 21 * sizeof(sljit_uw), SLJIT_R0, 0);
2524 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, SLJIT_W(-1457052677972));
2525 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R2, 0);
2526 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 22 * sizeof(sljit_uw), SLJIT_R0, 0);
2527 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, SLJIT_W(0xcef97a70b5));
2528 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R4, 0, SLJIT_R3, 0);
2529 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 23 * sizeof(sljit_uw), SLJIT_R4, 0);
2530 #endif
2532 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, 0x9faa5);
2533 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_S2, 0, SLJIT_S2, 0);
2534 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 24 * sizeof(sljit_uw), SLJIT_S2, 0);
2536 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2538 code.code = sljit_generate_code(compiler);
2539 CHECK(compiler);
2540 sljit_free_compiler(compiler);
2542 code.func1((sljit_sw)&buf);
2543 FAILED(buf[0] != 69, "test29 case 1 failed\n");
2544 FAILED(buf[1] != -93, "test29 case 2 failed\n");
2545 FAILED(buf[2] != 200, "test29 case 3 failed\n");
2546 FAILED(buf[3] != 0xe5, "test29 case 4 failed\n");
2547 FAILED(buf[4] != 19640, "test29 case 5 failed\n");
2548 FAILED(buf[5] != -31005, "test29 case 6 failed\n");
2549 FAILED(buf[6] != 52646, "test29 case 7 failed\n");
2550 FAILED(buf[7] != 0xb0a6, "test29 case 8 failed\n");
2552 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2553 FAILED(buf[8] != SLJIT_W(714537581), "test29 case 9 failed\n");
2554 FAILED(buf[9] != SLJIT_W(-1938520854), "test29 case 10 failed\n");
2555 FAILED(buf[10] != SLJIT_W(3236202668), "test29 case 11 failed\n");
2556 FAILED(buf[11] != SLJIT_W(0xf97a70b5), "test29 case 12 failed\n");
2557 #endif
2559 FAILED(buf[12] != 69, "test29 case 13 failed\n");
2560 FAILED(buf[13] != -93, "test29 case 14 failed\n");
2561 FAILED(buf[14] != 200, "test29 case 15 failed\n");
2562 FAILED(buf[15] != 0xe5, "test29 case 16 failed\n");
2563 FAILED(buf[16] != 19640, "test29 case 17 failed\n");
2564 FAILED(buf[17] != -31005, "test29 case 18 failed\n");
2565 FAILED(buf[18] != 52646, "test29 case 19 failed\n");
2566 FAILED(buf[19] != 0xb0a6, "test29 case 20 failed\n");
2568 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2569 FAILED(buf[20] != SLJIT_W(714537581), "test29 case 21 failed\n");
2570 FAILED(buf[21] != SLJIT_W(-1938520854), "test29 case 22 failed\n");
2571 FAILED(buf[22] != SLJIT_W(3236202668), "test29 case 23 failed\n");
2572 FAILED(buf[23] != SLJIT_W(0xf97a70b5), "test29 case 24 failed\n");
2573 #endif
2575 FAILED(buf[24] != -91, "test29 case 25 failed\n");
2577 sljit_free_code(code.code);
2578 successful_tests++;
2581 static void test30(void)
2583 /* Test unused results. */
2584 executable_code code;
2585 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2586 sljit_sw buf[1];
2588 if (verbose)
2589 printf("Run test30\n");
2591 FAILED(!compiler, "cannot create compiler\n");
2592 buf[0] = 0;
2593 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 5, 5, 0, 0, 0);
2595 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
2596 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
2597 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 1);
2598 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 1);
2599 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_IMM, 1);
2600 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2601 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_S1, 0, SLJIT_IMM, SLJIT_W(-0x123ffffffff));
2602 #else
2603 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_S1, 0, SLJIT_IMM, 1);
2604 #endif
2605 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, 1);
2606 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, 1);
2607 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S4, 0, SLJIT_IMM, 1);
2609 /* Some calculations with unused results. */
2610 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_UNUSED, 0, SLJIT_R2, 0);
2611 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_UNUSED, 0, SLJIT_R1, 0);
2612 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0);
2613 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0);
2614 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_GREATER_EQUAL, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0);
2615 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_UNUSED, 0, SLJIT_S0, 0, SLJIT_MEM1(SLJIT_S0), 0);
2616 sljit_emit_op2(compiler, SLJIT_SHL | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_S3, 0, SLJIT_R2, 0);
2617 sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 5);
2618 sljit_emit_op2(compiler, SLJIT_AND, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0xff);
2619 sljit_emit_op1(compiler, SLJIT_NOT32 | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_S1, 0);
2621 /* Testing that any change happens. */
2622 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2623 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R2, 0);
2624 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R3, 0);
2625 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R4, 0);
2626 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_S1, 0, SLJIT_S1, 0);
2627 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S1, 0);
2628 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S2, 0);
2629 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S3, 0);
2630 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0, SLJIT_S4, 0);
2632 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2634 code.code = sljit_generate_code(compiler);
2635 CHECK(compiler);
2636 sljit_free_compiler(compiler);
2638 code.func1((sljit_sw)&buf);
2639 FAILED(buf[0] != 9, "test30 case 1 failed\n");
2641 sljit_free_code(code.code);
2642 successful_tests++;
2645 static void test31(void)
2647 /* Integer mul and set flags. */
2648 executable_code code;
2649 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2650 sljit_sw buf[12];
2651 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2652 sljit_sw big_word = SLJIT_W(0x7fffffff00000000);
2653 sljit_sw big_word2 = SLJIT_W(0x7fffffff00000012);
2654 #else
2655 sljit_sw big_word = 0x7fffffff;
2656 sljit_sw big_word2 = 0x00000012;
2657 #endif
2659 if (verbose)
2660 printf("Run test31\n");
2662 buf[0] = 3;
2663 buf[1] = 3;
2664 buf[2] = 3;
2665 buf[3] = 3;
2666 buf[4] = 3;
2667 buf[5] = 3;
2668 buf[6] = 3;
2669 buf[7] = 3;
2670 buf[8] = 3;
2671 buf[9] = 3;
2672 buf[10] = 3;
2673 buf[11] = 3;
2675 FAILED(!compiler, "cannot create compiler\n");
2677 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 5, 0, 0, 0);
2678 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
2679 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R1, 0, SLJIT_IMM, -45);
2680 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MUL_NOT_OVERFLOW);
2681 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R1, 0, SLJIT_IMM, -45);
2682 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MUL_OVERFLOW);
2684 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, big_word);
2685 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_OVERFLOW, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, -2);
2686 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 33); /* Should not change flags. */
2687 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0); /* Should not change flags. */
2688 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_MUL_OVERFLOW);
2689 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_OVERFLOW, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, -2);
2690 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_MUL_NOT_OVERFLOW);
2692 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_S3, 0, SLJIT_IMM, 0x3f6b0);
2693 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_S4, 0, SLJIT_IMM, 0x2a783);
2694 sljit_emit_op2(compiler, SLJIT_MUL32 | SLJIT_SET_MUL_OVERFLOW, SLJIT_R1, 0, SLJIT_S3, 0, SLJIT_S4, 0);
2695 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_MUL_OVERFLOW32);
2696 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R1, 0);
2698 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, big_word2);
2699 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R2, 0, SLJIT_R1, 0);
2700 sljit_emit_op2(compiler, SLJIT_MUL32 | SLJIT_SET_MUL_OVERFLOW, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 23);
2701 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_MUL_OVERFLOW32);
2703 sljit_emit_op2(compiler, SLJIT_MUL32 | SLJIT_SET_MUL_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, -23);
2704 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_MUL_NOT_OVERFLOW32);
2705 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, -23);
2706 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_MUL_NOT_OVERFLOW);
2708 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 67);
2709 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_OVERFLOW, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, -23);
2710 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_R1, 0);
2712 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2714 code.code = sljit_generate_code(compiler);
2715 CHECK(compiler);
2716 sljit_free_compiler(compiler);
2718 code.func1((sljit_sw)&buf);
2720 FAILED(buf[0] != 1, "test31 case 1 failed\n");
2721 FAILED(buf[1] != 2, "test31 case 2 failed\n");
2722 /* Qemu issues for 64 bit muls. */
2723 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2724 FAILED(buf[2] != 1, "test31 case 3 failed\n");
2725 FAILED(buf[3] != 2, "test31 case 4 failed\n");
2726 #endif
2727 FAILED(buf[4] != 1, "test31 case 5 failed\n");
2728 FAILED((buf[5] & 0xffffffff) != 0x85540c10, "test31 case 6 failed\n");
2729 FAILED(buf[6] != 2, "test31 case 7 failed\n");
2730 FAILED(buf[7] != 1, "test31 case 8 failed\n");
2731 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2732 FAILED(buf[8] != 1, "test31 case 9 failed\n");
2733 #endif
2734 FAILED(buf[9] != -1541, "test31 case 10 failed\n");
2736 sljit_free_code(code.code);
2737 successful_tests++;
2740 static void test32(void)
2742 /* Floating point set flags. */
2743 executable_code code;
2744 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2746 sljit_sw buf[16];
2747 union {
2748 sljit_f64 value;
2749 struct {
2750 sljit_s32 value1;
2751 sljit_s32 value2;
2752 } u;
2753 } dbuf[4];
2755 if (verbose)
2756 printf("Run test32\n");
2758 buf[0] = 5;
2759 buf[1] = 5;
2760 buf[2] = 5;
2761 buf[3] = 5;
2762 buf[4] = 5;
2763 buf[5] = 5;
2764 buf[6] = 5;
2765 buf[7] = 5;
2766 buf[8] = 5;
2767 buf[9] = 5;
2768 buf[10] = 5;
2769 buf[11] = 5;
2770 buf[12] = 5;
2771 buf[13] = 5;
2772 buf[14] = 5;
2773 buf[15] = 5;
2775 /* Two NaNs */
2776 dbuf[0].u.value1 = 0x7fffffff;
2777 dbuf[0].u.value2 = 0x7fffffff;
2778 dbuf[1].u.value1 = 0x7fffffff;
2779 dbuf[1].u.value2 = 0x7fffffff;
2780 dbuf[2].value = -13.0;
2781 dbuf[3].value = 27.0;
2783 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
2784 if (verbose)
2785 printf("no fpu available, test32 skipped\n");
2786 successful_tests++;
2787 if (compiler)
2788 sljit_free_compiler(compiler);
2789 return;
2792 FAILED(!compiler, "cannot create compiler\n");
2793 SLJIT_ASSERT(sizeof(sljit_f64) == 8 && sizeof(sljit_s32) == 4 && sizeof(dbuf[0]) == 8);
2795 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 1, 2, 4, 0, 0);
2797 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), 0);
2798 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_UNORDERED_F, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64), SLJIT_FR0, 0);
2799 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f64));
2800 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_UNORDERED_F64);
2801 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_ORDERED_F, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64), SLJIT_FR0, 0);
2802 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_ORDERED_F64);
2804 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64));
2805 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_UNORDERED_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2806 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_UNORDERED_F64);
2807 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_ORDERED_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2808 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_ORDERED_F64);
2809 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_LESS_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2810 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_LESS_F64);
2811 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_GREATER_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2812 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_GREATER_EQUAL_F64);
2813 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_GREATER_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2814 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_GREATER_F64);
2815 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_LESS_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2816 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_LESS_EQUAL_F64);
2817 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2818 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_EQUAL_F64);
2819 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_NOT_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2820 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_NOT_EQUAL_F64);
2822 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_UNORDERED_F, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64));
2823 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR3, 0, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f64));
2824 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_UNORDERED_F64);
2825 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_EQUAL_F, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64));
2826 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_EQUAL_F64);
2828 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_ORDERED_F, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f64), SLJIT_FR0, 0);
2829 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_ORDERED_F64);
2831 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_UNORDERED_F, SLJIT_FR3, 0, SLJIT_FR2, 0);
2832 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), 0);
2833 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_UNORDERED_F64);
2835 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2837 code.code = sljit_generate_code(compiler);
2838 CHECK(compiler);
2839 sljit_free_compiler(compiler);
2841 code.func2((sljit_sw)&buf, (sljit_sw)&dbuf);
2843 FAILED(buf[0] != 1, "test32 case 1 failed\n");
2844 FAILED(buf[1] != 2, "test32 case 2 failed\n");
2845 FAILED(buf[2] != 2, "test32 case 3 failed\n");
2846 FAILED(buf[3] != 1, "test32 case 4 failed\n");
2847 FAILED(buf[4] != 1, "test32 case 5 failed\n");
2848 FAILED(buf[5] != 2, "test32 case 6 failed\n");
2849 FAILED(buf[6] != 2, "test32 case 7 failed\n");
2850 FAILED(buf[7] != 1, "test32 case 8 failed\n");
2851 FAILED(buf[8] != 2, "test32 case 9 failed\n");
2852 FAILED(buf[9] != 1, "test32 case 10 failed\n");
2853 FAILED(buf[10] != 2, "test32 case 11 failed\n");
2854 FAILED(buf[11] != 1, "test32 case 12 failed\n");
2855 FAILED(buf[12] != 2, "test32 case 13 failed\n");
2856 FAILED(buf[13] != 1, "test32 case 14 failed\n");
2858 sljit_free_code(code.code);
2859 successful_tests++;
2862 static void test33(void)
2864 /* Test setting multiple flags. */
2865 executable_code code;
2866 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
2867 struct sljit_jump* jump;
2868 sljit_sw buf[10];
2870 if (verbose)
2871 printf("Run test33\n");
2873 buf[0] = 3;
2874 buf[1] = 3;
2875 buf[2] = 3;
2876 buf[3] = 3;
2877 buf[4] = 3;
2878 buf[5] = 3;
2879 buf[6] = 3;
2880 buf[7] = 3;
2881 buf[8] = 3;
2882 buf[9] = 3;
2884 FAILED(!compiler, "cannot create compiler\n");
2886 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 3, 0, 0, 0);
2888 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 20);
2889 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 10);
2890 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2891 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_ZERO);
2892 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -10);
2893 jump = sljit_emit_jump(compiler, SLJIT_LESS);
2894 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, 11);
2895 sljit_set_label(jump, sljit_emit_label(compiler));
2897 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_SIG_GREATER, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2898 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_SIG_GREATER);
2899 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_IMM, 45);
2900 jump = sljit_emit_jump(compiler, SLJIT_NOT_EQUAL);
2901 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_IMM, 55);
2902 sljit_set_label(jump, sljit_emit_label(compiler));
2904 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2905 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x8000000000000000));
2906 #else
2907 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x80000000));
2908 #endif
2909 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
2910 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2911 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_IMM, 33);
2912 jump = sljit_emit_jump(compiler, SLJIT_NOT_OVERFLOW);
2913 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_ZERO);
2914 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_IMM, 13);
2915 sljit_set_label(jump, sljit_emit_label(compiler));
2917 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x80000000));
2918 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_R0, 0);
2919 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2920 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 0);
2921 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_NOT_ZERO);
2922 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_IMM, 78);
2923 jump = sljit_emit_jump(compiler, SLJIT_OVERFLOW32);
2924 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_IMM, 48);
2925 sljit_set_label(jump, sljit_emit_label(compiler));
2927 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2928 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x8000000000000000));
2929 #else
2930 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x80000000));
2931 #endif
2932 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_R0, 0);
2933 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2934 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_IMM, 30);
2935 jump = sljit_emit_jump(compiler, SLJIT_NOT_OVERFLOW);
2936 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_IMM, 50);
2937 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_ZERO);
2938 sljit_set_label(jump, sljit_emit_label(compiler));
2940 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
2942 code.code = sljit_generate_code(compiler);
2943 CHECK(compiler);
2944 sljit_free_compiler(compiler);
2946 code.func1((sljit_sw)&buf);
2948 FAILED(buf[0] != 0, "test33 case 1 failed\n");
2949 FAILED(buf[1] != 11, "test33 case 2 failed\n");
2950 FAILED(buf[2] != 1, "test33 case 3 failed\n");
2951 FAILED(buf[3] != 45, "test33 case 4 failed\n");
2952 FAILED(buf[4] != 13, "test33 case 5 failed\n");
2953 FAILED(buf[5] != 0, "test33 case 6 failed\n");
2954 FAILED(buf[6] != 0, "test33 case 7 failed\n");
2955 FAILED(buf[7] != 48, "test33 case 8 failed\n");
2956 FAILED(buf[8] != 50, "test33 case 9 failed\n");
2957 FAILED(buf[9] != 1, "test33 case 10 failed\n");
2959 sljit_free_code(code.code);
2960 successful_tests++;
2963 static void test34(void)
2965 /* Test fast calls. */
2966 executable_code codeA;
2967 executable_code codeB;
2968 executable_code codeC;
2969 executable_code codeD;
2970 executable_code codeE;
2971 executable_code codeF;
2972 struct sljit_compiler* compiler;
2973 struct sljit_jump *jump;
2974 struct sljit_label* label;
2975 sljit_uw addr;
2976 sljit_p buf[2];
2978 if (verbose)
2979 printf("Run test34\n");
2981 buf[0] = 0;
2982 buf[1] = 0;
2984 /* A */
2985 compiler = sljit_create_compiler(NULL);
2986 FAILED(!compiler, "cannot create compiler\n");
2987 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
2989 sljit_emit_fast_enter(compiler, SLJIT_R1, 0);
2990 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 4);
2991 sljit_emit_fast_return(compiler, SLJIT_R1, 0);
2993 codeA.code = sljit_generate_code(compiler);
2994 CHECK(compiler);
2995 sljit_free_compiler(compiler);
2997 /* B */
2998 compiler = sljit_create_compiler(NULL);
2999 FAILED(!compiler, "cannot create compiler\n");
3000 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3002 sljit_emit_fast_enter(compiler, SLJIT_R4, 0);
3003 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 6);
3004 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(codeA.code));
3005 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_R1, 0);
3006 sljit_emit_fast_return(compiler, SLJIT_R4, 0);
3008 codeB.code = sljit_generate_code(compiler);
3009 CHECK(compiler);
3010 sljit_free_compiler(compiler);
3012 /* C */
3013 compiler = sljit_create_compiler(NULL);
3014 FAILED(!compiler, "cannot create compiler\n");
3015 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3017 sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_p));
3018 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 8);
3019 jump = sljit_emit_jump(compiler, SLJIT_FAST_CALL | SLJIT_REWRITABLE_JUMP);
3020 sljit_set_target(jump, SLJIT_FUNC_OFFSET(codeB.code));
3021 sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_p));
3023 codeC.code = sljit_generate_code(compiler);
3024 CHECK(compiler);
3025 sljit_free_compiler(compiler);
3027 /* D */
3028 compiler = sljit_create_compiler(NULL);
3029 FAILED(!compiler, "cannot create compiler\n");
3030 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3032 sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_SP), 0);
3033 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 10);
3034 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_OFFSET(codeC.code));
3035 sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_SP), 0);
3037 codeD.code = sljit_generate_code(compiler);
3038 CHECK(compiler);
3039 sljit_free_compiler(compiler);
3041 /* E */
3042 compiler = sljit_create_compiler(NULL);
3043 FAILED(!compiler, "cannot create compiler\n");
3044 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3046 sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_S0), 0);
3047 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 12);
3048 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_p), SLJIT_IMM, SLJIT_FUNC_OFFSET(codeD.code));
3049 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_p));
3050 sljit_emit_fast_return(compiler, SLJIT_MEM1(SLJIT_S0), 0);
3052 codeE.code = sljit_generate_code(compiler);
3053 CHECK(compiler);
3054 sljit_free_compiler(compiler);
3056 /* F */
3057 compiler = sljit_create_compiler(NULL);
3058 FAILED(!compiler, "cannot create compiler\n");
3060 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 5, 5, 0, 0, 2 * sizeof(sljit_p));
3061 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
3062 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_OFFSET(codeE.code));
3063 label = sljit_emit_label(compiler);
3064 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
3066 codeF.code = sljit_generate_code(compiler);
3067 CHECK(compiler);
3068 addr = sljit_get_label_addr(label);
3069 sljit_free_compiler(compiler);
3071 FAILED(codeF.func1((sljit_sw)&buf) != 40, "test34 case 1 failed\n");
3072 FAILED(buf[0] != addr - SLJIT_RETURN_ADDRESS_OFFSET, "test34 case 2 failed\n");
3074 sljit_free_code(codeA.code);
3075 sljit_free_code(codeB.code);
3076 sljit_free_code(codeC.code);
3077 sljit_free_code(codeD.code);
3078 sljit_free_code(codeE.code);
3079 sljit_free_code(codeF.code);
3080 successful_tests++;
3083 static void test35(void)
3085 /* More complicated tests for fast calls. */
3086 executable_code codeA;
3087 executable_code codeB;
3088 executable_code codeC;
3089 struct sljit_compiler* compiler;
3090 struct sljit_jump *jump = NULL;
3091 struct sljit_label* label;
3092 sljit_sw executable_offset;
3093 sljit_uw return_addr;
3094 sljit_uw jump_addr = 0;
3095 sljit_p buf[1];
3097 if (verbose)
3098 printf("Run test35\n");
3100 buf[0] = 0;
3102 /* A */
3103 compiler = sljit_create_compiler(NULL);
3104 FAILED(!compiler, "cannot create compiler\n");
3105 sljit_set_context(compiler, 0, 0, 2, 2, 0, 0, 0);
3107 sljit_emit_fast_enter(compiler, SLJIT_MEM0(), (sljit_sw)&buf[0]);
3108 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 5);
3110 jump = sljit_emit_jump(compiler, SLJIT_FAST_CALL | SLJIT_REWRITABLE_JUMP);
3111 sljit_set_target(jump, 0);
3113 label = sljit_emit_label(compiler);
3114 sljit_emit_fast_return(compiler, SLJIT_MEM0(), (sljit_sw)&buf[0]);
3116 codeA.code = sljit_generate_code(compiler);
3117 CHECK(compiler);
3118 executable_offset = sljit_get_executable_offset(compiler);
3119 jump_addr = sljit_get_jump_addr(jump);
3120 sljit_free_compiler(compiler);
3122 /* B */
3123 compiler = sljit_create_compiler(NULL);
3124 FAILED(!compiler, "cannot create compiler\n");
3125 sljit_set_context(compiler, 0, 0, 2, 2, 0, 0, 0);
3127 sljit_emit_fast_enter(compiler, SLJIT_R1, 0);
3128 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 7);
3129 sljit_emit_fast_return(compiler, SLJIT_R1, 0);
3131 codeB.code = sljit_generate_code(compiler);
3132 CHECK(compiler);
3133 sljit_free_compiler(compiler);
3135 sljit_set_jump_addr(jump_addr, SLJIT_FUNC_OFFSET(codeB.code), executable_offset);
3137 /* C */
3138 compiler = sljit_create_compiler(NULL);
3139 FAILED(!compiler, "cannot create compiler\n");
3141 sljit_emit_enter(compiler, 0, 0, 2, 2, 0, 0, 0);
3142 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
3143 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_OFFSET(codeA.code));
3144 label = sljit_emit_label(compiler);
3145 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
3147 codeC.code = sljit_generate_code(compiler);
3148 CHECK(compiler);
3149 return_addr = sljit_get_label_addr(label);
3150 sljit_free_compiler(compiler);
3152 FAILED(codeC.func0() != 12, "test35 case 1 failed\n");
3153 FAILED(buf[0] != return_addr - SLJIT_RETURN_ADDRESS_OFFSET, "test35 case 2 failed\n");
3155 sljit_free_code(codeA.code);
3156 sljit_free_code(codeB.code);
3157 sljit_free_code(codeC.code);
3158 successful_tests++;
3161 static void cmp_test(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src1, sljit_sw src1w, sljit_s32 src2, sljit_sw src2w)
3163 /* 2 = true, 1 = false */
3164 struct sljit_jump* jump;
3165 struct sljit_label* label;
3167 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_IMM, 2);
3168 jump = sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w);
3169 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_IMM, 1);
3170 label = sljit_emit_label(compiler);
3171 sljit_set_label(jump, label);
3172 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
3175 #define TEST_CASES (7 + 10 + 12 + 11 + 4)
3176 static void test36(void)
3178 /* Compare instruction. */
3179 executable_code code;
3180 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
3182 sljit_s8 buf[TEST_CASES];
3183 sljit_s8 compare_buf[TEST_CASES] = {
3184 1, 1, 2, 2, 1, 2, 2,
3185 1, 1, 2, 2, 2, 1, 2, 2, 1, 1,
3186 2, 2, 2, 1, 2, 2, 2, 2, 1, 1, 2, 2,
3187 2, 1, 2, 1, 1, 1, 2, 1, 2, 1, 2,
3188 2, 1, 1, 2
3190 sljit_sw data[4];
3191 sljit_s32 i;
3193 if (verbose)
3194 printf("Run test36\n");
3196 FAILED(!compiler, "cannot create compiler\n");
3197 for (i = 0; i < TEST_CASES; ++i)
3198 buf[i] = 100;
3199 data[0] = 32;
3200 data[1] = -9;
3201 data[2] = 43;
3202 data[3] = -13;
3204 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 3, 2, 0, 0, 0);
3205 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
3207 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 13);
3208 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 15);
3209 cmp_test(compiler, SLJIT_EQUAL, SLJIT_IMM, 9, SLJIT_R0, 0);
3210 cmp_test(compiler, SLJIT_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3211 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 3);
3212 cmp_test(compiler, SLJIT_EQUAL, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_IMM, -13);
3213 cmp_test(compiler, SLJIT_NOT_EQUAL, SLJIT_IMM, 0, SLJIT_R0, 0);
3214 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
3215 cmp_test(compiler, SLJIT_NOT_EQUAL | SLJIT_REWRITABLE_JUMP, SLJIT_IMM, 0, SLJIT_R0, 0);
3216 cmp_test(compiler, SLJIT_EQUAL, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT);
3217 cmp_test(compiler, SLJIT_EQUAL | SLJIT_REWRITABLE_JUMP, SLJIT_R0, 0, SLJIT_IMM, 0);
3219 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, 0);
3220 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -8);
3221 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
3222 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_R0, 0, SLJIT_IMM, 0);
3223 cmp_test(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 0);
3224 cmp_test(compiler, SLJIT_SIG_LESS | SLJIT_REWRITABLE_JUMP, SLJIT_R0, 0, SLJIT_IMM, 0);
3225 cmp_test(compiler, SLJIT_SIG_GREATER_EQUAL, SLJIT_R1, 0, SLJIT_IMM, 0);
3226 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_sw));
3227 cmp_test(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_IMM, 0, SLJIT_R1, 0);
3228 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_sw));
3229 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw));
3230 cmp_test(compiler, SLJIT_SIG_LESS | SLJIT_REWRITABLE_JUMP, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw));
3232 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
3233 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
3234 cmp_test(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_sw));
3235 cmp_test(compiler, SLJIT_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 8);
3236 cmp_test(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_IMM, -10);
3237 cmp_test(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_IMM, 8);
3238 cmp_test(compiler, SLJIT_GREATER_EQUAL, SLJIT_IMM, 8, SLJIT_R1, 0);
3239 cmp_test(compiler, SLJIT_GREATER_EQUAL | SLJIT_REWRITABLE_JUMP, SLJIT_IMM, 8, SLJIT_R1, 0);
3240 cmp_test(compiler, SLJIT_GREATER, SLJIT_IMM, 8, SLJIT_R1, 0);
3241 cmp_test(compiler, SLJIT_LESS_EQUAL, SLJIT_IMM, 7, SLJIT_R0, 0);
3242 cmp_test(compiler, SLJIT_GREATER, SLJIT_IMM, 1, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw));
3243 cmp_test(compiler, SLJIT_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3244 cmp_test(compiler, SLJIT_GREATER, SLJIT_R0, 0, SLJIT_R1, 0);
3245 cmp_test(compiler, SLJIT_GREATER | SLJIT_REWRITABLE_JUMP, SLJIT_R0, 0, SLJIT_R1, 0);
3247 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -3);
3248 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
3249 cmp_test(compiler, SLJIT_SIG_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3250 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_R0, 0, SLJIT_IMM, -1);
3251 cmp_test(compiler, SLJIT_SIG_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 1);
3252 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, -1);
3253 cmp_test(compiler, SLJIT_SIG_LESS | SLJIT_REWRITABLE_JUMP, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, -1);
3254 cmp_test(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3255 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_R0, 0, SLJIT_R1, 0);
3256 cmp_test(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_IMM, -4, SLJIT_R0, 0);
3257 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_IMM, -1, SLJIT_R1, 0);
3258 cmp_test(compiler, SLJIT_SIG_GREATER | SLJIT_REWRITABLE_JUMP, SLJIT_R1, 0, SLJIT_IMM, -1);
3260 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3261 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xf00000004));
3262 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_R0, 0);
3263 cmp_test(compiler, SLJIT_LESS32, SLJIT_R1, 0, SLJIT_IMM, 5);
3264 cmp_test(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_IMM, 5);
3265 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xff0000004));
3266 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_R0, 0);
3267 cmp_test(compiler, SLJIT_SIG_GREATER32, SLJIT_R1, 0, SLJIT_IMM, 5);
3268 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_R0, 0, SLJIT_IMM, 5);
3269 #else
3270 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 4);
3271 cmp_test(compiler, SLJIT_LESS32, SLJIT_R0, 0, SLJIT_IMM, 5);
3272 cmp_test(compiler, SLJIT_GREATER32, SLJIT_R0, 0, SLJIT_IMM, 5);
3273 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0xf0000004);
3274 cmp_test(compiler, SLJIT_SIG_GREATER32, SLJIT_R0, 0, SLJIT_IMM, 5);
3275 cmp_test(compiler, SLJIT_SIG_LESS32, SLJIT_R0, 0, SLJIT_IMM, 5);
3276 #endif
3278 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
3280 code.code = sljit_generate_code(compiler);
3281 CHECK(compiler);
3282 sljit_free_compiler(compiler);
3284 code.func2((sljit_sw)&buf, (sljit_sw)&data);
3286 for (i = 0; i < TEST_CASES; ++i)
3287 if (SLJIT_UNLIKELY(buf[i] != compare_buf[i])) {
3288 printf("test36 case %d failed\n", i + 1);
3289 return;
3292 sljit_free_code(code.code);
3293 successful_tests++;
3295 #undef TEST_CASES
3297 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3298 #define BITN(n) (SLJIT_W(1) << (63 - (n)))
3299 #define RESN(n) (n)
3300 #else
3301 #define BITN(n) (1 << (31 - ((n) & 0x1f)))
3302 #define RESN(n) ((n) & 0x1f)
3303 #endif
3305 static void test37(void)
3307 /* Test count leading zeroes. */
3308 executable_code code;
3309 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
3310 sljit_sw buf[9];
3311 sljit_s32 ibuf[2];
3312 sljit_s32 i;
3314 if (verbose)
3315 printf("Run test37\n");
3317 FAILED(!compiler, "cannot create compiler\n");
3319 for (i = 0; i < 9; i++)
3320 buf[i] = -1;
3321 buf[2] = 0;
3322 buf[4] = BITN(13);
3323 ibuf[0] = -1;
3324 ibuf[1] = -1;
3325 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 1, 3, 0, 0, 0);
3326 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, BITN(27));
3327 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
3328 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, BITN(47));
3329 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_R0, 0, SLJIT_S2, 0);
3330 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
3331 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw));
3332 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
3333 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_R0, 0, SLJIT_R0, 0);
3334 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_R0, 0);
3335 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0);
3336 sljit_emit_op1(compiler, SLJIT_CLZ32, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_R0, 0);
3337 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
3338 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_UNUSED, 0, SLJIT_R0, 0);
3339 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw));
3340 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
3341 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, BITN(58));
3342 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R0, 0);
3343 sljit_emit_op1(compiler, SLJIT_CLZ32, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_S1), 0 * sizeof(sljit_sw));
3344 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
3345 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_R0, 0);
3346 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3347 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xff08a00000));
3348 #else
3349 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x08a00000);
3350 #endif
3351 sljit_emit_op1(compiler, SLJIT_CLZ32, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32), SLJIT_R0, 0);
3352 sljit_emit_op1(compiler, SLJIT_CLZ32, SLJIT_R0, 0, SLJIT_R0, 0);
3353 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R0, 0);
3354 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3355 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xffc8a00000));
3356 #else
3357 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0xc8a00000);
3358 #endif
3359 sljit_emit_op1(compiler, SLJIT_CLZ32, SLJIT_R0, 0, SLJIT_R0, 0);
3360 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R0, 0);
3362 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
3364 code.code = sljit_generate_code(compiler);
3365 CHECK(compiler);
3366 sljit_free_compiler(compiler);
3368 code.func2((sljit_sw)&buf, (sljit_sw)&ibuf);
3369 FAILED(buf[0] != RESN(27), "test37 case 1 failed\n");
3370 FAILED(buf[1] != RESN(47), "test37 case 2 failed\n");
3371 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3372 FAILED(buf[2] != 64, "test37 case 3 failed\n");
3373 #else
3374 FAILED(buf[2] != 32, "test37 case 3 failed\n");
3375 #endif
3376 FAILED(buf[3] != 0, "test37 case 4 failed\n");
3377 FAILED(ibuf[0] != 32, "test37 case 5 failed\n");
3378 FAILED(buf[4] != RESN(13), "test37 case 6 failed\n");
3379 FAILED(buf[5] != RESN(58), "test37 case 7 failed\n");
3380 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3381 FAILED(buf[6] != 64, "test37 case 8 failed\n");
3382 #else
3383 FAILED(buf[6] != 32, "test37 case 8 failed\n");
3384 #endif
3385 FAILED(ibuf[1] != 4, "test37 case 9 failed\n");
3387 FAILED((buf[7] & 0xffffffff) != 4, "test37 case 10 failed\n");
3388 FAILED((buf[8] & 0xffffffff) != 0, "test37 case 11 failed\n");
3390 sljit_free_code(code.code);
3391 successful_tests++;
3393 #undef BITN
3394 #undef RESN
3396 static void test38(void)
3398 #if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK)
3399 /* Test stack utility. */
3400 executable_code code;
3401 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
3402 struct sljit_jump* alloc1_fail;
3403 struct sljit_jump* alloc2_fail;
3404 struct sljit_jump* alloc3_fail;
3405 struct sljit_jump* sanity1_fail;
3406 struct sljit_jump* sanity2_fail;
3407 struct sljit_jump* sanity3_fail;
3408 struct sljit_jump* sanity4_fail;
3409 struct sljit_jump* jump;
3410 struct sljit_label* label;
3412 if (verbose)
3413 printf("Run test38\n");
3415 FAILED(!compiler, "cannot create compiler\n");
3417 sljit_emit_enter(compiler, 0, 0, 3, 1, 0, 0, 0);
3419 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8192);
3420 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 65536);
3421 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 0);
3422 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));
3423 alloc1_fail = sljit_emit_cmp(compiler, SLJIT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
3424 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_RETURN_REG, 0);
3426 /* Write 8k data. */
3427 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, start));
3428 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 8192);
3429 label = sljit_emit_label(compiler);
3430 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_IMM, -1);
3431 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw));
3432 jump = sljit_emit_cmp(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
3433 sljit_set_label(jump, label);
3435 /* Grow stack. */
3436 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
3437 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, end), SLJIT_IMM, 65536);
3438 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW), SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_stack_resize));
3439 alloc2_fail = sljit_emit_cmp(compiler, SLJIT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
3440 sanity1_fail = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, start));
3442 /* Write 64k data. */
3443 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, start));
3444 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 65536);
3445 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, min_start));
3446 sanity2_fail = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_R0, 0, SLJIT_R2, 0);
3447 label = sljit_emit_label(compiler);
3448 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_IMM, -1);
3449 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw));
3450 jump = sljit_emit_cmp(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
3451 sljit_set_label(jump, label);
3453 /* Shrink stack. */
3454 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
3455 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, end), SLJIT_IMM, 32768);
3456 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW), SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_stack_resize));
3457 alloc3_fail = sljit_emit_cmp(compiler, SLJIT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
3458 sanity3_fail = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, start));
3460 /* Write 32k data. */
3461 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, start));
3462 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, end));
3463 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R2, 0, SLJIT_R1, 0, SLJIT_IMM, 32768);
3464 sanity4_fail = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_R0, 0, SLJIT_R2, 0);
3465 label = sljit_emit_label(compiler);
3466 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_IMM, -1);
3467 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw));
3468 jump = sljit_emit_cmp(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
3469 sljit_set_label(jump, label);
3471 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
3472 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
3473 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW), SLJIT_IMM, SLJIT_FUNC_OFFSET(sljit_free_stack));
3475 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, 4567);
3477 label = sljit_emit_label(compiler);
3478 sljit_set_label(alloc1_fail, label);
3479 sljit_set_label(alloc2_fail, label);
3480 sljit_set_label(alloc3_fail, label);
3481 sljit_set_label(sanity1_fail, label);
3482 sljit_set_label(sanity2_fail, label);
3483 sljit_set_label(sanity3_fail, label);
3484 sljit_set_label(sanity4_fail, label);
3485 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, 0);
3487 code.code = sljit_generate_code(compiler);
3488 CHECK(compiler);
3489 sljit_free_compiler(compiler);
3491 /* Just survive this. */
3492 FAILED(code.func0() != 4567, "test38 case 1 failed\n");
3494 sljit_free_code(code.code);
3495 #endif
3496 successful_tests++;
3499 static void test39(void)
3501 /* Test error handling. */
3502 executable_code code;
3503 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
3504 struct sljit_jump* jump;
3506 if (verbose)
3507 printf("Run test39\n");
3509 FAILED(!compiler, "cannot create compiler\n");
3511 /* Such assignment should never happen in a regular program. */
3512 compiler->error = -3967;
3514 SLJIT_ASSERT(sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 5, 5, 6, 0, 32) == -3967);
3515 SLJIT_ASSERT(sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R1, 0) == -3967);
3516 SLJIT_ASSERT(sljit_emit_op0(compiler, SLJIT_NOP) == -3967);
3517 SLJIT_ASSERT(sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), 1) == -3967);
3518 SLJIT_ASSERT(sljit_emit_op2(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R0), 64, SLJIT_MEM1(SLJIT_S0), -64) == -3967);
3519 SLJIT_ASSERT(sljit_emit_fop1(compiler, SLJIT_ABS_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_R1), 0) == -3967);
3520 SLJIT_ASSERT(sljit_emit_fop2(compiler, SLJIT_DIV_F64, SLJIT_FR2, 0, SLJIT_MEM2(SLJIT_R0, SLJIT_S0), 0, SLJIT_FR2, 0) == -3967);
3521 SLJIT_ASSERT(!sljit_emit_label(compiler));
3522 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW));
3523 SLJIT_ASSERT(!jump);
3524 sljit_set_label(jump, (struct sljit_label*)0x123450);
3525 sljit_set_target(jump, 0x123450);
3526 jump = sljit_emit_cmp(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3527 SLJIT_ASSERT(!jump);
3528 SLJIT_ASSERT(sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_MEM1(SLJIT_R0), 8) == -3967);
3529 SLJIT_ASSERT(sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MUL_OVERFLOW) == -3967);
3530 SLJIT_ASSERT(!sljit_emit_const(compiler, SLJIT_R0, 0, 99));
3532 SLJIT_ASSERT(!compiler->labels && !compiler->jumps && !compiler->consts);
3533 SLJIT_ASSERT(!compiler->last_label && !compiler->last_jump && !compiler->last_const);
3534 SLJIT_ASSERT(!compiler->buf->next && !compiler->buf->used_size);
3535 SLJIT_ASSERT(!compiler->abuf->next && !compiler->abuf->used_size);
3537 sljit_set_compiler_memory_error(compiler);
3538 FAILED(sljit_get_compiler_error(compiler) != -3967, "test39 case 1 failed\n");
3540 code.code = sljit_generate_code(compiler);
3541 FAILED(sljit_get_compiler_error(compiler) != -3967, "test39 case 2 failed\n");
3542 FAILED(!!code.code, "test39 case 3 failed\n");
3543 sljit_free_compiler(compiler);
3545 compiler = sljit_create_compiler(NULL);
3546 FAILED(!compiler, "cannot create compiler\n");
3548 FAILED(sljit_get_compiler_error(compiler) != SLJIT_SUCCESS, "test39 case 4 failed\n");
3549 sljit_set_compiler_memory_error(compiler);
3550 FAILED(sljit_get_compiler_error(compiler) != SLJIT_ERR_ALLOC_FAILED, "test39 case 5 failed\n");
3551 sljit_free_compiler(compiler);
3553 successful_tests++;
3556 static void test40(void)
3558 /* Test emit_op_flags. */
3559 executable_code code;
3560 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
3561 sljit_sw buf[10];
3563 if (verbose)
3564 printf("Run test40\n");
3566 FAILED(!compiler, "cannot create compiler\n");
3567 buf[0] = -100;
3568 buf[1] = -100;
3569 buf[2] = -100;
3570 buf[3] = -8;
3571 buf[4] = -100;
3572 buf[5] = -100;
3573 buf[6] = 0;
3574 buf[7] = 0;
3575 buf[8] = -100;
3576 buf[9] = -100;
3578 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 4, 0, 0, sizeof(sljit_sw));
3580 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -5);
3581 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_UNUSED, 0, SLJIT_IMM, -6, SLJIT_R0, 0);
3582 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x123456);
3583 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_SIG_LESS);
3584 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R1, 0);
3586 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -13);
3587 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_IMM, -13, SLJIT_R0, 0);
3588 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, 0);
3589 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_EQUAL);
3590 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_NOT_EQUAL);
3591 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);
3592 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_IMM, -13, SLJIT_R0, 0);
3593 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
3594 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_EQUAL);
3595 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_EQUAL);
3597 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -13);
3598 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 3);
3599 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R1, 0);
3600 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_MEM2(SLJIT_S0, SLJIT_R1), SLJIT_WORD_SHIFT, SLJIT_SIG_LESS);
3602 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -8);
3603 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 33);
3604 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
3605 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, 0);
3606 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_R2, 0, SLJIT_GREATER);
3607 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_S1, 0, SLJIT_EQUAL);
3608 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_R1, 0);
3609 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, 0x88);
3610 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_S3, 0, SLJIT_NOT_EQUAL);
3611 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_S1, 0);
3612 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_S3, 0);
3614 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x84);
3615 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_IMM, 0x180, SLJIT_R0, 0);
3616 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_EQUAL);
3617 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_EQUAL);
3619 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
3620 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
3621 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_NOT_EQUAL);
3622 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_NOT_EQUAL);
3624 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x123456);
3625 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
3626 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_R0, 0, SLJIT_GREATER);
3627 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 9, SLJIT_R0, 0);
3629 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, 0xbaddead);
3630 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0);
3632 code.code = sljit_generate_code(compiler);
3633 CHECK(compiler);
3634 sljit_free_compiler(compiler);
3636 FAILED(code.func1((sljit_sw)&buf) != 0xbaddead, "test40 case 1 failed\n");
3637 FAILED(buf[0] != 0x123457, "test40 case 2 failed\n");
3638 FAILED(buf[1] != 1, "test40 case 3 failed\n");
3639 FAILED(buf[2] != 0, "test40 case 4 failed\n");
3640 FAILED(buf[3] != -7, "test40 case 5 failed\n");
3641 FAILED(buf[4] != 0, "test40 case 6 failed\n");
3642 FAILED(buf[5] != 0x89, "test40 case 7 failed\n");
3643 FAILED(buf[6] != 0, "test40 case 8 failed\n");
3644 FAILED(buf[7] != 1, "test40 case 9 failed\n");
3645 FAILED(buf[8] != 1, "test40 case 10 failed\n");
3646 FAILED(buf[9] != 0x123457, "test40 case 11 failed\n");
3648 sljit_free_code(code.code);
3649 successful_tests++;
3652 static void test41(void)
3654 /* Test inline assembly. */
3655 executable_code code;
3656 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
3657 sljit_s32 i;
3658 sljit_f64 buf[3];
3659 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3660 sljit_u8 inst[16];
3661 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3662 sljit_u8 inst[16];
3663 sljit_s32 reg;
3664 #else
3665 sljit_u32 inst;
3666 #endif
3668 if (verbose)
3669 printf("Run test41\n");
3671 #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3672 SLJIT_ASSERT(sljit_has_cpu_feature(SLJIT_HAS_VIRTUAL_REGISTERS) == 0);
3673 #endif
3675 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++) {
3676 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3677 if (SLJIT_R(i) >= SLJIT_R3 && SLJIT_R(i) <= SLJIT_R8) {
3678 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R(i)) == -1);
3679 continue;
3681 #endif
3682 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R(i)) >= 0 && sljit_get_register_index(SLJIT_R(i)) < 64);
3685 FAILED(!compiler, "cannot create compiler\n");
3686 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 3, 3, 0, 0, 0);
3688 /* Returns with the sum of SLJIT_S0 and SLJIT_S1. */
3689 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3690 /* lea SLJIT_RETURN_REG, [SLJIT_S0, SLJIT_S1] */
3691 inst[0] = 0x48;
3692 inst[1] = 0x8d;
3693 inst[2] = 0x04 | ((sljit_get_register_index(SLJIT_RETURN_REG) & 0x7) << 3);
3694 inst[3] = (sljit_get_register_index(SLJIT_S0) & 0x7)
3695 | ((sljit_get_register_index(SLJIT_S1) & 0x7) << 3);
3696 sljit_emit_op_custom(compiler, inst, 4);
3697 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3698 /* lea SLJIT_RETURN_REG, [SLJIT_S0, SLJIT_S1] */
3699 inst[0] = 0x48; /* REX_W */
3700 inst[1] = 0x8d;
3701 inst[2] = 0x04;
3702 reg = sljit_get_register_index(SLJIT_RETURN_REG);
3703 inst[2] |= ((reg & 0x7) << 3);
3704 if (reg > 7)
3705 inst[0] |= 0x04; /* REX_R */
3706 reg = sljit_get_register_index(SLJIT_S0);
3707 inst[3] = reg & 0x7;
3708 if (reg > 7)
3709 inst[0] |= 0x01; /* REX_B */
3710 reg = sljit_get_register_index(SLJIT_S1);
3711 inst[3] |= (reg & 0x7) << 3;
3712 if (reg > 7)
3713 inst[0] |= 0x02; /* REX_X */
3714 sljit_emit_op_custom(compiler, inst, 4);
3715 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
3716 /* add rd, rn, rm */
3717 inst = 0xe0800000 | (sljit_get_register_index(SLJIT_RETURN_REG) << 12)
3718 | (sljit_get_register_index(SLJIT_S0) << 16)
3719 | sljit_get_register_index(SLJIT_S1);
3720 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3721 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
3722 /* add rd, rn, rm */
3723 inst = 0xeb000000 | (sljit_get_register_index(SLJIT_RETURN_REG) << 8)
3724 | (sljit_get_register_index(SLJIT_S0) << 16)
3725 | sljit_get_register_index(SLJIT_S1);
3726 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3727 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
3728 /* add rd, rn, rm */
3729 inst = 0x8b000000 | sljit_get_register_index(SLJIT_RETURN_REG)
3730 | (sljit_get_register_index(SLJIT_S0) << 5)
3731 | (sljit_get_register_index(SLJIT_S1) << 16);
3732 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3733 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
3734 /* add rD, rA, rB */
3735 inst = (31 << 26) | (266 << 1) | (sljit_get_register_index(SLJIT_RETURN_REG) << 21)
3736 | (sljit_get_register_index(SLJIT_S0) << 16)
3737 | (sljit_get_register_index(SLJIT_S1) << 11);
3738 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3739 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
3740 /* addu rd, rs, rt */
3741 inst = 33 | (sljit_get_register_index(SLJIT_RETURN_REG) << 11)
3742 | (sljit_get_register_index(SLJIT_S0) << 21)
3743 | (sljit_get_register_index(SLJIT_S1) << 16);
3744 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3745 #elif (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
3746 /* daddu rd, rs, rt */
3747 inst = 45 | (sljit_get_register_index(SLJIT_RETURN_REG) << 11)
3748 | (sljit_get_register_index(SLJIT_S0) << 21)
3749 | (sljit_get_register_index(SLJIT_S1) << 16);
3750 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3751 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3752 /* add rd, rs1, rs2 */
3753 inst = (0x2 << 30) | (sljit_get_register_index(SLJIT_RETURN_REG) << 25)
3754 | (sljit_get_register_index(SLJIT_S0) << 14)
3755 | sljit_get_register_index(SLJIT_S1);
3756 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3757 #else
3758 inst = 0;
3759 sljit_emit_op_custom(compiler, &inst, 0);
3760 #endif
3762 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
3764 code.code = sljit_generate_code(compiler);
3765 CHECK(compiler);
3766 sljit_free_compiler(compiler);
3768 FAILED(code.func2(32, -11) != 21, "test41 case 1 failed\n");
3769 FAILED(code.func2(1000, 234) != 1234, "test41 case 2 failed\n");
3770 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3771 FAILED(code.func2(SLJIT_W(0x20f0a04090c06070), SLJIT_W(0x020f0a04090c0607)) != SLJIT_W(0x22ffaa4499cc6677), "test41 case 3 failed\n");
3772 #endif
3774 sljit_free_code(code.code);
3776 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
3777 buf[0] = 13.5;
3778 buf[1] = -2.25;
3779 buf[2] = 0.0;
3781 compiler = sljit_create_compiler(NULL);
3782 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 0, 1, 2, 0, 0);
3783 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 0);
3784 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
3785 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3786 /* addsd x, xm */
3787 inst[0] = 0xf2;
3788 inst[1] = 0x0f;
3789 inst[2] = 0x58;
3790 inst[3] = 0xc0 | (sljit_get_float_register_index(SLJIT_FR0) << 3)
3791 | sljit_get_float_register_index(SLJIT_FR1);
3792 sljit_emit_op_custom(compiler, inst, 4);
3793 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3794 /* addsd x, xm */
3795 if (sljit_get_float_register_index(SLJIT_FR0) > 7 || sljit_get_float_register_index(SLJIT_FR1) > 7) {
3796 inst[0] = 0;
3797 if (sljit_get_float_register_index(SLJIT_FR0) > 7)
3798 inst[0] |= 0x04; /* REX_R */
3799 if (sljit_get_float_register_index(SLJIT_FR1) > 7)
3800 inst[0] |= 0x01; /* REX_B */
3801 inst[1] = 0xf2;
3802 inst[2] = 0x0f;
3803 inst[3] = 0x58;
3804 inst[4] = 0xc0 | ((sljit_get_float_register_index(SLJIT_FR0) & 0x7) << 3)
3805 | (sljit_get_float_register_index(SLJIT_FR1) & 0x7);
3806 sljit_emit_op_custom(compiler, inst, 5);
3808 else {
3809 inst[0] = 0xf2;
3810 inst[1] = 0x0f;
3811 inst[2] = 0x58;
3812 inst[3] = 0xc0 | (sljit_get_float_register_index(SLJIT_FR0) << 3)
3813 | sljit_get_float_register_index(SLJIT_FR1);
3814 sljit_emit_op_custom(compiler, inst, 4);
3816 #elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32)
3817 /* vadd.f64 dd, dn, dm */
3818 inst = 0xee300b00 | ((sljit_get_float_register_index(SLJIT_FR0) >> 1) << 12)
3819 | ((sljit_get_float_register_index(SLJIT_FR0) >> 1) << 16)
3820 | (sljit_get_float_register_index(SLJIT_FR1) >> 1);
3821 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3822 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
3823 /* fadd rd, rn, rm */
3824 inst = 0x1e602800 | sljit_get_float_register_index(SLJIT_FR0)
3825 | (sljit_get_float_register_index(SLJIT_FR0) << 5)
3826 | (sljit_get_float_register_index(SLJIT_FR1) << 16);
3827 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3828 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
3829 /* fadd frD, frA, frB */
3830 inst = (63 << 26) | (21 << 1) | (sljit_get_float_register_index(SLJIT_FR0) << 21)
3831 | (sljit_get_float_register_index(SLJIT_FR0) << 16)
3832 | (sljit_get_float_register_index(SLJIT_FR1) << 11);
3833 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3834 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
3835 /* add.d fd, fs, ft */
3836 inst = (17 << 26) | (17 << 21) | (sljit_get_float_register_index(SLJIT_FR0) << 6)
3837 | (sljit_get_float_register_index(SLJIT_FR0) << 11)
3838 | (sljit_get_float_register_index(SLJIT_FR1) << 16);
3839 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3840 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3841 /* faddd rd, rs1, rs2 */
3842 inst = (0x2 << 30) | (0x34 << 19) | (0x42 << 5)
3843 | (sljit_get_float_register_index(SLJIT_FR0) << 25)
3844 | (sljit_get_float_register_index(SLJIT_FR0) << 14)
3845 | sljit_get_float_register_index(SLJIT_FR1);
3846 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3847 #endif
3848 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64), SLJIT_FR0, 0);
3849 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
3851 code.code = sljit_generate_code(compiler);
3852 CHECK(compiler);
3853 sljit_free_compiler(compiler);
3855 code.func1((sljit_sw)&buf);
3856 FAILED(buf[2] != 11.25, "test41 case 3 failed\n");
3858 sljit_free_code(code.code);
3861 successful_tests++;
3864 static void test42(void)
3866 /* Test long multiply and division. */
3867 executable_code code;
3868 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
3869 sljit_s32 i;
3870 sljit_sw buf[7 + 4 + 8 + 8];
3872 if (verbose)
3873 printf("Run test42\n");
3875 FAILED(!compiler, "cannot create compiler\n");
3876 for (i = 0; i < 7 + 4 + 8 + 8; i++)
3877 buf[i] = -1;
3879 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 5, 5, 0, 0, 0);
3881 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -0x1fb308a);
3882 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0xf50c873);
3883 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_IMM, 0x8a0475b);
3884 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, 0x9dc849b);
3885 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, -0x7c69a35);
3886 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, 0x5a4d0c4);
3887 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S4, 0, SLJIT_IMM, 0x9a3b06d);
3889 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3890 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3891 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3892 sljit_emit_op0(compiler, SLJIT_LMUL_UW);
3893 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R0, 0);
3894 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R1, 0);
3896 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3897 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3898 sljit_emit_op0(compiler, SLJIT_LMUL_SW);
3899 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_R0, 0);
3900 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_R1, 0);
3902 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3903 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3904 sljit_emit_op0(compiler, SLJIT_DIVMOD_UW);
3905 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_R0, 0);
3906 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_R1, 0);
3908 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3909 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3910 sljit_emit_op0(compiler, SLJIT_DIVMOD_SW);
3911 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_R0, 0);
3912 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_sw), SLJIT_R1, 0);
3914 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x5cf783d3cf0a74b0));
3915 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3d5df42d03a28fc7));
3916 sljit_emit_op0(compiler, SLJIT_DIVMOD_U32);
3917 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
3918 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R1, 0, SLJIT_R1, 0);
3919 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 15 * sizeof(sljit_sw), SLJIT_R0, 0);
3920 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 16 * sizeof(sljit_sw), SLJIT_R1, 0);
3922 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x371df5197ba26a28));
3923 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x46c78a5cfd6a420c));
3924 sljit_emit_op0(compiler, SLJIT_DIVMOD_S32);
3925 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
3926 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R1, 0, SLJIT_R1, 0);
3927 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 17 * sizeof(sljit_sw), SLJIT_R0, 0);
3928 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_sw), SLJIT_R1, 0);
3930 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xc456f048c28a611b));
3931 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3d4af2c543));
3932 sljit_emit_op0(compiler, SLJIT_DIV_UW);
3933 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 19 * sizeof(sljit_sw), SLJIT_R0, 0);
3934 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 20 * sizeof(sljit_sw), SLJIT_R1, 0);
3936 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x720fa4b74c329b14));
3937 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0xa64ae42b7d6));
3938 sljit_emit_op0(compiler, SLJIT_DIV_SW);
3939 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 21 * sizeof(sljit_sw), SLJIT_R0, 0);
3940 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 22 * sizeof(sljit_sw), SLJIT_R1, 0);
3942 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x4af51c027b34));
3943 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x9ba4ff2906b14));
3944 sljit_emit_op0(compiler, SLJIT_DIV_U32);
3945 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
3946 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R1, 0, SLJIT_R1, 0);
3947 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 23 * sizeof(sljit_sw), SLJIT_R0, 0);
3948 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 24 * sizeof(sljit_sw), SLJIT_R1, 0);
3950 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xc40b58a3f20d));
3951 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(-0xa63c923));
3952 sljit_emit_op0(compiler, SLJIT_DIV_S32);
3953 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
3954 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R1, 0, SLJIT_R1, 0);
3955 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 25 * sizeof(sljit_sw), SLJIT_R0, 0);
3956 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 26 * sizeof(sljit_sw), SLJIT_R1, 0);
3958 #else
3959 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -0x58cd67f5);
3960 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x3cb088df);
3961 sljit_emit_op0(compiler, SLJIT_LMUL_UW);
3962 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R0, 0);
3963 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R1, 0);
3965 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -0x58cd67f5);
3966 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x3cb088df);
3967 sljit_emit_op0(compiler, SLJIT_LMUL_SW);
3968 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_R0, 0);
3969 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_R1, 0);
3971 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -0x58cd67f5);
3972 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x3cb088df);
3973 sljit_emit_op0(compiler, SLJIT_DIVMOD_UW);
3974 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_R0, 0);
3975 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_R1, 0);
3977 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -0x58cd67f5);
3978 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x3cb088df);
3979 sljit_emit_op0(compiler, SLJIT_DIVMOD_SW);
3980 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_R0, 0);
3981 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_sw), SLJIT_R1, 0);
3983 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0xcf0a74b0);
3984 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 0x03a28fc7);
3985 sljit_emit_op0(compiler, SLJIT_DIVMOD_U32);
3986 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 15 * sizeof(sljit_sw), SLJIT_R0, 0);
3987 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 16 * sizeof(sljit_sw), SLJIT_R1, 0);
3989 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x7ba26a28);
3990 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)0xfd6a420c);
3991 sljit_emit_op0(compiler, SLJIT_DIVMOD_S32);
3992 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 17 * sizeof(sljit_sw), SLJIT_R0, 0);
3993 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_sw), SLJIT_R1, 0);
3995 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x9d4b7036));
3996 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0xb86d0));
3997 sljit_emit_op0(compiler, SLJIT_DIV_UW);
3998 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 19 * sizeof(sljit_sw), SLJIT_R0, 0);
3999 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 20 * sizeof(sljit_sw), SLJIT_R1, 0);
4001 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x58b0692c));
4002 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0xd357));
4003 sljit_emit_op0(compiler, SLJIT_DIV_SW);
4004 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 21 * sizeof(sljit_sw), SLJIT_R0, 0);
4005 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 22 * sizeof(sljit_sw), SLJIT_R1, 0);
4007 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1c027b34));
4008 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0xf2906b14));
4009 sljit_emit_op0(compiler, SLJIT_DIV_U32);
4010 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
4011 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R1, 0, SLJIT_R1, 0);
4012 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 23 * sizeof(sljit_sw), SLJIT_R0, 0);
4013 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 24 * sizeof(sljit_sw), SLJIT_R1, 0);
4015 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x58a3f20d));
4016 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(-0xa63c923));
4017 sljit_emit_op0(compiler, SLJIT_DIV_S32);
4018 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
4019 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R1, 0, SLJIT_R1, 0);
4020 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 25 * sizeof(sljit_sw), SLJIT_R0, 0);
4021 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 26 * sizeof(sljit_sw), SLJIT_R1, 0);
4022 #endif
4024 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R2, 0);
4025 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R3, 0);
4026 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R4, 0);
4027 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_S1, 0);
4028 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_S2, 0);
4029 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_S3, 0);
4030 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_S4, 0);
4032 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
4034 code.code = sljit_generate_code(compiler);
4035 CHECK(compiler);
4036 sljit_free_compiler(compiler);
4038 code.func1((sljit_sw)&buf);
4040 FAILED(buf[0] != -0x1fb308a, "test42 case 1 failed\n");
4041 FAILED(buf[1] != 0xf50c873, "test42 case 2 failed\n");
4042 FAILED(buf[2] != 0x8a0475b, "test42 case 3 failed\n");
4043 FAILED(buf[3] != 0x9dc849b, "test42 case 4 failed\n");
4044 FAILED(buf[4] != -0x7c69a35, "test42 case 5 failed\n");
4045 FAILED(buf[5] != 0x5a4d0c4, "test42 case 6 failed\n");
4046 FAILED(buf[6] != 0x9a3b06d, "test42 case 7 failed\n");
4048 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4049 FAILED(buf[7] != SLJIT_W(-4388959407985636971), "test42 case 8 failed\n");
4050 FAILED(buf[8] != SLJIT_W(2901680654366567099), "test42 case 9 failed\n");
4051 FAILED(buf[9] != SLJIT_W(-4388959407985636971), "test42 case 10 failed\n");
4052 FAILED(buf[10] != SLJIT_W(-1677173957268872740), "test42 case 11 failed\n");
4053 FAILED(buf[11] != SLJIT_W(2), "test42 case 12 failed\n");
4054 FAILED(buf[12] != SLJIT_W(2532236178951865933), "test42 case 13 failed\n");
4055 FAILED(buf[13] != SLJIT_W(-1), "test42 case 14 failed\n");
4056 FAILED(buf[14] != SLJIT_W(-2177944059851366166), "test42 case 15 failed\n");
4057 #else
4058 FAILED(buf[7] != -1587000939, "test42 case 8 failed\n");
4059 FAILED(buf[8] != 665003983, "test42 case 9 failed\n");
4060 FAILED(buf[9] != -1587000939, "test42 case 10 failed\n");
4061 FAILED(buf[10] != -353198352, "test42 case 11 failed\n");
4062 FAILED(buf[11] != 2, "test42 case 12 failed\n");
4063 FAILED(buf[12] != 768706125, "test42 case 13 failed\n");
4064 FAILED(buf[13] != -1, "test42 case 14 failed\n");
4065 FAILED(buf[14] != -471654166, "test42 case 15 failed\n");
4066 #endif
4068 FAILED(buf[15] != SLJIT_W(56), "test42 case 16 failed\n");
4069 FAILED(buf[16] != SLJIT_W(58392872), "test42 case 17 failed\n");
4070 FAILED(buf[17] != SLJIT_W(-47), "test42 case 18 failed\n");
4071 FAILED(buf[18] != SLJIT_W(35949148), "test42 case 19 failed\n");
4073 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4074 FAILED(buf[19] != SLJIT_W(0x3340bfc), "test42 case 20 failed\n");
4075 FAILED(buf[20] != SLJIT_W(0x3d4af2c543), "test42 case 21 failed\n");
4076 FAILED(buf[21] != SLJIT_W(-0xaf978), "test42 case 22 failed\n");
4077 FAILED(buf[22] != SLJIT_W(0xa64ae42b7d6), "test42 case 23 failed\n");
4078 #else
4079 FAILED(buf[19] != SLJIT_W(0xda5), "test42 case 20 failed\n");
4080 FAILED(buf[20] != SLJIT_W(0xb86d0), "test42 case 21 failed\n");
4081 FAILED(buf[21] != SLJIT_W(-0x6b6e), "test42 case 22 failed\n");
4082 FAILED(buf[22] != SLJIT_W(0xd357), "test42 case 23 failed\n");
4083 #endif
4085 FAILED(buf[23] != SLJIT_W(0x0), "test42 case 24 failed\n");
4086 FAILED(buf[24] != SLJIT_W(0xf2906b14), "test42 case 25 failed\n");
4087 FAILED(buf[25] != SLJIT_W(-0x8), "test42 case 26 failed\n");
4088 FAILED(buf[26] != SLJIT_W(-0xa63c923), "test42 case 27 failed\n");
4090 sljit_free_code(code.code);
4091 successful_tests++;
4094 static void test43(void)
4096 /* Test floating point compare. */
4097 executable_code code;
4098 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4099 struct sljit_jump* jump;
4101 union {
4102 sljit_f64 value;
4103 struct {
4104 sljit_u32 value1;
4105 sljit_u32 value2;
4106 } u;
4107 } dbuf[4];
4109 if (verbose)
4110 printf("Run test43\n");
4112 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
4113 if (verbose)
4114 printf("no fpu available, test43 skipped\n");
4115 successful_tests++;
4116 if (compiler)
4117 sljit_free_compiler(compiler);
4118 return;
4121 FAILED(!compiler, "cannot create compiler\n");
4123 dbuf[0].value = 12.125;
4124 /* a NaN */
4125 dbuf[1].u.value1 = 0x7fffffff;
4126 dbuf[1].u.value2 = 0x7fffffff;
4127 dbuf[2].value = -13.5;
4128 dbuf[3].value = 12.125;
4130 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 1, 1, 3, 0, 0);
4131 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
4132 /* dbuf[0] < dbuf[2] -> -2 */
4133 jump = sljit_emit_fcmp(compiler, SLJIT_GREATER_EQUAL_F64, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_F64_SHIFT);
4134 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, -2);
4136 sljit_set_label(jump, sljit_emit_label(compiler));
4137 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 0);
4138 /* dbuf[0] and dbuf[1] is not NaN -> 5 */
4139 jump = sljit_emit_fcmp(compiler, SLJIT_UNORDERED_F64, SLJIT_MEM0(), (sljit_sw)&dbuf[1], SLJIT_FR1, 0);
4140 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, 5);
4142 sljit_set_label(jump, sljit_emit_label(compiler));
4143 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f64));
4144 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 11);
4145 /* dbuf[0] == dbuf[3] -> 11 */
4146 jump = sljit_emit_fcmp(compiler, SLJIT_EQUAL_F64, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_FR2, 0);
4148 /* else -> -17 */
4149 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, -17);
4150 sljit_set_label(jump, sljit_emit_label(compiler));
4151 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
4153 code.code = sljit_generate_code(compiler);
4154 CHECK(compiler);
4155 sljit_free_compiler(compiler);
4157 FAILED(code.func1((sljit_sw)&dbuf) != 11, "test43 case 1 failed\n");
4158 dbuf[3].value = 12;
4159 FAILED(code.func1((sljit_sw)&dbuf) != -17, "test43 case 2 failed\n");
4160 dbuf[1].value = 0;
4161 FAILED(code.func1((sljit_sw)&dbuf) != 5, "test43 case 3 failed\n");
4162 dbuf[2].value = 20;
4163 FAILED(code.func1((sljit_sw)&dbuf) != -2, "test43 case 4 failed\n");
4165 sljit_free_code(code.code);
4166 successful_tests++;
4169 static void test44(void)
4171 /* Test mov. */
4172 executable_code code;
4173 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4174 void *buf[5];
4176 if (verbose)
4177 printf("Run test44\n");
4179 FAILED(!compiler, "cannot create compiler\n");
4181 buf[0] = buf + 2;
4182 buf[1] = NULL;
4183 buf[2] = NULL;
4184 buf[3] = NULL;
4185 buf[4] = NULL;
4186 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 2, 0, 0, 0);
4188 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 0);
4189 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_p), SLJIT_R0, 0);
4190 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_p));
4191 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 2);
4192 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_MEM2(SLJIT_S0, SLJIT_R1), SLJIT_POINTER_SHIFT, SLJIT_R0, 0);
4193 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_p));
4194 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 3 << SLJIT_POINTER_SHIFT);
4195 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_S0, 0);
4196 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_MEM2(SLJIT_R2, SLJIT_R1), 0, SLJIT_R0, 0);
4197 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 2 * sizeof(sljit_p));
4198 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1 << SLJIT_POINTER_SHIFT);
4199 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_MEM2(SLJIT_R2, SLJIT_R1), 2, SLJIT_R0, 0);
4201 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
4203 code.code = sljit_generate_code(compiler);
4204 CHECK(compiler);
4205 sljit_free_compiler(compiler);
4207 FAILED(code.func1((sljit_sw)&buf) != (sljit_sw)(buf + 2), "test44 case 1 failed\n");
4208 FAILED(buf[1] != buf + 2, "test44 case 2 failed\n");
4209 FAILED(buf[2] != buf + 3, "test44 case 3 failed\n");
4210 FAILED(buf[3] != buf + 4, "test44 case 4 failed\n");
4211 FAILED(buf[4] != buf + 2, "test44 case 5 failed\n");
4213 sljit_free_code(code.code);
4214 successful_tests++;
4217 static void test45(void)
4219 /* Test single precision floating point. */
4221 executable_code code;
4222 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4223 sljit_f32 buf[12];
4224 sljit_sw buf2[6];
4225 struct sljit_jump* jump;
4227 if (verbose)
4228 printf("Run test45\n");
4230 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
4231 if (verbose)
4232 printf("no fpu available, test45 skipped\n");
4233 successful_tests++;
4234 if (compiler)
4235 sljit_free_compiler(compiler);
4236 return;
4239 FAILED(!compiler, "cannot create compiler\n");
4241 buf[0] = 5.5;
4242 buf[1] = -7.25;
4243 buf[2] = 0;
4244 buf[3] = 0;
4245 buf[4] = 0;
4246 buf[5] = 0;
4247 buf[6] = 0;
4248 buf[7] = 8.75;
4249 buf[8] = 0;
4250 buf[9] = 16.5;
4251 buf[10] = 0;
4252 buf[11] = 0;
4254 buf2[0] = -1;
4255 buf2[1] = -1;
4256 buf2[2] = -1;
4257 buf2[3] = -1;
4258 buf2[4] = -1;
4259 buf2[5] = -1;
4261 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 3, 2, 6, 0, 0);
4263 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 0);
4264 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4265 sljit_emit_fop1(compiler, SLJIT_NEG_F32, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f32), SLJIT_FR0, 0);
4266 sljit_emit_fop1(compiler, SLJIT_ABS_F32, SLJIT_FR1, 0, SLJIT_FR5, 0);
4267 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f32), SLJIT_FR1, 0);
4268 sljit_emit_fop1(compiler, SLJIT_ABS_F32, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f32), SLJIT_FR5, 0);
4269 sljit_emit_fop1(compiler, SLJIT_NEG_F32, SLJIT_FR4, 0, SLJIT_MEM1(SLJIT_S0), 0);
4270 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f32), SLJIT_FR4, 0);
4272 sljit_emit_fop2(compiler, SLJIT_ADD_F32, SLJIT_FR0, 0, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4273 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f32), SLJIT_FR0, 0);
4274 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);
4275 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 0);
4276 sljit_emit_fop2(compiler, SLJIT_MUL_F32, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_f32), SLJIT_FR0, 0, SLJIT_FR0, 0);
4277 sljit_emit_fop2(compiler, SLJIT_DIV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f32), SLJIT_FR0, 0);
4278 sljit_emit_fop1(compiler, SLJIT_ABS_F32, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f32), SLJIT_FR2, 0);
4279 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 0x3d0ac);
4280 sljit_emit_fop1(compiler, SLJIT_NEG_F32, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_R0), 0x3d0ac);
4281 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 0x3d0ac + sizeof(sljit_f32));
4282 sljit_emit_fop1(compiler, SLJIT_ABS_F32, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_R0), -0x3d0ac);
4284 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 0);
4285 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4286 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 0);
4287 cond_set(compiler, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_EQUAL_F32);
4288 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_LESS_F, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 0);
4289 cond_set(compiler, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_sw), SLJIT_LESS_F32);
4290 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
4291 cond_set(compiler, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_sw), SLJIT_EQUAL_F32);
4292 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_GREATER_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
4293 cond_set(compiler, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw), SLJIT_GREATER_EQUAL_F32);
4295 jump = sljit_emit_fcmp(compiler, SLJIT_LESS_EQUAL_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4296 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_sw), SLJIT_IMM, 7);
4297 sljit_set_label(jump, sljit_emit_label(compiler));
4299 jump = sljit_emit_fcmp(compiler, SLJIT_GREATER_F32, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_FR2, 0);
4300 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_sw), SLJIT_IMM, 6);
4301 sljit_set_label(jump, sljit_emit_label(compiler));
4303 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
4305 code.code = sljit_generate_code(compiler);
4306 CHECK(compiler);
4307 sljit_free_compiler(compiler);
4309 code.func2((sljit_sw)&buf, (sljit_sw)&buf2);
4310 FAILED(buf[2] != -5.5, "test45 case 1 failed\n");
4311 FAILED(buf[3] != 7.25, "test45 case 2 failed\n");
4312 FAILED(buf[4] != 7.25, "test45 case 3 failed\n");
4313 FAILED(buf[5] != -5.5, "test45 case 4 failed\n");
4314 FAILED(buf[6] != -1.75, "test45 case 5 failed\n");
4315 FAILED(buf[7] != 16.0, "test45 case 6 failed\n");
4316 FAILED(buf[8] != 30.25, "test45 case 7 failed\n");
4317 FAILED(buf[9] != 3, "test45 case 8 failed\n");
4318 FAILED(buf[10] != -5.5, "test45 case 9 failed\n");
4319 FAILED(buf[11] != 7.25, "test45 case 10 failed\n");
4320 FAILED(buf2[0] != 1, "test45 case 11 failed\n");
4321 FAILED(buf2[1] != 2, "test45 case 12 failed\n");
4322 FAILED(buf2[2] != 2, "test45 case 13 failed\n");
4323 FAILED(buf2[3] != 1, "test45 case 14 failed\n");
4324 FAILED(buf2[4] != 7, "test45 case 15 failed\n");
4325 FAILED(buf2[5] != -1, "test45 case 16 failed\n");
4327 sljit_free_code(code.code);
4328 successful_tests++;
4331 static void test46(void)
4333 /* Test sljit_emit_op_flags with 32 bit operations. */
4335 executable_code code;
4336 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4337 sljit_s32 buf[24];
4338 sljit_sw buf2[6];
4339 sljit_s32 i;
4341 if (verbose)
4342 printf("Run test46\n");
4344 for (i = 0; i < 24; ++i)
4345 buf[i] = -17;
4346 buf[16] = 0;
4347 for (i = 0; i < 6; ++i)
4348 buf2[i] = -13;
4349 buf2[4] = -124;
4351 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW), 3, 3, 0, 0, 0);
4353 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -7);
4354 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, 13);
4355 sljit_emit_op_flags(compiler, SLJIT_MOV32, SLJIT_MEM0(), (sljit_sw)&buf, SLJIT_LESS);
4356 sljit_emit_op_flags(compiler, SLJIT_AND32, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_s32), SLJIT_NOT_ZERO);
4358 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, -7);
4359 sljit_emit_op_flags(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_s32), SLJIT_EQUAL);
4360 sljit_emit_op_flags(compiler, SLJIT_AND32, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_s32), SLJIT_NOT_EQUAL);
4361 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x1235);
4362 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 0x1235);
4363 sljit_emit_op_flags(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_ZERO);
4364 sljit_emit_op_flags(compiler, SLJIT_AND32, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_s32), SLJIT_ZERO32);
4365 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_s32), SLJIT_R0, 0);
4367 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, -7);
4368 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 12);
4369 sljit_emit_op_flags(compiler, SLJIT_MOV32, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 2, SLJIT_EQUAL);
4370 sljit_emit_op_flags(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_EQUAL);
4371 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_s32), SLJIT_R0, 0);
4372 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 16);
4373 sljit_emit_op_flags(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 2, SLJIT_EQUAL);
4374 sljit_emit_op_flags(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_s32), SLJIT_NOT_EQUAL32);
4376 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, -7);
4377 sljit_emit_op_flags(compiler, SLJIT_XOR32 | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), 20 * sizeof(sljit_s32), SLJIT_ZERO);
4378 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 39);
4379 sljit_emit_op_flags(compiler, SLJIT_XOR32, SLJIT_R0, 0, SLJIT_NOT_ZERO);
4380 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S0), 22 * sizeof(sljit_s32), SLJIT_R0, 0);
4382 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, -7);
4383 sljit_emit_op_flags(compiler, SLJIT_AND, SLJIT_MEM0(), (sljit_sw)&buf2, SLJIT_GREATER);
4384 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, 5);
4385 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
4386 sljit_emit_op_flags(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_SIG_LESS);
4387 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
4388 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, 5);
4389 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_LESS);
4390 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_NOT_EQUAL);
4391 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, 5);
4392 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw), SLJIT_S2, 0);
4393 sljit_emit_op_flags(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_SIG_LESS);
4394 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_sw), SLJIT_ZERO);
4395 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_UNUSED, 0, SLJIT_R2, 0, SLJIT_IMM, 0);
4396 sljit_emit_op_flags(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_sw), SLJIT_GREATER);
4398 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
4400 code.code = sljit_generate_code(compiler);
4401 CHECK(compiler);
4402 sljit_free_compiler(compiler);
4404 code.func2((sljit_sw)&buf, (sljit_sw)&buf2);
4405 FAILED(buf[0] != 0, "test46 case 1 failed\n");
4406 FAILED(buf[1] != -17, "test46 case 2 failed\n");
4407 FAILED(buf[2] != 1, "test46 case 3 failed\n");
4408 FAILED(buf[3] != -17, "test46 case 4 failed\n");
4409 FAILED(buf[4] != 1, "test46 case 5 failed\n");
4410 FAILED(buf[5] != -17, "test46 case 6 failed\n");
4411 FAILED(buf[6] != 1, "test46 case 7 failed\n");
4412 FAILED(buf[7] != -17, "test46 case 8 failed\n");
4413 FAILED(buf[8] != 0, "test46 case 9 failed\n");
4414 FAILED(buf[9] != -17, "test46 case 10 failed\n");
4415 FAILED(buf[10] != 1, "test46 case 11 failed\n");
4416 FAILED(buf[11] != -17, "test46 case 12 failed\n");
4417 FAILED(buf[12] != 1, "test46 case 13 failed\n");
4418 FAILED(buf[13] != -17, "test46 case 14 failed\n");
4419 FAILED(buf[14] != 1, "test46 case 15 failed\n");
4420 FAILED(buf[15] != -17, "test46 case 16 failed\n");
4421 FAILED(buf[16] != 0, "test46 case 17 failed\n");
4422 FAILED(buf[17] != -17, "test46 case 18 failed\n");
4423 FAILED(buf[18] != 0, "test46 case 19 failed\n");
4424 FAILED(buf[19] != -17, "test46 case 20 failed\n");
4425 FAILED(buf[20] != -18, "test46 case 21 failed\n");
4426 FAILED(buf[21] != -17, "test46 case 22 failed\n");
4427 FAILED(buf[22] != 38, "test46 case 23 failed\n");
4428 FAILED(buf[23] != -17, "test46 case 24 failed\n");
4430 FAILED(buf2[0] != 0, "test46 case 25 failed\n");
4431 FAILED(buf2[1] != 1, "test46 case 26 failed\n");
4432 FAILED(buf2[2] != 0, "test46 case 27 failed\n");
4433 FAILED(buf2[3] != 1, "test46 case 28 failed\n");
4434 FAILED(buf2[4] != -123, "test46 case 29 failed\n");
4435 FAILED(buf2[5] != -14, "test46 case 30 failed\n");
4437 sljit_free_code(code.code);
4438 successful_tests++;
4441 static void test47(void)
4443 /* Test jump optimizations. */
4444 executable_code code;
4445 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4446 sljit_sw buf[3];
4448 if (verbose)
4449 printf("Run test47\n");
4451 FAILED(!compiler, "cannot create compiler\n");
4452 buf[0] = 0;
4453 buf[1] = 0;
4454 buf[2] = 0;
4456 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 0, 0, 0);
4457 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x3a5c6f);
4458 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 3);
4459 sljit_set_target(sljit_emit_jump(compiler, SLJIT_LESS), 0x11223344);
4460 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
4461 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xd37c10);
4462 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4463 sljit_set_target(sljit_emit_jump(compiler, SLJIT_LESS), SLJIT_W(0x112233445566));
4464 #endif
4465 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
4466 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x59b48e);
4467 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4468 sljit_set_target(sljit_emit_jump(compiler, SLJIT_LESS), SLJIT_W(0x1122334455667788));
4469 #endif
4470 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
4471 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
4473 code.code = sljit_generate_code(compiler);
4474 CHECK(compiler);
4475 sljit_free_compiler(compiler);
4477 code.func1((sljit_sw)&buf);
4478 FAILED(buf[0] != 0x3a5c6f, "test47 case 1 failed\n");
4479 FAILED(buf[1] != 0xd37c10, "test47 case 2 failed\n");
4480 FAILED(buf[2] != 0x59b48e, "test47 case 3 failed\n");
4482 sljit_free_code(code.code);
4483 successful_tests++;
4486 static void test48(void)
4488 /* Test floating point conversions. */
4489 executable_code code;
4490 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4491 int i;
4492 sljit_f64 dbuf[10];
4493 sljit_f32 sbuf[10];
4494 sljit_sw wbuf[10];
4495 sljit_s32 ibuf[10];
4497 if (verbose)
4498 printf("Run test48\n");
4500 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
4501 if (verbose)
4502 printf("no fpu available, test48 skipped\n");
4503 successful_tests++;
4504 if (compiler)
4505 sljit_free_compiler(compiler);
4506 return;
4509 FAILED(!compiler, "cannot create compiler\n");
4510 for (i = 0; i < 10; i++) {
4511 dbuf[i] = 0.0;
4512 sbuf[i] = 0.0;
4513 wbuf[i] = 0;
4514 ibuf[i] = 0;
4517 dbuf[0] = 123.5;
4518 dbuf[1] = -367;
4519 dbuf[2] = 917.75;
4521 sbuf[0] = 476.25;
4522 sbuf[1] = -1689.75;
4524 wbuf[0] = 2345;
4526 ibuf[0] = 312;
4527 ibuf[1] = -9324;
4529 sljit_emit_enter(compiler, 0, 0, 3, 3, 6, 0, 0);
4530 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, (sljit_sw)&dbuf);
4531 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, (sljit_sw)&sbuf);
4532 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, (sljit_sw)&wbuf);
4533 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, (sljit_sw)&ibuf);
4535 /* sbuf[2] */
4536 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_F64, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_S0), 0);
4537 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), 0);
4538 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 3);
4539 /* sbuf[3] */
4540 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_F64, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_F32_SHIFT, SLJIT_FR5, 0);
4541 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_F32, SLJIT_FR4, 0, SLJIT_MEM1(SLJIT_S1), 0);
4542 /* dbuf[3] */
4543 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f64), SLJIT_FR4, 0);
4544 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR3, 0, SLJIT_MEM1(SLJIT_S1), 0);
4545 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_F32, SLJIT_FR2, 0, SLJIT_FR3, 0);
4546 /* dbuf[4] */
4547 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f64), SLJIT_FR2, 0);
4548 /* sbuf[4] */
4549 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_f32), SLJIT_FR3, 0);
4551 /* wbuf[1] */
4552 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F64, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
4553 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
4554 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F64, SLJIT_R0, 0, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_F64_SHIFT);
4555 /* wbuf[2] */
4556 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
4557 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S1), 0);
4558 /* wbuf[3] */
4559 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F32, SLJIT_MEM1(SLJIT_S2), 3 * sizeof(sljit_sw), SLJIT_FR5, 0);
4560 sljit_emit_fop1(compiler, SLJIT_NEG_F32, SLJIT_FR0, 0, SLJIT_FR5, 0);
4561 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 4);
4562 /* wbuf[4] */
4563 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F32, SLJIT_MEM2(SLJIT_S2, SLJIT_R1), SLJIT_WORD_SHIFT, SLJIT_FR0, 0);
4564 sljit_emit_fop1(compiler, SLJIT_NEG_F64, SLJIT_FR4, 0, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64));
4565 /* ibuf[2] */
4566 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F64, SLJIT_MEM1(SLJIT_R2), 2 * sizeof(sljit_s32), SLJIT_FR4, 0);
4567 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f32));
4568 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F32, SLJIT_R0, 0, SLJIT_FR1, 0);
4569 /* ibuf[3] */
4570 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM1(SLJIT_R2), 3 * sizeof(sljit_s32), SLJIT_R0, 0);
4572 /* dbuf[5] */
4573 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_S2), 0);
4574 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_FR2, 0, SLJIT_IMM, -6213);
4575 /* dbuf[6] */
4576 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64), SLJIT_FR2, 0);
4577 /* dbuf[7] */
4578 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_S32, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_f64), SLJIT_MEM0(), (sljit_sw)&ibuf[0]);
4579 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R2), sizeof(sljit_s32));
4580 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_S32, SLJIT_FR1, 0, SLJIT_R0, 0);
4581 /* dbuf[8] */
4582 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_f64), SLJIT_FR1, 0);
4583 /* dbuf[9] */
4584 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_MEM0(), (sljit_sw)(dbuf + 9), SLJIT_IMM, -77);
4585 /* sbuf[5] */
4586 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_SW, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_f32), SLJIT_IMM, -123);
4587 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 7190);
4588 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_SW, SLJIT_FR3, 0, SLJIT_R0, 0);
4589 /* sbuf[6] */
4590 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 6 * sizeof(sljit_f32), SLJIT_FR3, 0);
4591 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 123);
4592 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_R2, 0, SLJIT_IMM, 123 * sizeof(sljit_s32));
4593 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_S32, SLJIT_FR1, 0, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 2);
4594 /* sbuf[7] */
4595 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 7 * sizeof(sljit_f32), SLJIT_FR1, 0);
4596 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
4597 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 3812);
4598 /* sbuf[8] */
4599 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_S32, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_F32_SHIFT, SLJIT_R1, 0);
4600 /* sbuf[9] */
4601 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_SW, SLJIT_MEM0(), (sljit_sw)(sbuf + 9), SLJIT_IMM, -79);
4603 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
4605 code.code = sljit_generate_code(compiler);
4606 CHECK(compiler);
4607 sljit_free_compiler(compiler);
4609 code.func0();
4610 FAILED(dbuf[3] != 476.25, "test48 case 1 failed\n");
4611 FAILED(dbuf[4] != 476.25, "test48 case 2 failed\n");
4612 FAILED(dbuf[5] != 2345.0, "test48 case 3 failed\n");
4613 FAILED(dbuf[6] != -6213.0, "test48 case 4 failed\n");
4614 FAILED(dbuf[7] != 312.0, "test48 case 5 failed\n");
4615 FAILED(dbuf[8] != -9324.0, "test48 case 6 failed\n");
4616 FAILED(dbuf[9] != -77.0, "test48 case 7 failed\n");
4618 FAILED(sbuf[2] != 123.5, "test48 case 8 failed\n");
4619 FAILED(sbuf[3] != 123.5, "test48 case 9 failed\n");
4620 FAILED(sbuf[4] != 476.25, "test48 case 10 failed\n");
4621 FAILED(sbuf[5] != -123, "test48 case 11 failed\n");
4622 FAILED(sbuf[6] != 7190, "test48 case 12 failed\n");
4623 FAILED(sbuf[7] != 312, "test48 case 13 failed\n");
4624 FAILED(sbuf[8] != 3812, "test48 case 14 failed\n");
4625 FAILED(sbuf[9] != -79.0, "test48 case 15 failed\n");
4627 FAILED(wbuf[1] != -367, "test48 case 16 failed\n");
4628 FAILED(wbuf[2] != 917, "test48 case 17 failed\n");
4629 FAILED(wbuf[3] != 476, "test48 case 18 failed\n");
4630 FAILED(wbuf[4] != -476, "test48 case 19 failed\n");
4632 FAILED(ibuf[2] != -917, "test48 case 20 failed\n");
4633 FAILED(ibuf[3] != -1689, "test48 case 21 failed\n");
4635 sljit_free_code(code.code);
4636 successful_tests++;
4639 static void test49(void)
4641 /* Test floating point conversions. */
4642 executable_code code;
4643 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4644 int i;
4645 sljit_f64 dbuf[10];
4646 sljit_f32 sbuf[9];
4647 sljit_sw wbuf[9];
4648 sljit_s32 ibuf[9];
4649 sljit_s32* dbuf_ptr = (sljit_s32*)dbuf;
4650 sljit_s32* sbuf_ptr = (sljit_s32*)sbuf;
4652 if (verbose)
4653 printf("Run test49\n");
4655 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
4656 if (verbose)
4657 printf("no fpu available, test49 skipped\n");
4658 successful_tests++;
4659 if (compiler)
4660 sljit_free_compiler(compiler);
4661 return;
4664 FAILED(!compiler, "cannot create compiler\n");
4666 for (i = 0; i < 9; i++) {
4667 dbuf_ptr[i << 1] = -1;
4668 dbuf_ptr[(i << 1) + 1] = -1;
4669 sbuf_ptr[i] = -1;
4670 wbuf[i] = -1;
4671 ibuf[i] = -1;
4674 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4675 dbuf[9] = (sljit_f64)SLJIT_W(0x1122334455);
4676 #endif
4677 dbuf[0] = 673.75;
4678 sbuf[0] = -879.75;
4679 wbuf[0] = 345;
4680 ibuf[0] = -249;
4682 sljit_emit_enter(compiler, 0, 0, 3, 3, 3, 0, 0);
4683 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, (sljit_sw)&dbuf);
4684 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, (sljit_sw)&sbuf);
4685 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, (sljit_sw)&wbuf);
4686 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, (sljit_sw)&ibuf);
4688 /* dbuf[2] */
4689 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_F32, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_S1), 0);
4690 /* sbuf[2] */
4691 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_F64, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_S0), 0);
4692 /* wbuf[2] */
4693 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F64, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 0);
4694 /* wbuf[4] */
4695 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F32, SLJIT_MEM1(SLJIT_S2), 4 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S1), 0);
4696 /* ibuf[2] */
4697 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F64, SLJIT_MEM1(SLJIT_R2), 2 * sizeof(sljit_s32), SLJIT_MEM1(SLJIT_S0), 0);
4698 /* ibuf[4] */
4699 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F32, SLJIT_MEM1(SLJIT_R2), 4 * sizeof(sljit_s32), SLJIT_MEM1(SLJIT_S1), 0);
4700 /* dbuf[4] */
4701 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_S2), 0);
4702 /* sbuf[4] */
4703 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_SW, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_S2), 0);
4704 /* dbuf[6] */
4705 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_S32, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_R2), 0);
4706 /* sbuf[6] */
4707 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_S32, SLJIT_MEM1(SLJIT_S1), 6 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_R2), 0);
4709 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4710 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F64, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f64));
4711 /* wbuf[8] */
4712 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S2), 8 * sizeof(sljit_sw), SLJIT_R0, 0);
4713 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f64));
4714 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F64, SLJIT_R0, 0, SLJIT_FR2, 0);
4715 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
4716 sljit_emit_op2(compiler, SLJIT_AND32, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffff);
4717 /* ibuf[8] */
4718 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_R2), 8 * sizeof(sljit_s32), SLJIT_R0, 0);
4719 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x4455667788));
4720 /* dbuf[8] */
4721 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_f64), SLJIT_R0, 0);
4722 /* dbuf[9] */
4723 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_S32, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f64), SLJIT_IMM, SLJIT_W(0x7766554433));
4724 #endif
4726 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
4728 code.code = sljit_generate_code(compiler);
4729 CHECK(compiler);
4730 sljit_free_compiler(compiler);
4732 code.func0();
4734 FAILED(dbuf_ptr[(1 * 2) + 0] != -1, "test49 case 1 failed\n");
4735 FAILED(dbuf_ptr[(1 * 2) + 1] != -1, "test49 case 2 failed\n");
4736 FAILED(dbuf[2] != -879.75, "test49 case 3 failed\n");
4737 FAILED(dbuf_ptr[(3 * 2) + 0] != -1, "test49 case 4 failed\n");
4738 FAILED(dbuf_ptr[(3 * 2) + 1] != -1, "test49 case 5 failed\n");
4739 FAILED(dbuf[4] != 345, "test49 case 6 failed\n");
4740 FAILED(dbuf_ptr[(5 * 2) + 0] != -1, "test49 case 7 failed\n");
4741 FAILED(dbuf_ptr[(5 * 2) + 1] != -1, "test49 case 8 failed\n");
4742 FAILED(dbuf[6] != -249, "test49 case 9 failed\n");
4743 FAILED(dbuf_ptr[(7 * 2) + 0] != -1, "test49 case 10 failed\n");
4744 FAILED(dbuf_ptr[(7 * 2) + 1] != -1, "test49 case 11 failed\n");
4746 FAILED(sbuf_ptr[1] != -1, "test49 case 12 failed\n");
4747 FAILED(sbuf[2] != 673.75, "test49 case 13 failed\n");
4748 FAILED(sbuf_ptr[3] != -1, "test49 case 14 failed\n");
4749 FAILED(sbuf[4] != 345, "test49 case 15 failed\n");
4750 FAILED(sbuf_ptr[5] != -1, "test49 case 16 failed\n");
4751 FAILED(sbuf[6] != -249, "test49 case 17 failed\n");
4752 FAILED(sbuf_ptr[7] != -1, "test49 case 18 failed\n");
4754 FAILED(wbuf[1] != -1, "test49 case 19 failed\n");
4755 FAILED(wbuf[2] != 673, "test49 case 20 failed\n");
4756 FAILED(wbuf[3] != -1, "test49 case 21 failed\n");
4757 FAILED(wbuf[4] != -879, "test49 case 22 failed\n");
4758 FAILED(wbuf[5] != -1, "test49 case 23 failed\n");
4760 FAILED(ibuf[1] != -1, "test49 case 24 failed\n");
4761 FAILED(ibuf[2] != 673, "test49 case 25 failed\n");
4762 FAILED(ibuf[3] != -1, "test49 case 26 failed\n");
4763 FAILED(ibuf[4] != -879, "test49 case 27 failed\n");
4764 FAILED(ibuf[5] != -1, "test49 case 28 failed\n");
4766 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4767 FAILED(dbuf[8] != (sljit_f64)SLJIT_W(0x4455667788), "test49 case 29 failed\n");
4768 FAILED(dbuf[9] != (sljit_f64)SLJIT_W(0x66554433), "test49 case 30 failed\n");
4769 FAILED(wbuf[8] != SLJIT_W(0x1122334455), "test48 case 31 failed\n");
4770 FAILED(ibuf[8] == 0x4455, "test48 case 32 failed\n");
4771 #endif
4773 sljit_free_code(code.code);
4774 successful_tests++;
4777 static void test50(void)
4779 /* Test stack and floating point operations. */
4780 executable_code code;
4781 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4782 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4783 sljit_uw size1, size2, size3;
4784 int result;
4785 #endif
4786 sljit_f32 sbuf[7];
4788 if (verbose)
4789 printf("Run test50\n");
4791 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
4792 if (verbose)
4793 printf("no fpu available, test50 skipped\n");
4794 successful_tests++;
4795 if (compiler)
4796 sljit_free_compiler(compiler);
4797 return;
4800 FAILED(!compiler, "cannot create compiler\n");
4802 sbuf[0] = 245.5;
4803 sbuf[1] = -100.25;
4804 sbuf[2] = 713.75;
4806 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 3, 6, 0, 8 * sizeof(sljit_f32));
4808 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_MEM1(SLJIT_S0), 0);
4809 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), 0);
4810 /* sbuf[3] */
4811 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), sizeof(sljit_f32));
4812 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_f32), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4813 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));
4814 /* sbuf[4] */
4815 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), 2 * sizeof(sljit_f32));
4816 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 2 * sizeof(sljit_f32), SLJIT_IMM, 5934);
4817 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));
4818 /* sbuf[5] */
4819 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), 3 * sizeof(sljit_f32));
4821 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4822 size1 = compiler->size;
4823 #endif
4824 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f32));
4825 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4826 size2 = compiler->size;
4827 #endif
4828 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR5, 0, SLJIT_FR2, 0);
4829 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4830 size3 = compiler->size;
4831 #endif
4832 /* sbuf[6] */
4833 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f32), SLJIT_FR5, 0);
4834 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4835 result = (compiler->size - size3) == (size3 - size2) && (size3 - size2) == (size2 - size1);
4836 #endif
4838 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
4840 code.code = sljit_generate_code(compiler);
4841 CHECK(compiler);
4842 sljit_free_compiler(compiler);
4844 code.func1((sljit_sw)&sbuf);
4846 FAILED(sbuf[3] != 245.5, "test50 case 1 failed\n");
4847 FAILED(sbuf[4] != 145.25, "test50 case 2 failed\n");
4848 FAILED(sbuf[5] != 5934, "test50 case 3 failed\n");
4849 FAILED(sbuf[6] != 713.75, "test50 case 4 failed\n");
4850 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4851 FAILED(!result, "test50 case 5 failed\n");
4852 #endif
4854 sljit_free_code(code.code);
4855 successful_tests++;
4858 static void test51(void)
4860 /* Test all registers provided by the CPU. */
4861 executable_code code;
4862 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
4863 struct sljit_jump* jump;
4864 sljit_sw buf[2];
4865 sljit_s32 i;
4867 if (verbose)
4868 printf("Run test51\n");
4870 FAILED(!compiler, "cannot create compiler\n");
4872 buf[0] = 39;
4874 sljit_emit_enter(compiler, 0, 0, SLJIT_NUMBER_OF_REGISTERS, 0, 0, 0, 0);
4876 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4877 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 32);
4879 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)buf);
4880 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
4882 for (i = 2; i < SLJIT_NUMBER_OF_REGISTERS; i++) {
4883 if (sljit_get_register_index(SLJIT_R(i)) >= 0) {
4884 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_R0, 0);
4885 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_R(i)), 0);
4886 } else
4887 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, buf[0]);
4890 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 32);
4891 for (i = 2; i < SLJIT_NUMBER_OF_REGISTERS; i++) {
4892 if (sljit_get_register_index(SLJIT_R(i)) >= 0) {
4893 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_R0, 0);
4894 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_R(i)), 32);
4895 } else
4896 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, buf[0]);
4899 for (i = 2; i < SLJIT_NUMBER_OF_REGISTERS; i++) {
4900 if (sljit_get_register_index(SLJIT_R(i)) >= 0) {
4901 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 32);
4902 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM2(SLJIT_R(i), SLJIT_R0), 0);
4903 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM2(SLJIT_R0, SLJIT_R(i)), 0);
4904 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 8);
4905 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM2(SLJIT_R0, SLJIT_R(i)), 2);
4906 } else
4907 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 3 * buf[0]);
4910 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 32 + sizeof(sljit_sw), SLJIT_R1, 0);
4912 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
4914 code.code = sljit_generate_code(compiler);
4915 CHECK(compiler);
4916 sljit_free_compiler(compiler);
4918 code.func0();
4920 FAILED(buf[1] != (39 * 5 * (SLJIT_NUMBER_OF_REGISTERS - 2)), "test51 case 1 failed\n");
4922 sljit_free_code(code.code);
4924 /* Next test. */
4926 compiler = sljit_create_compiler(NULL);
4928 FAILED(!compiler, "cannot create compiler\n");
4930 sljit_emit_enter(compiler, 0, 0, SLJIT_NUMBER_OF_SCRATCH_REGISTERS, SLJIT_NUMBER_OF_SAVED_REGISTERS, 0, 0, 0);
4932 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4933 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 17);
4935 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_RET(SW));
4936 /* SLJIT_R0 contains the first value. */
4937 for (i = 1; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4938 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R(i), 0);
4940 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
4942 sljit_set_label(jump, sljit_emit_label(compiler));
4943 sljit_emit_enter(compiler, 0, 0, SLJIT_NUMBER_OF_REGISTERS, 0, 0, 0, 0);
4944 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4945 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 35);
4946 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
4948 code.code = sljit_generate_code(compiler);
4949 CHECK(compiler);
4950 sljit_free_compiler(compiler);
4952 FAILED(code.func0() != (SLJIT_NUMBER_OF_SCRATCH_REGISTERS * 35 + SLJIT_NUMBER_OF_SAVED_REGISTERS * 17), "test51 case 2 failed\n");
4954 sljit_free_code(code.code);
4956 /* Next test. */
4958 compiler = sljit_create_compiler(NULL);
4960 FAILED(!compiler, "cannot create compiler\n");
4962 sljit_emit_enter(compiler, 0, 0, SLJIT_NUMBER_OF_SCRATCH_REGISTERS, SLJIT_NUMBER_OF_SAVED_REGISTERS, 0, 0, 0);
4964 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4965 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 68);
4967 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_RET(SW));
4968 /* SLJIT_R0 contains the first value. */
4969 for (i = 1; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4970 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R(i), 0);
4972 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
4974 sljit_set_label(jump, sljit_emit_label(compiler));
4975 sljit_emit_enter(compiler, 0, 0, 0, SLJIT_NUMBER_OF_REGISTERS, 0, 0, 0);
4976 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4977 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S(i), 0, SLJIT_IMM, 43);
4978 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
4980 code.code = sljit_generate_code(compiler);
4981 CHECK(compiler);
4982 sljit_free_compiler(compiler);
4984 FAILED(code.func0() != (SLJIT_NUMBER_OF_SCRATCH_REGISTERS * 43 + SLJIT_NUMBER_OF_SAVED_REGISTERS * 68), "test51 case 3 failed\n");
4986 sljit_free_code(code.code);
4987 successful_tests++;
4990 static void test52(void)
4992 /* Test all registers provided by the CPU. */
4993 executable_code code;
4994 struct sljit_compiler* compiler;
4995 struct sljit_jump* jump;
4996 sljit_f64 buf[3];
4997 sljit_s32 i;
4999 if (verbose)
5000 printf("Run test52\n");
5002 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5003 if (verbose)
5004 printf("no fpu available, test52 skipped\n");
5005 successful_tests++;
5006 return;
5009 /* Next test. */
5011 compiler = sljit_create_compiler(NULL);
5012 FAILED(!compiler, "cannot create compiler\n");
5013 buf[0] = 6.25;
5014 buf[1] = 17.75;
5016 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 0, 1, SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS, SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS, 0);
5018 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5019 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR(i), 0, SLJIT_MEM1(SLJIT_S0), 0);
5021 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_RET(VOID));
5022 /* SLJIT_FR0 contains the first value. */
5023 for (i = 1; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5024 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR0, 0, SLJIT_FR0, 0, SLJIT_FR(i), 0);
5025 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64), SLJIT_FR0, 0);
5027 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5029 sljit_set_label(jump, sljit_emit_label(compiler));
5030 sljit_emit_enter(compiler, 0, 0, 1, 0, SLJIT_NUMBER_OF_FLOAT_REGISTERS, 0, 0);
5031 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[1]);
5032 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5033 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR(i), 0, SLJIT_MEM1(SLJIT_R0), 0);
5034 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5036 code.code = sljit_generate_code(compiler);
5037 CHECK(compiler);
5038 sljit_free_compiler(compiler);
5040 code.func1((sljit_sw)&buf);
5041 FAILED(buf[2] != (SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS * 17.75 + SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS * 6.25), "test52 case 1 failed\n");
5043 sljit_free_code(code.code);
5045 /* Next test. */
5047 compiler = sljit_create_compiler(NULL);
5048 FAILED(!compiler, "cannot create compiler\n");
5049 buf[0] = -32.5;
5050 buf[1] = -11.25;
5052 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 0, 1, SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS, SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS, 0);
5054 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5055 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR(i), 0, SLJIT_MEM1(SLJIT_S0), 0);
5057 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_RET(VOID));
5058 /* SLJIT_FR0 contains the first value. */
5059 for (i = 1; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5060 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR0, 0, SLJIT_FR0, 0, SLJIT_FR(i), 0);
5061 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64), SLJIT_FR0, 0);
5063 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5065 sljit_set_label(jump, sljit_emit_label(compiler));
5066 sljit_emit_enter(compiler, 0, 0, 1, 0, 0, SLJIT_NUMBER_OF_FLOAT_REGISTERS, 0);
5067 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[1]);
5068 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5069 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FS(i), 0, SLJIT_MEM1(SLJIT_R0), 0);
5070 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5072 code.code = sljit_generate_code(compiler);
5073 CHECK(compiler);
5074 sljit_free_compiler(compiler);
5076 code.func1((sljit_sw)&buf);
5077 FAILED(buf[2] != (SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS * -11.25 + SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS * -32.5), "test52 case 2 failed\n");
5079 sljit_free_code(code.code);
5080 successful_tests++;
5083 static void test53(void)
5085 /* Check SLJIT_DOUBLE_ALIGNMENT. */
5086 executable_code code;
5087 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
5088 sljit_sw buf[1];
5090 if (verbose)
5091 printf("Run test53\n");
5093 FAILED(!compiler, "cannot create compiler\n");
5094 buf[0] = -1;
5096 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, SLJIT_ARG1(SW), 1, 1, 0, 0, 2 * sizeof(sljit_sw));
5098 sljit_get_local_base(compiler, SLJIT_R0, 0, 0);
5099 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
5101 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5103 code.code = sljit_generate_code(compiler);
5104 CHECK(compiler);
5105 sljit_free_compiler(compiler);
5107 code.func1((sljit_sw)&buf);
5109 FAILED((buf[0] & (sizeof(sljit_f64) - 1)) != 0, "test53 case 1 failed\n");
5111 sljit_free_code(code.code);
5113 /* Next test. */
5115 compiler = sljit_create_compiler(NULL);
5116 FAILED(!compiler, "cannot create compiler\n");
5117 buf[0] = -1;
5119 /* One more saved register to break the alignment on x86-32. */
5120 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, SLJIT_ARG1(SW), 1, 2, 0, 0, 2 * sizeof(sljit_sw));
5122 sljit_get_local_base(compiler, SLJIT_R0, 0, 0);
5123 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
5125 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5127 code.code = sljit_generate_code(compiler);
5128 CHECK(compiler);
5129 sljit_free_compiler(compiler);
5131 code.func1((sljit_sw)&buf);
5133 FAILED((buf[0] & (sizeof(sljit_f64) - 1)) != 0, "test53 case 2 failed\n");
5135 sljit_free_code(code.code);
5136 successful_tests++;
5139 static void test54(void)
5141 /* Check cmov. */
5142 executable_code code;
5143 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
5144 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
5145 sljit_sw large_num = SLJIT_W(0x1234567812345678);
5146 #else
5147 sljit_sw large_num = SLJIT_W(0x12345678);
5148 #endif
5149 int i;
5150 sljit_sw buf[19];
5151 sljit_s32 ibuf[4];
5153 union {
5154 sljit_f32 value;
5155 sljit_s32 s32_value;
5156 } sbuf[3];
5158 sbuf[0].s32_value = 0x7fffffff;
5159 sbuf[1].value = 7.5;
5160 sbuf[2].value = -14.75;
5162 if (verbose)
5163 printf("Run test54\n");
5165 FAILED(!compiler, "cannot create compiler\n");
5167 for (i = 0; i < 19; i++)
5168 buf[i] = 0;
5169 for (i = 0; i < 4; i++)
5170 ibuf[i] = 0;
5172 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), 5, 3, 3, 0, 0);
5174 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 17);
5175 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 34);
5176 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, -10);
5177 sljit_emit_cmov(compiler, SLJIT_SIG_LESS, SLJIT_R0, SLJIT_R1, 0);
5178 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
5179 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, -10);
5180 sljit_emit_cmov(compiler, SLJIT_SIG_GREATER, SLJIT_R0, SLJIT_R1, 0);
5181 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
5183 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 24);
5184 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 24);
5185 sljit_emit_cmov(compiler, SLJIT_NOT_EQUAL, SLJIT_R0, SLJIT_IMM, 66);
5186 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
5187 sljit_emit_cmov(compiler, SLJIT_EQUAL, SLJIT_R0, SLJIT_IMM, 78);
5188 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_R0, 0);
5189 sljit_emit_cmov(compiler, SLJIT_EQUAL, SLJIT_R0, SLJIT_IMM, large_num);
5190 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
5192 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
5193 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R3) == -1 && sljit_get_register_index(SLJIT_R4) == -1);
5194 #endif
5195 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 7);
5196 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -45);
5197 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_OVERFLOW, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 8);
5198 sljit_emit_cmov(compiler, SLJIT_MUL_OVERFLOW, SLJIT_R3, SLJIT_IMM, 35);
5199 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R3, 0);
5200 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, large_num);
5201 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_OVERFLOW, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, large_num);
5202 sljit_emit_cmov(compiler, SLJIT_MUL_OVERFLOW, SLJIT_R3, SLJIT_IMM, 35);
5203 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_R3, 0);
5205 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 71);
5206 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 13);
5207 sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 8);
5208 sljit_emit_cmov(compiler, SLJIT_EQUAL, SLJIT_R3, SLJIT_R0, 0);
5209 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R3, 0);
5211 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 12);
5212 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -29);
5213 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_MUL_OVERFLOW, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 8);
5214 sljit_emit_cmov(compiler, SLJIT_MUL_NOT_OVERFLOW, SLJIT_R0, SLJIT_R3, 0);
5215 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R3, 0);
5217 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 16);
5218 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -12);
5219 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_IMM, 21);
5220 sljit_emit_op2(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 8);
5221 sljit_emit_cmov(compiler, SLJIT_NOT_EQUAL, SLJIT_R3, SLJIT_R4, 0);
5222 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_R3, 0);
5223 sljit_emit_cmov(compiler, SLJIT_EQUAL, SLJIT_R3, SLJIT_R4, 0);
5224 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_R3, 0);
5226 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5227 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S2), 0);
5228 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f32));
5229 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_f32));
5231 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 16);
5232 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
5233 sljit_emit_cmov(compiler, SLJIT_EQUAL_F32, SLJIT_R0, SLJIT_IMM, -45);
5234 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_R0, 0);
5235 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_GREATER_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
5236 sljit_emit_cmov(compiler, SLJIT_GREATER_F32, SLJIT_R0, SLJIT_IMM, -45);
5237 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_R0, 0);
5238 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_GREATER_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
5239 sljit_emit_cmov(compiler, SLJIT_GREATER_EQUAL_F32, SLJIT_R0, SLJIT_IMM, 33);
5240 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_R0, 0);
5242 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
5243 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_LESS_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
5244 sljit_emit_cmov(compiler, SLJIT_LESS_F32, SLJIT_R0, SLJIT_IMM, -70);
5245 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_sw), SLJIT_R0, 0);
5246 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_LESS_EQUAL_F, SLJIT_FR2, 0, SLJIT_FR1, 0);
5247 sljit_emit_cmov(compiler, SLJIT_LESS_EQUAL_F32, SLJIT_R0, SLJIT_IMM, -60);
5248 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 15 * sizeof(sljit_sw), SLJIT_R0, 0);
5249 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_NOT_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
5250 sljit_emit_cmov(compiler, SLJIT_NOT_EQUAL_F32, SLJIT_R0, SLJIT_IMM, 31);
5251 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 16 * sizeof(sljit_sw), SLJIT_R0, 0);
5253 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 53);
5254 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_ORDERED_F, SLJIT_FR1, 0, SLJIT_FR0, 0);
5255 sljit_emit_cmov(compiler, SLJIT_ORDERED_F32, SLJIT_R0, SLJIT_IMM, 17);
5256 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 17 * sizeof(sljit_sw), SLJIT_R0, 0);
5257 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_UNORDERED_F, SLJIT_FR1, 0, SLJIT_FR0, 0);
5258 sljit_emit_cmov(compiler, SLJIT_UNORDERED_F32, SLJIT_R0, SLJIT_IMM, 59);
5259 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_sw), SLJIT_R0, 0);
5262 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 177);
5263 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 178);
5264 sljit_emit_cmov(compiler, SLJIT_LESS32, SLJIT_R0 | SLJIT_I32_OP, SLJIT_IMM, 200);
5265 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_R0, 0);
5267 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 95);
5268 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R3, 0, SLJIT_IMM, 177);
5269 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_LESS_EQUAL, SLJIT_UNUSED, 0, SLJIT_R0, 0, SLJIT_IMM, 95);
5270 sljit_emit_cmov(compiler, SLJIT_LESS_EQUAL, SLJIT_R3 | SLJIT_I32_OP, SLJIT_R0, 0);
5271 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0);
5272 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32), SLJIT_R3, 0);
5274 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R3, 0, SLJIT_IMM, 56);
5275 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R4, 0, SLJIT_IMM, -63);
5276 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_SIG_LESS, SLJIT_UNUSED, 0, SLJIT_R3, 0, SLJIT_R4, 0);
5277 sljit_emit_cmov(compiler, SLJIT_SIG_LESS32, SLJIT_R3 | SLJIT_I32_OP, SLJIT_R4, 0);
5278 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_s32), SLJIT_R3, 0);
5279 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_SIG_GREATER, SLJIT_UNUSED, 0, SLJIT_R3, 0, SLJIT_R4, 0);
5280 sljit_emit_cmov(compiler, SLJIT_SIG_GREATER32, SLJIT_R3 | SLJIT_I32_OP, SLJIT_R4, 0);
5281 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_s32), SLJIT_R3, 0);
5283 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5285 code.code = sljit_generate_code(compiler);
5286 CHECK(compiler);
5287 sljit_free_compiler(compiler);
5289 code.func3((sljit_sw)&buf, (sljit_sw)&ibuf, (sljit_sw)&sbuf);
5291 FAILED(buf[0] != 17, "test54 case 1 failed\n");
5292 FAILED(buf[1] != 34, "test54 case 2 failed\n");
5293 FAILED(buf[2] != 24, "test54 case 3 failed\n");
5294 FAILED(buf[3] != 78, "test54 case 4 failed\n");
5295 FAILED(buf[4] != large_num, "test54 case 5 failed\n");
5296 FAILED(buf[5] != -45, "test54 case 6 failed\n");
5297 FAILED(buf[6] != 35, "test54 case 7 failed\n");
5298 FAILED(buf[7] != 71, "test54 case 8 failed\n");
5299 FAILED(buf[8] != -29, "test54 case 9 failed\n");
5300 FAILED(buf[9] != -12, "test54 case 10 failed\n");
5301 FAILED(buf[10] != 21, "test54 case 11 failed\n");
5303 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5304 FAILED(buf[11] != 16, "test54 case 12 failed\n");
5305 FAILED(buf[12] != -45, "test54 case 13 failed\n");
5306 FAILED(buf[13] != 33, "test54 case 14 failed\n");
5307 FAILED(buf[14] != 8, "test54 case 15 failed\n");
5308 FAILED(buf[15] != -60, "test54 case 16 failed\n");
5309 FAILED(buf[16] != 31, "test54 case 17 failed\n");
5310 FAILED(buf[17] != 53, "test54 case 18 failed\n");
5311 FAILED(buf[18] != 59, "test54 case 19 failed\n");
5314 FAILED(ibuf[0] != 200, "test54 case 12 failed\n");
5315 FAILED(ibuf[1] != 95, "test54 case 13 failed\n");
5316 FAILED(ibuf[2] != 56, "test54 case 14 failed\n");
5317 FAILED(ibuf[3] != -63, "test54 case 15 failed\n");
5319 sljit_free_code(code.code);
5320 successful_tests++;
5323 static void test55(void)
5325 /* Check value preservation. */
5326 executable_code code;
5327 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
5328 sljit_sw buf[2];
5329 sljit_s32 i;
5331 if (verbose)
5332 printf("Run test55\n");
5334 FAILED(!compiler, "cannot create compiler\n");
5335 buf[0] = 0;
5336 buf[1] = 0;
5338 sljit_emit_enter(compiler, 0, 0, SLJIT_NUMBER_OF_REGISTERS, 0, 0, 0, sizeof (sljit_sw));
5340 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, 217);
5342 /* Check 1 */
5343 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5344 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 118);
5346 sljit_emit_op0(compiler, SLJIT_DIVMOD_SW);
5348 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
5350 for (i = 2; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5351 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R(i), 0);
5352 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_SP), 0);
5354 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM0(), (sljit_sw)(buf + 0), SLJIT_R0, 0);
5356 /* Check 2 */
5357 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5358 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 146);
5360 sljit_emit_op0(compiler, SLJIT_DIV_SW);
5362 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
5364 for (i = 1; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5365 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R(i), 0);
5366 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_SP), 0);
5368 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM0(), (sljit_sw)(buf + 1), SLJIT_R0, 0);
5370 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5372 code.code = sljit_generate_code(compiler);
5373 CHECK(compiler);
5374 sljit_free_compiler(compiler);
5376 code.func0();
5378 FAILED(buf[0] != (SLJIT_NUMBER_OF_REGISTERS - 2) * 118 + 217, "test55 case 1 failed\n");
5379 FAILED(buf[1] != (SLJIT_NUMBER_OF_REGISTERS - 1) * 146 + 217, "test55 case 2 failed\n");
5381 sljit_free_code(code.code);
5382 successful_tests++;
5385 static void test56(void)
5387 /* Check integer substraction with negative immediate. */
5388 executable_code code;
5389 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
5390 sljit_sw buf[13];
5391 sljit_s32 i;
5393 if (verbose)
5394 printf("Run test56\n");
5396 for (i = 0; i < 13; i++)
5397 buf[i] = 77;
5399 FAILED(!compiler, "cannot create compiler\n");
5401 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 0, 0, 0);
5403 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 90 << 12);
5404 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5405 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R1, 0);
5406 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_SIG_GREATER);
5407 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5408 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R1, 0);
5409 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_LESS);
5410 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER_EQUAL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5411 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_SIG_GREATER_EQUAL);
5412 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS_EQUAL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5413 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_LESS_EQUAL);
5414 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5415 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_GREATER);
5416 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5417 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_SIG_LESS);
5419 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 90);
5420 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, -91);
5421 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R0, 0);
5422 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_SIG_GREATER);
5423 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 90);
5424 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, -91);
5425 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_LESS_EQUAL);
5427 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, -0x7fffffff);
5428 sljit_emit_op2(compiler, SLJIT_ADD32 | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5429 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_OVERFLOW32);
5431 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, -0x80000000);
5432 sljit_emit_op1(compiler, SLJIT_NEG32 | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R0, 0);
5433 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_OVERFLOW32);
5435 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5437 code.code = sljit_generate_code(compiler);
5438 CHECK(compiler);
5439 sljit_free_compiler(compiler);
5441 code.func1((sljit_sw)&buf);
5443 FAILED(buf[0] != (181 << 12), "test56 case 1 failed\n");
5444 FAILED(buf[1] != 1, "test56 case 2 failed\n");
5445 FAILED(buf[2] != (181 << 12), "test56 case 3 failed\n");
5446 FAILED(buf[3] != 1, "test56 case 4 failed\n");
5447 FAILED(buf[4] != 1, "test56 case 5 failed\n");
5448 FAILED(buf[5] != 1, "test56 case 6 failed\n");
5449 FAILED(buf[6] != 0, "test56 case 7 failed\n");
5450 FAILED(buf[7] != 0, "test56 case 8 failed\n");
5451 FAILED(buf[8] != 181, "test56 case 9 failed\n");
5452 FAILED(buf[9] != 1, "test56 case 10 failed\n");
5453 FAILED(buf[10] != 1, "test56 case 11 failed\n");
5454 FAILED(buf[11] != 1, "test56 case 12 failed\n");
5455 FAILED(buf[12] != 1, "test56 case 13 failed\n");
5457 sljit_free_code(code.code);
5458 successful_tests++;
5461 static void test57(void)
5463 /* Check prefetch instructions. */
5464 executable_code code;
5465 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
5466 struct sljit_label* labels[2];
5468 if (verbose)
5469 printf("Run test57\n");
5471 FAILED(!compiler, "cannot create compiler\n");
5473 sljit_emit_enter(compiler, 0, 0, 3, 1, 0, 0, 0);
5475 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
5476 /* Should never crash. */
5477 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_sw));
5478 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
5479 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_R0), SLJIT_W(0x1122334455667788));
5480 #else
5481 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_R0), 0x11223344);
5482 #endif
5484 labels[0] = sljit_emit_label(compiler);
5485 /* Code size should be zero. */
5486 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_UNUSED, 0, SLJIT_R0, 0);
5487 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_UNUSED, 0, SLJIT_IMM, 135);
5488 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_UNUSED, 0, SLJIT_R1, 0);
5489 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_UNUSED, 0, SLJIT_R1, 0);
5490 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_R0), 0);
5491 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_UNUSED, 0, SLJIT_R1, 0, SLJIT_IMM, 6);
5492 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_UNUSED, 0, SLJIT_MEM0(), 0, SLJIT_IMM, 6);
5493 labels[1] = sljit_emit_label(compiler);
5495 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5497 code.code = sljit_generate_code(compiler);
5498 CHECK(compiler);
5499 sljit_free_compiler(compiler);
5501 code.func0();
5503 FAILED(sljit_get_label_addr(labels[0]) != sljit_get_label_addr(labels[1]), "test57 case 1 failed\n");
5505 sljit_free_code(code.code);
5506 successful_tests++;
5509 static sljit_f64 SLJIT_FUNC test58_f1(sljit_f32 a, sljit_f32 b, sljit_f64 c)
5511 return a + b + c;
5514 static sljit_f32 SLJIT_FUNC test58_f2(sljit_sw a, sljit_f64 b, sljit_f32 c)
5516 return a + b + c;
5519 static sljit_f64 SLJIT_FUNC test58_f3(sljit_sw a, sljit_f32 b, sljit_sw c)
5521 return a + b + c;
5524 static sljit_f64 test58_f4(sljit_f32 a, sljit_sw b)
5526 return a + b;
5529 static sljit_f32 test58_f5(sljit_f32 a, sljit_f64 b, sljit_s32 c)
5531 return a + b + c;
5534 static sljit_sw SLJIT_FUNC test58_f6(sljit_f64 a, sljit_sw b)
5536 return (sljit_sw)a + b;
5539 static void test58(void)
5541 /* Check function calls with floating point arguments. */
5542 executable_code code;
5543 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
5544 struct sljit_jump* jump = NULL;
5545 sljit_f64 dbuf[7];
5546 sljit_f32 sbuf[7];
5547 sljit_sw wbuf[2];
5549 if (verbose)
5550 printf("Run test58\n");
5552 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5553 if (verbose)
5554 printf("no fpu available, test58 skipped\n");
5555 successful_tests++;
5556 if (compiler)
5557 sljit_free_compiler(compiler);
5558 return;
5561 dbuf[0] = 5.25;
5562 dbuf[1] = 0.0;
5563 dbuf[2] = 2.5;
5564 dbuf[3] = 0.0;
5565 dbuf[4] = 0.0;
5566 dbuf[5] = 0.0;
5567 dbuf[6] = -18.0;
5569 sbuf[0] = 6.75;
5570 sbuf[1] = -3.5;
5571 sbuf[2] = 1.5;
5572 sbuf[3] = 0.0;
5573 sbuf[4] = 0.0;
5575 wbuf[0] = 0;
5576 wbuf[1] = 0;
5578 FAILED(!compiler, "cannot create compiler\n");
5580 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), 3, 3, 4, 0, sizeof(sljit_sw));
5582 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), 0);
5583 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f32));
5584 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 0);
5585 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));
5586 /* dbuf[1] */
5587 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64), SLJIT_FR0, 0);
5589 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f32));
5590 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f32));
5591 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64));
5592 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_RET(F64) | SLJIT_ARG1(F32) | SLJIT_ARG2(F32) | SLJIT_ARG3(F64));
5593 sljit_set_target(jump, SLJIT_FUNC_OFFSET(test58_f1));
5594 /* dbuf[3] */
5595 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f64), SLJIT_FR0, 0);
5597 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(test58_f2));
5598 sljit_get_local_base(compiler, SLJIT_R1, 0, -16);
5599 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 16);
5600 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 0);
5601 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f32));
5602 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);
5603 /* sbuf[3] */
5604 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f32), SLJIT_FR0, 0);
5606 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -4);
5607 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 9);
5608 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 0);
5609 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), 0);
5610 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_RET(F64) | SLJIT_ARG1(SW) | SLJIT_ARG2(F32) | SLJIT_ARG3(SW));
5611 sljit_set_target(jump, SLJIT_FUNC_OFFSET(test58_f3));
5612 /* dbuf[4] */
5613 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f64), SLJIT_FR0, 0);
5615 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f32));
5616 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -6);
5617 jump = sljit_emit_call(compiler, SLJIT_CALL_CDECL, SLJIT_RET(F64) | SLJIT_ARG1(F32) | SLJIT_ARG2(SW));
5618 sljit_set_target(jump, SLJIT_FUNC_OFFSET(test58_f4));
5619 /* dbuf[5] */
5620 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f64), SLJIT_FR0, 0);
5622 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(test58_f5));
5623 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f32));
5624 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64));
5625 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
5626 sljit_emit_icall(compiler, SLJIT_CALL_CDECL, SLJIT_RET(F32) | SLJIT_ARG1(F32) | SLJIT_ARG2(F64) | SLJIT_ARG3(S32), SLJIT_MEM1(SLJIT_SP), 0);
5627 /* sbuf[4] */
5628 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_f32), SLJIT_FR0, 0);
5630 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64));
5631 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(test58_f6));
5632 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(F64) | SLJIT_ARG2(SW), SLJIT_R0, 0);
5633 /* wbuf[0] */
5634 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S2), 0, SLJIT_R0, 0);
5636 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64));
5637 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 319);
5638 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(test58_f6));
5639 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(F64) | SLJIT_ARG2(SW), SLJIT_R1, 0);
5640 /* wbuf[1] */
5641 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_sw), SLJIT_R0, 0);
5643 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5645 code.code = sljit_generate_code(compiler);
5646 CHECK(compiler);
5647 sljit_free_compiler(compiler);
5649 code.func3((sljit_sw)&dbuf, (sljit_sw)&sbuf, (sljit_sw)&wbuf);
5651 FAILED(dbuf[1] != 8.5, "test58 case 1 failed\n");
5652 FAILED(dbuf[3] != 0.5, "test58 case 2 failed\n");
5653 FAILED(sbuf[3] != 17.75, "test58 case 3 failed\n");
5654 FAILED(dbuf[4] != 11.75, "test58 case 4 failed\n");
5655 FAILED(dbuf[5] != -9.5, "test58 case 5 failed\n");
5656 FAILED(sbuf[4] != 12, "test58 case 6 failed\n");
5657 FAILED(wbuf[0] != SLJIT_FUNC_OFFSET(test58_f6) - 18, "test58 case 7 failed\n");
5658 FAILED(wbuf[1] != 301, "test58 case 8 failed\n");
5660 sljit_free_code(code.code);
5661 successful_tests++;
5664 static sljit_sw SLJIT_FUNC test59_f1(sljit_sw a, sljit_s32 b, sljit_sw c, sljit_sw d)
5666 return (sljit_sw)(a + b + c + d - SLJIT_FUNC_OFFSET(test59_f1));
5669 static sljit_sw test59_f2(sljit_sw a, sljit_s32 b, sljit_sw c, sljit_sw d)
5671 return (sljit_sw)(a + b + c + d - SLJIT_FUNC_OFFSET(test59_f2));
5674 static sljit_s32 SLJIT_FUNC test59_f3(sljit_f64 a, sljit_f32 b, sljit_f64 c, sljit_sw d)
5676 return (sljit_s32)(a + b + c + d);
5679 static sljit_f32 SLJIT_FUNC test59_f4(sljit_f32 a, sljit_s32 b, sljit_f64 c, sljit_sw d)
5681 return (sljit_f32)(a + b + c + d);
5684 static sljit_f32 SLJIT_FUNC test59_f5(sljit_f32 a, sljit_f64 b, sljit_f32 c, sljit_f64 d)
5686 return (sljit_f32)(a + b + c + d);
5689 static void test59(void)
5691 /* Check function calls with four arguments. */
5692 executable_code code;
5693 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
5694 struct sljit_jump* jump = NULL;
5695 sljit_sw wbuf[6];
5696 sljit_f64 dbuf[3];
5697 sljit_f32 sbuf[4];
5699 if (verbose)
5700 printf("Run test59\n");
5702 wbuf[0] = 0;
5703 wbuf[1] = 0;
5704 wbuf[2] = 0;
5705 wbuf[3] = SLJIT_FUNC_OFFSET(test59_f1);
5706 wbuf[4] = 0;
5707 wbuf[5] = 0;
5709 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5710 dbuf[0] = 5.125;
5711 dbuf[1] = 6.125;
5712 dbuf[2] = 4.25;
5714 sbuf[0] = 0.75;
5715 sbuf[1] = -1.5;
5716 sbuf[2] = 0.0;
5717 sbuf[3] = 0.0;
5720 FAILED(!compiler, "cannot create compiler\n");
5722 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), 4, 3, 4, 0, sizeof(sljit_sw));
5724 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 33);
5725 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -20);
5726 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(test59_f1));
5727 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -40);
5728 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(S32) | SLJIT_ARG3(SW) | SLJIT_ARG4(SW), SLJIT_R2, 0);
5729 /* wbuf[0] */
5730 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
5732 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 16);
5733 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -30);
5734 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 50);
5735 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(test59_f2));
5736 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);
5737 /* wbuf[1] */
5738 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
5740 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(test59_f1));
5741 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -25);
5742 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 100);
5743 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -10);
5744 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(SW) | SLJIT_ARG1(SW) | SLJIT_ARG2(S32) | SLJIT_ARG3(SW) | SLJIT_ARG4(SW), SLJIT_R0, 0);
5745 /* wbuf[2] */
5746 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
5748 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
5749 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 231);
5750 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 3);
5751 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(test59_f1) - 100);
5752 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);
5753 /* wbuf[4] */
5754 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
5756 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5757 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), 0);
5758 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S2), 0);
5759 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f64));
5760 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -100);
5761 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));
5762 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
5763 /* wbuf[5] */
5764 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R0, 0);
5766 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f32));
5767 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f64));
5768 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 36);
5769 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 41);
5770 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_RET(F32) | SLJIT_ARG1(F32) | SLJIT_ARG2(S32) | SLJIT_ARG3(F64) | SLJIT_ARG4(SW));
5771 sljit_set_target(jump, SLJIT_FUNC_OFFSET(test59_f4));
5772 /* sbuf[2] */
5773 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_f32), SLJIT_FR0, 0);
5775 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_FUNC_OFFSET(test59_f5));
5776 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S2), 0);
5777 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), 0);
5778 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f32));
5779 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR3, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f64));
5780 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_RET(F32) | SLJIT_ARG1(F32) | SLJIT_ARG2(F64) | SLJIT_ARG3(F32) | SLJIT_ARG4(F64), SLJIT_R0, 0);
5781 /* sbuf[2] */
5782 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S2), 3 * sizeof(sljit_f32), SLJIT_FR0, 0);
5785 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5787 code.code = sljit_generate_code(compiler);
5788 CHECK(compiler);
5789 sljit_free_compiler(compiler);
5791 code.func3((sljit_sw)&wbuf, (sljit_sw)&dbuf, (sljit_sw)&sbuf);
5793 FAILED(wbuf[0] != -27, "test59 case 1 failed\n");
5794 FAILED(wbuf[1] != 36, "test59 case 2 failed\n");
5795 FAILED(wbuf[2] != 65, "test59 case 3 failed\n");
5796 FAILED(wbuf[4] != (sljit_sw)wbuf + 134, "test59 case 4 failed\n");
5798 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5799 FAILED(wbuf[5] != -88, "test59 case 5 failed\n");
5800 FAILED(sbuf[2] != 79.75, "test59 case 6 failed\n");
5801 FAILED(sbuf[3] != 8.625, "test59 case 7 failed\n");
5804 sljit_free_code(code.code);
5805 successful_tests++;
5808 static void test60(void)
5810 /* Test memory accesses with pre/post updates. */
5811 executable_code code;
5812 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
5813 sljit_s32 i;
5814 sljit_s32 supported[10];
5815 sljit_sw wbuf[18];
5816 sljit_s8 bbuf[4];
5817 sljit_s32 ibuf[4];
5819 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
5820 static sljit_u8 expected[10] = { 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 };
5821 #elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32)
5822 static sljit_u8 expected[10] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
5823 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32)
5824 static sljit_u8 expected[10] = { 1, 0, 1, 1, 0, 1, 1, 1, 0, 0 };
5825 #elif (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
5826 static sljit_u8 expected[10] = { 1, 0, 0, 1, 0, 0, 1, 1, 0, 0 };
5827 #else
5828 static sljit_u8 expected[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
5829 #endif
5831 if (verbose)
5832 printf("Run test60\n");
5834 for (i = 0; i < 18; i++)
5835 wbuf[i] = 0;
5836 wbuf[2] = -887766;
5838 bbuf[0] = 0;
5839 bbuf[1] = 0;
5840 bbuf[2] = -13;
5842 ibuf[0] = -5678;
5843 ibuf[1] = 0;
5844 ibuf[2] = 0;
5846 FAILED(!compiler, "cannot create compiler\n");
5848 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), 4, 3, 4, 0, sizeof(sljit_sw));
5850 supported[0] = sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R0), 2 * sizeof(sljit_sw));
5851 if (supported[0] == SLJIT_SUCCESS) {
5852 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
5853 sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R0), 2 * sizeof(sljit_sw));
5854 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R1, 0);
5855 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
5858 supported[1] = sljit_emit_mem(compiler, SLJIT_MOV_S8 | SLJIT_MEM_SUPP | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM1(SLJIT_R2), -2 * sizeof(sljit_s8));
5859 if (supported[1] == SLJIT_SUCCESS) {
5860 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S1, 0, SLJIT_IMM, 2 * sizeof(sljit_s8));
5861 sljit_emit_mem(compiler, SLJIT_MOV_S8 | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM1(SLJIT_R2), -2 * sizeof(sljit_s8));
5862 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_R0, 0);
5863 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R2, 0);
5866 supported[2] = sljit_emit_mem(compiler, SLJIT_MOV_S32 | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_R2, SLJIT_MEM1(SLJIT_R1), -2 * sizeof(sljit_s32));
5867 if (supported[2] == SLJIT_SUCCESS) {
5868 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S2, 0, SLJIT_IMM, 2 * sizeof(sljit_s32));
5869 sljit_emit_mem(compiler, SLJIT_MOV_S32 | SLJIT_MEM_PRE, SLJIT_R2, SLJIT_MEM1(SLJIT_R1), -2 * sizeof(sljit_s32));
5870 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R2, 0);
5871 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_R1, 0);
5874 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));
5875 if (supported[3] == SLJIT_SUCCESS) {
5876 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -8765);
5877 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, sizeof(sljit_s32));
5878 sljit_emit_mem(compiler, SLJIT_MOV32 | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R2), 2 * sizeof(sljit_s32));
5879 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R2, 0);
5882 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 * sizeof(sljit_s8));
5883 if (supported[4] == SLJIT_SUCCESS) {
5884 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -121);
5885 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_S1, 0);
5886 sljit_emit_mem(compiler, SLJIT_MOV_S8 | SLJIT_MEM_STORE | SLJIT_MEM_POST, SLJIT_R1, SLJIT_MEM1(SLJIT_R2), -128 * sizeof(sljit_s8));
5887 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R2, 0);
5890 supported[5] = sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R0), 1);
5891 if (supported[5] == SLJIT_SUCCESS) {
5892 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 9 * sizeof(sljit_sw) - 1);
5893 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -881199);
5894 sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R0), 1);
5895 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_R0, 0);
5898 supported[6] = sljit_emit_mem(compiler, SLJIT_MOV_S32 | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
5899 if (supported[6] == SLJIT_SUCCESS) {
5900 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S2, 0, SLJIT_IMM, 213);
5901 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -213);
5902 sljit_emit_mem(compiler, SLJIT_MOV_S32 | SLJIT_MEM_PRE, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
5903 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_R0, 0);
5904 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_R1, 0);
5907 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);
5908 if (supported[7] == SLJIT_SUCCESS) {
5909 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_S2, 0);
5910 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 2 * sizeof(sljit_s32));
5911 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -7890);
5912 sljit_emit_mem(compiler, SLJIT_MOV_S32 | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
5913 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_R1, 0);
5916 supported[8] = sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 2);
5917 if (supported[8] == SLJIT_SUCCESS) {
5918 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));
5919 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));
5920 sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 2);
5921 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_sw), SLJIT_R0, 0);
5922 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 15 * sizeof(sljit_sw), SLJIT_R1, 0);
5925 supported[9] = sljit_emit_mem(compiler, SLJIT_MOV_S8 | SLJIT_MEM_SUPP | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
5926 if (supported[9] == SLJIT_SUCCESS) {
5927 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S1, 0, SLJIT_IMM, 2 * sizeof(sljit_s8));
5928 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -2 * sizeof(sljit_s8));
5929 sljit_emit_mem(compiler, SLJIT_MOV_S8 | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
5930 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 16 * sizeof(sljit_sw), SLJIT_R0, 0);
5931 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 17 * sizeof(sljit_sw), SLJIT_R1, 0);
5934 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);
5935 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);
5937 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
5939 code.code = sljit_generate_code(compiler);
5940 CHECK(compiler);
5941 sljit_free_compiler(compiler);
5943 code.func3((sljit_sw)&wbuf, (sljit_sw)&bbuf, (sljit_sw)&ibuf);
5945 FAILED(sizeof(expected) != sizeof(supported) / sizeof(sljit_s32), "test60 case 1 failed\n");
5947 for (i = 0; i < sizeof(expected); i++) {
5948 if (expected[i]) {
5949 if (supported[i] != SLJIT_SUCCESS) {
5950 printf("tast60 case %d should be supported\n", i + 1);
5951 return;
5953 } else {
5954 if (supported[i] == SLJIT_SUCCESS) {
5955 printf("test60 case %d should not be supported\n", i + 1);
5956 return;
5961 FAILED(supported[0] == SLJIT_SUCCESS && wbuf[0] != -887766, "test60 case 2 failed\n");
5962 FAILED(supported[0] == SLJIT_SUCCESS && wbuf[1] != (sljit_sw)(wbuf + 2), "test60 case 3 failed\n");
5963 FAILED(supported[1] == SLJIT_SUCCESS && wbuf[3] != -13, "test60 case 4 failed\n");
5964 FAILED(supported[1] == SLJIT_SUCCESS && wbuf[4] != (sljit_sw)(bbuf), "test60 case 5 failed\n");
5965 FAILED(supported[2] == SLJIT_SUCCESS && wbuf[5] != -5678, "test60 case 6 failed\n");
5966 FAILED(supported[2] == SLJIT_SUCCESS && wbuf[6] != (sljit_sw)(ibuf), "test60 case 7 failed\n");
5967 FAILED(supported[3] == SLJIT_SUCCESS && ibuf[1] != -8765, "test60 case 8 failed\n");
5968 FAILED(supported[3] == SLJIT_SUCCESS && wbuf[7] != (sljit_sw)(ibuf + 1), "test60 case 9 failed\n");
5969 FAILED(supported[4] == SLJIT_SUCCESS && bbuf[0] != -121, "test60 case 10 failed\n");
5970 FAILED(supported[4] == SLJIT_SUCCESS && wbuf[8] != (sljit_sw)(bbuf) - 128 * sizeof(sljit_s8), "test60 case 11 failed\n");
5971 FAILED(supported[5] == SLJIT_SUCCESS && wbuf[9] != -881199, "test60 case 12 failed\n");
5972 FAILED(supported[5] == SLJIT_SUCCESS && wbuf[10] != (sljit_sw)(wbuf + 9), "test60 case 13 failed\n");
5973 FAILED(supported[6] == SLJIT_SUCCESS && wbuf[11] != -5678, "test60 case 14 failed\n");
5974 FAILED(supported[6] == SLJIT_SUCCESS && wbuf[12] != (sljit_sw)(ibuf), "test60 case 15 failed\n");
5975 FAILED(supported[7] == SLJIT_SUCCESS && ibuf[2] != -7890, "test60 case 16 failed\n");
5976 FAILED(supported[7] == SLJIT_SUCCESS && wbuf[13] != (sljit_sw)(ibuf + 2), "test60 case 17 failed\n");
5977 FAILED(supported[8] == SLJIT_SUCCESS && wbuf[14] != -887766, "test60 case 18 failed\n");
5978 FAILED(supported[8] == SLJIT_SUCCESS && wbuf[15] != (sljit_sw)(wbuf + 10), "test60 case 19 failed\n");
5979 FAILED(supported[9] == SLJIT_SUCCESS && wbuf[16] != -13, "test60 case 20 failed\n");
5980 FAILED(supported[9] == SLJIT_SUCCESS && wbuf[17] != (sljit_sw)(bbuf), "test60 case 21 failed\n");
5982 sljit_free_code(code.code);
5983 successful_tests++;
5986 static void test61(void)
5988 /* Test float memory accesses with pre/post updates. */
5989 executable_code code;
5990 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
5991 sljit_s32 i;
5992 sljit_s32 supported[6];
5993 sljit_sw wbuf[6];
5994 sljit_f64 dbuf[4];
5995 sljit_f32 sbuf[4];
5996 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
5997 static sljit_u8 expected[6] = { 1, 1, 1, 1, 0, 0 };
5998 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
5999 static sljit_u8 expected[6] = { 1, 0, 1, 0, 1, 1 };
6000 #else
6001 static sljit_u8 expected[6] = { 0, 0, 0, 0, 0, 0 };
6002 #endif
6004 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
6005 if (verbose)
6006 printf("no fpu available, test61 skipped\n");
6007 successful_tests++;
6008 if (compiler)
6009 sljit_free_compiler(compiler);
6010 return;
6013 if (verbose)
6014 printf("Run test61\n");
6016 for (i = 0; i < 6; i++)
6017 wbuf[i] = 0;
6019 dbuf[0] = 66.725;
6020 dbuf[1] = 0.0;
6021 dbuf[2] = 0.0;
6022 dbuf[3] = 0.0;
6024 sbuf[0] = 0.0;
6025 sbuf[1] = -22.125;
6026 sbuf[2] = 0.0;
6027 sbuf[3] = 0.0;
6029 FAILED(!compiler, "cannot create compiler\n");
6031 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW) | SLJIT_ARG2(SW) | SLJIT_ARG3(SW), 4, 3, 4, 0, sizeof(sljit_sw));
6033 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));
6034 if (supported[0] == SLJIT_SUCCESS) {
6035 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_IMM, 4 * sizeof(sljit_f64));
6036 sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_PRE, SLJIT_FR0, SLJIT_MEM1(SLJIT_R0), 4 * sizeof(sljit_f64));
6037 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f64), SLJIT_FR0, 0);
6038 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
6041 supported[1] = sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_SUPP | SLJIT_MEM_STORE | SLJIT_MEM_POST, SLJIT_FR2, SLJIT_MEM1(SLJIT_R0), -sizeof(sljit_f64));
6042 if (supported[1] == SLJIT_SUCCESS) {
6043 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_IMM, 2 * sizeof(sljit_f64));
6044 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), 0);
6045 sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_STORE | SLJIT_MEM_POST, SLJIT_FR2, SLJIT_MEM1(SLJIT_R0), -sizeof(sljit_f64));
6046 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
6049 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 * sizeof(sljit_f32));
6050 if (supported[2] == SLJIT_SUCCESS) {
6051 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, 4 * sizeof(sljit_f32));
6052 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f32));
6053 sljit_emit_fmem(compiler, SLJIT_MOV_F32 | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_FR1, SLJIT_MEM1(SLJIT_R2), -4 * sizeof(sljit_f32));
6054 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R2, 0);
6057 supported[3] = sljit_emit_fmem(compiler, SLJIT_MOV_F32 | SLJIT_MEM_SUPP | SLJIT_MEM_POST, SLJIT_FR1, SLJIT_MEM1(SLJIT_R1), sizeof(sljit_f32));
6058 if (supported[3] == SLJIT_SUCCESS) {
6059 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S2, 0, SLJIT_IMM, sizeof(sljit_f32));
6060 sljit_emit_fmem(compiler, SLJIT_MOV_F32 | SLJIT_MEM_POST, SLJIT_FR1, SLJIT_MEM1(SLJIT_R1), sizeof(sljit_f32));
6061 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_f32), SLJIT_FR1, 0);
6062 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_R1, 0);
6065 supported[4] = sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_FR0, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 0);
6066 if (supported[4] == SLJIT_SUCCESS) {
6067 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S1, 0, SLJIT_IMM, 8 * sizeof(sljit_f64));
6068 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -8 * sizeof(sljit_f64));
6069 sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_PRE, SLJIT_FR0, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 0);
6070 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64), SLJIT_FR0, 0);
6071 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R1, 0);
6074 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);
6075 if (supported[5] == SLJIT_SUCCESS) {
6076 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_S2, 0);
6077 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 3 * sizeof(sljit_f32));
6078 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f32));
6079 sljit_emit_fmem(compiler, SLJIT_MOV_F32 | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_FR2, SLJIT_MEM2(SLJIT_R2, SLJIT_R1), 0);
6080 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R2, 0);
6083 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);
6084 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);
6086 sljit_emit_return(compiler, SLJIT_UNUSED, 0, 0);
6088 code.code = sljit_generate_code(compiler);
6089 CHECK(compiler);
6090 sljit_free_compiler(compiler);
6092 code.func3((sljit_sw)&wbuf, (sljit_sw)&dbuf, (sljit_sw)&sbuf);
6094 FAILED(sizeof(expected) != sizeof(supported) / sizeof(sljit_s32), "test61 case 1 failed\n");
6096 for (i = 0; i < sizeof(expected); i++) {
6097 if (expected[i]) {
6098 if (supported[i] != SLJIT_SUCCESS) {
6099 printf("tast61 case %d should be supported\n", i + 1);
6100 return;
6102 } else {
6103 if (supported[i] == SLJIT_SUCCESS) {
6104 printf("test61 case %d should not be supported\n", i + 1);
6105 return;
6110 FAILED(supported[0] == SLJIT_SUCCESS && dbuf[1] != 66.725, "test61 case 2 failed\n");
6111 FAILED(supported[0] == SLJIT_SUCCESS && wbuf[0] != (sljit_sw)(dbuf), "test61 case 3 failed\n");
6112 FAILED(supported[1] == SLJIT_SUCCESS && dbuf[2] != 66.725, "test61 case 4 failed\n");
6113 FAILED(supported[1] == SLJIT_SUCCESS && wbuf[1] != (sljit_sw)(dbuf + 1), "test61 case 5 failed\n");
6114 FAILED(supported[2] == SLJIT_SUCCESS && sbuf[0] != -22.125, "test61 case 6 failed\n");
6115 FAILED(supported[2] == SLJIT_SUCCESS && wbuf[2] != (sljit_sw)(sbuf), "test61 case 7 failed\n");
6116 FAILED(supported[3] == SLJIT_SUCCESS && sbuf[2] != -22.125, "test61 case 8 failed\n");
6117 FAILED(supported[3] == SLJIT_SUCCESS && wbuf[3] != (sljit_sw)(sbuf + 2), "test61 case 9 failed\n");
6118 FAILED(supported[4] == SLJIT_SUCCESS && dbuf[3] != 66.725, "test61 case 10 failed\n");
6119 FAILED(supported[4] == SLJIT_SUCCESS && wbuf[4] != (sljit_sw)(dbuf), "test61 case 11 failed\n");
6120 FAILED(supported[5] == SLJIT_SUCCESS && sbuf[3] != -22.125, "test61 case 12 failed\n");
6121 FAILED(supported[5] == SLJIT_SUCCESS && wbuf[5] != (sljit_sw)(sbuf + 3), "test61 case 13 failed\n");
6123 sljit_free_code(code.code);
6124 successful_tests++;
6127 static void test62(void)
6129 /* Test fast calls flag preservation. */
6130 executable_code code1;
6131 executable_code code2;
6132 struct sljit_compiler* compiler;
6134 if (verbose)
6135 printf("Run test62\n");
6137 /* A */
6138 compiler = sljit_create_compiler(NULL);
6139 FAILED(!compiler, "cannot create compiler\n");
6140 sljit_set_context(compiler, 0, SLJIT_ARG1(SW), 1, 1, 0, 0, 0);
6142 sljit_emit_fast_enter(compiler, SLJIT_R0, 0);
6143 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, SLJIT_UNUSED, 0, SLJIT_S0, 0, SLJIT_IMM, 42);
6144 sljit_emit_fast_return(compiler, SLJIT_R0, 0);
6146 code1.code = sljit_generate_code(compiler);
6147 CHECK(compiler);
6148 sljit_free_compiler(compiler);
6150 /* B */
6151 compiler = sljit_create_compiler(NULL);
6152 FAILED(!compiler, "cannot create compiler\n");
6154 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 1, 1, 0, 0, 0);
6155 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_OFFSET(code1.code));
6156 sljit_set_current_flags(compiler, SLJIT_SET_Z | SLJIT_SET_LESS);
6157 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_ZERO);
6158 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_LESS);
6159 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
6160 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S0, 0);
6161 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
6163 code2.code = sljit_generate_code(compiler);
6164 CHECK(compiler);
6165 sljit_free_compiler(compiler);
6167 FAILED(code2.func1(88) != 0, "test62 case 1 failed\n");
6168 FAILED(code2.func1(42) != 1, "test62 case 2 failed\n");
6169 FAILED(code2.func1(0) != 2, "test62 case 3 failed\n");
6171 sljit_free_code(code1.code);
6172 sljit_free_code(code2.code);
6173 successful_tests++;
6176 static void test63(void)
6178 /* Test put label. */
6179 executable_code code;
6180 struct sljit_label *label[2];
6181 struct sljit_put_label *put_label[5];
6182 struct sljit_compiler* compiler = sljit_create_compiler(NULL);
6183 sljit_uw addr[2];
6184 sljit_uw buf[4];
6185 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
6186 sljit_sw offs = SLJIT_W(0x123456789012);
6187 #else
6188 sljit_sw offs = 0x12345678;
6189 #endif
6191 if (verbose)
6192 printf("Run test63\n");
6194 FAILED(!compiler, "cannot create compiler\n");
6195 buf[0] = 0;
6196 buf[1] = 0;
6197 buf[2] = 0;
6198 buf[3] = 0;
6200 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 0, 0, 2 * sizeof(sljit_sw));
6202 put_label[0] = sljit_emit_put_label(compiler, SLJIT_R0, 0);
6203 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
6205 put_label[1] = sljit_emit_put_label(compiler, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw));
6206 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw));
6208 label[0] = sljit_emit_label(compiler);
6209 sljit_set_put_label(put_label[0], label[0]);
6210 sljit_set_put_label(put_label[1], label[0]);
6212 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)(buf + 2) - offs);
6213 put_label[2] = sljit_emit_put_label(compiler, SLJIT_MEM1(SLJIT_R0), offs);
6215 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (offs + sizeof(sljit_uw)) >> 1);
6216 put_label[3] = sljit_emit_put_label(compiler, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), 1);
6218 label[1] = sljit_emit_label(compiler);
6219 sljit_set_put_label(put_label[2], label[1]);
6220 sljit_set_put_label(put_label[3], label[1]);
6222 put_label[4] = sljit_emit_put_label(compiler, SLJIT_RETURN_REG, 0);
6223 sljit_set_put_label(put_label[4], label[0]);
6224 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
6226 code.code = sljit_generate_code(compiler);
6227 CHECK(compiler);
6229 addr[0] = sljit_get_label_addr(label[0]);
6230 addr[1] = sljit_get_label_addr(label[1]);
6232 sljit_free_compiler(compiler);
6234 FAILED(code.func1((sljit_sw)&buf) != addr[0], "test63 case 1 failed\n");
6235 FAILED(buf[0] != addr[0], "test63 case 2 failed\n");
6236 FAILED(buf[1] != addr[0], "test63 case 3 failed\n");
6237 FAILED(buf[2] != addr[1], "test63 case 4 failed\n");
6238 FAILED(buf[3] != addr[1], "test63 case 4 failed\n");
6240 sljit_free_code(code.code);
6241 successful_tests++;
6244 static void test64(void)
6246 /* Test put label with false labels (small offsets).
6247 This code is allocator implementation dependent. */
6248 executable_code code;
6249 sljit_sw malloc_addr;
6250 struct sljit_label label[2];
6251 struct sljit_put_label *put_label[5];
6252 struct sljit_compiler* compiler;
6253 sljit_uw buf[4];
6254 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
6255 sljit_sw offs = SLJIT_W(0x123456789012);
6256 #else
6257 sljit_sw offs = 0x12345678;
6258 #endif
6260 if (verbose)
6261 printf("Run test64\n");
6263 malloc_addr = (sljit_sw)SLJIT_MALLOC_EXEC(1024);
6265 if (malloc_addr == 0) {
6266 printf("Cannot allocate executable memory.");
6267 return;
6270 malloc_addr += SLJIT_EXEC_OFFSET((void*)malloc_addr);
6272 SLJIT_FREE_EXEC((void*)malloc_addr);
6274 label[0].addr = 512;
6275 label[0].size = (sljit_uw)(512 - malloc_addr);
6277 label[1].addr = 0x123456;
6278 label[1].size = (sljit_uw)(0x123456 - malloc_addr);
6280 compiler = sljit_create_compiler(NULL);
6282 FAILED(!compiler, "cannot create compiler\n");
6283 buf[0] = 0;
6284 buf[1] = 0;
6285 buf[2] = 0;
6286 buf[3] = 0;
6288 sljit_emit_enter(compiler, 0, SLJIT_ARG1(SW), 3, 1, 0, 0, 2 * sizeof(sljit_sw));
6290 put_label[0] = sljit_emit_put_label(compiler, SLJIT_R0, 0);
6291 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
6293 put_label[1] = sljit_emit_put_label(compiler, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw));
6294 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw));
6296 sljit_set_put_label(put_label[0], &label[0]);
6297 sljit_set_put_label(put_label[1], &label[0]);
6299 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)(buf + 2) - offs);
6300 put_label[2] = sljit_emit_put_label(compiler, SLJIT_MEM1(SLJIT_R0), offs);
6302 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (offs + sizeof(sljit_uw)) >> 1);
6303 put_label[3] = sljit_emit_put_label(compiler, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), 1);
6305 sljit_set_put_label(put_label[2], &label[1]);
6306 sljit_set_put_label(put_label[3], &label[1]);
6308 put_label[4] = sljit_emit_put_label(compiler, SLJIT_RETURN_REG, 0);
6309 sljit_set_put_label(put_label[4], &label[0]);
6310 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
6312 code.code = sljit_generate_code(compiler);
6313 CHECK(compiler);
6314 sljit_free_compiler(compiler);
6316 if ((sljit_sw)code.code < malloc_addr || (sljit_sw)code.code >= malloc_addr + 1024) {
6317 printf("test64 executable alloc estimation failed\n");
6318 return;
6321 FAILED(code.func1((sljit_sw)&buf) != label[0].addr, "test63 case 1 failed\n");
6322 FAILED(buf[0] != label[0].addr, "test64 case 2 failed\n");
6323 FAILED(buf[1] != label[0].addr, "test64 case 3 failed\n");
6324 FAILED(buf[2] != label[1].addr, "test64 case 4 failed\n");
6325 FAILED(buf[3] != label[1].addr, "test64 case 4 failed\n");
6327 sljit_free_code(code.code);
6328 successful_tests++;
6331 void sljit_test(int argc, char* argv[])
6333 sljit_s32 has_arg = (argc >= 2 && argv[1][0] == '-' && argv[1][2] == '\0');
6334 verbose = has_arg && argv[1][1] == 'v';
6335 silent = has_arg && argv[1][1] == 's';
6337 if (!verbose && !silent)
6338 printf("Pass -v to enable verbose, -s to disable this hint.\n\n");
6340 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
6341 test_exec_allocator();
6342 #endif
6343 test1();
6344 test2();
6345 test3();
6346 test4();
6347 test5();
6348 test6();
6349 test7();
6350 test8();
6351 test9();
6352 test10();
6353 test11();
6354 test12();
6355 test13();
6356 test14();
6357 test15();
6358 test16();
6359 test17();
6360 test18();
6361 test19();
6362 test20();
6363 test21();
6364 test22();
6365 test23();
6366 test24();
6367 test25();
6368 test26();
6369 test27();
6370 test28();
6371 test29();
6372 test30();
6373 test31();
6374 test32();
6375 test33();
6376 test34();
6377 test35();
6378 test36();
6379 test37();
6380 test38();
6381 test39();
6382 test40();
6383 test41();
6384 test42();
6385 test43();
6386 test44();
6387 test45();
6388 test46();
6389 test47();
6390 test48();
6391 test49();
6392 test50();
6393 test51();
6394 test52();
6395 test53();
6396 test54();
6397 test55();
6398 test56();
6399 test57();
6400 test58();
6401 test59();
6402 test60();
6403 test61();
6404 test62();
6405 test63();
6406 test64();
6408 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
6409 sljit_free_unused_memory_exec();
6410 #endif
6412 # define TEST_COUNT 64
6414 printf("SLJIT tests: ");
6415 if (successful_tests == TEST_COUNT)
6416 printf("all tests are " COLOR_GREEN "PASSED" COLOR_DEFAULT " ");
6417 else
6418 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);
6419 printf("on " COLOR_ARCH "%s" COLOR_DEFAULT "%s\n", sljit_get_platform_name(), sljit_has_cpu_feature(SLJIT_HAS_FPU) ? " (with fpu)" : " (without fpu)");
6421 # undef TEST_COUNT