Reduce value conversion warnings on s390x.
[sljit.git] / test_src / sljitTest.c
blob82e66657c84b401b31e370d0ccb528ecbf36cd3d
1 /*
2 * Stack-less Just-In-Time compiler
4 * Copyright Zoltan Herczeg (hzmester@freemail.hu). All rights reserved.
6 * Redistribution and use in source and binary forms, with or without modification, are
7 * permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright notice, this list of
10 * conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 * of conditions and the following disclaimer in the documentation and/or other materials
14 * provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 /* Must be the first one. Must not depend on any other include. */
28 #include "sljitLir.h"
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
34 #ifdef _MSC_VER
35 #pragma warning(push)
36 #pragma warning(disable: 4127) /* conditional expression is constant */
37 #endif
39 #if defined _WIN32 || defined _WIN64
40 #define COLOR_RED
41 #define COLOR_GREEN
42 #define COLOR_ARCH
43 #define COLOR_DEFAULT
44 #else
45 #define COLOR_RED "\33[31m"
46 #define COLOR_GREEN "\33[32m"
47 #define COLOR_ARCH "\33[33m"
48 #define COLOR_DEFAULT "\33[0m"
49 #endif
51 union executable_code {
52 void* code;
53 sljit_sw (SLJIT_FUNC *func0)(void);
54 sljit_sw (SLJIT_FUNC *func1)(sljit_sw a);
55 sljit_sw (SLJIT_FUNC *func2)(sljit_sw a, sljit_sw b);
56 sljit_sw (SLJIT_FUNC *func3)(sljit_sw a, sljit_sw b, sljit_sw c);
58 void (SLJIT_FUNC *test70_f1)(sljit_s32 a, sljit_uw b, sljit_u32 c, sljit_sw d);
59 void (SLJIT_FUNC *test70_f2)(sljit_s32 a, sljit_u32 b, sljit_sw c, sljit_sw d);
60 void (SLJIT_FUNC *test70_f3)(sljit_s32 a, sljit_f32 b, sljit_uw c, sljit_f64 d);
61 void (SLJIT_FUNC *test70_f4)(sljit_f32 a, sljit_f64 b, sljit_f32 c, sljit_s32 d);
62 void (SLJIT_FUNC *test70_f5)(sljit_f64 a, sljit_f32 b, sljit_u32 c, sljit_f32 d);
63 void (SLJIT_FUNC *test70_f6)(sljit_f64 a, sljit_s32 b, sljit_f32 c, sljit_f64 d);
64 void (SLJIT_FUNC *test70_f7)(sljit_f32 a, sljit_s32 b, sljit_uw c, sljit_u32 d);
65 void (SLJIT_FUNC *test70_f8)(sljit_f64 a, sljit_f64 b, sljit_uw c, sljit_sw d);
66 void (SLJIT_FUNC *test70_f9)(sljit_f64 a, sljit_f64 b, sljit_uw c, sljit_f64 d);
67 void (SLJIT_FUNC *test70_f10)(sljit_f64 a, sljit_f64 b, sljit_f64 c, sljit_s32 d);
69 sljit_sw (SLJIT_FUNC *test71_f1)(sljit_f64 a, sljit_f64 b, sljit_f64 c, sljit_f64 d);
71 typedef union executable_code executable_code;
73 static sljit_s32 successful_tests = 0;
74 static sljit_s32 verbose = 0;
75 static sljit_s32 silent = 0;
77 #define FAILED(cond, text) \
78 if (SLJIT_UNLIKELY(cond)) { \
79 printf(text); \
80 return; \
83 #define CHECK(compiler) \
84 if (sljit_get_compiler_error(compiler) != SLJIT_ERR_COMPILED) { \
85 printf("Compiler error: %d\n", sljit_get_compiler_error(compiler)); \
86 sljit_free_compiler(compiler); \
87 return; \
90 static void cond_set(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_s32 type)
92 /* Testing both sljit_emit_op_flags and sljit_emit_jump. */
93 struct sljit_jump* jump;
94 struct sljit_label* label;
96 sljit_emit_op_flags(compiler, SLJIT_MOV, dst, dstw, type);
97 jump = sljit_emit_jump(compiler, type);
98 sljit_emit_op2(compiler, SLJIT_ADD, dst, dstw, dst, dstw, SLJIT_IMM, 2);
99 label = sljit_emit_label(compiler);
100 sljit_set_label(jump, label);
103 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
105 /* For interface testing and for test64. */
106 void *sljit_test_malloc_exec(sljit_uw size, void *exec_allocator_data)
108 if (exec_allocator_data)
109 return exec_allocator_data;
111 return SLJIT_BUILTIN_MALLOC_EXEC(size, exec_allocator_data);
114 /* For interface testing. */
115 void sljit_test_free_code(void* code, void *exec_allocator_data)
117 SLJIT_BUILTIN_FREE_EXEC(code, exec_allocator_data);
120 #define MALLOC_EXEC(result, size) \
121 result = SLJIT_MALLOC_EXEC(size, NULL); \
122 if (!result) { \
123 printf("Cannot allocate executable memory\n"); \
124 return; \
126 memset(result, 255, size);
128 #define FREE_EXEC(ptr) \
129 SLJIT_FREE_EXEC(((sljit_u8*)(ptr)) + SLJIT_EXEC_OFFSET(ptr), NULL);
131 static void test_exec_allocator(void)
133 /* This is not an sljit test. */
134 void *ptr1;
135 void *ptr2;
136 void *ptr3;
138 if (verbose)
139 printf("Run executable allocator test\n");
141 MALLOC_EXEC(ptr1, 32);
142 MALLOC_EXEC(ptr2, 512);
143 MALLOC_EXEC(ptr3, 512);
144 FREE_EXEC(ptr2);
145 FREE_EXEC(ptr3);
146 FREE_EXEC(ptr1);
147 MALLOC_EXEC(ptr1, 262104);
148 MALLOC_EXEC(ptr2, 32000);
149 FREE_EXEC(ptr1);
150 MALLOC_EXEC(ptr1, 262104);
151 FREE_EXEC(ptr1);
152 FREE_EXEC(ptr2);
153 MALLOC_EXEC(ptr1, 512);
154 MALLOC_EXEC(ptr2, 512);
155 MALLOC_EXEC(ptr3, 512);
156 FREE_EXEC(ptr2);
157 MALLOC_EXEC(ptr2, 512);
158 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
159 sljit_free_unused_memory_exec();
160 #endif
161 FREE_EXEC(ptr3);
162 FREE_EXEC(ptr1);
163 FREE_EXEC(ptr2);
165 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
166 sljit_free_unused_memory_exec();
167 #endif
170 #undef MALLOC_EXEC
172 #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
174 static void test1(void)
176 /* Enter and return from an sljit function. */
177 executable_code code;
178 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
180 if (verbose)
181 printf("Run test1\n");
183 FAILED(!compiler, "cannot create compiler\n");
185 /* 3 arguments passed, 3 arguments used. */
186 sljit_emit_enter(compiler, 0, SLJIT_ARGS3(W, W, W, W), 3, 3, 0, 0, 0);
187 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_S1, 0);
189 SLJIT_ASSERT(sljit_get_generated_code_size(compiler) == 0);
190 code.code = sljit_generate_code(compiler);
191 CHECK(compiler);
192 SLJIT_ASSERT(compiler->error == SLJIT_ERR_COMPILED);
193 SLJIT_ASSERT(sljit_get_generated_code_size(compiler) > 0);
194 sljit_free_compiler(compiler);
196 FAILED(code.func3(3, -21, 86) != -21, "test1 case 1 failed\n");
197 FAILED(code.func3(4789, 47890, 997) != 47890, "test1 case 2 failed\n");
199 sljit_free_code(code.code, NULL);
200 successful_tests++;
203 static void test2(void)
205 /* Test mov. */
206 executable_code code;
207 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
208 sljit_sw buf[8];
209 static sljit_sw data[2] = { 0, -9876 };
211 if (verbose)
212 printf("Run test2\n");
214 FAILED(!compiler, "cannot create compiler\n");
216 buf[0] = 5678;
217 buf[1] = 0;
218 buf[2] = 0;
219 buf[3] = 0;
220 buf[4] = 0;
221 buf[5] = 0;
222 buf[6] = 0;
223 buf[7] = 0;
224 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 2, 0, 0, 0);
225 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 9999);
226 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_S0, 0);
227 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_sw), SLJIT_R0, 0);
228 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
229 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM2(SLJIT_S1, SLJIT_R1), 0);
230 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, 2);
231 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_S1, SLJIT_S0), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_S1, SLJIT_R1), 0);
232 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, 3);
233 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_S1, SLJIT_S0), SLJIT_WORD_SHIFT, SLJIT_MEM0(), (sljit_sw)&buf);
234 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw));
235 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R0), (sljit_sw)&data);
236 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
237 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf - 0x12345678);
238 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R0), 0x12345678);
239 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_sw), SLJIT_R0, 0);
240 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 3456);
241 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&buf - 0xff890 + 6 * (sljit_sw)sizeof(sljit_sw));
242 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 0xff890, SLJIT_R0, 0);
243 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&buf + 0xff890 + 7 * (sljit_sw)sizeof(sljit_sw));
244 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), -0xff890, SLJIT_R0, 0);
245 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R2, 0);
247 code.code = sljit_generate_code(compiler);
248 CHECK(compiler);
249 sljit_free_compiler(compiler);
251 FAILED(code.func1((sljit_sw)&buf) != 9999, "test2 case 1 failed\n");
252 FAILED(buf[1] != 9999, "test2 case 2 failed\n");
253 FAILED(buf[2] != 9999, "test2 case 3 failed\n");
254 FAILED(buf[3] != 5678, "test2 case 4 failed\n");
255 FAILED(buf[4] != -9876, "test2 case 5 failed\n");
256 FAILED(buf[5] != 5678, "test2 case 6 failed\n");
257 FAILED(buf[6] != 3456, "test2 case 6 failed\n");
258 FAILED(buf[7] != 3456, "test2 case 6 failed\n");
260 sljit_free_code(code.code, NULL);
261 successful_tests++;
264 static void test3(void)
266 /* Test not. */
267 executable_code code;
268 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
269 sljit_sw buf[5];
271 if (verbose)
272 printf("Run test3\n");
274 FAILED(!compiler, "cannot create compiler\n");
275 buf[0] = 1234;
276 buf[1] = 0;
277 buf[2] = 9876;
278 buf[3] = 0;
279 buf[4] = 0x12345678;
281 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 1, 0, 0, 0);
282 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 0);
283 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM0(), (sljit_sw)&buf[1], SLJIT_MEM0(), (sljit_sw)&buf[1]);
284 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_S0), 0);
285 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2);
286 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&buf[4] - 0xff0000 - 0x20);
287 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, (sljit_sw)&buf[4] - 0xff0000);
288 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM1(SLJIT_R1), 0xff0000 + 0x20, SLJIT_MEM1(SLJIT_R2), 0xff0000);
289 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
291 code.code = sljit_generate_code(compiler);
292 CHECK(compiler);
293 sljit_free_compiler(compiler);
295 FAILED(code.func1((sljit_sw)&buf) != ~1234, "test3 case 1 failed\n");
296 FAILED(buf[1] != ~1234, "test3 case 2 failed\n");
297 FAILED(buf[3] != ~9876, "test3 case 3 failed\n");
298 FAILED(buf[4] != ~0x12345678, "test3 case 4 failed\n");
300 sljit_free_code(code.code, NULL);
301 successful_tests++;
304 static void test4(void)
306 /* Test neg. */
307 executable_code code;
308 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
309 sljit_sw buf[4];
311 if (verbose)
312 printf("Run test4\n");
314 FAILED(!compiler, "cannot create compiler\n");
315 buf[0] = 0;
316 buf[1] = 1234;
317 buf[2] = 0;
318 buf[3] = 0;
320 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(W, P, W), 3, 2, 0, 0, 0);
321 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_S1, 0);
322 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM0(), (sljit_sw)&buf[0], SLJIT_MEM0(), (sljit_sw)&buf[1]);
323 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 299);
324 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_R1, 0);
325 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_RETURN_REG, 0, SLJIT_S1, 0);
326 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
328 code.code = sljit_generate_code(compiler);
329 CHECK(compiler);
330 sljit_free_compiler(compiler);
332 FAILED(code.func2((sljit_sw)&buf, 4567) != -4567, "test4 case 1 failed\n");
333 FAILED(buf[0] != -1234, "test4 case 2 failed\n");
334 FAILED(buf[2] != -4567, "test4 case 3 failed\n");
335 FAILED(buf[3] != -299, "test4 case 4 failed\n");
337 sljit_free_code(code.code, NULL);
338 successful_tests++;
341 static void test5(void)
343 /* Test add. */
344 executable_code code;
345 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
346 sljit_sw buf[9];
348 if (verbose)
349 printf("Run test5\n");
351 FAILED(!compiler, "cannot create compiler\n");
352 buf[0] = 100;
353 buf[1] = 200;
354 buf[2] = 300;
355 buf[3] = 0;
356 buf[4] = 0;
357 buf[5] = 0;
358 buf[6] = 0;
359 buf[7] = 0;
360 buf[8] = 313;
362 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 2, 0, 0, 0);
363 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw));
364 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 50);
365 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);
366 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw) + 2);
367 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 50);
368 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 0);
369 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
370 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_IMM, 4, SLJIT_R0, 0);
371 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_IMM, 50, SLJIT_R1, 0);
372 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));
373 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R1, 0);
374 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));
375 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));
376 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);
377 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x1e7d39f2);
378 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_R1, 0, SLJIT_IMM, 0x23de7c06);
379 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_IMM, 0x3d72e452, SLJIT_R1, 0);
380 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));
381 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_IMM, 1000, SLJIT_R0, 0);
382 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 1430);
383 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_IMM, -99, SLJIT_R0, 0);
385 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
387 code.code = sljit_generate_code(compiler);
388 CHECK(compiler);
389 sljit_free_compiler(compiler);
391 FAILED(code.func1((sljit_sw)&buf) != 2437 + 2 * sizeof(sljit_sw), "test5 case 1 failed\n");
392 FAILED(buf[0] != 202 + 2 * sizeof(sljit_sw), "test5 case 2 failed\n");
393 FAILED(buf[2] != 500, "test5 case 3 failed\n");
394 FAILED(buf[3] != 400, "test5 case 4 failed\n");
395 FAILED(buf[4] != 200, "test5 case 5 failed\n");
396 FAILED(buf[5] != 250, "test5 case 6 failed\n");
397 FAILED(buf[6] != 0x425bb5f8, "test5 case 7 failed\n");
398 FAILED(buf[7] != 0x5bf01e44, "test5 case 8 failed\n");
399 FAILED(buf[8] != 270, "test5 case 9 failed\n");
401 sljit_free_code(code.code, NULL);
402 successful_tests++;
405 static void test6(void)
407 /* Test addc, sub, subc. */
408 executable_code code;
409 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
410 sljit_sw buf[11];
412 if (verbose)
413 printf("Run test6\n");
415 FAILED(!compiler, "cannot create compiler\n");
416 buf[0] = 0;
417 buf[1] = 0;
418 buf[2] = 0;
419 buf[3] = 0;
420 buf[4] = 0;
421 buf[5] = 0;
422 buf[6] = 0;
423 buf[7] = 0;
424 buf[8] = 0;
425 buf[9] = 0;
426 buf[10] = 4000;
428 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 1, 0, 0, 0);
429 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
430 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, -1);
431 sljit_emit_op2(compiler, SLJIT_ADDC, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0, SLJIT_IMM, 0);
432 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R0, 0);
433 sljit_emit_op2(compiler, SLJIT_ADDC, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, 4);
434 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 100);
435 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0, SLJIT_IMM, 50);
436 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 6000);
437 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_IMM, 10);
438 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);
439 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 100);
440 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2);
441 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R0, 0);
442 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 5000);
443 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R0, 0);
444 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_R1, 0);
445 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_R1, 0);
446 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 5000);
447 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_IMM, 6000, SLJIT_R0, 0);
448 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_R0, 0);
449 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 100);
450 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 32768);
451 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_R1, 0);
452 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -32767);
453 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_R1, 0);
454 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x52cd3bf4);
455 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 9, SLJIT_R0, 0, SLJIT_IMM, 0x3da297c6);
456 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 6000);
457 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 10, SLJIT_R1, 0);
458 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 10, SLJIT_R1, 0);
459 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 10);
460 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_CARRY, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 5);
461 sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 2);
462 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, -2220);
463 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
465 code.code = sljit_generate_code(compiler);
466 CHECK(compiler);
467 sljit_free_compiler(compiler);
469 FAILED(code.func1((sljit_sw)&buf) != 2223, "test6 case 1 failed\n");
470 FAILED(buf[0] != 1, "test6 case 2 failed\n");
471 FAILED(buf[1] != 5, "test6 case 3 failed\n");
472 FAILED(buf[2] != 50, "test6 case 4 failed\n");
473 FAILED(buf[3] != 4, "test6 case 5 failed\n");
474 FAILED(buf[4] != 50, "test6 case 6 failed\n");
475 FAILED(buf[5] != 50, "test6 case 7 failed\n");
476 FAILED(buf[6] != 1000, "test6 case 8 failed\n");
477 FAILED(buf[7] != 100 - 32768, "test6 case 9 failed\n");
478 FAILED(buf[8] != 100 + 32767, "test6 case 10 failed\n");
479 FAILED(buf[9] != 0x152aa42e, "test6 case 11 failed\n");
480 FAILED(buf[10] != -2000, "test6 case 12 failed\n");
482 sljit_free_code(code.code, NULL);
483 successful_tests++;
486 static void test7(void)
488 /* Test logical operators. */
489 executable_code code;
490 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
491 sljit_sw buf[8];
493 if (verbose)
494 printf("Run test7\n");
496 FAILED(!compiler, "cannot create compiler\n");
497 buf[0] = 0xff80;
498 buf[1] = 0x0f808080;
499 buf[2] = 0;
500 buf[3] = 0xaaaaaa;
501 buf[4] = 0;
502 buf[5] = 0x4040;
503 buf[6] = 0;
504 buf[7] = (sljit_sw)0xc43a7f95;
506 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 1, 0, 0, 0);
507 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xf0C000);
508 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0, SLJIT_IMM, 0x308f);
509 sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw));
510 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);
511 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xC0F0);
512 sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5);
513 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xff0000);
514 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R0, 0);
515 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 0xC0F0);
516 sljit_emit_op2(compiler, SLJIT_AND, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5);
517 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_R2, 0, SLJIT_IMM, 0xff0000);
518 sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, 0xFFFFFF, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw));
519 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_IMM, (sljit_sw)0xa56c82c0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6);
520 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7);
521 sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_IMM, (sljit_sw)0xff00ff00, SLJIT_R0, 0);
522 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)0xff00ff00);
523 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 0x0f);
524 sljit_emit_op2(compiler, SLJIT_AND, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0x888888, SLJIT_R1, 0);
525 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
527 code.code = sljit_generate_code(compiler);
528 CHECK(compiler);
529 sljit_free_compiler(compiler);
531 FAILED(code.func1((sljit_sw)&buf) != 0x8808, "test7 case 1 failed\n");
532 FAILED(buf[0] != 0x0F807F00, "test7 case 2 failed\n");
533 FAILED(buf[1] != 0x0F7F7F7F, "test7 case 3 failed\n");
534 FAILED(buf[2] != 0x00F0F08F, "test7 case 4 failed\n");
535 FAILED(buf[3] != 0x00A0A0A0, "test7 case 5 failed\n");
536 FAILED(buf[4] != 0x00FF80B0, "test7 case 6 failed\n");
537 FAILED(buf[5] != 0x00FF4040, "test7 case 7 failed\n");
538 FAILED(buf[6] != 0xa56c82c0, "test7 case 8 failed\n");
539 FAILED(buf[7] != 0x3b3a8095, "test7 case 9 failed\n");
541 sljit_free_code(code.code, NULL);
542 successful_tests++;
545 static void test8(void)
547 /* Test flags (neg, cmp, test). */
548 executable_code code;
549 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
550 sljit_sw buf[13];
552 if (verbose)
553 printf("Run test8\n");
555 FAILED(!compiler, "cannot create compiler\n");
556 buf[0] = 100;
557 buf[1] = 3;
558 buf[2] = 3;
559 buf[3] = 3;
560 buf[4] = 3;
561 buf[5] = 3;
562 buf[6] = 3;
563 buf[7] = 3;
564 buf[8] = 3;
565 buf[9] = 3;
566 buf[10] = 3;
567 buf[11] = 3;
568 buf[12] = 3;
570 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 3, 2, 0, 0, 0);
571 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 20);
572 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 10);
573 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_IMM, 6, SLJIT_IMM, 5);
574 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_NOT_EQUAL);
575 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_EQUAL);
576 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_R0, 0, SLJIT_IMM, 3000);
577 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_GREATER);
578 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_R0, 0, SLJIT_IMM, 3000);
579 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_S1, 0);
580 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_LESS);
581 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R2, 0);
582 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_R0, 0, SLJIT_IMM, -15);
583 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_SIG_GREATER);
584 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_R2, 0);
585 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -(sljit_sw)(~(sljit_uw)0 >> 1) - 1);
586 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R1, 0);
587 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
588 sljit_emit_op1(compiler, SLJIT_NEG | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_R0, 0);
589 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_OVERFLOW);
590 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
591 sljit_emit_op1(compiler, SLJIT_NOT | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_R0, 0);
592 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_ZERO);
593 sljit_emit_op1(compiler, SLJIT_NOT | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R1, 0);
594 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_ZERO);
595 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_IMM, 0xffff, SLJIT_R0, 0);
596 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_IMM, 0xffff);
597 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 9, SLJIT_NOT_ZERO);
598 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_IMM, 0xffff, SLJIT_R1, 0);
599 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_IMM, 0xffff);
600 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R1, 0);
601 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), 0);
602 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0);
603 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0x1);
604 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 10, SLJIT_NOT_ZERO);
605 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -(sljit_sw)(~(sljit_uw)0 >> 1) - 1);
606 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
607 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_R0, 0);
608 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 11, SLJIT_OVERFLOW);
609 sljit_emit_op2u(compiler, SLJIT_ADD | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_R0, 0);
610 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 12, SLJIT_OVERFLOW);
611 sljit_emit_return_void(compiler);
613 code.code = sljit_generate_code(compiler);
614 CHECK(compiler);
615 sljit_free_compiler(compiler);
617 code.func1((sljit_sw)&buf);
618 FAILED(buf[1] != 1, "test8 case 1 failed\n");
619 FAILED(buf[2] != 0, "test8 case 2 failed\n");
620 FAILED(buf[3] != 0, "test8 case 3 failed\n");
621 FAILED(buf[4] != 1, "test8 case 4 failed\n");
622 FAILED(buf[5] != 1, "test8 case 5 failed\n");
623 FAILED(buf[6] != 1, "test8 case 6 failed\n");
624 FAILED(buf[7] != 1, "test8 case 7 failed\n");
625 FAILED(buf[8] != 0, "test8 case 8 failed\n");
626 FAILED(buf[9] != 1, "test8 case 9 failed\n");
627 FAILED(buf[10] != 0, "test8 case 10 failed\n");
628 FAILED(buf[11] != 1, "test8 case 11 failed\n");
629 FAILED(buf[12] != 0, "test8 case 12 failed\n");
631 sljit_free_code(code.code, NULL);
632 successful_tests++;
635 static void test9(void)
637 /* Test shift. */
638 executable_code code;
639 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
640 sljit_sw buf[13];
641 #ifdef SLJIT_PREF_SHIFT_REG
642 sljit_s32 shift_reg = SLJIT_PREF_SHIFT_REG;
643 #else
644 sljit_s32 shift_reg = SLJIT_R2;
645 #endif
647 SLJIT_ASSERT(shift_reg >= SLJIT_R2 && shift_reg <= SLJIT_R3);
649 if (verbose)
650 printf("Run test9\n");
652 FAILED(!compiler, "cannot create compiler\n");
653 buf[0] = 0;
654 buf[1] = 0;
655 buf[2] = 0;
656 buf[3] = 0;
657 buf[4] = 1 << 10;
658 buf[5] = 0;
659 buf[6] = 0;
660 buf[7] = 0;
661 buf[8] = 0;
662 buf[9] = 3;
663 buf[10] = 0;
664 buf[11] = 0;
665 buf[12] = 0;
667 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 4, 2, 0, 0, 0);
668 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xf);
669 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 3);
670 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
671 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
672 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
673 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R1, 0, SLJIT_IMM, 1);
674 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -64);
675 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 2);
676 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0, shift_reg, 0);
678 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 0xff);
679 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4);
680 sljit_emit_op2(compiler, SLJIT_SHL, shift_reg, 0, shift_reg, 0, SLJIT_R0, 0);
681 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, shift_reg, 0);
682 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 0xff);
683 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
684 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);
685 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, shift_reg, 0, SLJIT_R0, 0);
687 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, 0xf);
688 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
689 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_R0, 0);
690 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_S1, 0);
691 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_R0, 0);
692 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_R0, 0);
693 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 0xf00);
694 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4);
695 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_R1, 0, SLJIT_R2, 0, SLJIT_R0, 0);
696 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_R1, 0);
698 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)buf);
699 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 9);
700 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);
702 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 4);
703 sljit_emit_op2(compiler, SLJIT_SHL, shift_reg, 0, SLJIT_IMM, 2, shift_reg, 0);
704 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 10, shift_reg, 0);
706 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xa9);
707 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 0);
708 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x7d00);
709 sljit_emit_op2(compiler, SLJIT_LSHR32, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 32);
710 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
711 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
712 #endif
713 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_R0, 0);
714 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xe30000);
715 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
716 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffc0);
717 #else
718 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffe0);
719 #endif
720 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_R0, 0);
721 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x25000000);
722 sljit_emit_op2(compiler, SLJIT_SHL32, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xfffe1);
723 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
724 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
725 #endif
726 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 11, SLJIT_R1, 0, SLJIT_R0, 0);
728 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 0);
729 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x5c);
730 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R1, 0, SLJIT_R0, 0, shift_reg, 0);
731 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0xf600);
732 sljit_emit_op2(compiler, SLJIT_LSHR32, SLJIT_R0, 0, SLJIT_R0, 0, shift_reg, 0);
733 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
734 /* Alternative form of uint32 type cast. */
735 sljit_emit_op2(compiler, SLJIT_AND, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffffffff);
736 #endif
737 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_R0, 0);
738 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x630000);
739 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_R0, 0, SLJIT_R0, 0, shift_reg, 0);
740 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 12, SLJIT_R1, 0, SLJIT_R0, 0);
742 sljit_emit_return_void(compiler);
744 code.code = sljit_generate_code(compiler);
745 CHECK(compiler);
746 sljit_free_compiler(compiler);
748 code.func1((sljit_sw)&buf);
749 FAILED(buf[0] != 0x3c, "test9 case 1 failed\n");
750 FAILED(buf[1] != 0xf0, "test9 case 2 failed\n");
751 FAILED(buf[2] != -16, "test9 case 3 failed\n");
752 FAILED(buf[3] != 0xff0, "test9 case 4 failed\n");
753 FAILED(buf[4] != 4, "test9 case 5 failed\n");
754 FAILED(buf[5] != 0xff00, "test9 case 6 failed\n");
755 FAILED(buf[6] != 0x3c, "test9 case 7 failed\n");
756 FAILED(buf[7] != 0xf0, "test9 case 8 failed\n");
757 FAILED(buf[8] != 0xf0, "test9 case 9 failed\n");
758 FAILED(buf[9] != 0x18, "test9 case 10 failed\n");
759 FAILED(buf[10] != 32, "test9 case 11 failed\n");
760 FAILED(buf[11] != 0x4ae37da9, "test9 case 12 failed\n");
761 FAILED(buf[12] != 0x63f65c, "test9 case 13 failed\n");
763 sljit_free_code(code.code, NULL);
764 successful_tests++;
767 static void test10(void)
769 /* Test multiplications. */
770 executable_code code;
771 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
772 sljit_sw buf[7];
774 if (verbose)
775 printf("Run test10\n");
777 FAILED(!compiler, "cannot create compiler\n");
778 buf[0] = 3;
779 buf[1] = 0;
780 buf[2] = 0;
781 buf[3] = 6;
782 buf[4] = -10;
783 buf[5] = 0;
784 buf[6] = 0;
786 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 1, 0, 0, 0);
787 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 5);
788 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
789 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
790 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 7);
791 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_R2, 0, SLJIT_IMM, 8);
792 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
793 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_IMM, -3, SLJIT_IMM, -4);
794 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0);
795 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -2);
796 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);
797 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw) / 2);
798 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&buf[3]);
799 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);
800 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 9);
801 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R0, 0);
802 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_R0, 0);
803 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
804 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 3);
805 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x123456789));
806 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_R0, 0);
807 #endif
808 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 11, SLJIT_IMM, 10);
809 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
811 code.code = sljit_generate_code(compiler);
812 CHECK(compiler);
813 sljit_free_compiler(compiler);
815 FAILED(code.func1((sljit_sw)&buf) != 110, "test10 case 1 failed\n");
816 FAILED(buf[0] != 15, "test10 case 2 failed\n");
817 FAILED(buf[1] != 56, "test10 case 3 failed\n");
818 FAILED(buf[2] != 12, "test10 case 4 failed\n");
819 FAILED(buf[3] != -12, "test10 case 5 failed\n");
820 FAILED(buf[4] != 100, "test10 case 6 failed\n");
821 FAILED(buf[5] != 81, "test10 case 7 failed\n");
822 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
823 FAILED(buf[6] != SLJIT_W(0x123456789) * 3, "test10 case 8 failed\n");
824 #endif
826 sljit_free_code(code.code, NULL);
827 successful_tests++;
830 static void test11(void)
832 /* Test rewritable constants. */
833 executable_code code;
834 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
835 struct sljit_const* const1;
836 struct sljit_const* const2;
837 struct sljit_const* const3;
838 struct sljit_const* const4;
839 void* value;
840 sljit_sw executable_offset;
841 sljit_uw const1_addr;
842 sljit_uw const2_addr;
843 sljit_uw const3_addr;
844 sljit_uw const4_addr;
845 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
846 sljit_sw word_value1 = (sljit_sw)SLJIT_W(0xaaaaaaaaaaaaaaaa);
847 sljit_sw word_value2 = (sljit_sw)SLJIT_W(0xfee1deadfbadf00d);
848 #else
849 sljit_sw word_value1 = (sljit_sw)0xaaaaaaaal;
850 sljit_sw word_value2 = (sljit_sw)0xfbadf00dl;
851 #endif
852 sljit_sw buf[3];
854 if (verbose)
855 printf("Run test11\n");
857 FAILED(!compiler, "cannot create compiler\n");
858 buf[0] = 0;
859 buf[1] = 0;
860 buf[2] = 0;
862 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 1, 0, 0, 0);
864 SLJIT_ASSERT(!sljit_alloc_memory(compiler, 0));
865 SLJIT_ASSERT(!sljit_alloc_memory(compiler, 16 * sizeof(sljit_sw) + 1));
867 const1 = sljit_emit_const(compiler, SLJIT_MEM0(), (sljit_sw)&buf[0], -0x81b9);
869 value = sljit_alloc_memory(compiler, 16 * sizeof(sljit_sw));
870 if (value != NULL)
872 SLJIT_ASSERT(!((sljit_sw)value & ((sljit_sw)sizeof(sljit_sw) - 1)));
873 memset(value, 255, 16 * sizeof(sljit_sw));
876 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
877 const2 = sljit_emit_const(compiler, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_WORD_SHIFT - 1, -65535);
878 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[0] + 2 * (sljit_sw)sizeof(sljit_sw) - 2);
879 const3 = sljit_emit_const(compiler, SLJIT_MEM1(SLJIT_R0), 0, word_value1);
881 value = sljit_alloc_memory(compiler, 17);
882 if (value != NULL)
884 SLJIT_ASSERT(!((sljit_sw)value & ((sljit_sw)sizeof(sljit_sw) - 1)));
885 memset(value, 255, 16);
888 const4 = sljit_emit_const(compiler, SLJIT_RETURN_REG, 0, (sljit_sw)0xf7afcdb7);
890 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
892 code.code = sljit_generate_code(compiler);
893 CHECK(compiler);
894 executable_offset = sljit_get_executable_offset(compiler);
895 const1_addr = sljit_get_const_addr(const1);
896 const2_addr = sljit_get_const_addr(const2);
897 const3_addr = sljit_get_const_addr(const3);
898 const4_addr = sljit_get_const_addr(const4);
899 sljit_free_compiler(compiler);
901 FAILED(code.func1((sljit_sw)&buf) != 0xf7afcdb7, "test11 case 1 failed\n");
902 FAILED(buf[0] != -0x81b9, "test11 case 2 failed\n");
903 FAILED(buf[1] != -65535, "test11 case 3 failed\n");
904 FAILED(buf[2] != word_value1, "test11 case 4 failed\n");
906 sljit_set_const(const1_addr, -1, executable_offset);
907 sljit_set_const(const2_addr, word_value2, executable_offset);
908 sljit_set_const(const3_addr, (sljit_sw)0xbab0fea1, executable_offset);
909 sljit_set_const(const4_addr, -60089, executable_offset);
911 FAILED(code.func1((sljit_sw)&buf) != -60089, "test11 case 5 failed\n");
912 FAILED(buf[0] != -1, "test11 case 6 failed\n");
913 FAILED(buf[1] != word_value2, "test11 case 7 failed\n");
914 FAILED(buf[2] != 0xbab0fea1, "test11 case 8 failed\n");
916 sljit_free_code(code.code, NULL);
917 successful_tests++;
920 static void test12(void)
922 /* Test rewriteable jumps. */
923 executable_code code;
924 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
925 struct sljit_label *label1;
926 struct sljit_label *label2;
927 struct sljit_label *label3;
928 struct sljit_jump *jump1;
929 struct sljit_jump *jump2;
930 struct sljit_jump *jump3;
931 sljit_sw executable_offset;
932 void* value;
933 sljit_uw jump1_addr;
934 sljit_uw label1_addr;
935 sljit_uw label2_addr;
936 sljit_sw buf[1];
938 if (verbose)
939 printf("Run test12\n");
941 FAILED(!compiler, "cannot create compiler\n");
942 buf[0] = 0;
944 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(VOID, P, W), 3, 2, 0, 0, 0);
945 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_S1, 0, SLJIT_IMM, 10);
946 jump1 = sljit_emit_jump(compiler, SLJIT_REWRITABLE_JUMP | SLJIT_SIG_GREATER);
947 /* Default handler. */
948 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 5);
949 jump2 = sljit_emit_jump(compiler, SLJIT_JUMP);
951 value = sljit_alloc_memory(compiler, 15);
952 if (value != NULL)
954 SLJIT_ASSERT(!((sljit_sw)value & ((sljit_sw)sizeof(sljit_sw) - 1)));
955 memset(value, 255, 15);
958 /* Handler 1. */
959 label1 = sljit_emit_label(compiler);
960 sljit_emit_op0(compiler, SLJIT_ENDBR);
961 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 6);
962 jump3 = sljit_emit_jump(compiler, SLJIT_JUMP);
963 /* Handler 2. */
964 label2 = sljit_emit_label(compiler);
965 sljit_emit_op0(compiler, SLJIT_ENDBR);
966 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 7);
967 /* Exit. */
968 label3 = sljit_emit_label(compiler);
969 sljit_emit_op0(compiler, SLJIT_ENDBR);
970 sljit_set_label(jump2, label3);
971 sljit_set_label(jump3, label3);
972 /* By default, set to handler 1. */
973 sljit_set_label(jump1, label1);
974 sljit_emit_return_void(compiler);
976 value = sljit_alloc_memory(compiler, 8);
977 if (value != NULL)
979 SLJIT_ASSERT(!((sljit_sw)value & ((sljit_sw)sizeof(sljit_sw) - 1)));
980 memset(value, 255, 8);
983 code.code = sljit_generate_code(compiler);
984 CHECK(compiler);
985 executable_offset = sljit_get_executable_offset(compiler);
986 jump1_addr = sljit_get_jump_addr(jump1);
987 label1_addr = sljit_get_label_addr(label1);
988 label2_addr = sljit_get_label_addr(label2);
989 sljit_free_compiler(compiler);
991 code.func2((sljit_sw)&buf, 4);
992 FAILED(buf[0] != 5, "test12 case 1 failed\n");
994 code.func2((sljit_sw)&buf, 11);
995 FAILED(buf[0] != 6, "test12 case 2 failed\n");
997 sljit_set_jump_addr(jump1_addr, label2_addr, executable_offset);
998 code.func2((sljit_sw)&buf, 12);
999 FAILED(buf[0] != 7, "test12 case 3 failed\n");
1001 sljit_set_jump_addr(jump1_addr, label1_addr, executable_offset);
1002 code.func2((sljit_sw)&buf, 13);
1003 FAILED(buf[0] != 6, "test12 case 4 failed\n");
1005 sljit_free_code(code.code, NULL);
1006 successful_tests++;
1009 static void test13(void)
1011 /* Test fpu monadic functions. */
1012 executable_code code;
1013 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1014 sljit_f64 buf[7];
1015 sljit_sw buf2[6];
1017 if (verbose)
1018 printf("Run test13\n");
1020 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
1021 if (verbose)
1022 printf("no fpu available, test13 skipped\n");
1023 successful_tests++;
1024 if (compiler)
1025 sljit_free_compiler(compiler);
1026 return;
1029 FAILED(!compiler, "cannot create compiler\n");
1030 buf[0] = 7.75;
1031 buf[1] = -4.5;
1032 buf[2] = 0.0;
1033 buf[3] = 0.0;
1034 buf[4] = 0.0;
1035 buf[5] = 0.0;
1036 buf[6] = 0.0;
1038 buf2[0] = 10;
1039 buf2[1] = 10;
1040 buf2[2] = 10;
1041 buf2[3] = 10;
1042 buf2[4] = 10;
1043 buf2[5] = 10;
1045 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(VOID, P, P), 3, 2, 6, 0, 0);
1046 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM0(), (sljit_sw)&buf[2], SLJIT_MEM0(), (sljit_sw)&buf[1]);
1047 sljit_emit_fop1(compiler, SLJIT_ABS_F64, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1048 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM0(), (sljit_sw)&buf[0]);
1049 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2 * sizeof(sljit_f64));
1050 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 0);
1051 sljit_emit_fop1(compiler, SLJIT_NEG_F64, SLJIT_FR2, 0, SLJIT_FR0, 0);
1052 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR3, 0, SLJIT_FR2, 0);
1053 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM0(), (sljit_sw)&buf[4], SLJIT_FR3, 0);
1054 sljit_emit_fop1(compiler, SLJIT_ABS_F64, SLJIT_FR4, 0, SLJIT_FR1, 0);
1055 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f64), SLJIT_FR4, 0);
1056 sljit_emit_fop1(compiler, SLJIT_NEG_F64, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64), SLJIT_FR4, 0);
1058 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), 0);
1059 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_GREATER_F, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1060 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_GREATER_F64);
1061 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_GREATER_F, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64), SLJIT_FR5, 0);
1062 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_sw), SLJIT_GREATER_F64);
1063 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_FR5, 0);
1064 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR1, 0);
1065 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_sw), SLJIT_EQUAL_F64);
1066 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_LESS_F, SLJIT_FR1, 0, SLJIT_FR1, 0);
1067 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw), SLJIT_LESS_F64);
1068 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1069 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_sw), SLJIT_EQUAL_F64);
1070 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_NOT_EQUAL_F, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1071 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_sw), SLJIT_NOT_EQUAL_F64);
1073 sljit_emit_return_void(compiler);
1075 code.code = sljit_generate_code(compiler);
1076 CHECK(compiler);
1077 sljit_free_compiler(compiler);
1079 code.func2((sljit_sw)&buf, (sljit_sw)&buf2);
1080 FAILED(buf[2] != -4.5, "test13 case 1 failed\n");
1081 FAILED(buf[3] != 4.5, "test13 case 2 failed\n");
1082 FAILED(buf[4] != -7.75, "test13 case 3 failed\n");
1083 FAILED(buf[5] != 4.5, "test13 case 4 failed\n");
1084 FAILED(buf[6] != -4.5, "test13 case 5 failed\n");
1086 FAILED(buf2[0] != 1, "test13 case 6 failed\n");
1087 FAILED(buf2[1] != 0, "test13 case 7 failed\n");
1088 FAILED(buf2[2] != 1, "test13 case 8 failed\n");
1089 FAILED(buf2[3] != 0, "test13 case 9 failed\n");
1090 FAILED(buf2[4] != 0, "test13 case 10 failed\n");
1091 FAILED(buf2[5] != 1, "test13 case 11 failed\n");
1093 sljit_free_code(code.code, NULL);
1094 successful_tests++;
1097 static void test14(void)
1099 /* Test fpu diadic functions. */
1100 executable_code code;
1101 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1102 sljit_f64 buf[15];
1104 if (verbose)
1105 printf("Run test14\n");
1107 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
1108 if (verbose)
1109 printf("no fpu available, test14 skipped\n");
1110 successful_tests++;
1111 if (compiler)
1112 sljit_free_compiler(compiler);
1113 return;
1115 buf[0] = 7.25;
1116 buf[1] = 3.5;
1117 buf[2] = 1.75;
1118 buf[3] = 0.0;
1119 buf[4] = 0.0;
1120 buf[5] = 0.0;
1121 buf[6] = 0.0;
1122 buf[7] = 0.0;
1123 buf[8] = 0.0;
1124 buf[9] = 0.0;
1125 buf[10] = 0.0;
1126 buf[11] = 0.0;
1127 buf[12] = 8.0;
1128 buf[13] = 4.0;
1129 buf[14] = 0.0;
1131 FAILED(!compiler, "cannot create compiler\n");
1132 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 3, 1, 6, 0, 0);
1134 /* ADD */
1135 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_f64));
1136 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1137 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 2);
1138 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);
1139 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR0, 0, SLJIT_FR0, 0, SLJIT_FR1, 0);
1140 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR1, 0, SLJIT_FR0, 0, SLJIT_FR1, 0);
1141 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 4, SLJIT_FR0, 0);
1142 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 5, SLJIT_FR1, 0);
1144 /* SUB */
1145 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 0);
1146 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR3, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 2);
1147 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 2);
1148 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);
1149 sljit_emit_fop2(compiler, SLJIT_SUB_F64, SLJIT_FR2, 0, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 2);
1150 sljit_emit_fop2(compiler, SLJIT_SUB_F64, SLJIT_FR3, 0, SLJIT_FR2, 0, SLJIT_FR3, 0);
1151 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 7, SLJIT_FR2, 0);
1152 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 8, SLJIT_FR3, 0);
1154 /* MUL */
1155 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
1156 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);
1157 sljit_emit_fop2(compiler, SLJIT_MUL_F64, SLJIT_FR1, 0, SLJIT_FR1, 0, SLJIT_FR2, 0);
1158 sljit_emit_fop2(compiler, SLJIT_MUL_F64, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 2, SLJIT_FR2, 0);
1159 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 10, SLJIT_FR1, 0);
1160 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 11, SLJIT_FR5, 0);
1162 /* DIV */
1163 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 12);
1164 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 13);
1165 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR4, 0, SLJIT_FR5, 0);
1166 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);
1167 sljit_emit_fop2(compiler, SLJIT_DIV_F64, SLJIT_FR5, 0, SLJIT_FR5, 0, SLJIT_FR1, 0);
1168 sljit_emit_fop2(compiler, SLJIT_DIV_F64, SLJIT_FR4, 0, SLJIT_FR1, 0, SLJIT_FR4, 0);
1169 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 13, SLJIT_FR5, 0);
1170 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 14, SLJIT_FR4, 0);
1172 sljit_emit_return_void(compiler);
1174 code.code = sljit_generate_code(compiler);
1175 CHECK(compiler);
1176 sljit_free_compiler(compiler);
1178 code.func1((sljit_sw)&buf);
1179 FAILED(buf[3] != 10.75, "test14 case 1 failed\n");
1180 FAILED(buf[4] != 5.25, "test14 case 2 failed\n");
1181 FAILED(buf[5] != 7.0, "test14 case 3 failed\n");
1182 FAILED(buf[6] != 0.0, "test14 case 4 failed\n");
1183 FAILED(buf[7] != 5.5, "test14 case 5 failed\n");
1184 FAILED(buf[8] != 3.75, "test14 case 6 failed\n");
1185 FAILED(buf[9] != 24.5, "test14 case 7 failed\n");
1186 FAILED(buf[10] != 38.5, "test14 case 8 failed\n");
1187 FAILED(buf[11] != 9.625, "test14 case 9 failed\n");
1188 FAILED(buf[12] != 2.0, "test14 case 10 failed\n");
1189 FAILED(buf[13] != 2.0, "test14 case 11 failed\n");
1190 FAILED(buf[14] != 0.5, "test14 case 12 failed\n");
1192 sljit_free_code(code.code, NULL);
1193 successful_tests++;
1196 static sljit_sw SLJIT_FUNC func(sljit_sw a, sljit_sw b, sljit_sw c)
1198 return a + b + c + 5;
1201 static void test15(void)
1203 /* Test function call. */
1204 executable_code code;
1205 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1206 struct sljit_jump* jump = NULL;
1207 sljit_sw buf[7];
1209 if (verbose)
1210 printf("Run test15\n");
1212 FAILED(!compiler, "cannot create compiler\n");
1213 buf[0] = 0;
1214 buf[1] = 0;
1215 buf[2] = 0;
1216 buf[3] = 0;
1217 buf[4] = 0;
1218 buf[5] = 0;
1219 buf[6] = SLJIT_FUNC_ADDR(func);
1221 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 4, 1, 0, 0, 0);
1223 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 5);
1224 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 7);
1225 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -3);
1226 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS3(W, W, W, W), SLJIT_IMM, SLJIT_FUNC_ADDR(func));
1227 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_RETURN_REG, 0);
1229 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -5);
1230 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -10);
1231 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 2);
1232 jump = sljit_emit_call(compiler, SLJIT_CALL | SLJIT_REWRITABLE_JUMP, SLJIT_ARGS3(W, W, W, W));
1233 sljit_set_target(jump, (sljit_uw)-1);
1234 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1236 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(func));
1237 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 40);
1238 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -3);
1239 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS3(W, W, W, W), SLJIT_R0, 0);
1240 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1242 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -60);
1243 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(func));
1244 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -30);
1245 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS3(W, W, W, W), SLJIT_R1, 0);
1246 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1248 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 10);
1249 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 16);
1250 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(func));
1251 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS3(W, W, W, W), SLJIT_R2, 0);
1252 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1254 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 100);
1255 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 110);
1256 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 120);
1257 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(func));
1258 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS3(W, W, W, W), SLJIT_R3, 0);
1259 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1261 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -10);
1262 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -16);
1263 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 6);
1264 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS3(W, W, W, W), SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw));
1265 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1267 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1269 code.code = sljit_generate_code(compiler);
1270 CHECK(compiler);
1271 sljit_set_jump_addr(sljit_get_jump_addr(jump), SLJIT_FUNC_UADDR(func), sljit_get_executable_offset(compiler));
1272 sljit_free_compiler(compiler);
1274 FAILED(code.func1((sljit_sw)&buf) != -15, "test15 case 1 failed\n");
1275 FAILED(buf[0] != 14, "test15 case 2 failed\n");
1276 FAILED(buf[1] != -8, "test15 case 3 failed\n");
1277 FAILED(buf[2] != SLJIT_FUNC_ADDR(func) + 42, "test15 case 4 failed\n");
1278 FAILED(buf[3] != SLJIT_FUNC_ADDR(func) - 85, "test15 case 5 failed\n");
1279 FAILED(buf[4] != SLJIT_FUNC_ADDR(func) + 31, "test15 case 6 failed\n");
1280 FAILED(buf[5] != 335, "test15 case 7 failed\n");
1281 FAILED(buf[6] != -15, "test15 case 8 failed\n");
1283 sljit_free_code(code.code, NULL);
1284 successful_tests++;
1287 static void test16(void)
1289 /* Ackermann benchmark. */
1290 executable_code code;
1291 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1292 struct sljit_label *entry;
1293 struct sljit_label *label;
1294 struct sljit_jump *jump;
1295 struct sljit_jump *jump1;
1296 struct sljit_jump *jump2;
1298 if (verbose)
1299 printf("Run test16\n");
1301 FAILED(!compiler, "cannot create compiler\n");
1303 entry = sljit_emit_label(compiler);
1304 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(W, W, W), 3, 2, 0, 0, 0);
1305 /* If x == 0. */
1306 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_S0, 0, SLJIT_IMM, 0);
1307 jump1 = sljit_emit_jump(compiler, SLJIT_EQUAL);
1308 /* If y == 0. */
1309 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_S1, 0, SLJIT_IMM, 0);
1310 jump2 = sljit_emit_jump(compiler, SLJIT_EQUAL);
1312 /* Ack(x,y-1). */
1313 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
1314 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_S1, 0, SLJIT_IMM, 1);
1315 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS2(W, W, W));
1316 sljit_set_label(jump, entry);
1318 /* Returns with Ack(x-1, Ack(x,y-1)). */
1319 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_RETURN_REG, 0);
1320 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
1321 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS2(W, W, W));
1322 sljit_set_label(jump, entry);
1323 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1325 /* Returns with y+1. */
1326 label = sljit_emit_label(compiler);
1327 sljit_set_label(jump1, label);
1328 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1, SLJIT_S1, 0);
1329 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1331 /* Returns with Ack(x-1,1) */
1332 label = sljit_emit_label(compiler);
1333 sljit_set_label(jump2, label);
1334 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
1335 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
1336 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS2(W, W, W));
1337 sljit_set_label(jump, entry);
1338 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1340 code.code = sljit_generate_code(compiler);
1341 CHECK(compiler);
1342 sljit_free_compiler(compiler);
1344 FAILED(code.func2(3, 3) != 61, "test16 case 1 failed\n");
1345 /* For benchmarking. */
1346 /* FAILED(code.func2(3, 11) != 16381, "test16 case 1 failed\n"); */
1348 sljit_free_code(code.code, NULL);
1349 successful_tests++;
1352 static void test17(void)
1354 /* Test arm constant pool. */
1355 executable_code code;
1356 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1357 sljit_s32 i;
1358 sljit_sw buf[5];
1360 if (verbose)
1361 printf("Run test17\n");
1363 FAILED(!compiler, "cannot create compiler\n");
1365 for (i = 0; i < 5; i++)
1366 buf[i] = 0;
1368 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 3, 1, 0, 0, 0);
1369 for (i = 0; i <= 0xfff; i++) {
1370 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)0x81818000 | i);
1371 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)0x81818000 | i);
1372 if ((i & 0x3ff) == 0)
1373 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), (i >> 10) * (sljit_sw)sizeof(sljit_sw), SLJIT_R0, 0);
1375 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
1376 sljit_emit_return_void(compiler);
1378 code.code = sljit_generate_code(compiler);
1379 CHECK(compiler);
1380 sljit_free_compiler(compiler);
1382 code.func1((sljit_sw)&buf);
1383 FAILED((sljit_uw)buf[0] != 0x81818000, "test17 case 1 failed\n");
1384 FAILED((sljit_uw)buf[1] != 0x81818400, "test17 case 2 failed\n");
1385 FAILED((sljit_uw)buf[2] != 0x81818800, "test17 case 3 failed\n");
1386 FAILED((sljit_uw)buf[3] != 0x81818c00, "test17 case 4 failed\n");
1387 FAILED((sljit_uw)buf[4] != 0x81818fff, "test17 case 5 failed\n");
1389 sljit_free_code(code.code, NULL);
1390 successful_tests++;
1393 static void test18(void)
1395 /* Test 64 bit. */
1396 executable_code code;
1397 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1398 sljit_sw buf[11];
1400 if (verbose)
1401 printf("Run test18\n");
1403 FAILED(!compiler, "cannot create compiler\n");
1404 buf[0] = 0;
1405 buf[1] = 0;
1406 buf[2] = 0;
1407 buf[3] = 0;
1408 buf[4] = 0;
1409 buf[5] = 100;
1410 buf[6] = 100;
1411 buf[7] = 100;
1412 buf[8] = 100;
1413 buf[9] = 0;
1414 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) && (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
1415 buf[10] = SLJIT_W(1) << 32;
1416 #else
1417 buf[10] = 1;
1418 #endif
1420 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 3, 2, 0, 0, 0);
1422 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1423 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, SLJIT_W(0x1122334455667788));
1424 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x1122334455667788));
1426 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(1000000000000));
1427 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(1000000000000));
1428 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_IMM, SLJIT_W(5000000000000), SLJIT_R0, 0);
1430 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x1108080808));
1431 sljit_emit_op2(compiler, SLJIT_ADD32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x1120202020));
1433 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1108080808));
1434 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1120202020));
1435 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_ZERO);
1436 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_S1, 0);
1437 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
1438 sljit_emit_op2u(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1120202020));
1439 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_ZERO);
1441 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1108080808));
1442 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x2208080808));
1443 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_LESS);
1444 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
1445 sljit_emit_op2u(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1104040404));
1446 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_NOT_ZERO);
1448 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 4);
1449 sljit_emit_op2(compiler, SLJIT_SHL32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 9, SLJIT_IMM, SLJIT_W(0xffff0000), SLJIT_R0, 0);
1451 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);
1452 #else
1453 /* 32 bit operations. */
1455 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0x11223344);
1456 sljit_emit_op2(compiler, SLJIT_ADD32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, 0x44332211);
1458 #endif
1460 sljit_emit_return_void(compiler);
1462 code.code = sljit_generate_code(compiler);
1463 CHECK(compiler);
1464 sljit_free_compiler(compiler);
1466 code.func1((sljit_sw)&buf);
1467 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1468 FAILED(buf[0] != SLJIT_W(0x1122334455667788), "test18 case 1 failed\n");
1469 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1470 FAILED(buf[1] != 0x55667788, "test18 case 2 failed\n");
1471 #else
1472 FAILED(buf[1] != SLJIT_W(0x5566778800000000), "test18 case 2 failed\n");
1473 #endif
1474 FAILED(buf[2] != SLJIT_W(2000000000000), "test18 case 3 failed\n");
1475 FAILED(buf[3] != SLJIT_W(4000000000000), "test18 case 4 failed\n");
1476 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1477 FAILED(buf[4] != 0x28282828, "test18 case 5 failed\n");
1478 #else
1479 FAILED(buf[4] != SLJIT_W(0x2828282800000000), "test18 case 5 failed\n");
1480 #endif
1481 FAILED(buf[5] != 0, "test18 case 6 failed\n");
1482 FAILED(buf[6] != 1, "test18 case 7 failed\n");
1483 FAILED(buf[7] != 1, "test18 case 8 failed\n");
1484 FAILED(buf[8] != 0, "test18 case 9 failed\n");
1485 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1486 FAILED(buf[9] != 0xfff00000, "test18 case 10 failed\n");
1487 FAILED(buf[10] != 0xffffffff, "test18 case 11 failed\n");
1488 #else
1489 FAILED(buf[9] != SLJIT_W(0xfff0000000000000), "test18 case 10 failed\n");
1490 FAILED(buf[10] != SLJIT_W(0xffffffff00000000), "test18 case 11 failed\n");
1491 #endif
1492 #else
1493 FAILED(buf[0] != 0x11223344, "test18 case 1 failed\n");
1494 FAILED(buf[1] != 0x44332211, "test18 case 2 failed\n");
1495 #endif
1497 sljit_free_code(code.code, NULL);
1498 successful_tests++;
1501 static void test19(void)
1503 /* Test arm partial instruction caching. */
1504 executable_code code;
1505 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1506 sljit_sw buf[10];
1508 if (verbose)
1509 printf("Run test19\n");
1511 FAILED(!compiler, "cannot create compiler\n");
1512 buf[0] = 6;
1513 buf[1] = 4;
1514 buf[2] = 0;
1515 buf[3] = 0;
1516 buf[4] = 0;
1517 buf[5] = 0;
1518 buf[6] = 2;
1519 buf[7] = 0;
1521 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 3, 1, 0, 0, 0);
1522 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw));
1523 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM0(), (sljit_sw)&buf[2], SLJIT_MEM0(), (sljit_sw)&buf[1], SLJIT_MEM0(), (sljit_sw)&buf[0]);
1524 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
1525 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
1526 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]);
1527 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_MEM0(), (sljit_sw)&buf[0], SLJIT_IMM, 2);
1528 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_R0), (sljit_sw)&buf[0] + 4 * (sljit_sw)sizeof(sljit_sw));
1529 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_IMM, 10);
1530 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 7);
1531 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]);
1533 sljit_emit_return_void(compiler);
1535 code.code = sljit_generate_code(compiler);
1536 CHECK(compiler);
1537 sljit_free_compiler(compiler);
1539 code.func1((sljit_sw)&buf);
1540 FAILED(buf[0] != 10, "test19 case 1 failed\n");
1541 FAILED(buf[1] != 4, "test19 case 2 failed\n");
1542 FAILED(buf[2] != 14, "test19 case 3 failed\n");
1543 FAILED(buf[3] != 14, "test19 case 4 failed\n");
1544 FAILED(buf[4] != 8, "test19 case 5 failed\n");
1545 FAILED(buf[5] != 6, "test19 case 6 failed\n");
1546 FAILED(buf[6] != 12, "test19 case 7 failed\n");
1547 FAILED(buf[7] != 10, "test19 case 8 failed\n");
1549 sljit_free_code(code.code, NULL);
1550 successful_tests++;
1553 static void test20(void)
1555 /* Test stack. */
1556 executable_code code;
1557 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1558 struct sljit_jump* jump;
1559 struct sljit_label* label;
1560 sljit_sw buf[6];
1561 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1562 sljit_sw offset_value = SLJIT_W(0x1234567812345678);
1563 #else
1564 sljit_sw offset_value = SLJIT_W(0x12345678);
1565 #endif
1567 if (verbose)
1568 printf("Run test20\n");
1570 FAILED(!compiler, "cannot create compiler\n");
1571 buf[0] = 5;
1572 buf[1] = 12;
1573 buf[2] = 0;
1574 buf[3] = 0;
1575 buf[4] = 111;
1576 buf[5] = -12345;
1578 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 5, 5, 0, 0, 4 * sizeof(sljit_sw));
1579 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw), SLJIT_MEM1(SLJIT_S0), 0);
1580 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw));
1581 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -1);
1582 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_IMM, -1);
1583 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, -1);
1584 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S4, 0, SLJIT_IMM, -1);
1585 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));
1586 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);
1587 sljit_get_local_base(compiler, SLJIT_R0, 0, -offset_value);
1588 sljit_get_local_base(compiler, SLJIT_MEM1(SLJIT_S0), 0, -0x1234);
1589 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), 0);
1590 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));
1591 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_uw));
1592 /* Dummy last instructions. */
1593 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, 23);
1594 sljit_emit_label(compiler);
1596 code.code = sljit_generate_code(compiler);
1597 CHECK(compiler);
1598 sljit_free_compiler(compiler);
1600 FAILED(code.func1((sljit_sw)&buf) != -12345, "test20 case 1 failed\n")
1602 FAILED(buf[2] != 60, "test20 case 2 failed\n");
1603 FAILED(buf[3] != 17, "test20 case 3 failed\n");
1604 FAILED(buf[4] != 7, "test20 case 4 failed\n");
1606 sljit_free_code(code.code, NULL);
1608 compiler = sljit_create_compiler(NULL, NULL);
1609 sljit_emit_enter(compiler, 0, SLJIT_ARGS3(W, W, W, W), 3, 3, 0, 0, SLJIT_MAX_LOCAL_SIZE);
1611 sljit_get_local_base(compiler, SLJIT_R0, 0, SLJIT_MAX_LOCAL_SIZE - sizeof(sljit_sw));
1612 sljit_get_local_base(compiler, SLJIT_R1, 0, -(sljit_sw)sizeof(sljit_sw));
1613 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -1);
1614 label = sljit_emit_label(compiler);
1615 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
1616 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 0, SLJIT_R2, 0);
1617 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_R0, 0);
1618 jump = sljit_emit_jump(compiler, SLJIT_NOT_EQUAL);
1619 sljit_set_label(jump, label);
1621 /* Saved registers should keep their value. */
1622 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_S1, 0);
1623 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_S2, 0);
1624 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
1626 code.code = sljit_generate_code(compiler);
1627 CHECK(compiler);
1628 sljit_free_compiler(compiler);
1630 FAILED(code.func3(1234, 5678, 9012) != 15924, "test20 case 5 failed\n");
1632 sljit_free_code(code.code, NULL);
1634 compiler = sljit_create_compiler(NULL, NULL);
1635 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, SLJIT_ARGS0(W), 3, 0, 0, 0, SLJIT_MAX_LOCAL_SIZE);
1637 sljit_get_local_base(compiler, SLJIT_R0, 0, SLJIT_MAX_LOCAL_SIZE - sizeof(sljit_sw));
1638 sljit_get_local_base(compiler, SLJIT_R1, 0, -(sljit_sw)sizeof(sljit_sw));
1639 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -1);
1640 label = sljit_emit_label(compiler);
1641 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
1642 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 0, SLJIT_R2, 0);
1643 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_R0, 0);
1644 jump = sljit_emit_jump(compiler, SLJIT_NOT_EQUAL);
1645 sljit_set_label(jump, label);
1647 sljit_get_local_base(compiler, SLJIT_R0, 0, 0);
1648 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
1650 code.code = sljit_generate_code(compiler);
1651 CHECK(compiler);
1652 sljit_free_compiler(compiler);
1654 FAILED((sljit_uw)code.func0() % sizeof(sljit_f64) != 0, "test20 case 6 failed\n");
1656 sljit_free_code(code.code, NULL);
1657 successful_tests++;
1660 static void test21(void)
1662 /* Test set context. The parts of the jit code can be separated in the memory. */
1663 executable_code code1;
1664 executable_code code2;
1665 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1666 struct sljit_jump* jump = NULL;
1667 sljit_uw addr;
1668 sljit_sw executable_offset;
1669 sljit_sw buf[4];
1671 if (verbose)
1672 printf("Run test21\n");
1674 FAILED(!compiler, "cannot create compiler\n");
1675 buf[0] = 9;
1676 buf[1] = -6;
1677 buf[2] = 0;
1678 buf[3] = 0;
1680 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 2, 0, 0, 2 * sizeof(sljit_sw));
1682 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, 10);
1683 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_SP), 0);
1685 jump = sljit_emit_jump(compiler, SLJIT_JUMP | SLJIT_REWRITABLE_JUMP);
1686 sljit_set_target(jump, 0);
1688 code1.code = sljit_generate_code(compiler);
1689 CHECK(compiler);
1691 executable_offset = sljit_get_executable_offset(compiler);
1692 addr = sljit_get_jump_addr(jump);
1694 sljit_free_compiler(compiler);
1696 compiler = sljit_create_compiler(NULL, NULL);
1697 FAILED(!compiler, "cannot create compiler\n");
1699 /* Other part of the jit code. */
1700 sljit_set_context(compiler, 0, 1, 3, 2, 0, 0, 2 * sizeof(sljit_sw));
1702 sljit_emit_op0(compiler, SLJIT_ENDBR);
1703 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);
1704 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_MEM1(SLJIT_SP), 0);
1705 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_sw));
1707 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1709 code2.code = sljit_generate_code(compiler);
1710 CHECK(compiler);
1711 sljit_free_compiler(compiler);
1713 sljit_set_jump_addr(addr, SLJIT_FUNC_UADDR(code2.code), executable_offset);
1715 FAILED(code1.func1((sljit_sw)&buf) != 19, "test21 case 1 failed\n");
1716 FAILED(buf[2] != -16, "test21 case 2 failed\n");
1717 FAILED(buf[3] != 100, "test21 case 3 failed\n");
1719 sljit_free_code(code1.code, NULL);
1720 sljit_free_code(code2.code, NULL);
1721 successful_tests++;
1724 static void test22(void)
1726 /* Test simple byte and half-int data transfers. */
1727 executable_code code;
1728 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1729 sljit_sw buf[4];
1730 sljit_s16 sbuf[9];
1731 sljit_s8 bbuf[5];
1733 if (verbose)
1734 printf("Run test22\n");
1736 FAILED(!compiler, "cannot create compiler\n");
1737 buf[0] = 0;
1738 buf[1] = 0;
1739 buf[2] = -1;
1740 buf[3] = -1;
1742 sbuf[0] = 0;
1743 sbuf[1] = 0;
1744 sbuf[2] = -9;
1745 sbuf[3] = 0;
1746 sbuf[4] = 0;
1747 sbuf[5] = 0;
1748 sbuf[6] = 0;
1750 bbuf[0] = 0;
1751 bbuf[1] = 0;
1752 bbuf[2] = -56;
1753 bbuf[3] = 0;
1754 bbuf[4] = 0;
1756 sljit_emit_enter(compiler, 0, SLJIT_ARGS3(VOID, P, P, P), 3, 3, 0, 0, 0);
1758 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, -13);
1759 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s16), SLJIT_IMM, 0x1234);
1760 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_s16));
1761 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
1762 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_IMM, 2 * sizeof(sljit_s16));
1763 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s16), SLJIT_MEM1(SLJIT_S1), -(sljit_sw)sizeof(sljit_s16));
1764 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xff0000 + 8000);
1765 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 2);
1766 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM2(SLJIT_S1, SLJIT_R1), 1, SLJIT_R0, 0);
1767 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R2, 0, SLJIT_S1, 0, SLJIT_IMM, 0x1234 - 3 * sizeof(sljit_s16));
1768 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_R2), 0x1234, SLJIT_IMM, -9317);
1769 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S1, 0, SLJIT_IMM, 0x1234 + 4 * sizeof(sljit_s16));
1770 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_R2), -0x1234, SLJIT_IMM, -9317);
1771 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R2, 0, SLJIT_S1, 0, SLJIT_IMM, 0x12348 - 5 * sizeof(sljit_s16));
1772 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_R2), 0x12348, SLJIT_IMM, -8888);
1773 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S1, 0, SLJIT_IMM, 0x12348 + 6 * sizeof(sljit_s16));
1774 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_R2), -0x12348, SLJIT_IMM, -8888);
1776 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_MEM1(SLJIT_S2), 0, SLJIT_IMM, -45);
1777 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_s8), SLJIT_IMM, 0x12);
1778 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4 * sizeof(sljit_s8));
1779 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_s8));
1780 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_S1, 0, SLJIT_R1, 0);
1781 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_S1, 0, SLJIT_S1, 0);
1782 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R2, 0, SLJIT_S1, 0);
1783 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R2, 0);
1784 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S2), 3 * sizeof(sljit_s8), SLJIT_S1, 0);
1785 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM2(SLJIT_S2, SLJIT_R0), 0, SLJIT_R0, 0);
1786 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
1787 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_R0, 0, SLJIT_IMM, 0);
1788 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
1789 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
1790 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
1791 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_R0, 0);
1793 sljit_emit_return_void(compiler);
1795 code.code = sljit_generate_code(compiler);
1796 CHECK(compiler);
1797 sljit_free_compiler(compiler);
1799 code.func3((sljit_sw)&buf, (sljit_sw)&sbuf, (sljit_sw)&bbuf);
1800 FAILED(buf[0] != -9, "test22 case 1 failed\n");
1801 FAILED(buf[1] != -56, "test22 case 2 failed\n");
1802 FAILED(buf[2] != 0, "test22 case 3 failed\n");
1803 FAILED(buf[3] != 0, "test22 case 4 failed\n");
1805 FAILED(sbuf[0] != -13, "test22 case 5 failed\n");
1806 FAILED(sbuf[1] != 0x1234, "test22 case 6 failed\n");
1807 FAILED(sbuf[3] != 0x1234, "test22 case 7 failed\n");
1808 FAILED(sbuf[4] != 8000, "test22 case 8 failed\n");
1809 FAILED(sbuf[5] != -9317, "test22 case 9 failed\n");
1810 FAILED(sbuf[6] != -9317, "test22 case 10 failed\n");
1811 FAILED(sbuf[7] != -8888, "test22 case 11 failed\n");
1812 FAILED(sbuf[8] != -8888, "test22 case 12 failed\n");
1814 FAILED(bbuf[0] != -45, "test22 case 13 failed\n");
1815 FAILED(bbuf[1] != 0x12, "test22 case 14 failed\n");
1816 FAILED(bbuf[3] != -56, "test22 case 15 failed\n");
1817 FAILED(bbuf[4] != 4, "test22 case 16 failed\n");
1819 sljit_free_code(code.code, NULL);
1820 successful_tests++;
1823 static void test23(void)
1825 /* Test 32 bit / 64 bit signed / unsigned int transfer and conversion.
1826 This test has do real things on 64 bit systems, but works on 32 bit systems as well. */
1827 executable_code code;
1828 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1829 sljit_sw buf[9];
1830 sljit_s32 ibuf[5];
1831 union {
1832 sljit_s32 asint;
1833 sljit_u8 asbytes[4];
1834 } u;
1835 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1836 sljit_sw garbage = SLJIT_W(0x1234567812345678);
1837 #else
1838 sljit_sw garbage = 0x12345678;
1839 #endif
1841 if (verbose)
1842 printf("Run test23\n");
1844 FAILED(!compiler, "cannot create compiler\n");
1845 buf[0] = 0;
1846 buf[1] = 0;
1847 buf[2] = 0;
1848 buf[3] = 0;
1849 buf[4] = 0;
1850 buf[5] = 0;
1851 buf[6] = 0;
1852 buf[7] = 0;
1853 buf[8] = 0;
1855 ibuf[0] = 0;
1856 ibuf[1] = 0;
1857 ibuf[2] = -5791;
1858 ibuf[3] = 43579;
1859 ibuf[4] = 658923;
1861 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(W, P, P), 3, 3, 0, 0, 0);
1862 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, 34567);
1863 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4);
1864 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), 0, SLJIT_IMM, -7654);
1865 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, garbage);
1866 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_s32));
1867 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
1868 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, garbage);
1869 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_s32));
1870 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
1871 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, garbage);
1872 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_s32));
1873 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
1874 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
1875 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x0f00f00);
1876 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 0x7777);
1877 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 0x7777 + 3 * sizeof(sljit_sw), SLJIT_R0, 0);
1878 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 0x7777);
1879 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), -0x7777 + 4 * (sljit_sw)sizeof(sljit_sw), SLJIT_R0, 0);
1880 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 5 * sizeof(sljit_sw));
1881 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 1);
1882 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_R1, SLJIT_R1), 0, SLJIT_IMM, 16);
1883 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
1884 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), 1, SLJIT_IMM, 64, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), 1);
1885 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM0(), (sljit_sw)&buf[7], SLJIT_IMM, 0x123456);
1886 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), (sljit_sw)&buf[6], SLJIT_MEM0(), (sljit_sw)&buf[7]);
1887 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 5 * sizeof(sljit_sw));
1888 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 2 * sizeof(sljit_sw), SLJIT_R1, 0);
1889 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S0, 0, SLJIT_IMM, 7 * sizeof(sljit_sw));
1890 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, 1);
1891 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM2(SLJIT_R2, SLJIT_R2), 0);
1892 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[8] - 0x12340);
1893 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0x12340, SLJIT_R2, 0);
1894 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_R0), 0x12340, SLJIT_MEM1(SLJIT_R2), 3 * sizeof(sljit_sw), SLJIT_IMM, 6);
1895 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_s32), SLJIT_IMM, 0x12345678);
1896 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x2bd700 | 243);
1897 sljit_emit_return(compiler, SLJIT_MOV_S8, SLJIT_R1, 0);
1899 code.code = sljit_generate_code(compiler);
1900 CHECK(compiler);
1901 sljit_free_compiler(compiler);
1903 FAILED(code.func2((sljit_sw)&buf, (sljit_sw)&ibuf) != -13, "test23 case 1 failed\n");
1904 FAILED(buf[0] != -5791, "test23 case 2 failed\n");
1905 FAILED(buf[1] != 43579, "test23 case 3 failed\n");
1906 FAILED(buf[2] != 658923, "test23 case 4 failed\n");
1907 FAILED(buf[3] != 0x0f00f00, "test23 case 5 failed\n");
1908 FAILED(buf[4] != 0x0f00f00, "test23 case 6 failed\n");
1909 FAILED(buf[5] != 80, "test23 case 7 failed\n");
1910 FAILED(buf[6] != 0x123456, "test23 case 8 failed\n");
1911 FAILED(buf[7] != (sljit_sw)&buf[5], "test23 case 9 failed\n");
1912 FAILED(buf[8] != (sljit_sw)&buf[5] + 6, "test23 case 10 failed\n");
1914 FAILED(ibuf[0] != 34567, "test23 case 11 failed\n");
1915 FAILED(ibuf[1] != -7654, "test23 case 12 failed\n");
1916 u.asint = ibuf[4];
1917 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1918 FAILED(u.asbytes[0] != 0x78, "test23 case 13 failed\n");
1919 FAILED(u.asbytes[1] != 0x56, "test23 case 14 failed\n");
1920 FAILED(u.asbytes[2] != 0x34, "test23 case 15 failed\n");
1921 FAILED(u.asbytes[3] != 0x12, "test23 case 16 failed\n");
1922 #else
1923 FAILED(u.asbytes[0] != 0x12, "test23 case 13 failed\n");
1924 FAILED(u.asbytes[1] != 0x34, "test23 case 14 failed\n");
1925 FAILED(u.asbytes[2] != 0x56, "test23 case 15 failed\n");
1926 FAILED(u.asbytes[3] != 0x78, "test23 case 16 failed\n");
1927 #endif
1929 sljit_free_code(code.code, NULL);
1930 successful_tests++;
1933 static void test24(void)
1935 /* Some complicated addressing modes. */
1936 executable_code code;
1937 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1938 sljit_sw buf[9];
1939 sljit_s16 sbuf[5];
1940 sljit_s8 bbuf[7];
1942 if (verbose)
1943 printf("Run test24\n");
1945 FAILED(!compiler, "cannot create compiler\n");
1947 buf[0] = 100567;
1948 buf[1] = 75799;
1949 buf[2] = 0;
1950 buf[3] = -8;
1951 buf[4] = -50;
1952 buf[5] = 0;
1953 buf[6] = 0;
1954 buf[7] = 0;
1955 buf[8] = 0;
1957 sbuf[0] = 30000;
1958 sbuf[1] = 0;
1959 sbuf[2] = 0;
1960 sbuf[3] = -12345;
1961 sbuf[4] = 0;
1963 bbuf[0] = -128;
1964 bbuf[1] = 0;
1965 bbuf[2] = 0;
1966 bbuf[3] = 99;
1967 bbuf[4] = 0;
1968 bbuf[5] = 0;
1969 bbuf[6] = 0;
1971 sljit_emit_enter(compiler, 0, SLJIT_ARGS3(VOID, P, P, P), 3, 3, 0, 0, 0);
1973 /* Nothing should be updated. */
1974 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM0(), (sljit_sw)&sbuf[1], SLJIT_MEM0(), (sljit_sw)&sbuf[0]);
1975 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_MEM0(), (sljit_sw)&bbuf[1], SLJIT_MEM0(), (sljit_sw)&bbuf[0]);
1976 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
1977 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), 1, SLJIT_MEM0(), (sljit_sw)&sbuf[3]);
1978 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[0]);
1979 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
1980 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 2);
1981 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);
1982 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_s8));
1983 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_R0), (sljit_sw)&bbuf[1], SLJIT_MEM1(SLJIT_R0), (sljit_sw)&bbuf[2]);
1985 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_s16));
1986 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_R1), (sljit_sw)&sbuf[3], SLJIT_R1, 0);
1988 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 3);
1989 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);
1990 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4);
1991 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_S0, 0);
1992 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);
1994 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 9 * sizeof(sljit_sw));
1995 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 4 * sizeof(sljit_sw));
1996 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -4 << SLJIT_WORD_SHIFT);
1997 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_R0, SLJIT_R2), 0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
1999 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf - 0x7fff8000 + 6 * (sljit_sw)sizeof(sljit_sw));
2000 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 952467);
2001 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0x7fff8000, SLJIT_R1, 0);
2002 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0x7fff8000 + sizeof(sljit_sw), SLJIT_MEM1(SLJIT_R0), 0x7fff8000);
2004 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf + 0x7fff7fff + 6 * (sljit_sw)sizeof(sljit_sw));
2005 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_R0), -0x7fff7fff + 2 * (sljit_sw)sizeof(sljit_sw), SLJIT_MEM1(SLJIT_R0), -0x7fff7fff + (sljit_sw)sizeof(sljit_sw), SLJIT_MEM1(SLJIT_R0), -0x7fff7fff);
2006 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&bbuf - 0x7fff7ffe + 3 * (sljit_sw)sizeof(sljit_s8));
2007 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_MEM1(SLJIT_R0), 0x7fff7fff, SLJIT_MEM1(SLJIT_R0), 0x7fff7ffe);
2008 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&bbuf + 0x7fff7fff + 5 * (sljit_sw)sizeof(sljit_s8));
2009 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_MEM1(SLJIT_R0), -0x7fff7fff, SLJIT_MEM1(SLJIT_R0), -0x7fff8000);
2010 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2011 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&bbuf - SLJIT_W(0x123456123456));
2012 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&bbuf - SLJIT_W(0x123456123456));
2013 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));
2014 #endif
2016 sljit_emit_return_void(compiler);
2018 code.code = sljit_generate_code(compiler);
2019 CHECK(compiler);
2020 sljit_free_compiler(compiler);
2022 code.func3((sljit_sw)&buf, (sljit_sw)&sbuf, (sljit_sw)&bbuf);
2023 FAILED(buf[2] != 176366, "test24 case 1 failed\n");
2024 FAILED(buf[3] != 64, "test24 case 2 failed\n");
2025 FAILED(buf[4] != -100, "test24 case 3 failed\n");
2026 FAILED(buf[5] != 100567, "test24 case 4 failed\n");
2027 FAILED(buf[6] != 952467, "test24 case 5 failed\n");
2028 FAILED(buf[7] != 952467, "test24 case 6 failed\n");
2029 FAILED(buf[8] != 952467 * 2, "test24 case 7 failed\n");
2031 FAILED(sbuf[1] != 30000, "test24 case 8 failed\n");
2032 FAILED(sbuf[2] != -12345, "test24 case 9 failed\n");
2033 FAILED(sbuf[4] != sizeof(sljit_s16), "test24 case 10 failed\n");
2035 FAILED(bbuf[1] != -128, "test24 case 11 failed\n");
2036 FAILED(bbuf[2] != 99, "test24 case 12 failed\n");
2037 FAILED(bbuf[4] != 99, "test24 case 13 failed\n");
2038 FAILED(bbuf[5] != 99, "test24 case 14 failed\n");
2039 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2040 FAILED(bbuf[6] != -128, "test24 case 15 failed\n");
2041 #endif
2043 sljit_free_code(code.code, NULL);
2044 successful_tests++;
2047 static void test25(void)
2049 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2050 /* 64 bit loads. */
2051 executable_code code;
2052 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
2053 sljit_sw buf[14];
2055 if (verbose)
2056 printf("Run test25\n");
2058 FAILED(!compiler, "cannot create compiler\n");
2059 buf[0] = 7;
2060 buf[1] = 0;
2061 buf[2] = 0;
2062 buf[3] = 0;
2063 buf[4] = 0;
2064 buf[5] = 0;
2065 buf[6] = 0;
2066 buf[7] = 0;
2067 buf[8] = 0;
2068 buf[9] = 0;
2069 buf[10] = 0;
2070 buf[11] = 0;
2071 buf[12] = 0;
2072 buf[13] = 0;
2074 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 3, 1, 0, 0, 0);
2076 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0);
2077 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 1 * sizeof(sljit_sw), SLJIT_IMM, 0x7fff);
2078 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_IMM, -0x8000);
2079 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_IMM, 0x7fffffff);
2080 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(-0x80000000));
2081 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x1234567887654321));
2082 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0xff80000000));
2083 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x3ff0000000));
2084 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_IMM, (sljit_sw)SLJIT_W(0xfffffff800100000));
2085 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_IMM, (sljit_sw)SLJIT_W(0xfffffff80010f000));
2086 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00000008001));
2087 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00080010000));
2088 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00080018001));
2089 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00ffff00000));
2091 sljit_emit_return_void(compiler);
2093 code.code = sljit_generate_code(compiler);
2094 CHECK(compiler);
2095 sljit_free_compiler(compiler);
2097 code.func1((sljit_sw)&buf);
2098 FAILED(buf[0] != 0, "test25 case 1 failed\n");
2099 FAILED(buf[1] != 0x7fff, "test25 case 2 failed\n");
2100 FAILED(buf[2] != -0x8000, "test25 case 3 failed\n");
2101 FAILED(buf[3] != 0x7fffffff, "test25 case 4 failed\n");
2102 FAILED(buf[4] != SLJIT_W(-0x80000000), "test25 case 5 failed\n");
2103 FAILED(buf[5] != SLJIT_W(0x1234567887654321), "test25 case 6 failed\n");
2104 FAILED(buf[6] != SLJIT_W(0xff80000000), "test25 case 7 failed\n");
2105 FAILED(buf[7] != SLJIT_W(0x3ff0000000), "test25 case 8 failed\n");
2106 FAILED((sljit_uw)buf[8] != SLJIT_W(0xfffffff800100000), "test25 case 9 failed\n");
2107 FAILED((sljit_uw)buf[9] != SLJIT_W(0xfffffff80010f000), "test25 case 10 failed\n");
2108 FAILED(buf[10] != SLJIT_W(0x07fff00000008001), "test25 case 11 failed\n");
2109 FAILED(buf[11] != SLJIT_W(0x07fff00080010000), "test25 case 12 failed\n");
2110 FAILED(buf[12] != SLJIT_W(0x07fff00080018001), "test25 case 13 failed\n");
2111 FAILED(buf[13] != SLJIT_W(0x07fff00ffff00000), "test25 case 14 failed\n");
2113 sljit_free_code(code.code, NULL);
2114 #endif
2115 successful_tests++;
2118 static void test26(void)
2120 /* Aligned access without aligned offsets. */
2121 executable_code code;
2122 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
2123 sljit_sw buf[4];
2124 sljit_s32 ibuf[4];
2125 sljit_f64 dbuf[4];
2127 if (verbose)
2128 printf("Run test26\n");
2130 FAILED(!compiler, "cannot create compiler\n");
2132 buf[0] = -2789;
2133 buf[1] = 0;
2134 buf[2] = 4;
2135 buf[3] = -4;
2137 ibuf[0] = -689;
2138 ibuf[1] = 0;
2139 ibuf[2] = -6;
2140 ibuf[3] = 3;
2142 dbuf[0] = 5.75;
2143 dbuf[1] = 0.0;
2144 dbuf[2] = 0.0;
2145 dbuf[3] = -4.0;
2147 sljit_emit_enter(compiler, 0, SLJIT_ARGS3(VOID, P, P, P), 3, 3, 0, 0, 0);
2149 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 3);
2150 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_IMM, 1);
2151 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), -3);
2152 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32) - 1, SLJIT_R0, 0);
2153 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), -1);
2154 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) - 3, SLJIT_R0, 0);
2156 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 100);
2157 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM1(SLJIT_R0), (sljit_sw)sizeof(sljit_sw) * 2 - 103, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2 - 3, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3 - 3);
2158 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_IMM, 100);
2159 sljit_emit_op2(compiler, SLJIT_MUL32, SLJIT_MEM1(SLJIT_R0), (sljit_sw)sizeof(sljit_s32) * 2 - 101, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32) * 2 - 1, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32) * 3 - 1);
2161 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
2162 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S2, 0, SLJIT_S2, 0, SLJIT_IMM, 3);
2163 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f64) - 3, SLJIT_MEM1(SLJIT_S2), -3);
2164 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);
2165 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S2, 0, SLJIT_IMM, 2);
2166 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sizeof(sljit_f64) * 3 - 4) >> 1);
2167 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, 1);
2168 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);
2171 sljit_emit_return_void(compiler);
2173 code.code = sljit_generate_code(compiler);
2174 CHECK(compiler);
2175 sljit_free_compiler(compiler);
2177 code.func3((sljit_sw)&buf, (sljit_sw)&ibuf, (sljit_sw)&dbuf);
2179 FAILED(buf[1] != -689, "test26 case 1 failed\n");
2180 FAILED(buf[2] != -16, "test26 case 2 failed\n");
2181 FAILED(ibuf[1] != -2789, "test26 case 3 failed\n");
2182 FAILED(ibuf[2] != -18, "test26 case 4 failed\n");
2184 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
2185 FAILED(dbuf[1] != 5.75, "test26 case 5 failed\n");
2186 FAILED(dbuf[2] != 11.5, "test26 case 6 failed\n");
2187 FAILED(dbuf[3] != -2.875, "test26 case 7 failed\n");
2190 sljit_free_code(code.code, NULL);
2191 successful_tests++;
2194 static void test27(void)
2196 #define SET_NEXT_BYTE(type) \
2197 cond_set(compiler, SLJIT_R2, 0, type); \
2198 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R2, 0); \
2199 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
2200 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2201 #define RESULT(i) i
2202 #else
2203 #define RESULT(i) (3 - i)
2204 #endif
2206 /* Playing with conditional flags. */
2207 executable_code code;
2208 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
2209 sljit_u8 buf[41];
2210 sljit_s32 i;
2211 #ifdef SLJIT_PREF_SHIFT_REG
2212 sljit_s32 shift_reg = SLJIT_PREF_SHIFT_REG;
2213 #else
2214 sljit_s32 shift_reg = SLJIT_R2;
2215 #endif
2217 SLJIT_ASSERT(shift_reg >= SLJIT_R2 && shift_reg <= SLJIT_R3);
2219 if (verbose)
2220 printf("Run test27\n");
2222 for (i = 0; i < sizeof(buf); ++i)
2223 buf[i] = 10;
2225 FAILED(!compiler, "cannot create compiler\n");
2227 /* 3 arguments passed, 3 arguments used. */
2228 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 4, 3, 0, 0, 0);
2230 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
2232 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x1001);
2233 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 20);
2234 /* 0x100100000 on 64 bit machines, 0x100000 on 32 bit machines. */
2235 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x800000);
2236 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_R0, 0, SLJIT_R1, 0);
2237 sljit_emit_op0(compiler, SLJIT_ENDBR); /* ENDBR should keep the flags. */
2238 sljit_emit_op0(compiler, SLJIT_NOP); /* Nop should keep the flags. */
2239 SET_NEXT_BYTE(SLJIT_GREATER);
2240 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
2241 SET_NEXT_BYTE(SLJIT_LESS);
2242 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
2243 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_R1, 0);
2244 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_GREATER, SLJIT_R0, 0, SLJIT_R1, 0);
2245 sljit_emit_op0(compiler, SLJIT_ENDBR); /* ENDBR should keep the flags. */
2246 sljit_emit_op0(compiler, SLJIT_NOP); /* Nop should keep the flags. */
2247 SET_NEXT_BYTE(SLJIT_GREATER);
2248 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
2249 SET_NEXT_BYTE(SLJIT_LESS);
2251 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x1000);
2252 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 20);
2253 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0x10);
2254 /* 0x100000010 on 64 bit machines, 0x10 on 32 bit machines. */
2255 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_R0, 0, SLJIT_IMM, 0x80);
2256 SET_NEXT_BYTE(SLJIT_GREATER);
2257 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_R0, 0, SLJIT_IMM, 0x80);
2258 SET_NEXT_BYTE(SLJIT_LESS);
2259 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
2260 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_GREATER, SLJIT_R0, 0, SLJIT_IMM, 0x80);
2261 SET_NEXT_BYTE(SLJIT_GREATER);
2262 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_LESS, SLJIT_R0, 0, SLJIT_IMM, 0x80);
2263 SET_NEXT_BYTE(SLJIT_LESS);
2265 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2266 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2267 /* 0xff..ff on all machines. */
2268 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS_EQUAL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2269 SET_NEXT_BYTE(SLJIT_LESS_EQUAL);
2270 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2271 SET_NEXT_BYTE(SLJIT_GREATER_EQUAL);
2272 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_R2, 0, SLJIT_R1, 0, SLJIT_IMM, -1);
2273 SET_NEXT_BYTE(SLJIT_SIG_GREATER);
2274 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, -1);
2275 SET_NEXT_BYTE(SLJIT_SIG_LESS);
2276 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R2, 0, SLJIT_R1, 0, SLJIT_R0, 0);
2277 SET_NEXT_BYTE(SLJIT_EQUAL);
2278 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_R0, 0);
2279 SET_NEXT_BYTE(SLJIT_NOT_EQUAL);
2280 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, -2);
2281 SET_NEXT_BYTE(SLJIT_OVERFLOW);
2282 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, -2);
2283 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW);
2284 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, -2);
2285 SET_NEXT_BYTE(SLJIT_GREATER_EQUAL);
2286 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, -2);
2287 SET_NEXT_BYTE(SLJIT_LESS_EQUAL);
2288 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)-1 << ((8 * sizeof(sljit_sw)) - 1));
2289 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, 1);
2290 SET_NEXT_BYTE(SLJIT_SIG_LESS);
2291 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, -1);
2292 SET_NEXT_BYTE(SLJIT_SIG_GREATER);
2293 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, 1);
2294 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, -2);
2295 SET_NEXT_BYTE(SLJIT_SIG_GREATER_EQUAL);
2296 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 2);
2297 SET_NEXT_BYTE(SLJIT_SIG_GREATER);
2299 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)0x80000000);
2300 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 16);
2301 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 16);
2302 /* 0x80..0 on 64 bit machines, 0 on 32 bit machines. */
2303 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)0xffffffff);
2304 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R1, 0);
2305 SET_NEXT_BYTE(SLJIT_OVERFLOW);
2306 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R1, 0);
2307 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW);
2308 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
2309 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R1, 0, SLJIT_R1, 0);
2310 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R1, 0);
2311 SET_NEXT_BYTE(SLJIT_OVERFLOW);
2312 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R1, 0);
2313 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW);
2315 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2316 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_IMM, 1);
2317 sljit_emit_op2u(compiler, SLJIT_SUBC | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_IMM, 0);
2318 sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_R0, 0, SLJIT_IMM, 6, SLJIT_R0, 0);
2319 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R0, 0);
2320 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
2322 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
2323 sljit_emit_op2u(compiler, SLJIT_ADD | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_IMM, 1);
2324 sljit_emit_op2u(compiler, SLJIT_ADDC | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_IMM, 1);
2325 sljit_emit_op2(compiler, SLJIT_ADDC, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 9);
2326 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R0, 0);
2327 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
2329 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
2330 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, (8 * sizeof(sljit_sw)) - 1);
2331 sljit_emit_op2u(compiler, SLJIT_ADD | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_IMM, 0);
2332 SET_NEXT_BYTE(SLJIT_EQUAL);
2333 sljit_emit_op2u(compiler, SLJIT_ADD | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0);
2334 SET_NEXT_BYTE(SLJIT_EQUAL);
2336 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2337 sljit_emit_op2(compiler, SLJIT_ASHR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0);
2338 SET_NEXT_BYTE(SLJIT_EQUAL);
2339 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
2340 sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffffc0);
2341 SET_NEXT_BYTE(SLJIT_NOT_EQUAL);
2342 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 0);
2343 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2344 sljit_emit_op2(compiler, SLJIT_ASHR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0, shift_reg, 0);
2345 SET_NEXT_BYTE(SLJIT_EQUAL);
2346 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 0);
2347 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
2348 sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0, shift_reg, 0);
2349 SET_NEXT_BYTE(SLJIT_NOT_EQUAL);
2351 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2352 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
2353 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_R0, 0);
2354 sljit_emit_op2(compiler, SLJIT_SUBC | SLJIT_SET_CARRY, SLJIT_R2, 0, SLJIT_IMM, 1, SLJIT_R0, 0);
2355 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R2, 0);
2356 sljit_emit_op2u(compiler, SLJIT_SUBC | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_R1, 0);
2357 sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_R2, 0, SLJIT_IMM, 1, SLJIT_R0, 0);
2358 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 2, SLJIT_R2, 0);
2359 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 2);
2361 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -34);
2362 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_R0, 0, SLJIT_IMM, 0x1234);
2363 SET_NEXT_BYTE(SLJIT_LESS);
2364 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R0, 0, SLJIT_IMM, 0x1234);
2365 SET_NEXT_BYTE(SLJIT_SIG_LESS);
2366 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2367 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x12300000000) - 43);
2368 #else
2369 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, -43);
2370 #endif
2371 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -96);
2372 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
2373 SET_NEXT_BYTE(SLJIT_LESS);
2374 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_SIG_GREATER, SLJIT_R0, 0, SLJIT_R1, 0);
2375 SET_NEXT_BYTE(SLJIT_SIG_GREATER);
2377 sljit_emit_return_void(compiler);
2379 code.code = sljit_generate_code(compiler);
2380 CHECK(compiler);
2381 sljit_free_compiler(compiler);
2383 code.func1((sljit_sw)&buf);
2385 FAILED(buf[0] != RESULT(1), "test27 case 1 failed\n");
2386 FAILED(buf[1] != RESULT(2), "test27 case 2 failed\n");
2387 FAILED(buf[2] != 2, "test27 case 3 failed\n");
2388 FAILED(buf[3] != 1, "test27 case 4 failed\n");
2389 FAILED(buf[4] != RESULT(1), "test27 case 5 failed\n");
2390 FAILED(buf[5] != RESULT(2), "test27 case 6 failed\n");
2391 FAILED(buf[6] != 2, "test27 case 7 failed\n");
2392 FAILED(buf[7] != 1, "test27 case 8 failed\n");
2394 FAILED(buf[8] != 2, "test27 case 9 failed\n");
2395 FAILED(buf[9] != 1, "test27 case 10 failed\n");
2396 FAILED(buf[10] != 2, "test27 case 11 failed\n");
2397 FAILED(buf[11] != 1, "test27 case 12 failed\n");
2398 FAILED(buf[12] != 1, "test27 case 13 failed\n");
2399 FAILED(buf[13] != 2, "test27 case 14 failed\n");
2400 FAILED(buf[14] != 2, "test27 case 15 failed\n");
2401 FAILED(buf[15] != 1, "test27 case 16 failed\n");
2402 FAILED(buf[16] != 1, "test27 case 17 failed\n");
2403 FAILED(buf[17] != 2, "test27 case 18 failed\n");
2404 FAILED(buf[18] != 1, "test27 case 19 failed\n");
2405 FAILED(buf[19] != 1, "test27 case 20 failed\n");
2406 FAILED(buf[20] != 1, "test27 case 21 failed\n");
2407 FAILED(buf[21] != 2, "test27 case 22 failed\n");
2409 FAILED(buf[22] != RESULT(1), "test27 case 23 failed\n");
2410 FAILED(buf[23] != RESULT(2), "test27 case 24 failed\n");
2411 FAILED(buf[24] != 2, "test27 case 25 failed\n");
2412 FAILED(buf[25] != 1, "test27 case 26 failed\n");
2414 FAILED(buf[26] != 5, "test27 case 27 failed\n");
2415 FAILED(buf[27] != 9, "test27 case 28 failed\n");
2417 FAILED(buf[28] != 2, "test27 case 29 failed\n");
2418 FAILED(buf[29] != 1, "test27 case 30 failed\n");
2420 FAILED(buf[30] != 1, "test27 case 31 failed\n");
2421 FAILED(buf[31] != 1, "test27 case 32 failed\n");
2422 FAILED(buf[32] != 1, "test27 case 33 failed\n");
2423 FAILED(buf[33] != 1, "test27 case 34 failed\n");
2425 FAILED(buf[34] != 1, "test27 case 35 failed\n");
2426 FAILED(buf[35] != 0, "test27 case 36 failed\n");
2428 FAILED(buf[36] != 2, "test27 case 37 failed\n");
2429 FAILED(buf[37] != 1, "test27 case 38 failed\n");
2430 FAILED(buf[38] != 2, "test27 case 39 failed\n");
2431 FAILED(buf[39] != 1, "test27 case 40 failed\n");
2432 FAILED(buf[40] != 10, "test27 case 41 failed\n");
2434 sljit_free_code(code.code, NULL);
2435 successful_tests++;
2436 #undef SET_NEXT_BYTE
2437 #undef RESULT
2440 static void test28(void)
2442 /* Test mov. */
2443 executable_code code;
2444 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
2445 struct sljit_const* const1 = NULL;
2446 struct sljit_label* label = NULL;
2447 sljit_uw label_addr = 0;
2448 sljit_sw buf[5];
2450 if (verbose)
2451 printf("Run test28\n");
2453 FAILED(!compiler, "cannot create compiler\n");
2455 buf[0] = -36;
2456 buf[1] = 8;
2457 buf[2] = 0;
2458 buf[3] = 10;
2459 buf[4] = 0;
2461 FAILED(!compiler, "cannot create compiler\n");
2462 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 5, 5, 0, 0, 0);
2463 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -234);
2464 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw));
2465 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_S3, 0, SLJIT_R3, 0, SLJIT_R4, 0);
2466 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_S3, 0);
2467 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_S3, 0, SLJIT_IMM, 0);
2468 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_NOT_ZERO);
2469 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_S3, 0);
2470 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S4, 0, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw));
2471 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S4, 0, SLJIT_S4, 0, SLJIT_R4, 0);
2472 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_S4, 0);
2474 const1 = sljit_emit_const(compiler, SLJIT_S3, 0, 0);
2475 sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_S3, 0);
2476 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S3, 0, SLJIT_S3, 0, SLJIT_IMM, 100);
2477 label = sljit_emit_label(compiler);
2478 sljit_emit_op0(compiler, SLJIT_ENDBR);
2479 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_S3, 0);
2481 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R4, 0);
2483 code.code = sljit_generate_code(compiler);
2484 CHECK(compiler);
2486 label_addr = sljit_get_label_addr(label);
2487 sljit_set_const(sljit_get_const_addr(const1), (sljit_sw)label_addr, sljit_get_executable_offset(compiler));
2489 sljit_free_compiler(compiler);
2491 FAILED(code.func1((sljit_sw)&buf) != 8, "test28 case 1 failed\n");
2492 FAILED(buf[1] != -1872, "test28 case 2 failed\n");
2493 FAILED(buf[2] != 1, "test28 case 3 failed\n");
2494 FAILED(buf[3] != 2, "test28 case 4 failed\n");
2495 FAILED(buf[4] != label_addr, "test28 case 5 failed\n");
2497 sljit_free_code(code.code, NULL);
2498 successful_tests++;
2501 static void test29(void)
2503 /* Test signed/unsigned bytes and halfs. */
2504 executable_code code;
2505 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
2506 sljit_sw buf[25];
2507 sljit_s32 i;
2509 if (verbose)
2510 printf("Run test29\n");
2512 for (i = 0; i < 25; i++)
2513 buf[i] = 0;
2515 FAILED(!compiler, "cannot create compiler\n");
2516 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 5, 5, 0, 0, 0);
2518 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R0, 0, SLJIT_IMM, -187);
2519 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
2520 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R0, 0, SLJIT_IMM, -605);
2521 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R0, 0);
2522 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R0, 0, SLJIT_IMM, -56);
2523 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_uw), SLJIT_R0, 0);
2524 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R4, 0, SLJIT_IMM, 0xcde5);
2525 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_uw), SLJIT_R4, 0);
2527 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_R0, 0, SLJIT_IMM, -45896);
2528 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_uw), SLJIT_R0, 0);
2529 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_R0, 0, SLJIT_IMM, -1472797);
2530 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_uw), SLJIT_R0, 0);
2531 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_R0, 0, SLJIT_IMM, -12890);
2532 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_uw), SLJIT_R0, 0);
2533 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_R4, 0, SLJIT_IMM, 0x9cb0a6);
2534 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_uw), SLJIT_R4, 0);
2536 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2537 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-3580429715));
2538 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_uw), SLJIT_R0, 0);
2539 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-100722768662));
2540 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_uw), SLJIT_R0, 0);
2541 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-1457052677972));
2542 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_uw), SLJIT_R0, 0);
2543 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R4, 0, SLJIT_IMM, SLJIT_W(0xcef97a70b5));
2544 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_uw), SLJIT_R4, 0);
2545 #endif
2547 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -187);
2548 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R0, 0, SLJIT_R1, 0);
2549 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_uw), SLJIT_R0, 0);
2550 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, -605);
2551 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R0, 0, SLJIT_S2, 0);
2552 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_uw), SLJIT_R0, 0);
2553 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -56);
2554 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R0, 0, SLJIT_R2, 0);
2555 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_uw), SLJIT_R0, 0);
2556 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0xcde5);
2557 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R4, 0, SLJIT_R3, 0);
2558 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 15 * sizeof(sljit_uw), SLJIT_R4, 0);
2560 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -45896);
2561 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_R0, 0, SLJIT_R1, 0);
2562 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 16 * sizeof(sljit_uw), SLJIT_R0, 0);
2563 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, -1472797);
2564 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_R0, 0, SLJIT_S2, 0);
2565 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 17 * sizeof(sljit_uw), SLJIT_R0, 0);
2566 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -12890);
2567 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_R0, 0, SLJIT_R2, 0);
2568 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_uw), SLJIT_R0, 0);
2569 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0x9cb0a6);
2570 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_R4, 0, SLJIT_R3, 0);
2571 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 19 * sizeof(sljit_uw), SLJIT_R4, 0);
2573 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2574 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(-3580429715));
2575 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R1, 0);
2576 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 20 * sizeof(sljit_uw), SLJIT_R0, 0);
2577 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, SLJIT_W(-100722768662));
2578 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_S2, 0);
2579 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 21 * sizeof(sljit_uw), SLJIT_R0, 0);
2580 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, SLJIT_W(-1457052677972));
2581 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R2, 0);
2582 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 22 * sizeof(sljit_uw), SLJIT_R0, 0);
2583 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, SLJIT_W(0xcef97a70b5));
2584 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R4, 0, SLJIT_R3, 0);
2585 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 23 * sizeof(sljit_uw), SLJIT_R4, 0);
2586 #endif
2588 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, 0x9faa5);
2589 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_S2, 0, SLJIT_S2, 0);
2590 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 24 * sizeof(sljit_uw), SLJIT_S2, 0);
2592 sljit_emit_return_void(compiler);
2594 code.code = sljit_generate_code(compiler);
2595 CHECK(compiler);
2596 sljit_free_compiler(compiler);
2598 code.func1((sljit_sw)&buf);
2599 FAILED(buf[0] != 69, "test29 case 1 failed\n");
2600 FAILED(buf[1] != -93, "test29 case 2 failed\n");
2601 FAILED(buf[2] != 200, "test29 case 3 failed\n");
2602 FAILED(buf[3] != 0xe5, "test29 case 4 failed\n");
2603 FAILED(buf[4] != 19640, "test29 case 5 failed\n");
2604 FAILED(buf[5] != -31005, "test29 case 6 failed\n");
2605 FAILED(buf[6] != 52646, "test29 case 7 failed\n");
2606 FAILED(buf[7] != 0xb0a6, "test29 case 8 failed\n");
2608 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2609 FAILED(buf[8] != SLJIT_W(714537581), "test29 case 9 failed\n");
2610 FAILED(buf[9] != SLJIT_W(-1938520854), "test29 case 10 failed\n");
2611 FAILED(buf[10] != SLJIT_W(3236202668), "test29 case 11 failed\n");
2612 FAILED(buf[11] != SLJIT_W(0xf97a70b5), "test29 case 12 failed\n");
2613 #endif
2615 FAILED(buf[12] != 69, "test29 case 13 failed\n");
2616 FAILED(buf[13] != -93, "test29 case 14 failed\n");
2617 FAILED(buf[14] != 200, "test29 case 15 failed\n");
2618 FAILED(buf[15] != 0xe5, "test29 case 16 failed\n");
2619 FAILED(buf[16] != 19640, "test29 case 17 failed\n");
2620 FAILED(buf[17] != -31005, "test29 case 18 failed\n");
2621 FAILED(buf[18] != 52646, "test29 case 19 failed\n");
2622 FAILED(buf[19] != 0xb0a6, "test29 case 20 failed\n");
2624 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2625 FAILED(buf[20] != SLJIT_W(714537581), "test29 case 21 failed\n");
2626 FAILED(buf[21] != SLJIT_W(-1938520854), "test29 case 22 failed\n");
2627 FAILED(buf[22] != SLJIT_W(3236202668), "test29 case 23 failed\n");
2628 FAILED(buf[23] != SLJIT_W(0xf97a70b5), "test29 case 24 failed\n");
2629 #endif
2631 FAILED(buf[24] != -91, "test29 case 25 failed\n");
2633 sljit_free_code(code.code, NULL);
2634 successful_tests++;
2637 static void test30(void)
2639 /* Test unused results. */
2640 executable_code code;
2641 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
2642 sljit_sw buf[1];
2644 if (verbose)
2645 printf("Run test30\n");
2647 FAILED(!compiler, "cannot create compiler\n");
2648 buf[0] = 0;
2649 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 5, 5, 0, 0, 0);
2651 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
2652 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
2653 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 1);
2654 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 1);
2655 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_IMM, 1);
2656 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2657 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_S1, 0, SLJIT_IMM, SLJIT_W(-0x123ffffffff));
2658 #else
2659 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_S1, 0, SLJIT_IMM, 1);
2660 #endif
2661 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, 1);
2662 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, 1);
2663 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S4, 0, SLJIT_IMM, 1);
2665 /* Some calculations with unused results. */
2666 sljit_emit_op2u(compiler, SLJIT_ADD | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0);
2667 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_GREATER_EQUAL, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0);
2668 sljit_emit_op2u(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_S0, 0, SLJIT_MEM1(SLJIT_S0), 0);
2669 sljit_emit_op2u(compiler, SLJIT_SHL | SLJIT_SET_Z, SLJIT_S3, 0, SLJIT_R2, 0);
2670 sljit_emit_op2u(compiler, SLJIT_LSHR | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 5);
2671 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0xff);
2673 /* Testing that any change happens. */
2674 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2675 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R2, 0);
2676 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R3, 0);
2677 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R4, 0);
2678 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_S1, 0, SLJIT_S1, 0);
2679 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S1, 0);
2680 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S2, 0);
2681 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S3, 0);
2682 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0, SLJIT_S4, 0);
2684 sljit_emit_return_void(compiler);
2686 code.code = sljit_generate_code(compiler);
2687 CHECK(compiler);
2688 sljit_free_compiler(compiler);
2690 code.func1((sljit_sw)&buf);
2691 FAILED(buf[0] != 9, "test30 case 1 failed\n");
2693 sljit_free_code(code.code, NULL);
2694 successful_tests++;
2697 static void test31(void)
2699 /* Integer mul and set flags. */
2700 executable_code code;
2701 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
2702 sljit_sw buf[12];
2703 sljit_s32 i;
2704 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2705 sljit_sw big_word = SLJIT_W(0x7fffffff00000000);
2706 sljit_sw big_word2 = SLJIT_W(0x7fffffff00000012);
2707 #else
2708 sljit_sw big_word = 0x7fffffff;
2709 sljit_sw big_word2 = 0x00000012;
2710 #endif
2712 if (verbose)
2713 printf("Run test31\n");
2715 for (i = 0; i < 12; i++)
2716 buf[i] = 3;
2718 FAILED(!compiler, "cannot create compiler\n");
2720 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 3, 5, 0, 0, 0);
2721 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
2722 sljit_emit_op2u(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_IMM, -45);
2723 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_NOT_OVERFLOW);
2724 sljit_emit_op2u(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_IMM, -45);
2725 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_OVERFLOW);
2727 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, big_word);
2728 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, -2);
2729 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 33); /* Should not change flags. */
2730 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0); /* Should not change flags. */
2731 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_OVERFLOW);
2732 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, -2);
2733 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_NOT_OVERFLOW);
2735 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_S3, 0, SLJIT_IMM, 0x3f6b0);
2736 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_S4, 0, SLJIT_IMM, 0x2a783);
2737 sljit_emit_op2(compiler, SLJIT_MUL32 | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_S3, 0, SLJIT_S4, 0);
2738 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_OVERFLOW);
2739 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R1, 0);
2741 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, big_word2);
2742 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R2, 0, SLJIT_R1, 0);
2743 sljit_emit_op2(compiler, SLJIT_MUL32 | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 23);
2744 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_OVERFLOW);
2746 sljit_emit_op2u(compiler, SLJIT_MUL32 | SLJIT_SET_OVERFLOW, SLJIT_R2, 0, SLJIT_IMM, -23);
2747 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_NOT_OVERFLOW);
2748 sljit_emit_op2u(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_R2, 0, SLJIT_IMM, -23);
2749 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_NOT_OVERFLOW);
2751 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 67);
2752 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, -23);
2753 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_R1, 0);
2755 sljit_emit_return_void(compiler);
2757 code.code = sljit_generate_code(compiler);
2758 CHECK(compiler);
2759 sljit_free_compiler(compiler);
2761 code.func1((sljit_sw)&buf);
2763 FAILED(buf[0] != 1, "test31 case 1 failed\n");
2764 FAILED(buf[1] != 2, "test31 case 2 failed\n");
2765 /* Qemu issues for 64 bit muls. */
2766 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2767 FAILED(buf[2] != 1, "test31 case 3 failed\n");
2768 FAILED(buf[3] != 2, "test31 case 4 failed\n");
2769 #endif
2770 FAILED(buf[4] != 1, "test31 case 5 failed\n");
2771 FAILED((buf[5] & (sljit_sw)0xffffffff) != (sljit_sw)0x85540c10, "test31 case 6 failed\n");
2772 FAILED(buf[6] != 2, "test31 case 7 failed\n");
2773 FAILED(buf[7] != 1, "test31 case 8 failed\n");
2774 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2775 FAILED(buf[8] != 1, "test31 case 9 failed\n");
2776 #endif
2777 FAILED(buf[9] != -1541, "test31 case 10 failed\n");
2779 sljit_free_code(code.code, NULL);
2780 successful_tests++;
2783 static void test32(void)
2785 /* Floating point set flags. */
2786 executable_code code;
2787 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
2788 sljit_s32 i;
2790 sljit_sw buf[16];
2791 union {
2792 sljit_f64 value;
2793 struct {
2794 sljit_s32 value1;
2795 sljit_s32 value2;
2796 } u;
2797 } dbuf[4];
2799 if (verbose)
2800 printf("Run test32\n");
2802 for (i = 0; i < 16; i++)
2803 buf[i] = 5;
2805 /* Two NaNs */
2806 dbuf[0].u.value1 = 0x7fffffff;
2807 dbuf[0].u.value2 = 0x7fffffff;
2808 dbuf[1].u.value1 = 0x7fffffff;
2809 dbuf[1].u.value2 = 0x7fffffff;
2810 dbuf[2].value = -13.0;
2811 dbuf[3].value = 27.0;
2813 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
2814 if (verbose)
2815 printf("no fpu available, test32 skipped\n");
2816 successful_tests++;
2817 if (compiler)
2818 sljit_free_compiler(compiler);
2819 return;
2822 FAILED(!compiler, "cannot create compiler\n");
2823 SLJIT_ASSERT(sizeof(sljit_f64) == 8 && sizeof(sljit_s32) == 4 && sizeof(dbuf[0]) == 8);
2825 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(VOID, P, P), 1, 2, 4, 0, 0);
2827 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), 0);
2828 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_UNORDERED_F, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64), SLJIT_FR0, 0);
2829 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f64));
2830 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_UNORDERED_F64);
2831 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_ORDERED_F, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64), SLJIT_FR0, 0);
2832 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_ORDERED_F64);
2834 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64));
2835 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_UNORDERED_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2836 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_UNORDERED_F64);
2837 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_ORDERED_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2838 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_ORDERED_F64);
2839 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_LESS_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2840 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_LESS_F64);
2841 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_GREATER_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2842 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_GREATER_EQUAL_F64);
2843 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_GREATER_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2844 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_GREATER_F64);
2845 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_LESS_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2846 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_LESS_EQUAL_F64);
2847 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2848 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_EQUAL_F64);
2849 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_NOT_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2850 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_NOT_EQUAL_F64);
2852 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_UNORDERED_F, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64));
2853 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR3, 0, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f64));
2854 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_UNORDERED_F64);
2855 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_EQUAL_F, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64));
2856 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_EQUAL_F64);
2858 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_ORDERED_F, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f64), SLJIT_FR0, 0);
2859 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_ORDERED_F64);
2861 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_UNORDERED_F, SLJIT_FR3, 0, SLJIT_FR2, 0);
2862 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), 0);
2863 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_UNORDERED_F64);
2865 sljit_emit_return_void(compiler);
2867 code.code = sljit_generate_code(compiler);
2868 CHECK(compiler);
2869 sljit_free_compiler(compiler);
2871 code.func2((sljit_sw)&buf, (sljit_sw)&dbuf);
2873 FAILED(buf[0] != 1, "test32 case 1 failed\n");
2874 FAILED(buf[1] != 2, "test32 case 2 failed\n");
2875 FAILED(buf[2] != 2, "test32 case 3 failed\n");
2876 FAILED(buf[3] != 1, "test32 case 4 failed\n");
2877 FAILED(buf[4] != 1, "test32 case 5 failed\n");
2878 FAILED(buf[5] != 2, "test32 case 6 failed\n");
2879 FAILED(buf[6] != 2, "test32 case 7 failed\n");
2880 FAILED(buf[7] != 1, "test32 case 8 failed\n");
2881 FAILED(buf[8] != 2, "test32 case 9 failed\n");
2882 FAILED(buf[9] != 1, "test32 case 10 failed\n");
2883 FAILED(buf[10] != 2, "test32 case 11 failed\n");
2884 FAILED(buf[11] != 1, "test32 case 12 failed\n");
2885 FAILED(buf[12] != 2, "test32 case 13 failed\n");
2886 FAILED(buf[13] != 1, "test32 case 14 failed\n");
2888 sljit_free_code(code.code, NULL);
2889 successful_tests++;
2892 static void test33(void)
2894 /* Test setting multiple flags. */
2895 executable_code code;
2896 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
2897 struct sljit_jump* jump;
2898 sljit_sw buf[10];
2900 if (verbose)
2901 printf("Run test33\n");
2903 buf[0] = 3;
2904 buf[1] = 3;
2905 buf[2] = 3;
2906 buf[3] = 3;
2907 buf[4] = 3;
2908 buf[5] = 3;
2909 buf[6] = 3;
2910 buf[7] = 3;
2911 buf[8] = 3;
2912 buf[9] = 3;
2914 FAILED(!compiler, "cannot create compiler\n");
2916 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 3, 3, 0, 0, 0);
2918 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 20);
2919 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 10);
2920 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2921 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_ZERO);
2922 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -10);
2923 jump = sljit_emit_jump(compiler, SLJIT_LESS);
2924 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, 11);
2925 sljit_set_label(jump, sljit_emit_label(compiler));
2927 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_SIG_GREATER, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2928 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_SIG_GREATER);
2929 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_IMM, 45);
2930 jump = sljit_emit_jump(compiler, SLJIT_NOT_EQUAL);
2931 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_IMM, 55);
2932 sljit_set_label(jump, sljit_emit_label(compiler));
2934 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2935 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)SLJIT_W(0x8000000000000000));
2936 #else
2937 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)SLJIT_W(0x80000000));
2938 #endif
2939 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
2940 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2941 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_IMM, 33);
2942 jump = sljit_emit_jump(compiler, SLJIT_NOT_OVERFLOW);
2943 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_ZERO);
2944 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_IMM, 13);
2945 sljit_set_label(jump, sljit_emit_label(compiler));
2947 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)0x80000000);
2948 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_R0, 0);
2949 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2950 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 0);
2951 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_NOT_ZERO);
2952 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_IMM, 78);
2953 jump = sljit_emit_jump(compiler, SLJIT_OVERFLOW);
2954 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_IMM, 48);
2955 sljit_set_label(jump, sljit_emit_label(compiler));
2957 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2958 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)SLJIT_W(0x8000000000000000));
2959 #else
2960 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)SLJIT_W(0x80000000));
2961 #endif
2962 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_R0, 0);
2963 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2964 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_IMM, 30);
2965 jump = sljit_emit_jump(compiler, SLJIT_NOT_OVERFLOW);
2966 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_IMM, 50);
2967 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_ZERO);
2968 sljit_set_label(jump, sljit_emit_label(compiler));
2970 sljit_emit_return_void(compiler);
2972 code.code = sljit_generate_code(compiler);
2973 CHECK(compiler);
2974 sljit_free_compiler(compiler);
2976 code.func1((sljit_sw)&buf);
2978 FAILED(buf[0] != 0, "test33 case 1 failed\n");
2979 FAILED(buf[1] != 11, "test33 case 2 failed\n");
2980 FAILED(buf[2] != 1, "test33 case 3 failed\n");
2981 FAILED(buf[3] != 45, "test33 case 4 failed\n");
2982 FAILED(buf[4] != 13, "test33 case 5 failed\n");
2983 FAILED(buf[5] != 0, "test33 case 6 failed\n");
2984 FAILED(buf[6] != 0, "test33 case 7 failed\n");
2985 FAILED(buf[7] != 48, "test33 case 8 failed\n");
2986 FAILED(buf[8] != 50, "test33 case 9 failed\n");
2987 FAILED(buf[9] != 1, "test33 case 10 failed\n");
2989 sljit_free_code(code.code, NULL);
2990 successful_tests++;
2993 static void test34(void)
2995 /* Test fast calls. */
2996 executable_code codeA;
2997 executable_code codeB;
2998 executable_code codeC;
2999 executable_code codeD;
3000 executable_code codeE;
3001 executable_code codeF;
3002 struct sljit_compiler* compiler;
3003 struct sljit_jump *jump;
3004 struct sljit_label* label;
3005 sljit_uw addr;
3006 sljit_p buf[2];
3008 if (verbose)
3009 printf("Run test34\n");
3011 buf[0] = 0;
3012 buf[1] = 0;
3014 /* A */
3015 compiler = sljit_create_compiler(NULL, NULL);
3016 FAILED(!compiler, "cannot create compiler\n");
3017 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3019 sljit_emit_op0(compiler, SLJIT_ENDBR);
3020 sljit_emit_fast_enter(compiler, SLJIT_R1, 0);
3021 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 4);
3022 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_R1, 0);
3024 codeA.code = sljit_generate_code(compiler);
3025 CHECK(compiler);
3026 sljit_free_compiler(compiler);
3028 /* B */
3029 compiler = sljit_create_compiler(NULL, NULL);
3030 FAILED(!compiler, "cannot create compiler\n");
3031 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3033 sljit_emit_op0(compiler, SLJIT_ENDBR);
3034 sljit_emit_fast_enter(compiler, SLJIT_R4, 0);
3035 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 6);
3036 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(codeA.code));
3037 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_R1, 0);
3038 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_R4, 0);
3040 codeB.code = sljit_generate_code(compiler);
3041 CHECK(compiler);
3042 sljit_free_compiler(compiler);
3044 /* C */
3045 compiler = sljit_create_compiler(NULL, NULL);
3046 FAILED(!compiler, "cannot create compiler\n");
3047 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3049 sljit_emit_op0(compiler, SLJIT_ENDBR);
3050 sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_p));
3051 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 8);
3052 jump = sljit_emit_jump(compiler, SLJIT_FAST_CALL | SLJIT_REWRITABLE_JUMP);
3053 sljit_set_target(jump, SLJIT_FUNC_UADDR(codeB.code));
3054 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_p));
3056 codeC.code = sljit_generate_code(compiler);
3057 CHECK(compiler);
3058 sljit_free_compiler(compiler);
3060 /* D */
3061 compiler = sljit_create_compiler(NULL, NULL);
3062 FAILED(!compiler, "cannot create compiler\n");
3063 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3065 sljit_emit_op0(compiler, SLJIT_ENDBR);
3066 sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_SP), 0);
3067 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 10);
3068 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_ADDR(codeC.code));
3069 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_MEM1(SLJIT_SP), 0);
3071 codeD.code = sljit_generate_code(compiler);
3072 CHECK(compiler);
3073 sljit_free_compiler(compiler);
3075 /* E */
3076 compiler = sljit_create_compiler(NULL, NULL);
3077 FAILED(!compiler, "cannot create compiler\n");
3078 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3080 sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_S0), 0);
3081 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 12);
3082 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_p), SLJIT_IMM, SLJIT_FUNC_ADDR(codeD.code));
3083 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_p));
3084 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_MEM1(SLJIT_S0), 0);
3086 codeE.code = sljit_generate_code(compiler);
3087 CHECK(compiler);
3088 sljit_free_compiler(compiler);
3090 /* F */
3091 compiler = sljit_create_compiler(NULL, NULL);
3092 FAILED(!compiler, "cannot create compiler\n");
3094 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 5, 5, 0, 0, 2 * sizeof(sljit_p));
3095 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
3096 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_ADDR(codeE.code));
3097 label = sljit_emit_label(compiler);
3098 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
3100 codeF.code = sljit_generate_code(compiler);
3101 CHECK(compiler);
3102 addr = sljit_get_label_addr(label);
3103 sljit_free_compiler(compiler);
3105 FAILED(codeF.func1((sljit_sw)&buf) != 40, "test34 case 1 failed\n");
3106 FAILED(buf[0] != addr - SLJIT_RETURN_ADDRESS_OFFSET, "test34 case 2 failed\n");
3108 sljit_free_code(codeA.code, NULL);
3109 sljit_free_code(codeB.code, NULL);
3110 sljit_free_code(codeC.code, NULL);
3111 sljit_free_code(codeD.code, NULL);
3112 sljit_free_code(codeE.code, NULL);
3113 sljit_free_code(codeF.code, NULL);
3114 successful_tests++;
3117 static void test35(void)
3119 /* More complicated tests for fast calls. */
3120 executable_code codeA;
3121 executable_code codeB;
3122 executable_code codeC;
3123 struct sljit_compiler* compiler;
3124 struct sljit_jump *jump = NULL;
3125 struct sljit_label* label;
3126 sljit_sw executable_offset;
3127 sljit_uw return_addr;
3128 sljit_uw jump_addr = 0;
3129 sljit_p buf[1];
3131 if (verbose)
3132 printf("Run test35\n");
3134 buf[0] = 0;
3136 /* A */
3137 compiler = sljit_create_compiler(NULL, NULL);
3138 FAILED(!compiler, "cannot create compiler\n");
3139 sljit_set_context(compiler, 0, 0, 2, 2, 0, 0, 0);
3141 sljit_emit_fast_enter(compiler, SLJIT_MEM0(), (sljit_sw)&buf[0]);
3142 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 5);
3144 jump = sljit_emit_jump(compiler, SLJIT_FAST_CALL | SLJIT_REWRITABLE_JUMP);
3145 sljit_set_target(jump, 0);
3147 label = sljit_emit_label(compiler);
3148 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_MEM0(), (sljit_sw)&buf[0]);
3150 codeA.code = sljit_generate_code(compiler);
3151 CHECK(compiler);
3152 executable_offset = sljit_get_executable_offset(compiler);
3153 jump_addr = sljit_get_jump_addr(jump);
3154 sljit_free_compiler(compiler);
3156 /* B */
3157 compiler = sljit_create_compiler(NULL, NULL);
3158 FAILED(!compiler, "cannot create compiler\n");
3159 sljit_set_context(compiler, 0, 0, 2, 2, 0, 0, 0);
3161 sljit_emit_op0(compiler, SLJIT_ENDBR);
3162 sljit_emit_fast_enter(compiler, SLJIT_R1, 0);
3163 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 7);
3164 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_R1, 0);
3166 codeB.code = sljit_generate_code(compiler);
3167 CHECK(compiler);
3168 sljit_free_compiler(compiler);
3170 sljit_set_jump_addr(jump_addr, SLJIT_FUNC_UADDR(codeB.code), executable_offset);
3172 /* C */
3173 compiler = sljit_create_compiler(NULL, NULL);
3174 FAILED(!compiler, "cannot create compiler\n");
3176 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(W), 2, 2, 0, 0, 0);
3177 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
3178 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_ADDR(codeA.code));
3179 label = sljit_emit_label(compiler);
3180 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
3182 codeC.code = sljit_generate_code(compiler);
3183 CHECK(compiler);
3184 return_addr = sljit_get_label_addr(label);
3185 sljit_free_compiler(compiler);
3187 FAILED(codeC.func0() != 12, "test35 case 1 failed\n");
3188 FAILED(buf[0] != return_addr - SLJIT_RETURN_ADDRESS_OFFSET, "test35 case 2 failed\n");
3190 sljit_free_code(codeA.code, NULL);
3191 sljit_free_code(codeB.code, NULL);
3192 sljit_free_code(codeC.code, NULL);
3193 successful_tests++;
3196 static void cmp_test(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src1, sljit_sw src1w, sljit_s32 src2, sljit_sw src2w)
3198 /* 2 = true, 1 = false */
3199 struct sljit_jump* jump;
3200 struct sljit_label* label;
3202 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_IMM, 2);
3203 jump = sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w);
3204 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_IMM, 1);
3205 label = sljit_emit_label(compiler);
3206 sljit_emit_op0(compiler, SLJIT_ENDBR);
3207 sljit_set_label(jump, label);
3208 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
3211 #define TEST_CASES (7 + 10 + 12 + 11 + 4)
3212 static void test36(void)
3214 /* Compare instruction. */
3215 executable_code code;
3216 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
3218 sljit_s8 buf[TEST_CASES];
3219 sljit_s8 compare_buf[TEST_CASES] = {
3220 1, 1, 2, 2, 1, 2, 2,
3221 1, 1, 2, 2, 2, 1, 2, 2, 1, 1,
3222 2, 2, 2, 1, 2, 2, 2, 2, 1, 1, 2, 2,
3223 2, 1, 2, 1, 1, 1, 2, 1, 2, 1, 2,
3224 2, 1, 1, 2
3226 sljit_sw data[4];
3227 sljit_s32 i;
3229 if (verbose)
3230 printf("Run test36\n");
3232 FAILED(!compiler, "cannot create compiler\n");
3233 for (i = 0; i < TEST_CASES; ++i)
3234 buf[i] = 100;
3235 data[0] = 32;
3236 data[1] = -9;
3237 data[2] = 43;
3238 data[3] = -13;
3240 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(VOID, P, P), 3, 2, 0, 0, 0);
3241 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
3243 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 13);
3244 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 15);
3245 cmp_test(compiler, SLJIT_EQUAL, SLJIT_IMM, 9, SLJIT_R0, 0);
3246 cmp_test(compiler, SLJIT_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3247 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 3);
3248 cmp_test(compiler, SLJIT_EQUAL, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_IMM, -13);
3249 cmp_test(compiler, SLJIT_NOT_EQUAL, SLJIT_IMM, 0, SLJIT_R0, 0);
3250 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
3251 cmp_test(compiler, SLJIT_NOT_EQUAL | SLJIT_REWRITABLE_JUMP, SLJIT_IMM, 0, SLJIT_R0, 0);
3252 cmp_test(compiler, SLJIT_EQUAL, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT);
3253 cmp_test(compiler, SLJIT_EQUAL | SLJIT_REWRITABLE_JUMP, SLJIT_R0, 0, SLJIT_IMM, 0);
3255 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, 0);
3256 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -8);
3257 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
3258 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_R0, 0, SLJIT_IMM, 0);
3259 cmp_test(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 0);
3260 cmp_test(compiler, SLJIT_SIG_LESS | SLJIT_REWRITABLE_JUMP, SLJIT_R0, 0, SLJIT_IMM, 0);
3261 cmp_test(compiler, SLJIT_SIG_GREATER_EQUAL, SLJIT_R1, 0, SLJIT_IMM, 0);
3262 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_sw));
3263 cmp_test(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_IMM, 0, SLJIT_R1, 0);
3264 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_sw));
3265 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw));
3266 cmp_test(compiler, SLJIT_SIG_LESS | SLJIT_REWRITABLE_JUMP, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw));
3268 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
3269 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
3270 cmp_test(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_sw));
3271 cmp_test(compiler, SLJIT_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 8);
3272 cmp_test(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_IMM, -10);
3273 cmp_test(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_IMM, 8);
3274 cmp_test(compiler, SLJIT_GREATER_EQUAL, SLJIT_IMM, 8, SLJIT_R1, 0);
3275 cmp_test(compiler, SLJIT_GREATER_EQUAL | SLJIT_REWRITABLE_JUMP, SLJIT_IMM, 8, SLJIT_R1, 0);
3276 cmp_test(compiler, SLJIT_GREATER, SLJIT_IMM, 8, SLJIT_R1, 0);
3277 cmp_test(compiler, SLJIT_LESS_EQUAL, SLJIT_IMM, 7, SLJIT_R0, 0);
3278 cmp_test(compiler, SLJIT_GREATER, SLJIT_IMM, 1, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw));
3279 cmp_test(compiler, SLJIT_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3280 cmp_test(compiler, SLJIT_GREATER, SLJIT_R0, 0, SLJIT_R1, 0);
3281 cmp_test(compiler, SLJIT_GREATER | SLJIT_REWRITABLE_JUMP, SLJIT_R0, 0, SLJIT_R1, 0);
3283 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -3);
3284 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
3285 cmp_test(compiler, SLJIT_SIG_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3286 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_R0, 0, SLJIT_IMM, -1);
3287 cmp_test(compiler, SLJIT_SIG_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 1);
3288 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, -1);
3289 cmp_test(compiler, SLJIT_SIG_LESS | SLJIT_REWRITABLE_JUMP, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, -1);
3290 cmp_test(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3291 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_R0, 0, SLJIT_R1, 0);
3292 cmp_test(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_IMM, -4, SLJIT_R0, 0);
3293 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_IMM, -1, SLJIT_R1, 0);
3294 cmp_test(compiler, SLJIT_SIG_GREATER | SLJIT_REWRITABLE_JUMP, SLJIT_R1, 0, SLJIT_IMM, -1);
3296 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3297 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xf00000004));
3298 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_R0, 0);
3299 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_R1, 0);
3300 cmp_test(compiler, SLJIT_LESS | SLJIT_32, SLJIT_R1, 0, SLJIT_IMM, 5);
3301 cmp_test(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_IMM, 5);
3302 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xff0000004));
3303 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_R0, 0);
3304 cmp_test(compiler, SLJIT_SIG_GREATER | SLJIT_32, SLJIT_R1, 0, SLJIT_IMM, 5);
3305 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_R0, 0, SLJIT_IMM, 5);
3306 #else
3307 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 4);
3308 cmp_test(compiler, SLJIT_LESS | SLJIT_32, SLJIT_R0, 0, SLJIT_IMM, 5);
3309 cmp_test(compiler, SLJIT_GREATER | SLJIT_32, SLJIT_R0, 0, SLJIT_IMM, 5);
3310 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)0xf0000004);
3311 cmp_test(compiler, SLJIT_SIG_GREATER | SLJIT_32, SLJIT_R0, 0, SLJIT_IMM, 5);
3312 cmp_test(compiler, SLJIT_SIG_LESS | SLJIT_32, SLJIT_R0, 0, SLJIT_IMM, 5);
3313 #endif
3315 sljit_emit_return_void(compiler);
3317 code.code = sljit_generate_code(compiler);
3318 CHECK(compiler);
3319 sljit_free_compiler(compiler);
3321 code.func2((sljit_sw)&buf, (sljit_sw)&data);
3323 for (i = 0; i < TEST_CASES; ++i)
3324 if (SLJIT_UNLIKELY(buf[i] != compare_buf[i])) {
3325 printf("test36 case %d failed\n", i + 1);
3326 return;
3329 sljit_free_code(code.code, NULL);
3330 successful_tests++;
3332 #undef TEST_CASES
3334 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3335 #define BITN(n) (SLJIT_W(1) << (63 - (n)))
3336 #define RESN(n) (n)
3337 #else
3338 #define BITN(n) (1 << (31 - ((n) & 0x1f)))
3339 #define RESN(n) ((n) & 0x1f)
3340 #endif
3342 static void test37(void)
3344 /* Test count leading zeroes. */
3345 executable_code code;
3346 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
3347 sljit_sw buf[9];
3348 sljit_s32 ibuf[2];
3349 sljit_s32 i;
3351 if (verbose)
3352 printf("Run test37\n");
3354 FAILED(!compiler, "cannot create compiler\n");
3356 for (i = 0; i < 9; i++)
3357 buf[i] = -1;
3358 buf[2] = 0;
3359 buf[4] = BITN(13);
3360 ibuf[0] = -1;
3361 ibuf[1] = -1;
3362 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(VOID, P, P), 1, 3, 0, 0, 0);
3363 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, BITN(27));
3364 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
3365 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, BITN(47));
3366 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_R0, 0, SLJIT_S2, 0);
3367 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
3368 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw));
3369 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
3370 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_R0, 0, SLJIT_R0, 0);
3371 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_R0, 0);
3372 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0);
3373 sljit_emit_op1(compiler, SLJIT_CLZ32, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_R0, 0);
3374 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
3375 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw));
3376 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
3377 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, BITN(58));
3378 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R0, 0);
3379 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
3380 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_R0, 0);
3381 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3382 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xff08a00000));
3383 #else
3384 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x08a00000);
3385 #endif
3386 sljit_emit_op1(compiler, SLJIT_CLZ32, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32), SLJIT_R0, 0);
3387 sljit_emit_op1(compiler, SLJIT_CLZ32, SLJIT_R0, 0, SLJIT_R0, 0);
3388 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R0, 0);
3389 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3390 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xffc8a00000));
3391 #else
3392 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)0xc8a00000);
3393 #endif
3394 sljit_emit_op1(compiler, SLJIT_CLZ32, SLJIT_R0, 0, SLJIT_R0, 0);
3395 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R0, 0);
3397 sljit_emit_return_void(compiler);
3399 code.code = sljit_generate_code(compiler);
3400 CHECK(compiler);
3401 sljit_free_compiler(compiler);
3403 code.func2((sljit_sw)&buf, (sljit_sw)&ibuf);
3404 FAILED(buf[0] != RESN(27), "test37 case 1 failed\n");
3405 FAILED(buf[1] != RESN(47), "test37 case 2 failed\n");
3406 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3407 FAILED(buf[2] != 64, "test37 case 3 failed\n");
3408 #else
3409 FAILED(buf[2] != 32, "test37 case 3 failed\n");
3410 #endif
3411 FAILED(buf[3] != 0, "test37 case 4 failed\n");
3412 FAILED(ibuf[0] != 32, "test37 case 5 failed\n");
3413 FAILED(buf[4] != RESN(13), "test37 case 6 failed\n");
3414 FAILED(buf[5] != RESN(58), "test37 case 7 failed\n");
3415 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3416 FAILED(buf[6] != 64, "test37 case 8 failed\n");
3417 #else
3418 FAILED(buf[6] != 32, "test37 case 8 failed\n");
3419 #endif
3420 FAILED(ibuf[1] != 4, "test37 case 9 failed\n");
3422 FAILED((buf[7] & (sljit_sw)0xffffffff) != 4, "test37 case 10 failed\n");
3423 FAILED((buf[8] & (sljit_sw)0xffffffff) != 0, "test37 case 11 failed\n");
3425 sljit_free_code(code.code, NULL);
3426 successful_tests++;
3428 #undef BITN
3429 #undef RESN
3431 static void test38(void)
3433 #if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK)
3434 /* Test stack utility. */
3435 executable_code code;
3436 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
3437 struct sljit_jump* alloc1_fail;
3438 struct sljit_jump* alloc2_fail;
3439 struct sljit_jump* alloc3_fail;
3440 struct sljit_jump* sanity1_fail;
3441 struct sljit_jump* sanity2_fail;
3442 struct sljit_jump* sanity3_fail;
3443 struct sljit_jump* sanity4_fail;
3444 struct sljit_jump* jump;
3445 struct sljit_label* label;
3447 if (verbose)
3448 printf("Run test38\n");
3450 FAILED(!compiler, "cannot create compiler\n");
3452 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(W), 3, 1, 0, 0, 0);
3454 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8192);
3455 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 65536);
3456 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 0);
3457 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS3(P, W, W, P), SLJIT_IMM, SLJIT_FUNC_ADDR(sljit_allocate_stack));
3458 alloc1_fail = sljit_emit_cmp(compiler, SLJIT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
3459 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_RETURN_REG, 0);
3461 /* Write 8k data. */
3462 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, start));
3463 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 8192);
3464 label = sljit_emit_label(compiler);
3465 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_IMM, -1);
3466 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw));
3467 jump = sljit_emit_cmp(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
3468 sljit_set_label(jump, label);
3470 /* Grow stack. */
3471 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
3472 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, end), SLJIT_IMM, 65536);
3473 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS2(P, P, P), SLJIT_IMM, SLJIT_FUNC_ADDR(sljit_stack_resize));
3474 alloc2_fail = sljit_emit_cmp(compiler, SLJIT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
3475 sanity1_fail = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, start));
3477 /* Write 64k data. */
3478 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, start));
3479 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 65536);
3480 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, min_start));
3481 sanity2_fail = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_R0, 0, SLJIT_R2, 0);
3482 label = sljit_emit_label(compiler);
3483 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_IMM, -1);
3484 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw));
3485 jump = sljit_emit_cmp(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
3486 sljit_set_label(jump, label);
3488 /* Shrink stack. */
3489 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
3490 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, end), SLJIT_IMM, 32768);
3491 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS2(P, P, P), SLJIT_IMM, SLJIT_FUNC_ADDR(sljit_stack_resize));
3492 alloc3_fail = sljit_emit_cmp(compiler, SLJIT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
3493 sanity3_fail = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, start));
3495 /* Write 32k data. */
3496 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, start));
3497 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, end));
3498 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R2, 0, SLJIT_R1, 0, SLJIT_IMM, 32768);
3499 sanity4_fail = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_R0, 0, SLJIT_R2, 0);
3500 label = sljit_emit_label(compiler);
3501 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_IMM, -1);
3502 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw));
3503 jump = sljit_emit_cmp(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
3504 sljit_set_label(jump, label);
3506 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
3507 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
3508 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS2(VOID, P, P), SLJIT_IMM, SLJIT_FUNC_ADDR(sljit_free_stack));
3510 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, 4567);
3512 label = sljit_emit_label(compiler);
3513 sljit_set_label(alloc1_fail, label);
3514 sljit_set_label(alloc2_fail, label);
3515 sljit_set_label(alloc3_fail, label);
3516 sljit_set_label(sanity1_fail, label);
3517 sljit_set_label(sanity2_fail, label);
3518 sljit_set_label(sanity3_fail, label);
3519 sljit_set_label(sanity4_fail, label);
3520 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, 0);
3522 code.code = sljit_generate_code(compiler);
3523 CHECK(compiler);
3524 sljit_free_compiler(compiler);
3526 /* Just survive this. */
3527 FAILED(code.func0() != 4567, "test38 case 1 failed\n");
3529 sljit_free_code(code.code, NULL);
3530 #endif
3531 successful_tests++;
3534 static void test39(void)
3536 /* Test error handling. */
3537 executable_code code;
3538 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
3539 struct sljit_jump* jump;
3541 if (verbose)
3542 printf("Run test39\n");
3544 FAILED(!compiler, "cannot create compiler\n");
3546 /* Such assignment should never happen in a regular program. */
3547 compiler->error = -3967;
3549 SLJIT_ASSERT(sljit_emit_enter(compiler, 0, SLJIT_ARGS2(VOID, W, W), 5, 5, 6, 0, 32) == -3967);
3550 SLJIT_ASSERT(sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R1, 0) == -3967);
3551 SLJIT_ASSERT(sljit_emit_op0(compiler, SLJIT_NOP) == -3967);
3552 SLJIT_ASSERT(sljit_emit_op0(compiler, SLJIT_ENDBR) == -3967);
3553 SLJIT_ASSERT(sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), 1) == -3967);
3554 SLJIT_ASSERT(sljit_emit_op2(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R0), 64, SLJIT_MEM1(SLJIT_S0), -64) == -3967);
3555 SLJIT_ASSERT(sljit_emit_fop1(compiler, SLJIT_ABS_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_R1), 0) == -3967);
3556 SLJIT_ASSERT(sljit_emit_fop2(compiler, SLJIT_DIV_F64, SLJIT_FR2, 0, SLJIT_MEM2(SLJIT_R0, SLJIT_S0), 0, SLJIT_FR2, 0) == -3967);
3557 SLJIT_ASSERT(!sljit_emit_label(compiler));
3558 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS4(W, 32, P, F32, F64));
3559 SLJIT_ASSERT(!jump);
3560 sljit_set_label(jump, (struct sljit_label*)0x123450);
3561 sljit_set_target(jump, 0x123450);
3562 jump = sljit_emit_cmp(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3563 SLJIT_ASSERT(!jump);
3564 SLJIT_ASSERT(sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_MEM1(SLJIT_R0), 8) == -3967);
3565 SLJIT_ASSERT(sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_OVERFLOW) == -3967);
3566 SLJIT_ASSERT(!sljit_emit_const(compiler, SLJIT_R0, 0, 99));
3568 SLJIT_ASSERT(!compiler->labels && !compiler->jumps && !compiler->consts);
3569 SLJIT_ASSERT(!compiler->last_label && !compiler->last_jump && !compiler->last_const);
3570 SLJIT_ASSERT(!compiler->buf->next && !compiler->buf->used_size);
3571 SLJIT_ASSERT(!compiler->abuf->next && !compiler->abuf->used_size);
3573 sljit_set_compiler_memory_error(compiler);
3574 FAILED(sljit_get_compiler_error(compiler) != -3967, "test39 case 1 failed\n");
3576 code.code = sljit_generate_code(compiler);
3577 FAILED(sljit_get_compiler_error(compiler) != -3967, "test39 case 2 failed\n");
3578 FAILED(!!code.code, "test39 case 3 failed\n");
3579 sljit_free_compiler(compiler);
3581 compiler = sljit_create_compiler(NULL, NULL);
3582 FAILED(!compiler, "cannot create compiler\n");
3584 FAILED(sljit_get_compiler_error(compiler) != SLJIT_SUCCESS, "test39 case 4 failed\n");
3585 sljit_set_compiler_memory_error(compiler);
3586 FAILED(sljit_get_compiler_error(compiler) != SLJIT_ERR_ALLOC_FAILED, "test39 case 5 failed\n");
3587 sljit_free_compiler(compiler);
3589 successful_tests++;
3592 static void test40(void)
3594 /* Test emit_op_flags. */
3595 executable_code code;
3596 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
3597 sljit_sw buf[10];
3599 if (verbose)
3600 printf("Run test40\n");
3602 FAILED(!compiler, "cannot create compiler\n");
3603 buf[0] = -100;
3604 buf[1] = -100;
3605 buf[2] = -100;
3606 buf[3] = -8;
3607 buf[4] = -100;
3608 buf[5] = -100;
3609 buf[6] = 0;
3610 buf[7] = 0;
3611 buf[8] = -100;
3612 buf[9] = -100;
3614 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 4, 0, 0, sizeof(sljit_sw));
3616 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -5);
3617 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_IMM, -6, SLJIT_R0, 0);
3618 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x123456);
3619 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_SIG_LESS);
3620 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R1, 0);
3622 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -13);
3623 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_IMM, -13, SLJIT_R0, 0);
3624 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, 0);
3625 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_EQUAL);
3626 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_NOT_EQUAL);
3627 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);
3628 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_IMM, -13, SLJIT_R0, 0);
3629 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
3630 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_EQUAL);
3631 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_EQUAL);
3633 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -13);
3634 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 3);
3635 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R1, 0);
3636 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_MEM2(SLJIT_S0, SLJIT_R1), SLJIT_WORD_SHIFT, SLJIT_SIG_LESS);
3638 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -8);
3639 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 33);
3640 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_R0, 0, SLJIT_R1, 0);
3641 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, 0);
3642 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_R2, 0, SLJIT_GREATER);
3643 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_S1, 0, SLJIT_EQUAL);
3644 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R1, 0);
3645 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, 0x88);
3646 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_S3, 0, SLJIT_NOT_EQUAL);
3647 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_S1, 0);
3648 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_S3, 0);
3650 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x84);
3651 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_IMM, 0x180, SLJIT_R0, 0);
3652 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_EQUAL);
3653 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_EQUAL);
3655 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
3656 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_IMM, 1);
3657 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_NOT_EQUAL);
3658 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_NOT_EQUAL);
3660 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x123456);
3661 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_R0, 0, SLJIT_IMM, 1);
3662 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_R0, 0, SLJIT_GREATER);
3663 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 9, SLJIT_R0, 0);
3665 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, 0xbaddead);
3666 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0);
3668 code.code = sljit_generate_code(compiler);
3669 CHECK(compiler);
3670 sljit_free_compiler(compiler);
3672 FAILED(code.func1((sljit_sw)&buf) != 0xbaddead, "test40 case 1 failed\n");
3673 FAILED(buf[0] != 0x123457, "test40 case 2 failed\n");
3674 FAILED(buf[1] != 1, "test40 case 3 failed\n");
3675 FAILED(buf[2] != 0, "test40 case 4 failed\n");
3676 FAILED(buf[3] != -7, "test40 case 5 failed\n");
3677 FAILED(buf[4] != 0, "test40 case 6 failed\n");
3678 FAILED(buf[5] != 0x89, "test40 case 7 failed\n");
3679 FAILED(buf[6] != 0, "test40 case 8 failed\n");
3680 FAILED(buf[7] != 1, "test40 case 9 failed\n");
3681 FAILED(buf[8] != 1, "test40 case 10 failed\n");
3682 FAILED(buf[9] != 0x123457, "test40 case 11 failed\n");
3684 sljit_free_code(code.code, NULL);
3685 successful_tests++;
3688 static void test41(void)
3690 /* Test inline assembly. */
3691 executable_code code;
3692 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
3693 sljit_s32 i;
3694 sljit_f64 buf[3];
3695 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3696 sljit_u8 inst[16];
3697 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3698 sljit_u8 inst[16];
3699 sljit_s32 reg;
3700 #else
3701 sljit_u32 inst;
3702 #endif
3704 if (verbose)
3705 printf("Run test41\n");
3707 #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3708 SLJIT_ASSERT(sljit_has_cpu_feature(SLJIT_HAS_VIRTUAL_REGISTERS) == 0);
3709 #endif
3711 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++) {
3712 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3713 if (SLJIT_R(i) >= SLJIT_R3 && SLJIT_R(i) <= SLJIT_R8) {
3714 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R(i)) == -1);
3715 continue;
3717 #endif
3718 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R(i)) >= 0 && sljit_get_register_index(SLJIT_R(i)) < 64);
3721 FAILED(!compiler, "cannot create compiler\n");
3722 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(W, W, W), 3, 3, 0, 0, 0);
3724 /* Returns with the sum of SLJIT_S0 and SLJIT_S1. */
3725 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3726 /* lea SLJIT_RETURN_REG, [SLJIT_S0, SLJIT_S1] */
3727 inst[0] = 0x48;
3728 inst[1] = 0x8d;
3729 inst[2] = (sljit_u8)(0x04 | ((sljit_get_register_index(SLJIT_RETURN_REG) & 0x7) << 3));
3730 inst[3] = (sljit_u8)((sljit_get_register_index(SLJIT_S0) & 0x7)
3731 | ((sljit_get_register_index(SLJIT_S1) & 0x7) << 3));
3732 sljit_emit_op_custom(compiler, inst, 4);
3733 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3734 /* lea SLJIT_RETURN_REG, [SLJIT_S0, SLJIT_S1] */
3735 inst[0] = 0x48; /* REX_W */
3736 inst[1] = 0x8d;
3737 reg = sljit_get_register_index(SLJIT_RETURN_REG);
3738 inst[2] = (sljit_u8)(0x04 | ((reg & 0x7) << 3));
3739 if (reg > 7)
3740 inst[0] |= 0x04; /* REX_R */
3741 reg = sljit_get_register_index(SLJIT_S0);
3742 inst[3] = (sljit_u8)(reg & 0x7);
3743 if (reg > 7)
3744 inst[0] |= 0x01; /* REX_B */
3745 reg = sljit_get_register_index(SLJIT_S1);
3746 inst[3] = (sljit_u8)(inst[3] | ((reg & 0x7) << 3));
3747 if (reg > 7)
3748 inst[0] |= 0x02; /* REX_X */
3749 sljit_emit_op_custom(compiler, inst, 4);
3750 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
3751 /* add rd, rn, rm */
3752 inst = 0xe0800000 | ((sljit_u32)sljit_get_register_index(SLJIT_RETURN_REG) << 12)
3753 | ((sljit_u32)sljit_get_register_index(SLJIT_S0) << 16)
3754 | (sljit_u32)sljit_get_register_index(SLJIT_S1);
3755 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3756 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
3757 /* add rd, rn, rm */
3758 inst = 0xeb000000 | ((sljit_u32)sljit_get_register_index(SLJIT_RETURN_REG) << 8)
3759 | ((sljit_u32)sljit_get_register_index(SLJIT_S0) << 16)
3760 | (sljit_u32)sljit_get_register_index(SLJIT_S1);
3761 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3762 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
3763 /* add rd, rn, rm */
3764 inst = 0x8b000000 | (sljit_u32)sljit_get_register_index(SLJIT_RETURN_REG)
3765 | ((sljit_u32)sljit_get_register_index(SLJIT_S0) << 5)
3766 | ((sljit_u32)sljit_get_register_index(SLJIT_S1) << 16);
3767 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3768 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
3769 /* add rD, rA, rB */
3770 inst = (31 << 26) | (266 << 1) | ((sljit_u32)sljit_get_register_index(SLJIT_RETURN_REG) << 21)
3771 | ((sljit_u32)sljit_get_register_index(SLJIT_S0) << 16)
3772 | ((sljit_u32)sljit_get_register_index(SLJIT_S1) << 11);
3773 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3774 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
3775 /* addu rd, rs, rt */
3776 inst = 33 | ((sljit_u32)sljit_get_register_index(SLJIT_RETURN_REG) << 11)
3777 | ((sljit_u32)sljit_get_register_index(SLJIT_S0) << 21)
3778 | ((sljit_u32)sljit_get_register_index(SLJIT_S1) << 16);
3779 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3780 #elif (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
3781 /* daddu rd, rs, rt */
3782 inst = 45 | ((sljit_u32)sljit_get_register_index(SLJIT_RETURN_REG) << 11)
3783 | ((sljit_u32)sljit_get_register_index(SLJIT_S0) << 21)
3784 | ((sljit_u32)sljit_get_register_index(SLJIT_S1) << 16);
3785 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3786 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3787 /* add rd, rs1, rs2 */
3788 inst = (0x2u << 30) | ((sljit_u32)sljit_get_register_index(SLJIT_RETURN_REG) << 25)
3789 | ((sljit_u32)sljit_get_register_index(SLJIT_S0) << 14)
3790 | (sljit_u32)sljit_get_register_index(SLJIT_S1);
3791 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3792 #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
3793 /* agrk rd, rs1, rs2 */
3794 inst = (0xb9e8u << 16)
3795 | ((sljit_u32)sljit_get_register_index(SLJIT_RETURN_REG) << 4)
3796 | ((sljit_u32)sljit_get_register_index(SLJIT_S0) << 12)
3797 | (sljit_u32)sljit_get_register_index(SLJIT_S1);
3798 sljit_emit_op_custom(compiler, &inst, sizeof(inst));
3799 #else
3800 inst = 0;
3801 sljit_emit_op_custom(compiler, &inst, 0);
3802 #endif
3804 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
3806 code.code = sljit_generate_code(compiler);
3807 CHECK(compiler);
3808 sljit_free_compiler(compiler);
3810 FAILED(code.func2(32, -11) != 21, "test41 case 1 failed\n");
3811 FAILED(code.func2(1000, 234) != 1234, "test41 case 2 failed\n");
3812 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3813 FAILED(code.func2(SLJIT_W(0x20f0a04090c06070), SLJIT_W(0x020f0a04090c0607)) != SLJIT_W(0x22ffaa4499cc6677), "test41 case 3 failed\n");
3814 #endif
3816 sljit_free_code(code.code, NULL);
3818 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
3819 buf[0] = 13.5;
3820 buf[1] = -2.25;
3821 buf[2] = 0.0;
3823 compiler = sljit_create_compiler(NULL, NULL);
3824 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 0, 1, 2, 0, 0);
3825 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 0);
3826 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
3827 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3828 /* addsd x, xm */
3829 inst[0] = 0xf2;
3830 inst[1] = 0x0f;
3831 inst[2] = 0x58;
3832 inst[3] = (sljit_u8)(0xc0 | (sljit_get_float_register_index(SLJIT_FR0) << 3)
3833 | sljit_get_float_register_index(SLJIT_FR1));
3834 sljit_emit_op_custom(compiler, inst, 4);
3835 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3836 /* addsd x, xm */
3837 if (sljit_get_float_register_index(SLJIT_FR0) > 7 || sljit_get_float_register_index(SLJIT_FR1) > 7) {
3838 inst[0] = 0;
3839 if (sljit_get_float_register_index(SLJIT_FR0) > 7)
3840 inst[0] |= 0x04; /* REX_R */
3841 if (sljit_get_float_register_index(SLJIT_FR1) > 7)
3842 inst[0] |= 0x01; /* REX_B */
3843 inst[1] = 0xf2;
3844 inst[2] = 0x0f;
3845 inst[3] = 0x58;
3846 inst[4] = (sljit_u8)(0xc0 | ((sljit_get_float_register_index(SLJIT_FR0) & 0x7) << 3)
3847 | (sljit_get_float_register_index(SLJIT_FR1) & 0x7));
3848 sljit_emit_op_custom(compiler, inst, 5);
3850 else {
3851 inst[0] = 0xf2;
3852 inst[1] = 0x0f;
3853 inst[2] = 0x58;
3854 inst[3] = (sljit_u8)(0xc0 | (sljit_get_float_register_index(SLJIT_FR0) << 3)
3855 | sljit_get_float_register_index(SLJIT_FR1));
3856 sljit_emit_op_custom(compiler, inst, 4);
3858 #elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32)
3859 /* vadd.f64 dd, dn, dm */
3860 inst = 0xee300b00 | (((sljit_u32)sljit_get_float_register_index(SLJIT_FR0) >> 1) << 12)
3861 | (((sljit_u32)sljit_get_float_register_index(SLJIT_FR0) >> 1) << 16)
3862 | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR1) >> 1);
3863 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3864 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
3865 /* fadd rd, rn, rm */
3866 inst = 0x1e602800 | (sljit_u32)sljit_get_float_register_index(SLJIT_FR0)
3867 | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR0) << 5)
3868 | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR1) << 16);
3869 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3870 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
3871 /* fadd frD, frA, frB */
3872 inst = (63u << 26) | (21u << 1) | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR0) << 21)
3873 | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR0) << 16)
3874 | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR1) << 11);
3875 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3876 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
3877 /* add.d fd, fs, ft */
3878 inst = (17 << 26) | (17 << 21) | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR0) << 6)
3879 | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR0) << 11)
3880 | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR1) << 16);
3881 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3882 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3883 /* faddd rd, rs1, rs2 */
3884 inst = (0x2u << 30) | (0x34u << 19) | (0x42u << 5)
3885 | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR0) << 25)
3886 | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR0) << 14)
3887 | (sljit_u32)sljit_get_float_register_index(SLJIT_FR1);
3888 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3889 #endif
3890 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64), SLJIT_FR0, 0);
3891 sljit_emit_return_void(compiler);
3893 code.code = sljit_generate_code(compiler);
3894 CHECK(compiler);
3895 sljit_free_compiler(compiler);
3897 code.func1((sljit_sw)&buf);
3898 FAILED(buf[2] != 11.25, "test41 case 3 failed\n");
3900 sljit_free_code(code.code, NULL);
3903 successful_tests++;
3906 static void test42(void)
3908 /* Test long multiply and division. */
3909 executable_code code;
3910 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
3911 sljit_s32 i;
3912 sljit_sw buf[7 + 4 + 8 + 8];
3914 if (verbose)
3915 printf("Run test42\n");
3917 FAILED(!compiler, "cannot create compiler\n");
3918 for (i = 0; i < 7 + 4 + 8 + 8; i++)
3919 buf[i] = -1;
3921 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 5, 5, 0, 0, 0);
3923 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -0x1fb308a);
3924 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0xf50c873);
3925 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_IMM, 0x8a0475b);
3926 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, 0x9dc849b);
3927 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, -0x7c69a35);
3928 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, 0x5a4d0c4);
3929 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S4, 0, SLJIT_IMM, 0x9a3b06d);
3931 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3932 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3933 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3934 sljit_emit_op0(compiler, SLJIT_LMUL_UW);
3935 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R0, 0);
3936 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R1, 0);
3938 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3939 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3940 sljit_emit_op0(compiler, SLJIT_LMUL_SW);
3941 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_R0, 0);
3942 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_R1, 0);
3944 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3945 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3946 sljit_emit_op0(compiler, SLJIT_DIVMOD_UW);
3947 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_R0, 0);
3948 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_R1, 0);
3950 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3951 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3952 sljit_emit_op0(compiler, SLJIT_DIVMOD_SW);
3953 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_R0, 0);
3954 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_sw), SLJIT_R1, 0);
3956 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x5cf783d3cf0a74b0));
3957 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3d5df42d03a28fc7));
3958 sljit_emit_op0(compiler, SLJIT_DIVMOD_U32);
3959 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
3960 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R1, 0, SLJIT_R1, 0);
3961 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 15 * sizeof(sljit_sw), SLJIT_R0, 0);
3962 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 16 * sizeof(sljit_sw), SLJIT_R1, 0);
3964 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x371df5197ba26a28));
3965 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x46c78a5cfd6a420c));
3966 sljit_emit_op0(compiler, SLJIT_DIVMOD_S32);
3967 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
3968 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R1, 0, SLJIT_R1, 0);
3969 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 17 * sizeof(sljit_sw), SLJIT_R0, 0);
3970 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_sw), SLJIT_R1, 0);
3972 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)SLJIT_W(0xc456f048c28a611b));
3973 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3d4af2c543));
3974 sljit_emit_op0(compiler, SLJIT_DIV_UW);
3975 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 19 * sizeof(sljit_sw), SLJIT_R0, 0);
3976 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 20 * sizeof(sljit_sw), SLJIT_R1, 0);
3978 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x720fa4b74c329b14));
3979 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0xa64ae42b7d6));
3980 sljit_emit_op0(compiler, SLJIT_DIV_SW);
3981 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 21 * sizeof(sljit_sw), SLJIT_R0, 0);
3982 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 22 * sizeof(sljit_sw), SLJIT_R1, 0);
3984 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x4af51c027b34));
3985 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x9ba4ff2906b14));
3986 sljit_emit_op0(compiler, SLJIT_DIV_U32);
3987 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
3988 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R1, 0, SLJIT_R1, 0);
3989 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 23 * sizeof(sljit_sw), SLJIT_R0, 0);
3990 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 24 * sizeof(sljit_sw), SLJIT_R1, 0);
3992 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xc40b58a3f20d));
3993 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(-0xa63c923));
3994 sljit_emit_op0(compiler, SLJIT_DIV_S32);
3995 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
3996 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R1, 0, SLJIT_R1, 0);
3997 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 25 * sizeof(sljit_sw), SLJIT_R0, 0);
3998 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 26 * sizeof(sljit_sw), SLJIT_R1, 0);
4000 #else
4001 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -0x58cd67f5);
4002 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x3cb088df);
4003 sljit_emit_op0(compiler, SLJIT_LMUL_UW);
4004 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R0, 0);
4005 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R1, 0);
4007 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -0x58cd67f5);
4008 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x3cb088df);
4009 sljit_emit_op0(compiler, SLJIT_LMUL_SW);
4010 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_R0, 0);
4011 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_R1, 0);
4013 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -0x58cd67f5);
4014 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x3cb088df);
4015 sljit_emit_op0(compiler, SLJIT_DIVMOD_UW);
4016 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_R0, 0);
4017 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_R1, 0);
4019 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -0x58cd67f5);
4020 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x3cb088df);
4021 sljit_emit_op0(compiler, SLJIT_DIVMOD_SW);
4022 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_R0, 0);
4023 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_sw), SLJIT_R1, 0);
4025 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)0xcf0a74b0);
4026 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 0x03a28fc7);
4027 sljit_emit_op0(compiler, SLJIT_DIVMOD_U32);
4028 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 15 * sizeof(sljit_sw), SLJIT_R0, 0);
4029 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 16 * sizeof(sljit_sw), SLJIT_R1, 0);
4031 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x7ba26a28);
4032 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)0xfd6a420c);
4033 sljit_emit_op0(compiler, SLJIT_DIVMOD_S32);
4034 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 17 * sizeof(sljit_sw), SLJIT_R0, 0);
4035 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_sw), SLJIT_R1, 0);
4037 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)0x9d4b7036);
4038 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0xb86d0);
4039 sljit_emit_op0(compiler, SLJIT_DIV_UW);
4040 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 19 * sizeof(sljit_sw), SLJIT_R0, 0);
4041 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 20 * sizeof(sljit_sw), SLJIT_R1, 0);
4043 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -0x58b0692c);
4044 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0xd357);
4045 sljit_emit_op0(compiler, SLJIT_DIV_SW);
4046 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 21 * sizeof(sljit_sw), SLJIT_R0, 0);
4047 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 22 * sizeof(sljit_sw), SLJIT_R1, 0);
4049 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x1c027b34);
4050 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)0xf2906b14);
4051 sljit_emit_op0(compiler, SLJIT_DIV_U32);
4052 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
4053 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R1, 0, SLJIT_R1, 0);
4054 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 23 * sizeof(sljit_sw), SLJIT_R0, 0);
4055 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 24 * sizeof(sljit_sw), SLJIT_R1, 0);
4057 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x58a3f20d);
4058 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -0xa63c923);
4059 sljit_emit_op0(compiler, SLJIT_DIV_S32);
4060 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
4061 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R1, 0, SLJIT_R1, 0);
4062 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 25 * sizeof(sljit_sw), SLJIT_R0, 0);
4063 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 26 * sizeof(sljit_sw), SLJIT_R1, 0);
4064 #endif
4066 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R2, 0);
4067 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R3, 0);
4068 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R4, 0);
4069 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_S1, 0);
4070 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_S2, 0);
4071 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_S3, 0);
4072 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_S4, 0);
4074 sljit_emit_return_void(compiler);
4076 code.code = sljit_generate_code(compiler);
4077 CHECK(compiler);
4078 sljit_free_compiler(compiler);
4080 code.func1((sljit_sw)&buf);
4082 FAILED(buf[0] != -0x1fb308a, "test42 case 1 failed\n");
4083 FAILED(buf[1] != 0xf50c873, "test42 case 2 failed\n");
4084 FAILED(buf[2] != 0x8a0475b, "test42 case 3 failed\n");
4085 FAILED(buf[3] != 0x9dc849b, "test42 case 4 failed\n");
4086 FAILED(buf[4] != -0x7c69a35, "test42 case 5 failed\n");
4087 FAILED(buf[5] != 0x5a4d0c4, "test42 case 6 failed\n");
4088 FAILED(buf[6] != 0x9a3b06d, "test42 case 7 failed\n");
4090 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4091 FAILED(buf[7] != SLJIT_W(-4388959407985636971), "test42 case 8 failed\n");
4092 FAILED(buf[8] != SLJIT_W(2901680654366567099), "test42 case 9 failed\n");
4093 FAILED(buf[9] != SLJIT_W(-4388959407985636971), "test42 case 10 failed\n");
4094 FAILED(buf[10] != SLJIT_W(-1677173957268872740), "test42 case 11 failed\n");
4095 FAILED(buf[11] != SLJIT_W(2), "test42 case 12 failed\n");
4096 FAILED(buf[12] != SLJIT_W(2532236178951865933), "test42 case 13 failed\n");
4097 FAILED(buf[13] != SLJIT_W(-1), "test42 case 14 failed\n");
4098 FAILED(buf[14] != SLJIT_W(-2177944059851366166), "test42 case 15 failed\n");
4099 #else
4100 FAILED(buf[7] != -1587000939, "test42 case 8 failed\n");
4101 FAILED(buf[8] != 665003983, "test42 case 9 failed\n");
4102 FAILED(buf[9] != -1587000939, "test42 case 10 failed\n");
4103 FAILED(buf[10] != -353198352, "test42 case 11 failed\n");
4104 FAILED(buf[11] != 2, "test42 case 12 failed\n");
4105 FAILED(buf[12] != 768706125, "test42 case 13 failed\n");
4106 FAILED(buf[13] != -1, "test42 case 14 failed\n");
4107 FAILED(buf[14] != -471654166, "test42 case 15 failed\n");
4108 #endif
4110 FAILED(buf[15] != SLJIT_W(56), "test42 case 16 failed\n");
4111 FAILED(buf[16] != SLJIT_W(58392872), "test42 case 17 failed\n");
4112 FAILED(buf[17] != SLJIT_W(-47), "test42 case 18 failed\n");
4113 FAILED(buf[18] != SLJIT_W(35949148), "test42 case 19 failed\n");
4115 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4116 FAILED(buf[19] != SLJIT_W(0x3340bfc), "test42 case 20 failed\n");
4117 FAILED(buf[20] != SLJIT_W(0x3d4af2c543), "test42 case 21 failed\n");
4118 FAILED(buf[21] != SLJIT_W(-0xaf978), "test42 case 22 failed\n");
4119 FAILED(buf[22] != SLJIT_W(0xa64ae42b7d6), "test42 case 23 failed\n");
4120 #else
4121 FAILED(buf[19] != SLJIT_W(0xda5), "test42 case 20 failed\n");
4122 FAILED(buf[20] != SLJIT_W(0xb86d0), "test42 case 21 failed\n");
4123 FAILED(buf[21] != SLJIT_W(-0x6b6e), "test42 case 22 failed\n");
4124 FAILED(buf[22] != SLJIT_W(0xd357), "test42 case 23 failed\n");
4125 #endif
4127 FAILED(buf[23] != SLJIT_W(0x0), "test42 case 24 failed\n");
4128 FAILED(buf[24] != SLJIT_W(0xf2906b14), "test42 case 25 failed\n");
4129 FAILED(buf[25] != SLJIT_W(-0x8), "test42 case 26 failed\n");
4130 FAILED(buf[26] != SLJIT_W(-0xa63c923), "test42 case 27 failed\n");
4132 sljit_free_code(code.code, NULL);
4133 successful_tests++;
4136 static void test43(void)
4138 /* Test floating point compare. */
4139 executable_code code;
4140 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
4141 struct sljit_jump* jump;
4143 union {
4144 sljit_f64 value;
4145 struct {
4146 sljit_u32 value1;
4147 sljit_u32 value2;
4148 } u;
4149 } dbuf[4];
4151 if (verbose)
4152 printf("Run test43\n");
4154 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
4155 if (verbose)
4156 printf("no fpu available, test43 skipped\n");
4157 successful_tests++;
4158 if (compiler)
4159 sljit_free_compiler(compiler);
4160 return;
4163 FAILED(!compiler, "cannot create compiler\n");
4165 dbuf[0].value = 12.125;
4166 /* a NaN */
4167 dbuf[1].u.value1 = 0x7fffffff;
4168 dbuf[1].u.value2 = 0x7fffffff;
4169 dbuf[2].value = -13.5;
4170 dbuf[3].value = 12.125;
4172 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 1, 1, 3, 0, 0);
4173 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
4174 /* dbuf[0] < dbuf[2] -> -2 */
4175 jump = sljit_emit_fcmp(compiler, SLJIT_GREATER_EQUAL_F64, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_F64_SHIFT);
4176 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, -2);
4178 sljit_set_label(jump, sljit_emit_label(compiler));
4179 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 0);
4180 /* dbuf[0] and dbuf[1] is not NaN -> 5 */
4181 jump = sljit_emit_fcmp(compiler, SLJIT_UNORDERED_F64, SLJIT_MEM0(), (sljit_sw)&dbuf[1], SLJIT_FR1, 0);
4182 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, 5);
4184 sljit_set_label(jump, sljit_emit_label(compiler));
4185 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f64));
4186 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 11);
4187 /* dbuf[0] == dbuf[3] -> 11 */
4188 jump = sljit_emit_fcmp(compiler, SLJIT_EQUAL_F64, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_FR2, 0);
4190 /* else -> -17 */
4191 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, -17);
4192 sljit_set_label(jump, sljit_emit_label(compiler));
4193 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
4195 code.code = sljit_generate_code(compiler);
4196 CHECK(compiler);
4197 sljit_free_compiler(compiler);
4199 FAILED(code.func1((sljit_sw)&dbuf) != 11, "test43 case 1 failed\n");
4200 dbuf[3].value = 12;
4201 FAILED(code.func1((sljit_sw)&dbuf) != -17, "test43 case 2 failed\n");
4202 dbuf[1].value = 0;
4203 FAILED(code.func1((sljit_sw)&dbuf) != 5, "test43 case 3 failed\n");
4204 dbuf[2].value = 20;
4205 FAILED(code.func1((sljit_sw)&dbuf) != -2, "test43 case 4 failed\n");
4207 sljit_free_code(code.code, NULL);
4208 successful_tests++;
4211 static void test44(void)
4213 /* Test mov. */
4214 executable_code code;
4215 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
4216 void *buf[5];
4218 if (verbose)
4219 printf("Run test44\n");
4221 FAILED(!compiler, "cannot create compiler\n");
4223 buf[0] = buf + 2;
4224 buf[1] = NULL;
4225 buf[2] = NULL;
4226 buf[3] = NULL;
4227 buf[4] = NULL;
4228 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(P, P), 3, 2, 0, 0, 0);
4230 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 0);
4231 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_p), SLJIT_R0, 0);
4232 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_p));
4233 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 2);
4234 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_MEM2(SLJIT_S0, SLJIT_R1), SLJIT_POINTER_SHIFT, SLJIT_R0, 0);
4235 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_p));
4236 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 3 << SLJIT_POINTER_SHIFT);
4237 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_S0, 0);
4238 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_MEM2(SLJIT_R2, SLJIT_R1), 0, SLJIT_R0, 0);
4239 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 2 * sizeof(sljit_p));
4240 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1 << SLJIT_POINTER_SHIFT);
4241 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_MEM2(SLJIT_R2, SLJIT_R1), 2, SLJIT_R0, 0);
4243 sljit_emit_return(compiler, SLJIT_MOV_P, SLJIT_R0, 0);
4245 code.code = sljit_generate_code(compiler);
4246 CHECK(compiler);
4247 sljit_free_compiler(compiler);
4249 FAILED(code.func1((sljit_sw)&buf) != (sljit_sw)(buf + 2), "test44 case 1 failed\n");
4250 FAILED(buf[1] != buf + 2, "test44 case 2 failed\n");
4251 FAILED(buf[2] != buf + 3, "test44 case 3 failed\n");
4252 FAILED(buf[3] != buf + 4, "test44 case 4 failed\n");
4253 FAILED(buf[4] != buf + 2, "test44 case 5 failed\n");
4255 sljit_free_code(code.code, NULL);
4256 successful_tests++;
4259 static void test45(void)
4261 /* Test single precision floating point. */
4263 executable_code code;
4264 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
4265 sljit_f32 buf[12];
4266 sljit_sw buf2[6];
4267 struct sljit_jump* jump;
4269 if (verbose)
4270 printf("Run test45\n");
4272 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
4273 if (verbose)
4274 printf("no fpu available, test45 skipped\n");
4275 successful_tests++;
4276 if (compiler)
4277 sljit_free_compiler(compiler);
4278 return;
4281 FAILED(!compiler, "cannot create compiler\n");
4283 buf[0] = 5.5;
4284 buf[1] = -7.25;
4285 buf[2] = 0;
4286 buf[3] = 0;
4287 buf[4] = 0;
4288 buf[5] = 0;
4289 buf[6] = 0;
4290 buf[7] = 8.75;
4291 buf[8] = 0;
4292 buf[9] = 16.5;
4293 buf[10] = 0;
4294 buf[11] = 0;
4296 buf2[0] = -1;
4297 buf2[1] = -1;
4298 buf2[2] = -1;
4299 buf2[3] = -1;
4300 buf2[4] = -1;
4301 buf2[5] = -1;
4303 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(VOID, P, P), 3, 2, 6, 0, 0);
4305 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 0);
4306 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4307 sljit_emit_fop1(compiler, SLJIT_NEG_F32, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f32), SLJIT_FR0, 0);
4308 sljit_emit_fop1(compiler, SLJIT_ABS_F32, SLJIT_FR1, 0, SLJIT_FR5, 0);
4309 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f32), SLJIT_FR1, 0);
4310 sljit_emit_fop1(compiler, SLJIT_ABS_F32, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f32), SLJIT_FR5, 0);
4311 sljit_emit_fop1(compiler, SLJIT_NEG_F32, SLJIT_FR4, 0, SLJIT_MEM1(SLJIT_S0), 0);
4312 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f32), SLJIT_FR4, 0);
4314 sljit_emit_fop2(compiler, SLJIT_ADD_F32, SLJIT_FR0, 0, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4315 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f32), SLJIT_FR0, 0);
4316 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);
4317 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 0);
4318 sljit_emit_fop2(compiler, SLJIT_MUL_F32, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_f32), SLJIT_FR0, 0, SLJIT_FR0, 0);
4319 sljit_emit_fop2(compiler, SLJIT_DIV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f32), SLJIT_FR0, 0);
4320 sljit_emit_fop1(compiler, SLJIT_ABS_F32, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f32), SLJIT_FR2, 0);
4321 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 0x3d0ac);
4322 sljit_emit_fop1(compiler, SLJIT_NEG_F32, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_R0), 0x3d0ac);
4323 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 0x3d0ac + sizeof(sljit_f32));
4324 sljit_emit_fop1(compiler, SLJIT_ABS_F32, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_R0), -0x3d0ac);
4326 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 0);
4327 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4328 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 0);
4329 cond_set(compiler, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_EQUAL_F32);
4330 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_LESS_F, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 0);
4331 cond_set(compiler, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_sw), SLJIT_LESS_F32);
4332 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
4333 cond_set(compiler, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_sw), SLJIT_EQUAL_F32);
4334 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_GREATER_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
4335 cond_set(compiler, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw), SLJIT_GREATER_EQUAL_F32);
4337 jump = sljit_emit_fcmp(compiler, SLJIT_LESS_EQUAL_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4338 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_sw), SLJIT_IMM, 7);
4339 sljit_set_label(jump, sljit_emit_label(compiler));
4341 jump = sljit_emit_fcmp(compiler, SLJIT_GREATER_F32, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_FR2, 0);
4342 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_sw), SLJIT_IMM, 6);
4343 sljit_set_label(jump, sljit_emit_label(compiler));
4345 sljit_emit_return_void(compiler);
4347 code.code = sljit_generate_code(compiler);
4348 CHECK(compiler);
4349 sljit_free_compiler(compiler);
4351 code.func2((sljit_sw)&buf, (sljit_sw)&buf2);
4352 FAILED(buf[2] != -5.5, "test45 case 1 failed\n");
4353 FAILED(buf[3] != 7.25, "test45 case 2 failed\n");
4354 FAILED(buf[4] != 7.25, "test45 case 3 failed\n");
4355 FAILED(buf[5] != -5.5, "test45 case 4 failed\n");
4356 FAILED(buf[6] != -1.75, "test45 case 5 failed\n");
4357 FAILED(buf[7] != 16.0, "test45 case 6 failed\n");
4358 FAILED(buf[8] != 30.25, "test45 case 7 failed\n");
4359 FAILED(buf[9] != 3, "test45 case 8 failed\n");
4360 FAILED(buf[10] != -5.5, "test45 case 9 failed\n");
4361 FAILED(buf[11] != 7.25, "test45 case 10 failed\n");
4362 FAILED(buf2[0] != 1, "test45 case 11 failed\n");
4363 FAILED(buf2[1] != 2, "test45 case 12 failed\n");
4364 FAILED(buf2[2] != 2, "test45 case 13 failed\n");
4365 FAILED(buf2[3] != 1, "test45 case 14 failed\n");
4366 FAILED(buf2[4] != 7, "test45 case 15 failed\n");
4367 FAILED(buf2[5] != -1, "test45 case 16 failed\n");
4369 sljit_free_code(code.code, NULL);
4370 successful_tests++;
4373 static void test46(void)
4375 /* Test sljit_emit_op_flags with 32 bit operations. */
4377 executable_code code;
4378 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
4379 sljit_s32 buf[24];
4380 sljit_sw buf2[6];
4381 sljit_s32 i;
4383 if (verbose)
4384 printf("Run test46\n");
4386 for (i = 0; i < 24; ++i)
4387 buf[i] = -17;
4388 buf[16] = 0;
4389 for (i = 0; i < 6; ++i)
4390 buf2[i] = -13;
4391 buf2[4] = -124;
4393 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(VOID, P, P), 3, 3, 0, 0, 0);
4395 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -7);
4396 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, SLJIT_R2, 0, SLJIT_IMM, 13);
4397 sljit_emit_op_flags(compiler, SLJIT_MOV32, SLJIT_MEM0(), (sljit_sw)&buf, SLJIT_LESS);
4398 sljit_emit_op_flags(compiler, SLJIT_AND32, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_s32), SLJIT_NOT_ZERO);
4400 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R2, 0, SLJIT_IMM, -7);
4401 sljit_emit_op_flags(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_s32), SLJIT_EQUAL);
4402 sljit_emit_op_flags(compiler, SLJIT_AND32, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_s32), SLJIT_NOT_EQUAL);
4403 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x1235);
4404 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_IMM, 0x1235);
4405 sljit_emit_op_flags(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_ZERO);
4406 sljit_emit_op_flags(compiler, SLJIT_AND32, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_s32), SLJIT_ZERO);
4407 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_s32), SLJIT_R0, 0);
4409 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R2, 0, SLJIT_IMM, -7);
4410 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 12);
4411 sljit_emit_op_flags(compiler, SLJIT_MOV32, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 2, SLJIT_EQUAL);
4412 sljit_emit_op_flags(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_EQUAL);
4413 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_s32), SLJIT_R0, 0);
4414 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 16);
4415 sljit_emit_op_flags(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 2, SLJIT_EQUAL);
4416 sljit_emit_op_flags(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_s32), SLJIT_NOT_EQUAL);
4418 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R2, 0, SLJIT_IMM, -7);
4419 sljit_emit_op_flags(compiler, SLJIT_XOR32 | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), 20 * sizeof(sljit_s32), SLJIT_ZERO);
4420 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 39);
4421 sljit_emit_op_flags(compiler, SLJIT_XOR32, SLJIT_R0, 0, SLJIT_NOT_ZERO);
4422 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S0), 22 * sizeof(sljit_s32), SLJIT_R0, 0);
4424 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_R2, 0, SLJIT_IMM, -7);
4425 sljit_emit_op_flags(compiler, SLJIT_AND, SLJIT_MEM0(), (sljit_sw)&buf2, SLJIT_GREATER);
4426 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R2, 0, SLJIT_IMM, 5);
4427 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
4428 sljit_emit_op_flags(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_SIG_LESS);
4429 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
4430 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, SLJIT_R2, 0, SLJIT_IMM, 5);
4431 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_LESS);
4432 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_NOT_EQUAL);
4433 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R2, 0, SLJIT_IMM, 5);
4434 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw), SLJIT_S2, 0);
4435 sljit_emit_op_flags(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_SIG_LESS);
4436 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_sw), SLJIT_ZERO);
4437 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_R2, 0, SLJIT_IMM, 0);
4438 sljit_emit_op_flags(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_sw), SLJIT_GREATER);
4440 sljit_emit_return_void(compiler);
4442 code.code = sljit_generate_code(compiler);
4443 CHECK(compiler);
4444 sljit_free_compiler(compiler);
4446 code.func2((sljit_sw)&buf, (sljit_sw)&buf2);
4447 FAILED(buf[0] != 0, "test46 case 1 failed\n");
4448 FAILED(buf[1] != -17, "test46 case 2 failed\n");
4449 FAILED(buf[2] != 1, "test46 case 3 failed\n");
4450 FAILED(buf[3] != -17, "test46 case 4 failed\n");
4451 FAILED(buf[4] != 1, "test46 case 5 failed\n");
4452 FAILED(buf[5] != -17, "test46 case 6 failed\n");
4453 FAILED(buf[6] != 1, "test46 case 7 failed\n");
4454 FAILED(buf[7] != -17, "test46 case 8 failed\n");
4455 FAILED(buf[8] != 0, "test46 case 9 failed\n");
4456 FAILED(buf[9] != -17, "test46 case 10 failed\n");
4457 FAILED(buf[10] != 1, "test46 case 11 failed\n");
4458 FAILED(buf[11] != -17, "test46 case 12 failed\n");
4459 FAILED(buf[12] != 1, "test46 case 13 failed\n");
4460 FAILED(buf[13] != -17, "test46 case 14 failed\n");
4461 FAILED(buf[14] != 1, "test46 case 15 failed\n");
4462 FAILED(buf[15] != -17, "test46 case 16 failed\n");
4463 FAILED(buf[16] != 0, "test46 case 17 failed\n");
4464 FAILED(buf[17] != -17, "test46 case 18 failed\n");
4465 FAILED(buf[18] != 0, "test46 case 19 failed\n");
4466 FAILED(buf[19] != -17, "test46 case 20 failed\n");
4467 FAILED(buf[20] != -18, "test46 case 21 failed\n");
4468 FAILED(buf[21] != -17, "test46 case 22 failed\n");
4469 FAILED(buf[22] != 38, "test46 case 23 failed\n");
4470 FAILED(buf[23] != -17, "test46 case 24 failed\n");
4472 FAILED(buf2[0] != 0, "test46 case 25 failed\n");
4473 FAILED(buf2[1] != 1, "test46 case 26 failed\n");
4474 FAILED(buf2[2] != 0, "test46 case 27 failed\n");
4475 FAILED(buf2[3] != 1, "test46 case 28 failed\n");
4476 FAILED(buf2[4] != -123, "test46 case 29 failed\n");
4477 FAILED(buf2[5] != -14, "test46 case 30 failed\n");
4479 sljit_free_code(code.code, NULL);
4480 successful_tests++;
4483 static void test47(void)
4485 /* Test jump optimizations. */
4486 executable_code code;
4487 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
4488 sljit_sw buf[3];
4490 if (verbose)
4491 printf("Run test47\n");
4493 FAILED(!compiler, "cannot create compiler\n");
4494 buf[0] = 0;
4495 buf[1] = 0;
4496 buf[2] = 0;
4498 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 1, 0, 0, 0);
4499 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x3a5c6f);
4500 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_R0, 0, SLJIT_IMM, 3);
4501 sljit_set_target(sljit_emit_jump(compiler, SLJIT_LESS), 0x11223344);
4502 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
4503 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xd37c10);
4504 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4505 sljit_set_target(sljit_emit_jump(compiler, SLJIT_LESS), SLJIT_W(0x112233445566));
4506 #endif
4507 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
4508 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x59b48e);
4509 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4510 sljit_set_target(sljit_emit_jump(compiler, SLJIT_LESS), SLJIT_W(0x1122334455667788));
4511 #endif
4512 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
4513 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
4515 code.code = sljit_generate_code(compiler);
4516 CHECK(compiler);
4517 sljit_free_compiler(compiler);
4519 FAILED(code.func1((sljit_sw)&buf) != 0x59b48e, "test47 case 1 failed\n");
4520 FAILED(buf[0] != 0x3a5c6f, "test47 case 2 failed\n");
4521 FAILED(buf[1] != 0xd37c10, "test47 case 3 failed\n");
4522 FAILED(buf[2] != 0x59b48e, "test47 case 4 failed\n");
4524 sljit_free_code(code.code, NULL);
4525 successful_tests++;
4528 static void test48(void)
4530 /* Test floating point conversions. */
4531 executable_code code;
4532 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
4533 int i;
4534 sljit_f64 dbuf[10];
4535 sljit_f32 sbuf[10];
4536 sljit_sw wbuf[10];
4537 sljit_s32 ibuf[10];
4539 if (verbose)
4540 printf("Run test48\n");
4542 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
4543 if (verbose)
4544 printf("no fpu available, test48 skipped\n");
4545 successful_tests++;
4546 if (compiler)
4547 sljit_free_compiler(compiler);
4548 return;
4551 FAILED(!compiler, "cannot create compiler\n");
4552 for (i = 0; i < 10; i++) {
4553 dbuf[i] = 0.0;
4554 sbuf[i] = 0.0;
4555 wbuf[i] = 0;
4556 ibuf[i] = 0;
4559 dbuf[0] = 123.5;
4560 dbuf[1] = -367;
4561 dbuf[2] = 917.75;
4563 sbuf[0] = 476.25;
4564 sbuf[1] = -1689.75;
4566 wbuf[0] = 2345;
4568 ibuf[0] = 312;
4569 ibuf[1] = -9324;
4571 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(VOID), 3, 3, 6, 0, 0);
4572 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, (sljit_sw)&dbuf);
4573 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, (sljit_sw)&sbuf);
4574 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, (sljit_sw)&wbuf);
4575 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, (sljit_sw)&ibuf);
4577 /* sbuf[2] */
4578 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_F64, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_S0), 0);
4579 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), 0);
4580 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 3);
4581 /* sbuf[3] */
4582 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_F64, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_F32_SHIFT, SLJIT_FR5, 0);
4583 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_F32, SLJIT_FR4, 0, SLJIT_MEM1(SLJIT_S1), 0);
4584 /* dbuf[3] */
4585 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f64), SLJIT_FR4, 0);
4586 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR3, 0, SLJIT_MEM1(SLJIT_S1), 0);
4587 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_F32, SLJIT_FR2, 0, SLJIT_FR3, 0);
4588 /* dbuf[4] */
4589 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f64), SLJIT_FR2, 0);
4590 /* sbuf[4] */
4591 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_f32), SLJIT_FR3, 0);
4593 /* wbuf[1] */
4594 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F64, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
4595 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
4596 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F64, SLJIT_R0, 0, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_F64_SHIFT);
4597 /* wbuf[2] */
4598 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
4599 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S1), 0);
4600 /* wbuf[3] */
4601 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F32, SLJIT_MEM1(SLJIT_S2), 3 * sizeof(sljit_sw), SLJIT_FR5, 0);
4602 sljit_emit_fop1(compiler, SLJIT_NEG_F32, SLJIT_FR0, 0, SLJIT_FR5, 0);
4603 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 4);
4604 /* wbuf[4] */
4605 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F32, SLJIT_MEM2(SLJIT_S2, SLJIT_R1), SLJIT_WORD_SHIFT, SLJIT_FR0, 0);
4606 sljit_emit_fop1(compiler, SLJIT_NEG_F64, SLJIT_FR4, 0, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64));
4607 /* ibuf[2] */
4608 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F64, SLJIT_MEM1(SLJIT_R2), 2 * sizeof(sljit_s32), SLJIT_FR4, 0);
4609 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f32));
4610 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F32, SLJIT_R0, 0, SLJIT_FR1, 0);
4611 /* ibuf[3] */
4612 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM1(SLJIT_R2), 3 * sizeof(sljit_s32), SLJIT_R0, 0);
4614 /* dbuf[5] */
4615 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_S2), 0);
4616 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_FR2, 0, SLJIT_IMM, -6213);
4617 /* dbuf[6] */
4618 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64), SLJIT_FR2, 0);
4619 /* dbuf[7] */
4620 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_S32, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_f64), SLJIT_MEM0(), (sljit_sw)&ibuf[0]);
4621 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R2), sizeof(sljit_s32));
4622 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_S32, SLJIT_FR1, 0, SLJIT_R0, 0);
4623 /* dbuf[8] */
4624 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_f64), SLJIT_FR1, 0);
4625 /* dbuf[9] */
4626 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_MEM0(), (sljit_sw)(dbuf + 9), SLJIT_IMM, -77);
4627 /* sbuf[5] */
4628 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_SW, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_f32), SLJIT_IMM, -123);
4629 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 7190);
4630 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_SW, SLJIT_FR3, 0, SLJIT_R0, 0);
4631 /* sbuf[6] */
4632 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 6 * sizeof(sljit_f32), SLJIT_FR3, 0);
4633 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 123);
4634 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_R2, 0, SLJIT_IMM, 123 * sizeof(sljit_s32));
4635 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_S32, SLJIT_FR1, 0, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 2);
4636 /* sbuf[7] */
4637 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 7 * sizeof(sljit_f32), SLJIT_FR1, 0);
4638 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
4639 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 3812);
4640 /* sbuf[8] */
4641 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_S32, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_F32_SHIFT, SLJIT_R1, 0);
4642 /* sbuf[9] */
4643 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_SW, SLJIT_MEM0(), (sljit_sw)(sbuf + 9), SLJIT_IMM, -79);
4645 sljit_emit_return_void(compiler);
4647 code.code = sljit_generate_code(compiler);
4648 CHECK(compiler);
4649 sljit_free_compiler(compiler);
4651 code.func0();
4652 FAILED(dbuf[3] != 476.25, "test48 case 1 failed\n");
4653 FAILED(dbuf[4] != 476.25, "test48 case 2 failed\n");
4654 FAILED(dbuf[5] != 2345.0, "test48 case 3 failed\n");
4655 FAILED(dbuf[6] != -6213.0, "test48 case 4 failed\n");
4656 FAILED(dbuf[7] != 312.0, "test48 case 5 failed\n");
4657 FAILED(dbuf[8] != -9324.0, "test48 case 6 failed\n");
4658 FAILED(dbuf[9] != -77.0, "test48 case 7 failed\n");
4660 FAILED(sbuf[2] != 123.5, "test48 case 8 failed\n");
4661 FAILED(sbuf[3] != 123.5, "test48 case 9 failed\n");
4662 FAILED(sbuf[4] != 476.25, "test48 case 10 failed\n");
4663 FAILED(sbuf[5] != -123, "test48 case 11 failed\n");
4664 FAILED(sbuf[6] != 7190, "test48 case 12 failed\n");
4665 FAILED(sbuf[7] != 312, "test48 case 13 failed\n");
4666 FAILED(sbuf[8] != 3812, "test48 case 14 failed\n");
4667 FAILED(sbuf[9] != -79.0, "test48 case 15 failed\n");
4669 FAILED(wbuf[1] != -367, "test48 case 16 failed\n");
4670 FAILED(wbuf[2] != 917, "test48 case 17 failed\n");
4671 FAILED(wbuf[3] != 476, "test48 case 18 failed\n");
4672 FAILED(wbuf[4] != -476, "test48 case 19 failed\n");
4674 FAILED(ibuf[2] != -917, "test48 case 20 failed\n");
4675 FAILED(ibuf[3] != -1689, "test48 case 21 failed\n");
4677 sljit_free_code(code.code, NULL);
4678 successful_tests++;
4681 static void test49(void)
4683 /* Test floating point conversions. */
4684 executable_code code;
4685 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
4686 int i;
4687 sljit_f64 dbuf[10];
4688 sljit_f32 sbuf[9];
4689 sljit_sw wbuf[9];
4690 sljit_s32 ibuf[9];
4691 sljit_s32* dbuf_ptr = (sljit_s32*)dbuf;
4692 sljit_s32* sbuf_ptr = (sljit_s32*)sbuf;
4694 if (verbose)
4695 printf("Run test49\n");
4697 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
4698 if (verbose)
4699 printf("no fpu available, test49 skipped\n");
4700 successful_tests++;
4701 if (compiler)
4702 sljit_free_compiler(compiler);
4703 return;
4706 FAILED(!compiler, "cannot create compiler\n");
4708 for (i = 0; i < 9; i++) {
4709 dbuf_ptr[i << 1] = -1;
4710 dbuf_ptr[(i << 1) + 1] = -1;
4711 sbuf_ptr[i] = -1;
4712 wbuf[i] = -1;
4713 ibuf[i] = -1;
4716 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4717 dbuf[9] = (sljit_f64)SLJIT_W(0x1122334455);
4718 #endif
4719 dbuf[0] = 673.75;
4720 sbuf[0] = -879.75;
4721 wbuf[0] = 345;
4722 ibuf[0] = -249;
4724 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(VOID), 3, 3, 3, 0, 0);
4725 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, (sljit_sw)&dbuf);
4726 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, (sljit_sw)&sbuf);
4727 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, (sljit_sw)&wbuf);
4728 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, (sljit_sw)&ibuf);
4730 /* dbuf[2] */
4731 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_F32, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_S1), 0);
4732 /* sbuf[2] */
4733 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_F64, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_S0), 0);
4734 /* wbuf[2] */
4735 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F64, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 0);
4736 /* wbuf[4] */
4737 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F32, SLJIT_MEM1(SLJIT_S2), 4 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S1), 0);
4738 /* ibuf[2] */
4739 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F64, SLJIT_MEM1(SLJIT_R2), 2 * sizeof(sljit_s32), SLJIT_MEM1(SLJIT_S0), 0);
4740 /* ibuf[4] */
4741 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F32, SLJIT_MEM1(SLJIT_R2), 4 * sizeof(sljit_s32), SLJIT_MEM1(SLJIT_S1), 0);
4742 /* dbuf[4] */
4743 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_S2), 0);
4744 /* sbuf[4] */
4745 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_SW, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_S2), 0);
4746 /* dbuf[6] */
4747 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_S32, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_R2), 0);
4748 /* sbuf[6] */
4749 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_S32, SLJIT_MEM1(SLJIT_S1), 6 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_R2), 0);
4751 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4752 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F64, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f64));
4753 /* wbuf[8] */
4754 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S2), 8 * sizeof(sljit_sw), SLJIT_R0, 0);
4755 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f64));
4756 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F64, SLJIT_R0, 0, SLJIT_FR2, 0);
4757 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
4758 sljit_emit_op2(compiler, SLJIT_AND32, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffff);
4759 /* ibuf[8] */
4760 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_R2), 8 * sizeof(sljit_s32), SLJIT_R0, 0);
4761 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x4455667788));
4762 /* dbuf[8] */
4763 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_f64), SLJIT_R0, 0);
4764 /* dbuf[9] */
4765 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_S32, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f64), SLJIT_IMM, SLJIT_W(0x7766554433));
4766 #endif
4768 sljit_emit_return_void(compiler);
4770 code.code = sljit_generate_code(compiler);
4771 CHECK(compiler);
4772 sljit_free_compiler(compiler);
4774 code.func0();
4776 FAILED(dbuf_ptr[(1 * 2) + 0] != -1, "test49 case 1 failed\n");
4777 FAILED(dbuf_ptr[(1 * 2) + 1] != -1, "test49 case 2 failed\n");
4778 FAILED(dbuf[2] != -879.75, "test49 case 3 failed\n");
4779 FAILED(dbuf_ptr[(3 * 2) + 0] != -1, "test49 case 4 failed\n");
4780 FAILED(dbuf_ptr[(3 * 2) + 1] != -1, "test49 case 5 failed\n");
4781 FAILED(dbuf[4] != 345, "test49 case 6 failed\n");
4782 FAILED(dbuf_ptr[(5 * 2) + 0] != -1, "test49 case 7 failed\n");
4783 FAILED(dbuf_ptr[(5 * 2) + 1] != -1, "test49 case 8 failed\n");
4784 FAILED(dbuf[6] != -249, "test49 case 9 failed\n");
4785 FAILED(dbuf_ptr[(7 * 2) + 0] != -1, "test49 case 10 failed\n");
4786 FAILED(dbuf_ptr[(7 * 2) + 1] != -1, "test49 case 11 failed\n");
4788 FAILED(sbuf_ptr[1] != -1, "test49 case 12 failed\n");
4789 FAILED(sbuf[2] != 673.75, "test49 case 13 failed\n");
4790 FAILED(sbuf_ptr[3] != -1, "test49 case 14 failed\n");
4791 FAILED(sbuf[4] != 345, "test49 case 15 failed\n");
4792 FAILED(sbuf_ptr[5] != -1, "test49 case 16 failed\n");
4793 FAILED(sbuf[6] != -249, "test49 case 17 failed\n");
4794 FAILED(sbuf_ptr[7] != -1, "test49 case 18 failed\n");
4796 FAILED(wbuf[1] != -1, "test49 case 19 failed\n");
4797 FAILED(wbuf[2] != 673, "test49 case 20 failed\n");
4798 FAILED(wbuf[3] != -1, "test49 case 21 failed\n");
4799 FAILED(wbuf[4] != -879, "test49 case 22 failed\n");
4800 FAILED(wbuf[5] != -1, "test49 case 23 failed\n");
4802 FAILED(ibuf[1] != -1, "test49 case 24 failed\n");
4803 FAILED(ibuf[2] != 673, "test49 case 25 failed\n");
4804 FAILED(ibuf[3] != -1, "test49 case 26 failed\n");
4805 FAILED(ibuf[4] != -879, "test49 case 27 failed\n");
4806 FAILED(ibuf[5] != -1, "test49 case 28 failed\n");
4808 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4809 FAILED(dbuf[8] != (sljit_f64)SLJIT_W(0x4455667788), "test49 case 29 failed\n");
4810 FAILED(dbuf[9] != (sljit_f64)SLJIT_W(0x66554433), "test49 case 30 failed\n");
4811 FAILED(wbuf[8] != SLJIT_W(0x1122334455), "test48 case 31 failed\n");
4812 FAILED(ibuf[8] == 0x4455, "test48 case 32 failed\n");
4813 #endif
4815 sljit_free_code(code.code, NULL);
4816 successful_tests++;
4819 static void test50(void)
4821 /* Test stack and floating point operations. */
4822 executable_code code;
4823 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
4824 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4825 sljit_uw size1, size2, size3;
4826 int result;
4827 #endif
4828 sljit_f32 sbuf[7];
4830 if (verbose)
4831 printf("Run test50\n");
4833 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
4834 if (verbose)
4835 printf("no fpu available, test50 skipped\n");
4836 successful_tests++;
4837 if (compiler)
4838 sljit_free_compiler(compiler);
4839 return;
4842 FAILED(!compiler, "cannot create compiler\n");
4844 sbuf[0] = 245.5;
4845 sbuf[1] = -100.25;
4846 sbuf[2] = 713.75;
4848 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 3, 3, 6, 0, 8 * sizeof(sljit_f32));
4850 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_MEM1(SLJIT_S0), 0);
4851 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), 0);
4852 /* sbuf[3] */
4853 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), sizeof(sljit_f32));
4854 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_f32), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4855 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));
4856 /* sbuf[4] */
4857 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), 2 * sizeof(sljit_f32));
4858 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 2 * sizeof(sljit_f32), SLJIT_IMM, 5934);
4859 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));
4860 /* sbuf[5] */
4861 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), 3 * sizeof(sljit_f32));
4863 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4864 size1 = compiler->size;
4865 #endif
4866 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f32));
4867 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4868 size2 = compiler->size;
4869 #endif
4870 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR5, 0, SLJIT_FR2, 0);
4871 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4872 size3 = compiler->size;
4873 #endif
4874 /* sbuf[6] */
4875 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f32), SLJIT_FR5, 0);
4876 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4877 result = (compiler->size - size3) == (size3 - size2) && (size3 - size2) == (size2 - size1);
4878 #endif
4880 sljit_emit_return_void(compiler);
4882 code.code = sljit_generate_code(compiler);
4883 CHECK(compiler);
4884 sljit_free_compiler(compiler);
4886 code.func1((sljit_sw)&sbuf);
4888 FAILED(sbuf[3] != 245.5, "test50 case 1 failed\n");
4889 FAILED(sbuf[4] != 145.25, "test50 case 2 failed\n");
4890 FAILED(sbuf[5] != 5934, "test50 case 3 failed\n");
4891 FAILED(sbuf[6] != 713.75, "test50 case 4 failed\n");
4892 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4893 FAILED(!result, "test50 case 5 failed\n");
4894 #endif
4896 sljit_free_code(code.code, NULL);
4897 successful_tests++;
4900 static void test51(void)
4902 /* Test all registers provided by the CPU. */
4903 executable_code code;
4904 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
4905 struct sljit_jump* jump;
4906 sljit_sw buf[2];
4907 sljit_s32 i;
4909 if (verbose)
4910 printf("Run test51\n");
4912 FAILED(!compiler, "cannot create compiler\n");
4914 buf[0] = 39;
4916 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(VOID), SLJIT_NUMBER_OF_REGISTERS, 0, 0, 0, 0);
4918 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4919 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 32);
4921 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)buf);
4922 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
4924 for (i = 2; i < SLJIT_NUMBER_OF_REGISTERS; i++) {
4925 if (sljit_get_register_index(SLJIT_R(i)) >= 0) {
4926 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_R0, 0);
4927 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_R(i)), 0);
4928 } else
4929 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, buf[0]);
4932 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 32);
4933 for (i = 2; i < SLJIT_NUMBER_OF_REGISTERS; i++) {
4934 if (sljit_get_register_index(SLJIT_R(i)) >= 0) {
4935 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_R0, 0);
4936 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_R(i)), 32);
4937 } else
4938 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, buf[0]);
4941 for (i = 2; i < SLJIT_NUMBER_OF_REGISTERS; i++) {
4942 if (sljit_get_register_index(SLJIT_R(i)) >= 0) {
4943 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 32);
4944 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM2(SLJIT_R(i), SLJIT_R0), 0);
4945 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM2(SLJIT_R0, SLJIT_R(i)), 0);
4946 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 8);
4947 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM2(SLJIT_R0, SLJIT_R(i)), 2);
4948 } else
4949 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 3 * buf[0]);
4952 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 32 + sizeof(sljit_sw), SLJIT_R1, 0);
4954 sljit_emit_return_void(compiler);
4956 code.code = sljit_generate_code(compiler);
4957 CHECK(compiler);
4958 sljit_free_compiler(compiler);
4960 code.func0();
4962 FAILED(buf[1] != (39 * 5 * (SLJIT_NUMBER_OF_REGISTERS - 2)), "test51 case 1 failed\n");
4964 sljit_free_code(code.code, NULL);
4966 /* Next test. */
4968 compiler = sljit_create_compiler(NULL, NULL);
4970 FAILED(!compiler, "cannot create compiler\n");
4972 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(W), SLJIT_NUMBER_OF_SCRATCH_REGISTERS, SLJIT_NUMBER_OF_SAVED_REGISTERS, 0, 0, 0);
4974 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4975 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 17);
4977 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS0(W));
4978 /* SLJIT_R0 contains the first value. */
4979 for (i = 1; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4980 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R(i), 0);
4982 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
4984 sljit_set_label(jump, sljit_emit_label(compiler));
4985 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(VOID), SLJIT_NUMBER_OF_REGISTERS, 0, 0, 0, 0);
4986 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4987 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 35);
4988 sljit_emit_return_void(compiler);
4990 code.code = sljit_generate_code(compiler);
4991 CHECK(compiler);
4992 sljit_free_compiler(compiler);
4994 FAILED(code.func0() != (SLJIT_NUMBER_OF_SCRATCH_REGISTERS * 35 + SLJIT_NUMBER_OF_SAVED_REGISTERS * 17), "test51 case 2 failed\n");
4996 sljit_free_code(code.code, NULL);
4998 /* Next test. */
5000 compiler = sljit_create_compiler(NULL, NULL);
5002 FAILED(!compiler, "cannot create compiler\n");
5004 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(W), SLJIT_NUMBER_OF_SCRATCH_REGISTERS, SLJIT_NUMBER_OF_SAVED_REGISTERS, 0, 0, 0);
5006 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5007 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 68);
5009 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS0(W));
5010 /* SLJIT_R0 contains the first value. */
5011 for (i = 1; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5012 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R(i), 0);
5014 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
5016 sljit_set_label(jump, sljit_emit_label(compiler));
5017 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(VOID), 0, SLJIT_NUMBER_OF_REGISTERS, 0, 0, 0);
5018 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5019 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S(i), 0, SLJIT_IMM, 43);
5020 sljit_emit_return_void(compiler);
5022 code.code = sljit_generate_code(compiler);
5023 CHECK(compiler);
5024 sljit_free_compiler(compiler);
5026 FAILED(code.func0() != (SLJIT_NUMBER_OF_SCRATCH_REGISTERS * 43 + SLJIT_NUMBER_OF_SAVED_REGISTERS * 68), "test51 case 3 failed\n");
5028 sljit_free_code(code.code, NULL);
5029 successful_tests++;
5032 static void test52(void)
5034 /* Test all registers provided by the CPU. */
5035 executable_code code;
5036 struct sljit_compiler* compiler;
5037 struct sljit_jump* jump;
5038 sljit_f64 buf[3];
5039 sljit_s32 i;
5041 if (verbose)
5042 printf("Run test52\n");
5044 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5045 if (verbose)
5046 printf("no fpu available, test52 skipped\n");
5047 successful_tests++;
5048 return;
5051 /* Next test. */
5053 compiler = sljit_create_compiler(NULL, NULL);
5054 FAILED(!compiler, "cannot create compiler\n");
5055 buf[0] = 6.25;
5056 buf[1] = 17.75;
5058 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 0, 1, SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS, SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS, 0);
5060 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5061 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR(i), 0, SLJIT_MEM1(SLJIT_S0), 0);
5063 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS0(VOID));
5064 /* SLJIT_FR0 contains the first value. */
5065 for (i = 1; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5066 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR0, 0, SLJIT_FR0, 0, SLJIT_FR(i), 0);
5067 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64), SLJIT_FR0, 0);
5069 sljit_emit_return_void(compiler);
5071 sljit_set_label(jump, sljit_emit_label(compiler));
5072 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(VOID), 1, 0, SLJIT_NUMBER_OF_FLOAT_REGISTERS, 0, 0);
5073 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[1]);
5074 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5075 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR(i), 0, SLJIT_MEM1(SLJIT_R0), 0);
5076 sljit_emit_return_void(compiler);
5078 code.code = sljit_generate_code(compiler);
5079 CHECK(compiler);
5080 sljit_free_compiler(compiler);
5082 code.func1((sljit_sw)&buf);
5083 FAILED(buf[2] != (SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS * 17.75 + SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS * 6.25), "test52 case 1 failed\n");
5085 sljit_free_code(code.code, NULL);
5087 /* Next test. */
5089 compiler = sljit_create_compiler(NULL, NULL);
5090 FAILED(!compiler, "cannot create compiler\n");
5091 buf[0] = -32.5;
5092 buf[1] = -11.25;
5094 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 0, 1, SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS, SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS, 0);
5096 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5097 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR(i), 0, SLJIT_MEM1(SLJIT_S0), 0);
5099 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS0(VOID));
5100 /* SLJIT_FR0 contains the first value. */
5101 for (i = 1; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5102 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR0, 0, SLJIT_FR0, 0, SLJIT_FR(i), 0);
5103 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64), SLJIT_FR0, 0);
5105 sljit_emit_return_void(compiler);
5107 sljit_set_label(jump, sljit_emit_label(compiler));
5108 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(VOID), 1, 0, 0, SLJIT_NUMBER_OF_FLOAT_REGISTERS, 0);
5109 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[1]);
5110 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5111 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FS(i), 0, SLJIT_MEM1(SLJIT_R0), 0);
5112 sljit_emit_return_void(compiler);
5114 code.code = sljit_generate_code(compiler);
5115 CHECK(compiler);
5116 sljit_free_compiler(compiler);
5118 code.func1((sljit_sw)&buf);
5119 FAILED(buf[2] != (SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS * -11.25 + SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS * -32.5), "test52 case 2 failed\n");
5121 sljit_free_code(code.code, NULL);
5122 successful_tests++;
5125 static void test53(void)
5127 /* Check SLJIT_DOUBLE_ALIGNMENT. */
5128 executable_code code;
5129 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
5130 sljit_sw buf[1];
5132 if (verbose)
5133 printf("Run test53\n");
5135 FAILED(!compiler, "cannot create compiler\n");
5136 buf[0] = -1;
5138 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, SLJIT_ARGS1(VOID, P), 1, 1, 0, 0, 2 * sizeof(sljit_sw));
5140 sljit_get_local_base(compiler, SLJIT_R0, 0, 0);
5141 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
5143 sljit_emit_return_void(compiler);
5145 code.code = sljit_generate_code(compiler);
5146 CHECK(compiler);
5147 sljit_free_compiler(compiler);
5149 code.func1((sljit_sw)&buf);
5151 FAILED((buf[0] & ((sljit_sw)sizeof(sljit_f64) - 1)) != 0, "test53 case 1 failed\n");
5153 sljit_free_code(code.code, NULL);
5155 /* Next test. */
5157 compiler = sljit_create_compiler(NULL, NULL);
5158 FAILED(!compiler, "cannot create compiler\n");
5159 buf[0] = -1;
5161 /* One more saved register to break the alignment on x86-32. */
5162 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, SLJIT_ARGS1(VOID, P), 1, 2, 0, 0, 2 * sizeof(sljit_sw));
5164 sljit_get_local_base(compiler, SLJIT_R0, 0, 0);
5165 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
5167 sljit_emit_return_void(compiler);
5169 code.code = sljit_generate_code(compiler);
5170 CHECK(compiler);
5171 sljit_free_compiler(compiler);
5173 code.func1((sljit_sw)&buf);
5175 FAILED((buf[0] & ((sljit_sw)sizeof(sljit_f64) - 1)) != 0, "test53 case 2 failed\n");
5177 sljit_free_code(code.code, NULL);
5178 successful_tests++;
5181 static void test54(void)
5183 /* Check cmov. */
5184 executable_code code;
5185 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
5186 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
5187 sljit_sw large_num = SLJIT_W(0x1234567812345678);
5188 #else
5189 sljit_sw large_num = SLJIT_W(0x12345678);
5190 #endif
5191 int i;
5192 sljit_sw buf[19];
5193 sljit_s32 ibuf[4];
5195 union {
5196 sljit_f32 value;
5197 sljit_s32 s32_value;
5198 } sbuf[3];
5200 sbuf[0].s32_value = 0x7fffffff;
5201 sbuf[1].value = 7.5;
5202 sbuf[2].value = -14.75;
5204 if (verbose)
5205 printf("Run test54\n");
5207 FAILED(!compiler, "cannot create compiler\n");
5209 for (i = 0; i < 19; i++)
5210 buf[i] = 0;
5211 for (i = 0; i < 4; i++)
5212 ibuf[i] = 0;
5214 sljit_emit_enter(compiler, 0, SLJIT_ARGS3(VOID, P, P, P), 5, 3, 3, 0, 0);
5216 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 17);
5217 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 34);
5218 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R0, 0, SLJIT_IMM, -10);
5219 sljit_emit_cmov(compiler, SLJIT_SIG_LESS, SLJIT_R0, SLJIT_R1, 0);
5220 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
5221 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_R0, 0, SLJIT_IMM, -10);
5222 sljit_emit_cmov(compiler, SLJIT_SIG_GREATER, SLJIT_R0, SLJIT_R1, 0);
5223 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
5225 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 24);
5226 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_IMM, 24);
5227 sljit_emit_cmov(compiler, SLJIT_NOT_EQUAL, SLJIT_R0, SLJIT_IMM, 66);
5228 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
5229 sljit_emit_cmov(compiler, SLJIT_EQUAL, SLJIT_R0, SLJIT_IMM, 78);
5230 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_R0, 0);
5231 sljit_emit_cmov(compiler, SLJIT_EQUAL, SLJIT_R0, SLJIT_IMM, large_num);
5232 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
5234 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
5235 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R3) == -1 && sljit_get_register_index(SLJIT_R4) == -1);
5236 #endif
5237 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 7);
5238 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -45);
5239 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 8);
5240 sljit_emit_cmov(compiler, SLJIT_OVERFLOW, SLJIT_R3, SLJIT_IMM, 35);
5241 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R3, 0);
5242 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, large_num);
5243 sljit_emit_op2u(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_IMM, large_num);
5244 sljit_emit_cmov(compiler, SLJIT_OVERFLOW, SLJIT_R3, SLJIT_IMM, 35);
5245 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_R3, 0);
5247 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 71);
5248 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 13);
5249 sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 8);
5250 sljit_emit_cmov(compiler, SLJIT_EQUAL, SLJIT_R3, SLJIT_R0, 0);
5251 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R3, 0);
5253 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 12);
5254 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -29);
5255 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 8);
5256 sljit_emit_cmov(compiler, SLJIT_NOT_OVERFLOW, SLJIT_R0, SLJIT_R3, 0);
5257 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R3, 0);
5259 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 16);
5260 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -12);
5261 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_IMM, 21);
5262 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_IMM, 8);
5263 sljit_emit_cmov(compiler, SLJIT_NOT_EQUAL, SLJIT_R3, SLJIT_R4, 0);
5264 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_R3, 0);
5265 sljit_emit_cmov(compiler, SLJIT_EQUAL, SLJIT_R3, SLJIT_R4, 0);
5266 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_R3, 0);
5268 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5269 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S2), 0);
5270 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f32));
5271 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_f32));
5273 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 16);
5274 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
5275 sljit_emit_cmov(compiler, SLJIT_EQUAL_F32, SLJIT_R0, SLJIT_IMM, -45);
5276 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_R0, 0);
5277 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_GREATER_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
5278 sljit_emit_cmov(compiler, SLJIT_GREATER_F32, SLJIT_R0, SLJIT_IMM, -45);
5279 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_R0, 0);
5280 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_GREATER_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
5281 sljit_emit_cmov(compiler, SLJIT_GREATER_EQUAL_F32, SLJIT_R0, SLJIT_IMM, 33);
5282 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_R0, 0);
5284 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
5285 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_LESS_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
5286 sljit_emit_cmov(compiler, SLJIT_LESS_F32, SLJIT_R0, SLJIT_IMM, -70);
5287 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_sw), SLJIT_R0, 0);
5288 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_LESS_EQUAL_F, SLJIT_FR2, 0, SLJIT_FR1, 0);
5289 sljit_emit_cmov(compiler, SLJIT_LESS_EQUAL_F32, SLJIT_R0, SLJIT_IMM, -60);
5290 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 15 * sizeof(sljit_sw), SLJIT_R0, 0);
5291 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_NOT_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
5292 sljit_emit_cmov(compiler, SLJIT_NOT_EQUAL_F32, SLJIT_R0, SLJIT_IMM, 31);
5293 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 16 * sizeof(sljit_sw), SLJIT_R0, 0);
5295 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 53);
5296 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_ORDERED_F, SLJIT_FR1, 0, SLJIT_FR0, 0);
5297 sljit_emit_cmov(compiler, SLJIT_ORDERED_F32, SLJIT_R0, SLJIT_IMM, 17);
5298 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 17 * sizeof(sljit_sw), SLJIT_R0, 0);
5299 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_UNORDERED_F, SLJIT_FR1, 0, SLJIT_FR0, 0);
5300 sljit_emit_cmov(compiler, SLJIT_UNORDERED_F32, SLJIT_R0, SLJIT_IMM, 59);
5301 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_sw), SLJIT_R0, 0);
5304 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 177);
5305 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_LESS, SLJIT_R0, 0, SLJIT_IMM, 178);
5306 sljit_emit_cmov(compiler, SLJIT_LESS, SLJIT_R0 | SLJIT_32, SLJIT_IMM, 200);
5307 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_R0, 0);
5309 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 95);
5310 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R3, 0, SLJIT_IMM, 177);
5311 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_LESS_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 95);
5312 sljit_emit_cmov(compiler, SLJIT_LESS_EQUAL, SLJIT_R3 | SLJIT_32, SLJIT_R0, 0);
5313 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0);
5314 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32), SLJIT_R3, 0);
5316 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R3, 0, SLJIT_IMM, 56);
5317 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R4, 0, SLJIT_IMM, -63);
5318 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_SIG_LESS, SLJIT_R3, 0, SLJIT_R4, 0);
5319 sljit_emit_cmov(compiler, SLJIT_SIG_LESS, SLJIT_R3 | SLJIT_32, SLJIT_R4, 0);
5320 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_s32), SLJIT_R3, 0);
5321 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_SIG_GREATER, SLJIT_R3, 0, SLJIT_R4, 0);
5322 sljit_emit_cmov(compiler, SLJIT_SIG_GREATER, SLJIT_R3 | SLJIT_32, SLJIT_R4, 0);
5323 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_s32), SLJIT_R3, 0);
5325 sljit_emit_return_void(compiler);
5327 code.code = sljit_generate_code(compiler);
5328 CHECK(compiler);
5329 sljit_free_compiler(compiler);
5331 code.func3((sljit_sw)&buf, (sljit_sw)&ibuf, (sljit_sw)&sbuf);
5333 FAILED(buf[0] != 17, "test54 case 1 failed\n");
5334 FAILED(buf[1] != 34, "test54 case 2 failed\n");
5335 FAILED(buf[2] != 24, "test54 case 3 failed\n");
5336 FAILED(buf[3] != 78, "test54 case 4 failed\n");
5337 FAILED(buf[4] != large_num, "test54 case 5 failed\n");
5338 FAILED(buf[5] != -45, "test54 case 6 failed\n");
5339 FAILED(buf[6] != 35, "test54 case 7 failed\n");
5340 FAILED(buf[7] != 71, "test54 case 8 failed\n");
5341 FAILED(buf[8] != -29, "test54 case 9 failed\n");
5342 FAILED(buf[9] != -12, "test54 case 10 failed\n");
5343 FAILED(buf[10] != 21, "test54 case 11 failed\n");
5345 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5346 FAILED(buf[11] != 16, "test54 case 12 failed\n");
5347 FAILED(buf[12] != -45, "test54 case 13 failed\n");
5348 FAILED(buf[13] != 33, "test54 case 14 failed\n");
5349 FAILED(buf[14] != 8, "test54 case 15 failed\n");
5350 FAILED(buf[15] != -60, "test54 case 16 failed\n");
5351 FAILED(buf[16] != 31, "test54 case 17 failed\n");
5352 FAILED(buf[17] != 53, "test54 case 18 failed\n");
5353 FAILED(buf[18] != 59, "test54 case 19 failed\n");
5356 FAILED(ibuf[0] != 200, "test54 case 12 failed\n");
5357 FAILED(ibuf[1] != 95, "test54 case 13 failed\n");
5358 FAILED(ibuf[2] != 56, "test54 case 14 failed\n");
5359 FAILED(ibuf[3] != -63, "test54 case 15 failed\n");
5361 sljit_free_code(code.code, NULL);
5362 successful_tests++;
5365 static void test55(void)
5367 /* Check value preservation. */
5368 executable_code code;
5369 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
5370 sljit_sw buf[2];
5371 sljit_s32 i;
5373 if (verbose)
5374 printf("Run test55\n");
5376 FAILED(!compiler, "cannot create compiler\n");
5377 buf[0] = 0;
5378 buf[1] = 0;
5380 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(VOID), SLJIT_NUMBER_OF_REGISTERS, 0, 0, 0, sizeof (sljit_sw));
5382 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, 217);
5384 /* Check 1 */
5385 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5386 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 118);
5388 sljit_emit_op0(compiler, SLJIT_DIVMOD_SW);
5390 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
5392 for (i = 2; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5393 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R(i), 0);
5394 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_SP), 0);
5396 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM0(), (sljit_sw)(buf + 0), SLJIT_R0, 0);
5398 /* Check 2 */
5399 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5400 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 146);
5402 sljit_emit_op0(compiler, SLJIT_DIV_SW);
5404 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
5406 for (i = 1; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5407 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R(i), 0);
5408 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_SP), 0);
5410 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM0(), (sljit_sw)(buf + 1), SLJIT_R0, 0);
5412 sljit_emit_return_void(compiler);
5414 code.code = sljit_generate_code(compiler);
5415 CHECK(compiler);
5416 sljit_free_compiler(compiler);
5418 code.func0();
5420 FAILED(buf[0] != (SLJIT_NUMBER_OF_REGISTERS - 2) * 118 + 217, "test55 case 1 failed\n");
5421 FAILED(buf[1] != (SLJIT_NUMBER_OF_REGISTERS - 1) * 146 + 217, "test55 case 2 failed\n");
5423 sljit_free_code(code.code, NULL);
5424 successful_tests++;
5427 static void test56(void)
5429 /* Check integer substraction with negative immediate. */
5430 executable_code code;
5431 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
5432 sljit_sw buf[13];
5433 sljit_s32 i;
5435 if (verbose)
5436 printf("Run test56\n");
5438 for (i = 0; i < 13; i++)
5439 buf[i] = 77;
5441 FAILED(!compiler, "cannot create compiler\n");
5443 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 3, 1, 0, 0, 0);
5445 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 90 << 12);
5446 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5447 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R1, 0);
5448 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_SIG_GREATER);
5449 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5450 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R1, 0);
5451 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_LESS);
5452 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER_EQUAL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5453 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_SIG_GREATER_EQUAL);
5454 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS_EQUAL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5455 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_LESS_EQUAL);
5456 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5457 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_GREATER);
5458 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5459 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_SIG_LESS);
5461 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 90);
5462 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, -91);
5463 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R0, 0);
5464 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_SIG_GREATER);
5465 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 90);
5466 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, -91);
5467 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_LESS_EQUAL);
5469 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, -0x7fffffff);
5470 sljit_emit_op2(compiler, SLJIT_ADD32 | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5471 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_OVERFLOW);
5473 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, -0x7fffffff-1);
5474 sljit_emit_op1(compiler, SLJIT_NEG32 | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R0, 0);
5475 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_OVERFLOW);
5477 sljit_emit_return_void(compiler);
5479 code.code = sljit_generate_code(compiler);
5480 CHECK(compiler);
5481 sljit_free_compiler(compiler);
5483 code.func1((sljit_sw)&buf);
5485 FAILED(buf[0] != (181 << 12), "test56 case 1 failed\n");
5486 FAILED(buf[1] != 1, "test56 case 2 failed\n");
5487 FAILED(buf[2] != (181 << 12), "test56 case 3 failed\n");
5488 FAILED(buf[3] != 1, "test56 case 4 failed\n");
5489 FAILED(buf[4] != 1, "test56 case 5 failed\n");
5490 FAILED(buf[5] != 1, "test56 case 6 failed\n");
5491 FAILED(buf[6] != 0, "test56 case 7 failed\n");
5492 FAILED(buf[7] != 0, "test56 case 8 failed\n");
5493 FAILED(buf[8] != 181, "test56 case 9 failed\n");
5494 FAILED(buf[9] != 1, "test56 case 10 failed\n");
5495 FAILED(buf[10] != 1, "test56 case 11 failed\n");
5496 FAILED(buf[11] != 1, "test56 case 12 failed\n");
5497 FAILED(buf[12] != 1, "test56 case 13 failed\n");
5499 sljit_free_code(code.code, NULL);
5500 successful_tests++;
5503 static void test57(void)
5505 /* Check prefetch instructions. */
5506 executable_code code;
5507 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
5508 struct sljit_label* labels[5];
5509 sljit_p addr[5];
5510 int i;
5512 if (verbose)
5513 printf("Run test57\n");
5515 FAILED(!compiler, "cannot create compiler\n");
5517 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(VOID), 3, 1, 0, 0, 0);
5519 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
5520 labels[0] = sljit_emit_label(compiler);
5521 /* Should never crash. */
5522 sljit_emit_op_src(compiler, SLJIT_PREFETCH_L1, SLJIT_MEM2(SLJIT_R0, SLJIT_R0), 2);
5523 labels[1] = sljit_emit_label(compiler);
5524 sljit_emit_op_src(compiler, SLJIT_PREFETCH_L2, SLJIT_MEM0(), 0);
5525 labels[2] = sljit_emit_label(compiler);
5526 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
5527 sljit_emit_op_src(compiler, SLJIT_PREFETCH_L3, SLJIT_MEM1(SLJIT_R0), SLJIT_W(0x1122334455667788));
5528 #else
5529 sljit_emit_op_src(compiler, SLJIT_PREFETCH_L3, SLJIT_MEM1(SLJIT_R0), 0x11223344);
5530 #endif
5531 labels[3] = sljit_emit_label(compiler);
5532 sljit_emit_op_src(compiler, SLJIT_PREFETCH_ONCE, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_sw));
5533 labels[4] = sljit_emit_label(compiler);
5535 sljit_emit_return_void(compiler);
5537 code.code = sljit_generate_code(compiler);
5538 CHECK(compiler);
5540 for (i = 0; i < 5; i++)
5541 addr[i] = sljit_get_label_addr(labels[i]);
5543 sljit_free_compiler(compiler);
5545 code.func0();
5547 if (sljit_has_cpu_feature(SLJIT_HAS_PREFETCH)) {
5548 FAILED(addr[0] == addr[1], "test57 case 1 failed\n");
5549 FAILED(addr[1] == addr[2], "test57 case 2 failed\n");
5550 FAILED(addr[2] == addr[3], "test57 case 3 failed\n");
5551 FAILED(addr[3] == addr[4], "test57 case 4 failed\n");
5553 else {
5554 FAILED(addr[0] != addr[1], "test57 case 1 failed\n");
5555 FAILED(addr[1] != addr[2], "test57 case 2 failed\n");
5556 FAILED(addr[2] != addr[3], "test57 case 3 failed\n");
5557 FAILED(addr[3] != addr[4], "test57 case 4 failed\n");
5560 sljit_free_code(code.code, NULL);
5561 successful_tests++;
5564 static sljit_f64 SLJIT_FUNC test58_f1(sljit_f32 a, sljit_f32 b, sljit_f64 c)
5566 return (sljit_f64)a + (sljit_f64)b + c;
5569 static sljit_f32 SLJIT_FUNC test58_f2(sljit_sw a, sljit_f64 b, sljit_f32 c)
5571 return (sljit_f32)((sljit_f64)a + b + (sljit_f64)c);
5574 static sljit_f64 SLJIT_FUNC test58_f3(sljit_sw a, sljit_f32 b, sljit_sw c)
5576 return (sljit_f64)a + (sljit_f64)b + (sljit_f64)c;
5579 static sljit_f64 test58_f4(sljit_f32 a, sljit_sw b)
5581 return (sljit_f64)a + (sljit_f64)b;
5584 static sljit_f32 test58_f5(sljit_f32 a, sljit_f64 b, sljit_s32 c)
5586 return (sljit_f32)((sljit_f64)a + b + (sljit_f64)c);
5589 static sljit_sw SLJIT_FUNC test58_f6(sljit_f64 a, sljit_sw b)
5591 return (sljit_sw)(a + (sljit_f64)b);
5594 static void test58(void)
5596 /* Check function calls with floating point arguments. */
5597 executable_code code;
5598 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
5599 struct sljit_jump* jump = NULL;
5600 sljit_f64 dbuf[7];
5601 sljit_f32 sbuf[7];
5602 sljit_sw wbuf[2];
5604 if (verbose)
5605 printf("Run test58\n");
5607 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5608 if (verbose)
5609 printf("no fpu available, test58 skipped\n");
5610 successful_tests++;
5611 if (compiler)
5612 sljit_free_compiler(compiler);
5613 return;
5616 dbuf[0] = 5.25;
5617 dbuf[1] = 0.0;
5618 dbuf[2] = 2.5;
5619 dbuf[3] = 0.0;
5620 dbuf[4] = 0.0;
5621 dbuf[5] = 0.0;
5622 dbuf[6] = -18.0;
5624 sbuf[0] = 6.75;
5625 sbuf[1] = -3.5;
5626 sbuf[2] = 1.5;
5627 sbuf[3] = 0.0;
5628 sbuf[4] = 0.0;
5630 wbuf[0] = 0;
5631 wbuf[1] = 0;
5633 FAILED(!compiler, "cannot create compiler\n");
5635 sljit_emit_enter(compiler, 0, SLJIT_ARGS3(VOID, P, P, P), 3, 3, 4, 0, sizeof(sljit_sw));
5637 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), 0);
5638 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f32));
5639 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 0);
5640 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS3(F64, F32, F32, F64), SLJIT_IMM, SLJIT_FUNC_ADDR(test58_f1));
5641 /* dbuf[1] */
5642 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64), SLJIT_FR0, 0);
5644 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f32));
5645 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f32));
5646 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64));
5647 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS3(F64, F32, F32, F64));
5648 sljit_set_target(jump, SLJIT_FUNC_UADDR(test58_f1));
5649 /* dbuf[3] */
5650 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f64), SLJIT_FR0, 0);
5652 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test58_f2));
5653 sljit_get_local_base(compiler, SLJIT_R1, 0, -16);
5654 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 16);
5655 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 0);
5656 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f32));
5657 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS3(F32, W, F64, F32), SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 0);
5658 /* sbuf[3] */
5659 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f32), SLJIT_FR0, 0);
5661 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -4);
5662 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 9);
5663 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 0);
5664 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), 0);
5665 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS3(F64, W, F32, W));
5666 sljit_set_target(jump, SLJIT_FUNC_UADDR(test58_f3));
5667 /* dbuf[4] */
5668 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f64), SLJIT_FR0, 0);
5670 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f32));
5671 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -6);
5672 jump = sljit_emit_call(compiler, SLJIT_CALL_CDECL, SLJIT_ARGS2(F64, F32, W));
5673 sljit_set_target(jump, SLJIT_FUNC_UADDR(test58_f4));
5674 /* dbuf[5] */
5675 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f64), SLJIT_FR0, 0);
5677 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test58_f5));
5678 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f32));
5679 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64));
5680 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
5681 sljit_emit_icall(compiler, SLJIT_CALL_CDECL, SLJIT_ARGS3(F32, F32, F64, 32), SLJIT_MEM1(SLJIT_SP), 0);
5682 /* sbuf[4] */
5683 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_f32), SLJIT_FR0, 0);
5685 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64));
5686 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test58_f6));
5687 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS2(W, F64, W), SLJIT_R0, 0);
5688 /* wbuf[0] */
5689 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S2), 0, SLJIT_R0, 0);
5691 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64));
5692 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 319);
5693 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test58_f6));
5694 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS2(W, F64, W), SLJIT_R1, 0);
5695 /* wbuf[1] */
5696 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_sw), SLJIT_R0, 0);
5698 sljit_emit_return_void(compiler);
5700 code.code = sljit_generate_code(compiler);
5701 CHECK(compiler);
5702 sljit_free_compiler(compiler);
5704 code.func3((sljit_sw)&dbuf, (sljit_sw)&sbuf, (sljit_sw)&wbuf);
5706 FAILED(dbuf[1] != 8.5, "test58 case 1 failed\n");
5707 FAILED(dbuf[3] != 0.5, "test58 case 2 failed\n");
5708 FAILED(sbuf[3] != 17.75, "test58 case 3 failed\n");
5709 FAILED(dbuf[4] != 11.75, "test58 case 4 failed\n");
5710 FAILED(dbuf[5] != -9.5, "test58 case 5 failed\n");
5711 FAILED(sbuf[4] != 12, "test58 case 6 failed\n");
5712 FAILED(wbuf[0] != SLJIT_FUNC_ADDR(test58_f6) - 18, "test58 case 7 failed\n");
5713 FAILED(wbuf[1] != 301, "test58 case 8 failed\n");
5715 sljit_free_code(code.code, NULL);
5716 successful_tests++;
5719 static sljit_sw SLJIT_FUNC test59_f1(sljit_sw a, sljit_s32 b, sljit_sw c, sljit_sw d)
5721 return (sljit_sw)(a + b + c + d - SLJIT_FUNC_ADDR(test59_f1));
5724 static sljit_sw test59_f2(sljit_sw a, sljit_s32 b, sljit_sw c, sljit_sw d)
5726 return (sljit_sw)(a + b + c + d - SLJIT_FUNC_ADDR(test59_f2));
5729 static sljit_s32 SLJIT_FUNC test59_f3(sljit_f64 a, sljit_f32 b, sljit_f64 c, sljit_sw d)
5731 return (sljit_s32)(a + b + c + (sljit_f64)d);
5734 static sljit_f32 SLJIT_FUNC test59_f4(sljit_f32 a, sljit_s32 b, sljit_f64 c, sljit_sw d)
5736 return (sljit_f32)(a + (sljit_f64)b + c + (sljit_f64)d);
5739 static sljit_f32 SLJIT_FUNC test59_f5(sljit_f32 a, sljit_f64 b, sljit_f32 c, sljit_f64 d)
5741 return (sljit_f32)(a + b + c + (sljit_f64)d);
5744 static void test59(void)
5746 /* Check function calls with four arguments. */
5747 executable_code code;
5748 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
5749 struct sljit_jump* jump = NULL;
5750 sljit_sw wbuf[6];
5751 sljit_f64 dbuf[3];
5752 sljit_f32 sbuf[4];
5754 if (verbose)
5755 printf("Run test59\n");
5757 wbuf[0] = 0;
5758 wbuf[1] = 0;
5759 wbuf[2] = 0;
5760 wbuf[3] = SLJIT_FUNC_ADDR(test59_f1);
5761 wbuf[4] = 0;
5762 wbuf[5] = 0;
5764 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5765 dbuf[0] = 5.125;
5766 dbuf[1] = 6.125;
5767 dbuf[2] = 4.25;
5769 sbuf[0] = 0.75;
5770 sbuf[1] = -1.5;
5771 sbuf[2] = 0.0;
5772 sbuf[3] = 0.0;
5775 FAILED(!compiler, "cannot create compiler\n");
5777 sljit_emit_enter(compiler, 0, SLJIT_ARGS3(VOID, P, P, P), 4, 3, 4, 0, sizeof(sljit_sw));
5779 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 33);
5780 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -20);
5781 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test59_f1));
5782 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -40);
5783 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(W, W, 32, W, W), SLJIT_R2, 0);
5784 /* wbuf[0] */
5785 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
5787 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 16);
5788 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -30);
5789 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 50);
5790 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test59_f2));
5791 sljit_emit_icall(compiler, SLJIT_CALL_CDECL, SLJIT_ARGS4(W, W, 32, W, W), SLJIT_R3, 0);
5792 /* wbuf[1] */
5793 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
5795 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test59_f1));
5796 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -25);
5797 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 100);
5798 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -10);
5799 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(W, W, 32, W, W), SLJIT_R0, 0);
5800 /* wbuf[2] */
5801 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
5803 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
5804 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 231);
5805 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 3);
5806 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test59_f1) - 100);
5807 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(W, W, 32, W, W), SLJIT_MEM2(SLJIT_R0, SLJIT_R2), SLJIT_WORD_SHIFT);
5808 /* wbuf[4] */
5809 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
5811 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5812 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), 0);
5813 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S2), 0);
5814 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f64));
5815 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -100);
5816 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(32, F64, F32, F64, W), SLJIT_IMM, SLJIT_FUNC_ADDR(test59_f3));
5817 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
5818 /* wbuf[5] */
5819 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R0, 0);
5821 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f32));
5822 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f64));
5823 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 36);
5824 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 41);
5825 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS4(F32, F32, 32, F64, W));
5826 sljit_set_target(jump, SLJIT_FUNC_UADDR(test59_f4));
5827 /* sbuf[2] */
5828 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_f32), SLJIT_FR0, 0);
5830 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test59_f5));
5831 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S2), 0);
5832 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), 0);
5833 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f32));
5834 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR3, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f64));
5835 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(F32, F32, F64, F32, F64), SLJIT_R0, 0);
5836 /* sbuf[2] */
5837 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S2), 3 * sizeof(sljit_f32), SLJIT_FR0, 0);
5840 sljit_emit_return_void(compiler);
5842 code.code = sljit_generate_code(compiler);
5843 CHECK(compiler);
5844 sljit_free_compiler(compiler);
5846 code.func3((sljit_sw)&wbuf, (sljit_sw)&dbuf, (sljit_sw)&sbuf);
5848 FAILED(wbuf[0] != -27, "test59 case 1 failed\n");
5849 FAILED(wbuf[1] != 36, "test59 case 2 failed\n");
5850 FAILED(wbuf[2] != 65, "test59 case 3 failed\n");
5851 FAILED(wbuf[4] != (sljit_sw)wbuf + 134, "test59 case 4 failed\n");
5853 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5854 FAILED(wbuf[5] != -88, "test59 case 5 failed\n");
5855 FAILED(sbuf[2] != 79.75, "test59 case 6 failed\n");
5856 FAILED(sbuf[3] != 8.625, "test59 case 7 failed\n");
5859 sljit_free_code(code.code, NULL);
5860 successful_tests++;
5863 static void test60(void)
5865 /* Test memory accesses with pre/post updates. */
5866 executable_code code;
5867 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
5868 sljit_s32 i;
5869 sljit_s32 supported[10];
5870 sljit_sw wbuf[18];
5871 sljit_s8 bbuf[4];
5872 sljit_s32 ibuf[4];
5874 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
5875 static sljit_u8 expected[10] = { 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 };
5876 #elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32)
5877 static sljit_u8 expected[10] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
5878 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32)
5879 static sljit_u8 expected[10] = { 1, 0, 1, 1, 0, 1, 1, 1, 0, 0 };
5880 #elif (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
5881 static sljit_u8 expected[10] = { 1, 0, 0, 1, 0, 0, 1, 1, 0, 0 };
5882 #else
5883 static sljit_u8 expected[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
5884 #endif
5886 if (verbose)
5887 printf("Run test60\n");
5889 for (i = 0; i < 18; i++)
5890 wbuf[i] = 0;
5891 wbuf[2] = -887766;
5893 bbuf[0] = 0;
5894 bbuf[1] = 0;
5895 bbuf[2] = -13;
5897 ibuf[0] = -5678;
5898 ibuf[1] = 0;
5899 ibuf[2] = 0;
5901 FAILED(!compiler, "cannot create compiler\n");
5903 sljit_emit_enter(compiler, 0, SLJIT_ARGS3(VOID, P, P, P), 4, 3, 4, 0, sizeof(sljit_sw));
5905 supported[0] = sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R0), 2 * sizeof(sljit_sw));
5906 if (supported[0] == SLJIT_SUCCESS) {
5907 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
5908 sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R0), 2 * sizeof(sljit_sw));
5909 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R1, 0);
5910 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
5913 supported[1] = sljit_emit_mem(compiler, SLJIT_MOV_S8 | SLJIT_MEM_SUPP | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM1(SLJIT_R2), -2 * (sljit_sw)sizeof(sljit_s8));
5914 if (supported[1] == SLJIT_SUCCESS) {
5915 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S1, 0, SLJIT_IMM, 2 * sizeof(sljit_s8));
5916 sljit_emit_mem(compiler, SLJIT_MOV_S8 | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM1(SLJIT_R2), -2 * (sljit_sw)sizeof(sljit_s8));
5917 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_R0, 0);
5918 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R2, 0);
5921 supported[2] = sljit_emit_mem(compiler, SLJIT_MOV_S32 | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_R2, SLJIT_MEM1(SLJIT_R1), -2 * (sljit_sw)sizeof(sljit_s32));
5922 if (supported[2] == SLJIT_SUCCESS) {
5923 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S2, 0, SLJIT_IMM, 2 * sizeof(sljit_s32));
5924 sljit_emit_mem(compiler, SLJIT_MOV_S32 | SLJIT_MEM_PRE, SLJIT_R2, SLJIT_MEM1(SLJIT_R1), -2 * (sljit_sw)sizeof(sljit_s32));
5925 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R2, 0);
5926 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_R1, 0);
5929 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));
5930 if (supported[3] == SLJIT_SUCCESS) {
5931 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -8765);
5932 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, sizeof(sljit_s32));
5933 sljit_emit_mem(compiler, SLJIT_MOV32 | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R2), 2 * sizeof(sljit_s32));
5934 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R2, 0);
5937 supported[4] = sljit_emit_mem(compiler, SLJIT_MOV_S8 | SLJIT_MEM_SUPP | SLJIT_MEM_STORE | SLJIT_MEM_POST, SLJIT_R1, SLJIT_MEM1(SLJIT_R2), -128 * (sljit_sw)sizeof(sljit_s8));
5938 if (supported[4] == SLJIT_SUCCESS) {
5939 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -121);
5940 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_S1, 0);
5941 sljit_emit_mem(compiler, SLJIT_MOV_S8 | SLJIT_MEM_STORE | SLJIT_MEM_POST, SLJIT_R1, SLJIT_MEM1(SLJIT_R2), -128 * (sljit_sw)sizeof(sljit_s8));
5942 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R2, 0);
5945 supported[5] = sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R0), 1);
5946 if (supported[5] == SLJIT_SUCCESS) {
5947 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 9 * sizeof(sljit_sw) - 1);
5948 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -881199);
5949 sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R0), 1);
5950 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_R0, 0);
5953 supported[6] = sljit_emit_mem(compiler, SLJIT_MOV_S32 | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
5954 if (supported[6] == SLJIT_SUCCESS) {
5955 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S2, 0, SLJIT_IMM, 213);
5956 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -213);
5957 sljit_emit_mem(compiler, SLJIT_MOV_S32 | SLJIT_MEM_PRE, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
5958 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_R0, 0);
5959 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_R1, 0);
5962 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);
5963 if (supported[7] == SLJIT_SUCCESS) {
5964 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_S2, 0);
5965 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 2 * sizeof(sljit_s32));
5966 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -7890);
5967 sljit_emit_mem(compiler, SLJIT_MOV_S32 | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
5968 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_R1, 0);
5971 supported[8] = sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 2);
5972 if (supported[8] == SLJIT_SUCCESS) {
5973 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));
5974 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));
5975 sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 2);
5976 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_sw), SLJIT_R0, 0);
5977 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 15 * sizeof(sljit_sw), SLJIT_R1, 0);
5980 supported[9] = sljit_emit_mem(compiler, SLJIT_MOV_S8 | SLJIT_MEM_SUPP | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
5981 if (supported[9] == SLJIT_SUCCESS) {
5982 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S1, 0, SLJIT_IMM, 2 * sizeof(sljit_s8));
5983 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -2 * (sljit_sw)sizeof(sljit_s8));
5984 sljit_emit_mem(compiler, SLJIT_MOV_S8 | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
5985 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 16 * sizeof(sljit_sw), SLJIT_R0, 0);
5986 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 17 * sizeof(sljit_sw), SLJIT_R1, 0);
5989 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);
5990 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);
5992 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) || (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
5993 /* TODO: at least for ARM (both V5 and V7) the range below needs further fixing */
5994 SLJIT_ASSERT(sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R0), 256) == SLJIT_ERR_UNSUPPORTED);
5995 SLJIT_ASSERT(sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_POST, SLJIT_R1, SLJIT_MEM1(SLJIT_R0), -257) == SLJIT_ERR_UNSUPPORTED);
5996 #endif
5998 sljit_emit_return_void(compiler);
6000 code.code = sljit_generate_code(compiler);
6001 CHECK(compiler);
6002 sljit_free_compiler(compiler);
6004 code.func3((sljit_sw)&wbuf, (sljit_sw)&bbuf, (sljit_sw)&ibuf);
6006 FAILED(sizeof(expected) != sizeof(supported) / sizeof(sljit_s32), "test60 case 1 failed\n");
6008 for (i = 0; i < sizeof(expected); i++) {
6009 if (expected[i]) {
6010 if (supported[i] != SLJIT_SUCCESS) {
6011 printf("tast60 case %d should be supported\n", i + 1);
6012 return;
6014 } else {
6015 if (supported[i] == SLJIT_SUCCESS) {
6016 printf("test60 case %d should not be supported\n", i + 1);
6017 return;
6022 FAILED(supported[0] == SLJIT_SUCCESS && wbuf[0] != -887766, "test60 case 2 failed\n");
6023 FAILED(supported[0] == SLJIT_SUCCESS && wbuf[1] != (sljit_sw)(wbuf + 2), "test60 case 3 failed\n");
6024 FAILED(supported[1] == SLJIT_SUCCESS && wbuf[3] != -13, "test60 case 4 failed\n");
6025 FAILED(supported[1] == SLJIT_SUCCESS && wbuf[4] != (sljit_sw)(bbuf), "test60 case 5 failed\n");
6026 FAILED(supported[2] == SLJIT_SUCCESS && wbuf[5] != -5678, "test60 case 6 failed\n");
6027 FAILED(supported[2] == SLJIT_SUCCESS && wbuf[6] != (sljit_sw)(ibuf), "test60 case 7 failed\n");
6028 FAILED(supported[3] == SLJIT_SUCCESS && ibuf[1] != -8765, "test60 case 8 failed\n");
6029 FAILED(supported[3] == SLJIT_SUCCESS && wbuf[7] != (sljit_sw)(ibuf + 1), "test60 case 9 failed\n");
6030 FAILED(supported[4] == SLJIT_SUCCESS && bbuf[0] != -121, "test60 case 10 failed\n");
6031 FAILED(supported[4] == SLJIT_SUCCESS && wbuf[8] != (sljit_sw)(bbuf) - 128 * (sljit_sw)sizeof(sljit_s8), "test60 case 11 failed\n");
6032 FAILED(supported[5] == SLJIT_SUCCESS && wbuf[9] != -881199, "test60 case 12 failed\n");
6033 FAILED(supported[5] == SLJIT_SUCCESS && wbuf[10] != (sljit_sw)(wbuf + 9), "test60 case 13 failed\n");
6034 FAILED(supported[6] == SLJIT_SUCCESS && wbuf[11] != -5678, "test60 case 14 failed\n");
6035 FAILED(supported[6] == SLJIT_SUCCESS && wbuf[12] != (sljit_sw)(ibuf), "test60 case 15 failed\n");
6036 FAILED(supported[7] == SLJIT_SUCCESS && ibuf[2] != -7890, "test60 case 16 failed\n");
6037 FAILED(supported[7] == SLJIT_SUCCESS && wbuf[13] != (sljit_sw)(ibuf + 2), "test60 case 17 failed\n");
6038 FAILED(supported[8] == SLJIT_SUCCESS && wbuf[14] != -887766, "test60 case 18 failed\n");
6039 FAILED(supported[8] == SLJIT_SUCCESS && wbuf[15] != (sljit_sw)(wbuf + 10), "test60 case 19 failed\n");
6040 FAILED(supported[9] == SLJIT_SUCCESS && wbuf[16] != -13, "test60 case 20 failed\n");
6041 FAILED(supported[9] == SLJIT_SUCCESS && wbuf[17] != (sljit_sw)(bbuf), "test60 case 21 failed\n");
6043 sljit_free_code(code.code, NULL);
6044 successful_tests++;
6047 static void test61(void)
6049 /* Test float memory accesses with pre/post updates. */
6050 executable_code code;
6051 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
6052 sljit_s32 i;
6053 sljit_s32 supported[6];
6054 sljit_sw wbuf[6];
6055 sljit_f64 dbuf[4];
6056 sljit_f32 sbuf[4];
6057 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
6058 static sljit_u8 expected[6] = { 1, 1, 1, 1, 0, 0 };
6059 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
6060 static sljit_u8 expected[6] = { 1, 0, 1, 0, 1, 1 };
6061 #else
6062 static sljit_u8 expected[6] = { 0, 0, 0, 0, 0, 0 };
6063 #endif
6065 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
6066 if (verbose)
6067 printf("no fpu available, test61 skipped\n");
6068 successful_tests++;
6069 if (compiler)
6070 sljit_free_compiler(compiler);
6071 return;
6074 if (verbose)
6075 printf("Run test61\n");
6077 for (i = 0; i < 6; i++)
6078 wbuf[i] = 0;
6080 dbuf[0] = 66.725;
6081 dbuf[1] = 0.0;
6082 dbuf[2] = 0.0;
6083 dbuf[3] = 0.0;
6085 sbuf[0] = 0.0;
6086 sbuf[1] = -22.125;
6087 sbuf[2] = 0.0;
6088 sbuf[3] = 0.0;
6090 FAILED(!compiler, "cannot create compiler\n");
6092 sljit_emit_enter(compiler, 0, SLJIT_ARGS3(VOID, P, P, P), 4, 3, 4, 0, sizeof(sljit_sw));
6094 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));
6095 if (supported[0] == SLJIT_SUCCESS) {
6096 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_IMM, 4 * sizeof(sljit_f64));
6097 sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_PRE, SLJIT_FR0, SLJIT_MEM1(SLJIT_R0), 4 * sizeof(sljit_f64));
6098 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f64), SLJIT_FR0, 0);
6099 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
6102 supported[1] = sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_SUPP | SLJIT_MEM_STORE | SLJIT_MEM_POST, SLJIT_FR2, SLJIT_MEM1(SLJIT_R0), -(sljit_sw)sizeof(sljit_f64));
6103 if (supported[1] == SLJIT_SUCCESS) {
6104 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_IMM, 2 * sizeof(sljit_f64));
6105 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), 0);
6106 sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_STORE | SLJIT_MEM_POST, SLJIT_FR2, SLJIT_MEM1(SLJIT_R0), -(sljit_sw)sizeof(sljit_f64));
6107 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
6110 supported[2] = sljit_emit_fmem(compiler, SLJIT_MOV_F32 | SLJIT_MEM_SUPP | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_FR1, SLJIT_MEM1(SLJIT_R2), -4 * (sljit_sw)sizeof(sljit_f32));
6111 if (supported[2] == SLJIT_SUCCESS) {
6112 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, 4 * sizeof(sljit_f32));
6113 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f32));
6114 sljit_emit_fmem(compiler, SLJIT_MOV_F32 | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_FR1, SLJIT_MEM1(SLJIT_R2), -4 * (sljit_sw)sizeof(sljit_f32));
6115 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R2, 0);
6118 supported[3] = sljit_emit_fmem(compiler, SLJIT_MOV_F32 | SLJIT_MEM_SUPP | SLJIT_MEM_POST, SLJIT_FR1, SLJIT_MEM1(SLJIT_R1), sizeof(sljit_f32));
6119 if (supported[3] == SLJIT_SUCCESS) {
6120 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S2, 0, SLJIT_IMM, sizeof(sljit_f32));
6121 sljit_emit_fmem(compiler, SLJIT_MOV_F32 | SLJIT_MEM_POST, SLJIT_FR1, SLJIT_MEM1(SLJIT_R1), sizeof(sljit_f32));
6122 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_f32), SLJIT_FR1, 0);
6123 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_R1, 0);
6126 supported[4] = sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_FR0, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 0);
6127 if (supported[4] == SLJIT_SUCCESS) {
6128 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S1, 0, SLJIT_IMM, 8 * sizeof(sljit_f64));
6129 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -8 * (sljit_sw)sizeof(sljit_f64));
6130 sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_PRE, SLJIT_FR0, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 0);
6131 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64), SLJIT_FR0, 0);
6132 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R1, 0);
6135 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);
6136 if (supported[5] == SLJIT_SUCCESS) {
6137 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_S2, 0);
6138 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 3 * sizeof(sljit_f32));
6139 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f32));
6140 sljit_emit_fmem(compiler, SLJIT_MOV_F32 | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_FR2, SLJIT_MEM2(SLJIT_R2, SLJIT_R1), 0);
6141 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R2, 0);
6144 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);
6145 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);
6147 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
6148 /* TODO: at least for ARM (both V5 and V7) the range below needs further fixing */
6149 SLJIT_ASSERT(sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_FR0, SLJIT_MEM1(SLJIT_R0), 256) == SLJIT_ERR_UNSUPPORTED);
6150 SLJIT_ASSERT(sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_SUPP | SLJIT_MEM_POST, SLJIT_FR0, SLJIT_MEM1(SLJIT_R0), -257) == SLJIT_ERR_UNSUPPORTED);
6151 #endif
6153 sljit_emit_return_void(compiler);
6155 code.code = sljit_generate_code(compiler);
6156 CHECK(compiler);
6157 sljit_free_compiler(compiler);
6159 code.func3((sljit_sw)&wbuf, (sljit_sw)&dbuf, (sljit_sw)&sbuf);
6161 FAILED(sizeof(expected) != sizeof(supported) / sizeof(sljit_s32), "test61 case 1 failed\n");
6163 for (i = 0; i < sizeof(expected); i++) {
6164 if (expected[i]) {
6165 if (supported[i] != SLJIT_SUCCESS) {
6166 printf("tast61 case %d should be supported\n", i + 1);
6167 return;
6169 } else {
6170 if (supported[i] == SLJIT_SUCCESS) {
6171 printf("test61 case %d should not be supported\n", i + 1);
6172 return;
6177 FAILED(supported[0] == SLJIT_SUCCESS && dbuf[1] != 66.725, "test61 case 2 failed\n");
6178 FAILED(supported[0] == SLJIT_SUCCESS && wbuf[0] != (sljit_sw)(dbuf), "test61 case 3 failed\n");
6179 FAILED(supported[1] == SLJIT_SUCCESS && dbuf[2] != 66.725, "test61 case 4 failed\n");
6180 FAILED(supported[1] == SLJIT_SUCCESS && wbuf[1] != (sljit_sw)(dbuf + 1), "test61 case 5 failed\n");
6181 FAILED(supported[2] == SLJIT_SUCCESS && sbuf[0] != -22.125, "test61 case 6 failed\n");
6182 FAILED(supported[2] == SLJIT_SUCCESS && wbuf[2] != (sljit_sw)(sbuf), "test61 case 7 failed\n");
6183 FAILED(supported[3] == SLJIT_SUCCESS && sbuf[2] != -22.125, "test61 case 8 failed\n");
6184 FAILED(supported[3] == SLJIT_SUCCESS && wbuf[3] != (sljit_sw)(sbuf + 2), "test61 case 9 failed\n");
6185 FAILED(supported[4] == SLJIT_SUCCESS && dbuf[3] != 66.725, "test61 case 10 failed\n");
6186 FAILED(supported[4] == SLJIT_SUCCESS && wbuf[4] != (sljit_sw)(dbuf), "test61 case 11 failed\n");
6187 FAILED(supported[5] == SLJIT_SUCCESS && sbuf[3] != -22.125, "test61 case 12 failed\n");
6188 FAILED(supported[5] == SLJIT_SUCCESS && wbuf[5] != (sljit_sw)(sbuf + 3), "test61 case 13 failed\n");
6190 sljit_free_code(code.code, NULL);
6191 successful_tests++;
6194 static void test62(void)
6196 /* Test fast calls flag preservation. */
6197 executable_code code1;
6198 executable_code code2;
6199 struct sljit_compiler* compiler;
6201 if (verbose)
6202 printf("Run test62\n");
6204 /* A */
6205 compiler = sljit_create_compiler(NULL, NULL);
6206 FAILED(!compiler, "cannot create compiler\n");
6207 sljit_set_context(compiler, 0, SLJIT_ARGS1(W, W), 1, 1, 0, 0, 0);
6209 sljit_emit_fast_enter(compiler, SLJIT_R0, 0);
6210 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, SLJIT_S0, 0, SLJIT_IMM, 42);
6211 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_R0, 0);
6213 code1.code = sljit_generate_code(compiler);
6214 CHECK(compiler);
6215 sljit_free_compiler(compiler);
6217 /* B */
6218 compiler = sljit_create_compiler(NULL, NULL);
6219 FAILED(!compiler, "cannot create compiler\n");
6221 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, W), 1, 1, 0, 0, 0);
6222 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_ADDR(code1.code));
6223 sljit_set_current_flags(compiler, SLJIT_CURRENT_FLAGS_ADD_SUB | SLJIT_CURRENT_FLAGS_COMPARE | SLJIT_SET_Z | SLJIT_SET_LESS);
6224 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_ZERO);
6225 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_LESS);
6226 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
6227 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S0, 0);
6228 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
6230 code2.code = sljit_generate_code(compiler);
6231 CHECK(compiler);
6232 sljit_free_compiler(compiler);
6234 FAILED(code2.func1(88) != 0, "test62 case 1 failed\n");
6235 FAILED(code2.func1(42) != 1, "test62 case 2 failed\n");
6236 FAILED(code2.func1(0) != 2, "test62 case 3 failed\n");
6238 sljit_free_code(code1.code, NULL);
6239 sljit_free_code(code2.code, NULL);
6240 successful_tests++;
6243 static void test63(void)
6245 /* Test put label. */
6246 executable_code code;
6247 struct sljit_label *label[2];
6248 struct sljit_put_label *put_label[5];
6249 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
6250 sljit_uw addr[2];
6251 sljit_uw buf[4];
6252 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
6253 sljit_sw offs = SLJIT_W(0x123456789012);
6254 #else
6255 sljit_sw offs = 0x12345678;
6256 #endif
6258 if (verbose)
6259 printf("Run test63\n");
6261 FAILED(!compiler, "cannot create compiler\n");
6262 buf[0] = 0;
6263 buf[1] = 0;
6264 buf[2] = 0;
6265 buf[3] = 0;
6267 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 1, 0, 0, 2 * sizeof(sljit_sw));
6269 put_label[0] = sljit_emit_put_label(compiler, SLJIT_R0, 0);
6270 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
6272 put_label[1] = sljit_emit_put_label(compiler, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw));
6273 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw));
6275 label[0] = sljit_emit_label(compiler);
6276 sljit_set_put_label(put_label[0], label[0]);
6277 sljit_set_put_label(put_label[1], label[0]);
6279 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)(buf + 2) - offs);
6280 put_label[2] = sljit_emit_put_label(compiler, SLJIT_MEM1(SLJIT_R0), offs);
6282 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (offs + (sljit_sw)sizeof(sljit_uw)) >> 1);
6283 put_label[3] = sljit_emit_put_label(compiler, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), 1);
6285 label[1] = sljit_emit_label(compiler);
6286 sljit_set_put_label(put_label[2], label[1]);
6287 sljit_set_put_label(put_label[3], label[1]);
6289 put_label[4] = sljit_emit_put_label(compiler, SLJIT_RETURN_REG, 0);
6290 sljit_set_put_label(put_label[4], label[0]);
6291 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
6293 code.code = sljit_generate_code(compiler);
6294 CHECK(compiler);
6296 addr[0] = sljit_get_label_addr(label[0]);
6297 addr[1] = sljit_get_label_addr(label[1]);
6299 sljit_free_compiler(compiler);
6301 FAILED(code.func1((sljit_sw)&buf) != addr[0], "test63 case 1 failed\n");
6302 FAILED(buf[0] != addr[0], "test63 case 2 failed\n");
6303 FAILED(buf[1] != addr[0], "test63 case 3 failed\n");
6304 FAILED(buf[2] != addr[1], "test63 case 4 failed\n");
6305 FAILED(buf[3] != addr[1], "test63 case 5 failed\n");
6307 sljit_free_code(code.code, NULL);
6308 successful_tests++;
6311 static void test64(void)
6313 /* Test put label with absolute label addresses */
6314 executable_code code;
6315 sljit_uw malloc_addr;
6316 struct sljit_label label[4];
6317 struct sljit_put_label *put_label[2];
6318 struct sljit_compiler* compiler;
6319 sljit_uw buf[5];
6320 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
6321 sljit_sw offs1 = SLJIT_W(0x123456781122);
6322 sljit_sw offs2 = SLJIT_W(0x1234567811223344);
6323 #else /* !SLJIT_64BIT_ARCHITECTURE */
6324 sljit_sw offs1 = 0x12345678;
6325 sljit_sw offs2 = (sljit_sw)0x80000000;
6326 #endif /* SLJIT_64BIT_ARCHITECTURE */
6328 if (verbose)
6329 printf("Run test64\n");
6331 /* lock next allocation; see sljit_test_malloc_exec() */
6332 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
6333 malloc_addr = (sljit_uw)SLJIT_MALLOC_EXEC(1024, NULL);
6335 if (!malloc_addr) {
6336 printf("Cannot allocate executable memory\n");
6337 return;
6340 compiler = sljit_create_compiler(NULL, (void*)malloc_addr);
6341 malloc_addr += (sljit_uw)SLJIT_EXEC_OFFSET((void*)malloc_addr);
6342 #else /* SLJIT_CONFIG_UNSUPPORTED */
6343 malloc_addr = 0;
6344 compiler = sljit_create_compiler(NULL, (void*)malloc_addr);
6345 #endif /* !SLJIT_CONFIG_UNSUPPORTED */
6347 label[0].addr = 0x1234;
6348 label[0].size = (sljit_uw)0x1234 - malloc_addr;
6350 label[1].addr = 0x12345678;
6351 label[1].size = (sljit_uw)0x12345678 - malloc_addr;
6353 label[2].addr = (sljit_uw)offs1;
6354 label[2].size = (sljit_uw)offs1 - malloc_addr;
6356 label[3].addr = (sljit_uw)offs2;
6357 label[3].size = (sljit_uw)offs2 - malloc_addr;
6359 FAILED(!compiler, "cannot create compiler\n");
6360 buf[0] = 0;
6361 buf[1] = 0;
6362 buf[2] = 0;
6363 buf[3] = 0;
6364 buf[4] = 0;
6366 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 1, 0, 0, 2 * sizeof(sljit_sw));
6368 put_label[0] = sljit_emit_put_label(compiler, SLJIT_R0, 0);
6369 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
6371 put_label[1] = sljit_emit_put_label(compiler, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw));
6372 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw));
6374 sljit_set_put_label(put_label[0], &label[0]);
6375 sljit_set_put_label(put_label[1], &label[0]);
6377 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)(buf + 2) - offs1);
6378 put_label[0] = sljit_emit_put_label(compiler, SLJIT_MEM1(SLJIT_R0), offs1);
6380 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (offs1 + (sljit_sw)sizeof(sljit_uw)) >> 1);
6381 put_label[1] = sljit_emit_put_label(compiler, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), 1);
6383 sljit_set_put_label(put_label[0], &label[1]);
6384 sljit_set_put_label(put_label[1], &label[1]);
6386 put_label[0] = sljit_emit_put_label(compiler, SLJIT_R2, 0);
6387 sljit_set_put_label(put_label[0], &label[2]);
6388 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_uw), SLJIT_R2, 0);
6390 put_label[0] = sljit_emit_put_label(compiler, SLJIT_RETURN_REG, 0);
6391 sljit_set_put_label(put_label[0], &label[3]);
6392 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
6394 code.code = sljit_generate_code(compiler);
6395 CHECK(compiler);
6396 sljit_free_compiler(compiler);
6397 SLJIT_ASSERT(SLJIT_FUNC_UADDR(code.code) >= malloc_addr && SLJIT_FUNC_UADDR(code.code) <= malloc_addr + 8);
6399 FAILED(code.func1((sljit_sw)&buf) != label[3].addr, "test64 case 1 failed\n");
6400 FAILED(buf[0] != label[0].addr, "test64 case 2 failed\n");
6401 FAILED(buf[1] != label[0].addr, "test64 case 3 failed\n");
6402 FAILED(buf[2] != label[1].addr, "test64 case 4 failed\n");
6403 FAILED(buf[3] != label[1].addr, "test64 case 5 failed\n");
6404 FAILED(buf[4] != label[2].addr, "test64 case 6 failed\n");
6406 sljit_free_code(code.code, NULL);
6408 successful_tests++;
6411 static void test65(void)
6413 /* Test jump tables. */
6414 executable_code code;
6415 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
6416 sljit_s32 i;
6417 /* Normally this table is allocated on the heap. */
6418 sljit_uw addr[64];
6419 struct sljit_label *labels[64];
6420 struct sljit_jump *jump;
6422 if (verbose)
6423 printf("Run test65\n");
6425 FAILED(!compiler, "cannot create compiler\n");
6427 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(W, W, W), 1, 2, 0, 0, 0);
6429 jump = sljit_emit_cmp(compiler, SLJIT_GREATER_EQUAL, SLJIT_S0, 0, SLJIT_IMM, 64);
6430 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)addr);
6431 sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_MEM2(SLJIT_R0, SLJIT_S0), SLJIT_WORD_SHIFT);
6433 for (i = 0; i < 64; i++) {
6434 labels[i] = sljit_emit_label(compiler);
6435 sljit_emit_op0(compiler, SLJIT_ENDBR);
6436 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_IMM, i * 2);
6437 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
6440 sljit_set_label(jump, sljit_emit_label(compiler));
6441 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, -1);
6443 code.code = sljit_generate_code(compiler);
6444 CHECK(compiler);
6446 for (i = 0; i < 64; i++) {
6447 addr[i] = sljit_get_label_addr(labels[i]);
6450 sljit_free_compiler(compiler);
6452 FAILED(code.func2(64, 0) != -1, "test65 case 1 failed\n");
6454 for (i = 0; i < 64; i++) {
6455 FAILED(code.func2(i, i * 2) != i * 4, "test65 case 2 failed\n");
6458 sljit_free_code(code.code, NULL);
6459 successful_tests++;
6462 static void test66(void)
6464 /* Test direct jumps (computed goto). */
6465 executable_code code;
6466 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
6467 sljit_s32 i;
6468 sljit_uw addr[64];
6469 struct sljit_label *labels[64];
6471 if (verbose)
6472 printf("Run test66\n");
6474 FAILED(!compiler, "cannot create compiler\n");
6476 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(W, W, W), 1, 2, 0, 0, 0);
6477 sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_S0, 0);
6479 for (i = 0; i < 64; i++) {
6480 labels[i] = sljit_emit_label(compiler);
6481 sljit_emit_op0(compiler, SLJIT_ENDBR);
6482 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_IMM, i * 2);
6483 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
6486 code.code = sljit_generate_code(compiler);
6487 CHECK(compiler);
6489 for (i = 0; i < 64; i++) {
6490 addr[i] = sljit_get_label_addr(labels[i]);
6493 sljit_free_compiler(compiler);
6495 for (i = 0; i < 64; i++) {
6496 FAILED(code.func2((sljit_sw)addr[i], i) != i * 3, "test66 case 1 failed\n");
6499 sljit_free_code(code.code, NULL);
6500 successful_tests++;
6503 static void test67(void)
6505 /* Test skipping returns from fast calls (return type is fast). */
6506 executable_code code;
6507 struct sljit_compiler *compiler = sljit_create_compiler(NULL, NULL);
6508 struct sljit_jump *call, *jump;
6509 struct sljit_label *label;
6511 if (verbose)
6512 printf("Run test67\n");
6514 FAILED(!compiler, "cannot create compiler\n");
6516 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(W), 3, 1, 0, 0, 0);
6518 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
6519 call = sljit_emit_jump(compiler, SLJIT_FAST_CALL);
6521 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
6523 /* First function, never returns. */
6524 label = sljit_emit_label(compiler);
6525 sljit_set_label(call, label);
6526 sljit_emit_fast_enter(compiler, SLJIT_R1, 0);
6528 call = sljit_emit_jump(compiler, SLJIT_FAST_CALL);
6530 /* Should never return here, marked by a segmentation fault if it does. */
6531 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
6533 /* Second function, skips the first function. */
6534 sljit_set_label(call, sljit_emit_label(compiler));
6535 sljit_emit_fast_enter(compiler, SLJIT_R2, 0);
6537 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
6539 jump = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 1);
6541 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_R1, 0);
6542 sljit_set_label(sljit_emit_jump(compiler, SLJIT_FAST_CALL), label);
6543 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
6544 sljit_emit_op_src(compiler, SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN, SLJIT_S0, 0);
6545 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_S0, 0);
6547 sljit_set_label(jump, sljit_emit_label(compiler));
6548 sljit_emit_op_src(compiler, SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN, SLJIT_R1, 0);
6549 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_R1, 0);
6551 code.code = sljit_generate_code(compiler);
6552 CHECK(compiler);
6554 sljit_free_compiler(compiler);
6556 FAILED(code.func0() != 3, "test67 case 1 failed\n");
6558 sljit_free_code(code.code, NULL);
6559 successful_tests++;
6562 static void test68(void)
6564 /* Test skipping returns from fast calls (return type is normal). */
6565 executable_code code;
6566 struct sljit_compiler *compiler;
6567 struct sljit_jump *call, *jump;
6568 struct sljit_label *label;
6569 int i;
6571 if (verbose)
6572 printf("Run test68\n");
6574 for (i = 0; i < 6 * 2; i++) {
6575 compiler = sljit_create_compiler(NULL, NULL);
6576 FAILED(!compiler, "cannot create compiler\n");
6578 sljit_emit_enter(compiler, (i >= 6 ? SLJIT_F64_ALIGNMENT : 0), SLJIT_ARGS0(W), 2 + (i % 6), (i % 6), 0, 0, 0);
6580 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
6581 call = sljit_emit_jump(compiler, SLJIT_FAST_CALL);
6583 /* Should never return here, marked by a segmentation fault if it does. */
6584 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
6586 /* Recursive fast call. */
6587 label = sljit_emit_label(compiler);
6588 sljit_set_label(call, label);
6589 sljit_emit_fast_enter(compiler, SLJIT_R1, 0);
6591 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
6593 jump = sljit_emit_cmp(compiler, SLJIT_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 4);
6595 sljit_set_label(sljit_emit_jump(compiler, SLJIT_FAST_CALL), label);
6597 sljit_set_label(jump, sljit_emit_label(compiler));
6598 sljit_emit_op0(compiler, SLJIT_SKIP_FRAMES_BEFORE_RETURN);
6599 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
6601 code.code = sljit_generate_code(compiler);
6602 CHECK(compiler);
6604 sljit_free_compiler(compiler);
6606 if (SLJIT_UNLIKELY(code.func0() != 4)) {
6607 printf("test68 case %d failed\n", i + 1);
6608 return;
6610 sljit_free_code(code.code, NULL);
6613 successful_tests++;
6616 static void test69(void)
6618 /* Test sljit_set_current_flags. */
6619 executable_code code;
6620 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
6621 sljit_sw buf[8];
6622 sljit_s32 i;
6624 if (verbose)
6625 printf("Run test69\n");
6627 for (i = 0; i < 8; i++)
6628 buf[i] = 4;
6630 FAILED(!compiler, "cannot create compiler\n");
6632 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 3, 1, 0, 0, 0);
6634 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)1 << ((sizeof (sljit_sw) * 8) - 2));
6635 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_R0, 0);
6636 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_R1, 0);
6637 sljit_emit_label(compiler);
6638 sljit_set_current_flags(compiler, SLJIT_SET_OVERFLOW | SLJIT_CURRENT_FLAGS_ADD_SUB);
6639 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_OVERFLOW);
6641 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 5);
6642 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_R1, 0);
6643 sljit_emit_label(compiler);
6644 sljit_set_current_flags(compiler, SLJIT_SET_OVERFLOW | SLJIT_CURRENT_FLAGS_ADD_SUB);
6645 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_OVERFLOW);
6647 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_R0, 0);
6648 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_R1, 0);
6649 sljit_emit_label(compiler);
6650 sljit_set_current_flags(compiler, SLJIT_SET_OVERFLOW);
6651 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_OVERFLOW);
6653 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 5);
6654 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_R1, 0);
6655 sljit_emit_label(compiler);
6656 sljit_set_current_flags(compiler, SLJIT_SET_OVERFLOW);
6657 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_OVERFLOW);
6659 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 6);
6660 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 5);
6661 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_R1, 0, SLJIT_R2, 0);
6662 sljit_emit_label(compiler);
6663 sljit_set_current_flags(compiler, SLJIT_SET_GREATER | SLJIT_CURRENT_FLAGS_ADD_SUB | SLJIT_CURRENT_FLAGS_COMPARE);
6664 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_GREATER);
6666 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_R2, 0);
6667 sljit_emit_label(compiler);
6668 sljit_set_current_flags(compiler, SLJIT_SET_Z | SLJIT_CURRENT_FLAGS_ADD_SUB | SLJIT_CURRENT_FLAGS_COMPARE);
6669 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_ZERO);
6671 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -1 << 31);
6672 sljit_emit_op2u(compiler, SLJIT_ADD32 | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_R1, 0);
6673 sljit_emit_label(compiler);
6674 sljit_set_current_flags(compiler, SLJIT_SET_Z | SLJIT_CURRENT_FLAGS_32 | SLJIT_CURRENT_FLAGS_ADD_SUB);
6675 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_ZERO);
6677 sljit_emit_op2u(compiler, SLJIT_SHL32 | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_IMM, 1);
6678 sljit_emit_label(compiler);
6679 sljit_set_current_flags(compiler, SLJIT_SET_Z | SLJIT_CURRENT_FLAGS_32);
6680 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_NOT_ZERO);
6682 sljit_emit_return_void(compiler);
6684 code.code = sljit_generate_code(compiler);
6685 CHECK(compiler);
6686 sljit_free_compiler(compiler);
6688 code.func1((sljit_sw)&buf);
6690 FAILED(buf[0] != 1, "test69 case 1 failed\n");
6691 FAILED(buf[1] != 2, "test69 case 2 failed\n");
6692 FAILED(buf[2] != 1, "test69 case 3 failed\n");
6693 FAILED(buf[3] != 2, "test69 case 4 failed\n");
6694 FAILED(buf[4] != 1, "test69 case 5 failed\n");
6695 FAILED(buf[5] != 2, "test69 case 6 failed\n");
6696 FAILED(buf[6] != 1, "test69 case 7 failed\n");
6697 FAILED(buf[7] != 2, "test69 case 8 failed\n");
6699 sljit_free_code(code.code, NULL);
6700 successful_tests++;
6703 static void test70(void)
6705 /* Test argument passing to sljit_emit_enter. */
6706 executable_code code;
6707 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
6708 sljit_sw wbuf[2];
6709 sljit_s32 ibuf[2];
6710 sljit_f64 dbuf[3];
6711 sljit_f32 fbuf[2];
6713 if (verbose)
6714 printf("Run test70\n");
6716 wbuf[0] = 0;
6717 wbuf[1] = 0;
6718 ibuf[0] = 0;
6719 ibuf[1] = 0;
6721 FAILED(!compiler, "cannot create compiler\n");
6723 sljit_emit_enter(compiler, 0, SLJIT_ARGS4(VOID, 32, W, 32, W), 1, 4, 0, 0, 0);
6724 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&wbuf);
6725 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_S1, 0);
6726 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_sw), SLJIT_S3, 0);
6727 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&ibuf);
6728 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_S0, 0);
6729 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_s32), SLJIT_S2, 0);
6730 sljit_emit_return_void(compiler);
6732 code.code = sljit_generate_code(compiler);
6733 CHECK(compiler);
6734 sljit_free_compiler(compiler);
6736 code.test70_f1(-1478, 9476, 4928, -6832);
6738 FAILED(wbuf[0] != 9476, "test70 case 1 failed\n");
6739 FAILED(wbuf[1] != -6832, "test70 case 2 failed\n");
6740 FAILED(ibuf[0] != -1478, "test70 case 3 failed\n");
6741 FAILED(ibuf[1] != 4928, "test70 case 4 failed\n");
6743 sljit_free_code(code.code, NULL);
6745 compiler = sljit_create_compiler(NULL, NULL);
6746 FAILED(!compiler, "cannot create compiler\n");
6748 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, SLJIT_ARGS4(VOID, 32, 32, W, W), 1, 4, 0, 0, 0);
6749 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&wbuf);
6750 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_S0, 0);
6751 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_sw), SLJIT_S1, 0);
6752 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&ibuf);
6753 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_S2, 0);
6754 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_s32), SLJIT_S3, 0);
6755 sljit_emit_return_void(compiler);
6757 code.code = sljit_generate_code(compiler);
6758 CHECK(compiler);
6759 sljit_free_compiler(compiler);
6761 code.test70_f2(4721, 7892, -3579, -4830);
6763 FAILED(wbuf[0] != 4721, "test70 case 5 failed\n");
6764 FAILED(wbuf[1] != 7892, "test70 case 6 failed\n");
6765 FAILED(ibuf[0] != -3579, "test70 case 7 failed\n");
6766 FAILED(ibuf[1] != -4830, "test70 case 8 failed\n");
6768 sljit_free_code(code.code, NULL);
6770 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
6771 wbuf[0] = 0;
6772 ibuf[0] = 0;
6773 dbuf[0] = 0;
6774 fbuf[0] = 0;
6776 compiler = sljit_create_compiler(NULL, NULL);
6777 FAILED(!compiler, "cannot create compiler\n");
6779 sljit_emit_enter(compiler, 0, SLJIT_ARGS4(VOID, 32, F32, W, F64), 2, 2, 2, 0, 0);
6780 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM0(), (sljit_sw)&wbuf, SLJIT_S1, 0);
6781 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM0(), (sljit_sw)&ibuf, SLJIT_S0, 0);
6782 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM0(), (sljit_sw)&dbuf, SLJIT_FR1, 0);
6783 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM0(), (sljit_sw)&fbuf, SLJIT_FR0, 0);
6784 sljit_emit_return_void(compiler);
6786 code.code = sljit_generate_code(compiler);
6787 CHECK(compiler);
6788 sljit_free_compiler(compiler);
6790 code.test70_f3(-6834, 674.5, 2789, -895.25);
6792 FAILED(wbuf[0] != 2789, "test70 case 9 failed\n");
6793 FAILED(ibuf[0] != -6834, "test70 case 10 failed\n");
6794 FAILED(dbuf[0] != -895.25, "test70 case 11 failed\n");
6795 FAILED(fbuf[0] != 674.5, "test70 case 12 failed\n");
6797 ibuf[0] = 0;
6798 dbuf[0] = 0;
6799 fbuf[0] = 0;
6800 fbuf[1] = 0;
6802 compiler = sljit_create_compiler(NULL, NULL);
6803 FAILED(!compiler, "cannot create compiler\n");
6805 sljit_emit_enter(compiler, 0, SLJIT_ARGS4(VOID, F32, F64, F32, 32), 1, 1, 3, 0, 0);
6806 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM0(), (sljit_sw)&ibuf, SLJIT_S0, 0);
6807 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM0(), (sljit_sw)&dbuf, SLJIT_FR1, 0);
6808 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&fbuf);
6809 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_FR0, 0);
6810 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_f32), SLJIT_FR2, 0);
6811 sljit_emit_return_void(compiler);
6813 code.code = sljit_generate_code(compiler);
6814 CHECK(compiler);
6815 sljit_free_compiler(compiler);
6817 code.test70_f4(-4712.5, 5342.25, 2904.25, -4607);
6819 FAILED(ibuf[0] != -4607, "test70 case 13 failed\n");
6820 FAILED(dbuf[0] != 5342.25, "test70 case 14 failed\n");
6821 FAILED(fbuf[0] != -4712.5, "test70 case 15 failed\n");
6822 FAILED(fbuf[1] != 2904.25, "test70 case 16 failed\n");
6824 ibuf[0] = 0;
6825 dbuf[0] = 0;
6826 fbuf[0] = 0;
6827 fbuf[1] = 0;
6829 compiler = sljit_create_compiler(NULL, NULL);
6830 FAILED(!compiler, "cannot create compiler\n");
6832 sljit_emit_enter(compiler, 0, SLJIT_ARGS4(VOID, F64, F32, 32, F32), 1, 1, 3, 0, 0);
6833 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM0(), (sljit_sw)&ibuf, SLJIT_S0, 0);
6834 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM0(), (sljit_sw)&dbuf, SLJIT_FR0, 0);
6835 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&fbuf);
6836 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_FR1, 0);
6837 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_f32), SLJIT_FR2, 0);
6839 sljit_emit_return_void(compiler);
6841 code.code = sljit_generate_code(compiler);
6842 CHECK(compiler);
6843 sljit_free_compiler(compiler);
6845 code.test70_f5(3578.5, 4619.25, 6859, -1807.75);
6847 FAILED(ibuf[0] != 6859, "test70 case 17 failed\n");
6848 FAILED(dbuf[0] != 3578.5, "test70 case 18 failed\n");
6849 FAILED(fbuf[0] != 4619.25, "test70 case 19 failed\n");
6850 FAILED(fbuf[1] != -1807.75, "test70 case 20 failed\n");
6852 ibuf[0] = 0;
6853 dbuf[0] = 0;
6854 dbuf[1] = 0;
6855 fbuf[0] = 0;
6857 compiler = sljit_create_compiler(NULL, NULL);
6858 FAILED(!compiler, "cannot create compiler\n");
6860 sljit_emit_enter(compiler, 0, SLJIT_ARGS4(VOID, F64, 32, F32, F64), SLJIT_NUMBER_OF_SCRATCH_REGISTERS + 2, 1, 3, 0, 33);
6861 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM0(), (sljit_sw)&ibuf, SLJIT_S0, 0);
6862 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&dbuf);
6863 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_FR0, 0);
6864 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_f64), SLJIT_FR2, 0);
6865 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM0(), (sljit_sw)&fbuf, SLJIT_FR1, 0);
6866 sljit_emit_return_void(compiler);
6868 code.code = sljit_generate_code(compiler);
6869 CHECK(compiler);
6870 sljit_free_compiler(compiler);
6872 code.test70_f6(2740.75, -2651, -7909.25, 3671.5);
6874 FAILED(ibuf[0] != -2651, "test70 case 21 failed\n");
6875 FAILED(dbuf[0] != 2740.75, "test70 case 22 failed\n");
6876 FAILED(dbuf[1] != 3671.5, "test70 case 23 failed\n");
6877 FAILED(fbuf[0] != -7909.25, "test70 case 24 failed\n");
6879 wbuf[0] = 0;
6880 ibuf[0] = 0;
6881 ibuf[1] = 0;
6882 fbuf[0] = 0;
6884 compiler = sljit_create_compiler(NULL, NULL);
6885 FAILED(!compiler, "cannot create compiler\n");
6887 sljit_emit_enter(compiler, 0, SLJIT_ARGS4(VOID, F32, 32, W, 32), 1, 3, 1, 0, 1);
6888 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM0(), (sljit_sw)&wbuf, SLJIT_S1, 0);
6889 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&ibuf);
6890 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_S0, 0);
6891 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_s32), SLJIT_S2, 0);
6892 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM0(), (sljit_sw)&fbuf, SLJIT_FR0, 0);
6893 sljit_emit_return_void(compiler);
6895 code.code = sljit_generate_code(compiler);
6896 CHECK(compiler);
6897 sljit_free_compiler(compiler);
6899 code.test70_f7(-5219.25, -4530, 7214, 6741);
6901 FAILED(wbuf[0] != 7214, "test70 case 25 failed\n");
6902 FAILED(ibuf[0] != -4530, "test70 case 26 failed\n");
6903 FAILED(ibuf[1] != 6741, "test70 case 27 failed\n");
6904 FAILED(fbuf[0] != -5219.25, "test70 case 28 failed\n");
6906 wbuf[0] = 0;
6907 wbuf[1] = 0;
6908 dbuf[0] = 0;
6909 dbuf[1] = 0;
6911 compiler = sljit_create_compiler(NULL, NULL);
6912 FAILED(!compiler, "cannot create compiler\n");
6914 sljit_emit_enter(compiler, 0, SLJIT_ARGS4(VOID, F64, F64, W, W), 1, 5, 2, 0, SLJIT_MAX_LOCAL_SIZE - 1);
6915 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_S0, 0);
6916 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_SP), SLJIT_MAX_LOCAL_SIZE - 2 * sizeof(sljit_f64), SLJIT_FR0, 0);
6917 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&wbuf);
6918 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_S0, 0);
6919 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_sw), SLJIT_S1, 0);
6920 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&dbuf);
6921 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_FR0, 0);
6922 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_f64), SLJIT_FR1, 0);
6923 sljit_emit_return_void(compiler);
6925 code.code = sljit_generate_code(compiler);
6926 CHECK(compiler);
6927 sljit_free_compiler(compiler);
6929 code.test70_f8(-3749.75, 5280.5, 9134, -6506);
6931 FAILED(wbuf[0] != 9134, "test70 case 29 failed\n");
6932 FAILED(wbuf[1] != -6506, "test70 case 30 failed\n");
6933 FAILED(dbuf[0] != -3749.75, "test70 case 31 failed\n");
6934 FAILED(dbuf[1] != 5280.5, "test70 case 32 failed\n");
6936 wbuf[0] = 0;
6937 dbuf[0] = 0;
6938 dbuf[1] = 0;
6939 dbuf[2] = 0;
6941 compiler = sljit_create_compiler(NULL, NULL);
6942 FAILED(!compiler, "cannot create compiler\n");
6944 sljit_emit_enter(compiler, 0, SLJIT_ARGS4(VOID, F64, F64, W, F64), 1, 1, 3, 0, SLJIT_MAX_LOCAL_SIZE);
6945 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM0(), (sljit_sw)&wbuf, SLJIT_S0, 0);
6946 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&dbuf);
6947 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_FR0, 0);
6948 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_f64), SLJIT_FR1, 0);
6949 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_R0), 2 * sizeof(sljit_f64), SLJIT_FR2, 0);
6951 sljit_emit_return_void(compiler);
6953 code.code = sljit_generate_code(compiler);
6954 CHECK(compiler);
6955 sljit_free_compiler(compiler);
6957 code.test70_f9(-6049.25, 7301.5, 4610, -4312.75);
6959 FAILED(wbuf[0] != 4610, "test70 case 33 failed\n");
6960 FAILED(dbuf[0] != -6049.25, "test70 case 34 failed\n");
6961 FAILED(dbuf[1] != 7301.5, "test70 case 35 failed\n");
6962 FAILED(dbuf[2] != -4312.75, "test70 case 36 failed\n");
6964 ibuf[0] = 0;
6965 dbuf[0] = 0;
6966 dbuf[1] = 0;
6967 dbuf[2] = 0;
6969 compiler = sljit_create_compiler(NULL, NULL);
6970 FAILED(!compiler, "cannot create compiler\n");
6972 sljit_emit_enter(compiler, 0, SLJIT_ARGS4(VOID, F64, F64, F64, 32), 1, 1, 3, 0, 0);
6973 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM0(), (sljit_sw)&ibuf, SLJIT_S0, 0);
6974 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&dbuf);
6975 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_FR0, 0);
6976 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_f64), SLJIT_FR1, 0);
6977 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_R0), 2 * sizeof(sljit_f64), SLJIT_FR2, 0);
6979 sljit_emit_return_void(compiler);
6981 code.code = sljit_generate_code(compiler);
6982 CHECK(compiler);
6983 sljit_free_compiler(compiler);
6985 code.test70_f10(4810.5, -9148.75, 8601.25, 6703);
6987 FAILED(ibuf[0] != 6703, "test70 case 37 failed\n");
6988 FAILED(dbuf[0] != 4810.5, "test70 case 38 failed\n");
6989 FAILED(dbuf[1] != -9148.75, "test70 case 39 failed\n");
6990 FAILED(dbuf[2] != 8601.25, "test70 case 40 failed\n");
6993 successful_tests++;
6996 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
6998 static sljit_sw SLJIT_FUNC test71_f1(sljit_sw a)
7000 return a + 10000;
7003 static sljit_sw SLJIT_FUNC test71_f2(sljit_sw a, sljit_s32 b, sljit_s32 c, sljit_sw d)
7005 return a | b | c | d;
7008 static sljit_sw test71_f3(sljit_sw a, sljit_s32 b, sljit_s32 c, sljit_sw d)
7010 return a | b | c | d;
7013 static sljit_sw test71_f4(sljit_sw a, sljit_s32 b, sljit_s32 c, sljit_sw d)
7015 SLJIT_UNUSED_ARG(a);
7016 return b | c | d;
7019 static sljit_sw test71_f5(void)
7021 return 7461932;
7024 static sljit_sw SLJIT_FUNC test71_f6(sljit_f64 a, sljit_f64 b, sljit_f64 c, sljit_f64 d)
7026 if (a == 1345.5 && b == -8724.25 && c == 9034.75 && d == 6307.5)
7027 return 8920567;
7028 return 0;
7031 #endif /* SLJIT_CONFIG_X86 */
7033 static void test71(void)
7035 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
7036 /* Test tail calls. */
7037 executable_code code;
7038 struct sljit_compiler* compiler;
7039 struct sljit_jump *jump;
7040 sljit_uw jump_addr;
7041 sljit_sw executable_offset;
7042 sljit_sw wbuf[1];
7043 sljit_f64 dbuf[4];
7045 if (verbose)
7046 printf("Run test71\n");
7048 compiler = sljit_create_compiler(NULL, NULL);
7049 FAILED(!compiler, "cannot create compiler\n");
7051 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, W), 4, 4, 0, 0, 0);
7052 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
7053 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
7054 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 0);
7055 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0);
7056 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, -1);
7057 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, -1);
7058 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, -1);
7059 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, -1);
7060 sljit_emit_icall(compiler, SLJIT_CALL | SLJIT_TAIL_CALL, SLJIT_ARGS1(W, W), SLJIT_IMM, SLJIT_FUNC_ADDR(test71_f1));
7061 /* Should crash. */
7062 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
7064 code.code = sljit_generate_code(compiler);
7065 CHECK(compiler);
7066 sljit_free_compiler(compiler);
7068 FAILED(code.func1(7987) != 17987, "test71 case 1 failed\n");
7070 compiler = sljit_create_compiler(NULL, NULL);
7071 FAILED(!compiler, "cannot create compiler\n");
7073 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, W), 1, 4, 0, 0, 0);
7074 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
7075 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, -1);
7076 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, -1);
7077 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, -1);
7078 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, -1);
7079 jump = sljit_emit_call(compiler, SLJIT_CALL | SLJIT_REWRITABLE_JUMP | SLJIT_TAIL_CALL, SLJIT_ARGS1(W, W));
7080 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
7082 sljit_set_target(jump, 0);
7084 code.code = sljit_generate_code(compiler);
7085 CHECK(compiler);
7087 executable_offset = sljit_get_executable_offset(compiler);
7088 jump_addr = sljit_get_jump_addr(jump);
7089 sljit_free_compiler(compiler);
7091 sljit_set_jump_addr(jump_addr, SLJIT_FUNC_UADDR(test71_f1), executable_offset);
7093 FAILED(code.func1(3903) != 13903, "test71 case 2 failed\n");
7095 compiler = sljit_create_compiler(NULL, NULL);
7096 FAILED(!compiler, "cannot create compiler\n");
7098 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(W), 4, 2, 0, 0, SLJIT_MAX_LOCAL_SIZE);
7099 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test71_f2));
7100 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x28000000);
7101 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 0x00140000);
7102 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R2, 0, SLJIT_IMM, 0x00002800);
7103 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0x00000041);
7104 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, -1);
7105 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, -1);
7106 sljit_emit_icall(compiler, SLJIT_CALL | SLJIT_TAIL_CALL, SLJIT_ARGS4(W, W, 32, 32, W), SLJIT_MEM1(SLJIT_SP), 0);
7107 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
7109 code.code = sljit_generate_code(compiler);
7110 CHECK(compiler);
7111 sljit_free_compiler(compiler);
7113 FAILED(code.func0() != 0x28142841, "test71 case 3 failed\n");
7115 compiler = sljit_create_compiler(NULL, NULL);
7116 FAILED(!compiler, "cannot create compiler\n");
7118 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(W), 4, 4, 0, 0, SLJIT_MAX_LOCAL_SIZE);
7119 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test71_f2));
7120 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)0x81000000);
7121 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 0x00480000);
7122 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R2, 0, SLJIT_IMM, 0x00002100);
7123 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0x00000014);
7124 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, -1);
7125 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, -1);
7126 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, -1);
7127 sljit_emit_icall(compiler, SLJIT_CALL | SLJIT_TAIL_CALL, SLJIT_ARGS4(W, W, 32, 32, W), SLJIT_S3, 0);
7128 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
7130 code.code = sljit_generate_code(compiler);
7131 CHECK(compiler);
7132 sljit_free_compiler(compiler);
7134 FAILED(code.func0() != 0x81482114, "test71 case 4 failed\n");
7136 sljit_free_code(code.code, NULL);
7138 compiler = sljit_create_compiler(NULL, NULL);
7139 FAILED(!compiler, "cannot create compiler\n");
7141 sljit_emit_enter(compiler, 0, SLJIT_ARGS3(W, W, W, W), 4, 4, 0, 0, 0);
7142 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
7143 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_S1, 0);
7144 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R2, 0, SLJIT_S2, 0);
7145 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0x48000000);
7146 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, -1);
7147 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, -1);
7148 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, -1);
7149 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, -1);
7150 sljit_emit_icall(compiler, SLJIT_CALL_CDECL | SLJIT_TAIL_CALL, SLJIT_ARGS4(W, W, 32, 32, W), SLJIT_IMM, SLJIT_FUNC_ADDR(test71_f3));
7151 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
7153 code.code = sljit_generate_code(compiler);
7154 CHECK(compiler);
7155 sljit_free_compiler(compiler);
7157 FAILED(code.func3(0x12, 0x8800, 0x240000) != 0x48248812, "test71 case 5 failed\n");
7159 sljit_free_code(code.code, NULL);
7161 compiler = sljit_create_compiler(NULL, NULL);
7162 FAILED(!compiler, "cannot create compiler\n");
7164 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, SLJIT_ARGS0(W), 4, 0, 0, 0, 0);
7165 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test71_f4));
7166 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 0x342);
7167 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R2, 0, SLJIT_IMM, 0x451000);
7168 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0x21000000);
7169 sljit_emit_icall(compiler, SLJIT_CALL_CDECL | SLJIT_TAIL_CALL, SLJIT_ARGS4(W, W, 32, 32, W), SLJIT_R0, 0);
7170 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
7172 code.code = sljit_generate_code(compiler);
7173 CHECK(compiler);
7174 sljit_free_compiler(compiler);
7176 FAILED(code.func0() != 0x21451342, "test71 case 6 failed\n");
7178 sljit_free_code(code.code, NULL);
7180 compiler = sljit_create_compiler(NULL, NULL);
7181 FAILED(!compiler, "cannot create compiler\n");
7183 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, SLJIT_ARGS0(W), 1, 0, 0, 0, 9);
7184 sljit_emit_icall(compiler, SLJIT_CALL_CDECL | SLJIT_TAIL_CALL, SLJIT_ARGS0(W), SLJIT_IMM, SLJIT_FUNC_ADDR(test71_f5));
7185 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
7187 code.code = sljit_generate_code(compiler);
7188 CHECK(compiler);
7189 sljit_free_compiler(compiler);
7191 FAILED(code.func0() != 7461932, "test71 case 7 failed\n");
7193 sljit_free_code(code.code, NULL);
7195 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
7196 dbuf[0] = 1345.5;
7197 dbuf[1] = -8724.25;
7198 dbuf[2] = 9034.75;
7199 dbuf[3] = 6307.5;
7201 compiler = sljit_create_compiler(NULL, NULL);
7202 FAILED(!compiler, "cannot create compiler\n");
7204 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, SLJIT_ARGS0(W), 1, 0, 4, 0, 0);
7205 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&dbuf);
7206 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_R0), 0);
7207 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_f64));
7208 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_R0), 2 * sizeof(sljit_f64));
7209 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR3, 0, SLJIT_MEM1(SLJIT_R0), 3 * sizeof(sljit_f64));
7210 sljit_emit_icall(compiler, SLJIT_CALL | SLJIT_TAIL_CALL, SLJIT_ARGS4(W, F64, F64, F64, F64), SLJIT_IMM, SLJIT_FUNC_ADDR(test71_f6));
7211 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
7213 code.code = sljit_generate_code(compiler);
7214 CHECK(compiler);
7215 sljit_free_compiler(compiler);
7217 FAILED(code.func0() != 8920567, "test71 case 8 failed\n");
7219 sljit_free_code(code.code, NULL);
7221 wbuf[0] = SLJIT_FUNC_ADDR(test71_f6);
7223 compiler = sljit_create_compiler(NULL, NULL);
7224 FAILED(!compiler, "cannot create compiler\n");
7226 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, SLJIT_ARGS4(W, F64, F64, F64, F64), 1, 0, 4, 0, 0);
7227 sljit_emit_icall(compiler, SLJIT_CALL | SLJIT_TAIL_CALL, SLJIT_ARGS4(W, F64, F64, F64, F64), SLJIT_MEM0(), (sljit_sw)wbuf);
7228 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
7230 code.code = sljit_generate_code(compiler);
7231 CHECK(compiler);
7232 sljit_free_compiler(compiler);
7234 FAILED(code.test71_f1(1345.5, -8724.25, 9034.75, 6307.5) != 8920567, "test71 case 9 failed\n");
7236 sljit_free_code(code.code, NULL);
7238 #endif /* SLJIT_CONFIG_X86 */
7240 successful_tests++;
7243 int sljit_test(int argc, char* argv[])
7245 sljit_s32 has_arg = (argc >= 2 && argv[1][0] == '-' && argv[1][2] == '\0');
7246 verbose = has_arg && argv[1][1] == 'v';
7247 silent = has_arg && argv[1][1] == 's';
7249 if (!verbose && !silent)
7250 printf("Pass -v to enable verbose, -s to disable this hint.\n\n");
7252 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
7253 test_exec_allocator();
7254 #endif
7255 test1();
7256 test2();
7257 test3();
7258 test4();
7259 test5();
7260 test6();
7261 test7();
7262 test8();
7263 test9();
7264 test10();
7265 test11();
7266 test12();
7267 test13();
7268 test14();
7269 test15();
7270 test16();
7271 test17();
7272 test18();
7273 test19();
7274 test20();
7275 test21();
7276 test22();
7277 test23();
7278 test24();
7279 test25();
7280 test26();
7281 test27();
7282 test28();
7283 test29();
7284 test30();
7285 test31();
7286 test32();
7287 test33();
7288 test34();
7289 test35();
7290 test36();
7291 test37();
7292 test38();
7293 test39();
7294 test40();
7295 test41();
7296 test42();
7297 test43();
7298 test44();
7299 test45();
7300 test46();
7301 test47();
7302 test48();
7303 test49();
7304 test50();
7305 test51();
7306 test52();
7307 test53();
7308 test54();
7309 test55();
7310 test56();
7311 test57();
7312 test58();
7313 test59();
7314 test60();
7315 test61();
7316 test62();
7317 test63();
7318 test64();
7319 test65();
7320 test66();
7321 test67();
7322 test68();
7323 test69();
7324 test70();
7325 test71();
7327 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
7328 sljit_free_unused_memory_exec();
7329 #endif
7331 # define TEST_COUNT 71
7333 printf("SLJIT tests: ");
7334 if (successful_tests == TEST_COUNT)
7335 printf("all tests are " COLOR_GREEN "PASSED" COLOR_DEFAULT " ");
7336 else
7337 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 / TEST_COUNT);
7338 printf("on " COLOR_ARCH "%s" COLOR_DEFAULT "%s\n", sljit_get_platform_name(), sljit_has_cpu_feature(SLJIT_HAS_FPU) ? " (with fpu)" : " (without fpu)");
7340 return TEST_COUNT - successful_tests;
7342 # undef TEST_COUNT
7345 #ifdef _MSC_VER
7346 #pragma warning(pop)
7347 #endif