Increase the number floating point registers on x86 and ARM.
[sljit.git] / test_src / sljitTest.c
blob43ffccc59a9d245db06ffde20c58ab497e7140df
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);
70 sljit_sw (SLJIT_FUNC *test71_f2)(sljit_f64 a, sljit_f64 b, sljit_f64 c);
72 typedef union executable_code executable_code;
74 static sljit_s32 successful_tests = 0;
75 static sljit_s32 verbose = 0;
76 static sljit_s32 silent = 0;
78 #define FAILED(cond, text) \
79 if (SLJIT_UNLIKELY(cond)) { \
80 printf(text); \
81 return; \
84 #define CHECK(compiler) \
85 if (sljit_get_compiler_error(compiler) != SLJIT_ERR_COMPILED) { \
86 printf("Compiler error: %d\n", sljit_get_compiler_error(compiler)); \
87 sljit_free_compiler(compiler); \
88 return; \
91 static void cond_set(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_s32 type)
93 /* Testing both sljit_emit_op_flags and sljit_emit_jump. */
94 struct sljit_jump* jump;
95 struct sljit_label* label;
97 sljit_emit_op_flags(compiler, SLJIT_MOV, dst, dstw, type);
98 jump = sljit_emit_jump(compiler, type);
99 sljit_emit_op2(compiler, SLJIT_ADD, dst, dstw, dst, dstw, SLJIT_IMM, 2);
100 label = sljit_emit_label(compiler);
101 sljit_set_label(jump, label);
104 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
106 /* For interface testing and for test64. */
107 void *sljit_test_malloc_exec(sljit_uw size, void *exec_allocator_data)
109 if (exec_allocator_data)
110 return exec_allocator_data;
112 return SLJIT_BUILTIN_MALLOC_EXEC(size, exec_allocator_data);
115 /* For interface testing. */
116 void sljit_test_free_code(void* code, void *exec_allocator_data)
118 SLJIT_UNUSED_ARG(exec_allocator_data);
119 SLJIT_BUILTIN_FREE_EXEC(code, exec_allocator_data);
122 #define MALLOC_EXEC(result, size) \
123 result = SLJIT_MALLOC_EXEC(size, NULL); \
124 if (!result) { \
125 printf("Cannot allocate executable memory\n"); \
126 return; \
128 memset(result, 255, size);
130 #define FREE_EXEC(ptr) \
131 SLJIT_FREE_EXEC(((sljit_u8*)(ptr)) + SLJIT_EXEC_OFFSET(ptr), NULL);
133 static void test_exec_allocator(void)
135 /* This is not an sljit test. */
136 void *ptr1;
137 void *ptr2;
138 void *ptr3;
140 if (verbose)
141 printf("Run executable allocator test\n");
143 MALLOC_EXEC(ptr1, 32);
144 MALLOC_EXEC(ptr2, 512);
145 MALLOC_EXEC(ptr3, 512);
146 FREE_EXEC(ptr2);
147 FREE_EXEC(ptr3);
148 FREE_EXEC(ptr1);
149 MALLOC_EXEC(ptr1, 262104);
150 MALLOC_EXEC(ptr2, 32000);
151 FREE_EXEC(ptr1);
152 MALLOC_EXEC(ptr1, 262104);
153 FREE_EXEC(ptr1);
154 FREE_EXEC(ptr2);
155 MALLOC_EXEC(ptr1, 512);
156 MALLOC_EXEC(ptr2, 512);
157 MALLOC_EXEC(ptr3, 512);
158 FREE_EXEC(ptr2);
159 MALLOC_EXEC(ptr2, 512);
160 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
161 sljit_free_unused_memory_exec();
162 #endif
163 FREE_EXEC(ptr3);
164 FREE_EXEC(ptr1);
165 FREE_EXEC(ptr2);
167 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
168 sljit_free_unused_memory_exec();
169 #endif
172 #undef MALLOC_EXEC
174 #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
176 static void test1(void)
178 /* Enter and return from an sljit function. */
179 executable_code code;
180 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
182 if (verbose)
183 printf("Run test1\n");
185 FAILED(!compiler, "cannot create compiler\n");
187 /* 3 arguments passed, 3 arguments used. */
188 sljit_emit_enter(compiler, 0, SLJIT_ARGS3(W, W, W, W), 3, 3, 0, 0, 0);
189 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_S1, 0);
191 SLJIT_ASSERT(sljit_get_generated_code_size(compiler) == 0);
192 code.code = sljit_generate_code(compiler);
193 CHECK(compiler);
194 SLJIT_ASSERT(compiler->error == SLJIT_ERR_COMPILED);
195 SLJIT_ASSERT(sljit_get_generated_code_size(compiler) > 0);
196 sljit_free_compiler(compiler);
198 FAILED(code.func3(3, -21, 86) != -21, "test1 case 1 failed\n");
199 FAILED(code.func3(4789, 47890, 997) != 47890, "test1 case 2 failed\n");
201 sljit_free_code(code.code, NULL);
202 successful_tests++;
205 static void test2(void)
207 /* Test mov. */
208 executable_code code;
209 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
210 sljit_sw buf[8];
211 static sljit_sw data[2] = { 0, -9876 };
213 if (verbose)
214 printf("Run test2\n");
216 FAILED(!compiler, "cannot create compiler\n");
218 buf[0] = 5678;
219 buf[1] = 0;
220 buf[2] = 0;
221 buf[3] = 0;
222 buf[4] = 0;
223 buf[5] = 0;
224 buf[6] = 0;
225 buf[7] = 0;
226 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 2, 0, 0, 0);
227 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 9999);
228 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_S0, 0);
229 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_sw), SLJIT_R0, 0);
230 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
231 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM2(SLJIT_S1, SLJIT_R1), 0);
232 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, 2);
233 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_S1, SLJIT_S0), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_S1, SLJIT_R1), 0);
234 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, 3);
235 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_S1, SLJIT_S0), SLJIT_WORD_SHIFT, SLJIT_MEM0(), (sljit_sw)&buf);
236 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw));
237 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R0), (sljit_sw)&data);
238 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
239 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf - 0x12345678);
240 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R0), 0x12345678);
241 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_sw), SLJIT_R0, 0);
242 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 3456);
243 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&buf - 0xff890 + 6 * (sljit_sw)sizeof(sljit_sw));
244 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 0xff890, SLJIT_R0, 0);
245 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&buf + 0xff890 + 7 * (sljit_sw)sizeof(sljit_sw));
246 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), -0xff890, SLJIT_R0, 0);
247 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R2, 0);
249 code.code = sljit_generate_code(compiler);
250 CHECK(compiler);
251 sljit_free_compiler(compiler);
253 FAILED(code.func1((sljit_sw)&buf) != 9999, "test2 case 1 failed\n");
254 FAILED(buf[1] != 9999, "test2 case 2 failed\n");
255 FAILED(buf[2] != 9999, "test2 case 3 failed\n");
256 FAILED(buf[3] != 5678, "test2 case 4 failed\n");
257 FAILED(buf[4] != -9876, "test2 case 5 failed\n");
258 FAILED(buf[5] != 5678, "test2 case 6 failed\n");
259 FAILED(buf[6] != 3456, "test2 case 6 failed\n");
260 FAILED(buf[7] != 3456, "test2 case 6 failed\n");
262 sljit_free_code(code.code, NULL);
263 successful_tests++;
266 static void test3(void)
268 /* Test not. */
269 executable_code code;
270 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
271 sljit_sw buf[5];
273 if (verbose)
274 printf("Run test3\n");
276 FAILED(!compiler, "cannot create compiler\n");
277 buf[0] = 1234;
278 buf[1] = 0;
279 buf[2] = 9876;
280 buf[3] = 0;
281 buf[4] = 0x12345678;
283 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 1, 0, 0, 0);
284 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 0);
285 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM0(), (sljit_sw)&buf[1], SLJIT_MEM0(), (sljit_sw)&buf[1]);
286 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_S0), 0);
287 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2);
288 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&buf[4] - 0xff0000 - 0x20);
289 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, (sljit_sw)&buf[4] - 0xff0000);
290 sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM1(SLJIT_R1), 0xff0000 + 0x20, SLJIT_MEM1(SLJIT_R2), 0xff0000);
291 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
293 code.code = sljit_generate_code(compiler);
294 CHECK(compiler);
295 sljit_free_compiler(compiler);
297 FAILED(code.func1((sljit_sw)&buf) != ~1234, "test3 case 1 failed\n");
298 FAILED(buf[1] != ~1234, "test3 case 2 failed\n");
299 FAILED(buf[3] != ~9876, "test3 case 3 failed\n");
300 FAILED(buf[4] != ~0x12345678, "test3 case 4 failed\n");
302 sljit_free_code(code.code, NULL);
303 successful_tests++;
306 static void test4(void)
308 /* Test neg. */
309 executable_code code;
310 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
311 sljit_sw buf[4];
313 if (verbose)
314 printf("Run test4\n");
316 FAILED(!compiler, "cannot create compiler\n");
317 buf[0] = 0;
318 buf[1] = 1234;
319 buf[2] = 0;
320 buf[3] = 0;
322 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(W, P, W), 3, 2, 0, 0, 0);
323 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_S1, 0);
324 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM0(), (sljit_sw)&buf[0], SLJIT_MEM0(), (sljit_sw)&buf[1]);
325 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 299);
326 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_R1, 0);
327 sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_RETURN_REG, 0, SLJIT_S1, 0);
328 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
330 code.code = sljit_generate_code(compiler);
331 CHECK(compiler);
332 sljit_free_compiler(compiler);
334 FAILED(code.func2((sljit_sw)&buf, 4567) != -4567, "test4 case 1 failed\n");
335 FAILED(buf[0] != -1234, "test4 case 2 failed\n");
336 FAILED(buf[2] != -4567, "test4 case 3 failed\n");
337 FAILED(buf[3] != -299, "test4 case 4 failed\n");
339 sljit_free_code(code.code, NULL);
340 successful_tests++;
343 static void test5(void)
345 /* Test add. */
346 executable_code code;
347 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
348 sljit_sw buf[9];
350 if (verbose)
351 printf("Run test5\n");
353 FAILED(!compiler, "cannot create compiler\n");
354 buf[0] = 100;
355 buf[1] = 200;
356 buf[2] = 300;
357 buf[3] = 0;
358 buf[4] = 0;
359 buf[5] = 0;
360 buf[6] = 0;
361 buf[7] = 0;
362 buf[8] = 313;
364 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 2, 0, 0, 0);
365 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw));
366 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 50);
367 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);
368 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw) + 2);
369 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 50);
370 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 0);
371 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
372 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_IMM, 4, SLJIT_R0, 0);
373 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_IMM, 50, SLJIT_R1, 0);
374 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));
375 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R1, 0);
376 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));
377 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));
378 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);
379 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x1e7d39f2);
380 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_R1, 0, SLJIT_IMM, 0x23de7c06);
381 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_IMM, 0x3d72e452, SLJIT_R1, 0);
382 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));
383 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_IMM, 1000, SLJIT_R0, 0);
384 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 1430);
385 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_IMM, -99, SLJIT_R0, 0);
387 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
389 code.code = sljit_generate_code(compiler);
390 CHECK(compiler);
391 sljit_free_compiler(compiler);
393 FAILED(code.func1((sljit_sw)&buf) != 2437 + 2 * sizeof(sljit_sw), "test5 case 1 failed\n");
394 FAILED(buf[0] != 202 + 2 * sizeof(sljit_sw), "test5 case 2 failed\n");
395 FAILED(buf[2] != 500, "test5 case 3 failed\n");
396 FAILED(buf[3] != 400, "test5 case 4 failed\n");
397 FAILED(buf[4] != 200, "test5 case 5 failed\n");
398 FAILED(buf[5] != 250, "test5 case 6 failed\n");
399 FAILED(buf[6] != 0x425bb5f8, "test5 case 7 failed\n");
400 FAILED(buf[7] != 0x5bf01e44, "test5 case 8 failed\n");
401 FAILED(buf[8] != 270, "test5 case 9 failed\n");
403 sljit_free_code(code.code, NULL);
404 successful_tests++;
407 static void test6(void)
409 /* Test addc, sub, subc. */
410 executable_code code;
411 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
412 sljit_sw buf[11];
414 if (verbose)
415 printf("Run test6\n");
417 FAILED(!compiler, "cannot create compiler\n");
418 buf[0] = 0;
419 buf[1] = 0;
420 buf[2] = 0;
421 buf[3] = 0;
422 buf[4] = 0;
423 buf[5] = 0;
424 buf[6] = 0;
425 buf[7] = 0;
426 buf[8] = 0;
427 buf[9] = 0;
428 buf[10] = 4000;
430 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 1, 0, 0, 0);
431 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
432 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, -1);
433 sljit_emit_op2(compiler, SLJIT_ADDC, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0, SLJIT_IMM, 0);
434 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R0, 0);
435 sljit_emit_op2(compiler, SLJIT_ADDC, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, 4);
436 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 100);
437 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0, SLJIT_IMM, 50);
438 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 6000);
439 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_IMM, 10);
440 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);
441 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 100);
442 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2);
443 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R0, 0);
444 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 5000);
445 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R0, 0);
446 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_R1, 0);
447 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_R1, 0);
448 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 5000);
449 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_IMM, 6000, SLJIT_R0, 0);
450 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_R0, 0);
451 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 100);
452 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 32768);
453 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_R1, 0);
454 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -32767);
455 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_R1, 0);
456 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x52cd3bf4);
457 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 9, SLJIT_R0, 0, SLJIT_IMM, 0x3da297c6);
458 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 6000);
459 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 10, SLJIT_R1, 0);
460 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 10, SLJIT_R1, 0);
461 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 10);
462 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_CARRY, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 5);
463 sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, 2);
464 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_RETURN_REG, 0, SLJIT_RETURN_REG, 0, SLJIT_IMM, -2220);
465 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
467 code.code = sljit_generate_code(compiler);
468 CHECK(compiler);
469 sljit_free_compiler(compiler);
471 FAILED(code.func1((sljit_sw)&buf) != 2223, "test6 case 1 failed\n");
472 FAILED(buf[0] != 1, "test6 case 2 failed\n");
473 FAILED(buf[1] != 5, "test6 case 3 failed\n");
474 FAILED(buf[2] != 50, "test6 case 4 failed\n");
475 FAILED(buf[3] != 4, "test6 case 5 failed\n");
476 FAILED(buf[4] != 50, "test6 case 6 failed\n");
477 FAILED(buf[5] != 50, "test6 case 7 failed\n");
478 FAILED(buf[6] != 1000, "test6 case 8 failed\n");
479 FAILED(buf[7] != 100 - 32768, "test6 case 9 failed\n");
480 FAILED(buf[8] != 100 + 32767, "test6 case 10 failed\n");
481 FAILED(buf[9] != 0x152aa42e, "test6 case 11 failed\n");
482 FAILED(buf[10] != -2000, "test6 case 12 failed\n");
484 sljit_free_code(code.code, NULL);
485 successful_tests++;
488 static void test7(void)
490 /* Test logical operators. */
491 executable_code code;
492 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
493 sljit_sw buf[8];
495 if (verbose)
496 printf("Run test7\n");
498 FAILED(!compiler, "cannot create compiler\n");
499 buf[0] = 0xff80;
500 buf[1] = 0x0f808080;
501 buf[2] = 0;
502 buf[3] = 0xaaaaaa;
503 buf[4] = 0;
504 buf[5] = 0x4040;
505 buf[6] = 0;
506 buf[7] = (sljit_sw)0xc43a7f95;
508 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 1, 0, 0, 0);
509 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xf0C000);
510 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0, SLJIT_IMM, 0x308f);
511 sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw));
512 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);
513 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xC0F0);
514 sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5);
515 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xff0000);
516 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R0, 0);
517 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 0xC0F0);
518 sljit_emit_op2(compiler, SLJIT_AND, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5);
519 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_R2, 0, SLJIT_IMM, 0xff0000);
520 sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, 0xFFFFFF, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw));
521 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);
522 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7);
523 sljit_emit_op2(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_IMM, (sljit_sw)0xff00ff00, SLJIT_R0, 0);
524 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)0xff00ff00);
525 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 0x0f);
526 sljit_emit_op2(compiler, SLJIT_AND, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0x888888, SLJIT_R1, 0);
527 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
529 code.code = sljit_generate_code(compiler);
530 CHECK(compiler);
531 sljit_free_compiler(compiler);
533 FAILED(code.func1((sljit_sw)&buf) != 0x8808, "test7 case 1 failed\n");
534 FAILED(buf[0] != 0x0F807F00, "test7 case 2 failed\n");
535 FAILED(buf[1] != 0x0F7F7F7F, "test7 case 3 failed\n");
536 FAILED(buf[2] != 0x00F0F08F, "test7 case 4 failed\n");
537 FAILED(buf[3] != 0x00A0A0A0, "test7 case 5 failed\n");
538 FAILED(buf[4] != 0x00FF80B0, "test7 case 6 failed\n");
539 FAILED(buf[5] != 0x00FF4040, "test7 case 7 failed\n");
540 FAILED(buf[6] != (sljit_sw)0xa56c82c0, "test7 case 8 failed\n");
541 FAILED(buf[7] != 0x3b3a8095, "test7 case 9 failed\n");
543 sljit_free_code(code.code, NULL);
544 successful_tests++;
547 static void test8(void)
549 /* Test flags (neg, cmp, test). */
550 executable_code code;
551 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
552 sljit_sw buf[13];
554 if (verbose)
555 printf("Run test8\n");
557 FAILED(!compiler, "cannot create compiler\n");
558 buf[0] = 100;
559 buf[1] = 3;
560 buf[2] = 3;
561 buf[3] = 3;
562 buf[4] = 3;
563 buf[5] = 3;
564 buf[6] = 3;
565 buf[7] = 3;
566 buf[8] = 3;
567 buf[9] = 3;
568 buf[10] = 3;
569 buf[11] = 3;
570 buf[12] = 3;
572 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 3, 2, 0, 0, 0);
573 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 20);
574 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 10);
575 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_IMM, 6, SLJIT_IMM, 5);
576 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_NOT_EQUAL);
577 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_EQUAL);
578 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_R0, 0, SLJIT_IMM, 3000);
579 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_GREATER);
580 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_R0, 0, SLJIT_IMM, 3000);
581 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_S1, 0);
582 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_LESS);
583 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R2, 0);
584 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_R0, 0, SLJIT_IMM, -15);
585 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_SIG_GREATER);
586 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_R2, 0);
587 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -(sljit_sw)(~(sljit_uw)0 >> 1) - 1);
588 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R1, 0);
589 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
590 sljit_emit_op1(compiler, SLJIT_NEG | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_R0, 0);
591 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_OVERFLOW);
592 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
593 sljit_emit_op1(compiler, SLJIT_NOT | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_R0, 0);
594 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_ZERO);
595 sljit_emit_op1(compiler, SLJIT_NOT | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R1, 0);
596 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_ZERO);
597 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_IMM, 0xffff, SLJIT_R0, 0);
598 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_IMM, 0xffff);
599 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 9, SLJIT_NOT_ZERO);
600 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_IMM, 0xffff, SLJIT_R1, 0);
601 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_IMM, 0xffff);
602 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R1, 0);
603 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), 0);
604 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0);
605 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0x1);
606 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 10, SLJIT_NOT_ZERO);
607 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -(sljit_sw)(~(sljit_uw)0 >> 1) - 1);
608 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
609 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_R0, 0);
610 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 11, SLJIT_OVERFLOW);
611 sljit_emit_op2u(compiler, SLJIT_ADD | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_R0, 0);
612 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 12, SLJIT_OVERFLOW);
613 sljit_emit_return_void(compiler);
615 code.code = sljit_generate_code(compiler);
616 CHECK(compiler);
617 sljit_free_compiler(compiler);
619 code.func1((sljit_sw)&buf);
620 FAILED(buf[1] != 1, "test8 case 1 failed\n");
621 FAILED(buf[2] != 0, "test8 case 2 failed\n");
622 FAILED(buf[3] != 0, "test8 case 3 failed\n");
623 FAILED(buf[4] != 1, "test8 case 4 failed\n");
624 FAILED(buf[5] != 1, "test8 case 5 failed\n");
625 FAILED(buf[6] != 1, "test8 case 6 failed\n");
626 FAILED(buf[7] != 1, "test8 case 7 failed\n");
627 FAILED(buf[8] != 0, "test8 case 8 failed\n");
628 FAILED(buf[9] != 1, "test8 case 9 failed\n");
629 FAILED(buf[10] != 0, "test8 case 10 failed\n");
630 FAILED(buf[11] != 1, "test8 case 11 failed\n");
631 FAILED(buf[12] != 0, "test8 case 12 failed\n");
633 sljit_free_code(code.code, NULL);
634 successful_tests++;
637 static void test9(void)
639 /* Test shift. */
640 executable_code code;
641 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
642 sljit_sw buf[13];
643 #ifdef SLJIT_PREF_SHIFT_REG
644 sljit_s32 shift_reg = SLJIT_PREF_SHIFT_REG;
645 #else
646 sljit_s32 shift_reg = SLJIT_R2;
647 #endif
649 SLJIT_ASSERT(shift_reg >= SLJIT_R2 && shift_reg <= SLJIT_R3);
651 if (verbose)
652 printf("Run test9\n");
654 FAILED(!compiler, "cannot create compiler\n");
655 buf[0] = 0;
656 buf[1] = 0;
657 buf[2] = 0;
658 buf[3] = 0;
659 buf[4] = 1 << 10;
660 buf[5] = 0;
661 buf[6] = 0;
662 buf[7] = 0;
663 buf[8] = 0;
664 buf[9] = 3;
665 buf[10] = 0;
666 buf[11] = 0;
667 buf[12] = 0;
669 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 4, 2, 0, 0, 0);
670 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xf);
671 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 3);
672 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
673 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
674 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
675 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R1, 0, SLJIT_IMM, 1);
676 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -64);
677 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 2);
678 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0, shift_reg, 0);
680 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 0xff);
681 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4);
682 sljit_emit_op2(compiler, SLJIT_SHL, shift_reg, 0, shift_reg, 0, SLJIT_R0, 0);
683 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, shift_reg, 0);
684 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 0xff);
685 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
686 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);
687 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, shift_reg, 0, SLJIT_R0, 0);
689 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, 0xf);
690 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
691 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_R0, 0);
692 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_S1, 0);
693 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_R0, 0);
694 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_R0, 0);
695 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 0xf00);
696 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4);
697 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_R1, 0, SLJIT_R2, 0, SLJIT_R0, 0);
698 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_R1, 0);
700 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)buf);
701 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 9);
702 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);
704 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 4);
705 sljit_emit_op2(compiler, SLJIT_SHL, shift_reg, 0, SLJIT_IMM, 2, shift_reg, 0);
706 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 10, shift_reg, 0);
708 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xa9);
709 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 0);
710 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x7d00);
711 sljit_emit_op2(compiler, SLJIT_LSHR32, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 32);
712 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
713 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
714 #endif
715 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_R0, 0);
716 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xe30000);
717 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
718 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffc0);
719 #else
720 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffe0);
721 #endif
722 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_R0, 0);
723 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x25000000);
724 sljit_emit_op2(compiler, SLJIT_SHL32, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xfffe1);
725 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
726 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
727 #endif
728 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 11, SLJIT_R1, 0, SLJIT_R0, 0);
730 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 0);
731 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x5c);
732 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R1, 0, SLJIT_R0, 0, shift_reg, 0);
733 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0xf600);
734 sljit_emit_op2(compiler, SLJIT_LSHR32, SLJIT_R0, 0, SLJIT_R0, 0, shift_reg, 0);
735 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
736 /* Alternative form of uint32 type cast. */
737 sljit_emit_op2(compiler, SLJIT_AND, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffffffff);
738 #endif
739 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_R0, 0);
740 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x630000);
741 sljit_emit_op2(compiler, SLJIT_ASHR, SLJIT_R0, 0, SLJIT_R0, 0, shift_reg, 0);
742 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 12, SLJIT_R1, 0, SLJIT_R0, 0);
744 sljit_emit_return_void(compiler);
746 code.code = sljit_generate_code(compiler);
747 CHECK(compiler);
748 sljit_free_compiler(compiler);
750 code.func1((sljit_sw)&buf);
751 FAILED(buf[0] != 0x3c, "test9 case 1 failed\n");
752 FAILED(buf[1] != 0xf0, "test9 case 2 failed\n");
753 FAILED(buf[2] != -16, "test9 case 3 failed\n");
754 FAILED(buf[3] != 0xff0, "test9 case 4 failed\n");
755 FAILED(buf[4] != 4, "test9 case 5 failed\n");
756 FAILED(buf[5] != 0xff00, "test9 case 6 failed\n");
757 FAILED(buf[6] != 0x3c, "test9 case 7 failed\n");
758 FAILED(buf[7] != 0xf0, "test9 case 8 failed\n");
759 FAILED(buf[8] != 0xf0, "test9 case 9 failed\n");
760 FAILED(buf[9] != 0x18, "test9 case 10 failed\n");
761 FAILED(buf[10] != 32, "test9 case 11 failed\n");
762 FAILED(buf[11] != 0x4ae37da9, "test9 case 12 failed\n");
763 FAILED(buf[12] != 0x63f65c, "test9 case 13 failed\n");
765 sljit_free_code(code.code, NULL);
766 successful_tests++;
769 static void test10(void)
771 /* Test multiplications. */
772 executable_code code;
773 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
774 sljit_sw buf[7];
776 if (verbose)
777 printf("Run test10\n");
779 FAILED(!compiler, "cannot create compiler\n");
780 buf[0] = 3;
781 buf[1] = 0;
782 buf[2] = 0;
783 buf[3] = 6;
784 buf[4] = -10;
785 buf[5] = 0;
786 buf[6] = 0;
788 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 1, 0, 0, 0);
789 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 5);
790 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
791 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
792 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 7);
793 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_R2, 0, SLJIT_IMM, 8);
794 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
795 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_IMM, -3, SLJIT_IMM, -4);
796 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0);
797 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -2);
798 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);
799 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw) / 2);
800 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&buf[3]);
801 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);
802 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 9);
803 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R0, 0);
804 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_R0, 0);
805 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
806 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 3);
807 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x123456789));
808 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_R0, 0);
809 #endif
810 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 11, SLJIT_IMM, 10);
811 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
813 code.code = sljit_generate_code(compiler);
814 CHECK(compiler);
815 sljit_free_compiler(compiler);
817 FAILED(code.func1((sljit_sw)&buf) != 110, "test10 case 1 failed\n");
818 FAILED(buf[0] != 15, "test10 case 2 failed\n");
819 FAILED(buf[1] != 56, "test10 case 3 failed\n");
820 FAILED(buf[2] != 12, "test10 case 4 failed\n");
821 FAILED(buf[3] != -12, "test10 case 5 failed\n");
822 FAILED(buf[4] != 100, "test10 case 6 failed\n");
823 FAILED(buf[5] != 81, "test10 case 7 failed\n");
824 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
825 FAILED(buf[6] != SLJIT_W(0x123456789) * 3, "test10 case 8 failed\n");
826 #endif
828 sljit_free_code(code.code, NULL);
829 successful_tests++;
832 static void test11(void)
834 /* Test rewritable constants. */
835 executable_code code;
836 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
837 struct sljit_const* const1;
838 struct sljit_const* const2;
839 struct sljit_const* const3;
840 struct sljit_const* const4;
841 void* value;
842 sljit_sw executable_offset;
843 sljit_uw const1_addr;
844 sljit_uw const2_addr;
845 sljit_uw const3_addr;
846 sljit_uw const4_addr;
847 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
848 sljit_sw word_value1 = (sljit_sw)SLJIT_W(0xaaaaaaaaaaaaaaaa);
849 sljit_sw word_value2 = (sljit_sw)SLJIT_W(0xfee1deadfbadf00d);
850 #else
851 sljit_sw word_value1 = (sljit_sw)0xaaaaaaaal;
852 sljit_sw word_value2 = (sljit_sw)0xfbadf00dl;
853 #endif
854 sljit_sw buf[3];
856 if (verbose)
857 printf("Run test11\n");
859 FAILED(!compiler, "cannot create compiler\n");
860 buf[0] = 0;
861 buf[1] = 0;
862 buf[2] = 0;
864 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 1, 0, 0, 0);
866 SLJIT_ASSERT(!sljit_alloc_memory(compiler, 0));
867 SLJIT_ASSERT(!sljit_alloc_memory(compiler, 16 * sizeof(sljit_sw) + 1));
869 const1 = sljit_emit_const(compiler, SLJIT_MEM0(), (sljit_sw)&buf[0], -0x81b9);
871 value = sljit_alloc_memory(compiler, 16 * sizeof(sljit_sw));
872 if (value != NULL)
874 SLJIT_ASSERT(!((sljit_sw)value & ((sljit_sw)sizeof(sljit_sw) - 1)));
875 memset(value, 255, 16 * sizeof(sljit_sw));
878 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
879 const2 = sljit_emit_const(compiler, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_WORD_SHIFT - 1, -65535);
880 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);
881 const3 = sljit_emit_const(compiler, SLJIT_MEM1(SLJIT_R0), 0, word_value1);
883 value = sljit_alloc_memory(compiler, 17);
884 if (value != NULL)
886 SLJIT_ASSERT(!((sljit_sw)value & ((sljit_sw)sizeof(sljit_sw) - 1)));
887 memset(value, 255, 16);
890 const4 = sljit_emit_const(compiler, SLJIT_RETURN_REG, 0, (sljit_sw)0xf7afcdb7);
892 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
894 code.code = sljit_generate_code(compiler);
895 CHECK(compiler);
896 executable_offset = sljit_get_executable_offset(compiler);
897 const1_addr = sljit_get_const_addr(const1);
898 const2_addr = sljit_get_const_addr(const2);
899 const3_addr = sljit_get_const_addr(const3);
900 const4_addr = sljit_get_const_addr(const4);
901 sljit_free_compiler(compiler);
903 FAILED(code.func1((sljit_sw)&buf) != (sljit_sw)0xf7afcdb7, "test11 case 1 failed\n");
904 FAILED(buf[0] != -0x81b9, "test11 case 2 failed\n");
905 FAILED(buf[1] != -65535, "test11 case 3 failed\n");
906 FAILED(buf[2] != word_value1, "test11 case 4 failed\n");
908 sljit_set_const(const1_addr, -1, executable_offset);
909 sljit_set_const(const2_addr, word_value2, executable_offset);
910 sljit_set_const(const3_addr, (sljit_sw)0xbab0fea1, executable_offset);
911 sljit_set_const(const4_addr, -60089, executable_offset);
913 FAILED(code.func1((sljit_sw)&buf) != -60089, "test11 case 5 failed\n");
914 FAILED(buf[0] != -1, "test11 case 6 failed\n");
915 FAILED(buf[1] != word_value2, "test11 case 7 failed\n");
916 FAILED(buf[2] != (sljit_sw)0xbab0fea1, "test11 case 8 failed\n");
918 sljit_free_code(code.code, NULL);
919 successful_tests++;
922 static void test12(void)
924 /* Test rewriteable jumps. */
925 executable_code code;
926 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
927 struct sljit_label *label1;
928 struct sljit_label *label2;
929 struct sljit_label *label3;
930 struct sljit_jump *jump1;
931 struct sljit_jump *jump2;
932 struct sljit_jump *jump3;
933 sljit_sw executable_offset;
934 void* value;
935 sljit_uw jump1_addr;
936 sljit_uw label1_addr;
937 sljit_uw label2_addr;
938 sljit_sw buf[1];
940 if (verbose)
941 printf("Run test12\n");
943 FAILED(!compiler, "cannot create compiler\n");
944 buf[0] = 0;
946 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(VOID, P, W), 3, 2, 0, 0, 0);
947 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_S1, 0, SLJIT_IMM, 10);
948 jump1 = sljit_emit_jump(compiler, SLJIT_REWRITABLE_JUMP | SLJIT_SIG_GREATER);
949 /* Default handler. */
950 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 5);
951 jump2 = sljit_emit_jump(compiler, SLJIT_JUMP);
953 value = sljit_alloc_memory(compiler, 15);
954 if (value != NULL)
956 SLJIT_ASSERT(!((sljit_sw)value & ((sljit_sw)sizeof(sljit_sw) - 1)));
957 memset(value, 255, 15);
960 /* Handler 1. */
961 label1 = sljit_emit_label(compiler);
962 sljit_emit_op0(compiler, SLJIT_ENDBR);
963 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 6);
964 jump3 = sljit_emit_jump(compiler, SLJIT_JUMP);
965 /* Handler 2. */
966 label2 = sljit_emit_label(compiler);
967 sljit_emit_op0(compiler, SLJIT_ENDBR);
968 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 7);
969 /* Exit. */
970 label3 = sljit_emit_label(compiler);
971 sljit_emit_op0(compiler, SLJIT_ENDBR);
972 sljit_set_label(jump2, label3);
973 sljit_set_label(jump3, label3);
974 /* By default, set to handler 1. */
975 sljit_set_label(jump1, label1);
976 sljit_emit_return_void(compiler);
978 value = sljit_alloc_memory(compiler, 8);
979 if (value != NULL)
981 SLJIT_ASSERT(!((sljit_sw)value & ((sljit_sw)sizeof(sljit_sw) - 1)));
982 memset(value, 255, 8);
985 code.code = sljit_generate_code(compiler);
986 CHECK(compiler);
987 executable_offset = sljit_get_executable_offset(compiler);
988 jump1_addr = sljit_get_jump_addr(jump1);
989 label1_addr = sljit_get_label_addr(label1);
990 label2_addr = sljit_get_label_addr(label2);
991 sljit_free_compiler(compiler);
993 code.func2((sljit_sw)&buf, 4);
994 FAILED(buf[0] != 5, "test12 case 1 failed\n");
996 code.func2((sljit_sw)&buf, 11);
997 FAILED(buf[0] != 6, "test12 case 2 failed\n");
999 sljit_set_jump_addr(jump1_addr, label2_addr, executable_offset);
1000 code.func2((sljit_sw)&buf, 12);
1001 FAILED(buf[0] != 7, "test12 case 3 failed\n");
1003 sljit_set_jump_addr(jump1_addr, label1_addr, executable_offset);
1004 code.func2((sljit_sw)&buf, 13);
1005 FAILED(buf[0] != 6, "test12 case 4 failed\n");
1007 sljit_free_code(code.code, NULL);
1008 successful_tests++;
1011 static void test13(void)
1013 /* Test fpu monadic functions. */
1014 executable_code code;
1015 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1016 sljit_f64 buf[7];
1017 sljit_sw buf2[6];
1019 if (verbose)
1020 printf("Run test13\n");
1022 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
1023 if (verbose)
1024 printf("no fpu available, test13 skipped\n");
1025 successful_tests++;
1026 if (compiler)
1027 sljit_free_compiler(compiler);
1028 return;
1031 FAILED(!compiler, "cannot create compiler\n");
1032 buf[0] = 7.75;
1033 buf[1] = -4.5;
1034 buf[2] = 0.0;
1035 buf[3] = 0.0;
1036 buf[4] = 0.0;
1037 buf[5] = 0.0;
1038 buf[6] = 0.0;
1040 buf2[0] = 10;
1041 buf2[1] = 10;
1042 buf2[2] = 10;
1043 buf2[3] = 10;
1044 buf2[4] = 10;
1045 buf2[5] = 10;
1047 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(VOID, P, P), 3, 2, 6, 0, 0);
1048 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM0(), (sljit_sw)&buf[2], SLJIT_MEM0(), (sljit_sw)&buf[1]);
1049 sljit_emit_fop1(compiler, SLJIT_ABS_F64, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1050 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM0(), (sljit_sw)&buf[0]);
1051 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2 * sizeof(sljit_f64));
1052 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 0);
1053 sljit_emit_fop1(compiler, SLJIT_NEG_F64, SLJIT_FR2, 0, SLJIT_FR0, 0);
1054 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR3, 0, SLJIT_FR2, 0);
1055 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM0(), (sljit_sw)&buf[4], SLJIT_FR3, 0);
1056 sljit_emit_fop1(compiler, SLJIT_ABS_F64, SLJIT_FR4, 0, SLJIT_FR1, 0);
1057 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f64), SLJIT_FR4, 0);
1058 sljit_emit_fop1(compiler, SLJIT_NEG_F64, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64), SLJIT_FR4, 0);
1060 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), 0);
1061 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_GREATER_F, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1062 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_GREATER_F64);
1063 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_GREATER_F, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64), SLJIT_FR5, 0);
1064 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_sw), SLJIT_GREATER_F64);
1065 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_FR5, 0);
1066 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR1, 0);
1067 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_sw), SLJIT_EQUAL_F64);
1068 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_LESS_F, SLJIT_FR1, 0, SLJIT_FR1, 0);
1069 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw), SLJIT_LESS_F64);
1070 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1071 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_sw), SLJIT_EQUAL_F64);
1072 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_NOT_EQUAL_F, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1073 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_sw), SLJIT_NOT_EQUAL_F64);
1075 sljit_emit_return_void(compiler);
1077 code.code = sljit_generate_code(compiler);
1078 CHECK(compiler);
1079 sljit_free_compiler(compiler);
1081 code.func2((sljit_sw)&buf, (sljit_sw)&buf2);
1082 FAILED(buf[2] != -4.5, "test13 case 1 failed\n");
1083 FAILED(buf[3] != 4.5, "test13 case 2 failed\n");
1084 FAILED(buf[4] != -7.75, "test13 case 3 failed\n");
1085 FAILED(buf[5] != 4.5, "test13 case 4 failed\n");
1086 FAILED(buf[6] != -4.5, "test13 case 5 failed\n");
1088 FAILED(buf2[0] != 1, "test13 case 6 failed\n");
1089 FAILED(buf2[1] != 0, "test13 case 7 failed\n");
1090 FAILED(buf2[2] != 1, "test13 case 8 failed\n");
1091 FAILED(buf2[3] != 0, "test13 case 9 failed\n");
1092 FAILED(buf2[4] != 0, "test13 case 10 failed\n");
1093 FAILED(buf2[5] != 1, "test13 case 11 failed\n");
1095 sljit_free_code(code.code, NULL);
1096 successful_tests++;
1099 static void test14(void)
1101 /* Test fpu diadic functions. */
1102 executable_code code;
1103 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1104 sljit_f64 buf[15];
1106 if (verbose)
1107 printf("Run test14\n");
1109 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
1110 if (verbose)
1111 printf("no fpu available, test14 skipped\n");
1112 successful_tests++;
1113 if (compiler)
1114 sljit_free_compiler(compiler);
1115 return;
1117 buf[0] = 7.25;
1118 buf[1] = 3.5;
1119 buf[2] = 1.75;
1120 buf[3] = 0.0;
1121 buf[4] = 0.0;
1122 buf[5] = 0.0;
1123 buf[6] = 0.0;
1124 buf[7] = 0.0;
1125 buf[8] = 0.0;
1126 buf[9] = 0.0;
1127 buf[10] = 0.0;
1128 buf[11] = 0.0;
1129 buf[12] = 8.0;
1130 buf[13] = 4.0;
1131 buf[14] = 0.0;
1133 FAILED(!compiler, "cannot create compiler\n");
1134 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 3, 1, 6, 0, 0);
1136 /* ADD */
1137 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_f64));
1138 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
1139 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 2);
1140 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);
1141 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR0, 0, SLJIT_FR0, 0, SLJIT_FR1, 0);
1142 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR1, 0, SLJIT_FR0, 0, SLJIT_FR1, 0);
1143 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 4, SLJIT_FR0, 0);
1144 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 5, SLJIT_FR1, 0);
1146 /* SUB */
1147 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 0);
1148 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR3, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 2);
1149 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 2);
1150 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);
1151 sljit_emit_fop2(compiler, SLJIT_SUB_F64, SLJIT_FR2, 0, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 2);
1152 sljit_emit_fop2(compiler, SLJIT_SUB_F64, SLJIT_FR3, 0, SLJIT_FR2, 0, SLJIT_FR3, 0);
1153 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 7, SLJIT_FR2, 0);
1154 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 8, SLJIT_FR3, 0);
1156 /* MUL */
1157 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
1158 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);
1159 sljit_emit_fop2(compiler, SLJIT_MUL_F64, SLJIT_FR1, 0, SLJIT_FR1, 0, SLJIT_FR2, 0);
1160 sljit_emit_fop2(compiler, SLJIT_MUL_F64, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 2, SLJIT_FR2, 0);
1161 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 10, SLJIT_FR1, 0);
1162 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 11, SLJIT_FR5, 0);
1164 /* DIV */
1165 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 12);
1166 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 13);
1167 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR4, 0, SLJIT_FR5, 0);
1168 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);
1169 sljit_emit_fop2(compiler, SLJIT_DIV_F64, SLJIT_FR5, 0, SLJIT_FR5, 0, SLJIT_FR1, 0);
1170 sljit_emit_fop2(compiler, SLJIT_DIV_F64, SLJIT_FR4, 0, SLJIT_FR1, 0, SLJIT_FR4, 0);
1171 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 13, SLJIT_FR5, 0);
1172 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64) * 14, SLJIT_FR4, 0);
1174 sljit_emit_return_void(compiler);
1176 code.code = sljit_generate_code(compiler);
1177 CHECK(compiler);
1178 sljit_free_compiler(compiler);
1180 code.func1((sljit_sw)&buf);
1181 FAILED(buf[3] != 10.75, "test14 case 1 failed\n");
1182 FAILED(buf[4] != 5.25, "test14 case 2 failed\n");
1183 FAILED(buf[5] != 7.0, "test14 case 3 failed\n");
1184 FAILED(buf[6] != 0.0, "test14 case 4 failed\n");
1185 FAILED(buf[7] != 5.5, "test14 case 5 failed\n");
1186 FAILED(buf[8] != 3.75, "test14 case 6 failed\n");
1187 FAILED(buf[9] != 24.5, "test14 case 7 failed\n");
1188 FAILED(buf[10] != 38.5, "test14 case 8 failed\n");
1189 FAILED(buf[11] != 9.625, "test14 case 9 failed\n");
1190 FAILED(buf[12] != 2.0, "test14 case 10 failed\n");
1191 FAILED(buf[13] != 2.0, "test14 case 11 failed\n");
1192 FAILED(buf[14] != 0.5, "test14 case 12 failed\n");
1194 sljit_free_code(code.code, NULL);
1195 successful_tests++;
1198 static sljit_sw SLJIT_FUNC func(sljit_sw a, sljit_sw b, sljit_sw c)
1200 return a + b + c + 5;
1203 static void test15(void)
1205 /* Test function call. */
1206 executable_code code;
1207 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1208 struct sljit_jump* jump = NULL;
1209 sljit_sw buf[7];
1211 if (verbose)
1212 printf("Run test15\n");
1214 FAILED(!compiler, "cannot create compiler\n");
1215 buf[0] = 0;
1216 buf[1] = 0;
1217 buf[2] = 0;
1218 buf[3] = 0;
1219 buf[4] = 0;
1220 buf[5] = 0;
1221 buf[6] = SLJIT_FUNC_ADDR(func);
1223 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 4, 1, 0, 0, 0);
1225 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 5);
1226 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 7);
1227 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -3);
1228 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS3(W, W, W, W), SLJIT_IMM, SLJIT_FUNC_ADDR(func));
1229 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_RETURN_REG, 0);
1231 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -5);
1232 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -10);
1233 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 2);
1234 jump = sljit_emit_call(compiler, SLJIT_CALL | SLJIT_REWRITABLE_JUMP, SLJIT_ARGS3(W, W, W, W));
1235 sljit_set_target(jump, (sljit_uw)-1);
1236 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1238 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(func));
1239 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 40);
1240 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -3);
1241 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS3(W, W, W, W), SLJIT_R0, 0);
1242 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1244 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -60);
1245 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(func));
1246 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -30);
1247 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS3(W, W, W, W), SLJIT_R1, 0);
1248 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1250 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 10);
1251 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 16);
1252 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(func));
1253 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS3(W, W, W, W), SLJIT_R2, 0);
1254 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1256 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 100);
1257 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 110);
1258 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 120);
1259 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(func));
1260 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS3(W, W, W, W), SLJIT_R3, 0);
1261 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1263 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -10);
1264 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -16);
1265 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 6);
1266 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS3(W, W, W, W), SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw));
1267 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_RETURN_REG, 0);
1269 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1271 code.code = sljit_generate_code(compiler);
1272 CHECK(compiler);
1273 sljit_set_jump_addr(sljit_get_jump_addr(jump), SLJIT_FUNC_UADDR(func), sljit_get_executable_offset(compiler));
1274 sljit_free_compiler(compiler);
1276 FAILED(code.func1((sljit_sw)&buf) != -15, "test15 case 1 failed\n");
1277 FAILED(buf[0] != 14, "test15 case 2 failed\n");
1278 FAILED(buf[1] != -8, "test15 case 3 failed\n");
1279 FAILED(buf[2] != SLJIT_FUNC_ADDR(func) + 42, "test15 case 4 failed\n");
1280 FAILED(buf[3] != SLJIT_FUNC_ADDR(func) - 85, "test15 case 5 failed\n");
1281 FAILED(buf[4] != SLJIT_FUNC_ADDR(func) + 31, "test15 case 6 failed\n");
1282 FAILED(buf[5] != 335, "test15 case 7 failed\n");
1283 FAILED(buf[6] != -15, "test15 case 8 failed\n");
1285 sljit_free_code(code.code, NULL);
1286 successful_tests++;
1289 static void test16(void)
1291 /* Ackermann benchmark. */
1292 executable_code code;
1293 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1294 struct sljit_label *entry;
1295 struct sljit_label *label;
1296 struct sljit_jump *jump;
1297 struct sljit_jump *jump1;
1298 struct sljit_jump *jump2;
1300 if (verbose)
1301 printf("Run test16\n");
1303 FAILED(!compiler, "cannot create compiler\n");
1305 entry = sljit_emit_label(compiler);
1306 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(W, W, W), 3, 2, 0, 0, 0);
1307 /* If x == 0. */
1308 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_S0, 0, SLJIT_IMM, 0);
1309 jump1 = sljit_emit_jump(compiler, SLJIT_EQUAL);
1310 /* If y == 0. */
1311 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_S1, 0, SLJIT_IMM, 0);
1312 jump2 = sljit_emit_jump(compiler, SLJIT_EQUAL);
1314 /* Ack(x,y-1). */
1315 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
1316 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_S1, 0, SLJIT_IMM, 1);
1317 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS2(W, W, W));
1318 sljit_set_label(jump, entry);
1320 /* Returns with Ack(x-1, Ack(x,y-1)). */
1321 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_RETURN_REG, 0);
1322 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
1323 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS2(W, W, W));
1324 sljit_set_label(jump, entry);
1325 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1327 /* Returns with y+1. */
1328 label = sljit_emit_label(compiler);
1329 sljit_set_label(jump1, label);
1330 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_RETURN_REG, 0, SLJIT_IMM, 1, SLJIT_S1, 0);
1331 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1333 /* Returns with Ack(x-1,1) */
1334 label = sljit_emit_label(compiler);
1335 sljit_set_label(jump2, label);
1336 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
1337 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
1338 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS2(W, W, W));
1339 sljit_set_label(jump, entry);
1340 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1342 code.code = sljit_generate_code(compiler);
1343 CHECK(compiler);
1344 sljit_free_compiler(compiler);
1346 FAILED(code.func2(3, 3) != 61, "test16 case 1 failed\n");
1347 /* For benchmarking. */
1348 /* FAILED(code.func2(3, 11) != 16381, "test16 case 1 failed\n"); */
1350 sljit_free_code(code.code, NULL);
1351 successful_tests++;
1354 static void test17(void)
1356 /* Test arm constant pool. */
1357 executable_code code;
1358 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1359 sljit_s32 i;
1360 sljit_sw buf[5];
1362 if (verbose)
1363 printf("Run test17\n");
1365 FAILED(!compiler, "cannot create compiler\n");
1367 for (i = 0; i < 5; i++)
1368 buf[i] = 0;
1370 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 3, 1, 0, 0, 0);
1371 for (i = 0; i <= 0xfff; i++) {
1372 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)0x81818000 | i);
1373 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)0x81818000 | i);
1374 if ((i & 0x3ff) == 0)
1375 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), (i >> 10) * (sljit_sw)sizeof(sljit_sw), SLJIT_R0, 0);
1377 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
1378 sljit_emit_return_void(compiler);
1380 code.code = sljit_generate_code(compiler);
1381 CHECK(compiler);
1382 sljit_free_compiler(compiler);
1384 code.func1((sljit_sw)&buf);
1385 FAILED((sljit_uw)buf[0] != 0x81818000, "test17 case 1 failed\n");
1386 FAILED((sljit_uw)buf[1] != 0x81818400, "test17 case 2 failed\n");
1387 FAILED((sljit_uw)buf[2] != 0x81818800, "test17 case 3 failed\n");
1388 FAILED((sljit_uw)buf[3] != 0x81818c00, "test17 case 4 failed\n");
1389 FAILED((sljit_uw)buf[4] != 0x81818fff, "test17 case 5 failed\n");
1391 sljit_free_code(code.code, NULL);
1392 successful_tests++;
1395 static void test18(void)
1397 /* Test 64 bit. */
1398 executable_code code;
1399 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1400 sljit_sw buf[11];
1402 if (verbose)
1403 printf("Run test18\n");
1405 FAILED(!compiler, "cannot create compiler\n");
1406 buf[0] = 0;
1407 buf[1] = 0;
1408 buf[2] = 0;
1409 buf[3] = 0;
1410 buf[4] = 0;
1411 buf[5] = 100;
1412 buf[6] = 100;
1413 buf[7] = 100;
1414 buf[8] = 100;
1415 buf[9] = 0;
1416 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) && (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
1417 buf[10] = SLJIT_W(1) << 32;
1418 #else
1419 buf[10] = 1;
1420 #endif
1422 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 3, 2, 0, 0, 0);
1424 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1425 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, SLJIT_W(0x1122334455667788));
1426 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x1122334455667788));
1428 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(1000000000000));
1429 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(1000000000000));
1430 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_IMM, SLJIT_W(5000000000000), SLJIT_R0, 0);
1432 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x1108080808));
1433 sljit_emit_op2(compiler, SLJIT_ADD32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x1120202020));
1435 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1108080808));
1436 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1120202020));
1437 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_ZERO);
1438 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_S1, 0);
1439 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
1440 sljit_emit_op2u(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1120202020));
1441 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_ZERO);
1443 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1108080808));
1444 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x2208080808));
1445 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_LESS);
1446 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
1447 sljit_emit_op2u(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x1104040404));
1448 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_NOT_ZERO);
1450 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 4);
1451 sljit_emit_op2(compiler, SLJIT_SHL32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 9, SLJIT_IMM, SLJIT_W(0xffff0000), SLJIT_R0, 0);
1453 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);
1454 #else
1455 /* 32 bit operations. */
1457 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0x11223344);
1458 sljit_emit_op2(compiler, SLJIT_ADD32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, 0x44332211);
1460 #endif
1462 sljit_emit_return_void(compiler);
1464 code.code = sljit_generate_code(compiler);
1465 CHECK(compiler);
1466 sljit_free_compiler(compiler);
1468 code.func1((sljit_sw)&buf);
1469 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1470 FAILED(buf[0] != SLJIT_W(0x1122334455667788), "test18 case 1 failed\n");
1471 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1472 FAILED(buf[1] != 0x55667788, "test18 case 2 failed\n");
1473 #else
1474 FAILED(buf[1] != SLJIT_W(0x5566778800000000), "test18 case 2 failed\n");
1475 #endif
1476 FAILED(buf[2] != SLJIT_W(2000000000000), "test18 case 3 failed\n");
1477 FAILED(buf[3] != SLJIT_W(4000000000000), "test18 case 4 failed\n");
1478 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1479 FAILED(buf[4] != 0x28282828, "test18 case 5 failed\n");
1480 #else
1481 FAILED(buf[4] != SLJIT_W(0x2828282800000000), "test18 case 5 failed\n");
1482 #endif
1483 FAILED(buf[5] != 0, "test18 case 6 failed\n");
1484 FAILED(buf[6] != 1, "test18 case 7 failed\n");
1485 FAILED(buf[7] != 1, "test18 case 8 failed\n");
1486 FAILED(buf[8] != 0, "test18 case 9 failed\n");
1487 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1488 FAILED(buf[9] != (sljit_sw)0xfff00000, "test18 case 10 failed\n");
1489 FAILED(buf[10] != (sljit_sw)0xffffffff, "test18 case 11 failed\n");
1490 #else
1491 FAILED(buf[9] != (sljit_sw)SLJIT_W(0xfff0000000000000), "test18 case 10 failed\n");
1492 FAILED(buf[10] != (sljit_sw)SLJIT_W(0xffffffff00000000), "test18 case 11 failed\n");
1493 #endif
1494 #else
1495 FAILED(buf[0] != 0x11223344, "test18 case 1 failed\n");
1496 FAILED(buf[1] != 0x44332211, "test18 case 2 failed\n");
1497 #endif
1499 sljit_free_code(code.code, NULL);
1500 successful_tests++;
1503 static void test19(void)
1505 /* Test arm partial instruction caching. */
1506 executable_code code;
1507 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1508 sljit_sw buf[10];
1510 if (verbose)
1511 printf("Run test19\n");
1513 FAILED(!compiler, "cannot create compiler\n");
1514 buf[0] = 6;
1515 buf[1] = 4;
1516 buf[2] = 0;
1517 buf[3] = 0;
1518 buf[4] = 0;
1519 buf[5] = 0;
1520 buf[6] = 2;
1521 buf[7] = 0;
1523 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 3, 1, 0, 0, 0);
1524 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw));
1525 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM0(), (sljit_sw)&buf[2], SLJIT_MEM0(), (sljit_sw)&buf[1], SLJIT_MEM0(), (sljit_sw)&buf[0]);
1526 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
1527 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
1528 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]);
1529 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_MEM0(), (sljit_sw)&buf[0], SLJIT_IMM, 2);
1530 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));
1531 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_IMM, 10);
1532 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 7);
1533 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]);
1535 sljit_emit_return_void(compiler);
1537 code.code = sljit_generate_code(compiler);
1538 CHECK(compiler);
1539 sljit_free_compiler(compiler);
1541 code.func1((sljit_sw)&buf);
1542 FAILED(buf[0] != 10, "test19 case 1 failed\n");
1543 FAILED(buf[1] != 4, "test19 case 2 failed\n");
1544 FAILED(buf[2] != 14, "test19 case 3 failed\n");
1545 FAILED(buf[3] != 14, "test19 case 4 failed\n");
1546 FAILED(buf[4] != 8, "test19 case 5 failed\n");
1547 FAILED(buf[5] != 6, "test19 case 6 failed\n");
1548 FAILED(buf[6] != 12, "test19 case 7 failed\n");
1549 FAILED(buf[7] != 10, "test19 case 8 failed\n");
1551 sljit_free_code(code.code, NULL);
1552 successful_tests++;
1555 static void test20(void)
1557 /* Test stack. */
1558 executable_code code;
1559 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1560 struct sljit_jump* jump;
1561 struct sljit_label* label;
1562 sljit_sw buf[6];
1563 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1564 sljit_sw offset_value = SLJIT_W(0x1234567812345678);
1565 #else
1566 sljit_sw offset_value = SLJIT_W(0x12345678);
1567 #endif
1569 if (verbose)
1570 printf("Run test20\n");
1572 FAILED(!compiler, "cannot create compiler\n");
1573 buf[0] = 5;
1574 buf[1] = 12;
1575 buf[2] = 0;
1576 buf[3] = 0;
1577 buf[4] = 111;
1578 buf[5] = -12345;
1580 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 5, 5, 0, 0, 4 * sizeof(sljit_sw));
1581 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw), SLJIT_MEM1(SLJIT_S0), 0);
1582 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw));
1583 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -1);
1584 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_IMM, -1);
1585 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, -1);
1586 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S4, 0, SLJIT_IMM, -1);
1587 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));
1588 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);
1589 sljit_get_local_base(compiler, SLJIT_R0, 0, -offset_value);
1590 sljit_get_local_base(compiler, SLJIT_MEM1(SLJIT_S0), 0, -0x1234);
1591 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), 0);
1592 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));
1593 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_uw));
1594 /* Dummy last instructions. */
1595 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, 23);
1596 sljit_emit_label(compiler);
1598 code.code = sljit_generate_code(compiler);
1599 CHECK(compiler);
1600 sljit_free_compiler(compiler);
1602 FAILED(code.func1((sljit_sw)&buf) != -12345, "test20 case 1 failed\n")
1604 FAILED(buf[2] != 60, "test20 case 2 failed\n");
1605 FAILED(buf[3] != 17, "test20 case 3 failed\n");
1606 FAILED(buf[4] != 7, "test20 case 4 failed\n");
1608 sljit_free_code(code.code, NULL);
1610 compiler = sljit_create_compiler(NULL, NULL);
1611 sljit_emit_enter(compiler, 0, SLJIT_ARGS3(W, W, W, W), 3, 3, 0, 0, SLJIT_MAX_LOCAL_SIZE);
1613 sljit_get_local_base(compiler, SLJIT_R0, 0, SLJIT_MAX_LOCAL_SIZE - sizeof(sljit_sw));
1614 sljit_get_local_base(compiler, SLJIT_R1, 0, -(sljit_sw)sizeof(sljit_sw));
1615 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -1);
1616 label = sljit_emit_label(compiler);
1617 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
1618 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 0, SLJIT_R2, 0);
1619 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_R0, 0);
1620 jump = sljit_emit_jump(compiler, SLJIT_NOT_EQUAL);
1621 sljit_set_label(jump, label);
1623 /* Saved registers should keep their value. */
1624 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_S1, 0);
1625 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_S2, 0);
1626 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
1628 code.code = sljit_generate_code(compiler);
1629 CHECK(compiler);
1630 sljit_free_compiler(compiler);
1632 FAILED(code.func3(1234, 5678, 9012) != 15924, "test20 case 5 failed\n");
1634 sljit_free_code(code.code, NULL);
1636 compiler = sljit_create_compiler(NULL, NULL);
1637 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, SLJIT_ARGS0(W), 3, 0, 0, 0, SLJIT_MAX_LOCAL_SIZE);
1639 sljit_get_local_base(compiler, SLJIT_R0, 0, SLJIT_MAX_LOCAL_SIZE - sizeof(sljit_sw));
1640 sljit_get_local_base(compiler, SLJIT_R1, 0, -(sljit_sw)sizeof(sljit_sw));
1641 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -1);
1642 label = sljit_emit_label(compiler);
1643 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
1644 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 0, SLJIT_R2, 0);
1645 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_R0, 0);
1646 jump = sljit_emit_jump(compiler, SLJIT_NOT_EQUAL);
1647 sljit_set_label(jump, label);
1649 sljit_get_local_base(compiler, SLJIT_R0, 0, 0);
1650 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
1652 code.code = sljit_generate_code(compiler);
1653 CHECK(compiler);
1654 sljit_free_compiler(compiler);
1656 FAILED((sljit_uw)code.func0() % sizeof(sljit_f64) != 0, "test20 case 6 failed\n");
1658 sljit_free_code(code.code, NULL);
1659 successful_tests++;
1662 static void test21(void)
1664 /* Test set context. The parts of the jit code can be separated in the memory. */
1665 executable_code code1;
1666 executable_code code2;
1667 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1668 struct sljit_jump* jump = NULL;
1669 sljit_uw addr;
1670 sljit_sw executable_offset;
1671 sljit_sw buf[4];
1673 if (verbose)
1674 printf("Run test21\n");
1676 FAILED(!compiler, "cannot create compiler\n");
1677 buf[0] = 9;
1678 buf[1] = -6;
1679 buf[2] = 0;
1680 buf[3] = 0;
1682 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 2, 0, 0, 2 * sizeof(sljit_sw));
1684 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, 10);
1685 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_SP), 0);
1687 jump = sljit_emit_jump(compiler, SLJIT_JUMP | SLJIT_REWRITABLE_JUMP);
1688 sljit_set_target(jump, 0);
1690 code1.code = sljit_generate_code(compiler);
1691 CHECK(compiler);
1693 executable_offset = sljit_get_executable_offset(compiler);
1694 addr = sljit_get_jump_addr(jump);
1696 sljit_free_compiler(compiler);
1698 compiler = sljit_create_compiler(NULL, NULL);
1699 FAILED(!compiler, "cannot create compiler\n");
1701 /* Other part of the jit code. */
1702 sljit_set_context(compiler, 0, 1, 3, 2, 0, 0, 2 * sizeof(sljit_sw));
1704 sljit_emit_op0(compiler, SLJIT_ENDBR);
1705 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);
1706 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 3, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_MEM1(SLJIT_SP), 0);
1707 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_sw));
1709 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
1711 code2.code = sljit_generate_code(compiler);
1712 CHECK(compiler);
1713 sljit_free_compiler(compiler);
1715 sljit_set_jump_addr(addr, SLJIT_FUNC_UADDR(code2.code), executable_offset);
1717 FAILED(code1.func1((sljit_sw)&buf) != 19, "test21 case 1 failed\n");
1718 FAILED(buf[2] != -16, "test21 case 2 failed\n");
1719 FAILED(buf[3] != 100, "test21 case 3 failed\n");
1721 sljit_free_code(code1.code, NULL);
1722 sljit_free_code(code2.code, NULL);
1723 successful_tests++;
1726 static void test22(void)
1728 /* Test simple byte and half-int data transfers. */
1729 executable_code code;
1730 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1731 sljit_sw buf[4];
1732 sljit_s16 sbuf[9];
1733 sljit_s8 bbuf[5];
1735 if (verbose)
1736 printf("Run test22\n");
1738 FAILED(!compiler, "cannot create compiler\n");
1739 buf[0] = 0;
1740 buf[1] = 0;
1741 buf[2] = -1;
1742 buf[3] = -1;
1744 sbuf[0] = 0;
1745 sbuf[1] = 0;
1746 sbuf[2] = -9;
1747 sbuf[3] = 0;
1748 sbuf[4] = 0;
1749 sbuf[5] = 0;
1750 sbuf[6] = 0;
1752 bbuf[0] = 0;
1753 bbuf[1] = 0;
1754 bbuf[2] = -56;
1755 bbuf[3] = 0;
1756 bbuf[4] = 0;
1758 sljit_emit_enter(compiler, 0, SLJIT_ARGS3(VOID, P, P, P), 3, 3, 0, 0, 0);
1760 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, -13);
1761 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s16), SLJIT_IMM, 0x1234);
1762 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_s16));
1763 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
1764 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_IMM, 2 * sizeof(sljit_s16));
1765 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s16), SLJIT_MEM1(SLJIT_S1), -(sljit_sw)sizeof(sljit_s16));
1766 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xff0000 + 8000);
1767 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 2);
1768 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM2(SLJIT_S1, SLJIT_R1), 1, SLJIT_R0, 0);
1769 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R2, 0, SLJIT_S1, 0, SLJIT_IMM, 0x1234 - 3 * 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_ADD, SLJIT_R2, 0, SLJIT_S1, 0, SLJIT_IMM, 0x1234 + 4 * sizeof(sljit_s16));
1772 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_R2), -0x1234, SLJIT_IMM, -9317);
1773 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R2, 0, SLJIT_S1, 0, SLJIT_IMM, 0x12348 - 5 * sizeof(sljit_s16));
1774 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_R2), 0x12348, SLJIT_IMM, -8888);
1775 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S1, 0, SLJIT_IMM, 0x12348 + 6 * sizeof(sljit_s16));
1776 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_R2), -0x12348, SLJIT_IMM, -8888);
1778 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_MEM1(SLJIT_S2), 0, SLJIT_IMM, -45);
1779 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_s8), SLJIT_IMM, 0x12);
1780 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4 * sizeof(sljit_s8));
1781 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_s8));
1782 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_S1, 0, SLJIT_R1, 0);
1783 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_S1, 0, SLJIT_S1, 0);
1784 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R2, 0, SLJIT_S1, 0);
1785 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R2, 0);
1786 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S2), 3 * sizeof(sljit_s8), SLJIT_S1, 0);
1787 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM2(SLJIT_S2, SLJIT_R0), 0, SLJIT_R0, 0);
1788 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
1789 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_R0, 0, SLJIT_IMM, 0);
1790 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
1791 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
1792 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
1793 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_R0, 0);
1795 sljit_emit_return_void(compiler);
1797 code.code = sljit_generate_code(compiler);
1798 CHECK(compiler);
1799 sljit_free_compiler(compiler);
1801 code.func3((sljit_sw)&buf, (sljit_sw)&sbuf, (sljit_sw)&bbuf);
1802 FAILED(buf[0] != -9, "test22 case 1 failed\n");
1803 FAILED(buf[1] != -56, "test22 case 2 failed\n");
1804 FAILED(buf[2] != 0, "test22 case 3 failed\n");
1805 FAILED(buf[3] != 0, "test22 case 4 failed\n");
1807 FAILED(sbuf[0] != -13, "test22 case 5 failed\n");
1808 FAILED(sbuf[1] != 0x1234, "test22 case 6 failed\n");
1809 FAILED(sbuf[3] != 0x1234, "test22 case 7 failed\n");
1810 FAILED(sbuf[4] != 8000, "test22 case 8 failed\n");
1811 FAILED(sbuf[5] != -9317, "test22 case 9 failed\n");
1812 FAILED(sbuf[6] != -9317, "test22 case 10 failed\n");
1813 FAILED(sbuf[7] != -8888, "test22 case 11 failed\n");
1814 FAILED(sbuf[8] != -8888, "test22 case 12 failed\n");
1816 FAILED(bbuf[0] != -45, "test22 case 13 failed\n");
1817 FAILED(bbuf[1] != 0x12, "test22 case 14 failed\n");
1818 FAILED(bbuf[3] != -56, "test22 case 15 failed\n");
1819 FAILED(bbuf[4] != 4, "test22 case 16 failed\n");
1821 sljit_free_code(code.code, NULL);
1822 successful_tests++;
1825 static void test23(void)
1827 /* Test 32 bit / 64 bit signed / unsigned int transfer and conversion.
1828 This test has do real things on 64 bit systems, but works on 32 bit systems as well. */
1829 executable_code code;
1830 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1831 sljit_sw buf[9];
1832 sljit_s32 ibuf[5];
1833 union {
1834 sljit_s32 asint;
1835 sljit_u8 asbytes[4];
1836 } u;
1837 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1838 sljit_sw garbage = SLJIT_W(0x1234567812345678);
1839 #else
1840 sljit_sw garbage = 0x12345678;
1841 #endif
1843 if (verbose)
1844 printf("Run test23\n");
1846 FAILED(!compiler, "cannot create compiler\n");
1847 buf[0] = 0;
1848 buf[1] = 0;
1849 buf[2] = 0;
1850 buf[3] = 0;
1851 buf[4] = 0;
1852 buf[5] = 0;
1853 buf[6] = 0;
1854 buf[7] = 0;
1855 buf[8] = 0;
1857 ibuf[0] = 0;
1858 ibuf[1] = 0;
1859 ibuf[2] = -5791;
1860 ibuf[3] = 43579;
1861 ibuf[4] = 658923;
1863 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(W, P, P), 3, 3, 0, 0, 0);
1864 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, 34567);
1865 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4);
1866 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), 0, SLJIT_IMM, -7654);
1867 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, garbage);
1868 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_s32));
1869 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
1870 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, garbage);
1871 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_s32));
1872 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
1873 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, garbage);
1874 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_s32));
1875 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
1876 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
1877 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x0f00f00);
1878 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 0x7777);
1879 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 0x7777 + 3 * sizeof(sljit_sw), SLJIT_R0, 0);
1880 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 0x7777);
1881 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), -0x7777 + 4 * (sljit_sw)sizeof(sljit_sw), SLJIT_R0, 0);
1882 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 5 * sizeof(sljit_sw));
1883 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 1);
1884 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_R1, SLJIT_R1), 0, SLJIT_IMM, 16);
1885 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
1886 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), 1, SLJIT_IMM, 64, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), 1);
1887 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM0(), (sljit_sw)&buf[7], SLJIT_IMM, 0x123456);
1888 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), (sljit_sw)&buf[6], SLJIT_MEM0(), (sljit_sw)&buf[7]);
1889 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 5 * sizeof(sljit_sw));
1890 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R1), 2 * sizeof(sljit_sw), SLJIT_R1, 0);
1891 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S0, 0, SLJIT_IMM, 7 * sizeof(sljit_sw));
1892 sljit_emit_op2(compiler, SLJIT_LSHR, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_IMM, 1);
1893 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM2(SLJIT_R2, SLJIT_R2), 0);
1894 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[8] - 0x12340);
1895 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0x12340, SLJIT_R2, 0);
1896 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_R0), 0x12340, SLJIT_MEM1(SLJIT_R2), 3 * sizeof(sljit_sw), SLJIT_IMM, 6);
1897 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_s32), SLJIT_IMM, 0x12345678);
1898 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x2bd700 | 243);
1899 sljit_emit_return(compiler, SLJIT_MOV_S8, SLJIT_R1, 0);
1901 code.code = sljit_generate_code(compiler);
1902 CHECK(compiler);
1903 sljit_free_compiler(compiler);
1905 FAILED(code.func2((sljit_sw)&buf, (sljit_sw)&ibuf) != -13, "test23 case 1 failed\n");
1906 FAILED(buf[0] != -5791, "test23 case 2 failed\n");
1907 FAILED(buf[1] != 43579, "test23 case 3 failed\n");
1908 FAILED(buf[2] != 658923, "test23 case 4 failed\n");
1909 FAILED(buf[3] != 0x0f00f00, "test23 case 5 failed\n");
1910 FAILED(buf[4] != 0x0f00f00, "test23 case 6 failed\n");
1911 FAILED(buf[5] != 80, "test23 case 7 failed\n");
1912 FAILED(buf[6] != 0x123456, "test23 case 8 failed\n");
1913 FAILED(buf[7] != (sljit_sw)&buf[5], "test23 case 9 failed\n");
1914 FAILED(buf[8] != (sljit_sw)&buf[5] + 6, "test23 case 10 failed\n");
1916 FAILED(ibuf[0] != 34567, "test23 case 11 failed\n");
1917 FAILED(ibuf[1] != -7654, "test23 case 12 failed\n");
1918 u.asint = ibuf[4];
1919 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1920 FAILED(u.asbytes[0] != 0x78, "test23 case 13 failed\n");
1921 FAILED(u.asbytes[1] != 0x56, "test23 case 14 failed\n");
1922 FAILED(u.asbytes[2] != 0x34, "test23 case 15 failed\n");
1923 FAILED(u.asbytes[3] != 0x12, "test23 case 16 failed\n");
1924 #else
1925 FAILED(u.asbytes[0] != 0x12, "test23 case 13 failed\n");
1926 FAILED(u.asbytes[1] != 0x34, "test23 case 14 failed\n");
1927 FAILED(u.asbytes[2] != 0x56, "test23 case 15 failed\n");
1928 FAILED(u.asbytes[3] != 0x78, "test23 case 16 failed\n");
1929 #endif
1931 sljit_free_code(code.code, NULL);
1932 successful_tests++;
1935 static void test24(void)
1937 /* Some complicated addressing modes. */
1938 executable_code code;
1939 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
1940 sljit_sw buf[9];
1941 sljit_s16 sbuf[5];
1942 sljit_s8 bbuf[7];
1944 if (verbose)
1945 printf("Run test24\n");
1947 FAILED(!compiler, "cannot create compiler\n");
1949 buf[0] = 100567;
1950 buf[1] = 75799;
1951 buf[2] = 0;
1952 buf[3] = -8;
1953 buf[4] = -50;
1954 buf[5] = 0;
1955 buf[6] = 0;
1956 buf[7] = 0;
1957 buf[8] = 0;
1959 sbuf[0] = 30000;
1960 sbuf[1] = 0;
1961 sbuf[2] = 0;
1962 sbuf[3] = -12345;
1963 sbuf[4] = 0;
1965 bbuf[0] = -128;
1966 bbuf[1] = 0;
1967 bbuf[2] = 0;
1968 bbuf[3] = 99;
1969 bbuf[4] = 0;
1970 bbuf[5] = 0;
1971 bbuf[6] = 0;
1973 sljit_emit_enter(compiler, 0, SLJIT_ARGS3(VOID, P, P, P), 3, 3, 0, 0, 0);
1975 /* Nothing should be updated. */
1976 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM0(), (sljit_sw)&sbuf[1], SLJIT_MEM0(), (sljit_sw)&sbuf[0]);
1977 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_MEM0(), (sljit_sw)&bbuf[1], SLJIT_MEM0(), (sljit_sw)&bbuf[0]);
1978 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
1979 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), 1, SLJIT_MEM0(), (sljit_sw)&sbuf[3]);
1980 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[0]);
1981 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_sw));
1982 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 2);
1983 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);
1984 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_s8));
1985 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_R0), (sljit_sw)&bbuf[1], SLJIT_MEM1(SLJIT_R0), (sljit_sw)&bbuf[2]);
1987 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, sizeof(sljit_s16));
1988 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_MEM1(SLJIT_R1), (sljit_sw)&sbuf[3], SLJIT_R1, 0);
1990 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 3);
1991 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);
1992 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 4);
1993 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_S0, 0);
1994 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);
1996 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 9 * sizeof(sljit_sw));
1997 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 4 * sizeof(sljit_sw));
1998 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -(4 << SLJIT_WORD_SHIFT));
1999 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_R0, SLJIT_R2), 0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
2001 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf - 0x7fff8000 + 6 * (sljit_sw)sizeof(sljit_sw));
2002 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 952467);
2003 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0x7fff8000, SLJIT_R1, 0);
2004 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0x7fff8000 + sizeof(sljit_sw), SLJIT_MEM1(SLJIT_R0), 0x7fff8000);
2006 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf + 0x7fff7fff + 6 * (sljit_sw)sizeof(sljit_sw));
2007 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);
2008 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&bbuf - 0x7fff7ffe + 3 * (sljit_sw)sizeof(sljit_s8));
2009 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_MEM1(SLJIT_R0), 0x7fff7fff, SLJIT_MEM1(SLJIT_R0), 0x7fff7ffe);
2010 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&bbuf + 0x7fff7fff + 5 * (sljit_sw)sizeof(sljit_s8));
2011 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_MEM1(SLJIT_R0), -0x7fff7fff, SLJIT_MEM1(SLJIT_R0), -0x7fff8000);
2012 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2013 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&bbuf - SLJIT_W(0x123456123456));
2014 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)&bbuf - SLJIT_W(0x123456123456));
2015 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));
2016 #endif
2018 sljit_emit_return_void(compiler);
2020 code.code = sljit_generate_code(compiler);
2021 CHECK(compiler);
2022 sljit_free_compiler(compiler);
2024 code.func3((sljit_sw)&buf, (sljit_sw)&sbuf, (sljit_sw)&bbuf);
2025 FAILED(buf[2] != 176366, "test24 case 1 failed\n");
2026 FAILED(buf[3] != 64, "test24 case 2 failed\n");
2027 FAILED(buf[4] != -100, "test24 case 3 failed\n");
2028 FAILED(buf[5] != 100567, "test24 case 4 failed\n");
2029 FAILED(buf[6] != 952467, "test24 case 5 failed\n");
2030 FAILED(buf[7] != 952467, "test24 case 6 failed\n");
2031 FAILED(buf[8] != 952467 * 2, "test24 case 7 failed\n");
2033 FAILED(sbuf[1] != 30000, "test24 case 8 failed\n");
2034 FAILED(sbuf[2] != -12345, "test24 case 9 failed\n");
2035 FAILED(sbuf[4] != sizeof(sljit_s16), "test24 case 10 failed\n");
2037 FAILED(bbuf[1] != -128, "test24 case 11 failed\n");
2038 FAILED(bbuf[2] != 99, "test24 case 12 failed\n");
2039 FAILED(bbuf[4] != 99, "test24 case 13 failed\n");
2040 FAILED(bbuf[5] != 99, "test24 case 14 failed\n");
2041 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2042 FAILED(bbuf[6] != -128, "test24 case 15 failed\n");
2043 #endif
2045 sljit_free_code(code.code, NULL);
2046 successful_tests++;
2049 static void test25(void)
2051 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2052 /* 64 bit loads. */
2053 executable_code code;
2054 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
2055 sljit_sw buf[14];
2057 if (verbose)
2058 printf("Run test25\n");
2060 FAILED(!compiler, "cannot create compiler\n");
2061 buf[0] = 7;
2062 buf[1] = 0;
2063 buf[2] = 0;
2064 buf[3] = 0;
2065 buf[4] = 0;
2066 buf[5] = 0;
2067 buf[6] = 0;
2068 buf[7] = 0;
2069 buf[8] = 0;
2070 buf[9] = 0;
2071 buf[10] = 0;
2072 buf[11] = 0;
2073 buf[12] = 0;
2074 buf[13] = 0;
2076 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 3, 1, 0, 0, 0);
2078 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0);
2079 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 1 * sizeof(sljit_sw), SLJIT_IMM, 0x7fff);
2080 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_IMM, -0x8000);
2081 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_IMM, 0x7fffffff);
2082 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(-0x80000000));
2083 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x1234567887654321));
2084 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0xff80000000));
2085 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x3ff0000000));
2086 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_IMM, (sljit_sw)SLJIT_W(0xfffffff800100000));
2087 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_IMM, (sljit_sw)SLJIT_W(0xfffffff80010f000));
2088 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00000008001));
2089 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00080010000));
2090 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00080018001));
2091 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_IMM, SLJIT_W(0x07fff00ffff00000));
2093 sljit_emit_return_void(compiler);
2095 code.code = sljit_generate_code(compiler);
2096 CHECK(compiler);
2097 sljit_free_compiler(compiler);
2099 code.func1((sljit_sw)&buf);
2100 FAILED(buf[0] != 0, "test25 case 1 failed\n");
2101 FAILED(buf[1] != 0x7fff, "test25 case 2 failed\n");
2102 FAILED(buf[2] != -0x8000, "test25 case 3 failed\n");
2103 FAILED(buf[3] != 0x7fffffff, "test25 case 4 failed\n");
2104 FAILED(buf[4] != SLJIT_W(-0x80000000), "test25 case 5 failed\n");
2105 FAILED(buf[5] != SLJIT_W(0x1234567887654321), "test25 case 6 failed\n");
2106 FAILED(buf[6] != SLJIT_W(0xff80000000), "test25 case 7 failed\n");
2107 FAILED(buf[7] != SLJIT_W(0x3ff0000000), "test25 case 8 failed\n");
2108 FAILED((sljit_uw)buf[8] != SLJIT_W(0xfffffff800100000), "test25 case 9 failed\n");
2109 FAILED((sljit_uw)buf[9] != SLJIT_W(0xfffffff80010f000), "test25 case 10 failed\n");
2110 FAILED(buf[10] != SLJIT_W(0x07fff00000008001), "test25 case 11 failed\n");
2111 FAILED(buf[11] != SLJIT_W(0x07fff00080010000), "test25 case 12 failed\n");
2112 FAILED(buf[12] != SLJIT_W(0x07fff00080018001), "test25 case 13 failed\n");
2113 FAILED(buf[13] != SLJIT_W(0x07fff00ffff00000), "test25 case 14 failed\n");
2115 sljit_free_code(code.code, NULL);
2116 #endif
2117 successful_tests++;
2120 static void test26(void)
2122 /* Aligned access without aligned offsets. */
2123 executable_code code;
2124 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
2125 sljit_sw buf[4];
2126 sljit_s32 ibuf[4];
2127 sljit_f64 dbuf[4];
2129 if (verbose)
2130 printf("Run test26\n");
2132 FAILED(!compiler, "cannot create compiler\n");
2134 buf[0] = -2789;
2135 buf[1] = 0;
2136 buf[2] = 4;
2137 buf[3] = -4;
2139 ibuf[0] = -689;
2140 ibuf[1] = 0;
2141 ibuf[2] = -6;
2142 ibuf[3] = 3;
2144 dbuf[0] = 5.75;
2145 dbuf[1] = 0.0;
2146 dbuf[2] = 0.0;
2147 dbuf[3] = -4.0;
2149 sljit_emit_enter(compiler, 0, SLJIT_ARGS3(VOID, P, P, P), 3, 3, 0, 0, 0);
2151 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 3);
2152 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S1, 0, SLJIT_S1, 0, SLJIT_IMM, 1);
2153 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), -3);
2154 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32) - 1, SLJIT_R0, 0);
2155 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), -1);
2156 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) - 3, SLJIT_R0, 0);
2158 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 100);
2159 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);
2160 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_IMM, 100);
2161 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);
2163 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
2164 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S2, 0, SLJIT_S2, 0, SLJIT_IMM, 3);
2165 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f64) - 3, SLJIT_MEM1(SLJIT_S2), -3);
2166 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);
2167 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S2, 0, SLJIT_IMM, 2);
2168 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sizeof(sljit_f64) * 3 - 4) >> 1);
2169 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, 1);
2170 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);
2173 sljit_emit_return_void(compiler);
2175 code.code = sljit_generate_code(compiler);
2176 CHECK(compiler);
2177 sljit_free_compiler(compiler);
2179 code.func3((sljit_sw)&buf, (sljit_sw)&ibuf, (sljit_sw)&dbuf);
2181 FAILED(buf[1] != -689, "test26 case 1 failed\n");
2182 FAILED(buf[2] != -16, "test26 case 2 failed\n");
2183 FAILED(ibuf[1] != -2789, "test26 case 3 failed\n");
2184 FAILED(ibuf[2] != -18, "test26 case 4 failed\n");
2186 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
2187 FAILED(dbuf[1] != 5.75, "test26 case 5 failed\n");
2188 FAILED(dbuf[2] != 11.5, "test26 case 6 failed\n");
2189 FAILED(dbuf[3] != -2.875, "test26 case 7 failed\n");
2192 sljit_free_code(code.code, NULL);
2193 successful_tests++;
2196 static void test27(void)
2198 #define SET_NEXT_BYTE(type) \
2199 cond_set(compiler, SLJIT_R2, 0, type); \
2200 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R2, 0); \
2201 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
2202 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2203 #define RESULT(i) i
2204 #else
2205 #define RESULT(i) (3 - i)
2206 #endif
2208 /* Playing with conditional flags. */
2209 executable_code code;
2210 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
2211 sljit_u8 buf[41];
2212 sljit_u32 i;
2213 #ifdef SLJIT_PREF_SHIFT_REG
2214 sljit_s32 shift_reg = SLJIT_PREF_SHIFT_REG;
2215 #else
2216 sljit_s32 shift_reg = SLJIT_R2;
2217 #endif
2219 SLJIT_ASSERT(shift_reg >= SLJIT_R2 && shift_reg <= SLJIT_R3);
2221 if (verbose)
2222 printf("Run test27\n");
2224 for (i = 0; i < sizeof(buf); ++i)
2225 buf[i] = 10;
2227 FAILED(!compiler, "cannot create compiler\n");
2229 /* 3 arguments passed, 3 arguments used. */
2230 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 4, 3, 0, 0, 0);
2232 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
2234 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x1001);
2235 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 20);
2236 /* 0x100100000 on 64 bit machines, 0x100000 on 32 bit machines. */
2237 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x800000);
2238 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_R0, 0, SLJIT_R1, 0);
2239 sljit_emit_op0(compiler, SLJIT_ENDBR); /* ENDBR should keep the flags. */
2240 sljit_emit_op0(compiler, SLJIT_NOP); /* Nop should keep the flags. */
2241 SET_NEXT_BYTE(SLJIT_GREATER);
2242 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
2243 SET_NEXT_BYTE(SLJIT_LESS);
2244 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
2245 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_R1, 0);
2246 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_GREATER, SLJIT_R0, 0, SLJIT_R1, 0);
2247 sljit_emit_op0(compiler, SLJIT_ENDBR); /* ENDBR should keep the flags. */
2248 sljit_emit_op0(compiler, SLJIT_NOP); /* Nop should keep the flags. */
2249 SET_NEXT_BYTE(SLJIT_GREATER);
2250 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
2251 SET_NEXT_BYTE(SLJIT_LESS);
2253 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x1000);
2254 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 20);
2255 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0x10);
2256 /* 0x100000010 on 64 bit machines, 0x10 on 32 bit machines. */
2257 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_R0, 0, SLJIT_IMM, 0x80);
2258 SET_NEXT_BYTE(SLJIT_GREATER);
2259 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_R0, 0, SLJIT_IMM, 0x80);
2260 SET_NEXT_BYTE(SLJIT_LESS);
2261 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
2262 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_GREATER, SLJIT_R0, 0, SLJIT_IMM, 0x80);
2263 SET_NEXT_BYTE(SLJIT_GREATER);
2264 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_LESS, SLJIT_R0, 0, SLJIT_IMM, 0x80);
2265 SET_NEXT_BYTE(SLJIT_LESS);
2267 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2268 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2269 /* 0xff..ff on all machines. */
2270 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS_EQUAL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2271 SET_NEXT_BYTE(SLJIT_LESS_EQUAL);
2272 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
2273 SET_NEXT_BYTE(SLJIT_GREATER_EQUAL);
2274 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_R2, 0, SLJIT_R1, 0, SLJIT_IMM, -1);
2275 SET_NEXT_BYTE(SLJIT_SIG_GREATER);
2276 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, -1);
2277 SET_NEXT_BYTE(SLJIT_SIG_LESS);
2278 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R2, 0, SLJIT_R1, 0, SLJIT_R0, 0);
2279 SET_NEXT_BYTE(SLJIT_EQUAL);
2280 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_R0, 0);
2281 SET_NEXT_BYTE(SLJIT_NOT_EQUAL);
2282 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, -2);
2283 SET_NEXT_BYTE(SLJIT_OVERFLOW);
2284 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, -2);
2285 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW);
2286 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, -2);
2287 SET_NEXT_BYTE(SLJIT_GREATER_EQUAL);
2288 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, -2);
2289 SET_NEXT_BYTE(SLJIT_LESS_EQUAL);
2290 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)((sljit_uw)1 << ((8 * sizeof(sljit_uw)) - 1)));
2291 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, 1);
2292 SET_NEXT_BYTE(SLJIT_SIG_LESS);
2293 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, -1);
2294 SET_NEXT_BYTE(SLJIT_SIG_GREATER);
2295 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_R1, 0, SLJIT_IMM, 1);
2296 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, -2);
2297 SET_NEXT_BYTE(SLJIT_SIG_GREATER_EQUAL);
2298 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 2);
2299 SET_NEXT_BYTE(SLJIT_SIG_GREATER);
2301 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)0x80000000);
2302 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 16);
2303 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 16);
2304 /* 0x80..0 on 64 bit machines, 0 on 32 bit machines. */
2305 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)0xffffffff);
2306 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R1, 0);
2307 SET_NEXT_BYTE(SLJIT_OVERFLOW);
2308 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R1, 0);
2309 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW);
2310 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
2311 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R1, 0, SLJIT_R1, 0);
2312 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R1, 0);
2313 SET_NEXT_BYTE(SLJIT_OVERFLOW);
2314 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R1, 0);
2315 SET_NEXT_BYTE(SLJIT_NOT_OVERFLOW);
2317 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2318 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_IMM, 1);
2319 sljit_emit_op2u(compiler, SLJIT_SUBC | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_IMM, 0);
2320 sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_R0, 0, SLJIT_IMM, 6, SLJIT_R0, 0);
2321 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R0, 0);
2322 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
2324 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
2325 sljit_emit_op2u(compiler, SLJIT_ADD | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_IMM, 1);
2326 sljit_emit_op2u(compiler, SLJIT_ADDC | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_IMM, 1);
2327 sljit_emit_op2(compiler, SLJIT_ADDC, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 9);
2328 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R0, 0);
2329 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
2331 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
2332 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, (8 * sizeof(sljit_sw)) - 1);
2333 sljit_emit_op2u(compiler, SLJIT_ADD | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_IMM, 0);
2334 SET_NEXT_BYTE(SLJIT_EQUAL);
2335 sljit_emit_op2u(compiler, SLJIT_ADD | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0);
2336 SET_NEXT_BYTE(SLJIT_EQUAL);
2338 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2339 sljit_emit_op2(compiler, SLJIT_ASHR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0);
2340 SET_NEXT_BYTE(SLJIT_EQUAL);
2341 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
2342 sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffffc0);
2343 SET_NEXT_BYTE(SLJIT_NOT_EQUAL);
2344 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 0);
2345 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2346 sljit_emit_op2(compiler, SLJIT_ASHR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0, shift_reg, 0);
2347 SET_NEXT_BYTE(SLJIT_EQUAL);
2348 sljit_emit_op1(compiler, SLJIT_MOV, shift_reg, 0, SLJIT_IMM, 0);
2349 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
2350 sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R0, 0, shift_reg, 0);
2351 SET_NEXT_BYTE(SLJIT_NOT_EQUAL);
2353 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
2354 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
2355 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_R0, 0);
2356 sljit_emit_op2(compiler, SLJIT_SUBC | SLJIT_SET_CARRY, SLJIT_R2, 0, SLJIT_IMM, 1, SLJIT_R0, 0);
2357 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_R2, 0);
2358 sljit_emit_op2u(compiler, SLJIT_SUBC | SLJIT_SET_CARRY, SLJIT_R0, 0, SLJIT_R1, 0);
2359 sljit_emit_op2(compiler, SLJIT_SUBC, SLJIT_R2, 0, SLJIT_IMM, 1, SLJIT_R0, 0);
2360 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 2, SLJIT_R2, 0);
2361 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 2);
2363 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -34);
2364 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_R0, 0, SLJIT_IMM, 0x1234);
2365 SET_NEXT_BYTE(SLJIT_LESS);
2366 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R0, 0, SLJIT_IMM, 0x1234);
2367 SET_NEXT_BYTE(SLJIT_SIG_LESS);
2368 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2369 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x12300000000) - 43);
2370 #else
2371 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, -43);
2372 #endif
2373 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -96);
2374 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
2375 SET_NEXT_BYTE(SLJIT_LESS);
2376 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_SIG_GREATER, SLJIT_R0, 0, SLJIT_R1, 0);
2377 SET_NEXT_BYTE(SLJIT_SIG_GREATER);
2379 sljit_emit_return_void(compiler);
2381 code.code = sljit_generate_code(compiler);
2382 CHECK(compiler);
2383 sljit_free_compiler(compiler);
2385 code.func1((sljit_sw)&buf);
2387 FAILED(buf[0] != RESULT(1), "test27 case 1 failed\n");
2388 FAILED(buf[1] != RESULT(2), "test27 case 2 failed\n");
2389 FAILED(buf[2] != 2, "test27 case 3 failed\n");
2390 FAILED(buf[3] != 1, "test27 case 4 failed\n");
2391 FAILED(buf[4] != RESULT(1), "test27 case 5 failed\n");
2392 FAILED(buf[5] != RESULT(2), "test27 case 6 failed\n");
2393 FAILED(buf[6] != 2, "test27 case 7 failed\n");
2394 FAILED(buf[7] != 1, "test27 case 8 failed\n");
2396 FAILED(buf[8] != 2, "test27 case 9 failed\n");
2397 FAILED(buf[9] != 1, "test27 case 10 failed\n");
2398 FAILED(buf[10] != 2, "test27 case 11 failed\n");
2399 FAILED(buf[11] != 1, "test27 case 12 failed\n");
2400 FAILED(buf[12] != 1, "test27 case 13 failed\n");
2401 FAILED(buf[13] != 2, "test27 case 14 failed\n");
2402 FAILED(buf[14] != 2, "test27 case 15 failed\n");
2403 FAILED(buf[15] != 1, "test27 case 16 failed\n");
2404 FAILED(buf[16] != 1, "test27 case 17 failed\n");
2405 FAILED(buf[17] != 2, "test27 case 18 failed\n");
2406 FAILED(buf[18] != 1, "test27 case 19 failed\n");
2407 FAILED(buf[19] != 1, "test27 case 20 failed\n");
2408 FAILED(buf[20] != 1, "test27 case 21 failed\n");
2409 FAILED(buf[21] != 2, "test27 case 22 failed\n");
2411 FAILED(buf[22] != RESULT(1), "test27 case 23 failed\n");
2412 FAILED(buf[23] != RESULT(2), "test27 case 24 failed\n");
2413 FAILED(buf[24] != 2, "test27 case 25 failed\n");
2414 FAILED(buf[25] != 1, "test27 case 26 failed\n");
2416 FAILED(buf[26] != 5, "test27 case 27 failed\n");
2417 FAILED(buf[27] != 9, "test27 case 28 failed\n");
2419 FAILED(buf[28] != 2, "test27 case 29 failed\n");
2420 FAILED(buf[29] != 1, "test27 case 30 failed\n");
2422 FAILED(buf[30] != 1, "test27 case 31 failed\n");
2423 FAILED(buf[31] != 1, "test27 case 32 failed\n");
2424 FAILED(buf[32] != 1, "test27 case 33 failed\n");
2425 FAILED(buf[33] != 1, "test27 case 34 failed\n");
2427 FAILED(buf[34] != 1, "test27 case 35 failed\n");
2428 FAILED(buf[35] != 0, "test27 case 36 failed\n");
2430 FAILED(buf[36] != 2, "test27 case 37 failed\n");
2431 FAILED(buf[37] != 1, "test27 case 38 failed\n");
2432 FAILED(buf[38] != 2, "test27 case 39 failed\n");
2433 FAILED(buf[39] != 1, "test27 case 40 failed\n");
2434 FAILED(buf[40] != 10, "test27 case 41 failed\n");
2436 sljit_free_code(code.code, NULL);
2437 successful_tests++;
2438 #undef SET_NEXT_BYTE
2439 #undef RESULT
2442 static void test28(void)
2444 /* Test mov. */
2445 executable_code code;
2446 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
2447 struct sljit_const* const1 = NULL;
2448 struct sljit_label* label = NULL;
2449 sljit_uw label_addr = 0;
2450 sljit_sw buf[5];
2452 if (verbose)
2453 printf("Run test28\n");
2455 FAILED(!compiler, "cannot create compiler\n");
2457 buf[0] = -36;
2458 buf[1] = 8;
2459 buf[2] = 0;
2460 buf[3] = 10;
2461 buf[4] = 0;
2463 FAILED(!compiler, "cannot create compiler\n");
2464 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 5, 5, 0, 0, 0);
2465 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -234);
2466 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw));
2467 sljit_emit_op2(compiler, SLJIT_MUL, SLJIT_S3, 0, SLJIT_R3, 0, SLJIT_R4, 0);
2468 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_S3, 0);
2469 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_S3, 0, SLJIT_IMM, 0);
2470 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_NOT_ZERO);
2471 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_S3, 0);
2472 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S4, 0, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw));
2473 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S4, 0, SLJIT_S4, 0, SLJIT_R4, 0);
2474 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_S4, 0);
2476 const1 = sljit_emit_const(compiler, SLJIT_S3, 0, 0);
2477 sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_S3, 0);
2478 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S3, 0, SLJIT_S3, 0, SLJIT_IMM, 100);
2479 label = sljit_emit_label(compiler);
2480 sljit_emit_op0(compiler, SLJIT_ENDBR);
2481 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_S3, 0);
2483 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R4, 0);
2485 code.code = sljit_generate_code(compiler);
2486 CHECK(compiler);
2488 label_addr = sljit_get_label_addr(label);
2489 sljit_set_const(sljit_get_const_addr(const1), (sljit_sw)label_addr, sljit_get_executable_offset(compiler));
2491 sljit_free_compiler(compiler);
2493 FAILED(code.func1((sljit_sw)&buf) != 8, "test28 case 1 failed\n");
2494 FAILED(buf[1] != -1872, "test28 case 2 failed\n");
2495 FAILED(buf[2] != 1, "test28 case 3 failed\n");
2496 FAILED(buf[3] != 2, "test28 case 4 failed\n");
2497 FAILED(buf[4] != (sljit_sw)label_addr, "test28 case 5 failed\n");
2499 sljit_free_code(code.code, NULL);
2500 successful_tests++;
2503 static void test29(void)
2505 /* Test signed/unsigned bytes and halfs. */
2506 executable_code code;
2507 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
2508 sljit_sw buf[25];
2509 sljit_s32 i;
2511 if (verbose)
2512 printf("Run test29\n");
2514 for (i = 0; i < 25; i++)
2515 buf[i] = 0;
2517 FAILED(!compiler, "cannot create compiler\n");
2518 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 5, 5, 0, 0, 0);
2520 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R0, 0, SLJIT_IMM, -187);
2521 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
2522 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R0, 0, SLJIT_IMM, -605);
2523 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_R0, 0);
2524 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R0, 0, SLJIT_IMM, -56);
2525 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_uw), SLJIT_R0, 0);
2526 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R4, 0, SLJIT_IMM, 0xcde5);
2527 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_uw), SLJIT_R4, 0);
2529 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_R0, 0, SLJIT_IMM, -45896);
2530 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_uw), SLJIT_R0, 0);
2531 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_R0, 0, SLJIT_IMM, -1472797);
2532 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_uw), SLJIT_R0, 0);
2533 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_R0, 0, SLJIT_IMM, -12890);
2534 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_uw), SLJIT_R0, 0);
2535 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_R4, 0, SLJIT_IMM, 0x9cb0a6);
2536 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_uw), SLJIT_R4, 0);
2538 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2539 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-3580429715));
2540 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_uw), SLJIT_R0, 0);
2541 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-100722768662));
2542 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_uw), SLJIT_R0, 0);
2543 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-1457052677972));
2544 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_uw), SLJIT_R0, 0);
2545 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R4, 0, SLJIT_IMM, SLJIT_W(0xcef97a70b5));
2546 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_uw), SLJIT_R4, 0);
2547 #endif
2549 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -187);
2550 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R0, 0, SLJIT_R1, 0);
2551 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_uw), SLJIT_R0, 0);
2552 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, -605);
2553 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_R0, 0, SLJIT_S2, 0);
2554 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_uw), SLJIT_R0, 0);
2555 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -56);
2556 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R0, 0, SLJIT_R2, 0);
2557 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_uw), SLJIT_R0, 0);
2558 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0xcde5);
2559 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R4, 0, SLJIT_R3, 0);
2560 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 15 * sizeof(sljit_uw), SLJIT_R4, 0);
2562 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -45896);
2563 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_R0, 0, SLJIT_R1, 0);
2564 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 16 * sizeof(sljit_uw), SLJIT_R0, 0);
2565 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, -1472797);
2566 sljit_emit_op1(compiler, SLJIT_MOV_S16, SLJIT_R0, 0, SLJIT_S2, 0);
2567 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 17 * sizeof(sljit_uw), SLJIT_R0, 0);
2568 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -12890);
2569 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_R0, 0, SLJIT_R2, 0);
2570 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_uw), SLJIT_R0, 0);
2571 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0x9cb0a6);
2572 sljit_emit_op1(compiler, SLJIT_MOV_U16, SLJIT_R4, 0, SLJIT_R3, 0);
2573 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 19 * sizeof(sljit_uw), SLJIT_R4, 0);
2575 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2576 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(-3580429715));
2577 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R1, 0);
2578 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 20 * sizeof(sljit_uw), SLJIT_R0, 0);
2579 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, SLJIT_W(-100722768662));
2580 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_S2, 0);
2581 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 21 * sizeof(sljit_uw), SLJIT_R0, 0);
2582 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, SLJIT_W(-1457052677972));
2583 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R2, 0);
2584 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 22 * sizeof(sljit_uw), SLJIT_R0, 0);
2585 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, SLJIT_W(0xcef97a70b5));
2586 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R4, 0, SLJIT_R3, 0);
2587 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 23 * sizeof(sljit_uw), SLJIT_R4, 0);
2588 #endif
2590 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, 0x9faa5);
2591 sljit_emit_op1(compiler, SLJIT_MOV_S8, SLJIT_S2, 0, SLJIT_S2, 0);
2592 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 24 * sizeof(sljit_uw), SLJIT_S2, 0);
2594 sljit_emit_return_void(compiler);
2596 code.code = sljit_generate_code(compiler);
2597 CHECK(compiler);
2598 sljit_free_compiler(compiler);
2600 code.func1((sljit_sw)&buf);
2601 FAILED(buf[0] != 69, "test29 case 1 failed\n");
2602 FAILED(buf[1] != -93, "test29 case 2 failed\n");
2603 FAILED(buf[2] != 200, "test29 case 3 failed\n");
2604 FAILED(buf[3] != 0xe5, "test29 case 4 failed\n");
2605 FAILED(buf[4] != 19640, "test29 case 5 failed\n");
2606 FAILED(buf[5] != -31005, "test29 case 6 failed\n");
2607 FAILED(buf[6] != 52646, "test29 case 7 failed\n");
2608 FAILED(buf[7] != 0xb0a6, "test29 case 8 failed\n");
2610 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2611 FAILED(buf[8] != SLJIT_W(714537581), "test29 case 9 failed\n");
2612 FAILED(buf[9] != SLJIT_W(-1938520854), "test29 case 10 failed\n");
2613 FAILED(buf[10] != SLJIT_W(3236202668), "test29 case 11 failed\n");
2614 FAILED(buf[11] != SLJIT_W(0xf97a70b5), "test29 case 12 failed\n");
2615 #endif
2617 FAILED(buf[12] != 69, "test29 case 13 failed\n");
2618 FAILED(buf[13] != -93, "test29 case 14 failed\n");
2619 FAILED(buf[14] != 200, "test29 case 15 failed\n");
2620 FAILED(buf[15] != 0xe5, "test29 case 16 failed\n");
2621 FAILED(buf[16] != 19640, "test29 case 17 failed\n");
2622 FAILED(buf[17] != -31005, "test29 case 18 failed\n");
2623 FAILED(buf[18] != 52646, "test29 case 19 failed\n");
2624 FAILED(buf[19] != 0xb0a6, "test29 case 20 failed\n");
2626 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2627 FAILED(buf[20] != SLJIT_W(714537581), "test29 case 21 failed\n");
2628 FAILED(buf[21] != SLJIT_W(-1938520854), "test29 case 22 failed\n");
2629 FAILED(buf[22] != SLJIT_W(3236202668), "test29 case 23 failed\n");
2630 FAILED(buf[23] != SLJIT_W(0xf97a70b5), "test29 case 24 failed\n");
2631 #endif
2633 FAILED(buf[24] != -91, "test29 case 25 failed\n");
2635 sljit_free_code(code.code, NULL);
2636 successful_tests++;
2639 static void test30(void)
2641 /* Test unused results. */
2642 executable_code code;
2643 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
2644 sljit_sw buf[1];
2646 if (verbose)
2647 printf("Run test30\n");
2649 FAILED(!compiler, "cannot create compiler\n");
2650 buf[0] = 0;
2651 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 5, 5, 0, 0, 0);
2653 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
2654 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
2655 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 1);
2656 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 1);
2657 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_IMM, 1);
2658 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2659 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_S1, 0, SLJIT_IMM, SLJIT_W(-0x123ffffffff));
2660 #else
2661 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_S1, 0, SLJIT_IMM, 1);
2662 #endif
2663 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, 1);
2664 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, 1);
2665 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S4, 0, SLJIT_IMM, 1);
2667 /* Some calculations with unused results. */
2668 sljit_emit_op2u(compiler, SLJIT_ADD | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0);
2669 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_GREATER_EQUAL, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM1(SLJIT_S0), 0);
2670 sljit_emit_op2u(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_S0, 0, SLJIT_MEM1(SLJIT_S0), 0);
2671 sljit_emit_op2u(compiler, SLJIT_SHL | SLJIT_SET_Z, SLJIT_S3, 0, SLJIT_R2, 0);
2672 sljit_emit_op2u(compiler, SLJIT_LSHR | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 5);
2673 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, 0xff);
2675 /* Testing that any change happens. */
2676 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2677 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R2, 0);
2678 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R3, 0);
2679 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R4, 0);
2680 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_S1, 0, SLJIT_S1, 0);
2681 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S1, 0);
2682 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S2, 0);
2683 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S3, 0);
2684 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0, SLJIT_S4, 0);
2686 sljit_emit_return_void(compiler);
2688 code.code = sljit_generate_code(compiler);
2689 CHECK(compiler);
2690 sljit_free_compiler(compiler);
2692 code.func1((sljit_sw)&buf);
2693 FAILED(buf[0] != 9, "test30 case 1 failed\n");
2695 sljit_free_code(code.code, NULL);
2696 successful_tests++;
2699 static void test31(void)
2701 /* Integer mul and set flags. */
2702 executable_code code;
2703 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
2704 sljit_sw buf[12];
2705 sljit_s32 i;
2706 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2707 sljit_sw big_word = SLJIT_W(0x7fffffff00000000);
2708 sljit_sw big_word2 = SLJIT_W(0x7fffffff00000012);
2709 #else
2710 sljit_sw big_word = 0x7fffffff;
2711 sljit_sw big_word2 = 0x00000012;
2712 #endif
2714 if (verbose)
2715 printf("Run test31\n");
2717 for (i = 0; i < 12; i++)
2718 buf[i] = 3;
2720 FAILED(!compiler, "cannot create compiler\n");
2722 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 3, 5, 0, 0, 0);
2723 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
2724 sljit_emit_op2u(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_IMM, -45);
2725 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_NOT_OVERFLOW);
2726 sljit_emit_op2u(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_IMM, -45);
2727 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_OVERFLOW);
2729 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, big_word);
2730 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, -2);
2731 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 33); /* Should not change flags. */
2732 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0); /* Should not change flags. */
2733 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_OVERFLOW);
2734 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, -2);
2735 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_NOT_OVERFLOW);
2737 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_S3, 0, SLJIT_IMM, 0x3f6b0);
2738 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_S4, 0, SLJIT_IMM, 0x2a783);
2739 sljit_emit_op2(compiler, SLJIT_MUL32 | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_S3, 0, SLJIT_S4, 0);
2740 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_OVERFLOW);
2741 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R1, 0);
2743 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, big_word2);
2744 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R2, 0, SLJIT_R1, 0);
2745 sljit_emit_op2(compiler, SLJIT_MUL32 | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 23);
2746 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_OVERFLOW);
2748 sljit_emit_op2u(compiler, SLJIT_MUL32 | SLJIT_SET_OVERFLOW, SLJIT_R2, 0, SLJIT_IMM, -23);
2749 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_NOT_OVERFLOW);
2750 sljit_emit_op2u(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_R2, 0, SLJIT_IMM, -23);
2751 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_NOT_OVERFLOW);
2753 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 67);
2754 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, -23);
2755 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_R1, 0);
2757 sljit_emit_return_void(compiler);
2759 code.code = sljit_generate_code(compiler);
2760 CHECK(compiler);
2761 sljit_free_compiler(compiler);
2763 code.func1((sljit_sw)&buf);
2765 FAILED(buf[0] != 1, "test31 case 1 failed\n");
2766 FAILED(buf[1] != 2, "test31 case 2 failed\n");
2767 /* Qemu issues for 64 bit muls. */
2768 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2769 FAILED(buf[2] != 1, "test31 case 3 failed\n");
2770 FAILED(buf[3] != 2, "test31 case 4 failed\n");
2771 #endif
2772 FAILED(buf[4] != 1, "test31 case 5 failed\n");
2773 FAILED((buf[5] & (sljit_sw)0xffffffff) != (sljit_sw)0x85540c10, "test31 case 6 failed\n");
2774 FAILED(buf[6] != 2, "test31 case 7 failed\n");
2775 FAILED(buf[7] != 1, "test31 case 8 failed\n");
2776 #if !(defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2777 FAILED(buf[8] != 1, "test31 case 9 failed\n");
2778 #endif
2779 FAILED(buf[9] != -1541, "test31 case 10 failed\n");
2781 sljit_free_code(code.code, NULL);
2782 successful_tests++;
2785 static void test32(void)
2787 /* Floating point set flags. */
2788 executable_code code;
2789 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
2790 sljit_s32 i;
2792 sljit_sw buf[16];
2793 union {
2794 sljit_f64 value;
2795 struct {
2796 sljit_s32 value1;
2797 sljit_s32 value2;
2798 } u;
2799 } dbuf[4];
2801 if (verbose)
2802 printf("Run test32\n");
2804 for (i = 0; i < 16; i++)
2805 buf[i] = 5;
2807 /* Two NaNs */
2808 dbuf[0].u.value1 = 0x7fffffff;
2809 dbuf[0].u.value2 = 0x7fffffff;
2810 dbuf[1].u.value1 = 0x7fffffff;
2811 dbuf[1].u.value2 = 0x7fffffff;
2812 dbuf[2].value = -13.0;
2813 dbuf[3].value = 27.0;
2815 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
2816 if (verbose)
2817 printf("no fpu available, test32 skipped\n");
2818 successful_tests++;
2819 if (compiler)
2820 sljit_free_compiler(compiler);
2821 return;
2824 FAILED(!compiler, "cannot create compiler\n");
2825 SLJIT_ASSERT(sizeof(sljit_f64) == 8 && sizeof(sljit_s32) == 4 && sizeof(dbuf[0]) == 8);
2827 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(VOID, P, P), 1, 2, 4, 0, 0);
2829 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), 0);
2830 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_UNORDERED_F, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64), SLJIT_FR0, 0);
2831 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f64));
2832 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_UNORDERED_F64);
2833 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_ORDERED_F, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64), SLJIT_FR0, 0);
2834 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_ORDERED_F64);
2836 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64));
2837 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_UNORDERED_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2838 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_UNORDERED_F64);
2839 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_ORDERED_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2840 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_ORDERED_F64);
2841 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_LESS_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2842 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_LESS_F64);
2843 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_GREATER_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2844 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_GREATER_EQUAL_F64);
2845 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_GREATER_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2846 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_GREATER_F64);
2847 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_LESS_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2848 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_LESS_EQUAL_F64);
2849 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2850 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_EQUAL_F64);
2851 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_NOT_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
2852 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_NOT_EQUAL_F64);
2854 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR3, 0, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f64));
2855 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_UNORDERED_F, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64));
2856 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_UNORDERED_F64);
2857 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_EQUAL_F, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64));
2858 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_EQUAL_F64);
2860 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_ORDERED_F, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f64), SLJIT_FR0, 0);
2861 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_ORDERED_F64);
2863 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | SLJIT_SET_UNORDERED_F, SLJIT_FR3, 0, SLJIT_FR2, 0);
2864 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), 0);
2865 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_UNORDERED_F64);
2867 sljit_emit_return_void(compiler);
2869 code.code = sljit_generate_code(compiler);
2870 CHECK(compiler);
2871 sljit_free_compiler(compiler);
2873 code.func2((sljit_sw)&buf, (sljit_sw)&dbuf);
2875 FAILED(buf[0] != 1, "test32 case 1 failed\n");
2876 FAILED(buf[1] != 2, "test32 case 2 failed\n");
2877 FAILED(buf[2] != 2, "test32 case 3 failed\n");
2878 FAILED(buf[3] != 1, "test32 case 4 failed\n");
2879 FAILED(buf[4] != 1, "test32 case 5 failed\n");
2880 FAILED(buf[5] != 2, "test32 case 6 failed\n");
2881 FAILED(buf[6] != 2, "test32 case 7 failed\n");
2882 FAILED(buf[7] != 1, "test32 case 8 failed\n");
2883 FAILED(buf[8] != 2, "test32 case 9 failed\n");
2884 FAILED(buf[9] != 1, "test32 case 10 failed\n");
2885 FAILED(buf[10] != 2, "test32 case 11 failed\n");
2886 FAILED(buf[11] != 1, "test32 case 12 failed\n");
2887 FAILED(buf[12] != 2, "test32 case 13 failed\n");
2888 FAILED(buf[13] != 1, "test32 case 14 failed\n");
2890 sljit_free_code(code.code, NULL);
2891 successful_tests++;
2894 static void test33(void)
2896 /* Test setting multiple flags. */
2897 executable_code code;
2898 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
2899 struct sljit_jump* jump;
2900 sljit_sw buf[10];
2902 if (verbose)
2903 printf("Run test33\n");
2905 buf[0] = 3;
2906 buf[1] = 3;
2907 buf[2] = 3;
2908 buf[3] = 3;
2909 buf[4] = 3;
2910 buf[5] = 3;
2911 buf[6] = 3;
2912 buf[7] = 3;
2913 buf[8] = 3;
2914 buf[9] = 3;
2916 FAILED(!compiler, "cannot create compiler\n");
2918 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 3, 3, 0, 0, 0);
2920 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 20);
2921 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 10);
2922 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2923 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_ZERO);
2924 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -10);
2925 jump = sljit_emit_jump(compiler, SLJIT_LESS);
2926 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_IMM, 11);
2927 sljit_set_label(jump, sljit_emit_label(compiler));
2929 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_SIG_GREATER, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2930 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_SIG_GREATER);
2931 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_IMM, 45);
2932 jump = sljit_emit_jump(compiler, SLJIT_NOT_EQUAL);
2933 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_IMM, 55);
2934 sljit_set_label(jump, sljit_emit_label(compiler));
2936 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2937 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)SLJIT_W(0x8000000000000000));
2938 #else
2939 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)SLJIT_W(0x80000000));
2940 #endif
2941 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1);
2942 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2943 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_IMM, 33);
2944 jump = sljit_emit_jump(compiler, SLJIT_NOT_OVERFLOW);
2945 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_ZERO);
2946 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_IMM, 13);
2947 sljit_set_label(jump, sljit_emit_label(compiler));
2949 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)0x80000000);
2950 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_R0, 0);
2951 sljit_emit_op2(compiler, SLJIT_SUB32 | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2952 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 0);
2953 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_NOT_ZERO);
2954 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_IMM, 78);
2955 jump = sljit_emit_jump(compiler, SLJIT_OVERFLOW);
2956 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_IMM, 48);
2957 sljit_set_label(jump, sljit_emit_label(compiler));
2959 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2960 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)SLJIT_W(0x8000000000000000));
2961 #else
2962 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)SLJIT_W(0x80000000));
2963 #endif
2964 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_R0, 0);
2965 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_Z | SLJIT_SET_OVERFLOW, SLJIT_R2, 0, SLJIT_R0, 0, SLJIT_R1, 0);
2966 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_IMM, 30);
2967 jump = sljit_emit_jump(compiler, SLJIT_NOT_OVERFLOW);
2968 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_IMM, 50);
2969 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_ZERO);
2970 sljit_set_label(jump, sljit_emit_label(compiler));
2972 sljit_emit_return_void(compiler);
2974 code.code = sljit_generate_code(compiler);
2975 CHECK(compiler);
2976 sljit_free_compiler(compiler);
2978 code.func1((sljit_sw)&buf);
2980 FAILED(buf[0] != 0, "test33 case 1 failed\n");
2981 FAILED(buf[1] != 11, "test33 case 2 failed\n");
2982 FAILED(buf[2] != 1, "test33 case 3 failed\n");
2983 FAILED(buf[3] != 45, "test33 case 4 failed\n");
2984 FAILED(buf[4] != 13, "test33 case 5 failed\n");
2985 FAILED(buf[5] != 0, "test33 case 6 failed\n");
2986 FAILED(buf[6] != 0, "test33 case 7 failed\n");
2987 FAILED(buf[7] != 48, "test33 case 8 failed\n");
2988 FAILED(buf[8] != 50, "test33 case 9 failed\n");
2989 FAILED(buf[9] != 1, "test33 case 10 failed\n");
2991 sljit_free_code(code.code, NULL);
2992 successful_tests++;
2995 static void test34(void)
2997 /* Test fast calls. */
2998 executable_code codeA;
2999 executable_code codeB;
3000 executable_code codeC;
3001 executable_code codeD;
3002 executable_code codeE;
3003 executable_code codeF;
3004 struct sljit_compiler* compiler;
3005 struct sljit_jump *jump;
3006 struct sljit_label* label;
3007 sljit_uw addr;
3008 sljit_p buf[2];
3010 if (verbose)
3011 printf("Run test34\n");
3013 buf[0] = 0;
3014 buf[1] = 0;
3016 /* A */
3017 compiler = sljit_create_compiler(NULL, NULL);
3018 FAILED(!compiler, "cannot create compiler\n");
3019 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3021 sljit_emit_op0(compiler, SLJIT_ENDBR);
3022 sljit_emit_fast_enter(compiler, SLJIT_R1, 0);
3023 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 4);
3024 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_R1, 0);
3026 codeA.code = sljit_generate_code(compiler);
3027 CHECK(compiler);
3028 sljit_free_compiler(compiler);
3030 /* B */
3031 compiler = sljit_create_compiler(NULL, NULL);
3032 FAILED(!compiler, "cannot create compiler\n");
3033 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3035 sljit_emit_op0(compiler, SLJIT_ENDBR);
3036 sljit_emit_fast_enter(compiler, SLJIT_R4, 0);
3037 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 6);
3038 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(codeA.code));
3039 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_R1, 0);
3040 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_R4, 0);
3042 codeB.code = sljit_generate_code(compiler);
3043 CHECK(compiler);
3044 sljit_free_compiler(compiler);
3046 /* C */
3047 compiler = sljit_create_compiler(NULL, NULL);
3048 FAILED(!compiler, "cannot create compiler\n");
3049 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3051 sljit_emit_op0(compiler, SLJIT_ENDBR);
3052 sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_p));
3053 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 8);
3054 jump = sljit_emit_jump(compiler, SLJIT_FAST_CALL | SLJIT_REWRITABLE_JUMP);
3055 sljit_set_target(jump, SLJIT_FUNC_UADDR(codeB.code));
3056 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_p));
3058 codeC.code = sljit_generate_code(compiler);
3059 CHECK(compiler);
3060 sljit_free_compiler(compiler);
3062 /* D */
3063 compiler = sljit_create_compiler(NULL, NULL);
3064 FAILED(!compiler, "cannot create compiler\n");
3065 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3067 sljit_emit_op0(compiler, SLJIT_ENDBR);
3068 sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_SP), 0);
3069 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 10);
3070 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_ADDR(codeC.code));
3071 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_MEM1(SLJIT_SP), 0);
3073 codeD.code = sljit_generate_code(compiler);
3074 CHECK(compiler);
3075 sljit_free_compiler(compiler);
3077 /* E */
3078 compiler = sljit_create_compiler(NULL, NULL);
3079 FAILED(!compiler, "cannot create compiler\n");
3080 sljit_set_context(compiler, 0, 1, 5, 5, 0, 0, 2 * sizeof(sljit_p));
3082 sljit_emit_fast_enter(compiler, SLJIT_MEM1(SLJIT_S0), 0);
3083 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 12);
3084 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_p), SLJIT_IMM, SLJIT_FUNC_ADDR(codeD.code));
3085 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_p));
3086 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_MEM1(SLJIT_S0), 0);
3088 codeE.code = sljit_generate_code(compiler);
3089 CHECK(compiler);
3090 sljit_free_compiler(compiler);
3092 /* F */
3093 compiler = sljit_create_compiler(NULL, NULL);
3094 FAILED(!compiler, "cannot create compiler\n");
3096 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 5, 5, 0, 0, 2 * sizeof(sljit_p));
3097 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
3098 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_ADDR(codeE.code));
3099 label = sljit_emit_label(compiler);
3100 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
3102 codeF.code = sljit_generate_code(compiler);
3103 CHECK(compiler);
3104 addr = sljit_get_label_addr(label);
3105 sljit_free_compiler(compiler);
3107 FAILED(codeF.func1((sljit_sw)&buf) != 40, "test34 case 1 failed\n");
3108 FAILED(buf[0] != addr - SLJIT_RETURN_ADDRESS_OFFSET, "test34 case 2 failed\n");
3110 sljit_free_code(codeA.code, NULL);
3111 sljit_free_code(codeB.code, NULL);
3112 sljit_free_code(codeC.code, NULL);
3113 sljit_free_code(codeD.code, NULL);
3114 sljit_free_code(codeE.code, NULL);
3115 sljit_free_code(codeF.code, NULL);
3116 successful_tests++;
3119 static void test35(void)
3121 /* More complicated tests for fast calls. */
3122 executable_code codeA;
3123 executable_code codeB;
3124 executable_code codeC;
3125 struct sljit_compiler* compiler;
3126 struct sljit_jump *jump = NULL;
3127 struct sljit_label* label;
3128 sljit_sw executable_offset;
3129 sljit_uw return_addr;
3130 sljit_uw jump_addr = 0;
3131 sljit_p buf[1];
3133 if (verbose)
3134 printf("Run test35\n");
3136 buf[0] = 0;
3138 /* A */
3139 compiler = sljit_create_compiler(NULL, NULL);
3140 FAILED(!compiler, "cannot create compiler\n");
3141 sljit_set_context(compiler, 0, 0, 2, 2, 0, 0, 0);
3143 sljit_emit_fast_enter(compiler, SLJIT_MEM0(), (sljit_sw)&buf[0]);
3144 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 5);
3146 jump = sljit_emit_jump(compiler, SLJIT_FAST_CALL | SLJIT_REWRITABLE_JUMP);
3147 sljit_set_target(jump, 0);
3149 label = sljit_emit_label(compiler);
3150 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_MEM0(), (sljit_sw)&buf[0]);
3152 codeA.code = sljit_generate_code(compiler);
3153 CHECK(compiler);
3154 executable_offset = sljit_get_executable_offset(compiler);
3155 jump_addr = sljit_get_jump_addr(jump);
3156 sljit_free_compiler(compiler);
3158 /* B */
3159 compiler = sljit_create_compiler(NULL, NULL);
3160 FAILED(!compiler, "cannot create compiler\n");
3161 sljit_set_context(compiler, 0, 0, 2, 2, 0, 0, 0);
3163 sljit_emit_op0(compiler, SLJIT_ENDBR);
3164 sljit_emit_fast_enter(compiler, SLJIT_R1, 0);
3165 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 7);
3166 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_R1, 0);
3168 codeB.code = sljit_generate_code(compiler);
3169 CHECK(compiler);
3170 sljit_free_compiler(compiler);
3172 sljit_set_jump_addr(jump_addr, SLJIT_FUNC_UADDR(codeB.code), executable_offset);
3174 /* C */
3175 compiler = sljit_create_compiler(NULL, NULL);
3176 FAILED(!compiler, "cannot create compiler\n");
3178 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(W), 2, 2, 0, 0, 0);
3179 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
3180 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_ADDR(codeA.code));
3181 label = sljit_emit_label(compiler);
3182 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
3184 codeC.code = sljit_generate_code(compiler);
3185 CHECK(compiler);
3186 return_addr = sljit_get_label_addr(label);
3187 sljit_free_compiler(compiler);
3189 FAILED(codeC.func0() != 12, "test35 case 1 failed\n");
3190 FAILED(buf[0] != return_addr - SLJIT_RETURN_ADDRESS_OFFSET, "test35 case 2 failed\n");
3192 sljit_free_code(codeA.code, NULL);
3193 sljit_free_code(codeB.code, NULL);
3194 sljit_free_code(codeC.code, NULL);
3195 successful_tests++;
3198 static void cmp_test(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src1, sljit_sw src1w, sljit_s32 src2, sljit_sw src2w)
3200 /* 2 = true, 1 = false */
3201 struct sljit_jump* jump;
3202 struct sljit_label* label;
3204 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_IMM, 2);
3205 jump = sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w);
3206 sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM1(SLJIT_S0), 1, SLJIT_IMM, 1);
3207 label = sljit_emit_label(compiler);
3208 sljit_emit_op0(compiler, SLJIT_ENDBR);
3209 sljit_set_label(jump, label);
3210 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
3213 #define TEST_CASES (7 + 10 + 12 + 11 + 4)
3214 static void test36(void)
3216 /* Compare instruction. */
3217 executable_code code;
3218 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
3220 sljit_s8 buf[TEST_CASES];
3221 sljit_s8 compare_buf[TEST_CASES] = {
3222 1, 1, 2, 2, 1, 2, 2,
3223 1, 1, 2, 2, 2, 1, 2, 2, 1, 1,
3224 2, 2, 2, 1, 2, 2, 2, 2, 1, 1, 2, 2,
3225 2, 1, 2, 1, 1, 1, 2, 1, 2, 1, 2,
3226 2, 1, 1, 2
3228 sljit_sw data[4];
3229 sljit_s32 i;
3231 if (verbose)
3232 printf("Run test36\n");
3234 FAILED(!compiler, "cannot create compiler\n");
3235 for (i = 0; i < TEST_CASES; ++i)
3236 buf[i] = 100;
3237 data[0] = 32;
3238 data[1] = -9;
3239 data[2] = 43;
3240 data[3] = -13;
3242 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(VOID, P, P), 3, 2, 0, 0, 0);
3243 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
3245 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 13);
3246 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 15);
3247 cmp_test(compiler, SLJIT_EQUAL, SLJIT_IMM, 9, SLJIT_R0, 0);
3248 cmp_test(compiler, SLJIT_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3249 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 3);
3250 cmp_test(compiler, SLJIT_EQUAL, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_IMM, -13);
3251 cmp_test(compiler, SLJIT_NOT_EQUAL, SLJIT_IMM, 0, SLJIT_R0, 0);
3252 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
3253 cmp_test(compiler, SLJIT_NOT_EQUAL | SLJIT_REWRITABLE_JUMP, SLJIT_IMM, 0, SLJIT_R0, 0);
3254 cmp_test(compiler, SLJIT_EQUAL, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT);
3255 cmp_test(compiler, SLJIT_EQUAL | SLJIT_REWRITABLE_JUMP, SLJIT_R0, 0, SLJIT_IMM, 0);
3257 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, 0);
3258 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -8);
3259 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
3260 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_R0, 0, SLJIT_IMM, 0);
3261 cmp_test(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 0);
3262 cmp_test(compiler, SLJIT_SIG_LESS | SLJIT_REWRITABLE_JUMP, SLJIT_R0, 0, SLJIT_IMM, 0);
3263 cmp_test(compiler, SLJIT_SIG_GREATER_EQUAL, SLJIT_R1, 0, SLJIT_IMM, 0);
3264 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_sw));
3265 cmp_test(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_IMM, 0, SLJIT_R1, 0);
3266 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_sw));
3267 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw));
3268 cmp_test(compiler, SLJIT_SIG_LESS | SLJIT_REWRITABLE_JUMP, SLJIT_IMM, 0, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw));
3270 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
3271 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
3272 cmp_test(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_sw));
3273 cmp_test(compiler, SLJIT_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 8);
3274 cmp_test(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_IMM, -10);
3275 cmp_test(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_IMM, 8);
3276 cmp_test(compiler, SLJIT_GREATER_EQUAL, SLJIT_IMM, 8, SLJIT_R1, 0);
3277 cmp_test(compiler, SLJIT_GREATER_EQUAL | SLJIT_REWRITABLE_JUMP, SLJIT_IMM, 8, SLJIT_R1, 0);
3278 cmp_test(compiler, SLJIT_GREATER, SLJIT_IMM, 8, SLJIT_R1, 0);
3279 cmp_test(compiler, SLJIT_LESS_EQUAL, SLJIT_IMM, 7, SLJIT_R0, 0);
3280 cmp_test(compiler, SLJIT_GREATER, SLJIT_IMM, 1, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw));
3281 cmp_test(compiler, SLJIT_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3282 cmp_test(compiler, SLJIT_GREATER, SLJIT_R0, 0, SLJIT_R1, 0);
3283 cmp_test(compiler, SLJIT_GREATER | SLJIT_REWRITABLE_JUMP, SLJIT_R0, 0, SLJIT_R1, 0);
3285 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -3);
3286 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
3287 cmp_test(compiler, SLJIT_SIG_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3288 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_R0, 0, SLJIT_IMM, -1);
3289 cmp_test(compiler, SLJIT_SIG_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 1);
3290 cmp_test(compiler, SLJIT_SIG_LESS, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, -1);
3291 cmp_test(compiler, SLJIT_SIG_LESS | SLJIT_REWRITABLE_JUMP, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_IMM, -1);
3292 cmp_test(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3293 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_R0, 0, SLJIT_R1, 0);
3294 cmp_test(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_IMM, -4, SLJIT_R0, 0);
3295 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_IMM, -1, SLJIT_R1, 0);
3296 cmp_test(compiler, SLJIT_SIG_GREATER | SLJIT_REWRITABLE_JUMP, SLJIT_R1, 0, SLJIT_IMM, -1);
3298 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3299 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xf00000004));
3300 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_R0, 0);
3301 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_R1, 0);
3302 cmp_test(compiler, SLJIT_LESS | SLJIT_32, SLJIT_R1, 0, SLJIT_IMM, 5);
3303 cmp_test(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_IMM, 5);
3304 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xff0000004));
3305 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_R0, 0);
3306 cmp_test(compiler, SLJIT_SIG_GREATER | SLJIT_32, SLJIT_R1, 0, SLJIT_IMM, 5);
3307 cmp_test(compiler, SLJIT_SIG_GREATER, SLJIT_R0, 0, SLJIT_IMM, 5);
3308 #else
3309 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 4);
3310 cmp_test(compiler, SLJIT_LESS | SLJIT_32, SLJIT_R0, 0, SLJIT_IMM, 5);
3311 cmp_test(compiler, SLJIT_GREATER | SLJIT_32, SLJIT_R0, 0, SLJIT_IMM, 5);
3312 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)0xf0000004);
3313 cmp_test(compiler, SLJIT_SIG_GREATER | SLJIT_32, SLJIT_R0, 0, SLJIT_IMM, 5);
3314 cmp_test(compiler, SLJIT_SIG_LESS | SLJIT_32, SLJIT_R0, 0, SLJIT_IMM, 5);
3315 #endif
3317 sljit_emit_return_void(compiler);
3319 code.code = sljit_generate_code(compiler);
3320 CHECK(compiler);
3321 sljit_free_compiler(compiler);
3323 code.func2((sljit_sw)&buf, (sljit_sw)&data);
3325 for (i = 0; i < TEST_CASES; ++i)
3326 if (SLJIT_UNLIKELY(buf[i] != compare_buf[i])) {
3327 printf("test36 case %d failed\n", i + 1);
3328 return;
3331 sljit_free_code(code.code, NULL);
3332 successful_tests++;
3334 #undef TEST_CASES
3336 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3337 #define BITN(n) (SLJIT_W(1) << (63 - (n)))
3338 #define RESN(n) (n)
3339 #else
3340 #define BITN(n) (1 << (31 - ((n) & 0x1f)))
3341 #define RESN(n) ((n) & 0x1f)
3342 #endif
3344 static void test37(void)
3346 /* Test count leading zeroes. */
3347 executable_code code;
3348 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
3349 sljit_sw buf[9];
3350 sljit_s32 ibuf[2];
3351 sljit_s32 i;
3353 if (verbose)
3354 printf("Run test37\n");
3356 FAILED(!compiler, "cannot create compiler\n");
3358 for (i = 0; i < 9; i++)
3359 buf[i] = -1;
3360 buf[2] = 0;
3361 buf[4] = BITN(13);
3362 ibuf[0] = -1;
3363 ibuf[1] = -1;
3364 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(VOID, P, P), 1, 3, 0, 0, 0);
3365 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, BITN(27));
3366 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
3367 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, BITN(47));
3368 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_R0, 0, SLJIT_S2, 0);
3369 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
3370 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw));
3371 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
3372 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_R0, 0, SLJIT_R0, 0);
3373 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_R0, 0);
3374 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0);
3375 sljit_emit_op1(compiler, SLJIT_CLZ32, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_R0, 0);
3376 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -1);
3377 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw));
3378 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
3379 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, BITN(58));
3380 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R0, 0);
3381 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
3382 sljit_emit_op1(compiler, SLJIT_CLZ, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_R0, 0);
3383 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3384 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xff08a00000));
3385 #else
3386 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x08a00000);
3387 #endif
3388 sljit_emit_op1(compiler, SLJIT_CLZ32, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32), SLJIT_R0, 0);
3389 sljit_emit_op1(compiler, SLJIT_CLZ32, SLJIT_R0, 0, SLJIT_R0, 0);
3390 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R0, 0);
3391 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3392 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xffc8a00000));
3393 #else
3394 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)0xc8a00000);
3395 #endif
3396 sljit_emit_op1(compiler, SLJIT_CLZ32, SLJIT_R0, 0, SLJIT_R0, 0);
3397 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R0, 0);
3399 sljit_emit_return_void(compiler);
3401 code.code = sljit_generate_code(compiler);
3402 CHECK(compiler);
3403 sljit_free_compiler(compiler);
3405 code.func2((sljit_sw)&buf, (sljit_sw)&ibuf);
3406 FAILED(buf[0] != RESN(27), "test37 case 1 failed\n");
3407 FAILED(buf[1] != RESN(47), "test37 case 2 failed\n");
3408 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3409 FAILED(buf[2] != 64, "test37 case 3 failed\n");
3410 #else
3411 FAILED(buf[2] != 32, "test37 case 3 failed\n");
3412 #endif
3413 FAILED(buf[3] != 0, "test37 case 4 failed\n");
3414 FAILED(ibuf[0] != 32, "test37 case 5 failed\n");
3415 FAILED(buf[4] != RESN(13), "test37 case 6 failed\n");
3416 FAILED(buf[5] != RESN(58), "test37 case 7 failed\n");
3417 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3418 FAILED(buf[6] != 64, "test37 case 8 failed\n");
3419 #else
3420 FAILED(buf[6] != 32, "test37 case 8 failed\n");
3421 #endif
3422 FAILED(ibuf[1] != 4, "test37 case 9 failed\n");
3424 FAILED((buf[7] & (sljit_sw)0xffffffff) != 4, "test37 case 10 failed\n");
3425 FAILED((buf[8] & (sljit_sw)0xffffffff) != 0, "test37 case 11 failed\n");
3427 sljit_free_code(code.code, NULL);
3428 successful_tests++;
3430 #undef BITN
3431 #undef RESN
3433 static void test38(void)
3435 #if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK)
3436 /* Test stack utility. */
3437 executable_code code;
3438 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
3439 struct sljit_jump* alloc1_fail;
3440 struct sljit_jump* alloc2_fail;
3441 struct sljit_jump* alloc3_fail;
3442 struct sljit_jump* sanity1_fail;
3443 struct sljit_jump* sanity2_fail;
3444 struct sljit_jump* sanity3_fail;
3445 struct sljit_jump* sanity4_fail;
3446 struct sljit_jump* jump;
3447 struct sljit_label* label;
3449 if (verbose)
3450 printf("Run test38\n");
3452 FAILED(!compiler, "cannot create compiler\n");
3454 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(W), 3, 1, 0, 0, 0);
3456 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8192);
3457 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 65536);
3458 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 0);
3459 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS3(P, W, W, P), SLJIT_IMM, SLJIT_FUNC_ADDR(sljit_allocate_stack));
3460 alloc1_fail = sljit_emit_cmp(compiler, SLJIT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
3461 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_RETURN_REG, 0);
3463 /* Write 8k data. */
3464 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, start));
3465 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 8192);
3466 label = sljit_emit_label(compiler);
3467 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_IMM, -1);
3468 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw));
3469 jump = sljit_emit_cmp(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
3470 sljit_set_label(jump, label);
3472 /* Grow stack. */
3473 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
3474 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, end), SLJIT_IMM, 65536);
3475 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS2(P, P, P), SLJIT_IMM, SLJIT_FUNC_ADDR(sljit_stack_resize));
3476 alloc2_fail = sljit_emit_cmp(compiler, SLJIT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
3477 sanity1_fail = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, start));
3479 /* Write 64k data. */
3480 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, start));
3481 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 65536);
3482 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, min_start));
3483 sanity2_fail = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_R0, 0, SLJIT_R2, 0);
3484 label = sljit_emit_label(compiler);
3485 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_IMM, -1);
3486 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw));
3487 jump = sljit_emit_cmp(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
3488 sljit_set_label(jump, label);
3490 /* Shrink stack. */
3491 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
3492 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, end), SLJIT_IMM, 32768);
3493 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS2(P, P, P), SLJIT_IMM, SLJIT_FUNC_ADDR(sljit_stack_resize));
3494 alloc3_fail = sljit_emit_cmp(compiler, SLJIT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_IMM, 0);
3495 sanity3_fail = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, start));
3497 /* Write 32k data. */
3498 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, start));
3499 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_S0), SLJIT_OFFSETOF(struct sljit_stack, end));
3500 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R2, 0, SLJIT_R1, 0, SLJIT_IMM, 32768);
3501 sanity4_fail = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_R0, 0, SLJIT_R2, 0);
3502 label = sljit_emit_label(compiler);
3503 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_IMM, -1);
3504 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_sw));
3505 jump = sljit_emit_cmp(compiler, SLJIT_LESS, SLJIT_R0, 0, SLJIT_R1, 0);
3506 sljit_set_label(jump, label);
3508 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
3509 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
3510 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS2(VOID, P, P), SLJIT_IMM, SLJIT_FUNC_ADDR(sljit_free_stack));
3512 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, 4567);
3514 label = sljit_emit_label(compiler);
3515 sljit_set_label(alloc1_fail, label);
3516 sljit_set_label(alloc2_fail, label);
3517 sljit_set_label(alloc3_fail, label);
3518 sljit_set_label(sanity1_fail, label);
3519 sljit_set_label(sanity2_fail, label);
3520 sljit_set_label(sanity3_fail, label);
3521 sljit_set_label(sanity4_fail, label);
3522 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, 0);
3524 code.code = sljit_generate_code(compiler);
3525 CHECK(compiler);
3526 sljit_free_compiler(compiler);
3528 /* Just survive this. */
3529 FAILED(code.func0() != 4567, "test38 case 1 failed\n");
3531 sljit_free_code(code.code, NULL);
3532 #endif
3533 successful_tests++;
3536 static void test39(void)
3538 /* Test error handling. */
3539 executable_code code;
3540 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
3541 struct sljit_jump* jump;
3543 if (verbose)
3544 printf("Run test39\n");
3546 FAILED(!compiler, "cannot create compiler\n");
3548 /* Such assignment should never happen in a regular program. */
3549 compiler->error = -3967;
3551 SLJIT_ASSERT(sljit_emit_enter(compiler, 0, SLJIT_ARGS2(VOID, W, W), 5, 5, 6, 0, 32) == -3967);
3552 SLJIT_ASSERT(sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R1, 0) == -3967);
3553 SLJIT_ASSERT(sljit_emit_op0(compiler, SLJIT_NOP) == -3967);
3554 SLJIT_ASSERT(sljit_emit_op0(compiler, SLJIT_ENDBR) == -3967);
3555 SLJIT_ASSERT(sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), 1) == -3967);
3556 SLJIT_ASSERT(sljit_emit_op2(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R0), 64, SLJIT_MEM1(SLJIT_S0), -64) == -3967);
3557 SLJIT_ASSERT(sljit_emit_fop1(compiler, SLJIT_ABS_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_R1), 0) == -3967);
3558 SLJIT_ASSERT(sljit_emit_fop2(compiler, SLJIT_DIV_F64, SLJIT_FR2, 0, SLJIT_MEM2(SLJIT_R0, SLJIT_S0), 0, SLJIT_FR2, 0) == -3967);
3559 SLJIT_ASSERT(!sljit_emit_label(compiler));
3560 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS4(W, 32, P, F32, F64));
3561 SLJIT_ASSERT(!jump);
3562 sljit_set_label(jump, (struct sljit_label*)0x123450);
3563 sljit_set_target(jump, 0x123450);
3564 jump = sljit_emit_cmp(compiler, SLJIT_SIG_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R1, 0);
3565 SLJIT_ASSERT(!jump);
3566 SLJIT_ASSERT(sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_MEM1(SLJIT_R0), 8) == -3967);
3567 SLJIT_ASSERT(sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_OVERFLOW) == -3967);
3568 SLJIT_ASSERT(!sljit_emit_const(compiler, SLJIT_R0, 0, 99));
3570 SLJIT_ASSERT(!compiler->labels && !compiler->jumps && !compiler->consts);
3571 SLJIT_ASSERT(!compiler->last_label && !compiler->last_jump && !compiler->last_const);
3572 SLJIT_ASSERT(!compiler->buf->next && !compiler->buf->used_size);
3573 SLJIT_ASSERT(!compiler->abuf->next && !compiler->abuf->used_size);
3575 sljit_set_compiler_memory_error(compiler);
3576 FAILED(sljit_get_compiler_error(compiler) != -3967, "test39 case 1 failed\n");
3578 code.code = sljit_generate_code(compiler);
3579 FAILED(sljit_get_compiler_error(compiler) != -3967, "test39 case 2 failed\n");
3580 FAILED(!!code.code, "test39 case 3 failed\n");
3581 sljit_free_compiler(compiler);
3583 compiler = sljit_create_compiler(NULL, NULL);
3584 FAILED(!compiler, "cannot create compiler\n");
3586 FAILED(sljit_get_compiler_error(compiler) != SLJIT_SUCCESS, "test39 case 4 failed\n");
3587 sljit_set_compiler_memory_error(compiler);
3588 FAILED(sljit_get_compiler_error(compiler) != SLJIT_ERR_ALLOC_FAILED, "test39 case 5 failed\n");
3589 sljit_free_compiler(compiler);
3591 successful_tests++;
3594 static void test40(void)
3596 /* Test emit_op_flags. */
3597 executable_code code;
3598 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
3599 sljit_sw buf[10];
3601 if (verbose)
3602 printf("Run test40\n");
3604 FAILED(!compiler, "cannot create compiler\n");
3605 buf[0] = -100;
3606 buf[1] = -100;
3607 buf[2] = -100;
3608 buf[3] = -8;
3609 buf[4] = -100;
3610 buf[5] = -100;
3611 buf[6] = 0;
3612 buf[7] = 0;
3613 buf[8] = -100;
3614 buf[9] = -100;
3616 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 4, 0, 0, sizeof(sljit_sw));
3618 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -5);
3619 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_IMM, -6, SLJIT_R0, 0);
3620 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x123456);
3621 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_R1, 0, SLJIT_SIG_LESS);
3622 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R1, 0);
3624 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -13);
3625 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_IMM, -13, SLJIT_R0, 0);
3626 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, 0);
3627 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_EQUAL);
3628 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_NOT_EQUAL);
3629 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);
3630 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_IMM, -13, SLJIT_R0, 0);
3631 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
3632 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_EQUAL);
3633 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 2, SLJIT_EQUAL);
3635 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -13);
3636 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 3);
3637 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R1, 0);
3638 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_MEM2(SLJIT_S0, SLJIT_R1), SLJIT_WORD_SHIFT, SLJIT_SIG_LESS);
3640 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -8);
3641 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 33);
3642 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_R0, 0, SLJIT_R1, 0);
3643 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, 0);
3644 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_R2, 0, SLJIT_GREATER);
3645 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_S1, 0, SLJIT_EQUAL);
3646 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_R1, 0);
3647 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, 0x88);
3648 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_S3, 0, SLJIT_NOT_EQUAL);
3649 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 4, SLJIT_S1, 0);
3650 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 5, SLJIT_S3, 0);
3652 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x84);
3653 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_IMM, 0x180, SLJIT_R0, 0);
3654 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 6, SLJIT_EQUAL);
3655 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 7, SLJIT_EQUAL);
3657 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
3658 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_IMM, 1);
3659 sljit_emit_op_flags(compiler, SLJIT_OR | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_NOT_EQUAL);
3660 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 8, SLJIT_NOT_EQUAL);
3662 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x123456);
3663 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_R0, 0, SLJIT_IMM, 1);
3664 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_R0, 0, SLJIT_GREATER);
3665 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw) * 9, SLJIT_R0, 0);
3667 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, 0xbaddead);
3668 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0);
3670 code.code = sljit_generate_code(compiler);
3671 CHECK(compiler);
3672 sljit_free_compiler(compiler);
3674 FAILED(code.func1((sljit_sw)&buf) != 0xbaddead, "test40 case 1 failed\n");
3675 FAILED(buf[0] != 0x123457, "test40 case 2 failed\n");
3676 FAILED(buf[1] != 1, "test40 case 3 failed\n");
3677 FAILED(buf[2] != 0, "test40 case 4 failed\n");
3678 FAILED(buf[3] != -7, "test40 case 5 failed\n");
3679 FAILED(buf[4] != 0, "test40 case 6 failed\n");
3680 FAILED(buf[5] != 0x89, "test40 case 7 failed\n");
3681 FAILED(buf[6] != 0, "test40 case 8 failed\n");
3682 FAILED(buf[7] != 1, "test40 case 9 failed\n");
3683 FAILED(buf[8] != 1, "test40 case 10 failed\n");
3684 FAILED(buf[9] != 0x123457, "test40 case 11 failed\n");
3686 sljit_free_code(code.code, NULL);
3687 successful_tests++;
3690 static void test41(void)
3692 /* Test inline assembly. */
3693 executable_code code;
3694 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
3695 sljit_s32 i;
3696 sljit_f64 buf[3];
3697 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3698 sljit_u8 inst[16];
3699 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3700 sljit_u8 inst[16];
3701 sljit_s32 reg;
3702 #else
3703 sljit_u32 inst;
3704 #endif
3706 if (verbose)
3707 printf("Run test41\n");
3709 #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3710 SLJIT_ASSERT(sljit_has_cpu_feature(SLJIT_HAS_VIRTUAL_REGISTERS) == 0);
3711 #endif
3713 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++) {
3714 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3715 if (SLJIT_R(i) >= SLJIT_R3 && SLJIT_R(i) <= SLJIT_R8) {
3716 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R(i)) == -1);
3717 continue;
3719 #endif
3720 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R(i)) >= 0 && sljit_get_register_index(SLJIT_R(i)) < 64);
3723 FAILED(!compiler, "cannot create compiler\n");
3724 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(W, W, W), 3, 3, 0, 0, 0);
3726 /* Returns with the sum of SLJIT_S0 and SLJIT_S1. */
3727 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3728 /* lea SLJIT_RETURN_REG, [SLJIT_S0, SLJIT_S1] */
3729 inst[0] = 0x48;
3730 inst[1] = 0x8d;
3731 inst[2] = (sljit_u8)(0x04 | ((sljit_get_register_index(SLJIT_RETURN_REG) & 0x7) << 3));
3732 inst[3] = (sljit_u8)((sljit_get_register_index(SLJIT_S0) & 0x7)
3733 | ((sljit_get_register_index(SLJIT_S1) & 0x7) << 3));
3734 sljit_emit_op_custom(compiler, inst, 4);
3735 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3736 /* lea SLJIT_RETURN_REG, [SLJIT_S0, SLJIT_S1] */
3737 inst[0] = 0x48; /* REX_W */
3738 inst[1] = 0x8d;
3739 reg = sljit_get_register_index(SLJIT_RETURN_REG);
3740 inst[2] = (sljit_u8)(0x04 | ((reg & 0x7) << 3));
3741 if (reg > 7)
3742 inst[0] |= 0x04; /* REX_R */
3743 reg = sljit_get_register_index(SLJIT_S0);
3744 inst[3] = (sljit_u8)(reg & 0x7);
3745 if (reg > 7)
3746 inst[0] |= 0x01; /* REX_B */
3747 reg = sljit_get_register_index(SLJIT_S1);
3748 inst[3] = (sljit_u8)(inst[3] | ((reg & 0x7) << 3));
3749 if (reg > 7)
3750 inst[0] |= 0x02; /* REX_X */
3751 sljit_emit_op_custom(compiler, inst, 4);
3752 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
3753 /* add rd, rn, rm */
3754 inst = 0xe0800000 | ((sljit_u32)sljit_get_register_index(SLJIT_RETURN_REG) << 12)
3755 | ((sljit_u32)sljit_get_register_index(SLJIT_S0) << 16)
3756 | (sljit_u32)sljit_get_register_index(SLJIT_S1);
3757 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3758 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
3759 /* add rd, rn, rm */
3760 inst = 0xeb000000 | ((sljit_u32)sljit_get_register_index(SLJIT_RETURN_REG) << 8)
3761 | ((sljit_u32)sljit_get_register_index(SLJIT_S0) << 16)
3762 | (sljit_u32)sljit_get_register_index(SLJIT_S1);
3763 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3764 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
3765 /* add rd, rn, rm */
3766 inst = 0x8b000000 | (sljit_u32)sljit_get_register_index(SLJIT_RETURN_REG)
3767 | ((sljit_u32)sljit_get_register_index(SLJIT_S0) << 5)
3768 | ((sljit_u32)sljit_get_register_index(SLJIT_S1) << 16);
3769 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3770 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
3771 /* add rD, rA, rB */
3772 inst = (31 << 26) | (266 << 1) | ((sljit_u32)sljit_get_register_index(SLJIT_RETURN_REG) << 21)
3773 | ((sljit_u32)sljit_get_register_index(SLJIT_S0) << 16)
3774 | ((sljit_u32)sljit_get_register_index(SLJIT_S1) << 11);
3775 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3776 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
3777 /* addu rd, rs, rt */
3778 inst = 33 | ((sljit_u32)sljit_get_register_index(SLJIT_RETURN_REG) << 11)
3779 | ((sljit_u32)sljit_get_register_index(SLJIT_S0) << 21)
3780 | ((sljit_u32)sljit_get_register_index(SLJIT_S1) << 16);
3781 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3782 #elif (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
3783 /* daddu rd, rs, rt */
3784 inst = 45 | ((sljit_u32)sljit_get_register_index(SLJIT_RETURN_REG) << 11)
3785 | ((sljit_u32)sljit_get_register_index(SLJIT_S0) << 21)
3786 | ((sljit_u32)sljit_get_register_index(SLJIT_S1) << 16);
3787 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3788 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3789 /* add rd, rs1, rs2 */
3790 inst = (0x2u << 30) | ((sljit_u32)sljit_get_register_index(SLJIT_RETURN_REG) << 25)
3791 | ((sljit_u32)sljit_get_register_index(SLJIT_S0) << 14)
3792 | (sljit_u32)sljit_get_register_index(SLJIT_S1);
3793 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3794 #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
3795 /* agrk rd, rs1, rs2 */
3796 inst = (0xb9e8u << 16)
3797 | ((sljit_u32)sljit_get_register_index(SLJIT_RETURN_REG) << 4)
3798 | ((sljit_u32)sljit_get_register_index(SLJIT_S0) << 12)
3799 | (sljit_u32)sljit_get_register_index(SLJIT_S1);
3800 sljit_emit_op_custom(compiler, &inst, sizeof(inst));
3801 #else
3802 inst = 0;
3803 sljit_emit_op_custom(compiler, &inst, 0);
3804 #endif
3806 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
3808 code.code = sljit_generate_code(compiler);
3809 CHECK(compiler);
3810 sljit_free_compiler(compiler);
3812 FAILED(code.func2(32, -11) != 21, "test41 case 1 failed\n");
3813 FAILED(code.func2(1000, 234) != 1234, "test41 case 2 failed\n");
3814 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3815 FAILED(code.func2(SLJIT_W(0x20f0a04090c06070), SLJIT_W(0x020f0a04090c0607)) != SLJIT_W(0x22ffaa4499cc6677), "test41 case 3 failed\n");
3816 #endif
3818 sljit_free_code(code.code, NULL);
3820 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
3821 buf[0] = 13.5;
3822 buf[1] = -2.25;
3823 buf[2] = 0.0;
3825 compiler = sljit_create_compiler(NULL, NULL);
3826 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 0, 1, 2, 0, 0);
3827 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 0);
3828 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
3829 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
3830 /* addsd x, xm */
3831 inst[0] = 0xf2;
3832 inst[1] = 0x0f;
3833 inst[2] = 0x58;
3834 inst[3] = (sljit_u8)(0xc0 | (sljit_get_float_register_index(SLJIT_FR0) << 3)
3835 | sljit_get_float_register_index(SLJIT_FR1));
3836 sljit_emit_op_custom(compiler, inst, 4);
3837 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
3838 /* addsd x, xm */
3839 if (sljit_get_float_register_index(SLJIT_FR0) > 7 || sljit_get_float_register_index(SLJIT_FR1) > 7) {
3840 inst[0] = 0;
3841 if (sljit_get_float_register_index(SLJIT_FR0) > 7)
3842 inst[0] |= 0x04; /* REX_R */
3843 if (sljit_get_float_register_index(SLJIT_FR1) > 7)
3844 inst[0] |= 0x01; /* REX_B */
3845 inst[1] = 0xf2;
3846 inst[2] = 0x0f;
3847 inst[3] = 0x58;
3848 inst[4] = (sljit_u8)(0xc0 | ((sljit_get_float_register_index(SLJIT_FR0) & 0x7) << 3)
3849 | (sljit_get_float_register_index(SLJIT_FR1) & 0x7));
3850 sljit_emit_op_custom(compiler, inst, 5);
3852 else {
3853 inst[0] = 0xf2;
3854 inst[1] = 0x0f;
3855 inst[2] = 0x58;
3856 inst[3] = (sljit_u8)(0xc0 | (sljit_get_float_register_index(SLJIT_FR0) << 3)
3857 | sljit_get_float_register_index(SLJIT_FR1));
3858 sljit_emit_op_custom(compiler, inst, 4);
3860 #elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32)
3861 /* vadd.f64 dd, dn, dm */
3862 inst = 0xee300b00 | (((sljit_u32)sljit_get_float_register_index(SLJIT_FR0) >> 1) << 12)
3863 | (((sljit_u32)sljit_get_float_register_index(SLJIT_FR0) >> 1) << 16)
3864 | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR1) >> 1);
3865 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3866 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
3867 /* fadd rd, rn, rm */
3868 inst = 0x1e602800 | (sljit_u32)sljit_get_float_register_index(SLJIT_FR0)
3869 | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR0) << 5)
3870 | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR1) << 16);
3871 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3872 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
3873 /* fadd frD, frA, frB */
3874 inst = (63u << 26) | (21u << 1) | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR0) << 21)
3875 | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR0) << 16)
3876 | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR1) << 11);
3877 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3878 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
3879 /* add.d fd, fs, ft */
3880 inst = (17 << 26) | (17 << 21) | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR0) << 6)
3881 | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR0) << 11)
3882 | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR1) << 16);
3883 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3884 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
3885 /* faddd rd, rs1, rs2 */
3886 inst = (0x2u << 30) | (0x34u << 19) | (0x42u << 5)
3887 | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR0) << 25)
3888 | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR0) << 14)
3889 | (sljit_u32)sljit_get_float_register_index(SLJIT_FR1);
3890 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3891 #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
3892 /* adbr r1, r2 */
3893 inst = 0xb31a0000
3894 | ((sljit_u32)sljit_get_float_register_index(SLJIT_FR0) << 4)
3895 | (sljit_u32)sljit_get_float_register_index(SLJIT_FR1);
3896 sljit_emit_op_custom(compiler, &inst, sizeof(sljit_u32));
3897 #endif
3898 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64), SLJIT_FR0, 0);
3899 sljit_emit_return_void(compiler);
3901 code.code = sljit_generate_code(compiler);
3902 CHECK(compiler);
3903 sljit_free_compiler(compiler);
3905 code.func1((sljit_sw)&buf);
3906 FAILED(buf[2] != 11.25, "test41 case 3 failed\n");
3908 sljit_free_code(code.code, NULL);
3911 successful_tests++;
3914 static void test42(void)
3916 /* Test long multiply and division. */
3917 executable_code code;
3918 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
3919 sljit_s32 i;
3920 sljit_sw buf[7 + 4 + 8 + 8];
3922 if (verbose)
3923 printf("Run test42\n");
3925 FAILED(!compiler, "cannot create compiler\n");
3926 for (i = 0; i < 7 + 4 + 8 + 8; i++)
3927 buf[i] = -1;
3929 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 5, 5, 0, 0, 0);
3931 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -0x1fb308a);
3932 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0xf50c873);
3933 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_IMM, 0x8a0475b);
3934 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, 0x9dc849b);
3935 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, -0x7c69a35);
3936 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, 0x5a4d0c4);
3937 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S4, 0, SLJIT_IMM, 0x9a3b06d);
3939 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
3940 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3941 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3942 sljit_emit_op0(compiler, SLJIT_LMUL_UW);
3943 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R0, 0);
3944 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R1, 0);
3946 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3947 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3948 sljit_emit_op0(compiler, SLJIT_LMUL_SW);
3949 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_R0, 0);
3950 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_R1, 0);
3952 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3953 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3954 sljit_emit_op0(compiler, SLJIT_DIVMOD_UW);
3955 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_R0, 0);
3956 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_R1, 0);
3958 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x5dc4f897b8cd67f5));
3959 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3f8b5c026cb088df));
3960 sljit_emit_op0(compiler, SLJIT_DIVMOD_SW);
3961 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_R0, 0);
3962 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_sw), SLJIT_R1, 0);
3964 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x5cf783d3cf0a74b0));
3965 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3d5df42d03a28fc7));
3966 sljit_emit_op0(compiler, SLJIT_DIVMOD_U32);
3967 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
3968 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R1, 0, SLJIT_R1, 0);
3969 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 15 * sizeof(sljit_sw), SLJIT_R0, 0);
3970 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 16 * sizeof(sljit_sw), SLJIT_R1, 0);
3972 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x371df5197ba26a28));
3973 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x46c78a5cfd6a420c));
3974 sljit_emit_op0(compiler, SLJIT_DIVMOD_S32);
3975 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
3976 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R1, 0, SLJIT_R1, 0);
3977 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 17 * sizeof(sljit_sw), SLJIT_R0, 0);
3978 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_sw), SLJIT_R1, 0);
3980 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)SLJIT_W(0xc456f048c28a611b));
3981 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x3d4af2c543));
3982 sljit_emit_op0(compiler, SLJIT_DIV_UW);
3983 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 19 * sizeof(sljit_sw), SLJIT_R0, 0);
3984 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 20 * sizeof(sljit_sw), SLJIT_R1, 0);
3986 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(-0x720fa4b74c329b14));
3987 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0xa64ae42b7d6));
3988 sljit_emit_op0(compiler, SLJIT_DIV_SW);
3989 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 21 * sizeof(sljit_sw), SLJIT_R0, 0);
3990 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 22 * sizeof(sljit_sw), SLJIT_R1, 0);
3992 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x4af51c027b34));
3993 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(0x9ba4ff2906b14));
3994 sljit_emit_op0(compiler, SLJIT_DIV_U32);
3995 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
3996 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R1, 0, SLJIT_R1, 0);
3997 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 23 * sizeof(sljit_sw), SLJIT_R0, 0);
3998 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 24 * sizeof(sljit_sw), SLJIT_R1, 0);
4000 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0xc40b58a3f20d));
4001 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, SLJIT_W(-0xa63c923));
4002 sljit_emit_op0(compiler, SLJIT_DIV_S32);
4003 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
4004 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R1, 0, SLJIT_R1, 0);
4005 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 25 * sizeof(sljit_sw), SLJIT_R0, 0);
4006 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 26 * sizeof(sljit_sw), SLJIT_R1, 0);
4008 #else
4009 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -0x58cd67f5);
4010 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x3cb088df);
4011 sljit_emit_op0(compiler, SLJIT_LMUL_UW);
4012 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R0, 0);
4013 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R1, 0);
4015 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -0x58cd67f5);
4016 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x3cb088df);
4017 sljit_emit_op0(compiler, SLJIT_LMUL_SW);
4018 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_R0, 0);
4019 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_R1, 0);
4021 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -0x58cd67f5);
4022 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x3cb088df);
4023 sljit_emit_op0(compiler, SLJIT_DIVMOD_UW);
4024 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_R0, 0);
4025 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_R1, 0);
4027 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -0x58cd67f5);
4028 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0x3cb088df);
4029 sljit_emit_op0(compiler, SLJIT_DIVMOD_SW);
4030 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_R0, 0);
4031 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_sw), SLJIT_R1, 0);
4033 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)0xcf0a74b0);
4034 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 0x03a28fc7);
4035 sljit_emit_op0(compiler, SLJIT_DIVMOD_U32);
4036 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 15 * sizeof(sljit_sw), SLJIT_R0, 0);
4037 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 16 * sizeof(sljit_sw), SLJIT_R1, 0);
4039 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x7ba26a28);
4040 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)0xfd6a420c);
4041 sljit_emit_op0(compiler, SLJIT_DIVMOD_S32);
4042 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 17 * sizeof(sljit_sw), SLJIT_R0, 0);
4043 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_sw), SLJIT_R1, 0);
4045 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)0x9d4b7036);
4046 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0xb86d0);
4047 sljit_emit_op0(compiler, SLJIT_DIV_UW);
4048 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 19 * sizeof(sljit_sw), SLJIT_R0, 0);
4049 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 20 * sizeof(sljit_sw), SLJIT_R1, 0);
4051 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -0x58b0692c);
4052 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0xd357);
4053 sljit_emit_op0(compiler, SLJIT_DIV_SW);
4054 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 21 * sizeof(sljit_sw), SLJIT_R0, 0);
4055 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 22 * sizeof(sljit_sw), SLJIT_R1, 0);
4057 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x1c027b34);
4058 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, (sljit_sw)0xf2906b14);
4059 sljit_emit_op0(compiler, SLJIT_DIV_U32);
4060 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R0, 0, SLJIT_R0, 0);
4061 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_R1, 0, SLJIT_R1, 0);
4062 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 23 * sizeof(sljit_sw), SLJIT_R0, 0);
4063 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 24 * sizeof(sljit_sw), SLJIT_R1, 0);
4065 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0x58a3f20d);
4066 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -0xa63c923);
4067 sljit_emit_op0(compiler, SLJIT_DIV_S32);
4068 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
4069 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R1, 0, SLJIT_R1, 0);
4070 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 25 * sizeof(sljit_sw), SLJIT_R0, 0);
4071 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 26 * sizeof(sljit_sw), SLJIT_R1, 0);
4072 #endif
4074 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R2, 0);
4075 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R3, 0);
4076 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R4, 0);
4077 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_S1, 0);
4078 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_S2, 0);
4079 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_S3, 0);
4080 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_S4, 0);
4082 sljit_emit_return_void(compiler);
4084 code.code = sljit_generate_code(compiler);
4085 CHECK(compiler);
4086 sljit_free_compiler(compiler);
4088 code.func1((sljit_sw)&buf);
4090 FAILED(buf[0] != -0x1fb308a, "test42 case 1 failed\n");
4091 FAILED(buf[1] != 0xf50c873, "test42 case 2 failed\n");
4092 FAILED(buf[2] != 0x8a0475b, "test42 case 3 failed\n");
4093 FAILED(buf[3] != 0x9dc849b, "test42 case 4 failed\n");
4094 FAILED(buf[4] != -0x7c69a35, "test42 case 5 failed\n");
4095 FAILED(buf[5] != 0x5a4d0c4, "test42 case 6 failed\n");
4096 FAILED(buf[6] != 0x9a3b06d, "test42 case 7 failed\n");
4098 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4099 FAILED(buf[7] != SLJIT_W(-4388959407985636971), "test42 case 8 failed\n");
4100 FAILED(buf[8] != SLJIT_W(2901680654366567099), "test42 case 9 failed\n");
4101 FAILED(buf[9] != SLJIT_W(-4388959407985636971), "test42 case 10 failed\n");
4102 FAILED(buf[10] != SLJIT_W(-1677173957268872740), "test42 case 11 failed\n");
4103 FAILED(buf[11] != SLJIT_W(2), "test42 case 12 failed\n");
4104 FAILED(buf[12] != SLJIT_W(2532236178951865933), "test42 case 13 failed\n");
4105 FAILED(buf[13] != SLJIT_W(-1), "test42 case 14 failed\n");
4106 FAILED(buf[14] != SLJIT_W(-2177944059851366166), "test42 case 15 failed\n");
4107 #else
4108 FAILED(buf[7] != -1587000939, "test42 case 8 failed\n");
4109 FAILED(buf[8] != 665003983, "test42 case 9 failed\n");
4110 FAILED(buf[9] != -1587000939, "test42 case 10 failed\n");
4111 FAILED(buf[10] != -353198352, "test42 case 11 failed\n");
4112 FAILED(buf[11] != 2, "test42 case 12 failed\n");
4113 FAILED(buf[12] != 768706125, "test42 case 13 failed\n");
4114 FAILED(buf[13] != -1, "test42 case 14 failed\n");
4115 FAILED(buf[14] != -471654166, "test42 case 15 failed\n");
4116 #endif
4118 FAILED(buf[15] != 56, "test42 case 16 failed\n");
4119 FAILED(buf[16] != 58392872, "test42 case 17 failed\n");
4120 FAILED(buf[17] != -47, "test42 case 18 failed\n");
4121 FAILED(buf[18] != 35949148, "test42 case 19 failed\n");
4123 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4124 FAILED(buf[19] != SLJIT_W(0x3340bfc), "test42 case 20 failed\n");
4125 FAILED(buf[20] != SLJIT_W(0x3d4af2c543), "test42 case 21 failed\n");
4126 FAILED(buf[21] != SLJIT_W(-0xaf978), "test42 case 22 failed\n");
4127 FAILED(buf[22] != SLJIT_W(0xa64ae42b7d6), "test42 case 23 failed\n");
4128 #else
4129 FAILED(buf[19] != SLJIT_W(0xda5), "test42 case 20 failed\n");
4130 FAILED(buf[20] != SLJIT_W(0xb86d0), "test42 case 21 failed\n");
4131 FAILED(buf[21] != SLJIT_W(-0x6b6e), "test42 case 22 failed\n");
4132 FAILED(buf[22] != SLJIT_W(0xd357), "test42 case 23 failed\n");
4133 #endif
4135 FAILED(buf[23] != 0x0, "test42 case 24 failed\n");
4136 FAILED(buf[24] != (sljit_sw)0xf2906b14, "test42 case 25 failed\n");
4137 FAILED(buf[25] != -0x8, "test42 case 26 failed\n");
4138 FAILED(buf[26] != -0xa63c923, "test42 case 27 failed\n");
4140 sljit_free_code(code.code, NULL);
4141 successful_tests++;
4144 static void test43(void)
4146 /* Test floating point compare. */
4147 executable_code code;
4148 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
4149 struct sljit_jump* jump;
4151 union {
4152 sljit_f64 value;
4153 struct {
4154 sljit_u32 value1;
4155 sljit_u32 value2;
4156 } u;
4157 } dbuf[4];
4159 if (verbose)
4160 printf("Run test43\n");
4162 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
4163 if (verbose)
4164 printf("no fpu available, test43 skipped\n");
4165 successful_tests++;
4166 if (compiler)
4167 sljit_free_compiler(compiler);
4168 return;
4171 FAILED(!compiler, "cannot create compiler\n");
4173 dbuf[0].value = 12.125;
4174 /* a NaN */
4175 dbuf[1].u.value1 = 0x7fffffff;
4176 dbuf[1].u.value2 = 0x7fffffff;
4177 dbuf[2].value = -13.5;
4178 dbuf[3].value = 12.125;
4180 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 1, 1, 3, 0, 0);
4181 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
4182 /* dbuf[0] < dbuf[2] -> -2 */
4183 jump = sljit_emit_fcmp(compiler, SLJIT_GREATER_EQUAL_F64, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_F64_SHIFT);
4184 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, -2);
4186 sljit_set_label(jump, sljit_emit_label(compiler));
4187 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 0);
4188 /* dbuf[0] and dbuf[1] is not NaN -> 5 */
4189 jump = sljit_emit_fcmp(compiler, SLJIT_UNORDERED_F64, SLJIT_MEM0(), (sljit_sw)&dbuf[1], SLJIT_FR1, 0);
4190 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, 5);
4192 sljit_set_label(jump, sljit_emit_label(compiler));
4193 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f64));
4194 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, 11);
4195 /* dbuf[0] == dbuf[3] -> 11 */
4196 jump = sljit_emit_fcmp(compiler, SLJIT_EQUAL_F64, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_FR2, 0);
4198 /* else -> -17 */
4199 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, -17);
4200 sljit_set_label(jump, sljit_emit_label(compiler));
4201 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
4203 code.code = sljit_generate_code(compiler);
4204 CHECK(compiler);
4205 sljit_free_compiler(compiler);
4207 FAILED(code.func1((sljit_sw)&dbuf) != 11, "test43 case 1 failed\n");
4208 dbuf[3].value = 12;
4209 FAILED(code.func1((sljit_sw)&dbuf) != -17, "test43 case 2 failed\n");
4210 dbuf[1].value = 0;
4211 FAILED(code.func1((sljit_sw)&dbuf) != 5, "test43 case 3 failed\n");
4212 dbuf[2].value = 20;
4213 FAILED(code.func1((sljit_sw)&dbuf) != -2, "test43 case 4 failed\n");
4215 sljit_free_code(code.code, NULL);
4216 successful_tests++;
4219 static void test44(void)
4221 /* Test mov. */
4222 executable_code code;
4223 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
4224 void *buf[5];
4226 if (verbose)
4227 printf("Run test44\n");
4229 FAILED(!compiler, "cannot create compiler\n");
4231 buf[0] = buf + 2;
4232 buf[1] = NULL;
4233 buf[2] = NULL;
4234 buf[3] = NULL;
4235 buf[4] = NULL;
4236 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(P, P), 3, 2, 0, 0, 0);
4238 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 0);
4239 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_p), SLJIT_R0, 0);
4240 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_p));
4241 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 2);
4242 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_MEM2(SLJIT_S0, SLJIT_R1), SLJIT_POINTER_SHIFT, SLJIT_R0, 0);
4243 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, sizeof(sljit_p));
4244 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 3 << SLJIT_POINTER_SHIFT);
4245 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_S0, 0);
4246 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_MEM2(SLJIT_R2, SLJIT_R1), 0, SLJIT_R0, 0);
4247 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 2 * sizeof(sljit_p));
4248 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 1 << SLJIT_POINTER_SHIFT);
4249 sljit_emit_op1(compiler, SLJIT_MOV_P, SLJIT_MEM2(SLJIT_R2, SLJIT_R1), 2, SLJIT_R0, 0);
4251 sljit_emit_return(compiler, SLJIT_MOV_P, SLJIT_R0, 0);
4253 code.code = sljit_generate_code(compiler);
4254 CHECK(compiler);
4255 sljit_free_compiler(compiler);
4257 FAILED(code.func1((sljit_sw)&buf) != (sljit_sw)(buf + 2), "test44 case 1 failed\n");
4258 FAILED(buf[1] != buf + 2, "test44 case 2 failed\n");
4259 FAILED(buf[2] != buf + 3, "test44 case 3 failed\n");
4260 FAILED(buf[3] != buf + 4, "test44 case 4 failed\n");
4261 FAILED(buf[4] != buf + 2, "test44 case 5 failed\n");
4263 sljit_free_code(code.code, NULL);
4264 successful_tests++;
4267 static void test45(void)
4269 /* Test single precision floating point. */
4271 executable_code code;
4272 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
4273 sljit_f32 buf[12];
4274 sljit_sw buf2[6];
4275 struct sljit_jump* jump;
4277 if (verbose)
4278 printf("Run test45\n");
4280 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
4281 if (verbose)
4282 printf("no fpu available, test45 skipped\n");
4283 successful_tests++;
4284 if (compiler)
4285 sljit_free_compiler(compiler);
4286 return;
4289 FAILED(!compiler, "cannot create compiler\n");
4291 buf[0] = 5.5;
4292 buf[1] = -7.25;
4293 buf[2] = 0;
4294 buf[3] = 0;
4295 buf[4] = 0;
4296 buf[5] = 0;
4297 buf[6] = 0;
4298 buf[7] = 8.75;
4299 buf[8] = 0;
4300 buf[9] = 16.5;
4301 buf[10] = 0;
4302 buf[11] = 0;
4304 buf2[0] = -1;
4305 buf2[1] = -1;
4306 buf2[2] = -1;
4307 buf2[3] = -1;
4308 buf2[4] = -1;
4309 buf2[5] = -1;
4311 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(VOID, P, P), 3, 2, 6, 0, 0);
4313 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 0);
4314 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4315 sljit_emit_fop1(compiler, SLJIT_NEG_F32, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f32), SLJIT_FR0, 0);
4316 sljit_emit_fop1(compiler, SLJIT_ABS_F32, SLJIT_FR1, 0, SLJIT_FR5, 0);
4317 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f32), SLJIT_FR1, 0);
4318 sljit_emit_fop1(compiler, SLJIT_ABS_F32, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f32), SLJIT_FR5, 0);
4319 sljit_emit_fop1(compiler, SLJIT_NEG_F32, SLJIT_FR4, 0, SLJIT_MEM1(SLJIT_S0), 0);
4320 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f32), SLJIT_FR4, 0);
4322 sljit_emit_fop2(compiler, SLJIT_ADD_F32, SLJIT_FR0, 0, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4323 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f32), SLJIT_FR0, 0);
4324 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);
4325 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 0);
4326 sljit_emit_fop2(compiler, SLJIT_MUL_F32, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_f32), SLJIT_FR0, 0, SLJIT_FR0, 0);
4327 sljit_emit_fop2(compiler, SLJIT_DIV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f32), SLJIT_FR0, 0);
4328 sljit_emit_fop1(compiler, SLJIT_ABS_F32, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f32), SLJIT_FR2, 0);
4329 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 0x3d0ac);
4330 sljit_emit_fop1(compiler, SLJIT_NEG_F32, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_R0), 0x3d0ac);
4331 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 0x3d0ac + sizeof(sljit_f32));
4332 sljit_emit_fop1(compiler, SLJIT_ABS_F32, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_R0), -0x3d0ac);
4334 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 0);
4335 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4336 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 0);
4337 cond_set(compiler, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_EQUAL_F32);
4338 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_LESS_F, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 0);
4339 cond_set(compiler, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_sw), SLJIT_LESS_F32);
4340 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
4341 cond_set(compiler, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_sw), SLJIT_EQUAL_F32);
4342 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_GREATER_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
4343 cond_set(compiler, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw), SLJIT_GREATER_EQUAL_F32);
4345 jump = sljit_emit_fcmp(compiler, SLJIT_LESS_EQUAL_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4346 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_sw), SLJIT_IMM, 7);
4347 sljit_set_label(jump, sljit_emit_label(compiler));
4349 jump = sljit_emit_fcmp(compiler, SLJIT_GREATER_F32, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_FR2, 0);
4350 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_sw), SLJIT_IMM, 6);
4351 sljit_set_label(jump, sljit_emit_label(compiler));
4353 sljit_emit_return_void(compiler);
4355 code.code = sljit_generate_code(compiler);
4356 CHECK(compiler);
4357 sljit_free_compiler(compiler);
4359 code.func2((sljit_sw)&buf, (sljit_sw)&buf2);
4360 FAILED(buf[2] != -5.5, "test45 case 1 failed\n");
4361 FAILED(buf[3] != 7.25, "test45 case 2 failed\n");
4362 FAILED(buf[4] != 7.25, "test45 case 3 failed\n");
4363 FAILED(buf[5] != -5.5, "test45 case 4 failed\n");
4364 FAILED(buf[6] != -1.75, "test45 case 5 failed\n");
4365 FAILED(buf[7] != 16.0, "test45 case 6 failed\n");
4366 FAILED(buf[8] != 30.25, "test45 case 7 failed\n");
4367 FAILED(buf[9] != 3, "test45 case 8 failed\n");
4368 FAILED(buf[10] != -5.5, "test45 case 9 failed\n");
4369 FAILED(buf[11] != 7.25, "test45 case 10 failed\n");
4370 FAILED(buf2[0] != 1, "test45 case 11 failed\n");
4371 FAILED(buf2[1] != 2, "test45 case 12 failed\n");
4372 FAILED(buf2[2] != 2, "test45 case 13 failed\n");
4373 FAILED(buf2[3] != 1, "test45 case 14 failed\n");
4374 FAILED(buf2[4] != 7, "test45 case 15 failed\n");
4375 FAILED(buf2[5] != -1, "test45 case 16 failed\n");
4377 sljit_free_code(code.code, NULL);
4378 successful_tests++;
4381 static void test46(void)
4383 /* Test sljit_emit_op_flags with 32 bit operations. */
4385 executable_code code;
4386 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
4387 sljit_s32 buf[24];
4388 sljit_sw buf2[6];
4389 sljit_s32 i;
4391 if (verbose)
4392 printf("Run test46\n");
4394 for (i = 0; i < 24; ++i)
4395 buf[i] = -17;
4396 buf[16] = 0;
4397 for (i = 0; i < 6; ++i)
4398 buf2[i] = -13;
4399 buf2[4] = -124;
4401 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(VOID, P, P), 3, 3, 0, 0, 0);
4403 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -7);
4404 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, SLJIT_R2, 0, SLJIT_IMM, 13);
4405 sljit_emit_op_flags(compiler, SLJIT_MOV32, SLJIT_MEM0(), (sljit_sw)&buf, SLJIT_LESS);
4406 sljit_emit_op_flags(compiler, SLJIT_AND32, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_s32), SLJIT_NOT_ZERO);
4408 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R2, 0, SLJIT_IMM, -7);
4409 sljit_emit_op_flags(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_s32), SLJIT_EQUAL);
4410 sljit_emit_op_flags(compiler, SLJIT_AND32, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_s32), SLJIT_NOT_EQUAL);
4411 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x1235);
4412 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_IMM, 0x1235);
4413 sljit_emit_op_flags(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_ZERO);
4414 sljit_emit_op_flags(compiler, SLJIT_AND32, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_s32), SLJIT_ZERO);
4415 sljit_emit_op1(compiler, SLJIT_MOV_U32, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_s32), SLJIT_R0, 0);
4417 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R2, 0, SLJIT_IMM, -7);
4418 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 12);
4419 sljit_emit_op_flags(compiler, SLJIT_MOV32, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 2, SLJIT_EQUAL);
4420 sljit_emit_op_flags(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_EQUAL);
4421 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_s32), SLJIT_R0, 0);
4422 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 16);
4423 sljit_emit_op_flags(compiler, SLJIT_AND32 | SLJIT_SET_Z, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), 2, SLJIT_EQUAL);
4424 sljit_emit_op_flags(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_s32), SLJIT_NOT_EQUAL);
4426 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R2, 0, SLJIT_IMM, -7);
4427 sljit_emit_op_flags(compiler, SLJIT_XOR32 | SLJIT_SET_Z, SLJIT_MEM1(SLJIT_S0), 20 * sizeof(sljit_s32), SLJIT_ZERO);
4428 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 39);
4429 sljit_emit_op_flags(compiler, SLJIT_XOR32, SLJIT_R0, 0, SLJIT_NOT_ZERO);
4430 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S0), 22 * sizeof(sljit_s32), SLJIT_R0, 0);
4432 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_R2, 0, SLJIT_IMM, -7);
4433 sljit_emit_op_flags(compiler, SLJIT_AND, SLJIT_MEM0(), (sljit_sw)&buf2, SLJIT_GREATER);
4434 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R2, 0, SLJIT_IMM, 5);
4435 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1);
4436 sljit_emit_op_flags(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_SIG_LESS);
4437 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
4438 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, SLJIT_R2, 0, SLJIT_IMM, 5);
4439 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_LESS);
4440 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_NOT_EQUAL);
4441 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R2, 0, SLJIT_IMM, 5);
4442 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_sw), SLJIT_S2, 0);
4443 sljit_emit_op_flags(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_WORD_SHIFT, SLJIT_SIG_LESS);
4444 sljit_emit_op_flags(compiler, SLJIT_OR, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_sw), SLJIT_ZERO);
4445 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_R2, 0, SLJIT_IMM, 0);
4446 sljit_emit_op_flags(compiler, SLJIT_XOR, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_sw), SLJIT_GREATER);
4448 sljit_emit_return_void(compiler);
4450 code.code = sljit_generate_code(compiler);
4451 CHECK(compiler);
4452 sljit_free_compiler(compiler);
4454 code.func2((sljit_sw)&buf, (sljit_sw)&buf2);
4455 FAILED(buf[0] != 0, "test46 case 1 failed\n");
4456 FAILED(buf[1] != -17, "test46 case 2 failed\n");
4457 FAILED(buf[2] != 1, "test46 case 3 failed\n");
4458 FAILED(buf[3] != -17, "test46 case 4 failed\n");
4459 FAILED(buf[4] != 1, "test46 case 5 failed\n");
4460 FAILED(buf[5] != -17, "test46 case 6 failed\n");
4461 FAILED(buf[6] != 1, "test46 case 7 failed\n");
4462 FAILED(buf[7] != -17, "test46 case 8 failed\n");
4463 FAILED(buf[8] != 0, "test46 case 9 failed\n");
4464 FAILED(buf[9] != -17, "test46 case 10 failed\n");
4465 FAILED(buf[10] != 1, "test46 case 11 failed\n");
4466 FAILED(buf[11] != -17, "test46 case 12 failed\n");
4467 FAILED(buf[12] != 1, "test46 case 13 failed\n");
4468 FAILED(buf[13] != -17, "test46 case 14 failed\n");
4469 FAILED(buf[14] != 1, "test46 case 15 failed\n");
4470 FAILED(buf[15] != -17, "test46 case 16 failed\n");
4471 FAILED(buf[16] != 0, "test46 case 17 failed\n");
4472 FAILED(buf[17] != -17, "test46 case 18 failed\n");
4473 FAILED(buf[18] != 0, "test46 case 19 failed\n");
4474 FAILED(buf[19] != -17, "test46 case 20 failed\n");
4475 FAILED(buf[20] != -18, "test46 case 21 failed\n");
4476 FAILED(buf[21] != -17, "test46 case 22 failed\n");
4477 FAILED(buf[22] != 38, "test46 case 23 failed\n");
4478 FAILED(buf[23] != -17, "test46 case 24 failed\n");
4480 FAILED(buf2[0] != 0, "test46 case 25 failed\n");
4481 FAILED(buf2[1] != 1, "test46 case 26 failed\n");
4482 FAILED(buf2[2] != 0, "test46 case 27 failed\n");
4483 FAILED(buf2[3] != 1, "test46 case 28 failed\n");
4484 FAILED(buf2[4] != -123, "test46 case 29 failed\n");
4485 FAILED(buf2[5] != -14, "test46 case 30 failed\n");
4487 sljit_free_code(code.code, NULL);
4488 successful_tests++;
4491 static void test47(void)
4493 /* Test jump optimizations. */
4494 executable_code code;
4495 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
4496 sljit_sw buf[3];
4498 if (verbose)
4499 printf("Run test47\n");
4501 FAILED(!compiler, "cannot create compiler\n");
4502 buf[0] = 0;
4503 buf[1] = 0;
4504 buf[2] = 0;
4506 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 1, 0, 0, 0);
4507 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x3a5c6f);
4508 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_R0, 0, SLJIT_IMM, 3);
4509 sljit_set_target(sljit_emit_jump(compiler, SLJIT_LESS), 0x11223344);
4510 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
4511 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0xd37c10);
4512 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4513 sljit_set_target(sljit_emit_jump(compiler, SLJIT_LESS), SLJIT_W(0x112233445566));
4514 #endif
4515 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
4516 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x59b48e);
4517 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4518 sljit_set_target(sljit_emit_jump(compiler, SLJIT_LESS), SLJIT_W(0x1122334455667788));
4519 #endif
4520 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
4521 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
4523 code.code = sljit_generate_code(compiler);
4524 CHECK(compiler);
4525 sljit_free_compiler(compiler);
4527 FAILED(code.func1((sljit_sw)&buf) != 0x59b48e, "test47 case 1 failed\n");
4528 FAILED(buf[0] != 0x3a5c6f, "test47 case 2 failed\n");
4529 FAILED(buf[1] != 0xd37c10, "test47 case 3 failed\n");
4530 FAILED(buf[2] != 0x59b48e, "test47 case 4 failed\n");
4532 sljit_free_code(code.code, NULL);
4533 successful_tests++;
4536 static void test48(void)
4538 /* Test floating point conversions. */
4539 executable_code code;
4540 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
4541 int i;
4542 sljit_f64 dbuf[10];
4543 sljit_f32 sbuf[10];
4544 sljit_sw wbuf[10];
4545 sljit_s32 ibuf[10];
4547 if (verbose)
4548 printf("Run test48\n");
4550 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
4551 if (verbose)
4552 printf("no fpu available, test48 skipped\n");
4553 successful_tests++;
4554 if (compiler)
4555 sljit_free_compiler(compiler);
4556 return;
4559 FAILED(!compiler, "cannot create compiler\n");
4560 for (i = 0; i < 10; i++) {
4561 dbuf[i] = 0.0;
4562 sbuf[i] = 0.0;
4563 wbuf[i] = 0;
4564 ibuf[i] = 0;
4567 dbuf[0] = 123.5;
4568 dbuf[1] = -367;
4569 dbuf[2] = 917.75;
4571 sbuf[0] = 476.25;
4572 sbuf[1] = -1689.75;
4574 wbuf[0] = 2345;
4576 ibuf[0] = 312;
4577 ibuf[1] = -9324;
4579 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(VOID), 3, 3, 6, 0, 0);
4580 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, (sljit_sw)&dbuf);
4581 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, (sljit_sw)&sbuf);
4582 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, (sljit_sw)&wbuf);
4583 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, (sljit_sw)&ibuf);
4585 /* sbuf[2] */
4586 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_F64, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_S0), 0);
4587 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S0), 0);
4588 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 3);
4589 /* sbuf[3] */
4590 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_F64, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_F32_SHIFT, SLJIT_FR5, 0);
4591 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_F32, SLJIT_FR4, 0, SLJIT_MEM1(SLJIT_S1), 0);
4592 /* dbuf[3] */
4593 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f64), SLJIT_FR4, 0);
4594 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR3, 0, SLJIT_MEM1(SLJIT_S1), 0);
4595 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_F32, SLJIT_FR2, 0, SLJIT_FR3, 0);
4596 /* dbuf[4] */
4597 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f64), SLJIT_FR2, 0);
4598 /* sbuf[4] */
4599 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_f32), SLJIT_FR3, 0);
4601 /* wbuf[1] */
4602 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F64, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
4603 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2);
4604 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F64, SLJIT_R0, 0, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_F64_SHIFT);
4605 /* wbuf[2] */
4606 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
4607 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR5, 0, SLJIT_MEM1(SLJIT_S1), 0);
4608 /* wbuf[3] */
4609 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F32, SLJIT_MEM1(SLJIT_S2), 3 * sizeof(sljit_sw), SLJIT_FR5, 0);
4610 sljit_emit_fop1(compiler, SLJIT_NEG_F32, SLJIT_FR0, 0, SLJIT_FR5, 0);
4611 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 4);
4612 /* wbuf[4] */
4613 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F32, SLJIT_MEM2(SLJIT_S2, SLJIT_R1), SLJIT_WORD_SHIFT, SLJIT_FR0, 0);
4614 sljit_emit_fop1(compiler, SLJIT_NEG_F64, SLJIT_FR4, 0, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64));
4615 /* ibuf[2] */
4616 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F64, SLJIT_MEM1(SLJIT_R2), 2 * sizeof(sljit_s32), SLJIT_FR4, 0);
4617 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f32));
4618 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F32, SLJIT_R0, 0, SLJIT_FR1, 0);
4619 /* ibuf[3] */
4620 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_MEM1(SLJIT_R2), 3 * sizeof(sljit_s32), SLJIT_R0, 0);
4622 /* dbuf[5] */
4623 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_S2), 0);
4624 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_FR2, 0, SLJIT_IMM, -6213);
4625 /* dbuf[6] */
4626 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64), SLJIT_FR2, 0);
4627 /* dbuf[7] */
4628 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_S32, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_f64), SLJIT_MEM0(), (sljit_sw)&ibuf[0]);
4629 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_R2), sizeof(sljit_s32));
4630 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_S32, SLJIT_FR1, 0, SLJIT_R0, 0);
4631 /* dbuf[8] */
4632 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_f64), SLJIT_FR1, 0);
4633 /* dbuf[9] */
4634 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_MEM0(), (sljit_sw)(dbuf + 9), SLJIT_IMM, -77);
4635 /* sbuf[5] */
4636 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_SW, SLJIT_MEM1(SLJIT_S1), 5 * sizeof(sljit_f32), SLJIT_IMM, -123);
4637 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 7190);
4638 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_SW, SLJIT_FR3, 0, SLJIT_R0, 0);
4639 /* sbuf[6] */
4640 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 6 * sizeof(sljit_f32), SLJIT_FR3, 0);
4641 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 123);
4642 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R1, 0, SLJIT_R2, 0, SLJIT_IMM, 123 * sizeof(sljit_s32));
4643 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_S32, SLJIT_FR1, 0, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 2);
4644 /* sbuf[7] */
4645 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 7 * sizeof(sljit_f32), SLJIT_FR1, 0);
4646 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
4647 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 3812);
4648 /* sbuf[8] */
4649 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_S32, SLJIT_MEM2(SLJIT_S1, SLJIT_R0), SLJIT_F32_SHIFT, SLJIT_R1, 0);
4650 /* sbuf[9] */
4651 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_SW, SLJIT_MEM0(), (sljit_sw)(sbuf + 9), SLJIT_IMM, -79);
4653 sljit_emit_return_void(compiler);
4655 code.code = sljit_generate_code(compiler);
4656 CHECK(compiler);
4657 sljit_free_compiler(compiler);
4659 code.func0();
4660 FAILED(dbuf[3] != 476.25, "test48 case 1 failed\n");
4661 FAILED(dbuf[4] != 476.25, "test48 case 2 failed\n");
4662 FAILED(dbuf[5] != 2345.0, "test48 case 3 failed\n");
4663 FAILED(dbuf[6] != -6213.0, "test48 case 4 failed\n");
4664 FAILED(dbuf[7] != 312.0, "test48 case 5 failed\n");
4665 FAILED(dbuf[8] != -9324.0, "test48 case 6 failed\n");
4666 FAILED(dbuf[9] != -77.0, "test48 case 7 failed\n");
4668 FAILED(sbuf[2] != 123.5, "test48 case 8 failed\n");
4669 FAILED(sbuf[3] != 123.5, "test48 case 9 failed\n");
4670 FAILED(sbuf[4] != 476.25, "test48 case 10 failed\n");
4671 FAILED(sbuf[5] != -123, "test48 case 11 failed\n");
4672 FAILED(sbuf[6] != 7190, "test48 case 12 failed\n");
4673 FAILED(sbuf[7] != 312, "test48 case 13 failed\n");
4674 FAILED(sbuf[8] != 3812, "test48 case 14 failed\n");
4675 FAILED(sbuf[9] != -79.0, "test48 case 15 failed\n");
4677 FAILED(wbuf[1] != -367, "test48 case 16 failed\n");
4678 FAILED(wbuf[2] != 917, "test48 case 17 failed\n");
4679 FAILED(wbuf[3] != 476, "test48 case 18 failed\n");
4680 FAILED(wbuf[4] != -476, "test48 case 19 failed\n");
4682 FAILED(ibuf[2] != -917, "test48 case 20 failed\n");
4683 FAILED(ibuf[3] != -1689, "test48 case 21 failed\n");
4685 sljit_free_code(code.code, NULL);
4686 successful_tests++;
4689 static void test49(void)
4691 /* Test floating point conversions. */
4692 executable_code code;
4693 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
4694 int i;
4695 sljit_f64 dbuf[10];
4696 sljit_f32 sbuf[9];
4697 sljit_sw wbuf[9];
4698 sljit_s32 ibuf[9];
4699 sljit_s32* dbuf_ptr = (sljit_s32*)dbuf;
4700 sljit_s32* sbuf_ptr = (sljit_s32*)sbuf;
4702 if (verbose)
4703 printf("Run test49\n");
4705 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
4706 if (verbose)
4707 printf("no fpu available, test49 skipped\n");
4708 successful_tests++;
4709 if (compiler)
4710 sljit_free_compiler(compiler);
4711 return;
4714 FAILED(!compiler, "cannot create compiler\n");
4716 for (i = 0; i < 9; i++) {
4717 dbuf_ptr[i << 1] = -1;
4718 dbuf_ptr[(i << 1) + 1] = -1;
4719 sbuf_ptr[i] = -1;
4720 wbuf[i] = -1;
4721 ibuf[i] = -1;
4724 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4725 dbuf[9] = (sljit_f64)SLJIT_W(0x1122334455);
4726 #endif
4727 dbuf[0] = 673.75;
4728 sbuf[0] = -879.75;
4729 wbuf[0] = 345;
4730 ibuf[0] = -249;
4732 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(VOID), 3, 3, 3, 0, 0);
4733 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, (sljit_sw)&dbuf);
4734 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, (sljit_sw)&sbuf);
4735 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, (sljit_sw)&wbuf);
4736 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, (sljit_sw)&ibuf);
4738 /* dbuf[2] */
4739 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_F32, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_S1), 0);
4740 /* sbuf[2] */
4741 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_F64, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_S0), 0);
4742 /* wbuf[2] */
4743 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F64, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S0), 0);
4744 /* wbuf[4] */
4745 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F32, SLJIT_MEM1(SLJIT_S2), 4 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_S1), 0);
4746 /* ibuf[2] */
4747 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F64, SLJIT_MEM1(SLJIT_R2), 2 * sizeof(sljit_s32), SLJIT_MEM1(SLJIT_S0), 0);
4748 /* ibuf[4] */
4749 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F32, SLJIT_MEM1(SLJIT_R2), 4 * sizeof(sljit_s32), SLJIT_MEM1(SLJIT_S1), 0);
4750 /* dbuf[4] */
4751 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_S2), 0);
4752 /* sbuf[4] */
4753 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_SW, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_S2), 0);
4754 /* dbuf[6] */
4755 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_S32, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64), SLJIT_MEM1(SLJIT_R2), 0);
4756 /* sbuf[6] */
4757 sljit_emit_fop1(compiler, SLJIT_CONV_F32_FROM_S32, SLJIT_MEM1(SLJIT_S1), 6 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_R2), 0);
4759 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4760 sljit_emit_fop1(compiler, SLJIT_CONV_SW_FROM_F64, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f64));
4761 /* wbuf[8] */
4762 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S2), 8 * sizeof(sljit_sw), SLJIT_R0, 0);
4763 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f64));
4764 sljit_emit_fop1(compiler, SLJIT_CONV_S32_FROM_F64, SLJIT_R0, 0, SLJIT_FR2, 0);
4765 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_R0, 0);
4766 sljit_emit_op2(compiler, SLJIT_AND32, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 0xffff);
4767 /* ibuf[8] */
4768 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_R2), 8 * sizeof(sljit_s32), SLJIT_R0, 0);
4769 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_W(0x4455667788));
4770 /* dbuf[8] */
4771 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_SW, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_f64), SLJIT_R0, 0);
4772 /* dbuf[9] */
4773 sljit_emit_fop1(compiler, SLJIT_CONV_F64_FROM_S32, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_f64), SLJIT_IMM, SLJIT_W(0x7766554433));
4774 #endif
4776 sljit_emit_return_void(compiler);
4778 code.code = sljit_generate_code(compiler);
4779 CHECK(compiler);
4780 sljit_free_compiler(compiler);
4782 code.func0();
4784 FAILED(dbuf_ptr[(1 * 2) + 0] != -1, "test49 case 1 failed\n");
4785 FAILED(dbuf_ptr[(1 * 2) + 1] != -1, "test49 case 2 failed\n");
4786 FAILED(dbuf[2] != -879.75, "test49 case 3 failed\n");
4787 FAILED(dbuf_ptr[(3 * 2) + 0] != -1, "test49 case 4 failed\n");
4788 FAILED(dbuf_ptr[(3 * 2) + 1] != -1, "test49 case 5 failed\n");
4789 FAILED(dbuf[4] != 345, "test49 case 6 failed\n");
4790 FAILED(dbuf_ptr[(5 * 2) + 0] != -1, "test49 case 7 failed\n");
4791 FAILED(dbuf_ptr[(5 * 2) + 1] != -1, "test49 case 8 failed\n");
4792 FAILED(dbuf[6] != -249, "test49 case 9 failed\n");
4793 FAILED(dbuf_ptr[(7 * 2) + 0] != -1, "test49 case 10 failed\n");
4794 FAILED(dbuf_ptr[(7 * 2) + 1] != -1, "test49 case 11 failed\n");
4796 FAILED(sbuf_ptr[1] != -1, "test49 case 12 failed\n");
4797 FAILED(sbuf[2] != 673.75, "test49 case 13 failed\n");
4798 FAILED(sbuf_ptr[3] != -1, "test49 case 14 failed\n");
4799 FAILED(sbuf[4] != 345, "test49 case 15 failed\n");
4800 FAILED(sbuf_ptr[5] != -1, "test49 case 16 failed\n");
4801 FAILED(sbuf[6] != -249, "test49 case 17 failed\n");
4802 FAILED(sbuf_ptr[7] != -1, "test49 case 18 failed\n");
4804 FAILED(wbuf[1] != -1, "test49 case 19 failed\n");
4805 FAILED(wbuf[2] != 673, "test49 case 20 failed\n");
4806 FAILED(wbuf[3] != -1, "test49 case 21 failed\n");
4807 FAILED(wbuf[4] != -879, "test49 case 22 failed\n");
4808 FAILED(wbuf[5] != -1, "test49 case 23 failed\n");
4810 FAILED(ibuf[1] != -1, "test49 case 24 failed\n");
4811 FAILED(ibuf[2] != 673, "test49 case 25 failed\n");
4812 FAILED(ibuf[3] != -1, "test49 case 26 failed\n");
4813 FAILED(ibuf[4] != -879, "test49 case 27 failed\n");
4814 FAILED(ibuf[5] != -1, "test49 case 28 failed\n");
4816 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
4817 FAILED(dbuf[8] != (sljit_f64)SLJIT_W(0x4455667788), "test49 case 29 failed\n");
4818 FAILED(dbuf[9] != (sljit_f64)SLJIT_W(0x66554433), "test49 case 30 failed\n");
4819 FAILED(wbuf[8] != SLJIT_W(0x1122334455), "test48 case 31 failed\n");
4820 FAILED(ibuf[8] == 0x4455, "test48 case 32 failed\n");
4821 #endif
4823 sljit_free_code(code.code, NULL);
4824 successful_tests++;
4827 static void test50(void)
4829 /* Test stack and floating point operations. */
4830 executable_code code;
4831 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
4832 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4833 sljit_uw size1, size2, size3;
4834 int result;
4835 #endif
4836 sljit_f32 sbuf[7];
4838 if (verbose)
4839 printf("Run test50\n");
4841 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
4842 if (verbose)
4843 printf("no fpu available, test50 skipped\n");
4844 successful_tests++;
4845 if (compiler)
4846 sljit_free_compiler(compiler);
4847 return;
4850 FAILED(!compiler, "cannot create compiler\n");
4852 sbuf[0] = 245.5;
4853 sbuf[1] = -100.25;
4854 sbuf[2] = 713.75;
4856 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 3, 3, 6, 0, 8 * sizeof(sljit_f32));
4858 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_MEM1(SLJIT_S0), 0);
4859 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), 0);
4860 /* sbuf[3] */
4861 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), sizeof(sljit_f32));
4862 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_f32), SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f32));
4863 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));
4864 /* sbuf[4] */
4865 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), 2 * sizeof(sljit_f32));
4866 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 2 * sizeof(sljit_f32), SLJIT_IMM, 5934);
4867 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));
4868 /* sbuf[5] */
4869 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f32), SLJIT_MEM1(SLJIT_SP), 3 * sizeof(sljit_f32));
4871 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4872 size1 = compiler->size;
4873 #endif
4874 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f32));
4875 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4876 size2 = compiler->size;
4877 #endif
4878 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR5, 0, SLJIT_FR2, 0);
4879 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4880 size3 = compiler->size;
4881 #endif
4882 /* sbuf[6] */
4883 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f32), SLJIT_FR5, 0);
4884 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4885 result = (compiler->size - size3) == (size3 - size2) && (size3 - size2) == (size2 - size1);
4886 #endif
4888 sljit_emit_return_void(compiler);
4890 code.code = sljit_generate_code(compiler);
4891 CHECK(compiler);
4892 sljit_free_compiler(compiler);
4894 code.func1((sljit_sw)&sbuf);
4896 FAILED(sbuf[3] != 245.5, "test50 case 1 failed\n");
4897 FAILED(sbuf[4] != 145.25, "test50 case 2 failed\n");
4898 FAILED(sbuf[5] != 5934, "test50 case 3 failed\n");
4899 FAILED(sbuf[6] != 713.75, "test50 case 4 failed\n");
4900 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
4901 FAILED(!result, "test50 case 5 failed\n");
4902 #endif
4904 sljit_free_code(code.code, NULL);
4905 successful_tests++;
4908 static void test51(void)
4910 /* Test all registers provided by the CPU. */
4911 executable_code code;
4912 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
4913 struct sljit_jump* jump;
4914 sljit_sw buf[2];
4915 sljit_s32 i;
4917 if (verbose)
4918 printf("Run test51\n");
4920 FAILED(!compiler, "cannot create compiler\n");
4922 buf[0] = 39;
4924 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(VOID), SLJIT_NUMBER_OF_REGISTERS, 0, 0, 0, 0);
4926 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4927 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 32);
4929 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)buf);
4930 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
4932 for (i = 2; i < SLJIT_NUMBER_OF_REGISTERS; i++) {
4933 if (sljit_get_register_index(SLJIT_R(i)) >= 0) {
4934 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_R0, 0);
4935 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_R(i)), 0);
4936 } else
4937 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, buf[0]);
4940 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 32);
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_R0, 0);
4944 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM1(SLJIT_R(i)), 32);
4945 } else
4946 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, buf[0]);
4949 for (i = 2; i < SLJIT_NUMBER_OF_REGISTERS; i++) {
4950 if (sljit_get_register_index(SLJIT_R(i)) >= 0) {
4951 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 32);
4952 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM2(SLJIT_R(i), SLJIT_R0), 0);
4953 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM2(SLJIT_R0, SLJIT_R(i)), 0);
4954 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 8);
4955 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_MEM2(SLJIT_R0, SLJIT_R(i)), 2);
4956 } else
4957 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_IMM, 3 * buf[0]);
4960 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 32 + sizeof(sljit_sw), SLJIT_R1, 0);
4962 sljit_emit_return_void(compiler);
4964 code.code = sljit_generate_code(compiler);
4965 CHECK(compiler);
4966 sljit_free_compiler(compiler);
4968 code.func0();
4970 FAILED(buf[1] != (39 * 5 * (SLJIT_NUMBER_OF_REGISTERS - 2)), "test51 case 1 failed\n");
4972 sljit_free_code(code.code, NULL);
4974 /* Next test. */
4976 compiler = sljit_create_compiler(NULL, NULL);
4978 FAILED(!compiler, "cannot create compiler\n");
4980 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(W), SLJIT_NUMBER_OF_SCRATCH_REGISTERS, SLJIT_NUMBER_OF_SAVED_REGISTERS, 0, 0, 0);
4982 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4983 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 17);
4985 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS0(W));
4986 /* SLJIT_R0 contains the first value. */
4987 for (i = 1; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4988 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R(i), 0);
4990 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
4992 sljit_set_label(jump, sljit_emit_label(compiler));
4993 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(VOID), SLJIT_NUMBER_OF_REGISTERS, 0, 0, 0, 0);
4994 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
4995 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 35);
4996 sljit_emit_return_void(compiler);
4998 code.code = sljit_generate_code(compiler);
4999 CHECK(compiler);
5000 sljit_free_compiler(compiler);
5002 FAILED(code.func0() != (SLJIT_NUMBER_OF_SCRATCH_REGISTERS * 35 + SLJIT_NUMBER_OF_SAVED_REGISTERS * 17), "test51 case 2 failed\n");
5004 sljit_free_code(code.code, NULL);
5006 /* Next test. */
5008 compiler = sljit_create_compiler(NULL, NULL);
5010 FAILED(!compiler, "cannot create compiler\n");
5012 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(W), SLJIT_NUMBER_OF_SCRATCH_REGISTERS, SLJIT_NUMBER_OF_SAVED_REGISTERS, 0, 0, 0);
5014 for (i = 0; i < SLJIT_NUMBER_OF_SCRATCH_REGISTERS; i++)
5015 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 68);
5016 for (i = 0; i < SLJIT_NUMBER_OF_SAVED_REGISTERS; i++)
5017 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S(i), 0, SLJIT_IMM, 68);
5019 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS0(W));
5020 /* SLJIT_R0 contains the first value. */
5021 for (i = 1; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5022 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R(i), 0);
5024 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
5026 sljit_set_label(jump, sljit_emit_label(compiler));
5027 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(VOID), SLJIT_NUMBER_OF_REGISTERS, 0, 0, 0, 0);
5028 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5029 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 43);
5030 sljit_emit_return_void(compiler);
5032 code.code = sljit_generate_code(compiler);
5033 CHECK(compiler);
5034 sljit_free_compiler(compiler);
5036 FAILED(code.func0() != (SLJIT_NUMBER_OF_SCRATCH_REGISTERS * 43 + SLJIT_NUMBER_OF_SAVED_REGISTERS * 68), "test51 case 3 failed\n");
5038 sljit_free_code(code.code, NULL);
5039 successful_tests++;
5042 static void test52(void)
5044 /* Test all registers provided by the CPU. */
5045 executable_code code;
5046 struct sljit_compiler* compiler;
5047 struct sljit_jump* jump;
5048 sljit_f64 buf[3];
5049 sljit_s32 i;
5051 if (verbose)
5052 printf("Run test52\n");
5054 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5055 if (verbose)
5056 printf("no fpu available, test52 skipped\n");
5057 successful_tests++;
5058 return;
5061 /* Next test. */
5063 compiler = sljit_create_compiler(NULL, NULL);
5064 FAILED(!compiler, "cannot create compiler\n");
5065 buf[0] = 6.25;
5066 buf[1] = 17.75;
5068 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 0, 1, SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS, SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS, 0);
5070 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5071 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR(i), 0, SLJIT_MEM1(SLJIT_S0), 0);
5073 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS0(VOID));
5074 /* SLJIT_FR0 contains the first value. */
5075 for (i = 1; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5076 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR0, 0, SLJIT_FR0, 0, SLJIT_FR(i), 0);
5077 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64), SLJIT_FR0, 0);
5079 sljit_emit_return_void(compiler);
5081 sljit_set_label(jump, sljit_emit_label(compiler));
5082 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(VOID), 1, 0, SLJIT_NUMBER_OF_FLOAT_REGISTERS, 0, 0);
5083 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[1]);
5084 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5085 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR(i), 0, SLJIT_MEM1(SLJIT_R0), 0);
5086 sljit_emit_return_void(compiler);
5088 code.code = sljit_generate_code(compiler);
5089 CHECK(compiler);
5090 sljit_free_compiler(compiler);
5092 code.func1((sljit_sw)&buf);
5093 FAILED(buf[2] != (SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS * 17.75 + SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS * 6.25), "test52 case 1 failed\n");
5095 sljit_free_code(code.code, NULL);
5097 /* Next test. */
5099 compiler = sljit_create_compiler(NULL, NULL);
5100 FAILED(!compiler, "cannot create compiler\n");
5101 buf[0] = -32.5;
5102 buf[1] = -11.25;
5104 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 0, 1, SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS, SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS, 0);
5106 for (i = 0; i < SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS; i++)
5107 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR(i), 0, SLJIT_MEM1(SLJIT_S0), 0);
5108 for (i = 0; i < SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS; i++)
5109 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FS(i), 0, SLJIT_MEM1(SLJIT_S0), 0);
5111 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS0(VOID));
5112 /* SLJIT_FR0 contains the first value. */
5113 for (i = 1; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5114 sljit_emit_fop2(compiler, SLJIT_ADD_F64, SLJIT_FR0, 0, SLJIT_FR0, 0, SLJIT_FR(i), 0);
5115 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64), SLJIT_FR0, 0);
5117 sljit_emit_return_void(compiler);
5119 sljit_set_label(jump, sljit_emit_label(compiler));
5120 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(VOID), 1, 0, SLJIT_NUMBER_OF_FLOAT_REGISTERS, 0, 0);
5121 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[1]);
5122 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
5123 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR(i), 0, SLJIT_MEM1(SLJIT_R0), 0);
5124 sljit_emit_return_void(compiler);
5126 code.code = sljit_generate_code(compiler);
5127 CHECK(compiler);
5128 sljit_free_compiler(compiler);
5130 code.func1((sljit_sw)&buf);
5131 FAILED(buf[2] != (SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS * -11.25 + SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS * -32.5), "test52 case 2 failed\n");
5133 sljit_free_code(code.code, NULL);
5134 successful_tests++;
5137 static void test53(void)
5139 /* Check SLJIT_DOUBLE_ALIGNMENT. */
5140 executable_code code;
5141 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
5142 sljit_sw buf[1];
5144 if (verbose)
5145 printf("Run test53\n");
5147 FAILED(!compiler, "cannot create compiler\n");
5148 buf[0] = -1;
5150 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, SLJIT_ARGS1(VOID, P), 1, 1, 0, 0, 2 * sizeof(sljit_sw));
5152 sljit_get_local_base(compiler, SLJIT_R0, 0, 0);
5153 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
5155 sljit_emit_return_void(compiler);
5157 code.code = sljit_generate_code(compiler);
5158 CHECK(compiler);
5159 sljit_free_compiler(compiler);
5161 code.func1((sljit_sw)&buf);
5163 FAILED((buf[0] & ((sljit_sw)sizeof(sljit_f64) - 1)) != 0, "test53 case 1 failed\n");
5165 sljit_free_code(code.code, NULL);
5167 /* Next test. */
5169 compiler = sljit_create_compiler(NULL, NULL);
5170 FAILED(!compiler, "cannot create compiler\n");
5171 buf[0] = -1;
5173 /* One more saved register to break the alignment on x86-32. */
5174 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, SLJIT_ARGS1(VOID, P), 1, 2, 0, 0, 2 * sizeof(sljit_sw));
5176 sljit_get_local_base(compiler, SLJIT_R0, 0, 0);
5177 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
5179 sljit_emit_return_void(compiler);
5181 code.code = sljit_generate_code(compiler);
5182 CHECK(compiler);
5183 sljit_free_compiler(compiler);
5185 code.func1((sljit_sw)&buf);
5187 FAILED((buf[0] & ((sljit_sw)sizeof(sljit_f64) - 1)) != 0, "test53 case 2 failed\n");
5189 sljit_free_code(code.code, NULL);
5190 successful_tests++;
5193 static void test54(void)
5195 /* Check cmov. */
5196 executable_code code;
5197 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
5198 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
5199 sljit_sw large_num = SLJIT_W(0x1234567812345678);
5200 #else
5201 sljit_sw large_num = SLJIT_W(0x12345678);
5202 #endif
5203 int i;
5204 sljit_sw buf[19];
5205 sljit_s32 ibuf[4];
5207 union {
5208 sljit_f32 value;
5209 sljit_s32 s32_value;
5210 } sbuf[3];
5212 sbuf[0].s32_value = 0x7fffffff;
5213 sbuf[1].value = 7.5;
5214 sbuf[2].value = -14.75;
5216 if (verbose)
5217 printf("Run test54\n");
5219 FAILED(!compiler, "cannot create compiler\n");
5221 for (i = 0; i < 19; i++)
5222 buf[i] = 0;
5223 for (i = 0; i < 4; i++)
5224 ibuf[i] = 0;
5226 sljit_emit_enter(compiler, 0, SLJIT_ARGS3(VOID, P, P, P), 5, 3, 3, 0, 0);
5228 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 17);
5229 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 34);
5230 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R0, 0, SLJIT_IMM, -10);
5231 sljit_emit_cmov(compiler, SLJIT_SIG_LESS, SLJIT_R0, SLJIT_R1, 0);
5232 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
5233 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_R0, 0, SLJIT_IMM, -10);
5234 sljit_emit_cmov(compiler, SLJIT_SIG_GREATER, SLJIT_R0, SLJIT_R1, 0);
5235 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
5237 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 24);
5238 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_IMM, 24);
5239 sljit_emit_cmov(compiler, SLJIT_NOT_EQUAL, SLJIT_R0, SLJIT_IMM, 66);
5240 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
5241 sljit_emit_cmov(compiler, SLJIT_EQUAL, SLJIT_R0, SLJIT_IMM, 78);
5242 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_R0, 0);
5243 sljit_emit_cmov(compiler, SLJIT_EQUAL, SLJIT_R0, SLJIT_IMM, large_num);
5244 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
5246 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
5247 SLJIT_ASSERT(sljit_get_register_index(SLJIT_R3) == -1 && sljit_get_register_index(SLJIT_R4) == -1);
5248 #endif
5249 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 7);
5250 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -45);
5251 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 8);
5252 sljit_emit_cmov(compiler, SLJIT_OVERFLOW, SLJIT_R3, SLJIT_IMM, 35);
5253 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R3, 0);
5254 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, large_num);
5255 sljit_emit_op2u(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_IMM, large_num);
5256 sljit_emit_cmov(compiler, SLJIT_OVERFLOW, SLJIT_R3, SLJIT_IMM, 35);
5257 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_R3, 0);
5259 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 71);
5260 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 13);
5261 sljit_emit_op2(compiler, SLJIT_LSHR | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, 8);
5262 sljit_emit_cmov(compiler, SLJIT_EQUAL, SLJIT_R3, SLJIT_R0, 0);
5263 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R3, 0);
5265 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 12);
5266 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -29);
5267 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 8);
5268 sljit_emit_cmov(compiler, SLJIT_NOT_OVERFLOW, SLJIT_R0, SLJIT_R3, 0);
5269 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R3, 0);
5271 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 16);
5272 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -12);
5273 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R4, 0, SLJIT_IMM, 21);
5274 sljit_emit_op2u(compiler, SLJIT_AND | SLJIT_SET_Z, SLJIT_R0, 0, SLJIT_IMM, 8);
5275 sljit_emit_cmov(compiler, SLJIT_NOT_EQUAL, SLJIT_R3, SLJIT_R4, 0);
5276 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_R3, 0);
5277 sljit_emit_cmov(compiler, SLJIT_EQUAL, SLJIT_R3, SLJIT_R4, 0);
5278 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_R3, 0);
5280 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5281 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S2), 0);
5282 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f32));
5283 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_f32));
5285 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 16);
5286 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
5287 sljit_emit_cmov(compiler, SLJIT_EQUAL_F32, SLJIT_R0, SLJIT_IMM, -45);
5288 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_R0, 0);
5289 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_GREATER_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
5290 sljit_emit_cmov(compiler, SLJIT_GREATER_F32, SLJIT_R0, SLJIT_IMM, -45);
5291 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_R0, 0);
5292 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_GREATER_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
5293 sljit_emit_cmov(compiler, SLJIT_GREATER_EQUAL_F32, SLJIT_R0, SLJIT_IMM, 33);
5294 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_R0, 0);
5296 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
5297 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_LESS_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
5298 sljit_emit_cmov(compiler, SLJIT_LESS_F32, SLJIT_R0, SLJIT_IMM, -70);
5299 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_sw), SLJIT_R0, 0);
5300 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_LESS_EQUAL_F, SLJIT_FR2, 0, SLJIT_FR1, 0);
5301 sljit_emit_cmov(compiler, SLJIT_LESS_EQUAL_F32, SLJIT_R0, SLJIT_IMM, -60);
5302 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 15 * sizeof(sljit_sw), SLJIT_R0, 0);
5303 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_NOT_EQUAL_F, SLJIT_FR1, 0, SLJIT_FR2, 0);
5304 sljit_emit_cmov(compiler, SLJIT_NOT_EQUAL_F32, SLJIT_R0, SLJIT_IMM, 31);
5305 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 16 * sizeof(sljit_sw), SLJIT_R0, 0);
5307 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 53);
5308 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_ORDERED_F, SLJIT_FR1, 0, SLJIT_FR0, 0);
5309 sljit_emit_cmov(compiler, SLJIT_ORDERED_F32, SLJIT_R0, SLJIT_IMM, 17);
5310 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 17 * sizeof(sljit_sw), SLJIT_R0, 0);
5311 sljit_emit_fop1(compiler, SLJIT_CMP_F32 | SLJIT_SET_UNORDERED_F, SLJIT_FR1, 0, SLJIT_FR0, 0);
5312 sljit_emit_cmov(compiler, SLJIT_UNORDERED_F32, SLJIT_R0, SLJIT_IMM, 59);
5313 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 18 * sizeof(sljit_sw), SLJIT_R0, 0);
5316 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 177);
5317 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_LESS, SLJIT_R0, 0, SLJIT_IMM, 178);
5318 sljit_emit_cmov(compiler, SLJIT_LESS, SLJIT_R0 | SLJIT_32, SLJIT_IMM, 200);
5319 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S1), 0, SLJIT_R0, 0);
5321 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 95);
5322 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R3, 0, SLJIT_IMM, 177);
5323 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_LESS_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 95);
5324 sljit_emit_cmov(compiler, SLJIT_LESS_EQUAL, SLJIT_R3 | SLJIT_32, SLJIT_R0, 0);
5325 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 0);
5326 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_s32), SLJIT_R3, 0);
5328 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R3, 0, SLJIT_IMM, 56);
5329 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R4, 0, SLJIT_IMM, -63);
5330 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_SIG_LESS, SLJIT_R3, 0, SLJIT_R4, 0);
5331 sljit_emit_cmov(compiler, SLJIT_SIG_LESS, SLJIT_R3 | SLJIT_32, SLJIT_R4, 0);
5332 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_s32), SLJIT_R3, 0);
5333 sljit_emit_op2u(compiler, SLJIT_SUB32 | SLJIT_SET_SIG_GREATER, SLJIT_R3, 0, SLJIT_R4, 0);
5334 sljit_emit_cmov(compiler, SLJIT_SIG_GREATER, SLJIT_R3 | SLJIT_32, SLJIT_R4, 0);
5335 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_s32), SLJIT_R3, 0);
5337 sljit_emit_return_void(compiler);
5339 code.code = sljit_generate_code(compiler);
5340 CHECK(compiler);
5341 sljit_free_compiler(compiler);
5343 code.func3((sljit_sw)&buf, (sljit_sw)&ibuf, (sljit_sw)&sbuf);
5345 FAILED(buf[0] != 17, "test54 case 1 failed\n");
5346 FAILED(buf[1] != 34, "test54 case 2 failed\n");
5347 FAILED(buf[2] != 24, "test54 case 3 failed\n");
5348 FAILED(buf[3] != 78, "test54 case 4 failed\n");
5349 FAILED(buf[4] != large_num, "test54 case 5 failed\n");
5350 FAILED(buf[5] != -45, "test54 case 6 failed\n");
5351 FAILED(buf[6] != 35, "test54 case 7 failed\n");
5352 FAILED(buf[7] != 71, "test54 case 8 failed\n");
5353 FAILED(buf[8] != -29, "test54 case 9 failed\n");
5354 FAILED(buf[9] != -12, "test54 case 10 failed\n");
5355 FAILED(buf[10] != 21, "test54 case 11 failed\n");
5357 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5358 FAILED(buf[11] != 16, "test54 case 12 failed\n");
5359 FAILED(buf[12] != -45, "test54 case 13 failed\n");
5360 FAILED(buf[13] != 33, "test54 case 14 failed\n");
5361 FAILED(buf[14] != 8, "test54 case 15 failed\n");
5362 FAILED(buf[15] != -60, "test54 case 16 failed\n");
5363 FAILED(buf[16] != 31, "test54 case 17 failed\n");
5364 FAILED(buf[17] != 53, "test54 case 18 failed\n");
5365 FAILED(buf[18] != 59, "test54 case 19 failed\n");
5368 FAILED(ibuf[0] != 200, "test54 case 12 failed\n");
5369 FAILED(ibuf[1] != 95, "test54 case 13 failed\n");
5370 FAILED(ibuf[2] != 56, "test54 case 14 failed\n");
5371 FAILED(ibuf[3] != -63, "test54 case 15 failed\n");
5373 sljit_free_code(code.code, NULL);
5374 successful_tests++;
5377 static void test55(void)
5379 /* Check value preservation. */
5380 executable_code code;
5381 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
5382 sljit_sw buf[2];
5383 sljit_s32 i;
5385 if (verbose)
5386 printf("Run test55\n");
5388 FAILED(!compiler, "cannot create compiler\n");
5389 buf[0] = 0;
5390 buf[1] = 0;
5392 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(VOID), SLJIT_NUMBER_OF_REGISTERS, 0, 0, 0, sizeof (sljit_sw));
5394 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, 217);
5396 /* Check 1 */
5397 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5398 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 118);
5400 sljit_emit_op0(compiler, SLJIT_DIVMOD_SW);
5402 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
5404 for (i = 2; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5405 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R(i), 0);
5406 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_SP), 0);
5408 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM0(), (sljit_sw)(buf + 0), SLJIT_R0, 0);
5410 /* Check 2 */
5411 for (i = 0; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5412 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R(i), 0, SLJIT_IMM, 146);
5414 sljit_emit_op0(compiler, SLJIT_DIV_SW);
5416 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
5418 for (i = 1; i < SLJIT_NUMBER_OF_REGISTERS; i++)
5419 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_R(i), 0);
5420 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_MEM1(SLJIT_SP), 0);
5422 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM0(), (sljit_sw)(buf + 1), SLJIT_R0, 0);
5424 sljit_emit_return_void(compiler);
5426 code.code = sljit_generate_code(compiler);
5427 CHECK(compiler);
5428 sljit_free_compiler(compiler);
5430 code.func0();
5432 FAILED(buf[0] != (SLJIT_NUMBER_OF_REGISTERS - 2) * 118 + 217, "test55 case 1 failed\n");
5433 FAILED(buf[1] != (SLJIT_NUMBER_OF_REGISTERS - 1) * 146 + 217, "test55 case 2 failed\n");
5435 sljit_free_code(code.code, NULL);
5436 successful_tests++;
5439 static void test56(void)
5441 /* Check integer substraction with negative immediate. */
5442 executable_code code;
5443 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
5444 sljit_sw buf[13];
5445 sljit_s32 i;
5447 if (verbose)
5448 printf("Run test56\n");
5450 for (i = 0; i < 13; i++)
5451 buf[i] = 77;
5453 FAILED(!compiler, "cannot create compiler\n");
5455 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 3, 1, 0, 0, 0);
5457 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 90 << 12);
5458 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5459 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R1, 0);
5460 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_SIG_GREATER);
5461 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5462 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R1, 0);
5463 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_LESS);
5464 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER_EQUAL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5465 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_SIG_GREATER_EQUAL);
5466 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS_EQUAL, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5467 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_LESS_EQUAL);
5468 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5469 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_GREATER);
5470 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_LESS, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5471 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_SIG_LESS);
5473 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 90);
5474 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_SIG_GREATER, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, -91);
5475 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R0, 0);
5476 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 9 * sizeof(sljit_sw), SLJIT_SIG_GREATER);
5477 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 90);
5478 sljit_emit_op2(compiler, SLJIT_SUB | SLJIT_SET_LESS_EQUAL, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, -91);
5479 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_LESS_EQUAL);
5481 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, -0x7fffffff);
5482 sljit_emit_op2(compiler, SLJIT_ADD32 | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, -(91 << 12));
5483 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_OVERFLOW);
5485 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, -0x7fffffff-1);
5486 sljit_emit_op1(compiler, SLJIT_NEG32 | SLJIT_SET_OVERFLOW, SLJIT_R0, 0, SLJIT_R0, 0);
5487 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_OVERFLOW);
5489 sljit_emit_return_void(compiler);
5491 code.code = sljit_generate_code(compiler);
5492 CHECK(compiler);
5493 sljit_free_compiler(compiler);
5495 code.func1((sljit_sw)&buf);
5497 FAILED(buf[0] != (181 << 12), "test56 case 1 failed\n");
5498 FAILED(buf[1] != 1, "test56 case 2 failed\n");
5499 FAILED(buf[2] != (181 << 12), "test56 case 3 failed\n");
5500 FAILED(buf[3] != 1, "test56 case 4 failed\n");
5501 FAILED(buf[4] != 1, "test56 case 5 failed\n");
5502 FAILED(buf[5] != 1, "test56 case 6 failed\n");
5503 FAILED(buf[6] != 0, "test56 case 7 failed\n");
5504 FAILED(buf[7] != 0, "test56 case 8 failed\n");
5505 FAILED(buf[8] != 181, "test56 case 9 failed\n");
5506 FAILED(buf[9] != 1, "test56 case 10 failed\n");
5507 FAILED(buf[10] != 1, "test56 case 11 failed\n");
5508 FAILED(buf[11] != 1, "test56 case 12 failed\n");
5509 FAILED(buf[12] != 1, "test56 case 13 failed\n");
5511 sljit_free_code(code.code, NULL);
5512 successful_tests++;
5515 static void test57(void)
5517 /* Check prefetch instructions. */
5518 executable_code code;
5519 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
5520 struct sljit_label* labels[5];
5521 sljit_p addr[5];
5522 int i;
5524 if (verbose)
5525 printf("Run test57\n");
5527 FAILED(!compiler, "cannot create compiler\n");
5529 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(VOID), 3, 1, 0, 0, 0);
5531 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
5532 labels[0] = sljit_emit_label(compiler);
5533 /* Should never crash. */
5534 sljit_emit_op_src(compiler, SLJIT_PREFETCH_L1, SLJIT_MEM2(SLJIT_R0, SLJIT_R0), 2);
5535 labels[1] = sljit_emit_label(compiler);
5536 sljit_emit_op_src(compiler, SLJIT_PREFETCH_L2, SLJIT_MEM0(), 0);
5537 labels[2] = sljit_emit_label(compiler);
5538 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
5539 sljit_emit_op_src(compiler, SLJIT_PREFETCH_L3, SLJIT_MEM1(SLJIT_R0), SLJIT_W(0x1122334455667788));
5540 #else
5541 sljit_emit_op_src(compiler, SLJIT_PREFETCH_L3, SLJIT_MEM1(SLJIT_R0), 0x11223344);
5542 #endif
5543 labels[3] = sljit_emit_label(compiler);
5544 sljit_emit_op_src(compiler, SLJIT_PREFETCH_ONCE, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_sw));
5545 labels[4] = sljit_emit_label(compiler);
5547 sljit_emit_return_void(compiler);
5549 code.code = sljit_generate_code(compiler);
5550 CHECK(compiler);
5552 for (i = 0; i < 5; i++)
5553 addr[i] = sljit_get_label_addr(labels[i]);
5555 sljit_free_compiler(compiler);
5557 code.func0();
5559 if (sljit_has_cpu_feature(SLJIT_HAS_PREFETCH)) {
5560 FAILED(addr[0] == addr[1], "test57 case 1 failed\n");
5561 FAILED(addr[1] == addr[2], "test57 case 2 failed\n");
5562 FAILED(addr[2] == addr[3], "test57 case 3 failed\n");
5563 FAILED(addr[3] == addr[4], "test57 case 4 failed\n");
5565 else {
5566 FAILED(addr[0] != addr[1], "test57 case 1 failed\n");
5567 FAILED(addr[1] != addr[2], "test57 case 2 failed\n");
5568 FAILED(addr[2] != addr[3], "test57 case 3 failed\n");
5569 FAILED(addr[3] != addr[4], "test57 case 4 failed\n");
5572 sljit_free_code(code.code, NULL);
5573 successful_tests++;
5576 static sljit_f64 SLJIT_FUNC test58_f1(sljit_f32 a, sljit_f32 b, sljit_f64 c)
5578 return (sljit_f64)a + (sljit_f64)b + c;
5581 static sljit_f32 SLJIT_FUNC test58_f2(sljit_sw a, sljit_f64 b, sljit_f32 c)
5583 return (sljit_f32)((sljit_f64)a + b + (sljit_f64)c);
5586 static sljit_f64 SLJIT_FUNC test58_f3(sljit_sw a, sljit_f32 b, sljit_sw c)
5588 return (sljit_f64)a + (sljit_f64)b + (sljit_f64)c;
5591 static sljit_f64 test58_f4(sljit_f32 a, sljit_sw b)
5593 return (sljit_f64)a + (sljit_f64)b;
5596 static sljit_f32 test58_f5(sljit_f32 a, sljit_f64 b, sljit_s32 c)
5598 return (sljit_f32)((sljit_f64)a + b + (sljit_f64)c);
5601 static sljit_sw SLJIT_FUNC test58_f6(sljit_f64 a, sljit_sw b)
5603 return (sljit_sw)(a + (sljit_f64)b);
5606 static void test58(void)
5608 /* Check function calls with floating point arguments. */
5609 executable_code code;
5610 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
5611 struct sljit_jump* jump = NULL;
5612 sljit_f64 dbuf[7];
5613 sljit_f32 sbuf[7];
5614 sljit_sw wbuf[2];
5616 if (verbose)
5617 printf("Run test58\n");
5619 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5620 if (verbose)
5621 printf("no fpu available, test58 skipped\n");
5622 successful_tests++;
5623 if (compiler)
5624 sljit_free_compiler(compiler);
5625 return;
5628 dbuf[0] = 5.25;
5629 dbuf[1] = 0.0;
5630 dbuf[2] = 2.5;
5631 dbuf[3] = 0.0;
5632 dbuf[4] = 0.0;
5633 dbuf[5] = 0.0;
5634 dbuf[6] = -18.0;
5636 sbuf[0] = 6.75;
5637 sbuf[1] = -3.5;
5638 sbuf[2] = 1.5;
5639 sbuf[3] = 0.0;
5640 sbuf[4] = 0.0;
5642 wbuf[0] = 0;
5643 wbuf[1] = 0;
5645 FAILED(!compiler, "cannot create compiler\n");
5647 sljit_emit_enter(compiler, 0, SLJIT_ARGS3(VOID, P, P, P), 3, 3, 4, 0, sizeof(sljit_sw));
5649 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), 0);
5650 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f32));
5651 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 0);
5652 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS3(F64, F32, F32, F64), SLJIT_IMM, SLJIT_FUNC_ADDR(test58_f1));
5653 /* dbuf[1] */
5654 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64), SLJIT_FR0, 0);
5656 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f32));
5657 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f32));
5658 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64));
5659 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS3(F64, F32, F32, F64));
5660 sljit_set_target(jump, SLJIT_FUNC_UADDR(test58_f1));
5661 /* dbuf[3] */
5662 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_f64), SLJIT_FR0, 0);
5664 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test58_f2));
5665 sljit_get_local_base(compiler, SLJIT_R1, 0, -16);
5666 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 16);
5667 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 0);
5668 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f32));
5669 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS3(F32, W, F64, F32), SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 0);
5670 /* sbuf[3] */
5671 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f32), SLJIT_FR0, 0);
5673 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -4);
5674 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 9);
5675 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 0);
5676 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), 0);
5677 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS3(F64, W, F32, W));
5678 sljit_set_target(jump, SLJIT_FUNC_UADDR(test58_f3));
5679 /* dbuf[4] */
5680 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_f64), SLJIT_FR0, 0);
5682 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f32));
5683 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -6);
5684 jump = sljit_emit_call(compiler, SLJIT_CALL_CDECL, SLJIT_ARGS2(F64, F32, W));
5685 sljit_set_target(jump, SLJIT_FUNC_UADDR(test58_f4));
5686 /* dbuf[5] */
5687 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_f64), SLJIT_FR0, 0);
5689 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test58_f5));
5690 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f32));
5691 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_f64));
5692 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 8);
5693 sljit_emit_icall(compiler, SLJIT_CALL_CDECL, SLJIT_ARGS3(F32, F32, F64, 32), SLJIT_MEM1(SLJIT_SP), 0);
5694 /* sbuf[4] */
5695 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S1), 4 * sizeof(sljit_f32), SLJIT_FR0, 0);
5697 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64));
5698 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test58_f6));
5699 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS2(W, F64, W), SLJIT_R0, 0);
5700 /* wbuf[0] */
5701 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S2), 0, SLJIT_R0, 0);
5703 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_f64));
5704 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 319);
5705 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test58_f6));
5706 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS2(W, F64, W), SLJIT_R1, 0);
5707 /* wbuf[1] */
5708 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_sw), SLJIT_R0, 0);
5710 sljit_emit_return_void(compiler);
5712 code.code = sljit_generate_code(compiler);
5713 CHECK(compiler);
5714 sljit_free_compiler(compiler);
5716 code.func3((sljit_sw)&dbuf, (sljit_sw)&sbuf, (sljit_sw)&wbuf);
5718 FAILED(dbuf[1] != 8.5, "test58 case 1 failed\n");
5719 FAILED(dbuf[3] != 0.5, "test58 case 2 failed\n");
5720 FAILED(sbuf[3] != 17.75, "test58 case 3 failed\n");
5721 FAILED(dbuf[4] != 11.75, "test58 case 4 failed\n");
5722 FAILED(dbuf[5] != -9.5, "test58 case 5 failed\n");
5723 FAILED(sbuf[4] != 12, "test58 case 6 failed\n");
5724 FAILED(wbuf[0] != SLJIT_FUNC_ADDR(test58_f6) - 18, "test58 case 7 failed\n");
5725 FAILED(wbuf[1] != 301, "test58 case 8 failed\n");
5727 sljit_free_code(code.code, NULL);
5728 successful_tests++;
5731 static sljit_sw SLJIT_FUNC test59_f1(sljit_sw a, sljit_s32 b, sljit_sw c, sljit_sw d)
5733 return (sljit_sw)(a + b + c + d - SLJIT_FUNC_ADDR(test59_f1));
5736 static sljit_sw test59_f2(sljit_sw a, sljit_s32 b, sljit_sw c, sljit_sw d)
5738 return (sljit_sw)(a + b + c + d - SLJIT_FUNC_ADDR(test59_f2));
5741 static sljit_s32 SLJIT_FUNC test59_f3(sljit_f64 a, sljit_f32 b, sljit_f64 c, sljit_sw d)
5743 return (sljit_s32)(a + b + c + (sljit_f64)d);
5746 static sljit_f32 SLJIT_FUNC test59_f4(sljit_f32 a, sljit_s32 b, sljit_f64 c, sljit_sw d)
5748 return (sljit_f32)(a + (sljit_f64)b + c + (sljit_f64)d);
5751 static sljit_f32 SLJIT_FUNC test59_f5(sljit_f32 a, sljit_f64 b, sljit_f32 c, sljit_f64 d)
5753 return (sljit_f32)(a + b + c + (sljit_f64)d);
5756 static void test59(void)
5758 /* Check function calls with four arguments. */
5759 executable_code code;
5760 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
5761 struct sljit_jump* jump = NULL;
5762 sljit_sw wbuf[6];
5763 sljit_f64 dbuf[3];
5764 sljit_f32 sbuf[4];
5766 if (verbose)
5767 printf("Run test59\n");
5769 wbuf[0] = 0;
5770 wbuf[1] = 0;
5771 wbuf[2] = 0;
5772 wbuf[3] = SLJIT_FUNC_ADDR(test59_f1);
5773 wbuf[4] = 0;
5774 wbuf[5] = 0;
5776 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5777 dbuf[0] = 5.125;
5778 dbuf[1] = 6.125;
5779 dbuf[2] = 4.25;
5781 sbuf[0] = 0.75;
5782 sbuf[1] = -1.5;
5783 sbuf[2] = 0.0;
5784 sbuf[3] = 0.0;
5787 FAILED(!compiler, "cannot create compiler\n");
5789 sljit_emit_enter(compiler, 0, SLJIT_ARGS3(VOID, P, P, P), 4, 3, 4, 0, sizeof(sljit_sw));
5791 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 33);
5792 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -20);
5793 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test59_f1));
5794 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -40);
5795 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(W, W, 32, W, W), SLJIT_R2, 0);
5796 /* wbuf[0] */
5797 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
5799 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 16);
5800 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -30);
5801 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 50);
5802 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test59_f2));
5803 sljit_emit_icall(compiler, SLJIT_CALL_CDECL, SLJIT_ARGS4(W, W, 32, W, W), SLJIT_R3, 0);
5804 /* wbuf[1] */
5805 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
5807 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test59_f1));
5808 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -25);
5809 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 100);
5810 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, -10);
5811 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(W, W, 32, W, W), SLJIT_R0, 0);
5812 /* wbuf[2] */
5813 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R0, 0);
5815 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
5816 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 231);
5817 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 3);
5818 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test59_f1) - 100);
5819 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(W, W, 32, W, W), SLJIT_MEM2(SLJIT_R0, SLJIT_R2), SLJIT_WORD_SHIFT);
5820 /* wbuf[4] */
5821 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R0, 0);
5823 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5824 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), 0);
5825 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S2), 0);
5826 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f64));
5827 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -100);
5828 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(32, F64, F32, F64, W), SLJIT_IMM, SLJIT_FUNC_ADDR(test59_f3));
5829 sljit_emit_op1(compiler, SLJIT_MOV_S32, SLJIT_R0, 0, SLJIT_R0, 0);
5830 /* wbuf[5] */
5831 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R0, 0);
5833 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f32));
5834 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f64));
5835 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R0, 0, SLJIT_IMM, 36);
5836 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 41);
5837 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS4(F32, F32, 32, F64, W));
5838 sljit_set_target(jump, SLJIT_FUNC_UADDR(test59_f4));
5839 /* sbuf[2] */
5840 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_f32), SLJIT_FR0, 0);
5842 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test59_f5));
5843 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S2), 0);
5844 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S1), 0);
5845 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f32));
5846 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR3, 0, SLJIT_MEM1(SLJIT_S1), 2 * sizeof(sljit_f64));
5847 sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS4(F32, F32, F64, F32, F64), SLJIT_R0, 0);
5848 /* sbuf[2] */
5849 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S2), 3 * sizeof(sljit_f32), SLJIT_FR0, 0);
5852 sljit_emit_return_void(compiler);
5854 code.code = sljit_generate_code(compiler);
5855 CHECK(compiler);
5856 sljit_free_compiler(compiler);
5858 code.func3((sljit_sw)&wbuf, (sljit_sw)&dbuf, (sljit_sw)&sbuf);
5860 FAILED(wbuf[0] != -27, "test59 case 1 failed\n");
5861 FAILED(wbuf[1] != 36, "test59 case 2 failed\n");
5862 FAILED(wbuf[2] != 65, "test59 case 3 failed\n");
5863 FAILED(wbuf[4] != (sljit_sw)wbuf + 134, "test59 case 4 failed\n");
5865 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
5866 FAILED(wbuf[5] != -88, "test59 case 5 failed\n");
5867 FAILED(sbuf[2] != 79.75, "test59 case 6 failed\n");
5868 FAILED(sbuf[3] != 8.625, "test59 case 7 failed\n");
5871 sljit_free_code(code.code, NULL);
5872 successful_tests++;
5875 static void test60(void)
5877 /* Test memory accesses with pre/post updates. */
5878 executable_code code;
5879 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
5880 sljit_u32 i;
5881 sljit_s32 supported[10];
5882 sljit_sw wbuf[18];
5883 sljit_s8 bbuf[4];
5884 sljit_s32 ibuf[4];
5886 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
5887 static sljit_u8 expected[10] = { 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 };
5888 #elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32)
5889 static sljit_u8 expected[10] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
5890 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32)
5891 static sljit_u8 expected[10] = { 1, 0, 1, 1, 0, 1, 1, 1, 0, 0 };
5892 #elif (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
5893 static sljit_u8 expected[10] = { 1, 0, 0, 1, 0, 0, 1, 1, 0, 0 };
5894 #else
5895 static sljit_u8 expected[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
5896 #endif
5898 if (verbose)
5899 printf("Run test60\n");
5901 for (i = 0; i < 18; i++)
5902 wbuf[i] = 0;
5903 wbuf[2] = -887766;
5905 bbuf[0] = 0;
5906 bbuf[1] = 0;
5907 bbuf[2] = -13;
5909 ibuf[0] = -5678;
5910 ibuf[1] = 0;
5911 ibuf[2] = 0;
5913 FAILED(!compiler, "cannot create compiler\n");
5915 sljit_emit_enter(compiler, 0, SLJIT_ARGS3(VOID, P, P, P), 4, 3, 4, 0, sizeof(sljit_sw));
5917 supported[0] = sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R0), 2 * sizeof(sljit_sw));
5918 if (supported[0] == SLJIT_SUCCESS) {
5919 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
5920 sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R0), 2 * sizeof(sljit_sw));
5921 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R1, 0);
5922 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
5925 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));
5926 if (supported[1] == SLJIT_SUCCESS) {
5927 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S1, 0, SLJIT_IMM, 2 * sizeof(sljit_s8));
5928 sljit_emit_mem(compiler, SLJIT_MOV_S8 | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM1(SLJIT_R2), -2 * (sljit_sw)sizeof(sljit_s8));
5929 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_R0, 0);
5930 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R2, 0);
5933 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));
5934 if (supported[2] == SLJIT_SUCCESS) {
5935 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S2, 0, SLJIT_IMM, 2 * sizeof(sljit_s32));
5936 sljit_emit_mem(compiler, SLJIT_MOV_S32 | SLJIT_MEM_PRE, SLJIT_R2, SLJIT_MEM1(SLJIT_R1), -2 * (sljit_sw)sizeof(sljit_s32));
5937 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R2, 0);
5938 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_R1, 0);
5941 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));
5942 if (supported[3] == SLJIT_SUCCESS) {
5943 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, -8765);
5944 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, sizeof(sljit_s32));
5945 sljit_emit_mem(compiler, SLJIT_MOV32 | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R2), 2 * sizeof(sljit_s32));
5946 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R2, 0);
5949 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));
5950 if (supported[4] == SLJIT_SUCCESS) {
5951 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -121);
5952 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_S1, 0);
5953 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));
5954 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R2, 0);
5957 supported[5] = sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R0), 1);
5958 if (supported[5] == SLJIT_SUCCESS) {
5959 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S0, 0, SLJIT_IMM, 9 * sizeof(sljit_sw) - 1);
5960 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, -881199);
5961 sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R0), 1);
5962 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), SLJIT_R0, 0);
5965 supported[6] = sljit_emit_mem(compiler, SLJIT_MOV_S32 | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
5966 if (supported[6] == SLJIT_SUCCESS) {
5967 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S2, 0, SLJIT_IMM, 213);
5968 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -213);
5969 sljit_emit_mem(compiler, SLJIT_MOV_S32 | SLJIT_MEM_PRE, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
5970 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 11 * sizeof(sljit_sw), SLJIT_R0, 0);
5971 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 12 * sizeof(sljit_sw), SLJIT_R1, 0);
5974 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);
5975 if (supported[7] == SLJIT_SUCCESS) {
5976 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_S2, 0);
5977 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 2 * sizeof(sljit_s32));
5978 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -7890);
5979 sljit_emit_mem(compiler, SLJIT_MOV_S32 | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
5980 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 13 * sizeof(sljit_sw), SLJIT_R1, 0);
5983 supported[8] = sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 2);
5984 if (supported[8] == SLJIT_SUCCESS) {
5985 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S0, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));
5986 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 2 * sizeof(sljit_sw));
5987 sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 2);
5988 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 14 * sizeof(sljit_sw), SLJIT_R0, 0);
5989 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 15 * sizeof(sljit_sw), SLJIT_R1, 0);
5992 supported[9] = sljit_emit_mem(compiler, SLJIT_MOV_S8 | SLJIT_MEM_SUPP | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
5993 if (supported[9] == SLJIT_SUCCESS) {
5994 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S1, 0, SLJIT_IMM, 2 * sizeof(sljit_s8));
5995 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, -2 * (sljit_sw)sizeof(sljit_s8));
5996 sljit_emit_mem(compiler, SLJIT_MOV_S8 | SLJIT_MEM_POST, SLJIT_R0, SLJIT_MEM2(SLJIT_R1, SLJIT_R2), 0);
5997 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 16 * sizeof(sljit_sw), SLJIT_R0, 0);
5998 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 17 * sizeof(sljit_sw), SLJIT_R1, 0);
6001 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);
6002 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);
6004 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) || (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
6005 /* TODO: at least for ARM (both V5 and V7) the range below needs further fixing */
6006 SLJIT_ASSERT(sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_R1, SLJIT_MEM1(SLJIT_R0), 256) == SLJIT_ERR_UNSUPPORTED);
6007 SLJIT_ASSERT(sljit_emit_mem(compiler, SLJIT_MOV | SLJIT_MEM_SUPP | SLJIT_MEM_POST, SLJIT_R1, SLJIT_MEM1(SLJIT_R0), -257) == SLJIT_ERR_UNSUPPORTED);
6008 #endif
6010 sljit_emit_return_void(compiler);
6012 code.code = sljit_generate_code(compiler);
6013 CHECK(compiler);
6014 sljit_free_compiler(compiler);
6016 code.func3((sljit_sw)&wbuf, (sljit_sw)&bbuf, (sljit_sw)&ibuf);
6018 FAILED(sizeof(expected) != sizeof(supported) / sizeof(sljit_s32), "test60 case 1 failed\n");
6020 for (i = 0; i < sizeof(expected); i++) {
6021 if (expected[i]) {
6022 if (supported[i] != SLJIT_SUCCESS) {
6023 printf("tast60 case %d should be supported\n", i + 1);
6024 return;
6026 } else {
6027 if (supported[i] == SLJIT_SUCCESS) {
6028 printf("test60 case %d should not be supported\n", i + 1);
6029 return;
6034 FAILED(supported[0] == SLJIT_SUCCESS && wbuf[0] != -887766, "test60 case 2 failed\n");
6035 FAILED(supported[0] == SLJIT_SUCCESS && wbuf[1] != (sljit_sw)(wbuf + 2), "test60 case 3 failed\n");
6036 FAILED(supported[1] == SLJIT_SUCCESS && wbuf[3] != -13, "test60 case 4 failed\n");
6037 FAILED(supported[1] == SLJIT_SUCCESS && wbuf[4] != (sljit_sw)(bbuf), "test60 case 5 failed\n");
6038 FAILED(supported[2] == SLJIT_SUCCESS && wbuf[5] != -5678, "test60 case 6 failed\n");
6039 FAILED(supported[2] == SLJIT_SUCCESS && wbuf[6] != (sljit_sw)(ibuf), "test60 case 7 failed\n");
6040 FAILED(supported[3] == SLJIT_SUCCESS && ibuf[1] != -8765, "test60 case 8 failed\n");
6041 FAILED(supported[3] == SLJIT_SUCCESS && wbuf[7] != (sljit_sw)(ibuf + 1), "test60 case 9 failed\n");
6042 FAILED(supported[4] == SLJIT_SUCCESS && bbuf[0] != -121, "test60 case 10 failed\n");
6043 FAILED(supported[4] == SLJIT_SUCCESS && wbuf[8] != (sljit_sw)(bbuf) - 128 * (sljit_sw)sizeof(sljit_s8), "test60 case 11 failed\n");
6044 FAILED(supported[5] == SLJIT_SUCCESS && wbuf[9] != -881199, "test60 case 12 failed\n");
6045 FAILED(supported[5] == SLJIT_SUCCESS && wbuf[10] != (sljit_sw)(wbuf + 9), "test60 case 13 failed\n");
6046 FAILED(supported[6] == SLJIT_SUCCESS && wbuf[11] != -5678, "test60 case 14 failed\n");
6047 FAILED(supported[6] == SLJIT_SUCCESS && wbuf[12] != (sljit_sw)(ibuf), "test60 case 15 failed\n");
6048 FAILED(supported[7] == SLJIT_SUCCESS && ibuf[2] != -7890, "test60 case 16 failed\n");
6049 FAILED(supported[7] == SLJIT_SUCCESS && wbuf[13] != (sljit_sw)(ibuf + 2), "test60 case 17 failed\n");
6050 FAILED(supported[8] == SLJIT_SUCCESS && wbuf[14] != -887766, "test60 case 18 failed\n");
6051 FAILED(supported[8] == SLJIT_SUCCESS && wbuf[15] != (sljit_sw)(wbuf + 10), "test60 case 19 failed\n");
6052 FAILED(supported[9] == SLJIT_SUCCESS && wbuf[16] != -13, "test60 case 20 failed\n");
6053 FAILED(supported[9] == SLJIT_SUCCESS && wbuf[17] != (sljit_sw)(bbuf), "test60 case 21 failed\n");
6055 sljit_free_code(code.code, NULL);
6056 successful_tests++;
6059 static void test61(void)
6061 /* Test float memory accesses with pre/post updates. */
6062 executable_code code;
6063 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
6064 sljit_u32 i;
6065 sljit_s32 supported[6];
6066 sljit_sw wbuf[6];
6067 sljit_f64 dbuf[4];
6068 sljit_f32 sbuf[4];
6069 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
6070 static sljit_u8 expected[6] = { 1, 1, 1, 1, 0, 0 };
6071 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
6072 static sljit_u8 expected[6] = { 1, 0, 1, 0, 1, 1 };
6073 #else
6074 static sljit_u8 expected[6] = { 0, 0, 0, 0, 0, 0 };
6075 #endif
6077 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
6078 if (verbose)
6079 printf("no fpu available, test61 skipped\n");
6080 successful_tests++;
6081 if (compiler)
6082 sljit_free_compiler(compiler);
6083 return;
6086 if (verbose)
6087 printf("Run test61\n");
6089 for (i = 0; i < 6; i++)
6090 wbuf[i] = 0;
6092 dbuf[0] = 66.725;
6093 dbuf[1] = 0.0;
6094 dbuf[2] = 0.0;
6095 dbuf[3] = 0.0;
6097 sbuf[0] = 0.0;
6098 sbuf[1] = -22.125;
6099 sbuf[2] = 0.0;
6100 sbuf[3] = 0.0;
6102 FAILED(!compiler, "cannot create compiler\n");
6104 sljit_emit_enter(compiler, 0, SLJIT_ARGS3(VOID, P, P, P), 4, 3, 4, 0, sizeof(sljit_sw));
6106 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));
6107 if (supported[0] == SLJIT_SUCCESS) {
6108 sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_IMM, 4 * sizeof(sljit_f64));
6109 sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_PRE, SLJIT_FR0, SLJIT_MEM1(SLJIT_R0), 4 * sizeof(sljit_f64));
6110 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S1), sizeof(sljit_f64), SLJIT_FR0, 0);
6111 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
6114 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));
6115 if (supported[1] == SLJIT_SUCCESS) {
6116 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_IMM, 2 * sizeof(sljit_f64));
6117 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S1), 0);
6118 sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_STORE | SLJIT_MEM_POST, SLJIT_FR2, SLJIT_MEM1(SLJIT_R0), -(sljit_sw)sizeof(sljit_f64));
6119 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_R0, 0);
6122 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));
6123 if (supported[2] == SLJIT_SUCCESS) {
6124 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S2, 0, SLJIT_IMM, 4 * sizeof(sljit_f32));
6125 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f32));
6126 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));
6127 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R2, 0);
6130 supported[3] = sljit_emit_fmem(compiler, SLJIT_MOV_F32 | SLJIT_MEM_SUPP | SLJIT_MEM_POST, SLJIT_FR1, SLJIT_MEM1(SLJIT_R1), sizeof(sljit_f32));
6131 if (supported[3] == SLJIT_SUCCESS) {
6132 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S2, 0, SLJIT_IMM, sizeof(sljit_f32));
6133 sljit_emit_fmem(compiler, SLJIT_MOV_F32 | SLJIT_MEM_POST, SLJIT_FR1, SLJIT_MEM1(SLJIT_R1), sizeof(sljit_f32));
6134 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_S2), 2 * sizeof(sljit_f32), SLJIT_FR1, 0);
6135 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_R1, 0);
6138 supported[4] = sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_SUPP | SLJIT_MEM_PRE, SLJIT_FR0, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 0);
6139 if (supported[4] == SLJIT_SUCCESS) {
6140 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R1, 0, SLJIT_S1, 0, SLJIT_IMM, 8 * sizeof(sljit_f64));
6141 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, -8 * (sljit_sw)sizeof(sljit_f64));
6142 sljit_emit_fmem(compiler, SLJIT_MOV_F64 | SLJIT_MEM_PRE, SLJIT_FR0, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 0);
6143 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S1), 3 * sizeof(sljit_f64), SLJIT_FR0, 0);
6144 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_R1, 0);
6147 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);
6148 if (supported[5] == SLJIT_SUCCESS) {
6149 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_S2, 0);
6150 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 3 * sizeof(sljit_f32));
6151 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_S2), sizeof(sljit_f32));
6152 sljit_emit_fmem(compiler, SLJIT_MOV_F32 | SLJIT_MEM_STORE | SLJIT_MEM_PRE, SLJIT_FR2, SLJIT_MEM2(SLJIT_R2, SLJIT_R1), 0);
6153 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_R2, 0);
6156 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);
6157 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);
6159 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
6160 /* TODO: at least for ARM (both V5 and V7) the range below needs further fixing */
6161 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);
6162 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);
6163 #endif
6165 sljit_emit_return_void(compiler);
6167 code.code = sljit_generate_code(compiler);
6168 CHECK(compiler);
6169 sljit_free_compiler(compiler);
6171 code.func3((sljit_sw)&wbuf, (sljit_sw)&dbuf, (sljit_sw)&sbuf);
6173 FAILED(sizeof(expected) != sizeof(supported) / sizeof(sljit_s32), "test61 case 1 failed\n");
6175 for (i = 0; i < sizeof(expected); i++) {
6176 if (expected[i]) {
6177 if (supported[i] != SLJIT_SUCCESS) {
6178 printf("tast61 case %d should be supported\n", i + 1);
6179 return;
6181 } else {
6182 if (supported[i] == SLJIT_SUCCESS) {
6183 printf("test61 case %d should not be supported\n", i + 1);
6184 return;
6189 FAILED(supported[0] == SLJIT_SUCCESS && dbuf[1] != 66.725, "test61 case 2 failed\n");
6190 FAILED(supported[0] == SLJIT_SUCCESS && wbuf[0] != (sljit_sw)(dbuf), "test61 case 3 failed\n");
6191 FAILED(supported[1] == SLJIT_SUCCESS && dbuf[2] != 66.725, "test61 case 4 failed\n");
6192 FAILED(supported[1] == SLJIT_SUCCESS && wbuf[1] != (sljit_sw)(dbuf + 1), "test61 case 5 failed\n");
6193 FAILED(supported[2] == SLJIT_SUCCESS && sbuf[0] != -22.125, "test61 case 6 failed\n");
6194 FAILED(supported[2] == SLJIT_SUCCESS && wbuf[2] != (sljit_sw)(sbuf), "test61 case 7 failed\n");
6195 FAILED(supported[3] == SLJIT_SUCCESS && sbuf[2] != -22.125, "test61 case 8 failed\n");
6196 FAILED(supported[3] == SLJIT_SUCCESS && wbuf[3] != (sljit_sw)(sbuf + 2), "test61 case 9 failed\n");
6197 FAILED(supported[4] == SLJIT_SUCCESS && dbuf[3] != 66.725, "test61 case 10 failed\n");
6198 FAILED(supported[4] == SLJIT_SUCCESS && wbuf[4] != (sljit_sw)(dbuf), "test61 case 11 failed\n");
6199 FAILED(supported[5] == SLJIT_SUCCESS && sbuf[3] != -22.125, "test61 case 12 failed\n");
6200 FAILED(supported[5] == SLJIT_SUCCESS && wbuf[5] != (sljit_sw)(sbuf + 3), "test61 case 13 failed\n");
6202 sljit_free_code(code.code, NULL);
6203 successful_tests++;
6206 static void test62(void)
6208 /* Test fast calls flag preservation. */
6209 executable_code code1;
6210 executable_code code2;
6211 struct sljit_compiler* compiler;
6213 if (verbose)
6214 printf("Run test62\n");
6216 /* A */
6217 compiler = sljit_create_compiler(NULL, NULL);
6218 FAILED(!compiler, "cannot create compiler\n");
6219 sljit_set_context(compiler, 0, SLJIT_ARGS1(W, W), 1, 1, 0, 0, 0);
6221 sljit_emit_fast_enter(compiler, SLJIT_R0, 0);
6222 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z | SLJIT_SET_LESS, SLJIT_S0, 0, SLJIT_IMM, 42);
6223 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_R0, 0);
6225 code1.code = sljit_generate_code(compiler);
6226 CHECK(compiler);
6227 sljit_free_compiler(compiler);
6229 /* B */
6230 compiler = sljit_create_compiler(NULL, NULL);
6231 FAILED(!compiler, "cannot create compiler\n");
6233 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, W), 1, 1, 0, 0, 0);
6234 sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM, SLJIT_FUNC_ADDR(code1.code));
6235 sljit_set_current_flags(compiler, SLJIT_CURRENT_FLAGS_ADD_SUB | SLJIT_CURRENT_FLAGS_COMPARE | SLJIT_SET_Z | SLJIT_SET_LESS);
6236 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_ZERO);
6237 sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_LESS);
6238 sljit_emit_op2(compiler, SLJIT_SHL, SLJIT_S0, 0, SLJIT_S0, 0, SLJIT_IMM, 1);
6239 sljit_emit_op2(compiler, SLJIT_OR, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S0, 0);
6240 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
6242 code2.code = sljit_generate_code(compiler);
6243 CHECK(compiler);
6244 sljit_free_compiler(compiler);
6246 FAILED(code2.func1(88) != 0, "test62 case 1 failed\n");
6247 FAILED(code2.func1(42) != 1, "test62 case 2 failed\n");
6248 FAILED(code2.func1(0) != 2, "test62 case 3 failed\n");
6250 sljit_free_code(code1.code, NULL);
6251 sljit_free_code(code2.code, NULL);
6252 successful_tests++;
6255 static void test63(void)
6257 /* Test put label. */
6258 executable_code code;
6259 struct sljit_label *label[2];
6260 struct sljit_put_label *put_label[5];
6261 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
6262 sljit_uw addr[2];
6263 sljit_uw buf[4];
6264 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
6265 sljit_sw offs = SLJIT_W(0x123456789012);
6266 #else
6267 sljit_sw offs = 0x12345678;
6268 #endif
6270 if (verbose)
6271 printf("Run test63\n");
6273 FAILED(!compiler, "cannot create compiler\n");
6274 buf[0] = 0;
6275 buf[1] = 0;
6276 buf[2] = 0;
6277 buf[3] = 0;
6279 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 1, 0, 0, 2 * sizeof(sljit_sw));
6281 put_label[0] = sljit_emit_put_label(compiler, SLJIT_R0, 0);
6282 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
6284 put_label[1] = sljit_emit_put_label(compiler, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw));
6285 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw));
6287 label[0] = sljit_emit_label(compiler);
6288 sljit_set_put_label(put_label[0], label[0]);
6289 sljit_set_put_label(put_label[1], label[0]);
6291 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)(buf + 2) - offs);
6292 put_label[2] = sljit_emit_put_label(compiler, SLJIT_MEM1(SLJIT_R0), offs);
6294 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (offs + (sljit_sw)sizeof(sljit_uw)) >> 1);
6295 put_label[3] = sljit_emit_put_label(compiler, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), 1);
6297 label[1] = sljit_emit_label(compiler);
6298 sljit_set_put_label(put_label[2], label[1]);
6299 sljit_set_put_label(put_label[3], label[1]);
6301 put_label[4] = sljit_emit_put_label(compiler, SLJIT_RETURN_REG, 0);
6302 sljit_set_put_label(put_label[4], label[0]);
6303 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
6305 code.code = sljit_generate_code(compiler);
6306 CHECK(compiler);
6308 addr[0] = sljit_get_label_addr(label[0]);
6309 addr[1] = sljit_get_label_addr(label[1]);
6311 sljit_free_compiler(compiler);
6313 FAILED(code.func1((sljit_sw)&buf) != (sljit_sw)addr[0], "test63 case 1 failed\n");
6314 FAILED(buf[0] != addr[0], "test63 case 2 failed\n");
6315 FAILED(buf[1] != addr[0], "test63 case 3 failed\n");
6316 FAILED(buf[2] != addr[1], "test63 case 4 failed\n");
6317 FAILED(buf[3] != addr[1], "test63 case 5 failed\n");
6319 sljit_free_code(code.code, NULL);
6320 successful_tests++;
6323 static void test64(void)
6325 /* Test put label with absolute label addresses */
6326 executable_code code;
6327 sljit_uw malloc_addr;
6328 struct sljit_label label[4];
6329 struct sljit_put_label *put_label[2];
6330 struct sljit_compiler* compiler;
6331 sljit_uw buf[5];
6332 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
6333 sljit_sw offs1 = SLJIT_W(0x123456781122);
6334 sljit_sw offs2 = SLJIT_W(0x1234567811223344);
6335 #else /* !SLJIT_64BIT_ARCHITECTURE */
6336 sljit_sw offs1 = 0x12345678;
6337 sljit_sw offs2 = (sljit_sw)0x80000000;
6338 #endif /* SLJIT_64BIT_ARCHITECTURE */
6340 if (verbose)
6341 printf("Run test64\n");
6343 /* lock next allocation; see sljit_test_malloc_exec() */
6344 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
6345 malloc_addr = (sljit_uw)SLJIT_MALLOC_EXEC(1024, NULL);
6347 if (!malloc_addr) {
6348 printf("Cannot allocate executable memory\n");
6349 return;
6352 compiler = sljit_create_compiler(NULL, (void*)malloc_addr);
6353 malloc_addr += (sljit_uw)SLJIT_EXEC_OFFSET((void*)malloc_addr);
6354 #else /* SLJIT_CONFIG_UNSUPPORTED */
6355 malloc_addr = 0;
6356 compiler = sljit_create_compiler(NULL, (void*)malloc_addr);
6357 #endif /* !SLJIT_CONFIG_UNSUPPORTED */
6359 label[0].addr = 0x1234;
6360 label[0].size = (sljit_uw)0x1234 - malloc_addr;
6362 label[1].addr = 0x12345678;
6363 label[1].size = (sljit_uw)0x12345678 - malloc_addr;
6365 label[2].addr = (sljit_uw)offs1;
6366 label[2].size = (sljit_uw)offs1 - malloc_addr;
6368 label[3].addr = (sljit_uw)offs2;
6369 label[3].size = (sljit_uw)offs2 - malloc_addr;
6371 FAILED(!compiler, "cannot create compiler\n");
6372 buf[0] = 0;
6373 buf[1] = 0;
6374 buf[2] = 0;
6375 buf[3] = 0;
6376 buf[4] = 0;
6378 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, P), 3, 1, 0, 0, 2 * sizeof(sljit_sw));
6380 put_label[0] = sljit_emit_put_label(compiler, SLJIT_R0, 0);
6381 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_R0, 0);
6383 put_label[1] = sljit_emit_put_label(compiler, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw));
6384 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_uw), SLJIT_MEM1(SLJIT_SP), sizeof(sljit_uw));
6386 sljit_set_put_label(put_label[0], &label[0]);
6387 sljit_set_put_label(put_label[1], &label[0]);
6389 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)(buf + 2) - offs1);
6390 put_label[0] = sljit_emit_put_label(compiler, SLJIT_MEM1(SLJIT_R0), offs1);
6392 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, (offs1 + (sljit_sw)sizeof(sljit_uw)) >> 1);
6393 put_label[1] = sljit_emit_put_label(compiler, SLJIT_MEM2(SLJIT_R0, SLJIT_R1), 1);
6395 sljit_set_put_label(put_label[0], &label[1]);
6396 sljit_set_put_label(put_label[1], &label[1]);
6398 put_label[0] = sljit_emit_put_label(compiler, SLJIT_R2, 0);
6399 sljit_set_put_label(put_label[0], &label[2]);
6400 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_uw), SLJIT_R2, 0);
6402 put_label[0] = sljit_emit_put_label(compiler, SLJIT_RETURN_REG, 0);
6403 sljit_set_put_label(put_label[0], &label[3]);
6404 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
6406 code.code = sljit_generate_code(compiler);
6407 CHECK(compiler);
6408 sljit_free_compiler(compiler);
6409 SLJIT_ASSERT(SLJIT_FUNC_UADDR(code.code) >= malloc_addr && SLJIT_FUNC_UADDR(code.code) <= malloc_addr + 8);
6411 FAILED(code.func1((sljit_sw)&buf) != (sljit_sw)label[3].addr, "test64 case 1 failed\n");
6412 FAILED(buf[0] != label[0].addr, "test64 case 2 failed\n");
6413 FAILED(buf[1] != label[0].addr, "test64 case 3 failed\n");
6414 FAILED(buf[2] != label[1].addr, "test64 case 4 failed\n");
6415 FAILED(buf[3] != label[1].addr, "test64 case 5 failed\n");
6416 FAILED(buf[4] != label[2].addr, "test64 case 6 failed\n");
6418 sljit_free_code(code.code, NULL);
6420 successful_tests++;
6423 static void test65(void)
6425 /* Test jump tables. */
6426 executable_code code;
6427 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
6428 sljit_s32 i;
6429 /* Normally this table is allocated on the heap. */
6430 sljit_uw addr[64];
6431 struct sljit_label *labels[64];
6432 struct sljit_jump *jump;
6434 if (verbose)
6435 printf("Run test65\n");
6437 FAILED(!compiler, "cannot create compiler\n");
6439 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(W, W, W), 1, 2, 0, 0, 0);
6441 jump = sljit_emit_cmp(compiler, SLJIT_GREATER_EQUAL, SLJIT_S0, 0, SLJIT_IMM, 64);
6442 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)addr);
6443 sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_MEM2(SLJIT_R0, SLJIT_S0), SLJIT_WORD_SHIFT);
6445 for (i = 0; i < 64; i++) {
6446 labels[i] = sljit_emit_label(compiler);
6447 sljit_emit_op0(compiler, SLJIT_ENDBR);
6448 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_IMM, i * 2);
6449 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
6452 sljit_set_label(jump, sljit_emit_label(compiler));
6453 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_IMM, -1);
6455 code.code = sljit_generate_code(compiler);
6456 CHECK(compiler);
6458 for (i = 0; i < 64; i++) {
6459 addr[i] = sljit_get_label_addr(labels[i]);
6462 sljit_free_compiler(compiler);
6464 FAILED(code.func2(64, 0) != -1, "test65 case 1 failed\n");
6466 for (i = 0; i < 64; i++) {
6467 FAILED(code.func2(i, i * 2) != i * 4, "test65 case 2 failed\n");
6470 sljit_free_code(code.code, NULL);
6471 successful_tests++;
6474 static void test66(void)
6476 /* Test direct jumps (computed goto). */
6477 executable_code code;
6478 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
6479 sljit_s32 i;
6480 sljit_uw addr[64];
6481 struct sljit_label *labels[64];
6483 if (verbose)
6484 printf("Run test66\n");
6486 FAILED(!compiler, "cannot create compiler\n");
6488 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(W, W, W), 1, 2, 0, 0, 0);
6489 sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_S0, 0);
6491 for (i = 0; i < 64; i++) {
6492 labels[i] = sljit_emit_label(compiler);
6493 sljit_emit_op0(compiler, SLJIT_ENDBR);
6494 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_S1, 0, SLJIT_IMM, i * 2);
6495 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
6498 code.code = sljit_generate_code(compiler);
6499 CHECK(compiler);
6501 for (i = 0; i < 64; i++) {
6502 addr[i] = sljit_get_label_addr(labels[i]);
6505 sljit_free_compiler(compiler);
6507 for (i = 0; i < 64; i++) {
6508 FAILED(code.func2((sljit_sw)addr[i], i) != i * 3, "test66 case 1 failed\n");
6511 sljit_free_code(code.code, NULL);
6512 successful_tests++;
6515 static void test67(void)
6517 /* Test skipping returns from fast calls (return type is fast). */
6518 executable_code code;
6519 struct sljit_compiler *compiler = sljit_create_compiler(NULL, NULL);
6520 struct sljit_jump *call, *jump;
6521 struct sljit_label *label;
6523 if (verbose)
6524 printf("Run test67\n");
6526 FAILED(!compiler, "cannot create compiler\n");
6528 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(W), 3, 1, 0, 0, 0);
6530 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
6531 call = sljit_emit_jump(compiler, SLJIT_FAST_CALL);
6533 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
6535 /* First function, never returns. */
6536 label = sljit_emit_label(compiler);
6537 sljit_set_label(call, label);
6538 sljit_emit_fast_enter(compiler, SLJIT_R1, 0);
6540 call = sljit_emit_jump(compiler, SLJIT_FAST_CALL);
6542 /* Should never return here, marked by a segmentation fault if it does. */
6543 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
6545 /* Second function, skips the first function. */
6546 sljit_set_label(call, sljit_emit_label(compiler));
6547 sljit_emit_fast_enter(compiler, SLJIT_R2, 0);
6549 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
6551 jump = sljit_emit_cmp(compiler, SLJIT_NOT_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 1);
6553 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_R1, 0);
6554 sljit_set_label(sljit_emit_jump(compiler, SLJIT_FAST_CALL), label);
6555 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
6556 sljit_emit_op_src(compiler, SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN, SLJIT_S0, 0);
6557 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_S0, 0);
6559 sljit_set_label(jump, sljit_emit_label(compiler));
6560 sljit_emit_op_src(compiler, SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN, SLJIT_R1, 0);
6561 sljit_emit_op_src(compiler, SLJIT_FAST_RETURN, SLJIT_R1, 0);
6563 code.code = sljit_generate_code(compiler);
6564 CHECK(compiler);
6566 sljit_free_compiler(compiler);
6568 FAILED(code.func0() != 3, "test67 case 1 failed\n");
6570 sljit_free_code(code.code, NULL);
6571 successful_tests++;
6574 static void test68(void)
6576 /* Test skipping returns from fast calls (return type is normal). */
6577 executable_code code;
6578 struct sljit_compiler *compiler;
6579 struct sljit_jump *call, *jump;
6580 struct sljit_label *label;
6581 int i;
6583 if (verbose)
6584 printf("Run test68\n");
6586 for (i = 0; i < 6 * 2; i++) {
6587 compiler = sljit_create_compiler(NULL, NULL);
6588 FAILED(!compiler, "cannot create compiler\n");
6590 sljit_emit_enter(compiler, (i >= 6 ? SLJIT_F64_ALIGNMENT : 0), SLJIT_ARGS0(W), 2 + (i % 6), (i % 6), 0, 0, 0);
6592 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0);
6593 call = sljit_emit_jump(compiler, SLJIT_FAST_CALL);
6595 /* Should never return here, marked by a segmentation fault if it does. */
6596 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
6598 /* Recursive fast call. */
6599 label = sljit_emit_label(compiler);
6600 sljit_set_label(call, label);
6601 sljit_emit_fast_enter(compiler, SLJIT_R1, 0);
6603 sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, 1);
6605 jump = sljit_emit_cmp(compiler, SLJIT_GREATER_EQUAL, SLJIT_R0, 0, SLJIT_IMM, 4);
6607 sljit_set_label(sljit_emit_jump(compiler, SLJIT_FAST_CALL), label);
6609 sljit_set_label(jump, sljit_emit_label(compiler));
6610 sljit_emit_op0(compiler, SLJIT_SKIP_FRAMES_BEFORE_RETURN);
6611 sljit_emit_return(compiler, SLJIT_MOV, SLJIT_R0, 0);
6613 code.code = sljit_generate_code(compiler);
6614 CHECK(compiler);
6616 sljit_free_compiler(compiler);
6618 if (SLJIT_UNLIKELY(code.func0() != 4)) {
6619 printf("test68 case %d failed\n", i + 1);
6620 return;
6622 sljit_free_code(code.code, NULL);
6625 successful_tests++;
6628 static void test69(void)
6630 /* Test sljit_set_current_flags. */
6631 executable_code code;
6632 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
6633 sljit_sw buf[8];
6634 sljit_s32 i;
6636 if (verbose)
6637 printf("Run test69\n");
6639 for (i = 0; i < 8; i++)
6640 buf[i] = 4;
6642 FAILED(!compiler, "cannot create compiler\n");
6644 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 3, 1, 0, 0, 0);
6646 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)1 << ((sizeof (sljit_sw) * 8) - 2));
6647 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_R0, 0);
6648 sljit_emit_op2(compiler, SLJIT_ADD | 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 | SLJIT_CURRENT_FLAGS_ADD_SUB);
6651 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_OVERFLOW);
6653 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 5);
6654 sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_R1, 0);
6655 sljit_emit_label(compiler);
6656 sljit_set_current_flags(compiler, SLJIT_SET_OVERFLOW | SLJIT_CURRENT_FLAGS_ADD_SUB);
6657 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), SLJIT_OVERFLOW);
6659 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_R0, 0);
6660 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_R0, 0, SLJIT_R1, 0);
6661 sljit_emit_label(compiler);
6662 sljit_set_current_flags(compiler, SLJIT_SET_OVERFLOW);
6663 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_OVERFLOW);
6665 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 5);
6666 sljit_emit_op2(compiler, SLJIT_MUL | SLJIT_SET_OVERFLOW, SLJIT_R1, 0, SLJIT_R1, 0, SLJIT_R1, 0);
6667 sljit_emit_label(compiler);
6668 sljit_set_current_flags(compiler, SLJIT_SET_OVERFLOW);
6669 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_OVERFLOW);
6671 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 6);
6672 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 5);
6673 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_GREATER, SLJIT_R1, 0, SLJIT_R2, 0);
6674 sljit_emit_label(compiler);
6675 sljit_set_current_flags(compiler, SLJIT_SET_GREATER | SLJIT_CURRENT_FLAGS_ADD_SUB | SLJIT_CURRENT_FLAGS_COMPARE);
6676 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_GREATER);
6678 sljit_emit_op2u(compiler, SLJIT_SUB | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_R2, 0);
6679 sljit_emit_label(compiler);
6680 sljit_set_current_flags(compiler, SLJIT_SET_Z | SLJIT_CURRENT_FLAGS_ADD_SUB | SLJIT_CURRENT_FLAGS_COMPARE);
6681 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_ZERO);
6683 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 1 << 31);
6684 sljit_emit_op2u(compiler, SLJIT_ADD32 | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_R1, 0);
6685 sljit_emit_label(compiler);
6686 sljit_set_current_flags(compiler, SLJIT_SET_Z | SLJIT_CURRENT_FLAGS_32 | SLJIT_CURRENT_FLAGS_ADD_SUB);
6687 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 6 * sizeof(sljit_sw), SLJIT_ZERO);
6689 sljit_emit_op2u(compiler, SLJIT_SHL32 | SLJIT_SET_Z, SLJIT_R1, 0, SLJIT_IMM, 1);
6690 sljit_emit_label(compiler);
6691 sljit_set_current_flags(compiler, SLJIT_SET_Z | SLJIT_CURRENT_FLAGS_32);
6692 cond_set(compiler, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_NOT_ZERO);
6694 sljit_emit_return_void(compiler);
6696 code.code = sljit_generate_code(compiler);
6697 CHECK(compiler);
6698 sljit_free_compiler(compiler);
6700 code.func1((sljit_sw)&buf);
6702 FAILED(buf[0] != 1, "test69 case 1 failed\n");
6703 FAILED(buf[1] != 2, "test69 case 2 failed\n");
6704 FAILED(buf[2] != 1, "test69 case 3 failed\n");
6705 FAILED(buf[3] != 2, "test69 case 4 failed\n");
6706 FAILED(buf[4] != 1, "test69 case 5 failed\n");
6707 FAILED(buf[5] != 2, "test69 case 6 failed\n");
6708 FAILED(buf[6] != 1, "test69 case 7 failed\n");
6709 FAILED(buf[7] != 2, "test69 case 8 failed\n");
6711 sljit_free_code(code.code, NULL);
6712 successful_tests++;
6715 static void test70(void)
6717 /* Test argument passing to sljit_emit_enter. */
6718 executable_code code;
6719 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
6720 sljit_sw wbuf[2];
6721 sljit_s32 ibuf[2];
6722 sljit_f64 dbuf[3];
6723 sljit_f32 fbuf[2];
6725 if (verbose)
6726 printf("Run test70\n");
6728 wbuf[0] = 0;
6729 wbuf[1] = 0;
6730 ibuf[0] = 0;
6731 ibuf[1] = 0;
6733 FAILED(!compiler, "cannot create compiler\n");
6735 sljit_emit_enter(compiler, 0, SLJIT_ARGS4(VOID, 32, W, 32, W), 1, 4, 0, 0, 0);
6736 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&wbuf);
6737 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_S1, 0);
6738 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_sw), SLJIT_S3, 0);
6739 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&ibuf);
6740 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_S0, 0);
6741 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_s32), SLJIT_S2, 0);
6742 sljit_emit_return_void(compiler);
6744 code.code = sljit_generate_code(compiler);
6745 CHECK(compiler);
6746 sljit_free_compiler(compiler);
6748 code.test70_f1(-1478, 9476, 4928, -6832);
6750 FAILED(wbuf[0] != 9476, "test70 case 1 failed\n");
6751 FAILED(wbuf[1] != -6832, "test70 case 2 failed\n");
6752 FAILED(ibuf[0] != -1478, "test70 case 3 failed\n");
6753 FAILED(ibuf[1] != 4928, "test70 case 4 failed\n");
6755 sljit_free_code(code.code, NULL);
6757 compiler = sljit_create_compiler(NULL, NULL);
6758 FAILED(!compiler, "cannot create compiler\n");
6760 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, SLJIT_ARGS4(VOID, 32, 32, W, W), 1, 4, 0, 0, 0);
6761 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&wbuf);
6762 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_S0, 0);
6763 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_sw), SLJIT_S1, 0);
6764 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&ibuf);
6765 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_S2, 0);
6766 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_s32), SLJIT_S3, 0);
6767 sljit_emit_return_void(compiler);
6769 code.code = sljit_generate_code(compiler);
6770 CHECK(compiler);
6771 sljit_free_compiler(compiler);
6773 code.test70_f2(4721, 7892, -3579, -4830);
6775 FAILED(wbuf[0] != 4721, "test70 case 5 failed\n");
6776 FAILED(wbuf[1] != 7892, "test70 case 6 failed\n");
6777 FAILED(ibuf[0] != -3579, "test70 case 7 failed\n");
6778 FAILED(ibuf[1] != -4830, "test70 case 8 failed\n");
6780 sljit_free_code(code.code, NULL);
6782 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
6783 wbuf[0] = 0;
6784 ibuf[0] = 0;
6785 dbuf[0] = 0;
6786 fbuf[0] = 0;
6788 compiler = sljit_create_compiler(NULL, NULL);
6789 FAILED(!compiler, "cannot create compiler\n");
6791 sljit_emit_enter(compiler, 0, SLJIT_ARGS4(VOID, 32, F32, W, F64), 2, 2, 2, 0, 0);
6792 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM0(), (sljit_sw)&wbuf, SLJIT_S1, 0);
6793 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM0(), (sljit_sw)&ibuf, SLJIT_S0, 0);
6794 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM0(), (sljit_sw)&dbuf, SLJIT_FR1, 0);
6795 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM0(), (sljit_sw)&fbuf, SLJIT_FR0, 0);
6796 sljit_emit_return_void(compiler);
6798 code.code = sljit_generate_code(compiler);
6799 CHECK(compiler);
6800 sljit_free_compiler(compiler);
6802 code.test70_f3(-6834, 674.5, 2789, -895.25);
6804 FAILED(wbuf[0] != 2789, "test70 case 9 failed\n");
6805 FAILED(ibuf[0] != -6834, "test70 case 10 failed\n");
6806 FAILED(dbuf[0] != -895.25, "test70 case 11 failed\n");
6807 FAILED(fbuf[0] != 674.5, "test70 case 12 failed\n");
6809 ibuf[0] = 0;
6810 dbuf[0] = 0;
6811 fbuf[0] = 0;
6812 fbuf[1] = 0;
6814 compiler = sljit_create_compiler(NULL, NULL);
6815 FAILED(!compiler, "cannot create compiler\n");
6817 sljit_emit_enter(compiler, 0, SLJIT_ARGS4(VOID, F32, F64, F32, 32), 1, 1, 3, 0, 0);
6818 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM0(), (sljit_sw)&ibuf, SLJIT_S0, 0);
6819 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM0(), (sljit_sw)&dbuf, SLJIT_FR1, 0);
6820 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&fbuf);
6821 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_FR0, 0);
6822 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_f32), SLJIT_FR2, 0);
6823 sljit_emit_return_void(compiler);
6825 code.code = sljit_generate_code(compiler);
6826 CHECK(compiler);
6827 sljit_free_compiler(compiler);
6829 code.test70_f4(-4712.5, 5342.25, 2904.25, -4607);
6831 FAILED(ibuf[0] != -4607, "test70 case 13 failed\n");
6832 FAILED(dbuf[0] != 5342.25, "test70 case 14 failed\n");
6833 FAILED(fbuf[0] != -4712.5, "test70 case 15 failed\n");
6834 FAILED(fbuf[1] != 2904.25, "test70 case 16 failed\n");
6836 ibuf[0] = 0;
6837 dbuf[0] = 0;
6838 fbuf[0] = 0;
6839 fbuf[1] = 0;
6841 compiler = sljit_create_compiler(NULL, NULL);
6842 FAILED(!compiler, "cannot create compiler\n");
6844 sljit_emit_enter(compiler, 0, SLJIT_ARGS4(VOID, F64, F32, 32, F32), 1, 1, 3, 0, 0);
6845 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM0(), (sljit_sw)&ibuf, SLJIT_S0, 0);
6846 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM0(), (sljit_sw)&dbuf, SLJIT_FR0, 0);
6847 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&fbuf);
6848 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_FR1, 0);
6849 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_f32), SLJIT_FR2, 0);
6851 sljit_emit_return_void(compiler);
6853 code.code = sljit_generate_code(compiler);
6854 CHECK(compiler);
6855 sljit_free_compiler(compiler);
6857 code.test70_f5(3578.5, 4619.25, 6859, -1807.75);
6859 FAILED(ibuf[0] != 6859, "test70 case 17 failed\n");
6860 FAILED(dbuf[0] != 3578.5, "test70 case 18 failed\n");
6861 FAILED(fbuf[0] != 4619.25, "test70 case 19 failed\n");
6862 FAILED(fbuf[1] != -1807.75, "test70 case 20 failed\n");
6864 ibuf[0] = 0;
6865 dbuf[0] = 0;
6866 dbuf[1] = 0;
6867 fbuf[0] = 0;
6869 compiler = sljit_create_compiler(NULL, NULL);
6870 FAILED(!compiler, "cannot create compiler\n");
6872 sljit_emit_enter(compiler, 0, SLJIT_ARGS4(VOID, F64, 32, F32, F64), SLJIT_NUMBER_OF_SCRATCH_REGISTERS + 2, 1, 3, 0, 33);
6873 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM0(), (sljit_sw)&ibuf, SLJIT_S0, 0);
6874 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&dbuf);
6875 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_FR0, 0);
6876 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_f64), SLJIT_FR2, 0);
6877 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM0(), (sljit_sw)&fbuf, SLJIT_FR1, 0);
6878 sljit_emit_return_void(compiler);
6880 code.code = sljit_generate_code(compiler);
6881 CHECK(compiler);
6882 sljit_free_compiler(compiler);
6884 code.test70_f6(2740.75, -2651, -7909.25, 3671.5);
6886 FAILED(ibuf[0] != -2651, "test70 case 21 failed\n");
6887 FAILED(dbuf[0] != 2740.75, "test70 case 22 failed\n");
6888 FAILED(dbuf[1] != 3671.5, "test70 case 23 failed\n");
6889 FAILED(fbuf[0] != -7909.25, "test70 case 24 failed\n");
6891 wbuf[0] = 0;
6892 ibuf[0] = 0;
6893 ibuf[1] = 0;
6894 fbuf[0] = 0;
6896 compiler = sljit_create_compiler(NULL, NULL);
6897 FAILED(!compiler, "cannot create compiler\n");
6899 sljit_emit_enter(compiler, 0, SLJIT_ARGS4(VOID, F32, 32, W, 32), 1, 3, 1, 0, 1);
6900 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM0(), (sljit_sw)&wbuf, SLJIT_S1, 0);
6901 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&ibuf);
6902 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_S0, 0);
6903 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_s32), SLJIT_S2, 0);
6904 sljit_emit_fop1(compiler, SLJIT_MOV_F32, SLJIT_MEM0(), (sljit_sw)&fbuf, SLJIT_FR0, 0);
6905 sljit_emit_return_void(compiler);
6907 code.code = sljit_generate_code(compiler);
6908 CHECK(compiler);
6909 sljit_free_compiler(compiler);
6911 code.test70_f7(-5219.25, -4530, 7214, 6741);
6913 FAILED(wbuf[0] != 7214, "test70 case 25 failed\n");
6914 FAILED(ibuf[0] != -4530, "test70 case 26 failed\n");
6915 FAILED(ibuf[1] != 6741, "test70 case 27 failed\n");
6916 FAILED(fbuf[0] != -5219.25, "test70 case 28 failed\n");
6918 wbuf[0] = 0;
6919 wbuf[1] = 0;
6920 dbuf[0] = 0;
6921 dbuf[1] = 0;
6923 compiler = sljit_create_compiler(NULL, NULL);
6924 FAILED(!compiler, "cannot create compiler\n");
6926 sljit_emit_enter(compiler, 0, SLJIT_ARGS4(VOID, F64, F64, W, W), 1, 5, 2, 0, SLJIT_MAX_LOCAL_SIZE - 1);
6927 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_S0, 0);
6928 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_SP), SLJIT_MAX_LOCAL_SIZE - 2 * sizeof(sljit_f64), SLJIT_FR0, 0);
6929 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&wbuf);
6930 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_S0, 0);
6931 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_sw), SLJIT_S1, 0);
6932 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&dbuf);
6933 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_FR0, 0);
6934 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_f64), SLJIT_FR1, 0);
6935 sljit_emit_return_void(compiler);
6937 code.code = sljit_generate_code(compiler);
6938 CHECK(compiler);
6939 sljit_free_compiler(compiler);
6941 code.test70_f8(-3749.75, 5280.5, 9134, -6506);
6943 FAILED(wbuf[0] != 9134, "test70 case 29 failed\n");
6944 FAILED(wbuf[1] != -6506, "test70 case 30 failed\n");
6945 FAILED(dbuf[0] != -3749.75, "test70 case 31 failed\n");
6946 FAILED(dbuf[1] != 5280.5, "test70 case 32 failed\n");
6948 wbuf[0] = 0;
6949 dbuf[0] = 0;
6950 dbuf[1] = 0;
6951 dbuf[2] = 0;
6953 compiler = sljit_create_compiler(NULL, NULL);
6954 FAILED(!compiler, "cannot create compiler\n");
6956 sljit_emit_enter(compiler, 0, SLJIT_ARGS4(VOID, F64, F64, W, F64), 1, 1, 3, 0, SLJIT_MAX_LOCAL_SIZE);
6957 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM0(), (sljit_sw)&wbuf, SLJIT_S0, 0);
6958 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&dbuf);
6959 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_FR0, 0);
6960 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_f64), SLJIT_FR1, 0);
6961 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_R0), 2 * sizeof(sljit_f64), SLJIT_FR2, 0);
6963 sljit_emit_return_void(compiler);
6965 code.code = sljit_generate_code(compiler);
6966 CHECK(compiler);
6967 sljit_free_compiler(compiler);
6969 code.test70_f9(-6049.25, 7301.5, 4610, -4312.75);
6971 FAILED(wbuf[0] != 4610, "test70 case 33 failed\n");
6972 FAILED(dbuf[0] != -6049.25, "test70 case 34 failed\n");
6973 FAILED(dbuf[1] != 7301.5, "test70 case 35 failed\n");
6974 FAILED(dbuf[2] != -4312.75, "test70 case 36 failed\n");
6976 ibuf[0] = 0;
6977 dbuf[0] = 0;
6978 dbuf[1] = 0;
6979 dbuf[2] = 0;
6981 compiler = sljit_create_compiler(NULL, NULL);
6982 FAILED(!compiler, "cannot create compiler\n");
6984 sljit_emit_enter(compiler, 0, SLJIT_ARGS4(VOID, F64, F64, F64, 32), 1, 1, 3, 0, 0);
6985 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM0(), (sljit_sw)&ibuf, SLJIT_S0, 0);
6986 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&dbuf);
6987 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_R0), 0, SLJIT_FR0, 0);
6988 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_f64), SLJIT_FR1, 0);
6989 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_R0), 2 * sizeof(sljit_f64), SLJIT_FR2, 0);
6991 sljit_emit_return_void(compiler);
6993 code.code = sljit_generate_code(compiler);
6994 CHECK(compiler);
6995 sljit_free_compiler(compiler);
6997 code.test70_f10(4810.5, -9148.75, 8601.25, 6703);
6999 FAILED(ibuf[0] != 6703, "test70 case 37 failed\n");
7000 FAILED(dbuf[0] != 4810.5, "test70 case 38 failed\n");
7001 FAILED(dbuf[1] != -9148.75, "test70 case 39 failed\n");
7002 FAILED(dbuf[2] != 8601.25, "test70 case 40 failed\n");
7005 successful_tests++;
7008 #if !(defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
7010 static sljit_sw SLJIT_FUNC test71_f1(sljit_sw a)
7012 return a + 10000;
7015 static sljit_sw SLJIT_FUNC test71_f2(sljit_sw a, sljit_s32 b, sljit_s32 c, sljit_sw d)
7017 return a | b | c | d;
7020 static sljit_sw test71_f3(sljit_sw a, sljit_s32 b, sljit_s32 c, sljit_sw d)
7022 return a | b | c | d;
7025 static sljit_sw test71_f4(sljit_sw a, sljit_s32 b, sljit_s32 c, sljit_sw d)
7027 SLJIT_UNUSED_ARG(a);
7028 return b | c | d;
7031 static sljit_sw test71_f5(void)
7033 return 7461932;
7036 static sljit_sw SLJIT_FUNC test71_f6(sljit_f64 a, sljit_f64 b, sljit_f64 c, sljit_f64 d)
7038 if (a == 1345.5 && b == -8724.25 && c == 9034.75 && d == 6307.5)
7039 return 8920567;
7040 return 0;
7043 static sljit_sw SLJIT_FUNC test71_f7(sljit_f64 a, sljit_f64 b, sljit_f64 c, sljit_sw d)
7045 if (a == 4061.25 && b == -3291.75 && c == 8703.5 && d == 1706)
7046 return 5074526;
7047 return 0;
7050 #endif /* !SLJIT_CONFIG_SPARC */
7052 static void test71(void)
7054 #if !(defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
7055 /* Test tail calls. */
7056 executable_code code;
7057 struct sljit_compiler* compiler;
7058 struct sljit_jump *jump;
7059 sljit_uw jump_addr;
7060 sljit_sw executable_offset;
7061 sljit_sw wbuf[1];
7062 sljit_f64 dbuf[4];
7064 if (verbose)
7065 printf("Run test71\n");
7067 compiler = sljit_create_compiler(NULL, NULL);
7068 FAILED(!compiler, "cannot create compiler\n");
7070 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, W), 4, 4, 0, 0, 0);
7071 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
7072 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_IMM, 0);
7073 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_IMM, 0);
7074 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 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 sljit_emit_icall(compiler, SLJIT_CALL | SLJIT_TAIL_CALL, SLJIT_ARGS1(W, W), SLJIT_IMM, SLJIT_FUNC_ADDR(test71_f1));
7080 /* Should crash. */
7081 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
7083 code.code = sljit_generate_code(compiler);
7084 CHECK(compiler);
7085 sljit_free_compiler(compiler);
7087 FAILED(code.func1(7987) != 17987, "test71 case 1 failed\n");
7089 compiler = sljit_create_compiler(NULL, NULL);
7090 FAILED(!compiler, "cannot create compiler\n");
7092 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(W, W), 1, 4, 0, 0, 0);
7093 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
7094 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, -1);
7095 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, -1);
7096 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, -1);
7097 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, -1);
7098 jump = sljit_emit_call(compiler, SLJIT_CALL | SLJIT_REWRITABLE_JUMP | SLJIT_TAIL_CALL, SLJIT_ARGS1(W, W));
7099 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
7101 sljit_set_target(jump, 0);
7103 code.code = sljit_generate_code(compiler);
7104 CHECK(compiler);
7106 executable_offset = sljit_get_executable_offset(compiler);
7107 jump_addr = sljit_get_jump_addr(jump);
7108 sljit_free_compiler(compiler);
7110 sljit_set_jump_addr(jump_addr, SLJIT_FUNC_UADDR(test71_f1), executable_offset);
7112 FAILED(code.func1(3903) != 13903, "test71 case 2 failed\n");
7114 compiler = sljit_create_compiler(NULL, NULL);
7115 FAILED(!compiler, "cannot create compiler\n");
7117 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(W), 4, 2, 0, 0, SLJIT_MAX_LOCAL_SIZE);
7118 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test71_f2));
7119 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 0x28000000);
7120 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 0x00140000);
7121 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R2, 0, SLJIT_IMM, 0x00002800);
7122 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0x00000041);
7123 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, -1);
7124 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, -1);
7125 sljit_emit_icall(compiler, SLJIT_CALL | SLJIT_TAIL_CALL, SLJIT_ARGS4(W, W, 32, 32, W), SLJIT_MEM1(SLJIT_SP), 0);
7126 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
7128 code.code = sljit_generate_code(compiler);
7129 CHECK(compiler);
7130 sljit_free_compiler(compiler);
7132 FAILED(code.func0() != 0x28142841, "test71 case 3 failed\n");
7134 compiler = sljit_create_compiler(NULL, NULL);
7135 FAILED(!compiler, "cannot create compiler\n");
7137 sljit_emit_enter(compiler, 0, SLJIT_ARGS0(W), 4, 4, 0, 0, SLJIT_MAX_LOCAL_SIZE);
7138 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test71_f2));
7139 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)0x81000000);
7140 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 0x00480000);
7141 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R2, 0, SLJIT_IMM, 0x00002100);
7142 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0x00000014);
7143 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, -1);
7144 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, -1);
7145 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, -1);
7146 sljit_emit_icall(compiler, SLJIT_CALL | SLJIT_TAIL_CALL, SLJIT_ARGS4(W, W, 32, 32, W), SLJIT_S3, 0);
7147 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
7149 code.code = sljit_generate_code(compiler);
7150 CHECK(compiler);
7151 sljit_free_compiler(compiler);
7153 FAILED(code.func0() != (sljit_sw)0x81482114, "test71 case 4 failed\n");
7155 sljit_free_code(code.code, NULL);
7157 compiler = sljit_create_compiler(NULL, NULL);
7158 FAILED(!compiler, "cannot create compiler\n");
7160 sljit_emit_enter(compiler, 0, SLJIT_ARGS3(W, W, W, W), 4, 4, 0, 0, 0);
7161 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);
7162 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_S1, 0);
7163 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R2, 0, SLJIT_S2, 0);
7164 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0x48000000);
7165 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S0, 0, SLJIT_IMM, -1);
7166 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S1, 0, SLJIT_IMM, -1);
7167 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S2, 0, SLJIT_IMM, -1);
7168 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_S3, 0, SLJIT_IMM, -1);
7169 sljit_emit_icall(compiler, SLJIT_CALL_CDECL | SLJIT_TAIL_CALL, SLJIT_ARGS4(W, W, 32, 32, W), SLJIT_IMM, SLJIT_FUNC_ADDR(test71_f3));
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.func3(0x12, 0x8800, 0x240000) != 0x48248812, "test71 case 5 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), 4, 0, 0, 0, 0);
7184 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, SLJIT_FUNC_ADDR(test71_f4));
7185 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R1, 0, SLJIT_IMM, 0x342);
7186 sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_R2, 0, SLJIT_IMM, 0x451000);
7187 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R3, 0, SLJIT_IMM, 0x21000000);
7188 sljit_emit_icall(compiler, SLJIT_CALL_CDECL | SLJIT_TAIL_CALL, SLJIT_ARGS4(W, W, 32, 32, W), SLJIT_R0, 0);
7189 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
7191 code.code = sljit_generate_code(compiler);
7192 CHECK(compiler);
7193 sljit_free_compiler(compiler);
7195 FAILED(code.func0() != 0x21451342, "test71 case 6 failed\n");
7197 sljit_free_code(code.code, NULL);
7199 compiler = sljit_create_compiler(NULL, NULL);
7200 FAILED(!compiler, "cannot create compiler\n");
7202 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, SLJIT_ARGS0(W), 1, 0, 0, 0, 9);
7203 sljit_emit_icall(compiler, SLJIT_CALL_CDECL | SLJIT_TAIL_CALL, SLJIT_ARGS0(W), SLJIT_IMM, SLJIT_FUNC_ADDR(test71_f5));
7204 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
7206 code.code = sljit_generate_code(compiler);
7207 CHECK(compiler);
7208 sljit_free_compiler(compiler);
7210 FAILED(code.func0() != 7461932, "test71 case 7 failed\n");
7212 sljit_free_code(code.code, NULL);
7214 if (sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
7215 dbuf[0] = 1345.5;
7216 dbuf[1] = -8724.25;
7217 dbuf[2] = 9034.75;
7218 dbuf[3] = 6307.5;
7220 compiler = sljit_create_compiler(NULL, NULL);
7221 FAILED(!compiler, "cannot create compiler\n");
7223 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, SLJIT_ARGS0(W), 1, 1, 4, 0, 0);
7224 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&dbuf);
7225 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_R0), 0);
7226 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR1, 0, SLJIT_MEM1(SLJIT_R0), sizeof(sljit_f64));
7227 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR2, 0, SLJIT_MEM1(SLJIT_R0), 2 * sizeof(sljit_f64));
7228 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR3, 0, SLJIT_MEM1(SLJIT_R0), 3 * sizeof(sljit_f64));
7229 sljit_emit_icall(compiler, SLJIT_CALL | SLJIT_TAIL_CALL, SLJIT_ARGS4(W, F64, F64, F64, F64), SLJIT_IMM, SLJIT_FUNC_ADDR(test71_f6));
7230 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
7232 code.code = sljit_generate_code(compiler);
7233 CHECK(compiler);
7234 sljit_free_compiler(compiler);
7236 FAILED(code.func0() != 8920567, "test71 case 8 failed\n");
7238 sljit_free_code(code.code, NULL);
7240 wbuf[0] = SLJIT_FUNC_ADDR(test71_f6);
7242 compiler = sljit_create_compiler(NULL, NULL);
7243 FAILED(!compiler, "cannot create compiler\n");
7245 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, SLJIT_ARGS4(W, F64, F64, F64, F64), 1, 0, 4, 0, 0);
7246 sljit_emit_icall(compiler, SLJIT_CALL | SLJIT_TAIL_CALL, SLJIT_ARGS4(W, F64, F64, F64, F64), SLJIT_MEM0(), (sljit_sw)wbuf);
7247 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
7249 code.code = sljit_generate_code(compiler);
7250 CHECK(compiler);
7251 sljit_free_compiler(compiler);
7253 FAILED(code.test71_f1(1345.5, -8724.25, 9034.75, 6307.5) != 8920567, "test71 case 9 failed\n");
7255 sljit_free_code(code.code, NULL);
7257 compiler = sljit_create_compiler(NULL, NULL);
7258 FAILED(!compiler, "cannot create compiler\n");
7260 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, SLJIT_ARGS3(W, F64, F64, F64), 1, 0, 4, 0, 0);
7261 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1706);
7262 jump = sljit_emit_call(compiler, SLJIT_CALL | SLJIT_TAIL_CALL, SLJIT_ARGS4(W, F64, F64, F64, W));
7263 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
7265 sljit_set_target(jump, SLJIT_FUNC_UADDR(test71_f7));
7267 code.code = sljit_generate_code(compiler);
7268 CHECK(compiler);
7269 sljit_free_compiler(compiler);
7271 FAILED(code.test71_f2(4061.25, -3291.75, 8703.5) != 5074526, "test71 case 10 failed\n");
7273 sljit_free_code(code.code, NULL);
7275 compiler = sljit_create_compiler(NULL, NULL);
7276 FAILED(!compiler, "cannot create compiler\n");
7278 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, SLJIT_ARGS3(W, F64, F64, F64), SLJIT_NUMBER_OF_SCRATCH_REGISTERS + 1, 0, 4, 0, 0);
7279 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1706);
7280 jump = sljit_emit_call(compiler, SLJIT_CALL | SLJIT_TAIL_CALL, SLJIT_ARGS4(W, F64, F64, F64, W));
7281 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
7283 sljit_set_target(jump, SLJIT_FUNC_UADDR(test71_f7));
7285 code.code = sljit_generate_code(compiler);
7286 CHECK(compiler);
7287 sljit_free_compiler(compiler);
7289 FAILED(code.test71_f2(4061.25, -3291.75, 8703.5) != 5074526, "test71 case 11 failed\n");
7291 sljit_free_code(code.code, NULL);
7293 compiler = sljit_create_compiler(NULL, NULL);
7294 FAILED(!compiler, "cannot create compiler\n");
7296 sljit_emit_enter(compiler, SLJIT_F64_ALIGNMENT, SLJIT_ARGS3(W, F64, F64, F64), SLJIT_NUMBER_OF_SCRATCH_REGISTERS + 1, 1, 3, 0, SLJIT_MAX_LOCAL_SIZE);
7297 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 1706);
7298 jump = sljit_emit_call(compiler, SLJIT_CALL | SLJIT_TAIL_CALL, SLJIT_ARGS4(W, F64, F64, F64, W));
7299 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_MEM0(), 0);
7301 sljit_set_target(jump, SLJIT_FUNC_UADDR(test71_f7));
7303 code.code = sljit_generate_code(compiler);
7304 CHECK(compiler);
7305 sljit_free_compiler(compiler);
7307 FAILED(code.test71_f2(4061.25, -3291.75, 8703.5) != 5074526, "test71 case 12 failed\n");
7309 sljit_free_code(code.code, NULL);
7311 #endif /* !SLJIT_CONFIG_SPARC */
7313 successful_tests++;
7316 static void test72(void)
7318 /* Test using all fpu registers. */
7319 executable_code code;
7320 struct sljit_compiler* compiler = sljit_create_compiler(NULL, NULL);
7321 sljit_f64 buf[SLJIT_NUMBER_OF_FLOAT_REGISTERS];
7322 sljit_f64 buf2[2];
7323 struct sljit_jump *jump;
7324 sljit_s32 i;
7326 if (verbose)
7327 printf("Run test72\n");
7329 if (!sljit_has_cpu_feature(SLJIT_HAS_FPU)) {
7330 if (verbose)
7331 printf("no fpu available, test72 skipped\n");
7332 successful_tests++;
7333 if (compiler)
7334 sljit_free_compiler(compiler);
7335 return;
7338 /* Next test. */
7339 FAILED(!compiler, "cannot create compiler\n");
7341 buf2[0] = 7.75;
7342 buf2[1] = -8.25;
7344 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
7345 buf[i] = 0.0;
7347 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(VOID, P, P), 1, 2, SLJIT_NUMBER_OF_FLOAT_REGISTERS, 0, 0);
7348 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S1), 0);
7349 for (i = 1; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
7350 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR(i), 0, SLJIT_FR0, 0);
7352 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S1, 0);
7353 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS1(VOID, W));
7355 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
7356 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), i * (sljit_sw)sizeof(sljit_f64), SLJIT_FR(i), 0);
7357 sljit_emit_return_void(compiler);
7359 /* Called function. */
7360 sljit_set_label(jump, sljit_emit_label(compiler));
7361 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 0, 1, SLJIT_NUMBER_OF_FLOAT_REGISTERS, 0, 0);
7363 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
7364 for (i = 1; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
7365 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR(i), 0, SLJIT_FR0, 0);
7367 sljit_set_context(compiler, 0, SLJIT_ARGS1(VOID, P), 0, 1, SLJIT_NUMBER_OF_FLOAT_REGISTERS, 0, 0);
7368 sljit_emit_return_void(compiler);
7370 code.code = sljit_generate_code(compiler);
7371 CHECK(compiler);
7372 sljit_free_compiler(compiler);
7374 code.func2((sljit_sw)buf, (sljit_sw)buf2);
7376 for (i = 0; i < SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS; i++) {
7377 FAILED(buf[i] != -8.25, "test72 case 1 failed\n");
7380 for (i = SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++) {
7381 FAILED(buf[i] != 7.75, "test72 case 2 failed\n");
7384 sljit_free_code(code.code, NULL);
7386 /* Next test. */
7387 if (SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS >= 3) {
7388 compiler = sljit_create_compiler(NULL, NULL);
7389 FAILED(!compiler, "cannot create compiler\n");
7391 buf2[0] = -6.25;
7392 buf2[1] = 3.75;
7394 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
7395 buf[i] = 0.0;
7397 sljit_emit_enter(compiler, 0, SLJIT_ARGS2(VOID, P, P), 1, 2, SLJIT_NUMBER_OF_FLOAT_REGISTERS - 2, 1, SLJIT_MAX_LOCAL_SIZE);
7398 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FS0, 0, SLJIT_MEM1(SLJIT_S1), 0);
7399 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS - 2; i++)
7400 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR(i), 0, SLJIT_FS0, 0);
7402 sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S1, 0);
7403 jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS1(VOID, W));
7405 for (i = 0; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS - 2; i++)
7406 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), i * (sljit_sw)sizeof(sljit_f64), SLJIT_FR(i), 0);
7407 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_MEM1(SLJIT_S0), (SLJIT_NUMBER_OF_FLOAT_REGISTERS - 1) * (sljit_sw)sizeof(sljit_f64), SLJIT_FS0, 0);
7408 sljit_emit_return_void(compiler);
7410 /* Called function. */
7411 sljit_set_label(jump, sljit_emit_label(compiler));
7412 sljit_emit_enter(compiler, 0, SLJIT_ARGS1(VOID, P), 0, 1, SLJIT_NUMBER_OF_FLOAT_REGISTERS, 0, SLJIT_MAX_LOCAL_SIZE);
7414 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR0, 0, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_f64));
7415 for (i = 1; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS; i++)
7416 sljit_emit_fop1(compiler, SLJIT_MOV_F64, SLJIT_FR(i), 0, SLJIT_FR0, 0);
7418 sljit_set_context(compiler, 0, SLJIT_ARGS1(VOID, P), 0, 1, SLJIT_NUMBER_OF_FLOAT_REGISTERS, 0, SLJIT_MAX_LOCAL_SIZE);
7419 sljit_emit_return_void(compiler);
7421 code.code = sljit_generate_code(compiler);
7422 CHECK(compiler);
7423 sljit_free_compiler(compiler);
7425 code.func2((sljit_sw)buf, (sljit_sw)buf2);
7427 for (i = 0; i < SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS; i++) {
7428 FAILED(buf[i] != 3.75, "test72 case 3 failed\n");
7431 for (i = SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS; i < SLJIT_NUMBER_OF_FLOAT_REGISTERS - 2; i++) {
7432 FAILED(buf[i] != -6.25, "test72 case 4 failed\n");
7435 FAILED(buf[SLJIT_NUMBER_OF_FLOAT_REGISTERS - 2] != 0, "test72 case 5 failed\n");
7436 FAILED(buf[SLJIT_NUMBER_OF_FLOAT_REGISTERS - 1] != -6.25, "test72 case 6 failed\n");
7438 sljit_free_code(code.code, NULL);
7440 successful_tests++;
7443 int sljit_test(int argc, char* argv[])
7445 sljit_s32 has_arg = (argc >= 2 && argv[1][0] == '-' && argv[1][2] == '\0');
7446 verbose = has_arg && argv[1][1] == 'v';
7447 silent = has_arg && argv[1][1] == 's';
7449 if (!verbose && !silent)
7450 printf("Pass -v to enable verbose, -s to disable this hint.\n\n");
7452 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
7453 test_exec_allocator();
7454 #endif
7455 test1();
7456 test2();
7457 test3();
7458 test4();
7459 test5();
7460 test6();
7461 test7();
7462 test8();
7463 test9();
7464 test10();
7465 test11();
7466 test12();
7467 test13();
7468 test14();
7469 test15();
7470 test16();
7471 test17();
7472 test18();
7473 test19();
7474 test20();
7475 test21();
7476 test22();
7477 test23();
7478 test24();
7479 test25();
7480 test26();
7481 test27();
7482 test28();
7483 test29();
7484 test30();
7485 test31();
7486 test32();
7487 test33();
7488 test34();
7489 test35();
7490 test36();
7491 test37();
7492 test38();
7493 test39();
7494 test40();
7495 test41();
7496 test42();
7497 test43();
7498 test44();
7499 test45();
7500 test46();
7501 test47();
7502 test48();
7503 test49();
7504 test50();
7505 test51();
7506 test52();
7507 test53();
7508 test54();
7509 test55();
7510 test56();
7511 test57();
7512 test58();
7513 test59();
7514 test60();
7515 test61();
7516 test62();
7517 test63();
7518 test64();
7519 test65();
7520 test66();
7521 test67();
7522 test68();
7523 test69();
7524 test70();
7525 test71();
7526 test72();
7528 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
7529 sljit_free_unused_memory_exec();
7530 #endif
7532 # define TEST_COUNT 72
7534 printf("SLJIT tests: ");
7535 if (successful_tests == TEST_COUNT)
7536 printf("all tests are " COLOR_GREEN "PASSED" COLOR_DEFAULT " ");
7537 else
7538 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);
7539 printf("on " COLOR_ARCH "%s" COLOR_DEFAULT "%s\n", sljit_get_platform_name(), sljit_has_cpu_feature(SLJIT_HAS_FPU) ? " (with fpu)" : " (without fpu)");
7541 return TEST_COUNT - successful_tests;
7543 # undef TEST_COUNT
7546 #ifdef _MSC_VER
7547 #pragma warning(pop)
7548 #endif